SvcHandler.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using ChocolArm64.Events;
  2. using ChocolArm64.Memory;
  3. using ChocolArm64.State;
  4. using Ryujinx.HLE.HOS.Ipc;
  5. using Ryujinx.Common.Logging;
  6. using System;
  7. using System.Collections.Generic;
  8. namespace Ryujinx.HLE.HOS.Kernel
  9. {
  10. partial class SvcHandler
  11. {
  12. private delegate void SvcFunc(CpuThreadState threadState);
  13. private Dictionary<int, SvcFunc> _svcFuncs;
  14. private Switch _device;
  15. private KProcess _process;
  16. private Horizon _system;
  17. private MemoryManager _memory;
  18. private struct HleIpcMessage
  19. {
  20. public KThread Thread { get; }
  21. public KSession Session { get; }
  22. public IpcMessage Message { get; }
  23. public long MessagePtr { get; }
  24. public HleIpcMessage(
  25. KThread thread,
  26. KSession session,
  27. IpcMessage message,
  28. long messagePtr)
  29. {
  30. Thread = thread;
  31. Session = session;
  32. Message = message;
  33. MessagePtr = messagePtr;
  34. }
  35. }
  36. public SvcHandler(Switch device, KProcess process)
  37. {
  38. _svcFuncs = new Dictionary<int, SvcFunc>
  39. {
  40. { 0x01, SvcSetHeapSize },
  41. { 0x03, SvcSetMemoryAttribute },
  42. { 0x04, SvcMapMemory },
  43. { 0x05, SvcUnmapMemory },
  44. { 0x06, SvcQueryMemory },
  45. { 0x07, SvcExitProcess },
  46. { 0x08, CreateThread64 },
  47. { 0x09, SvcStartThread },
  48. { 0x0a, SvcExitThread },
  49. { 0x0b, SvcSleepThread },
  50. { 0x0c, SvcGetThreadPriority },
  51. { 0x0d, SvcSetThreadPriority },
  52. { 0x0e, SvcGetThreadCoreMask },
  53. { 0x0f, SetThreadCoreMask64 },
  54. { 0x10, SvcGetCurrentProcessorNumber },
  55. { 0x11, SignalEvent64 },
  56. { 0x12, ClearEvent64 },
  57. { 0x13, SvcMapSharedMemory },
  58. { 0x14, SvcUnmapSharedMemory },
  59. { 0x15, SvcCreateTransferMemory },
  60. { 0x16, SvcCloseHandle },
  61. { 0x17, ResetSignal64 },
  62. { 0x18, SvcWaitSynchronization },
  63. { 0x19, SvcCancelSynchronization },
  64. { 0x1a, SvcArbitrateLock },
  65. { 0x1b, SvcArbitrateUnlock },
  66. { 0x1c, SvcWaitProcessWideKeyAtomic },
  67. { 0x1d, SvcSignalProcessWideKey },
  68. { 0x1e, SvcGetSystemTick },
  69. { 0x1f, SvcConnectToNamedPort },
  70. { 0x21, SvcSendSyncRequest },
  71. { 0x22, SvcSendSyncRequestWithUserBuffer },
  72. { 0x24, GetProcessId64 },
  73. { 0x25, SvcGetThreadId },
  74. { 0x26, SvcBreak },
  75. { 0x27, SvcOutputDebugString },
  76. { 0x29, GetInfo64 },
  77. { 0x2c, SvcMapPhysicalMemory },
  78. { 0x2d, SvcUnmapPhysicalMemory },
  79. { 0x32, SvcSetThreadActivity },
  80. { 0x33, SvcGetThreadContext3 },
  81. { 0x34, SvcWaitForAddress },
  82. { 0x35, SvcSignalToAddress },
  83. { 0x45, CreateEvent64 },
  84. { 0x65, GetProcessList64 },
  85. { 0x6f, GetSystemInfo64 },
  86. { 0x70, CreatePort64 },
  87. { 0x71, ManageNamedPort64 }
  88. };
  89. _device = device;
  90. _process = process;
  91. _system = device.System;
  92. _memory = process.CpuMemory;
  93. }
  94. public void SvcCall(object sender, InstExceptionEventArgs e)
  95. {
  96. CpuThreadState threadState = (CpuThreadState)sender;
  97. if (_svcFuncs.TryGetValue(e.Id, out SvcFunc func))
  98. {
  99. Logger.PrintDebug(LogClass.KernelSvc, $"{func.Method.Name} called.");
  100. func(threadState);
  101. Logger.PrintDebug(LogClass.KernelSvc, $"{func.Method.Name} ended.");
  102. }
  103. else
  104. {
  105. //Process.PrintStackTrace(ThreadState);
  106. throw new NotImplementedException($"0x{e.Id:x4}");
  107. }
  108. }
  109. }
  110. }