1 /*
2  * Token attributes for the dmalloc program and _dmalloc_flags
3  *
4  * Copyright 2020 by Gray Watson
5  *
6  * This file is part of the dmalloc package.
7  *
8  * Permission to use, copy, modify, and distribute this software for
9  * any purpose and without fee is hereby granted, provided that the
10  * above copyright notice and this permission notice appear in all
11  * copies, and that the name of Gray Watson not be used in advertising
12  * or publicity pertaining to distribution of the document or software
13  * without specific, written prior permission.
14  *
15  * Gray Watson makes no representations about the suitability of the
16  * software described herein for any purpose.  It is provided "as is"
17  * without express or implied warranty.
18  *
19  * The author may be contacted via http://dmalloc.com/
20  */
21 
22 #ifndef __DEBUG_TOK_H__
23 #define __DEBUG_TOK_H__
24 
25 #include "dmalloc_loc.h"		/* for BIT_FLAG */
26 
27 /*
28  * special debug codes which detail what debug features are enabled
29  * NOTE: need to change debug_tok.h, mallocrc, and malloc.texi if any
30  * capabilities are added/removed/updated
31  */
32 
33 /* logging */
34 #define DMALLOC_DEBUG_LOG_STATS		BIT_FLAG(0)	/* generally log statistics */
35 #define DMALLOC_DEBUG_LOG_NONFREE	BIT_FLAG(1)	/* report non-freed pointers */
36 #define DMALLOC_DEBUG_LOG_KNOWN		BIT_FLAG(2)	/* report only known nonfreed*/
37 #define DMALLOC_DEBUG_LOG_TRANS		BIT_FLAG(3)	/* log memory transactions */
38 /* 4 available - 20001107 */
39 #define DMALLOC_DEBUG_LOG_ADMIN		BIT_FLAG(5)	/* log background admin info */
40 /* 6 available 20030508 */
41 /* 7 available - 20001107 */
42 #define DMALLOC_DEBUG_LOG_BAD_SPACE	BIT_FLAG(8)	/* dump space from bad pnt */
43 #define DMALLOC_DEBUG_LOG_NONFREE_SPACE	BIT_FLAG(9)	/* dump space from non-freed */
44 
45 #define DMALLOC_DEBUG_LOG_ELAPSED_TIME	BIT_FLAG(18)	/* log pnt elapsed time info */
46 #define DMALLOC_DEBUG_LOG_CURRENT_TIME	BIT_FLAG(19)	/* log pnt current time info */
47 
48 /* checking */
49 #define DMALLOC_DEBUG_CHECK_FENCE	BIT_FLAG(10)	/* check fence-post errors  */
50 #define DMALLOC_DEBUG_CHECK_HEAP	BIT_FLAG(11)	/* examine heap adm structs */
51 /* 12 available - 20030608 */
52 #define DMALLOC_DEBUG_CHECK_BLANK	BIT_FLAG(13)	/* check blank sections */
53 #define DMALLOC_DEBUG_CHECK_FUNCS	BIT_FLAG(14)	/* check functions */
54 #define DMALLOC_DEBUG_CHECK_SHUTDOWN	BIT_FLAG(15)	/* check pointers on shutdown*/
55 
56 /* misc */
57 /* 16 available - 20040709 */
58 #define DMALLOC_DEBUG_CATCH_SIGNALS	BIT_FLAG(17)	/* catch HUP, INT, and TERM */
59 /* 18,19 used above */
60 #define DMALLOC_DEBUG_REALLOC_COPY	BIT_FLAG(20)	/* copy all reallocations */
61 #define DMALLOC_DEBUG_FREE_BLANK	BIT_FLAG(21)	/* write over free'd memory */
62 #define DMALLOC_DEBUG_ERROR_ABORT	BIT_FLAG(22)	/* abort on error else exit */
63 #define DMALLOC_DEBUG_ALLOC_BLANK	BIT_FLAG(23)	/* write over to-be-alloced */
64 /* 24 available - 20030508 */
65 #define DMALLOC_DEBUG_PRINT_MESSAGES	BIT_FLAG(25)	/* write messages to STDERR */
66 #define DMALLOC_DEBUG_CATCH_NULL	BIT_FLAG(26)	/* quit before return null */
67 #define DMALLOC_DEBUG_NEVER_REUSE	BIT_FLAG(27)	/* never reuse memory */
68 #define DMALLOC_DEBUG_ERROR_FREE_NULL	BIT_FLAG(28)	/* catch free(0) */
69 /* 29 available - 20011130 */
70 #define DMALLOC_DEBUG_ERROR_DUMP	BIT_FLAG(30)	/* dump core on error */
71 /* 31 is the high bit and off-limits */
72 
73 /*
74  * structure for mapping the string to the numerical token
75  */
76 typedef struct {
77   char		*at_string;		/* attribute string */
78   unsigned long	at_value;		/* value for the item */
79   char		*at_desc;		/* description string */
80 } attr_t;
81 
82 static	attr_t		attributes[]
83 #ifdef __GNUC__
84 __attribute__ ((unused))
85 #endif
86 = {
87   { "none",		0,				"no functionality" },
88 
89   { "log-stats",	DMALLOC_DEBUG_LOG_STATS,	"log general statistics" },
90   { "log-non-free",	DMALLOC_DEBUG_LOG_NONFREE,	"log non-freed pointers" },
91   { "log-known",	DMALLOC_DEBUG_LOG_KNOWN,	"log only known non-freed" },
92   { "log-trans",	DMALLOC_DEBUG_LOG_TRANS,	"log memory transactions" },
93   { "log-admin",	DMALLOC_DEBUG_LOG_ADMIN,	"log administrative info" },
94   { "log-bad-space",	DMALLOC_DEBUG_LOG_BAD_SPACE,	"dump space from bad pnt" },
95   { "log-nonfree-space", DMALLOC_DEBUG_LOG_NONFREE_SPACE,
96     "dump space from non-freed pointers" },
97 
98   { "log-elapsed-time",	DMALLOC_DEBUG_LOG_ELAPSED_TIME,
99     "log elapsed-time for allocated pointer" },
100   { "log-current-time",	DMALLOC_DEBUG_LOG_CURRENT_TIME,
101     "log current-time for allocated pointer" },
102 
103   { "check-fence",	DMALLOC_DEBUG_CHECK_FENCE,	"check fence-post errors" },
104   { "check-heap",	DMALLOC_DEBUG_CHECK_HEAP,	"check heap adm structs" },
105   { "check-blank",	DMALLOC_DEBUG_CHECK_BLANK,
106     "check mem overwritten by alloc-blank, free-blank" },
107   { "check-funcs",	DMALLOC_DEBUG_CHECK_FUNCS,	"check functions" },
108   { "check-shutdown",	DMALLOC_DEBUG_CHECK_SHUTDOWN,	"check heap on shutdown" },
109 
110   { "catch-signals",	DMALLOC_DEBUG_CATCH_SIGNALS,
111     "shutdown program on SIGHUP, SIGINT, SIGTERM" },
112   { "realloc-copy",	DMALLOC_DEBUG_REALLOC_COPY,	"copy all re-allocations" },
113   { "free-blank",	DMALLOC_DEBUG_FREE_BLANK,
114     "overwrite freed memory with \\0337 byte (0xdf)" },
115   { "error-abort",	DMALLOC_DEBUG_ERROR_ABORT,	"abort immediately on error" },
116   { "alloc-blank",	DMALLOC_DEBUG_ALLOC_BLANK,
117     "overwrite allocated memory with \\0332 byte (0xda)" },
118   { "print-messages",	DMALLOC_DEBUG_PRINT_MESSAGES,	"write messages to stderr" },
119   { "catch-null",	DMALLOC_DEBUG_CATCH_NULL,      "abort if no memory available"},
120   { "never-reuse",	DMALLOC_DEBUG_NEVER_REUSE,	"never re-use freed memory" },
121   { "error-dump",	DMALLOC_DEBUG_ERROR_DUMP,
122     "dump core on error, then continue" },
123   { "error-free-null",	DMALLOC_DEBUG_ERROR_FREE_NULL,
124     "generate error when a 0L pointer is freed" },
125 
126   /*
127    * The following are here for backwards compatibility
128    */
129 
130   /* this is the default now and log-known is the opposite */
131   { "log-unknown",	0,
132     "Disabled -- this is the default now, log-known is opposite" },
133   { "log-blocks",	0,
134     "Disabled because of new heap organization" },
135   /* this is the default and force-linear is opposite */
136   { "allow-nonlinear",	0,
137     "Disabled -- this is the default now" },
138   /* this is the default and error-free-null opposite */
139   { "allow-free-null",	0,
140     "Disabled -- this is the default now, error-free-null is opposite" },
141   { "heap-check-map",	0,
142     "Disabled because of new heap organization" },
143   { "check-lists",	0,
144     "Disabled -- removed with new heap organization" },
145   { "force-linear",	0,
146     "Disabled -- removed with new mmap usage" },
147 
148   { NULL }
149 };
150 
151 #endif /* ! __DEBUG_TOK_H__ */
152