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. }