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;
|
2020-07-16 21:22:13 -07:00
|
|
|
using System;
|
2018-12-17 21:33:36 -08:00
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Kernel.Common
|
|
|
|
{
|
|
|
|
static class KernelTransfer
|
|
|
|
{
|
2020-05-03 20:41:29 -07:00
|
|
|
public static bool UserToKernelInt32(KernelContext context, ulong address, out int value)
|
2018-12-17 21:33:36 -08:00
|
|
|
{
|
2020-05-03 20:41:29 -07:00
|
|
|
KProcess currentProcess = context.Scheduler.GetCurrentProcess();
|
2018-12-17 21:33:36 -08:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-07-16 21:22:13 -07:00
|
|
|
public static bool UserToKernelInt32Array(KernelContext context, ulong address, Span<int> values)
|
2019-01-18 14:26:39 -08:00
|
|
|
{
|
2020-05-03 20:41:29 -07:00
|
|
|
KProcess currentProcess = context.Scheduler.GetCurrentProcess();
|
2019-01-18 14:26:39 -08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-05-03 20:41:29 -07:00
|
|
|
public static bool UserToKernelString(KernelContext context, ulong address, int size, out string value)
|
2018-12-17 21:33:36 -08:00
|
|
|
{
|
2020-05-03 20:41:29 -07:00
|
|
|
KProcess currentProcess = context.Scheduler.GetCurrentProcess();
|
2018-12-17 21:33:36 -08:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-05-03 20:41:29 -07:00
|
|
|
public static bool KernelToUserInt32(KernelContext context, ulong address, int value)
|
2018-12-17 21:33:36 -08:00
|
|
|
{
|
2020-05-03 20:41:29 -07:00
|
|
|
KProcess currentProcess = context.Scheduler.GetCurrentProcess();
|
2018-12-17 21:33:36 -08:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-05-03 20:41:29 -07:00
|
|
|
public static bool KernelToUserInt64(KernelContext context, ulong address, long value)
|
2018-12-17 21:33:36 -08:00
|
|
|
{
|
2020-05-03 20:41:29 -07:00
|
|
|
KProcess currentProcess = context.Scheduler.GetCurrentProcess();
|
2018-12-17 21:33:36 -08:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|