From 2a16c1f6f9118e7127d532421ae19b959b3f1d87 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sat, 20 Aug 2022 00:00:52 +0200 Subject: user/libc: don't access the old stack from the new thread at all --- src/user/lib/thread.S | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) (limited to 'src/user/lib/thread.S') diff --git a/src/user/lib/thread.S b/src/user/lib/thread.S index 3cd3500..1a27c30 100644 --- a/src/user/lib/thread.S +++ b/src/user/lib/thread.S @@ -1,8 +1,40 @@ +#define ASM_FILE 1 +#include +#include + .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" +.global thread_creates +.type thread_creates, @function +// void thread_creates(int flags, void (*fn)(void*), void *arg, void *stack); +thread_creates: + push %r12 + push %r13 + push %r14 + + /* save fn, arg, stack */ + mov %rsi, %r12 + mov %rdx, %r13 + mov %rcx, %r14 + + mov %rdi, %rsi + or $(FORK_SHAREMEM | FORK_SHAREHANDLE), %rsi + mov $_SYSCALL_FORK, %rdi + xor %rdx, %rdx + syscall + + test %rax, %rax + jz 1f + /* in parent, return normally */ + pop %r14 + pop %r13 + pop %r12 + ret +1: /* in child */ + mov %r14, %rsp + mov %r13, %rdi + call *%r12 + + mov $_SYSCALL_EXIT, %rdi + xor %rsi, %rsi + syscall + hlt /* if all else fails... */ -- cgit v1.2.3