0
0
Fork 0
mirror of https://github.com/GreemDev/Ryujinx.git synced 2024-12-27 20:35:48 +00:00
Ryujinx/Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs
Mary 20ce37dee6
kernel: A bit of refactoring and fix GetThreadContext3 correctness (#3042)
* Start refactoring kernel a bit and import some changes from kernel decoupling PR

* kernel: Put output always at the start in Syscall functions

* kernel: Rewrite GetThreadContext3 to use a structure and to be accurate

* kernel: make KernelTransfer use generic types and simplify

* Fix some warning and do not use getters on MemoryInfo

* Address gdkchan's comment

* GetThreadContext3: use correct pause flag
2022-01-29 22:18:03 +01:00

73 lines
No EOL
2 KiB
C#

using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Kernel.Process;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Kernel.Common
{
static class KernelTransfer
{
public static bool UserToKernel<T>(out T value, ulong address) where T : unmanaged
{
KProcess currentProcess = KernelStatic.GetCurrentProcess();
if (currentProcess.CpuMemory.IsRangeMapped(address, (ulong)Unsafe.SizeOf<T>()))
{
value = currentProcess.CpuMemory.Read<T>(address);
return true;
}
value = default;
return false;
}
public static bool UserToKernelArray<T>(ulong address, Span<T> values) where T : unmanaged
{
KProcess currentProcess = KernelStatic.GetCurrentProcess();
Span<byte> data = MemoryMarshal.Cast<T, byte>(values);
if (currentProcess.CpuMemory.IsRangeMapped(address, (ulong)data.Length))
{
currentProcess.CpuMemory.Read(address, data);
return true;
}
return false;
}
public static bool UserToKernelString(out string value, ulong address, uint size)
{
KProcess currentProcess = KernelStatic.GetCurrentProcess();
if (currentProcess.CpuMemory.IsRangeMapped(address, size))
{
value = MemoryHelper.ReadAsciiString(currentProcess.CpuMemory, address, size);
return true;
}
value = null;
return false;
}
public static bool KernelToUser<T>(ulong address, T value) where T: unmanaged
{
KProcess currentProcess = KernelStatic.GetCurrentProcess();
if (currentProcess.CpuMemory.IsRangeMapped(address, (ulong)Unsafe.SizeOf<T>()))
{
currentProcess.CpuMemory.Write(address, value);
return true;
}
return false;
}
}
}