1 /*
2  * (c) Copyright 1990 Conor P. Cahill (uunet!virtech!cpcahil).
3  * You may copy, distribute, and use this software as long as this
4  * copyright statement is not removed.
5  */
6 /*
7  * $Id: malloc.h,v 1.2 2006-07-25 10:08:50 rt Exp $
8  */
9 struct mlist
10 {
11 	struct mlist	* next;			/* next entry in chain	*/
12 	struct mlist	* prev;			/* prev entry in chain	*/
13 	int	 	  flag;			/* inuse flag		*/
14 	unsigned int	  r_size;		/* requested size	*/
15 	union
16 	{
17 		unsigned int	  size;		/* actual size		*/
18 		double		  unused_just_for_alignment;
19 	} s;
20 	char		  data[4];
21 };
22 
23 #define M_SIZE		((int)(char *)((struct mlist *)0)->data)
24 #define M_RND		0x08
25 
26 #define M_INUSE 	0x01
27 #define M_MAGIC 	0x03156100
28 
29 #define M_BLOCKSIZE	(1024*8)
30 
31 #define M_FILL		'\01'
32 #define M_FREE_FILL	'\02'
33 
34 #define M_ROUNDUP(size)	{\
35 				if( size & (M_RND-1) ) \
36 				{ \
37 					size &= ~(M_RND-1); \
38 					size += M_RND; \
39 				} \
40 			}
41 
42 /*
43  * Malloc warning/fatal error handler defines...
44  */
45 #define M_HANDLE_DUMP	0x80  /* 128 */
46 #define M_HANDLE_IGNORE	0
47 #define M_HANDLE_ABORT	1
48 #define M_HANDLE_EXIT	2
49 #define M_HANDLE_CORE	3
50 
51 /*
52  * Mallopt commands and defaults
53  */
54 
55 #define MALLOC_WARN	1		/* set malloc warning handling	*/
56 #define MALLOC_FATAL	2		/* set malloc fatal handling	*/
57 #define MALLOC_ERRFILE	3		/* specify malloc error file	*/
58 #define MALLOC_CKCHAIN	4		/* turn on chain checking	*/
59 union malloptarg
60 {
61 	int	  i;
62 	char	* str;
63 };
64 
65 /*
66  * Malloc warning/fatal error codes
67  */
68 
69 #define M_CODE_CHAIN_BROKE	1	/* malloc chain is broken	*/
70 #define M_CODE_NO_END		2	/* chain end != endptr		*/
71 #define M_CODE_BAD_PTR		3	/* pointer not in malloc area	*/
72 #define M_CODE_BAD_MAGIC	4	/* bad magic number in header	*/
73 #define M_CODE_BAD_CONNECT	5	/* chain poingers corrupt	*/
74 #define M_CODE_OVERRUN		6	/* data overrun in malloc seg	*/
75 #define M_CODE_REUSE		7	/* reuse of freed area		*/
76 #define M_CODE_NOT_INUSE	8	/* pointer is not in use	*/
77 #define M_CODE_NOMORE_MEM	9	/* no more memory available	*/
78 #define M_CODE_OUTOF_BOUNDS	10	/* gone beyound bounds 		*/
79 
80 void malloc_warning();
81 void malloc_fatal();
82 void malloc_check_data();
83 void malloc_check_str();
84 void malloc_verify();
85 
86