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