32 lines
769 B
C++
32 lines
769 B
C++
#include "sys/Syscall.h"
|
|
#include "thread/Scheduler.h"
|
|
|
|
Result<u64> sys_exit(Registers*, SyscallArgs args)
|
|
{
|
|
u8 status = (u8)args[0];
|
|
|
|
Thread* current = Scheduler::current();
|
|
|
|
Scheduler::for_each_child(current, [](Thread* child) {
|
|
child->parent = Scheduler::init_thread();
|
|
return true;
|
|
});
|
|
|
|
auto* parent = current->parent;
|
|
if (parent && parent->state == ThreadState::Waiting)
|
|
{
|
|
auto child = *parent->child_being_waited_for;
|
|
if (child == -1 || child == (pid_t)current->id)
|
|
{
|
|
parent->child_being_waited_for = (pid_t)current->id;
|
|
parent->wake_up();
|
|
}
|
|
}
|
|
|
|
current->status = status;
|
|
current->state = ThreadState::Exited;
|
|
|
|
kernel_yield();
|
|
unreachable();
|
|
}
|