From d06729d5aea6b91b675ab3e982b27c282dc47801 Mon Sep 17 00:00:00 2001 From: Michael Poole Date: Fri, 4 Feb 2005 16:36:40 +0000 Subject: [PATCH] more debugging updates src/alloc-slab.c: Switch free slab list from a stack to queue, and make sure there are SLAB_RESERVE in the queue before an old slab is dereferenced. This causes a fault when dereferencing stale pointers to the last SLAB_RESERVE full slabs. src/log.c: Make struct logEntry *last static, to make sure gcc does not optimize it away. git-archimport-id: srvx@srvx.net--2005-srvx/srvx--devo--1.3--patch-13 --- ChangeLog | 19 +++++++++++++++++++ src/alloc-slab.c | 43 +++++++++++++++++++++++++++++++++++-------- src/log.c | 2 +- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index e77de06..d65235b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,25 @@ # arch-tag: automatic-ChangeLog--srvx@srvx.net--2005-srvx/srvx--devo--1.3 # +2005-02-04 16:36:40 GMT Michael Poole patch-13 + + Summary: + more debugging updates + Revision: + srvx--devo--1.3--patch-13 + + src/alloc-slab.c: Switch free slab list from a stack to queue, and + make sure there are SLAB_RESERVE in the queue before an old slab is + dereferenced. This causes a fault when dereferencing stale pointers + to the last SLAB_RESERVE full slabs. + + src/log.c: Make struct logEntry *last static, to make sure gcc does + not optimize it away. + + modified files: + ChangeLog src/alloc-slab.c src/log.c + + 2005-01-31 22:28:59 GMT Michael Poole patch-12 Summary: diff --git a/src/alloc-slab.c b/src/alloc-slab.c index 27d38b7..dd07ecd 100644 --- a/src/alloc-slab.c +++ b/src/alloc-slab.c @@ -26,6 +26,7 @@ #endif #define SLAB_DEBUG 0 +#define SLAB_RESERVE 1024 #if SLAB_DEBUG @@ -105,7 +106,9 @@ struct slabset { */ static struct slabset little_slabs[SMALL_CUTOFF / SLAB_GRAIN]; -static struct slab *free_slabs; +static struct slab *free_slab_head; +static struct slab *free_slab_tail; +unsigned long free_slab_count; unsigned long big_alloc_count; unsigned long big_alloc_size; unsigned long slab_count; @@ -191,13 +194,15 @@ slab_alloc(struct slabset *sset) unsigned int ii, step; /* Allocate new slab. */ - if (free_slabs) { - slab = free_slabs; - free_slabs = slab->next; + if (free_slab_head) { + slab = free_slab_head; + if (!(free_slab_head = slab->next)) + free_slab_tail = NULL; } else { item = slab_map(slab_pagesize()); slab = (struct slab*)((char*)item + slab_pagesize() - sizeof(*slab)); slab->base = item; + slab_count++; } /* Populate free list. */ @@ -221,7 +226,6 @@ slab_alloc(struct slabset *sset) assert(!slab->prev || slab == slab->prev->next); sset->child = slab; sset->nslabs++; - slab_count++; /* log_module(MAIN_LOG, LOG_DEBUG, "Allocated new %u-slab %p.", sset->size, slab); */ } @@ -302,11 +306,34 @@ slab_unalloc(void *ptr, size_t size) assert(!new_next->prev || new_next == new_next->prev->next); } +#if SLAB_RESERVE + /* Make sure we have enough free slab pages. */ + while (free_slab_count < SLAB_RESERVE) { + struct slab *tslab; + item = slab_map(slab_pagesize()); + tslab = (struct slab*)((char*)item + slab_pagesize() - sizeof(*slab)); + tslab->base = item; + tslab->prev = free_slab_tail; + free_slab_tail = tslab; + if (!free_slab_head) + free_slab_head = tslab; + free_slab_count++; + slab_count++; + } + + /* Unmap old slab, so accesses to stale pointers will fault. */ + munmap(slab->base, slab_pagesize()); + slab_count--; +#else /* Link to list of free slabs. */ - slab->prev = NULL; slab->parent = NULL; - slab->next = free_slabs; - free_slabs = slab; + slab->prev = free_slab_tail; + slab->next = NULL; + free_slab_tail = slab; + if (!free_slab_head) + free_slab_head = slab; + free_slab_count++; +#endif } } diff --git a/src/log.c b/src/log.c index 8e2600a..ef64835 100644 --- a/src/log.c +++ b/src/log.c @@ -723,7 +723,7 @@ log_entry_search(struct logSearch *discrim, entry_search_func esf, void *data) unsigned int matched = 0; if (discrim->type) { - volatile struct logEntry *last; + static volatile struct logEntry *last; struct logEntry *entry; for (entry = discrim->type->log_oldest, last = NULL; -- 2.20.1