SvcThread.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using ChocolArm64.State;
  2. using Ryujinx.Core.OsHle.Handles;
  3. namespace Ryujinx.Core.OsHle.Svc
  4. {
  5. partial class SvcHandler
  6. {
  7. private void SvcCreateThread(AThreadState ThreadState)
  8. {
  9. long EntryPoint = (long)ThreadState.X1;
  10. long ArgsPtr = (long)ThreadState.X2;
  11. long StackTop = (long)ThreadState.X3;
  12. int Priority = (int)ThreadState.X4;
  13. int ProcessorId = (int)ThreadState.X5;
  14. if (Ns.Os.TryGetProcess(ThreadState.ProcessId, out Process Process))
  15. {
  16. if (ProcessorId == -2)
  17. {
  18. //TODO: Get this value from the NPDM file.
  19. ProcessorId = 0;
  20. }
  21. int Handle = Process.MakeThread(
  22. EntryPoint,
  23. StackTop,
  24. ArgsPtr,
  25. Priority,
  26. ProcessorId);
  27. ThreadState.X0 = 0;
  28. ThreadState.X1 = (ulong)Handle;
  29. }
  30. //TODO: Error codes.
  31. }
  32. private void SvcStartThread(AThreadState ThreadState)
  33. {
  34. int Handle = (int)ThreadState.X0;
  35. HThread Thread = Ns.Os.Handles.GetData<HThread>(Handle);
  36. if (Thread != null)
  37. {
  38. Process.Scheduler.StartThread(Thread);
  39. ThreadState.X0 = 0;
  40. }
  41. //TODO: Error codes.
  42. }
  43. private void SvcSleepThread(AThreadState ThreadState)
  44. {
  45. ulong NanoSecs = ThreadState.X0;
  46. HThread CurrThread = Process.GetThread(ThreadState.Tpidr);
  47. if (NanoSecs == 0)
  48. {
  49. Process.Scheduler.Yield(CurrThread);
  50. }
  51. else
  52. {
  53. Process.Scheduler.WaitForSignal(CurrThread, (int)(NanoSecs / 1000000));
  54. }
  55. }
  56. private void SvcGetThreadPriority(AThreadState ThreadState)
  57. {
  58. int Handle = (int)ThreadState.X1;
  59. HThread Thread = Ns.Os.Handles.GetData<HThread>(Handle);
  60. if (Thread != null)
  61. {
  62. ThreadState.X0 = 0;
  63. ThreadState.X1 = (ulong)Thread.Priority;
  64. }
  65. //TODO: Error codes.
  66. }
  67. private void SvcSetThreadPriority(AThreadState ThreadState)
  68. {
  69. int Handle = (int)ThreadState.X1;
  70. int Prio = (int)ThreadState.X0;
  71. HThread Thread = Ns.Os.Handles.GetData<HThread>(Handle);
  72. if (Thread != null)
  73. {
  74. Thread.Priority = Prio;
  75. ThreadState.X0 = 0;
  76. }
  77. //TODO: Error codes.
  78. }
  79. private void SvcSetThreadCoreMask(AThreadState ThreadState)
  80. {
  81. ThreadState.X0 = 0;
  82. //TODO: Error codes.
  83. }
  84. private void SvcGetThreadId(AThreadState ThreadState)
  85. {
  86. int Handle = (int)ThreadState.X0;
  87. HThread Thread = Ns.Os.Handles.GetData<HThread>(Handle);
  88. if (Thread != null)
  89. {
  90. ThreadState.X0 = 0;
  91. ThreadState.X1 = (ulong)Thread.ThreadId;
  92. }
  93. //TODO: Error codes.
  94. }
  95. }
  96. }