SvcHandler.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using ChocolArm64.Events;
  2. using ChocolArm64.Memory;
  3. using ChocolArm64.State;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace Ryujinx.Core.OsHle.Svc
  7. {
  8. partial class SvcHandler
  9. {
  10. private delegate void SvcFunc(AThreadState ThreadState);
  11. private Dictionary<int, SvcFunc> SvcFuncs;
  12. private Switch Ns;
  13. private Process Process;
  14. private AMemory Memory;
  15. private static Random Rng;
  16. private ulong CurrentHeapSize;
  17. public SvcHandler(Switch Ns, Process Process)
  18. {
  19. SvcFuncs = new Dictionary<int, SvcFunc>()
  20. {
  21. { 0x01, SvcSetHeapSize },
  22. { 0x03, SvcSetMemoryAttribute },
  23. { 0x04, SvcMapMemory },
  24. { 0x05, SvcUnmapMemory },
  25. { 0x06, SvcQueryMemory },
  26. { 0x07, SvcExitProcess },
  27. { 0x08, SvcCreateThread },
  28. { 0x09, SvcStartThread },
  29. { 0x0b, SvcSleepThread },
  30. { 0x0c, SvcGetThreadPriority },
  31. { 0x0d, SvcSetThreadPriority },
  32. { 0x0f, SvcSetThreadCoreMask },
  33. { 0x12, SvcClearEvent },
  34. { 0x13, SvcMapSharedMemory },
  35. { 0x14, SvcUnmapSharedMemory },
  36. { 0x15, SvcCreateTransferMemory },
  37. { 0x16, SvcCloseHandle },
  38. { 0x17, SvcResetSignal },
  39. { 0x18, SvcWaitSynchronization },
  40. { 0x1a, SvcArbitrateLock },
  41. { 0x1b, SvcArbitrateUnlock },
  42. { 0x1c, SvcWaitProcessWideKeyAtomic },
  43. { 0x1d, SvcSignalProcessWideKey },
  44. { 0x1e, SvcGetSystemTick },
  45. { 0x1f, SvcConnectToNamedPort },
  46. { 0x21, SvcSendSyncRequest },
  47. { 0x22, SvcSendSyncRequestWithUserBuffer },
  48. { 0x25, SvcGetThreadId },
  49. { 0x26, SvcBreak },
  50. { 0x27, SvcOutputDebugString },
  51. { 0x29, SvcGetInfo }
  52. };
  53. this.Ns = Ns;
  54. this.Process = Process;
  55. this.Memory = Process.Memory;
  56. }
  57. static SvcHandler()
  58. {
  59. Rng = new Random();
  60. }
  61. public void SvcCall(object sender, AInstExceptionEventArgs e)
  62. {
  63. AThreadState ThreadState = (AThreadState)sender;
  64. if (SvcFuncs.TryGetValue(e.Id, out SvcFunc Func))
  65. {
  66. Logging.Trace($"(Thread {ThreadState.ThreadId}) {Func.Method.Name} called.");
  67. Func(ThreadState);
  68. Logging.Trace($"(Thread {ThreadState.ThreadId}) {Func.Method.Name} ended.");
  69. }
  70. else
  71. {
  72. throw new NotImplementedException(e.Id.ToString("x4"));
  73. }
  74. }
  75. }
  76. }