1 /*
2  * global error codes for chunk allocation problems
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 __ERROR_VAL_H__
23 #define __ERROR_VAL_H__
24 
25 /*
26  * Dmalloc error codes.
27  *
28  * NOTE: these are here instead of error.h because the dmalloc utility
29  * needs them as well as the dmalloc library.
30  */
31 #define DMALLOC_ERROR_NONE		1	/* no error */
32 /* 2 is reserved for invalid error */
33 
34 /* administrative errors */
35 #define DMALLOC_ERROR_BAD_SETUP		10	/* bad setup value */
36 #define DMALLOC_ERROR_IN_TWICE		11	/* in malloc domain twice */
37 /* 12 unused */
38 #define DMALLOC_ERROR_LOCK_NOT_CONFIG	13	/* thread locking not config */
39 
40 /* pointer verification errors */
41 #define DMALLOC_ERROR_IS_NULL		20	/* pointer is NULL */
42 #define DMALLOC_ERROR_NOT_IN_HEAP	21	/* pointer is not in heap */
43 #define DMALLOC_ERROR_NOT_FOUND		22	/* pointer not-found */
44 #define DMALLOC_ERROR_IS_FOUND		23	/* found special pointer */
45 #define DMALLOC_ERROR_BAD_FILE		24	/* bad file-name */
46 #define DMALLOC_ERROR_BAD_LINE		25	/* bad line-number */
47 #define DMALLOC_ERROR_UNDER_FENCE	26	/* failed picket fence lower */
48 #define DMALLOC_ERROR_OVER_FENCE	27	/* failed picket fence upper */
49 #define DMALLOC_ERROR_WOULD_OVERWRITE	28	/* would overwrite fence */
50 /* 29 unused */
51 #define DMALLOC_ERROR_NOT_START_BLOCK	30	/* pointer not to start mem */
52 
53 /* allocation errors */
54 #define DMALLOC_ERROR_BAD_SIZE		40	/* bad size value */
55 #define DMALLOC_ERROR_TOO_BIG		41	/* allocation too large */
56 /* 42 unused */
57 #define DMALLOC_ERROR_ALLOC_FAILED	43	/* could not get more space */
58 /* 44 unused */
59 #define DMALLOC_ERROR_OVER_LIMIT	45	/* over allocation limit */
60 
61 /* free errors */
62 #define DMALLOC_ERROR_NOT_ON_BLOCK	60	/* not on block boundary */
63 #define DMALLOC_ERROR_ALREADY_FREE	61	/* already in free list */
64 /* 62-66 unused */
65 #define DMALLOC_ERROR_FREE_OVERWRITTEN	67	/* free space overwritten */
66 
67 /* administrative errors */
68 #define DMALLOC_ERROR_ADMIN_LIST	70	/* list pnt out of bounds */
69 /* 71 unused */
70 #define DMALLOC_ERROR_ADDRESS_LIST	72	/* invalid address list */
71 #define DMALLOC_ERROR_SLOT_CORRUPT	73	/* memory slot corruption */
72 
73 #define INVALID_ERROR		"errno value is not valid"
74 
75 typedef struct {
76   int		es_error;		/* error number */
77   char		*es_string;		/* associated string */
78 } error_str_t;
79 
80 /* string error codes which apply to error codes in error_val.h */
81 static	error_str_t	error_list[]
82 #ifdef __GNUC__
83 __attribute__ ((unused))
84 #endif
85 = {
86   { DMALLOC_ERROR_NONE,			"no error" },
87 
88   /* administrative errors */
89   { DMALLOC_ERROR_BAD_SETUP,		"dmalloc initialization and setup failed" },
90   { DMALLOC_ERROR_IN_TWICE,		"dmalloc library has gone recursive" },
91   { DMALLOC_ERROR_LOCK_NOT_CONFIG,	"dmalloc thread locking has not been configured" },
92 
93   /* pointer verification errors */
94   { DMALLOC_ERROR_IS_NULL,		"pointer is null" },
95   { DMALLOC_ERROR_NOT_IN_HEAP,		"pointer is not pointing to heap data space" },
96   { DMALLOC_ERROR_NOT_FOUND,		"cannot locate pointer in heap" },
97   { DMALLOC_ERROR_IS_FOUND,		"found pointer the user was looking for" },
98   { DMALLOC_ERROR_BAD_FILE,		"possibly bad .c filename pointer" },
99   { DMALLOC_ERROR_BAD_LINE,		"possibly bad .c file line-number" },
100   { DMALLOC_ERROR_UNDER_FENCE,		"failed UNDER picket-fence magic-number check"},
101   { DMALLOC_ERROR_OVER_FENCE,		"failed OVER picket-fence magic-number check"},
102   { DMALLOC_ERROR_WOULD_OVERWRITE,	"use of pointer would exceed allocation" },
103   { DMALLOC_ERROR_NOT_START_BLOCK,	"pointer is not to start of memory block" },
104 
105   /* allocation errors */
106   { DMALLOC_ERROR_BAD_SIZE,		"invalid allocation size" },
107   { DMALLOC_ERROR_TOO_BIG,		"largest maximum allocation size exceeded" },
108   { DMALLOC_ERROR_ALLOC_FAILED,		"could not grow heap by allocating memory" },
109   { DMALLOC_ERROR_OVER_LIMIT,		"over user specified allocation limit" },
110 
111   /* free errors */
112   { DMALLOC_ERROR_NOT_ON_BLOCK,		"pointer is not on block boundary" },
113   { DMALLOC_ERROR_ALREADY_FREE,		"tried to free previously freed pointer" },
114   { DMALLOC_ERROR_FREE_OVERWRITTEN,	"free space has been overwritten" },
115 
116   /* administrative errors */
117   { DMALLOC_ERROR_ADMIN_LIST,		"dmalloc bad admin structure list" },
118   { DMALLOC_ERROR_ADDRESS_LIST,		"dmalloc internal address list corruption" },
119   { DMALLOC_ERROR_SLOT_CORRUPT,		"dmalloc internal memory slot corruption" },
120 
121   { 0 }
122 };
123 
124 #endif /* ! __DMALLOC_ERROR_VAL_H__ */
125