2023-01-15 16:16:24 -05:00
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Memory;
|
2020-12-09 17:20:05 -05:00
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Process;
|
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
2023-01-04 17:15:45 -05:00
|
|
|
|
using Ryujinx.Horizon.Common;
|
2020-12-01 18:23:43 -05:00
|
|
|
|
using System;
|
2020-12-09 17:20:05 -05:00
|
|
|
|
using System.Threading;
|
2020-12-01 18:23:43 -05:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Kernel
|
|
|
|
|
{
|
|
|
|
|
static class KernelStatic
|
|
|
|
|
{
|
|
|
|
|
[ThreadStatic]
|
|
|
|
|
private static KernelContext Context;
|
|
|
|
|
|
2020-12-09 17:20:05 -05:00
|
|
|
|
[ThreadStatic]
|
|
|
|
|
private static KThread CurrentThread;
|
|
|
|
|
|
2023-01-04 17:15:45 -05:00
|
|
|
|
public static Result StartInitialProcess(
|
2020-12-09 17:20:05 -05:00
|
|
|
|
KernelContext context,
|
|
|
|
|
ProcessCreationInfo creationInfo,
|
2023-03-17 07:55:19 -04:00
|
|
|
|
ReadOnlySpan<uint> capabilities,
|
2020-12-09 17:20:05 -05:00
|
|
|
|
int mainThreadPriority,
|
|
|
|
|
ThreadStart customThreadStart)
|
2020-12-01 18:23:43 -05:00
|
|
|
|
{
|
2020-12-09 17:20:05 -05:00
|
|
|
|
KProcess process = new KProcess(context);
|
2020-12-01 18:23:43 -05:00
|
|
|
|
|
2023-01-04 17:15:45 -05:00
|
|
|
|
Result result = process.Initialize(
|
2020-12-09 17:20:05 -05:00
|
|
|
|
creationInfo,
|
|
|
|
|
capabilities,
|
|
|
|
|
context.ResourceLimit,
|
|
|
|
|
MemoryRegion.Service,
|
|
|
|
|
null,
|
|
|
|
|
customThreadStart);
|
2020-12-01 18:23:43 -05:00
|
|
|
|
|
2023-01-04 17:15:45 -05:00
|
|
|
|
if (result != Result.Success)
|
2020-12-09 17:20:05 -05:00
|
|
|
|
{
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2020-12-01 18:23:43 -05:00
|
|
|
|
|
2020-12-09 17:20:05 -05:00
|
|
|
|
process.DefaultCpuCore = 3;
|
2020-12-01 18:23:43 -05:00
|
|
|
|
|
2020-12-09 17:20:05 -05:00
|
|
|
|
context.Processes.TryAdd(process.Pid, process);
|
2020-12-01 18:23:43 -05:00
|
|
|
|
|
2020-12-09 17:20:05 -05:00
|
|
|
|
return process.Start(mainThreadPriority, 0x1000UL);
|
2020-12-01 18:23:43 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-09 17:20:05 -05:00
|
|
|
|
internal static void SetKernelContext(KernelContext context, KThread thread)
|
2020-12-01 18:23:43 -05:00
|
|
|
|
{
|
|
|
|
|
Context = context;
|
2020-12-09 17:20:05 -05:00
|
|
|
|
CurrentThread = thread;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static KThread GetCurrentThread()
|
|
|
|
|
{
|
|
|
|
|
return CurrentThread;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static KProcess GetCurrentProcess()
|
|
|
|
|
{
|
|
|
|
|
return GetCurrentThread().Owner;
|
2020-12-01 18:23:43 -05:00
|
|
|
|
}
|
2022-05-03 17:28:32 -04:00
|
|
|
|
|
|
|
|
|
internal static KProcess GetProcessByPid(ulong pid)
|
|
|
|
|
{
|
|
|
|
|
if (Context.Processes.TryGetValue(pid, out KProcess process))
|
|
|
|
|
{
|
|
|
|
|
return process;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2020-12-01 18:23:43 -05:00
|
|
|
|
}
|
2023-01-15 16:16:24 -05:00
|
|
|
|
}
|