]> git.corax.cc Git - corax/commitdiff
Change the signature of sys_posixcall() so it can modify the caller's stackframe...
authorMatthias Kruk <m@m10k.eu>
Mon, 4 Nov 2019 02:01:45 +0000 (11:01 +0900)
committerMatthias Kruk <m@m10k.eu>
Mon, 4 Nov 2019 02:01:45 +0000 (11:01 +0900)
kernel/arch/interrupt.c
kernel/core/posixcall.c

index c6af750fdfe5ea8ccd03f55434fbeedcb4725bf4..f109e709783d56fb6344c39b18d2ab93606f8d25 100644 (file)
@@ -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) */
 
index ffae24d23013184dc298f3fba8a4731d60c25174..781c8896e4c73ccdabf287ee9dc59ceed9ed508b 100644 (file)
@@ -5,7 +5,9 @@
 #include <corax/errno.h>
 #include <corax/syscall.h>
 #include <corax/types.h>
+#include <arch.h>
 #include <process.h>
+#include <debug.h>
 
 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: