2020-12-09 23:20:05 +01:00
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Memory;
|
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Process;
|
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
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;
|
|
|
|
|
|
|
|
|
|
public static KernelResult StartInitialProcess(
|
|
|
|
|
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
|
|
|
|
|
2020-12-09 23:20:05 +01:00
|
|
|
|
KernelResult result = process.Initialize(
|
|
|
|
|
creationInfo,
|
|
|
|
|
capabilities,
|
|
|
|
|
context.ResourceLimit,
|
|
|
|
|
MemoryRegion.Service,
|
|
|
|
|
null,
|
|
|
|
|
customThreadStart);
|
2020-12-02 00:23:43 +01:00
|
|
|
|
|
2020-12-09 23:20:05 +01:00
|
|
|
|
if (result != KernelResult.Success)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|