[Kernel] Implement GetThreadID, stub DuplicateHandle

This commit is contained in:
wheremyfoodat 2022-09-22 00:02:50 +03:00
parent 0b2e22ca6d
commit aef1520f17
5 changed files with 46 additions and 6 deletions

View file

@ -46,6 +46,7 @@ Handle Kernel::makeThread(u32 entrypoint, u32 initialSP, u32 priority, s32 id, u
t.gprs.fill(0);
t.fprs.fill(0);
t.arg = arg;
t.initialSP = initialSP;
t.entrypoint = entrypoint;
@ -93,4 +94,25 @@ void Kernel::sleepThreadOnArbiter(u32 waitingAddress) {
t.status = ThreadStatus::WaitArbiter;
t.waitingAddress = waitingAddress;
switchThread(1); // TODO: Properly change threads
}
void Kernel::getThreadID() {
Handle handle = regs[1];
printf("GetThreadID(handle = %X)\n", handle);
if (handle == KernelHandles::CurrentThread) {
regs[0] = SVCResult::Success;
regs[1] = currentThreadIndex;
return;
}
const auto thread = getObject(handle, KernelObjectType::Thread);
if (thread == nullptr) [[unlikely]] {
regs[0] = SVCResult::BadHandle;
return;
}
regs[0] = SVCResult::Success;
regs[1] = thread->getData<Thread>()->index;
}