Home | History | Annotate | Line # | Download | only in raidframe
rf_debugMem.h revision 1.13.56.1
      1  1.13.56.1  christos /*	$NetBSD: rf_debugMem.h,v 1.13.56.1 2019/06/10 22:07:31 christos 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.13.56.1  christos int     rf_ConfigureDebugMem(RF_ShutdownList_t **);
     46       1.10     oster 
     47  1.13.56.1  christos #ifndef RF_DEBUG_MEM
     48  1.13.56.1  christos # define RF_DEBUG_MEM	0
     49  1.13.56.1  christos # define RF_Malloc(s)	malloc(s, M_RAIDFRAME, M_WAITOK | M_ZERO)
     50  1.13.56.1  christos # define RF_Free(p, s)	free(p, M_RAIDFRAME)
     51  1.13.56.1  christos # define RF_MallocAndAdd(s, l) _RF_MallocAndAdd(s, l)
     52       1.10     oster #else
     53  1.13.56.1  christos extern long rf_memDebug;
     54  1.13.56.1  christos 
     55  1.13.56.1  christos void    rf_record_malloc(void *, size_t, const char *, uint32_t);
     56  1.13.56.1  christos void    rf_unrecord_malloc(void *, size_t);
     57  1.13.56.1  christos void    rf_print_unfreed(void);
     58        1.1     oster 
     59  1.13.56.1  christos # define RF_Malloc(s) _RF_Malloc(s, __FILE__, __LINE__)
     60  1.13.56.1  christos # define RF_MallocAndAdd(s, l) \
     61  1.13.56.1  christos     _RF_MallocAndAdd(s, l, __FILE__, __LINE__)
     62  1.13.56.1  christos 
     63  1.13.56.1  christos static __inline void *
     64  1.13.56.1  christos _RF_Malloc(size_t size, const char *file, uint32_t line)
     65  1.13.56.1  christos {
     66  1.13.56.1  christos 	void *p = malloc(size, M_RAIDFRAME, M_WAITOK | M_ZERO);
     67  1.13.56.1  christos 	if (rf_memDebug) rf_record_malloc(p, size, file, line);
     68  1.13.56.1  christos 	return p;
     69  1.13.56.1  christos }
     70  1.13.56.1  christos 
     71  1.13.56.1  christos static __inline void
     72  1.13.56.1  christos RF_Free(void *p, size_t size)
     73  1.13.56.1  christos {
     74  1.13.56.1  christos 	free(p, M_RAIDFRAME);
     75  1.13.56.1  christos 	if (rf_memDebug) rf_unrecord_malloc(p, size);
     76        1.1     oster   }
     77  1.13.56.1  christos #endif
     78        1.1     oster 
     79  1.13.56.1  christos static __inline void *
     80  1.13.56.1  christos _RF_MallocAndAdd(size_t size, RF_AllocListElem_t *l
     81       1.10     oster #if RF_DEBUG_MEM
     82  1.13.56.1  christos     , const char *file, uint32_t line
     83  1.13.56.1  christos #endif
     84  1.13.56.1  christos )
     85  1.13.56.1  christos {
     86  1.13.56.1  christos 	void *p = malloc(size, M_RAIDFRAME, M_WAITOK | M_ZERO);
     87  1.13.56.1  christos #if RF_DEBUG_MEM
     88  1.13.56.1  christos 	if (rf_memDebug) rf_record_malloc(p, size, file, line);
     89       1.10     oster #endif
     90  1.13.56.1  christos 	if (l) rf_AddToAllocList(l, p, size);
     91  1.13.56.1  christos 	return p;
     92  1.13.56.1  christos }
     93        1.1     oster 
     94        1.1     oster 
     95        1.4     oster #endif				/* !_RF__RF_DEBUGMEM_H_ */
     96