Browse Source

Plan 9 from Bell Labs 2008-09-18

David du Colombier 15 years ago
parent
commit
7a5cd16ee7
4 changed files with 22 additions and 14 deletions
  1. 1 1
      dist/replica/_plan9.db
  2. 1 1
      dist/replica/plan9.db
  3. 1 0
      dist/replica/plan9.log
  4. 19 12
      sys/src/9/port/allocb.c

+ 1 - 1
dist/replica/_plan9.db

@@ -8236,7 +8236,7 @@ sys/src/9/pc/wavelan.h - 664 sys sys 1107448246 6169
 sys/src/9/port - 20000000775 sys sys 1218341605 0
 sys/src/9/port/alarm.c - 664 sys sys 1134042902 1425
 sys/src/9/port/alloc.c - 664 sys sys 1138459977 5704
-sys/src/9/port/allocb.c - 664 sys sys 1123676437 3340
+sys/src/9/port/allocb.c - 664 sys sys 1221660911 3451
 sys/src/9/port/aoe.h - 664 sys sys 1196312063 1000
 sys/src/9/port/auth.c - 664 sys sys 1123647282 2392
 sys/src/9/port/cache.c - 664 sys sys 1218341675 9283

+ 1 - 1
dist/replica/plan9.db

@@ -8236,7 +8236,7 @@ sys/src/9/pc/wavelan.h - 664 sys sys 1107448246 6169
 sys/src/9/port - 20000000775 sys sys 1218341605 0
 sys/src/9/port/alarm.c - 664 sys sys 1134042902 1425
 sys/src/9/port/alloc.c - 664 sys sys 1138459977 5704
-sys/src/9/port/allocb.c - 664 sys sys 1123676437 3340
+sys/src/9/port/allocb.c - 664 sys sys 1221660911 3451
 sys/src/9/port/aoe.h - 664 sys sys 1196312063 1000
 sys/src/9/port/auth.c - 664 sys sys 1123647282 2392
 sys/src/9/port/cache.c - 664 sys sys 1218341675 9283

+ 1 - 0
dist/replica/plan9.log

@@ -36113,3 +36113,4 @@
 1221103804 0 c 386/bin/upas/fs - 775 sys sys 1221103144 333376
 1221364804 0 c sys/src/cmd/fax/receiverc - 775 sys sys 1221364152 1101
 1221364804 1 d sys/src/cmd/fax/receive - 775 sys sys 944960990 0
+1221661805 0 c sys/src/9/port/allocb.c - 664 sys sys 1221660911 3451

+ 19 - 12
sys/src/9/port/allocb.c

@@ -30,6 +30,8 @@ _allocb(int size)
 	b->list = nil;
 	b->free = 0;
 	b->flag = 0;
+	b->ref = 0;
+	_xinc(&b->ref);
 
 	/* align start of data portion by rounding up */
 	addr = (ulong)b;
@@ -61,11 +63,11 @@ allocb(int size)
 	 * Can still error out of here, though.
 	 */
 	if(up == nil)
-		panic("allocb without up: %luX\n", getcallerpc(&size));
+		panic("allocb without up: %#p", getcallerpc(&size));
 	if((b = _allocb(size)) == nil){
 		xsummary();
 		mallocsummary();
-		panic("allocb: no memory for %d bytes\n", size);
+		panic("allocb: no memory for %d bytes", size);
 	}
 	setmalloctag(b, getcallerpc(&size));
 
@@ -115,10 +117,16 @@ void
 freeb(Block *b)
 {
 	void *dead = (void*)Bdead;
+	long ref;
 
-	if(b == nil)
+	if(b == nil || (ref = _xdec(&b->ref)) > 0)
 		return;
 
+	if(ref < 0){
+		dumpstack();
+		panic("ref %ld callerpc %#p", ref, getcallerpc(&b));
+	}
+
 	/*
 	 * drivers which perform non cache coherent DMA manage their own buffer
 	 * pool of uncached buffers and provide their own free routine.
@@ -152,23 +160,22 @@ checkb(Block *b, char *msg)
 		panic("checkb b %s %lux", msg, b);
 	if(b->base == dead || b->lim == dead || b->next == dead
 	  || b->rp == dead || b->wp == dead){
-		print("checkb: base 0x%8.8luX lim 0x%8.8luX next 0x%8.8luX\n",
+		print("checkb: base %#p lim %#p next %#p\n",
 			b->base, b->lim, b->next);
-		print("checkb: rp 0x%8.8luX wp 0x%8.8luX\n", b->rp, b->wp);
-		panic("checkb dead: %s\n", msg);
+		print("checkb: rp %#p wp %#p\n", b->rp, b->wp);
+		panic("checkb dead: %s", msg);
 	}
 
 	if(b->base > b->lim)
-		panic("checkb 0 %s %lux %lux", msg, b->base, b->lim);
+		panic("checkb 0 %s %#p %#p", msg, b->base, b->lim);
 	if(b->rp < b->base)
-		panic("checkb 1 %s %lux %lux", msg, b->base, b->rp);
+		panic("checkb 1 %s %#p %#p", msg, b->base, b->rp);
 	if(b->wp < b->base)
-		panic("checkb 2 %s %lux %lux", msg, b->base, b->wp);
+		panic("checkb 2 %s %#p %#p", msg, b->base, b->wp);
 	if(b->rp > b->lim)
-		panic("checkb 3 %s %lux %lux", msg, b->rp, b->lim);
+		panic("checkb 3 %s %#p %#p", msg, b->rp, b->lim);
 	if(b->wp > b->lim)
-		panic("checkb 4 %s %lux %lux", msg, b->wp, b->lim);
-
+		panic("checkb 4 %s %#p %#p", msg, b->wp, b->lim);
 }
 
 void