From: Matthias Kruk Date: Mon, 4 Nov 2019 02:01:45 +0000 (+0900) Subject: Change the signature of sys_posixcall() so it can modify the caller's stackframe... X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=ade6c67b86c389e571dd5c1ce0285cc6b47d7444;p=corax Change the signature of sys_posixcall() so it can modify the caller's stackframe in the case of sys_fork() --- diff --git a/kernel/arch/interrupt.c b/kernel/arch/interrupt.c index c6af750..f109e70 100644 --- a/kernel/arch/interrupt.c +++ b/kernel/arch/interrupt.c @@ -29,7 +29,7 @@ void sched_tick(void); extern int sys_cxnet(long, long, long, long, long, long, long); extern int sys_cxipc(long, long, long); #if FEATURE(POSIX) -extern int sys_posixcall(long, long, long, long, long, long, long); +extern int sys_posixcall(stack_frame_t*); #endif /* FEATURE(POSIX) */ static const char *_exc_name[] = { @@ -170,7 +170,7 @@ void _sys_handle(stack_frame_t ctx) #if FEATURE(POSIX) case SYS_VECTOR_POSIX: - ret_val = sys_posixcall(ctx.eax, ctx.ebx, ctx.ecx, ctx.edx, ctx.esi, ctx.edi, ctx.ebp); + ret_val = sys_posixcall(&ctx); break; #endif /* FEATURE(POSIX) */ diff --git a/kernel/core/posixcall.c b/kernel/core/posixcall.c index ffae24d..781c889 100644 --- a/kernel/core/posixcall.c +++ b/kernel/core/posixcall.c @@ -5,7 +5,9 @@ #include #include #include +#include #include +#include int sys_exit(int status) { @@ -22,13 +24,27 @@ int sys_exit(int status) return(ret_val); } -int sys_fork(void) +int sys_fork(stack_frame_t *stk) { + int ret_val; + task_t *ct; + /* * process_fork() always forks the calling process, so * it doesn't get told which process to fork */ - return(process_fork(0)); + + ret_val = process_fork(0); + + /* + * Update the stack frame, since the page directory + * will have changed for one of the processes + */ + ct = task_get_current(); + + stk->cr3 = ct->t_pgdir; + + return(ret_val); } int sys_vfork(void) @@ -51,31 +67,36 @@ int sys_setsid(void) return(-ENOSYS); } -int sys_posixcall(long vec, long arg1, long arg2, long arg3, long arg4, long arg5, long arg6) +int sys_posixcall(stack_frame_t *stk) { int ret_val; ret_val = -EFAULT; - switch(vec) { + switch(stk->eax) { case SYS_EXIT: - ret_val = sys_exit((int)arg1); + ret_val = sys_exit((int)stk->ebx); break; case SYS_FORK: - ret_val = sys_fork(); + /* sys_fork() will need to modify the stack frame */ + ret_val = sys_fork(stk); break; case SYS_VFORK: + /* + * sys_vfork() spawns a new process within the same address space, + * so it's not necessary for it to modify the stack frame + */ ret_val = sys_vfork(); break; case SYS_WAIT: - ret_val = sys_wait((int*)arg1); + ret_val = sys_wait((int*)stk->ebx); break; case SYS_WAITPID: - ret_val = sys_waitpid((pid_t)arg1, (int*)arg2, (int)arg3); + ret_val = sys_waitpid((pid_t)stk->ebx, (int*)stk->ecx, (int)stk->edx); break; case SYS_WAITID: