1 #ifndef MP_LEAKTAB_H
2 #define MP_LEAKTAB_H
3 
4 
5 /*
6  * mpatrol
7  * A library for controlling and tracing dynamic memory allocations.
8  * Copyright (C) 1997-2002 Graeme S. Roy <graeme.roy@analog.com>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the Free
22  * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23  * MA 02111-1307, USA.
24  */
25 
26 
27 /*
28  * Memory leak tables.  Such tables are used by the mpatrol library to record
29  * where heap memory is allocated and freed so that a summary of where memory
30  * leaks occurred can be made.
31  */
32 
33 
34 /*
35  * $Id: leaktab.h,v 1.3 2002/01/08 20:13:59 graeme Exp $
36  */
37 
38 
39 #include "config.h"
40 #include "list.h"
41 #include "heap.h"
42 
43 
44 #define SOPT_ALLOCATED 0 /* sort by allocated memory */
45 #define SOPT_FREED     1 /* sort by freed memory */
46 #define SOPT_UNFREED   2 /* sort by unfreed memory */
47 
48 
49 /* A tablenode belongs to a hash table of table nodes and contains an
50  * allocation summary for a particular file name and line number, or
51  * alternatively for a particular function name or return address.
52  */
53 
54 typedef union tablenode
55 {
56     struct
57     {
58         listnode node;      /* internal list node */
59         void *block;        /* pointer to block of memory */
60         size_t size;        /* size of block of memory */
61     }
62     index;
63     struct
64     {
65         listnode node;      /* list node */
66         treenode tnode;     /* tree node */
67         char *file;         /* file name, or function name if line is 0 */
68         unsigned long line; /* line number, or return address if file is NULL */
69         size_t acount;      /* allocation count */
70         size_t atotal;      /* allocation total */
71         size_t dcount;      /* deallocation count */
72         size_t dtotal;      /* deallocation total */
73     }
74     data;
75 }
76 tablenode;
77 
78 
79 /* A leaktab holds the hash table of table nodes.
80  */
81 
82 typedef struct leaktab
83 {
84     heaphead *heap;                  /* pointer to heap */
85     slottable table;                 /* table of table nodes */
86     listhead slots[MP_LEAKTAB_SIZE]; /* array of lists for table nodes */
87     listhead list;                   /* internal list of memory blocks */
88     treeroot tree;                   /* tree for sorting */
89     size_t isize;                    /* memory used by internal blocks */
90     size_t size;                     /* number of nodes in table */
91     memaccess prot;                  /* protection status */
92     size_t protrecur;                /* protection recursion count */
93     char tracing;                    /* leak tracing status */
94 }
95 leaktab;
96 
97 
98 #ifdef __cplusplus
99 extern "C"
100 {
101 #endif /* __cplusplus */
102 
103 
104 MP_EXPORT void __mp_newleaktab(leaktab *, heaphead *);
105 MP_EXPORT void __mp_deleteleaktab(leaktab *);
106 MP_EXPORT void __mp_clearleaktab(leaktab *);
107 MP_EXPORT void __mp_sortleaktab(leaktab *, int, int);
108 MP_EXPORT int __mp_allocentry(leaktab *, char *, unsigned long, size_t);
109 MP_EXPORT int __mp_freeentry(leaktab *, char *, unsigned long, size_t);
110 MP_EXPORT int __mp_protectleaktab(leaktab *, memaccess);
111 
112 
113 #ifdef __cplusplus
114 }
115 #endif /* __cplusplus */
116 
117 
118 #endif /* MP_LEAKTAB_H */
119