SvcHandler.cs 2.8 KB

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