[USER] Exit and wait syscalls
This commit is contained in:
@@ -43,3 +43,5 @@ typedef long (*syscall_handler_t)(long num, long, long, long, long, long, long);
|
||||
SYSCALL_DECL(write);
|
||||
SYSCALL_DECL(brk);
|
||||
SYSCALL_DECL(fork);
|
||||
SYSCALL_DECL(exit);
|
||||
SYSCALL_DECL(wait);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user