diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2013-03-31 00:03:27 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2013-03-31 00:03:27 +0000 |
commit | 4fbe05687aa45699fcb4ff7968b4a4656369ba23 (patch) | |
tree | 5c7a86e9860a2fbba1678e00e0549cbb4e9a87ab /sys | |
parent | 7ed0940c8edeffe425069e0d2ef191e8c6abf092 (diff) |
replace pool debug magic with shared mem poison code
ok deraadt
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/subr_pool.c | 58 |
1 files changed, 22 insertions, 36 deletions
diff --git a/sys/kern/subr_pool.c b/sys/kern/subr_pool.c index df0f1d40e55..085eab2540d 100644 --- a/sys/kern/subr_pool.c +++ b/sys/kern/subr_pool.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_pool.c,v 1.115 2013/03/26 16:37:45 tedu Exp $ */ +/* $OpenBSD: subr_pool.c,v 1.116 2013/03/31 00:03:26 tedu Exp $ */ /* $NetBSD: subr_pool.c,v 1.61 2001/09/26 07:14:56 chs Exp $ */ /*- @@ -526,9 +526,6 @@ pool_do_get(struct pool *pp, int flags) struct pool_item_header *ph; void *v; int slowdown = 0; -#if defined(DIAGNOSTIC) && defined(POOL_DEBUG) - int i, *ip; -#endif #ifdef MALLOC_DEBUG if (pp->pr_roflags & PR_DEBUG) { @@ -647,14 +644,15 @@ startover: pp->pr_wchan, ph->ph_page, pi, 0, pi->pi_magic); #ifdef POOL_DEBUG if (pool_debug && ph->ph_magic) { - for (ip = (int *)pi, i = sizeof(*pi) / sizeof(int); - i < pp->pr_size / sizeof(int); i++) { - if (ip[i] != ph->ph_magic) { - panic("pool_do_get(%s): free list modified: " - "page %p; item addr %p; offset 0x%zx=0x%x", - pp->pr_wchan, ph->ph_page, pi, - i * sizeof(int), ip[i]); - } + size_t pidx; + int pval; + if (poison_check(pi + 1, pp->pr_size - sizeof(*pi), + &pidx, &pval)) { + int *ip = (int *)(pi + 1); + panic("pool_do_get(%s): free list modified: " + "page %p; item addr %p; offset 0x%zx=0x%x", + pp->pr_wchan, ph->ph_page, pi, + pidx * sizeof(int), ip[pidx]); } } #endif /* POOL_DEBUG */ @@ -745,9 +743,6 @@ pool_do_put(struct pool *pp, void *v) { struct pool_item *pi = v; struct pool_item_header *ph; -#if defined(DIAGNOSTIC) && defined(POOL_DEBUG) - int i, *ip; -#endif if (v == NULL) panic("pool_put of NULL"); @@ -781,9 +776,7 @@ pool_do_put(struct pool *pp, void *v) pi->pi_magic = PI_MAGIC; #ifdef POOL_DEBUG if (ph->ph_magic) { - for (ip = (int *)pi, i = sizeof(*pi)/sizeof(int); - i < pp->pr_size / sizeof(int); i++) - ip[i] = ph->ph_magic; + poison_mem(pi + 1, pp->pr_size - sizeof(*pi)); } #endif /* POOL_DEBUG */ #endif /* DIAGNOSTIC */ @@ -886,9 +879,6 @@ pool_prime_page(struct pool *pp, caddr_t storage, struct pool_item_header *ph) unsigned int align = pp->pr_align; unsigned int ioff = pp->pr_itemoffset; int n; -#if defined(DIAGNOSTIC) && defined(POOL_DEBUG) - int i, *ip; -#endif /* * Insert page header. @@ -935,9 +925,7 @@ pool_prime_page(struct pool *pp, caddr_t storage, struct pool_item_header *ph) pi->pi_magic = PI_MAGIC; #ifdef POOL_DEBUG if (ph->ph_magic) { - for (ip = (int *)pi, i = sizeof(*pi)/sizeof(int); - i < pp->pr_size / sizeof(int); i++) - ip[i] = ph->ph_magic; + poison_mem(pi + 1, pp->pr_size - sizeof(*pi)); } #endif /* POOL_DEBUG */ #endif /* DIAGNOSTIC */ @@ -1293,9 +1281,6 @@ pool_chk_page(struct pool *pp, struct pool_item_header *ph, int expected) struct pool_item *pi; caddr_t page; int n; -#if defined(DIAGNOSTIC) && defined(POOL_DEBUG) - int i, *ip; -#endif const char *label = pp->pr_wchan; page = (caddr_t)((u_long)ph & pp->pr_alloc->pa_pagemask); @@ -1323,15 +1308,16 @@ pool_chk_page(struct pool *pp, struct pool_item_header *ph, int expected) } #ifdef POOL_DEBUG if (pool_debug && ph->ph_magic) { - for (ip = (int *)pi, i = sizeof(*pi) / sizeof(int); - i < pp->pr_size / sizeof(int); i++) { - if (ip[i] != ph->ph_magic) { - printf("pool(%s): free list modified: " - "page %p; item ordinal %d; addr %p " - "(p %p); offset 0x%zx=0x%x\n", - pp->pr_wchan, ph->ph_page, n, pi, - page, i * sizeof(int), ip[i]); - } + size_t pidx; + int pval; + if (poison_check(pi + 1, pp->pr_size - sizeof(*pi), + &pidx, &pval)) { + int *ip = (int *)(pi + 1); + printf("pool(%s): free list modified: " + "page %p; item ordinal %d; addr %p " + "(p %p); offset 0x%zx=0x%x\n", + pp->pr_wchan, ph->ph_page, n, pi, + page, pidx * sizeof(int), ip[pidx]); } } |