RyuKen/Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs
Mary 305f06eb71
HLE: Fix integer sign inconcistency accross the codebase (#2222)
* Make all title id instances unsigned

* Replace address and size with ulong instead of signed types

Long overdue change.
Also change some logics here and there to optimize with the new memory
manager.

* Address Ac_K's comments

* Remove uneeded cast all around

* Fixes some others misalignment
2021-04-24 12:16:01 +02:00

93 lines
No EOL
2.7 KiB
C#

using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Kernel.Process;
using System;
namespace Ryujinx.HLE.HOS.Kernel.Common
{
static class KernelTransfer
{
public static bool UserToKernelInt32(KernelContext context, ulong address, out int value)
{
KProcess currentProcess = KernelStatic.GetCurrentProcess();
if (currentProcess.CpuMemory.IsMapped(address) &&
currentProcess.CpuMemory.IsMapped(address + 3))
{
value = currentProcess.CpuMemory.Read<int>(address);
return true;
}
value = 0;
return false;
}
public static bool UserToKernelInt32Array(KernelContext context, ulong address, Span<int> values)
{
KProcess currentProcess = KernelStatic.GetCurrentProcess();
for (int index = 0; index < values.Length; index++, address += 4)
{
if (currentProcess.CpuMemory.IsMapped(address) &&
currentProcess.CpuMemory.IsMapped(address + 3))
{
values[index]= currentProcess.CpuMemory.Read<int>(address);
}
else
{
return false;
}
}
return true;
}
public static bool UserToKernelString(KernelContext context, ulong address, int size, out string value)
{
KProcess currentProcess = KernelStatic.GetCurrentProcess();
if (currentProcess.CpuMemory.IsMapped(address) &&
currentProcess.CpuMemory.IsMapped(address + (ulong)size - 1))
{
value = MemoryHelper.ReadAsciiString(currentProcess.CpuMemory, address, size);
return true;
}
value = null;
return false;
}
public static bool KernelToUserInt32(KernelContext context, ulong address, int value)
{
KProcess currentProcess = KernelStatic.GetCurrentProcess();
if (currentProcess.CpuMemory.IsMapped(address) &&
currentProcess.CpuMemory.IsMapped(address + 3))
{
currentProcess.CpuMemory.Write(address, value);
return true;
}
return false;
}
public static bool KernelToUserInt64(KernelContext context, ulong address, long value)
{
KProcess currentProcess = KernelStatic.GetCurrentProcess();
if (currentProcess.CpuMemory.IsMapped(address) &&
currentProcess.CpuMemory.IsMapped(address + 7))
{
currentProcess.CpuMemory.Write(address, value);
return true;
}
return false;
}
}
}