From 5be0039ce9e22f140a29e167526c64c723c5be3c Mon Sep 17 00:00:00 2001
From: rtm <rtm>
Date: Thu, 10 Aug 2006 22:08:14 +0000
Subject: interrupts could be recursive since lapic_eoi() called before rti so
 fast interrupts overflow the kernel stack fix: cli() before lapic_eoi()

---
 spinlock.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

(limited to 'spinlock.c')

diff --git a/spinlock.c b/spinlock.c
index b1b4079..663fe33 100644
--- a/spinlock.c
+++ b/spinlock.c
@@ -10,8 +10,19 @@
 // because cprintf uses them itself.
 //#define cprintf dont_use_cprintf
 
+#define LOCKMAGIC 0x6673ffea
+
 extern int use_console_lock;
 
+void
+initlock(struct spinlock *lock, char *name)
+{
+  lock->magic = LOCKMAGIC;
+  lock->name = name;
+  lock->locked = 0;
+  lock->cpu = 0xffffffff;
+}
+
 void
 getcallerpcs(void *v, uint pcs[])
 {
@@ -27,6 +38,8 @@ getcallerpcs(void *v, uint pcs[])
 void
 acquire(struct spinlock * lock)
 {
+  if(lock->magic != LOCKMAGIC)
+    panic("weird lock magic");
   if(holding(lock))
     panic("acquire");
 
@@ -45,6 +58,9 @@ acquire(struct spinlock * lock)
 void
 release(struct spinlock * lock)
 {
+  if(lock->magic != LOCKMAGIC)
+    panic("weird lock magic");
+
 	if(!holding(lock))
 		panic("release");
 
@@ -55,8 +71,6 @@ release(struct spinlock * lock)
 	lock->locked = 0;
 	if(--cpus[cpu()].nlock == 0)
 		sti();
-        // xxx we may have just turned interrupts on during
-        // an interrupt, is that ok?
 }
 
 int
-- 
cgit v1.2.3