summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2009-02-16 23:48:18 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2009-02-16 23:48:18 +0000
commitf3c9ce4c57cf5b30ba66b26ba3dcfadbf6bb21e4 (patch)
treecd577cbe119750603e78bace98975e19af8f4683 /sys/kern
parent617538b3ebe218bf85d42593433b5aa517408904 (diff)
at tedu's request, bring back the basic single "first word" PI_MAGIC check
since it is essentially free. To turn on the checking of the rest of the allocation, use 'option POOL_DEBUG' ok tedu
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/subr_pool.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/sys/kern/subr_pool.c b/sys/kern/subr_pool.c
index db2716d5cee..0c0ba8a9350 100644
--- a/sys/kern/subr_pool.c
+++ b/sys/kern/subr_pool.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_pool.c,v 1.76 2009/02/16 22:11:41 deraadt Exp $ */
+/* $OpenBSD: subr_pool.c,v 1.77 2009/02/16 23:48:17 deraadt Exp $ */
/* $NetBSD: subr_pool.c,v 1.61 2001/09/26 07:14:56 chs Exp $ */
/*-
@@ -84,13 +84,11 @@ struct pool_item {
TAILQ_ENTRY(pool_item) pi_list;
};
-#if 0 /* Enable to debug pool corruption */
#ifdef DEADBEEF1
#define PI_MAGIC DEADBEEF1
#else
#define PI_MAGIC 0xdeafbeef
#endif
-#endif
#define POOL_NEEDS_CATCHUP(pp) \
((pp)->pr_nitems < (pp)->pr_minitems)
@@ -470,7 +468,7 @@ pool_do_get(struct pool *pp, int flags)
struct pool_item_header *ph;
void *v;
int slowdown = 0;
-#ifdef PI_MAGIC
+#ifdef POOL_DEBUG
int i, *ip;
#endif
@@ -591,11 +589,12 @@ startover:
}
#endif
-#ifdef PI_MAGIC
+#ifdef DIAGNOSTIC
if (__predict_false(pi->pi_magic != PI_MAGIC))
panic("pool_do_get(%s): free list modified: "
"page %p; item addr %p; offset 0x%x=0x%x",
pp->pr_wchan, ph->ph_page, pi, 0, pi->pi_magic);
+#ifdef POOL_DEBUG
for (ip = (int *)pi, i = sizeof(*pi) / sizeof(int);
i < pp->pr_size / sizeof(int); i++) {
if (ip[i] != PI_MAGIC) {
@@ -605,7 +604,8 @@ startover:
i * sizeof(int), ip[i]);
}
}
-#endif
+#endif /* POOL_DEBUG */
+#endif /* DIAGNOSTIC */
/*
* Remove from item list.
@@ -680,7 +680,7 @@ pool_do_put(struct pool *pp, void *v)
{
struct pool_item *pi = v;
struct pool_item_header *ph;
-#ifdef PI_MAGIC
+#ifdef POOL_DEBUG
int i, *ip;
#endif
@@ -712,12 +712,14 @@ pool_do_put(struct pool *pp, void *v)
/*
* Return to item list.
*/
-#ifdef PI_MAGIC
+#ifdef DIAGNOSTIC
pi->pi_magic = PI_MAGIC;
+#ifdef POOL_DEBUG
for (ip = (int *)pi, i = sizeof(*pi)/sizeof(int);
i < pp->pr_size / sizeof(int); i++)
ip[i] = PI_MAGIC;
-#endif
+#endif /* POOL_DEBUG */
+#endif /* DIAGNOSTIC */
TAILQ_INSERT_HEAD(&ph->ph_itemlist, pi, pi_list);
ph->ph_nmissing--;
@@ -820,7 +822,7 @@ 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;
-#ifdef PI_MAGIC
+#ifdef POOL_DEBUG
int i, *ip;
#endif
@@ -864,12 +866,15 @@ pool_prime_page(struct pool *pp, caddr_t storage, struct pool_item_header *ph)
/* Insert on page list */
TAILQ_INSERT_TAIL(&ph->ph_itemlist, pi, pi_list);
-#ifdef PI_MAGIC
+
+#ifdef DIAGNOSTIC
pi->pi_magic = PI_MAGIC;
+#ifdef POOL_DEBUG
for (ip = (int *)pi, i = sizeof(*pi)/sizeof(int);
i < pp->pr_size / sizeof(int); i++)
ip[i] = PI_MAGIC;
-#endif
+#endif /* POOL_DEBUG */
+#endif /* DIAGNOSTIC */
cp = (caddr_t)(cp + pp->pr_size);
}
@@ -1058,14 +1063,14 @@ void
pool_print_pagelist(struct pool_pagelist *pl, int (*pr)(const char *, ...))
{
struct pool_item_header *ph;
-#ifdef PI_MAGIC
+#ifdef DIAGNOSTIC
struct pool_item *pi;
#endif
LIST_FOREACH(ph, pl, ph_pagelist) {
(*pr)("\t\tpage %p, nmissing %d\n",
ph->ph_page, ph->ph_nmissing);
-#ifdef PI_MAGIC
+#ifdef DIAGNOSTIC
TAILQ_FOREACH(pi, &ph->ph_itemlist, pi_list) {
if (pi->pi_magic != PI_MAGIC) {
(*pr)("\t\t\titem %p, magic 0x%x\n",
@@ -1202,7 +1207,7 @@ pool_chk_page(struct pool *pp, const char *label, struct pool_item_header *ph)
struct pool_item *pi;
caddr_t page;
int n;
-#ifdef PI_MAGIC
+#ifdef POOL_DEBUG
int i, *ip;
#endif
@@ -1221,7 +1226,6 @@ pool_chk_page(struct pool *pp, const char *label, struct pool_item_header *ph)
pi != NULL;
pi = TAILQ_NEXT(pi,pi_list), n++) {
-#ifdef PI_MAGIC
if (pi->pi_magic != PI_MAGIC) {
if (label != NULL)
printf("%s: ", label);
@@ -1231,6 +1235,7 @@ pool_chk_page(struct pool *pp, const char *label, struct pool_item_header *ph)
pp->pr_wchan, ph->ph_page, n, pi, page,
0, pi->pi_magic);
}
+#ifdef POOL_DEBUG
for (ip = (int *)pi, i = sizeof(*pi) / sizeof(int);
i < pp->pr_size / sizeof(int); i++) {
if (ip[i] != PI_MAGIC) {