2023-01-05 22:39:56 +01:00
|
|
|
#include "sys/Syscall.h"
|
|
|
|
#include "thread/Scheduler.h"
|
|
|
|
|
2023-03-23 22:25:56 +01:00
|
|
|
Result<u64> sys_exit(Registers*, SyscallArgs args)
|
2023-01-05 22:39:56 +01:00
|
|
|
{
|
2023-03-23 22:25:56 +01:00
|
|
|
u8 status = (u8)args[0];
|
|
|
|
|
|
|
|
Thread* current = Scheduler::current();
|
|
|
|
|
2023-04-28 15:13:53 +02:00
|
|
|
Scheduler::for_each_child((pid_t)current->id, [](Thread* child) {
|
|
|
|
child->parent_id = 1;
|
|
|
|
return true;
|
|
|
|
});
|
2023-03-24 17:37:04 +01:00
|
|
|
|
2023-03-23 22:25:56 +01:00
|
|
|
current->status = status;
|
|
|
|
current->state = ThreadState::Exited;
|
|
|
|
|
|
|
|
kernel_yield();
|
2023-03-23 22:42:24 +01:00
|
|
|
unreachable();
|
2023-01-05 22:39:56 +01:00
|
|
|
}
|