2 * Copyright (c) 2000-2001, 2006 Sendmail, Inc. and its suppliers.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
9 * $Id: heap.h,v 1.23 2006/08/15 00:53:46 ca Exp $
12 #pragma ident "%Z%%M% %I% %E% SMI"
15 ** Sendmail debugging memory allocation package.
16 ** See libsm/heap.html for documentation.
24 # include <sm/debug.h>
27 /* change default to 0 for production? */
28 # ifndef SM_HEAP_CHECK
29 # define SM_HEAP_CHECK 1
30 # endif /* ! SM_HEAP_CHECK */
33 # define sm_malloc_x(sz) sm_malloc_tagged_x(sz, __FILE__, __LINE__, SmHeapGroup)
34 # define sm_malloc(size) sm_malloc_tagged(size, __FILE__, __LINE__, SmHeapGroup)
35 # define sm_free(ptr) sm_free_tagged(ptr, __FILE__, __LINE__)
37 extern void *sm_malloc_tagged
__P((size_t, char *, int, int));
38 extern void *sm_malloc_tagged_x
__P((size_t, char *, int, int));
39 extern void sm_free_tagged
__P((void *, char *, int));
40 extern void *sm_realloc_x
__P((void *, size_t));
41 extern bool sm_heap_register
__P((void *, size_t, char *, int, int));
42 extern void sm_heap_checkptr_tagged
__P((void *, char *, int));
43 extern void sm_heap_report
__P((SM_FILE_T
*, int));
45 # else /* SM_HEAP_CHECK */
46 # define sm_malloc_tagged(size, file, line, grp) sm_malloc(size)
47 # define sm_malloc_tagged_x(size, file, line, grp) sm_malloc_x(size)
48 # define sm_free_tagged(ptr, file, line) sm_free(ptr)
49 # define sm_heap_register(ptr, size, file, line, grp) (true)
50 # define sm_heap_checkptr_tagged(ptr, tag, num) ((void)0)
51 # define sm_heap_report(file, verbose) ((void)0)
53 extern void *sm_malloc
__P((size_t));
54 extern void *sm_malloc_x
__P((size_t));
55 extern void *sm_realloc_x
__P((void *, size_t));
56 extern void sm_free
__P((void *));
57 # endif /* SM_HEAP_CHECK */
59 extern void *sm_realloc
__P((void *, size_t));
61 # define sm_heap_checkptr(ptr) sm_heap_checkptr_tagged(ptr, __FILE__, __LINE__)
65 ** sm_f[mc]alloc are plug in replacements for malloc and calloc
66 ** which can be used in a context requiring a function pointer,
67 ** and which are compatible with sm_free. Warning: sm_heap_report
68 ** cannot report where storage leaked by sm_f[mc]alloc was allocated.
71 /* XXX unused right now */
84 ** Allocate 'permanent' storage that can be freed but may still be
85 ** allocated when the process exits. sm_heap_report will not complain
86 ** about a storage leak originating from a call to sm_pmalloc.
89 # define sm_pmalloc(size) sm_malloc_tagged(size, __FILE__, __LINE__, 0)
90 # define sm_pmalloc_x(size) sm_malloc_tagged_x(size, __FILE__, __LINE__, 0)
92 # define sm_heap_group() SmHeapGroup
93 # define sm_heap_setgroup(g) (SmHeapGroup = (g))
94 # define sm_heap_newgroup() (SmHeapGroup = ++SmHeapMaxGroup)
96 #define SM_FREE(ptr) \
106 extern int SmHeapGroup
;
107 extern int SmHeapMaxGroup
;
109 extern SM_DEBUG_T SmHeapTrace
;
110 extern SM_DEBUG_T SmHeapCheck
;
111 extern SM_EXC_T SmHeapOutOfMemory
;
113 #endif /* ! SM_HEAP_H */