mirror of
https://github.com/GreemDev/Ryujinx.git
synced 2024-12-23 22:05:46 +00:00
15d1cc806b
* Move kernel state from Horizon to KernelContext * Merge syscalls partial classes, split 32 and 64-bit variants * Sort usings
92 lines
No EOL
2.8 KiB
C#
92 lines
No EOL
2.8 KiB
C#
using Ryujinx.Cpu;
|
|
using Ryujinx.HLE.HOS.Kernel.Process;
|
|
|
|
namespace Ryujinx.HLE.HOS.Kernel.Common
|
|
{
|
|
static class KernelTransfer
|
|
{
|
|
public static bool UserToKernelInt32(KernelContext context, ulong address, out int value)
|
|
{
|
|
KProcess currentProcess = context.Scheduler.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, int[] values)
|
|
{
|
|
KProcess currentProcess = context.Scheduler.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 = context.Scheduler.GetCurrentProcess();
|
|
|
|
if (currentProcess.CpuMemory.IsMapped(address) &&
|
|
currentProcess.CpuMemory.IsMapped(address + (ulong)size - 1))
|
|
{
|
|
value = MemoryHelper.ReadAsciiString(currentProcess.CpuMemory, (long)address, size);
|
|
|
|
return true;
|
|
}
|
|
|
|
value = null;
|
|
|
|
return false;
|
|
}
|
|
|
|
public static bool KernelToUserInt32(KernelContext context, ulong address, int value)
|
|
{
|
|
KProcess currentProcess = context.Scheduler.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 = context.Scheduler.GetCurrentProcess();
|
|
|
|
if (currentProcess.CpuMemory.IsMapped(address) &&
|
|
currentProcess.CpuMemory.IsMapped(address + 7))
|
|
{
|
|
currentProcess.CpuMemory.Write(address, value);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
} |