Next: , Previous: dbmalloc, Up: Tools


8.2 Dmalloc-compatible functions

This file provides Dmalloc1-compatible functions which are built on top of the mpatrol library. They are compatible with the 4.8.2 release of Dmalloc, but only the Dmalloc-specific functions are defined here, leaving the overriding of standard functions up to the mpatrol library. As the mpatrol library does not currently override the C library string functions, neither does this file. In addition, the Dmalloc distribution comes with definitions for xmemalign(), xvalloc() and xrecalloc(), neither of which are defined by this file or by the mpatrol library.

This module is intended to work with the existing dmalloc command, which sets the contents of the DMALLOC_OPTIONS environment variable according to any specified command line options. The four documented Dmalloc global variables are also defined, although the two address variables are not acted upon and changing the dmalloc_logpath variable has no effect yet. The dmalloc_errno variable is mapped onto the __mp_errno variable and so the dmalloc_strerror() function always returns strings that are specific to the mpatrol library. Note that unlike the actual Dmalloc library, this file is not threadsafe, and the lockon option has no effect. In addition, the start option ignores the `file:line' syntax and uses allocation indices rather than events.

The dmalloc_debug() function does not support the setting of all of the Dmalloc flags, although this file defines preprocessor macros for each of them, something which is not currently done in the dmalloc.h file in the Dmalloc distribution. In fact, many of them do not make sense when applied to the mpatrol library. Some of them have slightly changed behaviour due to the mapping process and some of them cannot be implemented due to the mpatrol library having been initialised beforehand.

The dmalloc_verify() and dmalloc_examine() functions do not give an error message if the pointer passed in does not correspond to a heap allocation, and the latter function does not automatically perform an integrity check of the heap. The malloc_verify() function has not been included in this implementation since it is functionally identical to dmalloc_verify(). Note that the dmalloc_verify() function will only ever return DMALLOC_VERIFY_ERROR if the pointer to be checked is not null and is invalid — it always terminates with an error message in the mpatrol log file whenever the pointer to be checked is null and it has detected heap corruption.

The dmalloc_log_heap_map() and dmalloc_log_stats() functions map on to the __mp_memorymap() and __mp_summary() functions and so have entirely different display formats. The dmalloc_log_unfreed() and dmalloc_log_changed() functions have similar display formats to the original Dmalloc library, but the summary tables are displayed differently and will display symbol names if they are available and filename and line number information isn't. The dmalloc_message() and dmalloc_vmessage() functions write tracing to the mpatrol log file prefixed by three fields of optional information, which can be controlled by the `LOG_*' macros when building this module.

This file is initialised via the mpatrol library's initialiser function feature, which means that if the __mp_init_dmalloc() function is noted by the mpatrol symbol manager then it will be called when the mpatrol library is being initialised. If this feature is not supported then the dmalloc_init() function must be called as early on as possible, otherwise this file will not be initialised until one of its functions are called.


Footnotes

[1] Dmalloc is copyright © 1992-2001 Gray Watson.