Fixes deadlocks with the monitor
authorBarret Rhoden <brho@cs.berkeley.edu>
Mon, 26 Apr 2010 01:17:43 +0000 (18:17 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Thu, 3 Nov 2011 00:35:45 +0000 (17:35 -0700)
The monitor can be called from interrupt context, and it doesn't return
if you call kfs_run.

kern/src/monitor.c

index 7985c43..221b86e 100644 (file)
@@ -467,7 +467,7 @@ static int runcmd(char *NTS real_buf, trapframe_t *tf) {
 
 void monitor(trapframe_t *tf) {
        static spinlock_t monitor_lock = SPINLOCK_INITIALIZER;
-       spin_lock(&monitor_lock);
+       spin_lock_irqsave(&monitor_lock);
 
        char *buf;
 
@@ -477,12 +477,14 @@ void monitor(trapframe_t *tf) {
        if (tf != NULL)
                print_trapframe(tf);
 
+       spin_unlock_irqsave(&monitor_lock);
        while (1) {
+               spin_lock_irqsave(&monitor_lock);
                buf = readline("K> ");
-               if (buf != NULL)
+               if (buf != NULL) {
+                       spin_unlock_irqsave(&monitor_lock);
                        if (runcmd(buf, tf) < 0)
                                break;
+               }
        }
-
-       spin_unlock(&monitor_lock);
 }