aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs
diff options
context:
space:
mode:
authorMary <me@thog.eu>2022-01-29 22:18:03 +0100
committerGitHub <noreply@github.com>2022-01-29 22:18:03 +0100
commit20ce37dee6158ede18ad699338ecea083728423b (patch)
tree368333cced7160a272e1f29f92d99b9b48ae3199 /Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs
parentc52158b73361bd25364c23c2b39780d2e626c858 (diff)
kernel: A bit of refactoring and fix GetThreadContext3 correctness (#3042)1.1.12
* 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
Diffstat (limited to 'Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs')
-rw-r--r--Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs54
1 files changed, 17 insertions, 37 deletions
diff --git a/Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs b/Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs
index 53e539a2..cbc276c5 100644
--- a/Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs
+++ b/Ryujinx.HLE/HOS/Kernel/Common/KernelTransfer.cs
@@ -1,86 +1,66 @@
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 UserToKernelInt32(KernelContext context, ulong address, out int value)
+ public static bool UserToKernel<T>(out T value, ulong address) where T : unmanaged
{
KProcess currentProcess = KernelStatic.GetCurrentProcess();
- if (currentProcess.CpuMemory.IsMapped(address) &&
- currentProcess.CpuMemory.IsMapped(address + 3))
+ if (currentProcess.CpuMemory.IsRangeMapped(address, (ulong)Unsafe.SizeOf<T>()))
{
- value = currentProcess.CpuMemory.Read<int>(address);
+ value = currentProcess.CpuMemory.Read<T>(address);
return true;
}
- value = 0;
+ value = default;
return false;
}
- public static bool UserToKernelInt32Array(KernelContext context, ulong address, Span<int> values)
+ public static bool UserToKernelArray<T>(ulong address, Span<T> values) where T : unmanaged
{
KProcess currentProcess = KernelStatic.GetCurrentProcess();
- for (int index = 0; index < values.Length; index++, address += 4)
- {
- if (currentProcess.CpuMemory.IsMapped(address) &&
- currentProcess.CpuMemory.IsMapped(address + 3))
- {
- values[index]= currentProcess.CpuMemory.Read<int>(address);
- }
- else
- {
- return false;
- }
- }
-
- return true;
- }
-
- public static bool UserToKernelString(KernelContext context, ulong address, int size, out string value)
- {
- KProcess currentProcess = KernelStatic.GetCurrentProcess();
+ Span<byte> data = MemoryMarshal.Cast<T, byte>(values);
- if (currentProcess.CpuMemory.IsMapped(address) &&
- currentProcess.CpuMemory.IsMapped(address + (ulong)size - 1))
+ if (currentProcess.CpuMemory.IsRangeMapped(address, (ulong)data.Length))
{
- value = MemoryHelper.ReadAsciiString(currentProcess.CpuMemory, address, size);
+ currentProcess.CpuMemory.Read(address, data);
return true;
}
- value = null;
-
return false;
}
- public static bool KernelToUserInt32(KernelContext context, ulong address, int value)
+ public static bool UserToKernelString(out string value, ulong address, uint size)
{
KProcess currentProcess = KernelStatic.GetCurrentProcess();
- if (currentProcess.CpuMemory.IsMapped(address) &&
- currentProcess.CpuMemory.IsMapped(address + 3))
+ if (currentProcess.CpuMemory.IsRangeMapped(address, size))
{
- currentProcess.CpuMemory.Write(address, value);
+ value = MemoryHelper.ReadAsciiString(currentProcess.CpuMemory, address, size);
return true;
}
+ value = null;
+
return false;
}
- public static bool KernelToUserInt64(KernelContext context, ulong address, long value)
+ public static bool KernelToUser<T>(ulong address, T value) where T: unmanaged
{
KProcess currentProcess = KernelStatic.GetCurrentProcess();
- if (currentProcess.CpuMemory.IsMapped(address) &&
- currentProcess.CpuMemory.IsMapped(address + 7))
+ if (currentProcess.CpuMemory.IsRangeMapped(address, (ulong)Unsafe.SizeOf<T>()))
{
currentProcess.CpuMemory.Write(address, value);