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