summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_pool.c
diff options
context:
space:
mode:
authordlg <dlg@openbsd.org>2008-12-23 06:53:12 +0000
committerdlg <dlg@openbsd.org>2008-12-23 06:53:12 +0000
commit0aab2d45849be8f755798018a1bbe06ef6b974f2 (patch)
tree79040ef18bbf86203eaeb71fe2b5915e54292c32 /sys/kern/subr_pool.c
parentrecord the offset into each pool page that item allocations actually begin (diff)
downloadwireguard-openbsd-0aab2d45849be8f755798018a1bbe06ef6b974f2.tar.xz
wireguard-openbsd-0aab2d45849be8f755798018a1bbe06ef6b974f2.zip
add pool_walk as debug code.
this can be used to walk over all the items allocated with a pool and have them examined by a function the caller provides. with help from and ok tedu@
Diffstat (limited to 'sys/kern/subr_pool.c')
-rw-r--r--sys/kern/subr_pool.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/sys/kern/subr_pool.c b/sys/kern/subr_pool.c
index 6abb44bf617..a5491e7022c 100644
--- a/sys/kern/subr_pool.c
+++ b/sys/kern/subr_pool.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_pool.c,v 1.73 2008/12/23 06:50:48 dlg Exp $ */
+/* $OpenBSD: subr_pool.c,v 1.74 2008/12/23 06:53:12 dlg Exp $ */
/* $NetBSD: subr_pool.c,v 1.61 2001/09/26 07:14:56 chs Exp $ */
/*-
@@ -1270,6 +1270,43 @@ pool_chk(struct pool *pp, const char *label)
return (r);
}
+
+void
+pool_walk(struct pool *pp, void (*func)(void *))
+{
+ struct pool_item_header *ph;
+ struct pool_item *pi;
+ caddr_t cp;
+ int n;
+
+ LIST_FOREACH(ph, &pp->pr_emptypages, ph_pagelist) {
+ cp = ph->ph_colored;
+ n = ph->ph_nmissing;
+
+ while (n--) {
+ func(cp);
+ cp += pp->pr_size;
+ }
+ }
+
+ LIST_FOREACH(ph, &pp->pr_partpages, ph_pagelist) {
+ cp = ph->ph_colored;
+ n = ph->ph_nmissing;
+
+ do {
+ TAILQ_FOREACH(pi, &ph->ph_itemlist, pi_list) {
+ if (cp == (caddr_t)pi)
+ break;
+ }
+ if (cp != (caddr_t)pi) {
+ func(cp);
+ n--;
+ }
+
+ cp += pp->pr_size;
+ } while (n > 0);
+ }
+}
#endif
/*