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