KernelStatic.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using Ryujinx.HLE.HOS.Kernel.Common;
  2. using Ryujinx.HLE.HOS.Kernel.Memory;
  3. using Ryujinx.HLE.HOS.Kernel.Process;
  4. using Ryujinx.HLE.HOS.Kernel.Threading;
  5. using Ryujinx.Horizon.Common;
  6. using System;
  7. using System.Threading;
  8. namespace Ryujinx.HLE.HOS.Kernel
  9. {
  10. static class KernelStatic
  11. {
  12. [ThreadStatic]
  13. private static KernelContext Context;
  14. [ThreadStatic]
  15. private static KThread CurrentThread;
  16. public static Result StartInitialProcess(
  17. KernelContext context,
  18. ProcessCreationInfo creationInfo,
  19. ReadOnlySpan<int> capabilities,
  20. int mainThreadPriority,
  21. ThreadStart customThreadStart)
  22. {
  23. KProcess process = new KProcess(context);
  24. Result result = process.Initialize(
  25. creationInfo,
  26. capabilities,
  27. context.ResourceLimit,
  28. MemoryRegion.Service,
  29. null,
  30. customThreadStart);
  31. if (result != Result.Success)
  32. {
  33. return result;
  34. }
  35. process.DefaultCpuCore = 3;
  36. context.Processes.TryAdd(process.Pid, process);
  37. return process.Start(mainThreadPriority, 0x1000UL);
  38. }
  39. internal static void SetKernelContext(KernelContext context, KThread thread)
  40. {
  41. Context = context;
  42. CurrentThread = thread;
  43. }
  44. internal static KThread GetCurrentThread()
  45. {
  46. return CurrentThread;
  47. }
  48. internal static KProcess GetCurrentProcess()
  49. {
  50. return GetCurrentThread().Owner;
  51. }
  52. internal static KProcess GetProcessByPid(ulong pid)
  53. {
  54. if (Context.Processes.TryGetValue(pid, out KProcess process))
  55. {
  56. return process;
  57. }
  58. return null;
  59. }
  60. }
  61. }