SyscallHandler.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using ARMeilleure.State;
  2. using Ryujinx.HLE.HOS.Kernel.Threading;
  3. using System;
  4. namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
  5. {
  6. partial class SyscallHandler
  7. {
  8. private readonly KernelContext _context;
  9. private readonly Syscall32 _syscall32;
  10. private readonly Syscall64 _syscall64;
  11. public SyscallHandler(KernelContext context)
  12. {
  13. _context = context;
  14. _syscall32 = new Syscall32(context.Syscall);
  15. _syscall64 = new Syscall64(context.Syscall);
  16. }
  17. public void SvcCall(object sender, InstExceptionEventArgs e)
  18. {
  19. KThread currentThread = KernelStatic.GetCurrentThread();
  20. if (currentThread.Owner != null &&
  21. currentThread.GetUserDisableCount() != 0 &&
  22. currentThread.Owner.PinnedThreads[currentThread.CurrentCore] == null)
  23. {
  24. _context.CriticalSection.Enter();
  25. currentThread.Owner.PinThread(currentThread);
  26. currentThread.SetUserInterruptFlag();
  27. _context.CriticalSection.Leave();
  28. }
  29. ExecutionContext context = (ExecutionContext)sender;
  30. if (context.IsAarch32)
  31. {
  32. var svcFunc = SyscallTable.SvcTable32[e.Id];
  33. if (svcFunc == null)
  34. {
  35. throw new NotImplementedException($"SVC 0x{e.Id:X4} is not implemented.");
  36. }
  37. svcFunc(_syscall32, context);
  38. }
  39. else
  40. {
  41. var svcFunc = SyscallTable.SvcTable64[e.Id];
  42. if (svcFunc == null)
  43. {
  44. throw new NotImplementedException($"SVC 0x{e.Id:X4} is not implemented.");
  45. }
  46. svcFunc(_syscall64, context);
  47. }
  48. currentThread.HandlePostSyscall();
  49. }
  50. }
  51. }