rf_debugMem.h revision 1.10 1 1.10 oster /* $NetBSD: rf_debugMem.h,v 1.10 2002/09/16 23:40:57 oster Exp $ */
2 1.1 oster /*
3 1.1 oster * Copyright (c) 1995 Carnegie-Mellon University.
4 1.1 oster * All rights reserved.
5 1.1 oster *
6 1.1 oster * Author: Daniel Stodolsky, Mark Holland
7 1.1 oster *
8 1.1 oster * Permission to use, copy, modify and distribute this software and
9 1.1 oster * its documentation is hereby granted, provided that both the copyright
10 1.1 oster * notice and this permission notice appear in all copies of the
11 1.1 oster * software, derivative works or modified versions, and any portions
12 1.1 oster * thereof, and that both notices appear in supporting documentation.
13 1.1 oster *
14 1.1 oster * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 1.1 oster * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16 1.1 oster * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 1.1 oster *
18 1.1 oster * Carnegie Mellon requests users of this software to return to
19 1.1 oster *
20 1.1 oster * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
21 1.1 oster * School of Computer Science
22 1.1 oster * Carnegie Mellon University
23 1.1 oster * Pittsburgh PA 15213-3890
24 1.1 oster *
25 1.1 oster * any improvements or extensions that they make and grant Carnegie the
26 1.1 oster * rights to redistribute these changes.
27 1.1 oster */
28 1.1 oster
29 1.1 oster /*
30 1.1 oster * rf_debugMem.h -- memory leak debugging module
31 1.1 oster *
32 1.1 oster * IMPORTANT: if you put the lock/unlock mutex stuff back in here, you
33 1.1 oster * need to take it out of the routines in debugMem.c
34 1.1 oster *
35 1.1 oster */
36 1.1 oster
37 1.1 oster #ifndef _RF__RF_DEBUGMEM_H_
38 1.1 oster #define _RF__RF_DEBUGMEM_H_
39 1.1 oster
40 1.1 oster #include "rf_alloclist.h"
41 1.1 oster
42 1.1 oster #include <sys/types.h>
43 1.1 oster #include <sys/malloc.h>
44 1.1 oster
45 1.10 oster #ifndef RF_DEBUG_MEM
46 1.10 oster #define RF_DEBUG_MEM 0
47 1.10 oster #endif
48 1.10 oster
49 1.10 oster #if RF_DEBUG_MEM
50 1.1 oster #define RF_Malloc(_p_, _size_, _cast_) \
51 1.7 oster { \
52 1.7 oster _p_ = _cast_ malloc((u_long)_size_, M_RAIDFRAME, M_WAITOK); \
53 1.8 thorpej memset((char *)_p_, 0, _size_); \
54 1.7 oster if (rf_memDebug) rf_record_malloc(_p_, _size_, __LINE__, __FILE__); \
55 1.1 oster }
56 1.10 oster #else
57 1.10 oster #define RF_Malloc(_p_, _size_, _cast_) \
58 1.10 oster { \
59 1.10 oster _p_ = _cast_ malloc((u_long)_size_, M_RAIDFRAME, M_WAITOK); \
60 1.10 oster memset((char *)_p_, 0, _size_); \
61 1.10 oster }
62 1.10 oster #endif
63 1.1 oster
64 1.1 oster #define RF_MallocAndAdd(__p_, __size_, __cast_, __alist_) \
65 1.7 oster { \
66 1.1 oster RF_Malloc(__p_, __size_, __cast_); \
67 1.1 oster if (__alist_) rf_AddToAllocList(__alist_, __p_, __size_); \
68 1.1 oster }
69 1.1 oster
70 1.1 oster #define RF_Calloc(_p_, _nel_, _elsz_, _cast_) \
71 1.7 oster { \
72 1.1 oster RF_Malloc( _p_, (_nel_) * (_elsz_), _cast_); \
73 1.6 oster }
74 1.1 oster
75 1.7 oster #define RF_CallocAndAdd(__p,__nel,__elsz,__cast,__alist) \
76 1.7 oster { \
77 1.7 oster RF_Calloc(__p, __nel, __elsz, __cast); \
78 1.7 oster if (__alist) rf_AddToAllocList(__alist, __p, (__nel)*(__elsz)); \
79 1.1 oster }
80 1.1 oster
81 1.10 oster #if RF_DEBUG_MEM
82 1.7 oster #define RF_Free(_p_, _sz_) \
83 1.7 oster { \
84 1.7 oster free((void *)(_p_), M_RAIDFRAME); \
85 1.7 oster if (rf_memDebug) rf_unrecord_malloc(_p_, (u_int32_t) (_sz_)); \
86 1.2 thorpej }
87 1.10 oster #else
88 1.10 oster #define RF_Free(_p_, _sz_) \
89 1.10 oster { \
90 1.10 oster free((void *)(_p_), M_RAIDFRAME); \
91 1.10 oster }
92 1.10 oster #endif
93 1.1 oster
94 1.4 oster void rf_record_malloc(void *p, int size, int line, char *filen);
95 1.4 oster void rf_unrecord_malloc(void *p, int sz);
96 1.4 oster void rf_print_unfreed(void);
97 1.4 oster int rf_ConfigureDebugMem(RF_ShutdownList_t ** listp);
98 1.1 oster
99 1.4 oster #endif /* !_RF__RF_DEBUGMEM_H_ */
100