[USER] Exit and wait syscalls

This commit is contained in:
2017-02-24 15:30:45 +01:00
parent 5e4946e8e4
commit e3e661e7e5
6 changed files with 76 additions and 9 deletions

View File

@@ -3,6 +3,9 @@
#include <thread.h>
#include <scheduler.h>
#include <string.h>
#include <mem.h>
#include <debug.h>
#include <list.h>
SYSCALL_DEF(fork)
{
@@ -23,5 +26,41 @@ SYSCALL_DEF(fork)
// Return new pid
return new->pid;
}
__attribute__((noreturn)) SYSCALL_DEF(exit)
{
SYSCALL_INIT(int, status);
process_t *proc = get_current_process();
process_exit(proc, status);
schedule();
debug_error("PANIC - This line should be unreachable (%s:%d)\n", __FILE__, __LINE__);
for(;;);
}
SYSCALL_DEF(wait)
{
SYSCALL_INIT(int *, status);
process_t *proc = get_current_process();
int pid = 0;
while(!pid)
{
LIST_FOREACH(proc->children, process_t, p, siblings)
{
if(p->state == PROC_STATE_ZOMBIE)
{
pid = p->pid;
*status = p->status;
// Destroy the process
process_free(p);
break;
}
}
schedule();
}
return pid;
}

View File

@@ -59,6 +59,8 @@ void syscall_init()
SYSCALL_REGISTER(write, SYS_WRITE);
SYSCALL_REGISTER(brk, SYS_BRK);
SYSCALL_REGISTER(fork, SYS_FORK);
SYSCALL_REGISTER(exit, SYS_EXIT);
SYSCALL_REGISTER(wait, SYS_WAIT);
}
}