ref: ef9c5b4cc711a285947c16c7d1020f13acf7f7e7
parent: 384d4d2d6211544362d87a7e5a1392dd9c149092
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Jan 5 09:23:01 EST 2015
pool: more strict checktree() for poolcheck check that Free.next and Free.prev pointers are not nil. check that Free.left and Free.right are Poison in non-tree nodes. check that Free.left and Free.right are *not* Poison in tree nodes. change Poison to 0xffffffffcafebabe for 64bit machines.
--- a/sys/src/libc/port/pool.c
+++ b/sys/src/libc/port/pool.c
@@ -123,7 +123,7 @@
static uchar datamagic[] = { 0xFE, 0xF1, 0xF0, 0xFA };
-#define Poison (void*)0xCafeBabe
+#define Poison ((void*)-0x35014542) /* cafebabe */
#define _B2D(a) ((void*)((uchar*)a+sizeof(Bhdr)))
#define _D2B(v) ((Alloc*)((uchar*)v-sizeof(Bhdr)))
@@ -197,12 +197,12 @@
Free *q;
for(q=t->next; q!=t; q=q->next){
- assert(q->size == t->size);
- assert(q->next==nil || q->next->prev==q);
- assert(q->prev==nil || q->prev->next==q);
- // assert(q->left==nil);
- // assert(q->right==nil);
assert(q->magic==FREE_MAGIC);
+ assert(q->size==t->size);
+ assert(q->left==Poison);
+ assert(q->right==Poison);
+ assert(q->next!=nil && q->next!=Poison && q->next->prev==q);
+ assert(q->prev!=nil && q->prev!=Poison && q->prev->next==q);
}
}
@@ -211,8 +211,10 @@
{
assert(t->magic==FREE_MAGIC);
assert(a < t->size && t->size < b);
- assert(t->next==nil || t->next->prev==t);
- assert(t->prev==nil || t->prev->next==t);
+ assert(t->left!=Poison);
+ assert(t->right!=Poison);
+ assert(t->next!=nil && t->next!=Poison && t->next->prev==t);
+ assert(t->prev!=nil && t->prev!=Poison && t->prev->next==t);
checklist(t);
if(t->left)
checktree(t->left, a, t->size);