2020-05-03 22:54:50 +00:00
|
|
|
using Ryujinx.Cpu;
|
2018-12-18 05:33:36 +00:00
|
|
|
using Ryujinx.HLE.HOS.Kernel.Process;
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Kernel.Common
|
|
|
|
{
|
|
|
|
static class KernelTransfer
|
|
|
|
{
|
2020-05-04 03:41:29 +00:00
|
|
|
public static bool UserToKernelInt32(KernelContext context, ulong address, out int value)
|
2018-12-18 05:33:36 +00:00
|
|
|
{
|
2020-05-04 03:41:29 +00:00
|
|
|
KProcess currentProcess = context.Scheduler.GetCurrentProcess();
|
2018-12-18 05:33:36 +00:00
|
|
|
|
2020-05-03 22:54:50 +00:00
|
|
|
if (currentProcess.CpuMemory.IsMapped(address) &&
|
|
|
|
currentProcess.CpuMemory.IsMapped(address + 3))
|
2018-12-18 05:33:36 +00:00
|
|
|
{
|
2020-05-03 22:54:50 +00:00
|
|
|
value = currentProcess.CpuMemory.Read<int>(address);
|
2018-12-18 05:33:36 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = 0;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-04 03:41:29 +00:00
|
|
|
public static bool UserToKernelInt32Array(KernelContext context, ulong address, int[] values)
|
2019-01-18 22:26:39 +00:00
|
|
|
{
|
2020-05-04 03:41:29 +00:00
|
|
|
KProcess currentProcess = context.Scheduler.GetCurrentProcess();
|
2019-01-18 22:26:39 +00:00
|
|
|
|
|
|
|
for (int index = 0; index < values.Length; index++, address += 4)
|
|
|
|
{
|
2020-05-03 22:54:50 +00:00
|
|
|
if (currentProcess.CpuMemory.IsMapped(address) &&
|
|
|
|
currentProcess.CpuMemory.IsMapped(address + 3))
|
2019-01-18 22:26:39 +00:00
|
|
|
{
|
2020-05-03 22:54:50 +00:00
|
|
|
values[index]= currentProcess.CpuMemory.Read<int>(address);
|
2019-01-18 22:26:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-04 03:41:29 +00:00
|
|
|
public static bool UserToKernelString(KernelContext context, ulong address, int size, out string value)
|
2018-12-18 05:33:36 +00:00
|
|
|
{
|
2020-05-04 03:41:29 +00:00
|
|
|
KProcess currentProcess = context.Scheduler.GetCurrentProcess();
|
2018-12-18 05:33:36 +00:00
|
|
|
|
2020-05-03 22:54:50 +00:00
|
|
|
if (currentProcess.CpuMemory.IsMapped(address) &&
|
|
|
|
currentProcess.CpuMemory.IsMapped(address + (ulong)size - 1))
|
2018-12-18 05:33:36 +00:00
|
|
|
{
|
|
|
|
value = MemoryHelper.ReadAsciiString(currentProcess.CpuMemory, (long)address, size);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = null;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-04 03:41:29 +00:00
|
|
|
public static bool KernelToUserInt32(KernelContext context, ulong address, int value)
|
2018-12-18 05:33:36 +00:00
|
|
|
{
|
2020-05-04 03:41:29 +00:00
|
|
|
KProcess currentProcess = context.Scheduler.GetCurrentProcess();
|
2018-12-18 05:33:36 +00:00
|
|
|
|
2020-05-03 22:54:50 +00:00
|
|
|
if (currentProcess.CpuMemory.IsMapped(address) &&
|
|
|
|
currentProcess.CpuMemory.IsMapped(address + 3))
|
2018-12-18 05:33:36 +00:00
|
|
|
{
|
2020-05-03 22:54:50 +00:00
|
|
|
currentProcess.CpuMemory.Write(address, value);
|
2018-12-18 05:33:36 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-04 03:41:29 +00:00
|
|
|
public static bool KernelToUserInt64(KernelContext context, ulong address, long value)
|
2018-12-18 05:33:36 +00:00
|
|
|
{
|
2020-05-04 03:41:29 +00:00
|
|
|
KProcess currentProcess = context.Scheduler.GetCurrentProcess();
|
2018-12-18 05:33:36 +00:00
|
|
|
|
2020-05-03 22:54:50 +00:00
|
|
|
if (currentProcess.CpuMemory.IsMapped(address) &&
|
|
|
|
currentProcess.CpuMemory.IsMapped(address + 7))
|
2018-12-18 05:33:36 +00:00
|
|
|
{
|
2020-05-03 22:54:50 +00:00
|
|
|
currentProcess.CpuMemory.Write(address, value);
|
2018-12-18 05:33:36 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|