KernelTransfer.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using Ryujinx.Cpu;
  2. using Ryujinx.HLE.HOS.Kernel.Process;
  3. using System;
  4. namespace Ryujinx.HLE.HOS.Kernel.Common
  5. {
  6. static class KernelTransfer
  7. {
  8. public static bool UserToKernelInt32(KernelContext context, ulong address, out int value)
  9. {
  10. KProcess currentProcess = context.Scheduler.GetCurrentProcess();
  11. if (currentProcess.CpuMemory.IsMapped(address) &&
  12. currentProcess.CpuMemory.IsMapped(address + 3))
  13. {
  14. value = currentProcess.CpuMemory.Read<int>(address);
  15. return true;
  16. }
  17. value = 0;
  18. return false;
  19. }
  20. public static bool UserToKernelInt32Array(KernelContext context, ulong address, Span<int> values)
  21. {
  22. KProcess currentProcess = context.Scheduler.GetCurrentProcess();
  23. for (int index = 0; index < values.Length; index++, address += 4)
  24. {
  25. if (currentProcess.CpuMemory.IsMapped(address) &&
  26. currentProcess.CpuMemory.IsMapped(address + 3))
  27. {
  28. values[index]= currentProcess.CpuMemory.Read<int>(address);
  29. }
  30. else
  31. {
  32. return false;
  33. }
  34. }
  35. return true;
  36. }
  37. public static bool UserToKernelString(KernelContext context, ulong address, int size, out string value)
  38. {
  39. KProcess currentProcess = context.Scheduler.GetCurrentProcess();
  40. if (currentProcess.CpuMemory.IsMapped(address) &&
  41. currentProcess.CpuMemory.IsMapped(address + (ulong)size - 1))
  42. {
  43. value = MemoryHelper.ReadAsciiString(currentProcess.CpuMemory, (long)address, size);
  44. return true;
  45. }
  46. value = null;
  47. return false;
  48. }
  49. public static bool KernelToUserInt32(KernelContext context, ulong address, int value)
  50. {
  51. KProcess currentProcess = context.Scheduler.GetCurrentProcess();
  52. if (currentProcess.CpuMemory.IsMapped(address) &&
  53. currentProcess.CpuMemory.IsMapped(address + 3))
  54. {
  55. currentProcess.CpuMemory.Write(address, value);
  56. return true;
  57. }
  58. return false;
  59. }
  60. public static bool KernelToUserInt64(KernelContext context, ulong address, long value)
  61. {
  62. KProcess currentProcess = context.Scheduler.GetCurrentProcess();
  63. if (currentProcess.CpuMemory.IsMapped(address) &&
  64. currentProcess.CpuMemory.IsMapped(address + 7))
  65. {
  66. currentProcess.CpuMemory.Write(address, value);
  67. return true;
  68. }
  69. return false;
  70. }
  71. }
  72. }