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