SvcHandler.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using ChocolArm64.Memory;
  2. using ChocolArm64.State;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace Ryujinx.Core.OsHle.Svc
  6. {
  7. partial class SvcHandler
  8. {
  9. private delegate void SvcFunc(AThreadState ThreadState);
  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. { 0x07, SvcExitProcess },
  24. { 0x08, SvcCreateThread },
  25. { 0x09, SvcStartThread },
  26. { 0x0b, SvcSleepThread },
  27. { 0x0c, SvcGetThreadPriority },
  28. { 0x13, SvcMapSharedMemory },
  29. { 0x14, SvcUnmapSharedMemory },
  30. { 0x15, SvcCreateTransferMemory },
  31. { 0x16, SvcCloseHandle },
  32. { 0x17, SvcResetSignal },
  33. { 0x18, SvcWaitSynchronization },
  34. { 0x1a, SvcArbitrateLock },
  35. { 0x1b, SvcArbitrateUnlock },
  36. { 0x1c, SvcWaitProcessWideKeyAtomic },
  37. { 0x1d, SvcSignalProcessWideKey },
  38. { 0x1e, SvcGetSystemTick },
  39. { 0x1f, SvcConnectToNamedPort },
  40. { 0x21, SvcSendSyncRequest },
  41. { 0x22, SvcSendSyncRequestWithUserBuffer },
  42. { 0x26, SvcBreak },
  43. { 0x27, SvcOutputDebugString },
  44. { 0x29, SvcGetInfo }
  45. };
  46. this.Ns = Ns;
  47. this.Process = Process;
  48. this.Memory = Process.Memory;
  49. }
  50. static SvcHandler()
  51. {
  52. Rng = new Random();
  53. }
  54. public void SvcCall(object sender, AInstExceptEventArgs e)
  55. {
  56. AThreadState ThreadState = (AThreadState)sender;
  57. if (SvcFuncs.TryGetValue(e.Id, out SvcFunc Func))
  58. {
  59. Logging.Trace($"(Thread {ThreadState.ThreadId}) {Func.Method.Name} called.");
  60. Func(ThreadState);
  61. Logging.Trace($"(Thread {ThreadState.ThreadId}) {Func.Method.Name} ended.");
  62. }
  63. else
  64. {
  65. throw new NotImplementedException(e.Id.ToString("x4"));
  66. }
  67. }
  68. }
  69. }