[USER] Fork syscall

This commit is contained in:
thomas committed 2017-03-27 23:09:09 +02:00
1 parent a2cba95346
commit 5e4946e8e4
6 files changed
+63 -10

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
#include <syscall.h>
#include <process.h>
#include <thread.h>
#include <scheduler.h>
#include <string.h>
SYSCALL_DEF(fork)
{
SYSCALL_INIT();
// Copy process and memory space
process_t *p = get_current_process();
process_t *new = process_spawn(p);
// Copy thread
thread_t *th = new_thread(0, 1);
memcpy(&th->r, &get_current_thread()->r, sizeof(registers_t));
// Make new thread return 0
th->r.rax = 0;
process_attach(new, th);
scheduler_insert(th);
// Return new pid
return new->pid;
}
+1
View File
@@ -58,6 +58,7 @@ void syscall_init()
SYSCALL_REGISTER(debug, SYS_DEBUG);
SYSCALL_REGISTER(write, SYS_WRITE);
SYSCALL_REGISTER(brk, SYS_BRK);
SYSCALL_REGISTER(fork, SYS_FORK);
}
}