Set the default syscall return value to 0
authorKevin Klues <klueska@ros-dev.(none)>
Wed, 24 Mar 2010 07:22:03 +0000 (00:22 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Thu, 3 Nov 2011 00:35:37 +0000 (17:35 -0700)
In case syscall() does not return, we want to indicate
success by default.  (This applies to e.g. yield and
the child process after fork.)

kern/arch/i686/trap.c

index 7cbed53..5a6a2bd 100644 (file)
@@ -184,11 +184,17 @@ trap_dispatch(trapframe_t *tf)
                case T_SYSCALL:
                        // check for userspace, for now
                        assert(tf->tf_cs != GD_KT);
+
+                       // default return value is 0 if syscall doesn't return
+                       // e.g. for fork or yield
+                       intreg_t syscallno = tf->tf_regs.reg_eax;
+                       tf->tf_regs.reg_eax = 0;
+                       set_errno(tf,0);
+
                        // syscall code wants an edible reference for current
                        proc_incref(current, 1);
-print_trapframe(tf);
                        tf->tf_regs.reg_eax =
-                               syscall(current, tf->tf_regs.reg_eax, tf->tf_regs.reg_edx,
+                               syscall(current, syscallno, tf->tf_regs.reg_edx,
                                        tf->tf_regs.reg_ecx, tf->tf_regs.reg_ebx,
                                        tf->tf_regs.reg_edi, tf->tf_regs.reg_esi);
                        proc_decref(current, 1);
@@ -359,10 +365,16 @@ void sysenter_callwrapper(struct Trapframe *tf)
        // save a per-core reference to the tf
        set_current_tf(tf);
 
+       // default return value is 0 if syscall doesn't return
+       // e.g. for fork or yield
+       intreg_t syscallno = tf->tf_regs.reg_eax;
+       tf->tf_regs.reg_eax = 0;
+       set_errno(tf,0);
+
        // syscall code wants an edible reference for current
        proc_incref(current, 1);
        tf->tf_regs.reg_eax = (intreg_t) syscall(current,
-                                                tf->tf_regs.reg_eax,
+                                                syscallno,
                                                 tf->tf_regs.reg_edx,
                                                 tf->tf_regs.reg_ecx,
                                                 tf->tf_regs.reg_ebx,