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