proc_destroy() refcnting issues dealt with
[akaros.git] / kern / arch / i686 / trap.c
index 4b03b4b..2b6aaca 100644 (file)
@@ -238,13 +238,9 @@ trap_dispatch(trapframe_t *tf)
                case T_SYSCALL:
                        // check for userspace, for now
                        assert(tf->tf_cs != GD_KT);
-                       struct per_cpu_info* coreinfo = &per_cpu_info[core_id()];
-                       coreinfo->tf_retval_loc = &(tf->tf_regs.reg_eax);
                        /* Set up and run the async calls */
                        prep_syscalls(current, (struct syscall*)tf->tf_regs.reg_eax,
                                      tf->tf_regs.reg_edx);
-                       run_local_syscall();
-                       warn("No syscalls on a trap!");
                        break;
                default:
                        // Unexpected trap: The user process or the kernel has a bug.
@@ -253,8 +249,9 @@ trap_dispatch(trapframe_t *tf)
                                panic("Damn Damn!  Unhandled trap in the kernel!");
                        else {
                                warn("Unexpected trap from userspace");
-                               kref_get(&current->kref, 1);
+                               proc_incref(current, 1);
                                proc_destroy(current);
+                               assert(0);
                                return;
                        }
        }
@@ -302,7 +299,7 @@ void trap(struct trapframe *tf)
         * to still be okay (might not be after blocking) */
        if (in_kernel(tf))
                return; /* TODO: think about this, might want a helper instead. */
-       proc_restartcore(current, tf);
+       proc_restartcore();
        assert(0);
 }
 
@@ -334,7 +331,8 @@ void irq_handler(struct trapframe *tf)
        // For now, only 235-255 are available
        assert(tf->tf_trapno >= 32); // slows us down, but we should never have this
 
-#ifndef __CONFIG_DISABLE_MPTABLES__
+#ifdef __CONFIG_ENABLE_MPTABLES__
+       /* TODO: this should be for any IOAPIC EOI, not just MPTABLES */
        lapic_send_eoi();
 #else
        //Old PIC relatd code. Should be gone for good, but leaving it just incase.
@@ -348,7 +346,7 @@ void irq_handler(struct trapframe *tf)
         * to still be okay (might not be after blocking) */
        if (in_kernel(tf))
                return; /* TODO: think about this, might want a helper instead. */
-       proc_restartcore(current, tf);
+       proc_restartcore();
        assert(0);
 }
 
@@ -377,8 +375,9 @@ void page_fault_handler(struct trapframe *tf)
                       current->pid, prot & PROT_READ ? "READ" : "WRITE", fault_va,
                       tf->tf_eip, core_id(), err);
                print_trapframe(tf);
-               kref_get(&current->kref, 1);
+               proc_incref(current, 1);
                proc_destroy(current);
+               assert(0);
        }
 }
 
@@ -399,17 +398,10 @@ void sysenter_callwrapper(struct trapframe *tf)
 
        if (in_kernel(tf))
                panic("sysenter from a kernel TF!!");
-       pcpui->tf_retval_loc = &(tf->tf_regs.reg_eax);
        /* Set up and run the async calls */
        prep_syscalls(current, (struct syscall*)tf->tf_regs.reg_eax,
                      tf->tf_regs.reg_esi);
-       run_local_syscall();            /* alternatively, we can call smp_idle() */
-       warn("No syscalls on a sysenter!");
-       /* careful here - we need to make sure that this current is the right
-        * process, which could be weird if the syscall blocked.  it would need to
-        * restore the proper value in current before returning to here.
-        * likewise, tf could be pointing to random gibberish. */
-       proc_restartcore(current, tf);
+       proc_restartcore();
 }
 
 struct kmem_cache *kernel_msg_cache;
@@ -445,9 +437,11 @@ uint32_t send_kernel_message(uint32_t dst, amr_t pc, TV(a0t) arg0, TV(a1t) arg1,
                default:
                        panic("Unknown type of kernel message!");
        }
-       // since we touched memory the other core will touch (the lock), we don't
-       // need an wmb_f()
-       send_ipi(get_hw_coreid(dst), I_KERNEL_MSG);
+       /* since we touched memory the other core will touch (the lock), we don't
+        * need an wmb_f() */
+       /* if we're sending a routine message locally, we don't want/need an IPI */
+       if ((dst != k_msg->srcid) || (type == KMSG_IMMEDIATE))
+               send_ipi(get_hw_coreid(dst), I_KERNEL_MSG);
        return 0;
 }
 
@@ -508,6 +502,7 @@ void __kernel_message(struct trapframe *tf)
                                send_self_ipi(I_KERNEL_MSG);
                        /* Execute the kernel message */
                        assert(msg_cp.pc);
+                       /* TODO: when batching syscalls, this should be reread from cur_tf*/
                        msg_cp.pc(tf, msg_cp.srcid, msg_cp.arg0, msg_cp.arg1, msg_cp.arg2);
                }
        }