xref: /titanic_41/usr/src/cmd/sendmail/include/sm/heap.h (revision 6185db853e024a486ff8837e6784dd290d866112)
1 /*
2  * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
3  *	All rights reserved.
4  *
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.
8  *
9  *	$Id: heap.h,v 1.22 2001/09/04 22:41:55 ca Exp $
10  */
11 
12 #pragma ident	"%Z%%M%	%I%	%E% SMI"
13 
14 /*
15 **  Sendmail debugging memory allocation package.
16 **  See libsm/heap.html for documentation.
17 */
18 
19 #ifndef SM_HEAP_H
20 # define SM_HEAP_H
21 
22 # include <sm/io.h>
23 # include <stdlib.h>
24 # include <sm/debug.h>
25 # include <sm/exc.h>
26 
27 /* change default to 0 for production? */
28 # ifndef SM_HEAP_CHECK
29 #  define SM_HEAP_CHECK		1
30 # endif /* ! SM_HEAP_CHECK */
31 
32 # if 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__)
36 
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));
44 
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)
52 
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 */
58 
59 extern void *sm_realloc __P((void *, size_t));
60 
61 # define sm_heap_checkptr(ptr) sm_heap_checkptr_tagged(ptr, __FILE__, __LINE__)
62 
63 #if 0
64 /*
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.
69 */
70 
71 /* XXX unused right now */
72 
73 extern void *
74 sm_fmalloc __P((
75 	size_t));
76 
77 extern void *
78 sm_fcalloc __P((
79 	size_t,
80 	size_t));
81 #endif /* 0 */
82 
83 /*
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.
87 */
88 
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)
91 
92 # define sm_heap_group()	SmHeapGroup
93 # define sm_heap_setgroup(g)	(SmHeapGroup = (g))
94 # define sm_heap_newgroup()	(SmHeapGroup = ++SmHeapMaxGroup)
95 
96 extern int SmHeapGroup;
97 extern int SmHeapMaxGroup;
98 
99 extern SM_DEBUG_T SmHeapTrace;
100 extern SM_DEBUG_T SmHeapCheck;
101 extern SM_EXC_T SmHeapOutOfMemory;
102 
103 #endif /* ! SM_HEAP_H */
104