diff options
Diffstat (limited to 'src/user/lib')
-rw-r--r-- | src/user/lib/thread.S | 8 | ||||
-rw-r--r-- | src/user/lib/thread.c | 11 | ||||
-rw-r--r-- | src/user/lib/thread.h | 4 |
3 files changed, 23 insertions, 0 deletions
diff --git a/src/user/lib/thread.S b/src/user/lib/thread.S new file mode 100644 index 0000000..3cd3500 --- /dev/null +++ b/src/user/lib/thread.S @@ -0,0 +1,8 @@ +.section .text +.global chstack +.type chstack, @function +// _Noreturn void chstack(void *arg, void (*fn)(void*), void *esp); +chstack: + mov %rdx, %rsp + call *%rsi + jmp 0 // "exit" diff --git a/src/user/lib/thread.c b/src/user/lib/thread.c new file mode 100644 index 0000000..25d98a9 --- /dev/null +++ b/src/user/lib/thread.c @@ -0,0 +1,11 @@ +#include <camellia/flags.h> +#include <camellia/syscalls.h> +#include <stdlib.h> +#include <user/lib/thread.h> + +void thread_create(int flags, void (*fn)(void*), void *arg) { + if (!_syscall_fork(flags | FORK_SHAREMEM, NULL)) { + void *stack = malloc(4096); + chstack(arg, fn, stack + 4096); + } +} diff --git a/src/user/lib/thread.h b/src/user/lib/thread.h new file mode 100644 index 0000000..0d7376a --- /dev/null +++ b/src/user/lib/thread.h @@ -0,0 +1,4 @@ +#pragma once + +void thread_create(int flags, void (*fn)(void*), void *arg); +_Noreturn void chstack(void *arg, void (*fn)(void*), void *esp); |