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