Use the common memory poisoning functions to eliminate some funky
loops in pool. There are some more changes to come, but this is a
almost strictly mechanical change.

Index: subr_pool.c
===================================================================
RCS file: /cvs/src/sys/kern/subr_pool.c,v
retrieving revision 1.115
diff -u -p -r1.115 subr_pool.c
--- subr_pool.c 26 Mar 2013 16:37:45 -0000      1.115
+++ subr_pool.c 29 Mar 2013 17:50:43 -0000
@@ -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
        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
                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 po
        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 po
                }
 #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]);
                        }
                }
 


Reply via email to