aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs')
-rw-r--r--src/Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs b/src/Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs
new file mode 100644
index 00000000..cbc276c5
--- /dev/null
+++ b/src/Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs
@@ -0,0 +1,73 @@
+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;
+ }
+ }
+} \ No newline at end of file