2022-10-18 19:30:52 +00:00
|
|
|
#include "errno.h"
|
|
|
|
#include "memory/VMM.h"
|
2022-09-29 17:17:43 +00:00
|
|
|
#include "thread/Scheduler.h"
|
|
|
|
|
2022-10-08 15:56:40 +00:00
|
|
|
void sys_exit(Context* context, int status)
|
2022-09-29 17:17:43 +00:00
|
|
|
{
|
2022-10-08 15:56:40 +00:00
|
|
|
Scheduler::task_exit(context, status);
|
2022-09-29 17:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void sys_yield(Context* context)
|
|
|
|
{
|
|
|
|
context->rax = 0;
|
|
|
|
Scheduler::task_yield(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sys_sleep(Context* context, uint64_t ms)
|
|
|
|
{
|
|
|
|
context->rax = 0;
|
|
|
|
Task* task = Scheduler::current_task();
|
|
|
|
task->task_sleep = ms;
|
|
|
|
task->state = task->Sleeping;
|
|
|
|
Scheduler::task_yield(context);
|
2022-10-18 19:30:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void sys_waitpid(Context* context, long pid, int* wstatus,
|
|
|
|
int) // FIXME: Use the value in options and block if WNOHANG has not been specified.
|
|
|
|
{
|
|
|
|
Task* child = Scheduler::find_by_pid(pid); // FIXME: Wait for any child process if PID is -1.
|
|
|
|
if (!child)
|
|
|
|
{
|
|
|
|
context->rax = -ESRCH;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (child->state != child->Dying) // FIXME: This should block if WNOHANG has not been specified.
|
|
|
|
{
|
|
|
|
context->rax = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint64_t phys = VMM::get_physical((uint64_t)wstatus);
|
|
|
|
if (phys != (uint64_t)-1) { *(int*)phys = (int)(child->exit_status & 0xff); }
|
|
|
|
child->state = child->Exited;
|
|
|
|
context->rax = (long)child->id;
|
2022-09-29 17:17:43 +00:00
|
|
|
}
|