2018-11-28 23:18:09 +01:00
|
|
|
using ChocolArm64.Memory;
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Kernel
|
|
|
|
{
|
|
|
|
static class KernelTransfer
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
public static bool UserToKernelInt32(Horizon System, long Address, out int Value)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
KProcess CurrentProcess = System.Scheduler.GetCurrentProcess();
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (CurrentProcess.CpuMemory.IsMapped(Address) &&
|
|
|
|
CurrentProcess.CpuMemory.IsMapped(Address + 3))
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Value = CurrentProcess.CpuMemory.ReadInt32(Address);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
Value = 0;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public static bool UserToKernelString(Horizon System, long Address, int Size, out string Value)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
KProcess CurrentProcess = System.Scheduler.GetCurrentProcess();
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (CurrentProcess.CpuMemory.IsMapped(Address) &&
|
|
|
|
CurrentProcess.CpuMemory.IsMapped(Address + Size - 1))
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Value = MemoryHelper.ReadAsciiString(CurrentProcess.CpuMemory, Address, Size);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
Value = null;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public static bool KernelToUserInt32(Horizon System, long Address, int Value)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
KProcess CurrentProcess = System.Scheduler.GetCurrentProcess();
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (CurrentProcess.CpuMemory.IsMapped(Address) &&
|
|
|
|
CurrentProcess.CpuMemory.IsMapped(Address + 3))
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
CurrentProcess.CpuMemory.WriteInt32ToSharedAddr(Address, Value);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public static bool KernelToUserInt64(Horizon System, long Address, long Value)
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
KProcess CurrentProcess = System.Scheduler.GetCurrentProcess();
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (CurrentProcess.CpuMemory.IsMapped(Address) &&
|
|
|
|
CurrentProcess.CpuMemory.IsMapped(Address + 7))
|
2018-11-28 23:18:09 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
CurrentProcess.CpuMemory.WriteInt64(Address, Value);
|
2018-11-28 23:18:09 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|