1 #ifndef MP_CONFIG_H
2 #define MP_CONFIG_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 configuration.  All configuration constants for the mpatrol
29  * library are defined here.
30  */
31 
32 
33 /*
34  * $Id: config.h,v 1.87 2002/01/08 20:13:59 graeme Exp $
35  */
36 
37 
38 #include "target.h"
39 
40 
41 /* The keywords used to specify the visibility of all internal support
42  * functions and variables within the library.  If the library is composed
43  * of separate object modules then functions in one translation unit may
44  * need to call functions in another translation unit even though they
45  * should not be visible to the user.
46  */
47 
48 #ifndef MP_EXPORT
49 #define MP_EXPORT extern
50 #endif /* MP_EXPORT */
51 
52 #ifndef MP_GLOBAL
53 #define MP_GLOBAL
54 #endif /* MP_GLOBAL */
55 
56 
57 /* The keyword used to specify the visibility of functions and variables which
58  * are part of the library API.
59  */
60 
61 #ifndef MP_API
62 #define MP_API
63 #endif /* MP_API */
64 
65 
66 /* The keywords used to specify a constant variable or parameter and a variable
67  * that should not have accesses to it optimised away.  These may only be
68  * supported by ANSI C or C++ compilers so they are defined under a macro just
69  * in case.  Note that constness is really only used for the highest-level
70  * functions in the library to prevent clashes with any functions that are
71  * being overridden, and volatility is only used to prevent RCS identification
72  * strings from being removed by an optimising compiler.
73  */
74 
75 #ifndef MP_CONST
76 #if defined(__STDC__) || defined(__cplusplus)
77 #define MP_CONST const
78 #else /* __STDC__ && __cplusplus */
79 #define MP_CONST
80 #endif /* __STDC__ && __cplusplus */
81 #endif /* MP_CONST */
82 
83 #ifndef MP_VOLATILE
84 #if defined(__STDC__) || defined(__cplusplus)
85 #define MP_VOLATILE volatile
86 #else /* __STDC__ && __cplusplus */
87 #define MP_VOLATILE
88 #endif /* __STDC__ && __cplusplus */
89 #endif /* MP_VOLATILE */
90 
91 
92 /* Indicates if preprocessor macro versions of some internal library routines
93  * should be used instead of their function equivalents in order to increase
94  * run-time efficiency.  This might not be desirable if the library needs to be
95  * run under a debugger.
96  */
97 
98 #ifndef MP_MACROROUTINES
99 #define MP_MACROROUTINES 1
100 #endif /* MP_MACROROUTINES */
101 
102 
103 /* Indicates if system memory should be allocated from a static array rather
104  * than the process heap.  Use this to provide support for dynamic memory
105  * allocation routines on systems that don't have a system function to allocate
106  * heap memory.
107  */
108 
109 #ifndef MP_ARRAY_SUPPORT
110 #if TARGET == TARGET_ANY
111 #define MP_ARRAY_SUPPORT 1
112 #else /* TARGET */
113 #define MP_ARRAY_SUPPORT 0
114 #endif /* TARGET */
115 #endif /* MP_ARRAY_SUPPORT */
116 
117 
118 /* The size of the static memory array in bytes.  Any attempt to allocate more
119  * system memory than this will fail, although it should be remembered that the
120  * library will also be using this array for its internal structures.  The
121  * default is 1 megabyte.
122  */
123 
124 #if MP_ARRAY_SUPPORT
125 #ifndef MP_ARRAY_SIZE
126 #define MP_ARRAY_SIZE 1048576
127 #endif /* MP_ARRAY_SIZE */
128 #endif /* MP_ARRAY_SUPPORT */
129 
130 
131 /* The number of entries in the function and file name caches.  These caches
132  * are used when tracing in order to keep the size of the tracing output file
133  * down.  The caches will reuse their oldest entries when they are full.  Note
134  * that the size of the caches cannot be greater than 127 entries.
135  */
136 
137 #ifndef MP_NAMECACHE_SIZE
138 #define MP_NAMECACHE_SIZE 32
139 #endif /* MP_NAMECACHE_SIZE */
140 
141 
142 /* The number of entries in the memory reservation cache.  This cache is used
143  * when tracing in order to store information about heap memory reservations
144  * before the tracing output file has been opened.  If the number of entries
145  * to store exceeds this number then all subsequent entries will be discarded
146  * until the tracing output file has been opened.
147  */
148 
149 #ifndef MP_RESCACHE_SIZE
150 #define MP_RESCACHE_SIZE 256
151 #endif /* MP_RESCACHE_SIZE */
152 
153 
154 /* The size of the simulated UNIX heap in bytes.  This is used by the brk() and
155  * sbrk() functions on non-UNIX platforms and is used to allocate a block of
156  * memory of this size.  Any attempt to allocate memory beyond this block will
157  * cause these functions to fail.
158  */
159 
160 #ifndef MP_BREAK_SIZE
161 #define MP_BREAK_SIZE 262144
162 #endif /* MP_BREAK_SIZE */
163 
164 
165 /* The size of the input line buffer in bytes in the mptrace and mleak tools.
166  * If any of the entries in the tracing output file or any of the lines in the
167  * log file are longer than this then an error message will be generated and
168  * mptrace or mleak will terminate.
169  */
170 
171 #ifndef MP_BUFFER_SIZE
172 #define MP_BUFFER_SIZE 8192
173 #endif /* MP_BUFFER_SIZE */
174 
175 
176 /* The number of allocation bins to use when profiling.  Details of memory
177  * allocations of all sizes up to the bin size will be recorded in a table and
178  * written to the profiling output file at program termination.
179  */
180 
181 #ifndef MP_BIN_SIZE
182 #define MP_BIN_SIZE 1024
183 #endif /* MP_BIN_SIZE */
184 
185 
186 /* The number of buckets in the hash table used to implement the string table.
187  * This must be a prime number.
188  */
189 
190 #ifndef MP_HASHTAB_SIZE
191 #define MP_HASHTAB_SIZE 211
192 #endif /* MP_HASHTAB_SIZE */
193 
194 
195 /* The number of buckets in the hash table used to implement the leak table.
196  * This must be a prime number.
197  */
198 
199 #ifndef MP_LEAKTAB_SIZE
200 #define MP_LEAKTAB_SIZE 47
201 #endif /* MP_LEAKTAB_SIZE */
202 
203 
204 /* The multiple of pages to allocate from the heap every time a new block of
205  * internal memory is required.  The higher the value, the less distinct
206  * internal blocks to keep track of, but the potential for more memory wastage
207  * if not all of the block is required.
208  */
209 
210 #ifndef MP_ALLOCFACTOR
211 #define MP_ALLOCFACTOR 4
212 #endif /* MP_ALLOCFACTOR */
213 
214 
215 /* The maximum number of recursive calls to C++ operator delete and operator
216  * delete[] that will have source level information associated with them.
217  * This acts as a workaround for the fact that placement delete will only be
218  * called during an exception and not if explicitly invoked.  However, the
219  * current implementation is not thread-safe.
220  */
221 
222 #ifndef MP_MAXDELSTACK
223 #define MP_MAXDELSTACK 32
224 #endif /* MP_MAXDELSTACK */
225 
226 
227 /* The maximum number of initialisation and finalisation functions that can
228  * be registered with the mpatrol library through the __mp_init_*() functions
229  * and through the __mp_atexit() function respectively.  The initialisation
230  * functions are called in order of discovery when __mp_init() is called and
231  * the finalisation functions are called in reverse order when __mp_fini()
232  * is called.
233  */
234 
235 #ifndef MP_MAXINITS
236 #define MP_MAXINITS 32
237 #endif /* MP_MAXINITS */
238 
239 #ifndef MP_MAXFINIS
240 #define MP_MAXFINIS 32
241 #endif /* MP_MAXFINIS */
242 
243 
244 /* Indicates if all of the heap memory used by the library should be
245  * deleted when the process exits.  This should not be set on systems that
246  * make dynamic memory allocations after exit() or reference freed memory
247  * at process termination, and really only needs to be set on systems that
248  * do not reclaim memory from a process when it terminates.
249  */
250 
251 #ifndef MP_DELETEHEAP
252 #if TARGET == TARGET_UNIX || TARGET == TARGET_WINDOWS
253 #define MP_DELETEHEAP 0
254 #else /* TARGET */
255 #define MP_DELETEHEAP 1
256 #endif /* TARGET */
257 #endif /* MP_DELETEHEAP */
258 
259 
260 /* Indicates if the system supports memory protection.  If not, then the
261  * NOPROTECT option will always be used to prevent needless function calls
262  * and the PAGEALLOC option will have no effect.
263  */
264 
265 #ifndef MP_PROTECT_SUPPORT
266 #if TARGET == TARGET_UNIX || TARGET == TARGET_WINDOWS
267 #define MP_PROTECT_SUPPORT 1
268 #else /* TARGET */
269 #define MP_PROTECT_SUPPORT 0
270 #endif /* TARGET */
271 #endif /* MP_PROTECT_SUPPORT */
272 
273 
274 /* Indicates if the system supports the memalign() function call to allocate
275  * memory with a specified alignment.  This is used by mpalloc.c to implement
276  * release versions of memalign(), valloc() and pvalloc().
277  */
278 
279 #ifndef MP_MEMALIGN_SUPPORT
280 #if defined(HAVE_CONFIG_H) && defined(HAVE_MEMALIGN)
281 #define MP_MEMALIGN_SUPPORT 1
282 #else /* HAVE_CONFIG_H && HAVE_MEMALIGN */
283 #if SYSTEM == SYSTEM_CYGWIN || SYSTEM == SYSTEM_DGUX || \
284     SYSTEM == SYSTEM_DRSNX || SYSTEM == SYSTEM_IRIX || \
285     SYSTEM == SYSTEM_LINUX || SYSTEM == SYSTEM_SOLARIS || \
286     SYSTEM == SYSTEM_SUNOS || SYSTEM == SYSTEM_UNIXWARE
287 #define MP_MEMALIGN_SUPPORT 1
288 #else /* SYSTEM */
289 #define MP_MEMALIGN_SUPPORT 0
290 #endif /* SYSTEM */
291 #endif /* HAVE_CONFIG_H && HAVE_MEMALIGN */
292 #endif /* MP_MEMALIGN_SUPPORT */
293 
294 
295 /* Indicates if a UNIX system supports the mmap() function call to allocate
296  * memory as well as sbrk().  This must only be set if the system also supports
297  * the allocation of zero-initialised pages from either a special device file
298  * or via a special flag.  Note that sbrk() will still be used by default, but
299  * mmap() will be used to allocate memory that is internal to the mpatrol
300  * library.  The USEMMAP option can be used to switch this behaviour.
301  */
302 
303 #ifndef MP_MMAP_SUPPORT
304 #if defined(HAVE_CONFIG_H) && defined(HAVE_MMAP)
305 #define MP_MMAP_SUPPORT 1
306 #else /* HAVE_CONFIG_H && HAVE_MMAP */
307 #if SYSTEM == SYSTEM_AIX || SYSTEM == SYSTEM_CYGWIN || \
308     SYSTEM == SYSTEM_DGUX || SYSTEM == SYSTEM_DRSNX || \
309     SYSTEM == SYSTEM_DYNIX || SYSTEM == SYSTEM_FREEBSD || \
310     SYSTEM == SYSTEM_HPUX || SYSTEM == SYSTEM_IRIX || \
311     SYSTEM == SYSTEM_LINUX || SYSTEM == SYSTEM_NETBSD || \
312     SYSTEM == SYSTEM_OPENBSD || SYSTEM == SYSTEM_SINIX || \
313     SYSTEM == SYSTEM_SOLARIS || SYSTEM == SYSTEM_SUNOS || \
314     SYSTEM == SYSTEM_TRU64 || SYSTEM == SYSTEM_UNIXWARE
315 #define MP_MMAP_SUPPORT 1
316 #else /* SYSTEM */
317 #define MP_MMAP_SUPPORT 0
318 #endif /* SYSTEM */
319 #endif /* HAVE_CONFIG_H && HAVE_MMAP */
320 #endif /* MP_MMAP_SUPPORT */
321 
322 
323 /* Indicates if the mmap() function call supports the MAP_ANON or MAP_ANONYMOUS
324  * flag for allocating zero-filled pages.  If it doesn't then the filename
325  * specified by MP_MMAP_FILENAME will be used instead.
326  */
327 
328 #if MP_MMAP_SUPPORT
329 #ifndef MP_MMAP_ANONYMOUS
330 #if SYSTEM == SYSTEM_AIX || SYSTEM == SYSTEM_CYGWIN || \
331     SYSTEM == SYSTEM_DYNIX || SYSTEM == SYSTEM_FREEBSD || \
332     SYSTEM == SYSTEM_HPUX || SYSTEM == SYSTEM_LINUX || \
333     SYSTEM == SYSTEM_NETBSD || SYSTEM == SYSTEM_OPENBSD || \
334     SYSTEM == SYSTEM_TRU64 || SYSTEM == SYSTEM_UNIXWARE
335 #define MP_MMAP_ANONYMOUS 1
336 #else /* SYSTEM */
337 #define MP_MMAP_ANONYMOUS 0
338 #endif /* SYSTEM */
339 #endif /* MP_MMAP_ANONYMOUS */
340 #endif /* MP_MMAP_SUPPORT */
341 
342 
343 /* The full path to a special device file which contains an infinite number of
344  * zero bytes.  This is used with mmap() in order to allocate zero-filled pages.
345  */
346 
347 #if MP_MMAP_SUPPORT
348 #ifndef MP_MMAP_FILENAME
349 #define MP_MMAP_FILENAME "/dev/zero"
350 #endif /* MP_MMAP_FILENAME */
351 #endif /* MP_MMAP_SUPPORT */
352 
353 
354 /* Indicates if a UNIX system supports the mincore() function call to
355  * determine if a memory mapping is in core.
356  */
357 
358 #ifndef MP_MINCORE_SUPPORT
359 #if defined(HAVE_CONFIG_H) && defined(HAVE_MINCORE)
360 #define MP_MINCORE_SUPPORT 1
361 #else /* HAVE_CONFIG_H && HAVE_MINCORE */
362 #if SYSTEM == SYSTEM_AIX || SYSTEM == SYSTEM_DGUX || SYSTEM == SYSTEM_DRSNX || \
363     SYSTEM == SYSTEM_FREEBSD || SYSTEM == SYSTEM_NETBSD || \
364     SYSTEM == SYSTEM_OPENBSD || SYSTEM == SYSTEM_SOLARIS || \
365     SYSTEM == SYSTEM_SUNOS || SYSTEM == SYSTEM_UNIXWARE
366 #define MP_MINCORE_SUPPORT 1
367 #else /* SYSTEM */
368 #define MP_MINCORE_SUPPORT 0
369 #endif /* SYSTEM */
370 #endif /* HAVE_CONFIG_H && HAVE_MINCORE */
371 #endif /* MP_MINCORE_SUPPORT */
372 
373 
374 /* Indicates if the system supports watch areas.  If not, then the OFLOWWATCH
375  * option will have no effect.
376  */
377 
378 #ifndef MP_WATCH_SUPPORT
379 #if SYSTEM == SYSTEM_IRIX || SYSTEM == SYSTEM_SOLARIS
380 #define MP_WATCH_SUPPORT 1
381 #else /* SYSTEM */
382 #define MP_WATCH_SUPPORT 0
383 #endif /* SYSTEM */
384 #endif /* MP_WATCH_SUPPORT */
385 
386 
387 /* Indicates if the library is being built with thread-safe support.  This is
388  * normally set in the makefile.
389  */
390 
391 #ifndef MP_THREADS_SUPPORT
392 #define MP_THREADS_SUPPORT 0
393 #endif /* MP_THREADS_SUPPORT */
394 
395 
396 /* The system-specific preprocessor macro that needs to be defined in order to
397  * compile thread-safe code.
398  */
399 
400 #if MP_THREADS_SUPPORT
401 #if TARGET == TARGET_UNIX
402 #if SYSTEM == SYSTEM_AIX
403 #ifndef _REENTRANT
404 #define _REENTRANT 1
405 #endif /* _REENTRANT */
406 #ifndef _THREAD_SAFE
407 #define _THREAD_SAFE 1
408 #endif /* _THREAD_SAFE */
409 #elif SYSTEM == SYSTEM_DGUX
410 #ifndef _POSIX4A_DRAFT6_SOURCE
411 #define _POSIX4A_DRAFT6_SOURCE 1
412 #endif /* _POSIX4A_DRAFT6_SOURCE */
413 #elif SYSTEM == SYSTEM_DYNIX
414 #ifndef _SEQUENT_THREADS
415 #define _SEQUENT_THREADS 1
416 #endif /* _SEQUENT_THREADS */
417 #elif SYSTEM == SYSTEM_IRIX
418 #ifndef _SGI_REENTRANT_FUNCTIONS
419 #define _SGI_REENTRANT_FUNCTIONS 1
420 #endif /* _SGI_REENTRANT_FUNCTIONS */
421 #elif SYSTEM == SYSTEM_LYNXOS
422 #ifndef _MULTITHREADED
423 #define _MULTITHREADED 1
424 #endif /* _MULTITHREADED */
425 #ifndef __POSIX4_D9__
426 #define __POSIX4_D9__ 1
427 #endif /* __POSIX4_D9__ */
428 #else /* SYSTEM */
429 #ifndef _REENTRANT
430 #define _REENTRANT 1
431 #endif /* _REENTRANT */
432 #endif /* SYSTEM */
433 #elif TARGET == TARGET_WINDOWS
434 #ifndef _MT
435 #define _MT 1
436 #endif /* _MT */
437 #endif /* TARGET */
438 #endif /* MP_THREADS_SUPPORT */
439 
440 
441 /* Indicates if the system supports obtaining more information from within
442  * signal handlers.  If not, then the illegal memory access signal handler will
443  * not be able to determine where the faulty address was.
444  */
445 
446 #ifndef MP_SIGINFO_SUPPORT
447 #if SYSTEM == SYSTEM_DGUX || SYSTEM == SYSTEM_DRSNX || \
448     SYSTEM == SYSTEM_DYNIX || SYSTEM == SYSTEM_HPUX || \
449     SYSTEM == SYSTEM_SINIX || SYSTEM == SYSTEM_SOLARIS || \
450     SYSTEM == SYSTEM_TRU64 || SYSTEM == SYSTEM_UNIXWARE
451 #define MP_SIGINFO_SUPPORT 1
452 #else /* SYSTEM */
453 #define MP_SIGINFO_SUPPORT 0
454 #endif /* SYSTEM */
455 #endif /* MP_SIGINFO_SUPPORT */
456 
457 
458 /* Indicates if the system supports the /proc filesystem.  If this is the case
459  * then it may be possible to obtain more information about the running process
460  * as well as controlling certain aspects of it.
461  */
462 
463 #ifndef MP_PROCFS_SUPPORT
464 #if SYSTEM == SYSTEM_DRSNX || SYSTEM == SYSTEM_FREEBSD || \
465     SYSTEM == SYSTEM_IRIX || SYSTEM == SYSTEM_LINUX || \
466     SYSTEM == SYSTEM_NETBSD || SYSTEM == SYSTEM_OPENBSD || \
467     SYSTEM == SYSTEM_SOLARIS || SYSTEM == SYSTEM_TRU64 || \
468     SYSTEM == SYSTEM_UNIXWARE
469 #define MP_PROCFS_SUPPORT 1
470 #else /* SYSTEM */
471 #define MP_PROCFS_SUPPORT 0
472 #endif /* SYSTEM */
473 #endif /* MP_PROCFS_SUPPORT */
474 
475 
476 /* The full path to the directory representing the mount point of the /proc
477  * filesystem.  This isn't fixed on a particular system, but we have to assume
478  * that it's somewhere by default.
479  */
480 
481 #if MP_PROCFS_SUPPORT
482 #ifndef MP_PROCFS_DIRNAME
483 #define MP_PROCFS_DIRNAME "/proc"
484 #endif /* MP_PROCFS_DIRNAME */
485 #endif /* MP_PROCFS_SUPPORT */
486 
487 
488 /* The filename of the command line file within /proc that allows a process to
489  * examine the arguments it was invoked with.
490  */
491 
492 #if MP_PROCFS_SUPPORT
493 #ifndef MP_PROCFS_CMDNAME
494 #if SYSTEM == SYSTEM_FREEBSD || SYSTEM == SYSTEM_LINUX || \
495     SYSTEM == SYSTEM_NETBSD || SYSTEM == SYSTEM_OPENBSD
496 #define MP_PROCFS_CMDNAME MP_PROCFS_DIRNAME "/%lu/cmdline"
497 #endif /* SYSTEM */
498 #endif /* MP_PROCFS_CMDNAME */
499 #endif /* MP_PROCFS_SUPPORT */
500 
501 
502 /* The filename of the executable file within /proc that allows a process to
503  * examine the command it was invoked with.
504  */
505 
506 #if MP_PROCFS_SUPPORT
507 #ifndef MP_PROCFS_EXENAME
508 #if SYSTEM == SYSTEM_FREEBSD || SYSTEM == SYSTEM_NETBSD || \
509     SYSTEM == SYSTEM_OPENBSD
510 #define MP_PROCFS_EXENAME MP_PROCFS_DIRNAME "/%lu/file"
511 #elif SYSTEM == SYSTEM_LINUX
512 #define MP_PROCFS_EXENAME MP_PROCFS_DIRNAME "/%lu/exe"
513 #elif SYSTEM == SYSTEM_SOLARIS || SYSTEM == SYSTEM_UNIXWARE
514 #define MP_PROCFS_EXENAME MP_PROCFS_DIRNAME "/%lu/object/a.out"
515 #endif /* SYSTEM */
516 #endif /* MP_PROCFS_EXENAME */
517 #endif /* MP_PROCFS_SUPPORT */
518 
519 
520 /* The filename of the control file within /proc that allows a process to
521  * manipulate itself by writing commands to it.
522  */
523 
524 #if MP_PROCFS_SUPPORT && MP_WATCH_SUPPORT
525 #ifndef MP_PROCFS_CTLNAME
526 #if SYSTEM == SYSTEM_IRIX
527 #define MP_PROCFS_CTLNAME MP_PROCFS_DIRNAME "/%05lu"
528 #else /* SYSTEM */
529 #define MP_PROCFS_CTLNAME MP_PROCFS_DIRNAME "/%lu/ctl"
530 #endif /* SYSTEM */
531 #endif /* MP_PROCFS_CTLNAME */
532 #endif /* MP_PROCFS_SUPPORT && MP_WATCH_SUPPORT */
533 
534 
535 /* Indicates if the compiler supports the __builtin_frame_address() and
536  * __builtin_return_address() macros, and if they should be used instead of
537  * traversing the call stack directly.  Note that this method only allows a
538  * finite number of call stack traversals per function.
539  */
540 
541 #ifndef MP_BUILTINSTACK_SUPPORT
542 #if TARGET == TARGET_AMIGA && defined(__GNUC__)
543 #define MP_BUILTINSTACK_SUPPORT 1
544 #else /* TARGET && __GNUC__ */
545 #define MP_BUILTINSTACK_SUPPORT 0
546 #endif /* TARGET && __GNUC__ */
547 #endif /* MP_BUILTINSTACK_SUPPORT */
548 
549 
550 /* The maximum number of call stack traversals per function if builtin
551  * frame address and return address support is being used.  This number must
552  * be supported by the required number of macro functions in stack.c.
553  */
554 
555 #if MP_BUILTINSTACK_SUPPORT
556 #ifndef MP_MAXSTACK
557 #if TARGET == TARGET_AMIGA && defined(__GNUC__)
558 #define MP_MAXSTACK 3
559 #else /* TARGET && __GNUC__ */
560 #define MP_MAXSTACK 8
561 #endif /* TARGET && __GNUC__ */
562 #endif /* MP_MAXSTACK */
563 #endif /* MP_BUILTINSTACK_SUPPORT */
564 
565 
566 /* Indicates if the operating system provides support routines for traversing
567  * call stacks in an external library.  This is currently only available for
568  * HP/UX, IRIX, Tru64 and Windows, but the IRIX unwind() library routine calls
569  * malloc() and free() so the non-library method of call stack traversal is
570  * used instead as it is much faster.  Note that MP_BUILTINSTACK_SUPPORT takes
571  * precedence.
572  */
573 
574 #ifndef MP_LIBRARYSTACK_SUPPORT
575 #if !MP_BUILTINSTACK_SUPPORT
576 #if (TARGET == TARGET_UNIX && (SYSTEM == SYSTEM_HPUX || \
577       SYSTEM == SYSTEM_TRU64)) || (TARGET == TARGET_WINDOWS && \
578      !defined(__GNUC__))
579 #define MP_LIBRARYSTACK_SUPPORT 1
580 #else /* TARGET && SYSTEM */
581 #define MP_LIBRARYSTACK_SUPPORT 0
582 #endif /* TARGET && SYSTEM */
583 #else /* MP_BUILTINSTACK_SUPPORT */
584 #define MP_LIBRARYSTACK_SUPPORT 0
585 #endif /* MP_BUILTINSTACK_SUPPORT */
586 #endif /* MP_LIBRARYSTACK_SUPPORT */
587 
588 
589 /* Indicates if support for full stack tracebacks is available.  This
590  * information can then be used to decide if we should compare two call stacks
591  * for the purpose of determining when memory allocations made by the alloca()
592  * family of functions go out of scope.  Otherwise we have to use a less
593  * accurate system which takes the addresses of local variables.
594  */
595 
596 #ifndef MP_FULLSTACK
597 #if MP_BUILTINSTACK_SUPPORT
598 #define MP_FULLSTACK 0
599 #elif MP_LIBRARYSTACK_SUPPORT || (TARGET == TARGET_UNIX && \
600        (ARCH == ARCH_IX86 || ARCH == ARCH_M68K || ARCH == ARCH_M88K || \
601         ARCH == ARCH_MIPS || ARCH == ARCH_POWER || ARCH == ARCH_POWERPC || \
602         ARCH == ARCH_SPARC)) || ((TARGET == TARGET_WINDOWS || \
603         TARGET == TARGET_NETWARE) && ARCH == ARCH_IX86)
604 #define MP_FULLSTACK 1
605 #else /* MP_BUILTINSTACK_SUPPORT && MP_LIBRARYSTACK_SUPPORT && ... */
606 #define MP_FULLSTACK 0
607 #endif /* MP_BUILTINSTACK_SUPPORT && MP_LIBRARYSTACK_SUPPORT && ... */
608 #endif /* MP_FULLSTACK */
609 
610 
611 /* Indicates if the system dynamic linker supports preloading a set of shared
612  * libraries specified in an environment variable.
613  */
614 
615 #ifndef MP_PRELOAD_SUPPORT
616 #if SYSTEM == SYSTEM_DGUX || SYSTEM == SYSTEM_DYNIX || \
617     SYSTEM == SYSTEM_FREEBSD || SYSTEM == SYSTEM_IRIX || \
618     SYSTEM == SYSTEM_LINUX || SYSTEM == SYSTEM_NETBSD || \
619     SYSTEM == SYSTEM_OPENBSD || SYSTEM == SYSTEM_SOLARIS || \
620     SYSTEM == SYSTEM_TRU64
621 #define MP_PRELOAD_SUPPORT 1
622 #else /* SYSTEM */
623 #define MP_PRELOAD_SUPPORT 0
624 #endif /* SYSTEM */
625 #endif /* MP_PRELOAD_SUPPORT */
626 
627 
628 /* The name of the environment variable which is used to specify a list of
629  * shared libraries to preload, and the string which is used to delimit the
630  * name of every library specified in that environment variable.
631  */
632 
633 #if MP_PRELOAD_SUPPORT
634 #ifndef MP_PRELOAD_NAME
635 #if SYSTEM == SYSTEM_IRIX || SYSTEM == SYSTEM_TRU64
636 #define MP_PRELOAD_NAME "_RLD_LIST"
637 #else /* SYSTEM */
638 #define MP_PRELOAD_NAME "LD_PRELOAD"
639 #endif /* SYSTEM */
640 #endif /* MP_PRELOAD_NAME */
641 
642 #ifndef MP_PRELOAD_SEP
643 #if SYSTEM == SYSTEM_IRIX || SYSTEM == SYSTEM_TRU64
644 #define MP_PRELOAD_SEP ":"
645 #else /* SYSTEM */
646 #define MP_PRELOAD_SEP " "
647 #endif /* SYSTEM */
648 #endif /* MP_PRELOAD_SEP */
649 #endif /* MP_PRELOAD_SUPPORT */
650 
651 
652 /* The macro function which will be used to calculate the filenames for each
653  * of the shared libraries that must be preloaded.
654  */
655 
656 #if MP_PRELOAD_SUPPORT
657 #ifndef MP_LIBNAME
658 #if SYSTEM == SYSTEM_HPUX
659 #define MP_LIBNAME(l) "lib" #l ".sl"
660 #else /* SYSTEM */
661 #define MP_LIBNAME(l) "lib" #l ".so"
662 #endif /* SYSTEM */
663 #endif /* MP_LIBNAME */
664 #endif /* MP_PRELOAD_SUPPORT */
665 
666 
667 /* The filenames of all the different categories of libraries that must be
668  * included in the lists of shared libraries to preload.
669  */
670 
671 #if MP_PRELOAD_SUPPORT
672 #ifndef MP_MPATROL_LIBS
673 #define MP_MPATROL_LIBS MP_LIBNAME(mpatrol)
674 #endif /* MP_MPATROL_LIBS */
675 
676 #ifndef MP_MPATROLMT_LIBS
677 #define MP_MPATROLMT_LIBS MP_LIBNAME(mpatrolmt)
678 #endif /* MP_MPATROLMT_LIBS */
679 
680 #ifndef MP_SYMBOL_LIBS
681 #if FORMAT == FORMAT_COFF || FORMAT == FORMAT_XCOFF
682 #define MP_SYMBOL_LIBS , MP_LIBNAME(ld)
683 #elif FORMAT == FORMAT_ELF32 || FORMAT == FORMAT_ELF64
684 #define MP_SYMBOL_LIBS , MP_LIBNAME(elf)
685 #elif FORMAT == FORMAT_BFD
686 #define MP_SYMBOL_LIBS , MP_LIBNAME(bfd), MP_LIBNAME(iberty)
687 #elif FORMAT == FORMAT_PE
688 #define MP_SYMBOL_LIBS , MP_LIBNAME(imagehlp)
689 #else /* FORMAT */
690 #define MP_SYMBOL_LIBS
691 #endif /* FORMAT */
692 #endif /* MP_SYMBOL_LIBS */
693 
694 #ifndef MP_THREADS_LIBS
695 #if SYSTEM == SYSTEM_AIX
696 #define MP_THREADS_LIBS , MP_LIBNAME(pthreads)
697 #elif SYSTEM == SYSTEM_DGUX
698 #define MP_THREADS_LIBS , MP_LIBNAME(thread)
699 #elif SYSTEM == SYSTEM_LINUX || SYSTEM == SYSTEM_SOLARIS || \
700       SYSTEM == SYSTEM_TRU64 || SYSTEM == SYSTEM_UNIXWARE
701 #define MP_THREADS_LIBS , MP_LIBNAME(pthread)
702 #else /* SYSTEM */
703 #define MP_THREADS_LIBS
704 #endif /* SYSTEM */
705 #endif /* MP_THREADS_LIBS */
706 
707 #ifndef MP_SYSTEM_LIBS
708 #if SYSTEM == SYSTEM_HPUX
709 #if MP_LIBRARYSTACK_SUPPORT
710 #define MP_SYSTEM_LIBS , MP_LIBNAME(cl)
711 #else /* MP_LIBRARYSTACK_SUPPORT */
712 #define MP_SYSTEM_LIBS
713 #endif /* MP_LIBRARYSTACK_SUPPORT */
714 #elif SYSTEM == SYSTEM_IRIX || SYSTEM == SYSTEM_TRU64
715 #if MP_LIBRARYSTACK_SUPPORT
716 #define MP_SYSTEM_LIBS , MP_LIBNAME(exc), "DEFAULT"
717 #else /* MP_LIBRARYSTACK_SUPPORT */
718 #define MP_SYSTEM_LIBS , "DEFAULT"
719 #endif /* MP_LIBRARYSTACK_SUPPORT */
720 #else /* SYSTEM */
721 #define MP_SYSTEM_LIBS
722 #endif /* SYSTEM */
723 #endif /* MP_SYSTEM_LIBS */
724 #endif /* MP_PRELOAD_SUPPORT */
725 
726 
727 /* The final lists of normal and thread-safe shared libraries to preload.
728  * These must all exist in the shared library path used by the dynamic linker,
729  * otherwise full paths to the libraries must be explicitly given.
730  */
731 
732 #if MP_PRELOAD_SUPPORT
733 #ifndef MP_PRELOAD_LIBS
734 #define MP_PRELOAD_LIBS MP_MPATROL_LIBS MP_SYMBOL_LIBS MP_SYSTEM_LIBS
735 #endif /* MP_PRELOAD_LIBS */
736 
737 #ifndef MP_PRELOADMT_LIBS
738 #define MP_PRELOADMT_LIBS MP_MPATROLMT_LIBS MP_SYMBOL_LIBS MP_THREADS_LIBS \
739                           MP_SYSTEM_LIBS
740 #endif /* MP_PRELOADMT_LIBS */
741 #endif /* MP_PRELOAD_SUPPORT */
742 
743 
744 /* Indicates if support for Parasoft Inuse is enabled.  This is a commercial
745  * product which graphically displays process memory usage and is provided as
746  * an add-on for Parasoft Insure++.
747  */
748 
749 #ifndef MP_INUSE_SUPPORT
750 #define MP_INUSE_SUPPORT 0
751 #endif /* MP_INUSE_SUPPORT */
752 
753 
754 /* Indicates if the mptrace tool should be built with support for a graphical
755  * user interface.  This is currently only available on UNIX systems running
756  * X that have the Motif or LessTif libraries.
757  */
758 
759 #ifndef MP_GUI_SUPPORT
760 #if defined(HAVE_CONFIG_H) && !defined(X_DISPLAY_MISSING)
761 #define MP_GUI_SUPPORT 1
762 #else /* HAVE_CONFIG_H && X_DISPLAY_MISSING */
763 #define MP_GUI_SUPPORT 0
764 #endif /* HAVE_CONFIG_H && X_DISPLAY_MISSING */
765 #endif /* MP_GUI_SUPPORT */
766 
767 
768 /* Indicates if the C functions defined in malloc.c are to have duplicate
769  * functions defined with an alternative name.
770  */
771 
772 #ifndef MP_ALTFUNCNAMES
773 #if TARGET == TARGET_UNIX
774 #define MP_ALTFUNCNAMES 1
775 #else /* TARGET */
776 #define MP_ALTFUNCNAMES 0
777 #endif /* TARGET */
778 #endif /* MP_ALTFUNCNAMES */
779 
780 
781 /* The macro function which will be used to calculate the alternative names
782  * for all C functions that are defined in malloc.c.
783  */
784 
785 #if MP_ALTFUNCNAMES
786 #ifndef MP_ALTFUNCNAME
787 #define MP_ALTFUNCNAME(f) _ ## f
788 #endif /* MP_ALTFUNCNAME */
789 #endif /* MP_ALTFUNCNAMES */
790 
791 
792 /* Indicates if the system supports .init and .fini sections for placing
793  * calls to routines that will be called before main() and after exit().
794  * This is only likely to be true for ELF systems.
795  */
796 
797 #ifndef MP_INIT_SUPPORT
798 #if SYSTEM == SYSTEM_DGUX || SYSTEM == SYSTEM_DRSNX || \
799     SYSTEM == SYSTEM_DYNIX || SYSTEM == SYSTEM_LINUX || \
800     SYSTEM == SYSTEM_SOLARIS || SYSTEM == SYSTEM_UNIXWARE
801 #define MP_INIT_SUPPORT 1
802 #elif SYSTEM == SYSTEM_FREEBSD || SYSTEM == SYSTEM_NETBSD || \
803       SYSTEM == SYSTEM_OPENBSD || SYSTEM == SYSTEM_SUNOS
804 #ifdef __ELF__
805 #define MP_INIT_SUPPORT 1
806 #else /* __ELF__ */
807 #define MP_INIT_SUPPORT 0
808 #endif /* __ELF__ */
809 #else /* SYSTEM */
810 #define MP_INIT_SUPPORT 0
811 #endif /* SYSTEM */
812 #endif /* MP_INIT_SUPPORT */
813 
814 
815 /* Indicates if the mpatrol library can assume that any functions whose names
816  * begin with __mp_init_* when the symbols are being read should be called
817  * when __mp_init() is called.  This also applies to functions whose names
818  * begin with __mp_fini_*, in which case they will be called when __mp_fini()
819  * is called.  This should not be enabled on systems where the address of the
820  * symbol in the object file does not represent the entry point for the
821  * resulting function and will obviously not work if the symbol has been
822  * stripped from the executable or shared library at any point.
823  */
824 
825 #ifndef MP_INITFUNC_SUPPORT
826 #if TARGET == TARGET_AMIGA || TARGET == TARGET_NETWARE || \
827     ((SYSTEM == SYSTEM_AIX || SYSTEM == SYSTEM_LYNXOS) && \
828      (ARCH == ARCH_POWER || ARCH == ARCH_POWERPC))
829 #define MP_INITFUNC_SUPPORT 0
830 #else /* TARGET && SYSTEM && ARCH */
831 #define MP_INITFUNC_SUPPORT 1
832 #endif /* TARGET && SYSTEM && ARCH */
833 #endif /* MP_INITFUNC_SUPPORT */
834 
835 
836 /* Indicates if the __mp_fini() function should be registered with atexit() in
837  * order to terminate the mpatrol library.  This is disabled by default on
838  * systems that support .init and .fini sections, or if the compiler is the GNU
839  * compiler or a C++ compiler since there are better ways to terminate the
840  * library in these cases.  However, if there are problems with the mpatrol
841  * library not being terminated at the correct point in a program's execution
842  * then try using atexit() instead.
843  */
844 
845 #ifndef MP_USE_ATEXIT
846 #if MP_INIT_SUPPORT || SYSTEM == SYSTEM_TRU64 || defined(__GNUC__) || \
847     defined(__cplusplus)
848 #define MP_USE_ATEXIT 0
849 #else /* MP_INIT_SUPPORT && SYSTEM && __GNUC__ && __cplusplus */
850 #define MP_USE_ATEXIT 1
851 #endif /* MP_INIT_SUPPORT && SYSTEM && __GNUC__ && __cplusplus */
852 #endif /* MP_USE_ATEXIT */
853 
854 
855 /* Indicates if the compiler supports the ident preprocessor directive for
856  * placing a version string in the comment section of an object file.  This
857  * is only likely to be true for ELF systems.
858  */
859 
860 #ifndef MP_IDENT_SUPPORT
861 #if SYSTEM == SYSTEM_CYGWIN || SYSTEM == SYSTEM_DGUX || \
862     SYSTEM == SYSTEM_DRSNX || SYSTEM == SYSTEM_DYNIX || \
863     SYSTEM == SYSTEM_IRIX || SYSTEM == SYSTEM_LINUX || \
864     SYSTEM == SYSTEM_SINIX || SYSTEM == SYSTEM_SOLARIS || \
865     SYSTEM == SYSTEM_TRU64 || SYSTEM == SYSTEM_UNIXWARE
866 #define MP_IDENT_SUPPORT 1
867 #elif SYSTEM == SYSTEM_FREEBSD || SYSTEM == SYSTEM_NETBSD || \
868       SYSTEM == SYSTEM_OPENBSD || SYSTEM == SYSTEM_SUNOS
869 #ifdef __ELF__
870 #define MP_IDENT_SUPPORT 1
871 #else /* __ELF__ */
872 #define MP_IDENT_SUPPORT 0
873 #endif /* __ELF__ */
874 #else /* SYSTEM */
875 #define MP_IDENT_SUPPORT 0
876 #endif /* SYSTEM */
877 #endif /* MP_IDENT_SUPPORT */
878 
879 
880 /* Indicates if the compiler supports the long long type.  This is only used
881  * to determine the minimum alignment required for a generic memory allocation.
882  */
883 
884 #ifndef MP_LONGLONG_SUPPORT
885 #if ENVIRON == ENVIRON_64 || defined(__GNUC__)
886 #define MP_LONGLONG_SUPPORT 1
887 #else /* ENVIRON && __GNUC__ */
888 #define MP_LONGLONG_SUPPORT 0
889 #endif /* ENVIRON && __GNUC__ */
890 #endif /* MP_LONGLONG_SUPPORT */
891 
892 
893 /* The format string passed to fprintf() which is used to display addresses.
894  */
895 
896 #ifndef MP_POINTER
897 #if ENVIRON == ENVIRON_64
898 #define MP_POINTER "0x%016lX"
899 #else /* ENVIRON */
900 #define MP_POINTER "0x%08lX"
901 #endif /* ENVIRON */
902 #endif /* MP_POINTER */
903 
904 
905 /* The name of the command used to invoke a text editor on a source file.
906  */
907 
908 #ifndef MP_EDITOR
909 #define MP_EDITOR "mpedit"
910 #endif /* MP_EDITOR */
911 
912 
913 /* The name of the environment variable which contains library options.
914  */
915 
916 #ifndef MP_OPTIONS
917 #define MP_OPTIONS "MPATROL_OPTIONS"
918 #endif /* MP_OPTIONS */
919 
920 
921 /* The name of the log file used to send library diagnostics to.  This may
922  * be overridden at run-time using the LOGFILE option and may contain
923  * special formatting characters.  It may also be affected by the environment
924  * variable specified in MP_LOGDIR.
925  */
926 
927 #ifndef MP_LOGFILE
928 #define MP_LOGFILE "mpatrol.log"
929 #endif /* MP_LOGFILE */
930 
931 
932 /* The name of the environment variable used to specify a directory into which
933  * all mpatrol log files should be written.  The directory specified must
934  * actually exist.
935  */
936 
937 #ifndef MP_LOGDIR
938 #define MP_LOGDIR "LOGDIR"
939 #endif /* MP_LOGDIR */
940 
941 
942 /* The name of the file used to send memory allocation profiling information
943  * to.  This may be overridden at run-time using the PROFFILE option and may
944  * contain special formatting characters.  It may also be affected by the
945  * environment variable specified in MP_PROFDIR.
946  */
947 
948 #ifndef MP_PROFFILE
949 #define MP_PROFFILE "mpatrol.out"
950 #endif /* MP_PROFFILE */
951 
952 
953 /* The name of the environment variable used to specify a directory into which
954  * all mpatrol profiling output files should be written.  The directory
955  * specified must actually exist.
956  */
957 
958 #ifndef MP_PROFDIR
959 #define MP_PROFDIR "PROFDIR"
960 #endif /* MP_PROFDIR */
961 
962 
963 /* The name of the file used to send memory allocation tracing information
964  * to.  This may be overridden at run-time using the TRACEFILE option and may
965  * contain special formatting characters.  It may also be affected by the
966  * environment variable specified in MP_TRACEDIR.
967  */
968 
969 #ifndef MP_TRACEFILE
970 #define MP_TRACEFILE "mpatrol.trace"
971 #endif /* MP_TRACEFILE */
972 
973 
974 /* The name of the environment variable used to specify a directory into which
975  * all mpatrol tracing output files should be written.  The directory
976  * specified must actually exist.
977  */
978 
979 #ifndef MP_TRACEDIR
980 #define MP_TRACEDIR "TRACEDIR"
981 #endif /* MP_TRACEDIR */
982 
983 
984 /* The magic sequence of bytes to use at the beginning and end of every
985  * profiling output file for verification purposes.  This must be exactly
986  * four bytes in length and will be truncated if it is greater than that.
987  */
988 
989 #ifndef MP_PROFMAGIC
990 #define MP_PROFMAGIC "MPTL"
991 #endif /* MP_PROFMAGIC */
992 
993 
994 /* The magic sequence of bytes to use at the beginning and end of every
995  * tracing output file for verification purposes.  This must be exactly
996  * four bytes in length and will be truncated if it is greater than that.
997  */
998 
999 #ifndef MP_TRACEMAGIC
1000 #define MP_TRACEMAGIC "MTRC"
1001 #endif /* MP_TRACEMAGIC */
1002 
1003 
1004 /* The default prefix string to use when calculating the filename of each
1005  * allocation contents file.
1006  */
1007 
1008 #ifndef MP_CONTENTSFILE
1009 #define MP_CONTENTSFILE ".mpatrol"
1010 #endif /* MP_CONTENTSFILE */
1011 
1012 
1013 /* The prefix string to print at the start of each line in the mpatrol log
1014  * file when writing user data with __mp_printf().
1015  */
1016 
1017 #ifndef MP_PRINTPREFIX
1018 #define MP_PRINTPREFIX "> "
1019 #endif /* MP_PRINTPREFIX */
1020 
1021 
1022 /* The overflow buffer size in bytes.  This may be overridden at run-time
1023  * using the OFLOWSIZE option.  The default is zero since this setting
1024  * may dramatically increase execution time if it is non-zero.
1025  */
1026 
1027 #ifndef MP_OVERFLOW
1028 #define MP_OVERFLOW 0
1029 #endif /* MP_OVERFLOW */
1030 
1031 
1032 /* The overflow byte value.  This may be overridden at run-time using the
1033  * OFLOWBYTE option.  The default is the bit pattern 0b10101010.
1034  */
1035 
1036 #ifndef MP_OVERBYTE
1037 #define MP_OVERBYTE 0xAA
1038 #endif /* MP_OVERBYTE */
1039 
1040 
1041 /* The allocation byte value.  This may be overridden at run-time using the
1042  * ALLOCBYTE option.  The default is the bit pattern 0b11111111.
1043  */
1044 
1045 #ifndef MP_ALLOCBYTE
1046 #define MP_ALLOCBYTE 0xFF
1047 #endif /* MP_ALLOCBYTE */
1048 
1049 
1050 /* The free byte value.  This may be overridden at run-time using the
1051  * FREEBYTE option.  The default is the bit pattern 0b01010101.
1052  */
1053 
1054 #ifndef MP_FREEBYTE
1055 #define MP_FREEBYTE 0x55
1056 #endif /* MP_FREEBYTE */
1057 
1058 
1059 /* The number of bytes that distinguish where medium-sized allocations
1060  * begin and small-sized allocations end for profiling purposes.  This
1061  * may be overridden at run-time using the SMALLBOUND option.
1062  */
1063 
1064 #ifndef MP_SMALLBOUND
1065 #define MP_SMALLBOUND 32
1066 #endif /* MP_SMALLBOUND */
1067 
1068 
1069 /* The number of bytes that distinguish where large-sized allocations
1070  * begin and medium-sized allocations end for profiling purposes.  This
1071  * may be overridden at run-time using the MEDIUMBOUND option.
1072  */
1073 
1074 #ifndef MP_MEDIUMBOUND
1075 #define MP_MEDIUMBOUND 256
1076 #endif /* MP_MEDIUMBOUND */
1077 
1078 
1079 /* The number of bytes that distinguish where extra large-sized allocations
1080  * begin and large-sized allocations end for profiling purposes.  This
1081  * may be overridden at run-time using the LARGEBOUND option.
1082  */
1083 
1084 #ifndef MP_LARGEBOUND
1085 #define MP_LARGEBOUND 2048
1086 #endif /* MP_LARGEBOUND */
1087 
1088 
1089 /* Ensure that the small allocation boundary is less than the medium
1090  * allocation boundary and the medium allocation boundary is less than the
1091  * large allocation boundary.
1092  */
1093 
1094 #if MP_SMALLBOUND >= MP_MEDIUMBOUND || MP_MEDIUMBOUND >= MP_LARGEBOUND
1095 #error allocation boundary overlap
1096 #endif
1097 
1098 
1099 #endif /* MP_CONFIG_H */
1100