KernelTransfer.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using ChocolArm64.Memory;
  2. namespace Ryujinx.HLE.HOS.Kernel
  3. {
  4. static class KernelTransfer
  5. {
  6. public static bool UserToKernelInt32(Horizon System, long Address, out int Value)
  7. {
  8. KProcess CurrentProcess = System.Scheduler.GetCurrentProcess();
  9. if (CurrentProcess.CpuMemory.IsMapped(Address) &&
  10. CurrentProcess.CpuMemory.IsMapped(Address + 3))
  11. {
  12. Value = CurrentProcess.CpuMemory.ReadInt32(Address);
  13. return true;
  14. }
  15. Value = 0;
  16. return false;
  17. }
  18. public static bool UserToKernelString(Horizon System, long Address, int Size, out string Value)
  19. {
  20. KProcess CurrentProcess = System.Scheduler.GetCurrentProcess();
  21. if (CurrentProcess.CpuMemory.IsMapped(Address) &&
  22. CurrentProcess.CpuMemory.IsMapped(Address + Size - 1))
  23. {
  24. Value = MemoryHelper.ReadAsciiString(CurrentProcess.CpuMemory, Address, Size);
  25. return true;
  26. }
  27. Value = null;
  28. return false;
  29. }
  30. public static bool KernelToUserInt32(Horizon System, long Address, int Value)
  31. {
  32. KProcess CurrentProcess = System.Scheduler.GetCurrentProcess();
  33. if (CurrentProcess.CpuMemory.IsMapped(Address) &&
  34. CurrentProcess.CpuMemory.IsMapped(Address + 3))
  35. {
  36. CurrentProcess.CpuMemory.WriteInt32ToSharedAddr(Address, Value);
  37. return true;
  38. }
  39. return false;
  40. }
  41. public static bool KernelToUserInt64(Horizon System, long Address, long Value)
  42. {
  43. KProcess CurrentProcess = System.Scheduler.GetCurrentProcess();
  44. if (CurrentProcess.CpuMemory.IsMapped(Address) &&
  45. CurrentProcess.CpuMemory.IsMapped(Address + 7))
  46. {
  47. CurrentProcess.CpuMemory.WriteInt64(Address, Value);
  48. return true;
  49. }
  50. return false;
  51. }
  52. }
  53. }