0
0
Fork 0
This repository has been archived on 2024-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
ryujinx-final/Ryujinx.Core/OsHle/Svc/SvcThread.cs
gdkchan 4314a8f3e5
[WIP] Add support for events (#60)
* Add support for events, move concept of domains to IpcService

* Support waiting for KThread, remove some test code, other tweaks

* Use move handle on NIFM since I can't test that now, it's better to leave it how it was
2018-03-19 15:58:46 -03:00

133 lines
No EOL
3.5 KiB
C#

using ChocolArm64.State;
using Ryujinx.Core.OsHle.Handles;
namespace Ryujinx.Core.OsHle.Svc
{
partial class SvcHandler
{
private void SvcCreateThread(AThreadState ThreadState)
{
long EntryPoint = (long)ThreadState.X1;
long ArgsPtr = (long)ThreadState.X2;
long StackTop = (long)ThreadState.X3;
int Priority = (int)ThreadState.X4;
int ProcessorId = (int)ThreadState.X5;
if (Ns.Os.TryGetProcess(ThreadState.ProcessId, out Process Process))
{
if (ProcessorId == -2)
{
//TODO: Get this value from the NPDM file.
ProcessorId = 0;
}
int Handle = Process.MakeThread(
EntryPoint,
StackTop,
ArgsPtr,
Priority,
ProcessorId);
ThreadState.X0 = 0;
ThreadState.X1 = (ulong)Handle;
}
//TODO: Error codes.
}
private void SvcStartThread(AThreadState ThreadState)
{
int Handle = (int)ThreadState.X0;
KThread Thread = Process.HandleTable.GetData<KThread>(Handle);
if (Thread != null)
{
Process.Scheduler.StartThread(Thread);
ThreadState.X0 = 0;
}
//TODO: Error codes.
}
private void SvcExitThread(AThreadState ThreadState)
{
KThread CurrThread = Process.GetThread(ThreadState.Tpidr);
CurrThread.Thread.StopExecution();
CurrThread.Handle.Set();
}
private void SvcSleepThread(AThreadState ThreadState)
{
ulong NanoSecs = ThreadState.X0;
KThread CurrThread = Process.GetThread(ThreadState.Tpidr);
if (NanoSecs == 0)
{
Process.Scheduler.Yield(CurrThread);
}
else
{
Process.Scheduler.WaitForSignal(CurrThread, (int)(NanoSecs / 1000000));
}
}
private void SvcGetThreadPriority(AThreadState ThreadState)
{
int Handle = (int)ThreadState.X1;
KThread Thread = Process.HandleTable.GetData<KThread>(Handle);
if (Thread != null)
{
ThreadState.X0 = 0;
ThreadState.X1 = (ulong)Thread.Priority;
}
//TODO: Error codes.
}
private void SvcSetThreadPriority(AThreadState ThreadState)
{
int Prio = (int)ThreadState.X0;
int Handle = (int)ThreadState.X1;
KThread Thread = Process.HandleTable.GetData<KThread>(Handle);
if (Thread != null)
{
Thread.Priority = Prio;
ThreadState.X0 = 0;
}
//TODO: Error codes.
}
private void SvcSetThreadCoreMask(AThreadState ThreadState)
{
ThreadState.X0 = 0;
//TODO: Error codes.
}
private void SvcGetThreadId(AThreadState ThreadState)
{
int Handle = (int)ThreadState.X0;
KThread Thread = Process.HandleTable.GetData<KThread>(Handle);
if (Thread != null)
{
ThreadState.X0 = 0;
ThreadState.X1 = (ulong)Thread.ThreadId;
}
//TODO: Error codes.
}
}
}