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