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