uma_dbg.c revision 95771
1/*
2 * Copyright (c) 2002, Jeffrey Roberson <jroberson@chesapeake.net>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice unmodified, this list of conditions, and the following
10 *    disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/vm/uma_dbg.c 95771 2002-04-30 07:54:25Z jeff $
27 *
28 */
29
30/*
31 * uma_dbg.c	Debugging features for UMA users
32 *
33 */
34
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/kernel.h>
39#include <sys/types.h>
40#include <sys/queue.h>
41#include <sys/lock.h>
42#include <sys/mutex.h>
43
44#include <machine/types.h>
45
46#include <vm/uma.h>
47#include <vm/uma_int.h>
48#include <vm/uma_dbg.h>
49
50static const u_int32_t uma_junk = 0xdeadc0de;
51
52/*
53 * Checks an item to make sure it hasn't been overwritten since freed.
54 *
55 * Complies with standard ctor arg/return
56 *
57 */
58void
59trash_ctor(void *mem, int size, void *arg)
60{
61	int cnt;
62	u_int32_t *p;
63
64	cnt = size / sizeof(uma_junk);
65
66	for (p = mem; cnt > 0; cnt--, p++)
67		if (*p != uma_junk)
68			panic("Memory modified after free %p(%d)\n",
69			    mem, size);
70}
71
72/*
73 * Fills an item with predictable garbage
74 *
75 * Complies with standard dtor arg/return
76 *
77 */
78void
79trash_dtor(void *mem, int size, void *arg)
80{
81	int cnt;
82	u_int32_t *p;
83
84	cnt = size / sizeof(uma_junk);
85
86	for (p = mem; cnt > 0; cnt--, p++)
87		*p = uma_junk;
88}
89
90/*
91 * Fills an item with predictable garbage
92 *
93 * Complies with standard init arg/return
94 *
95 */
96void
97trash_init(void *mem, int size)
98{
99	trash_dtor(mem, size, NULL);
100}
101
102/*
103 * Checks an item to make sure it hasn't been overwritten since it was freed.
104 *
105 * Complies with standard fini arg/return
106 *
107 */
108void
109trash_fini(void *mem, int size)
110{
111	trash_ctor(mem, size, NULL);
112}
113