SvcHandler.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. { 0x13, SvcMapSharedMemory },
  34. { 0x14, SvcUnmapSharedMemory },
  35. { 0x15, SvcCreateTransferMemory },
  36. { 0x16, SvcCloseHandle },
  37. { 0x17, SvcResetSignal },
  38. { 0x18, SvcWaitSynchronization },
  39. { 0x1a, SvcArbitrateLock },
  40. { 0x1b, SvcArbitrateUnlock },
  41. { 0x1c, SvcWaitProcessWideKeyAtomic },
  42. { 0x1d, SvcSignalProcessWideKey },
  43. { 0x1e, SvcGetSystemTick },
  44. { 0x1f, SvcConnectToNamedPort },
  45. { 0x21, SvcSendSyncRequest },
  46. { 0x22, SvcSendSyncRequestWithUserBuffer },
  47. { 0x25, SvcGetThreadId },
  48. { 0x26, SvcBreak },
  49. { 0x27, SvcOutputDebugString },
  50. { 0x29, SvcGetInfo }
  51. };
  52. this.Ns = Ns;
  53. this.Process = Process;
  54. this.Memory = Process.Memory;
  55. }
  56. static SvcHandler()
  57. {
  58. Rng = new Random();
  59. }
  60. public void SvcCall(object sender, AInstExceptionEventArgs e)
  61. {
  62. AThreadState ThreadState = (AThreadState)sender;
  63. if (SvcFuncs.TryGetValue(e.Id, out SvcFunc Func))
  64. {
  65. Logging.Trace($"(Thread {ThreadState.ThreadId}) {Func.Method.Name} called.");
  66. Func(ThreadState);
  67. Logging.Trace($"(Thread {ThreadState.ThreadId}) {Func.Method.Name} ended.");
  68. }
  69. else
  70. {
  71. throw new NotImplementedException(e.Id.ToString("x4"));
  72. }
  73. }
  74. }
  75. }