0
0
Fork 0
mirror of https://github.com/ryujinx-mirror/ryujinx.git synced 2024-12-23 14:05:46 +00:00
ryujinx-fork/Ryujinx/OsHle/Svc/SvcThread.cs

79 lines
2.2 KiB
C#
Raw Normal View History

2018-02-04 23:08:20 +00:00
using ChocolArm64.Memory;
using ChocolArm64.State;
using Ryujinx.OsHle.Handles;
using System.Threading;
namespace Ryujinx.OsHle.Svc
{
partial class SvcHandler
{
private static void SvcCreateThread(Switch Ns, ARegisters Registers, AMemory Memory)
{
long EntryPoint = (long)Registers.X1;
long ArgsPtr = (long)Registers.X2;
long StackTop = (long)Registers.X3;
int Priority = (int)Registers.X4;
int ProcessorId = (int)Registers.X5;
if (Ns.Os.TryGetProcess(Registers.ProcessId, out Process Process))
{
int Handle = Process.MakeThread(
EntryPoint,
StackTop,
ArgsPtr,
Priority,
ProcessorId);
Registers.X0 = (int)SvcResult.Success;
Registers.X1 = (ulong)Handle;
}
//TODO: Error codes.
}
private static void SvcStartThread(Switch Ns, ARegisters Registers, AMemory Memory)
{
int Handle = (int)Registers.X0;
HThread HndData = Ns.Os.Handles.GetData<HThread>(Handle);
if (HndData != null)
{
HndData.Thread.Execute();
Registers.X0 = (int)SvcResult.Success;
}
//TODO: Error codes.
}
private static void SvcSleepThread(Switch Ns, ARegisters Registers, AMemory Memory)
{
ulong NanoSecs = Registers.X0;
if (NanoSecs == 0)
{
Thread.Yield();
}
else
{
Thread.Sleep((int)(NanoSecs / 1000000));
}
}
private static void SvcGetThreadPriority(Switch Ns, ARegisters Registers, AMemory Memory)
{
int Handle = (int)Registers.X1;
HThread HndData = Ns.Os.Handles.GetData<HThread>(Handle);
if (HndData != null)
{
Registers.X1 = (ulong)HndData.Thread.Priority;
Registers.X0 = (int)SvcResult.Success;
}
//TODO: Error codes.
}
}
}