Converted curenv calls into an opaque macro
[akaros.git] / kern / src / trap.c
index 924ccd3..561fddf 100644 (file)
@@ -158,8 +158,6 @@ void
 static void
 (IN_HANDLER trap_dispatch)(trapframe_t *tf)
 {
-       env_t* curenv = curenvs[lapic_get_id()];
-
        // Handle processor exceptions.
        switch(tf->tf_trapno) {
                case T_BRKPT:
@@ -174,10 +172,10 @@ static void
                        // check for userspace, for now
                        assert(tf->tf_cs != GD_KT);
                        tf->tf_regs.reg_eax =
-                               syscall(curenv, tf->tf_regs.reg_eax, tf->tf_regs.reg_edx,
+                               syscall(current, tf->tf_regs.reg_eax, 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);
-                       env_run(curenv);
+                       env_run(current); // Note the comment in syscall.c
                        break;
                default:
                        // Unexpected trap: The user process or the kernel has a bug.
@@ -186,7 +184,7 @@ static void
                                panic("Damn Damn!  Unhandled trap in the kernel!");
                        else {
                                warn("Unexpected trap from userspace");
-                               env_destroy(curenv);
+                               env_destroy(current);
                                return;
                        }
        }
@@ -198,7 +196,6 @@ void
 {
        //cprintf("Incoming TRAP frame at %p\n", tf);
 
-       env_t* curenv = curenvs[lapic_get_id()];
        if ((tf->tf_cs & ~3) != GD_UT && (tf->tf_cs & ~3) != GD_KT) {
                print_trapframe(tf);
                panic("Trapframe with invalid CS!");
@@ -208,12 +205,12 @@ void
                // Trapped from user mode.
                // TODO: this will change when an env has more than one context
                // Copy trap frame (which is currently on the stack)
-               // into 'curenv->env_tf', so that running the environment
+               // into 'current->env_tf', so that running the environment
                // will restart at the trap point.
-               assert(curenv);
-               curenv->env_tf = *tf;
+               assert(current);
+               current->env_tf = *tf;
                // The trapframe on the stack should be ignored from here on.
-               tf = &curenv->env_tf;
+               tf = &current->env_tf;
        }
 
        // Dispatch based on what type of trap occurred
@@ -223,8 +220,8 @@ void
        // so far we never get here
        assert(0);
         // Return to the current environment, which should be runnable.
-        assert(curenv && curenv->env_status == ENV_RUNNABLE);
-        env_run(curenv);
+        assert(current && current->env_status == ENV_RUNNABLE);
+        env_run(current);
 }
 
 void
@@ -286,7 +283,7 @@ page_fault_handler(trapframe_t *tf)
 
        // Call the environment's page fault upcall, if one exists.  Set up a
        // page fault stack frame on the user exception stack (below
-       // UXSTACKTOP), then branch to curenv->env_pgfault_upcall.
+       // UXSTACKTOP), then branch to current->env_pgfault_upcall.
        //
        // The page fault upcall might cause another page fault, in which case
        // we branch to the page fault upcall recursively, pushing another
@@ -306,17 +303,16 @@ page_fault_handler(trapframe_t *tf)
        //
        // Hints:
        //   user_mem_assert() and env_run() are useful here.
-       //   To change what the user environment runs, modify 'curenv->env_tf'
-       //   (the 'tf' variable points at 'curenv->env_tf').
+       //   To change what the user environment runs, modify 'current->env_tf'
+       //   (the 'tf' variable points at 'current->env_tf').
 
        // LAB 4: Your code here.
 
        // Destroy the environment that caused the fault.
-       env_t* curenv = curenvs[lapic_get_id()];
        cprintf("[%08x] user fault va %08x ip %08x from core %d\n",
-               curenv->env_id, fault_va, tf->tf_eip, lapic_get_id());
+               current->env_id, fault_va, tf->tf_eip, lapic_get_id());
        print_trapframe(tf);
-       env_destroy(curenv);
+       env_destroy(current);
 }
 
 void sysenter_init(void)