1 #ifndef MP_INTER_H
2 #define MP_INTER_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  * Library interface.  This module defines the visible interface for the
29  * mpatrol library.
30  */
31 
32 
33 /*
34  * $Id: inter.h,v 1.56 2002/01/08 20:13:59 graeme Exp $
35  */
36 
37 
38 #include "config.h"
39 #include "info.h"
40 #include "diag.h"
41 #include <stdarg.h>
42 
43 
44 /* An allocinfo structure provides information about a particular memory
45  * allocation.  This must be kept up to date with the definition of
46  * __mp_allocinfo in mpatrol.h.
47  */
48 
49 typedef struct allocinfo
50 {
51     void *block;           /* pointer to block of memory */
52     size_t size;           /* size of block of memory */
53     alloctype type;        /* type of memory allocation */
54     unsigned long alloc;   /* allocation index */
55     unsigned long realloc; /* reallocation index */
56     unsigned long thread;  /* thread identifier */
57     unsigned long event;   /* event of last modification */
58     char *func;            /* calling function name */
59     char *file;            /* file name in which call took place */
60     unsigned long line;    /* line number at which call took place */
61     addrnode *stack;       /* call stack details */
62     char *typestr;         /* type stored in allocation */
63     size_t typesize;       /* size of type stored in allocation */
64     void *userdata;        /* user data associated with allocation */
65     int allocated : 1;     /* allocation was allocated */
66     int freed : 1;         /* allocation has been freed */
67     int marked : 1;        /* allocation has been marked */
68     int profiled : 1;      /* allocation has been profiled */
69     int traced : 1;        /* allocation has been traced */
70     int internal : 1;      /* allocation is internal */
71 }
72 allocinfo;
73 
74 
75 /* A symbolinfo structure provides information about a particular symbol.
76  * This must be kept up to date with the definition of __mp_symbolinfo in
77  * mpatrol.h.
78  */
79 
80 typedef struct symbolinfo
81 {
82     char *name;         /* symbol name */
83     char *object;       /* module symbol located in */
84     void *addr;         /* start address */
85     size_t size;        /* size of symbol */
86     char *file;         /* file name corresponding to address */
87     unsigned long line; /* line number corresponding to address */
88 }
89 symbolinfo;
90 
91 
92 /* A heapinfo structure provides statistics about the current state of the
93  * heap.  This must be kept up to date with the definition of __mp_heapinfo
94  * in mpatrol.h
95  */
96 
97 typedef struct heapinfo
98 {
99     size_t acount; /* total number of allocated blocks */
100     size_t atotal; /* total size of allocated blocks */
101     size_t fcount; /* total number of free blocks */
102     size_t ftotal; /* total size of free blocks */
103     size_t gcount; /* total number of freed blocks */
104     size_t gtotal; /* total size of freed blocks */
105     size_t icount; /* total number of internal blocks */
106     size_t itotal; /* total size of internal blocks */
107     size_t mcount; /* total number of marked blocks */
108     size_t mtotal; /* total size of marked blocks */
109 }
110 heapinfo;
111 
112 
113 #ifdef __cplusplus
114 extern "C"
115 {
116 #endif /* __cplusplus */
117 
118 
119 MP_API extern errortype __mp_errno;
120 
121 
122 MP_API void __mp_init(void);
123 MP_API void __mp_reinit(void);
124 MP_API void __mp_fini(void);
125 MP_API void __mp_trap(void);
126 MP_API int __mp_atexit(void (*)(void));
127 MP_API unsigned long __mp_setoption(long, unsigned long);
128 MP_API int __mp_getoption(long, unsigned long *);
129 MP_API infohead *__mp_memhead(void);
130 MP_API void *__mp_alloc(size_t, size_t, alloctype, char *, char *,
131                         unsigned long, char *, size_t, size_t);
132 MP_API char *__mp_strdup(char *, size_t, alloctype, char *, char *,
133                          unsigned long, size_t);
134 MP_API void *__mp_realloc(void *, size_t, size_t, alloctype, char *, char *,
135                           unsigned long, char *, size_t, size_t);
136 MP_API void __mp_free(void *, alloctype, char *, char *, unsigned long, size_t);
137 MP_API void *__mp_setmem(void *, size_t, unsigned char, alloctype, char *,
138                          char *, unsigned long, size_t);
139 MP_API void *__mp_copymem(void *, void *, size_t, unsigned char, alloctype,
140                           char *, char *, unsigned long, size_t);
141 MP_API void *__mp_locatemem(void *, size_t, void *, size_t, alloctype, char *,
142                             char *, unsigned long, size_t);
143 MP_API int __mp_comparemem(void *, void *, size_t, alloctype, char *, char *,
144                            unsigned long, size_t);
145 MP_API unsigned long __mp_libversion(void);
146 MP_API char *__mp_strerror(errortype);
147 MP_API char *__mp_function(alloctype);
148 MP_API int __mp_setuser(void *, void *);
149 MP_API int __mp_setmark(void *);
150 MP_API int __mp_info(void *, allocinfo *);
151 MP_API int __mp_syminfo(void *, symbolinfo *);
152 MP_API char *__mp_symbol(void *);
153 MP_API int __mp_printinfo(void *);
154 MP_API unsigned long __mp_snapshot(void);
155 MP_API size_t __mp_iterate(int (*)(void *, void *), void *, unsigned long);
156 MP_API size_t __mp_iterateall(int (*)(void *, void *), void *);
157 MP_API int __mp_addallocentry(char *, unsigned long, size_t);
158 MP_API int __mp_addfreeentry(char *, unsigned long, size_t);
159 MP_API void __mp_clearleaktable(void);
160 MP_API int __mp_startleaktable(void);
161 MP_API int __mp_stopleaktable(void);
162 MP_API void __mp_leaktable(size_t, int, unsigned char);
163 MP_API void __mp_memorymap(int);
164 MP_API void __mp_summary(void);
165 MP_API int __mp_stats(heapinfo *);
166 MP_API void __mp_checkheap(char *, char *, unsigned long);
167 MP_API void __mp_check(void);
168 MP_API prologuehandler __mp_prologue(prologuehandler);
169 MP_API epiloguehandler __mp_epilogue(epiloguehandler);
170 MP_API nomemoryhandler __mp_nomemory(nomemoryhandler);
171 MP_API void __mp_pushdelstack(char *, char *, unsigned long);
172 MP_API void __mp_popdelstack(char **, char **, unsigned long *);
173 MP_API int __mp_printf(char *, ...);
174 MP_API int __mp_vprintf(char *, va_list);
175 MP_API void __mp_printfwithloc(char *, char *, unsigned long, char *, ...);
176 MP_API void __mp_vprintfwithloc(char *, char *, unsigned long, char *, va_list);
177 MP_API void __mp_logmemory(void *, size_t);
178 MP_API int __mp_logstack(size_t);
179 MP_API int __mp_logaddr(void *);
180 MP_API int __mp_edit(char *, unsigned long);
181 MP_API int __mp_list(char *, unsigned long);
182 MP_API int __mp_view(char *, unsigned long);
183 MP_API int __mp_readcontents(char *, void *);
184 MP_API int __mp_writecontents(char *, void *);
185 MP_API long __mp_cmpcontents(char *, void *);
186 MP_API int __mp_remcontents(char *, void *);
187 MP_API void __cyg_profile_func_enter(void *, void *);
188 MP_API void __cyg_profile_func_exit(void *, void *);
189 MP_API void chkr_set_right(void *, size_t, unsigned char);
190 MP_API void chkr_copy_bitmap(void *, void *, size_t);
191 MP_API void chkr_check_addr(void *, size_t, unsigned char);
192 MP_API void chkr_check_str(char *, unsigned char);
193 MP_API void chkr_check_exec(void *);
194 
195 
196 #ifdef __cplusplus
197 }
198 #endif /* __cplusplus */
199 
200 
201 #endif /* MP_INTER_H */
202