DUMA(3)
π DUMA(3) β NAME π
okay so bestie, this is the manual page for DUMA, aka the DUMA Malloc Debugger β and yes, it's a Library Functions Manual, and yes, it's that girl. she's been catching your memory bugs since before you were born, no cap. π
β¨ SYNOPSIS β¨
here's the lineup, verbatim, no notes:
#include <stdlib.h>
void * malloc (size_t size);
void free (void *ptr);
void * realloc (void *ptr, size_t size);
void * calloc (size_t nelem, size_t elsize);
void * memalign (size_t alignment, size_t size);
void * valloc (size_t size);
extern int DUMA_ALIGNMENT;
extern int DUMA_PROTECT_BELOW;
extern int DUMA_PROTECT_FREE;
extern int DUMA_ALLOW_MALLOC_0;
extern int DUMA_FILL;
π¦ DESCRIPTION π¦
so DUMA is here to catch two of the most common programming bugs in the wild:
- software that overruns the boundaries of a
malloc()memory allocation, and - software that touches a memory allocation that's already been released by
free().
and here's the flex: unlike other malloc() debuggers, DUMA will detect read accesses as well as writes, and it will pinpoint the exact instruction that causes an error. it's been in use at Pixar since 1987, and at many other sites for years. legacy behavior, honestly. π
the way it works is iconic: DUMA uses the virtual memory hardware of your computer to place an inaccessible memory page immediately after (or before, at the user's option) each memory allocation. when software reads or writes that inaccessible page, the hardware issues a segmentation fault, stopping the program right at the offending instruction. after that it's literally trivial to find the erroneous statement using your favorite debugger. same energy for freed memory: memory released by free() gets made inaccessible, and any code that touches it gets a segmentation fault. π
simply linking your application with libduma.a will let you detect most, but not all, malloc buffer overruns and accesses of free memory. if you want to be reasonably sure you've found all bugs of this type, you'll have to read and understand the rest of this man page. sorry bestie, that's the deal. π«Ά
πΈ USAGE πΈ
link your program with the library libduma.a.
make sure you are not linking with -lmalloc, -lmallocdebug, or with other malloc-debugger or malloc-enhancer libraries. you can only use one at a time. periodt.
if your system administrator has installed DUMA for public use, you'll be able to use the -lduma argument to the linker. otherwise you'll have to put the path-name for libduma.a in the linker's command line.
you can also use dynamic linking. if you're using a Bourne shell, this statement:
export LD_PRELOAD=libduma.so.0.0
will cause DUMA to be loaded to run all dynamic executables. and the duma command runs a single command under DUMA.
some systems will require special arguments to the linker to assure that you are using the DUMA malloc() and not the one from your C library. π
run your program using a debugger. it's easier to work this way than to create a core file and post-mortem debug it. DUMA can create huge core files, and some operating systems will thus take minutes simply to dump core! π some operating systems will not create usable core files from programs that are linked with DUMA.
if your program has one of the errors detected by DUMA, it will get a segmentation fault (SIGSEGV) at the offending instruction. use the debugger to locate the erroneous statement, and repair it. slay. π₯
π GLOBAL AND ENVIRONMENT VARIABLES π
DUMA has four configuration switches that can be enabled via the shell environment, or by setting the value of global integer variables using a debugger. these switches change what bugs DUMA will detect, so it's important that you know how to use them. π
DUMA_ALIGNMENTβ this is an integer that specifies the alignment for any memory allocations that will be returned bymalloc(),calloc(), andrealloc(). the value is specified in bytes, thus a value of4will cause memory to be aligned to 32-bit boundaries β unless your system doesn't have 8-bit characters.DUMA_ALIGNMENTis set tosizeof(int)by default, since that is generally the word-size of your CPU. if your program requires that allocations be aligned to 64-bit boundaries and you have a 32-bitint, you'll have to set this value to8. this is the case when compiling with the-mips2flag on MIPS-based systems such as those from SGI. the memory allocation returned byDUMAmalloc()is aligned using the value inDUMA_ALIGNMENT, and its size is the multiple of that value that is greater than or equal to the requested size. for this reason, you will sometimes want to setDUMA_ALIGNMENTto0(no alignment), so that you can detect overruns of less than your CPU's word size. be sure to read the section WORD-ALIGNMENT AND OVERRUN DETECTION in this manual page before you try this. to change this value, setDUMA_ALIGNMENTin the shell environment to an integer value, or assign to the global integer variableDUMA_ALIGNMENTusing a debugger.DUMA_PROTECT_BELOWβDUMAusually places an inaccessible page immediately after each memory allocation, so that software that runs past the end of the allocation will be detected. settingDUMA_PROTECT_BELOWto1causesDUMAto place the inaccessible page before the allocation in the address space, so that under-runs will be detected instead of over-runs. whenDUMA_PROTECT_BELOWis set, theDUMA_ALIGNMENTparameter is ignored. all allocations will be aligned to virtual-memory-page boundaries, and their size will be the exact size that was requested. to change this value, setDUMA_PROTECT_BELOWin the shell environment to an integer value, or assign to the global integer variableDUMA_PROTECT_BELOWusing a debugger.DUMA_PROTECT_FREEβDUMAusually returns free memory to a pool from which it may be re-allocated. if you suspect that a program may be touching free memory, setDUMA_PROTECT_FREEto1. this will causeDUMAto never re-allocate memory once it has been freed, so that any access to free memory will be detected. some programs will use tremendous amounts of memory when this parameter is set. π to change this value, setDUMA_PROTECT_FREEin the shell environment to an integer value, or assign to the global integer variableDUMA_PROTECT_FREEusing a debugger.DUMA_ALLOW_MALLOC_0β by default,DUMAtraps calls tomalloc()with a size of zero, because they are often the result of a software bug. ifDUMA_ALLOW_MALLOC_0is non-zero, the software will not trap calls tomalloc()with a size of zero. to change this value, setDUMA_ALLOC_MALLOC_0in the shell environment to an integer value, or assign to the global integer variableDUMA_ALLOC_MALLOC_0using a debugger.DUMA_FILLβ when set to a value between0and255, every byte of allocated memory is initialized to that value. this can help detect reads of uninitialized memory. when set to-1, some memory is filled with zeroes (the operating system default on most systems) and some memory will retain the values written to it during its last use.DUMA_MEMCPY_OVERLAPβ setting this variable to1will makeDUMAignorememcpyregion overlapping when the destination address is less than source address. it was added as a workaround for the ARM port, where thememmoveimplementation callsmemcpyif the overlapping destination is safe and produces false aborts.
π§ WORD-ALIGNMENT AND OVERRUN DETECTION π§
there is a conflict between the alignment restrictions that malloc() operates under and the debugging strategy used by DUMA. buckle up bestie, we're getting into it. β¨
when detecting overruns, DUMA malloc() allocates two or more virtual memory pages for each allocation. the last page is made inaccessible in such a way that any read, write, or execute access will cause a segmentation fault. then, DUMA malloc() will return an address such that the first byte after the end of the allocation is on the inaccessible page. thus, any overrun of the allocation will cause a segmentation fault. π
it follows that the address returned by malloc() is the address of the inaccessible page minus the size of the memory allocation. unfortunately, malloc() is required to return word-aligned allocations, since many CPUs can only access a word when its address is aligned. the conflict happens when software makes a memory allocation using a size that is not a multiple of the word size, and expects to do word accesses to that allocation. the location of the inaccessible page is fixed by hardware at a word-aligned address. if DUMA malloc() is to return an aligned address, it must increase the size of the allocation to a multiple of the word size. in addition, the functions memalign() and valloc() must honor explicit specifications on the alignment of the memory allocation, and this, as well, can only be implemented by increasing the size of the allocation. thus, there will be situations in which the end of a memory allocation contains some padding space, and accesses of that padding space will not be detected β even if they are overruns. π
DUMA provides the variable DUMA_ALIGNMENT so that the user can control the default alignment used by malloc(), calloc(), and realloc(). to debug overruns as small as a single byte, you can set DUMA_ALIGNMENT to zero. this will result in DUMA malloc() returning unaligned addresses for allocations with sizes that are not a multiple of the word size. this is not a problem in most cases, because compilers must pad the size of objects so that alignment restrictions are honored when storing those objects in arrays. the problem surfaces when software allocates odd-sized buffers for objects that must be word-aligned. one case of this is software that allocates a buffer to contain a structure and a string, and the string has an odd size (this example was in a popular TIFF library). if word references are made to un-aligned buffers, you will see a bus error (SIGBUS) instead of a segmentation fault. the only way to fix this is to re-write the offending code to make byte references or not make odd-sized allocations, or to set DUMA_ALIGNMENT to the word size. π«Ά
another example of software incompatible with DUMA_ALIGNMENT < word-size is the strcmp() function and other string functions on SunOS (and probably Solaris), which make word-sized accesses to character strings, and may attempt to access up to three bytes beyond the end of a string. these result in a segmentation fault (SIGSEGV). the only way around this is to use versions of the string functions that perform byte references instead of word references.
bestie, we are NOT done yet β part 2 is coming, so don't go anywhere. π
π INSTRUCTIONS FOR DEBUGGING YOUR PROGRAM π
Okay bestie, here's the whole ritual, step by step. Do NOT skip steps, this is a process π
- Link with
libduma.aas explained above. (iykyk) - Run your program in a debugger and fix any overruns or accesses to free memory. This is the main character moment π«Ά
- Quit the debugger.
- Set
DUMA_PROTECT_BELOW=1in the shell environment. Now we're looking down instead of up β¨ - Repeat step 2, this time repairing underruns if they occur. Underruns are just overruns who woke up on the wrong side of the allocation π
- Quit the debugger.
- Read the restrictions in the section on WORD-ALIGNMENT AND OVERRUN DETECTION. See if you can set
DUMA_ALIGNMENTto0and repeat step 2. Sometimes this will be too much work, or there will be problems with library routines for which you don't have the source, that will prevent you from doing this.
ngl step 7 is the vibe check that humbles everybody. Sometimes it's just not happening and that's valid π
π MEMORY USAGE AND EXECUTION SPEED π
So since DUMA uses at least two virtual memory pages for each of its allocations, it's a terrible memory hog. I've sometimes found it necessary to add a swap file using swapon(8) so that the system would have enough virtual memory to debug my program. Also, the way we manipulate memory results in various cache and translation buffer entries being flushed with each call to malloc or free. The end result is that your program will be much slower and use more resources while you are debugging it with DUMA.
π¨ Don't leave libduma.a linked into production software! Use it only for debugging. Like, genuinely. This is not a drill bestie ππ₯
π AUTHOR π
Hayati Ayguen
π WARNINGS π
I have tried to do as good a job as I can on this software, but I doubt that it is even theoretically possible to make it bug-free. This software has no warranty. It will not detect some bugs that you might expect it to detect, and will indicate that some non-bugs are bugs.
fr fr. Not every red flag is a real red flag, and not every real red flag is getting caught. It's giving humbling π
π LICENSE π
Copyright 1987-1999 Bruce Perens. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, Version 2, as published by the Free Software Foundation. A copy of this license is distributed with this software in the file "COPYING".
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Read the file "COPYING" for more details.
π CONTACTING THE AUTHOR π
Bruce Perens
1563 Solano Ave. #349
Berkeley, CA 94707
Telephone: 510-526-1165
Internet: bruce@perens.com
π FILES π
/dev/zeroβ Source of memory pages (viammap(2)). The plug, basically. The infinite vibe source β¨
π¦ SEE ALSO π¦
π DIAGNOSTICS π
- Segmentation Fault β Examine the offending statement for violation of the boundaries of a memory allocation. She's telling on you bestie π«Ά
- Bus Error β See the section on WORD-ALIGNMENT AND OVERRUN DETECTION. in this manual page. π
π BUGS π
My explanation of the alignment issue could be improved.
Some Sun systems running SunOS 4.1 were reported to signal an access to a protected page with SIGBUS rather than SIGSEGV. I suspect this is an undocumented feature of a particular Sun hardware version, not just the operating system. On these systems, dumatest will fail with a bus error until you modify the Makefile to define PAGE_PROTECTION_VIOLATED_SIGNAL as SIGBUS.
There are, without doubt, other bugs and porting issues. Please contact me via e-mail if you have any bug reports, ideas, etc.
not the Sun hardware being extra for no reason π iconic behaviour, honestly
β WHAT'S BETTER β
Purify does a much more thorough job than DUMA, and does not have the huge memory overhead. Checkergcc, a modified version of the GNU C Compiler that instruments all memory references, is available on Linux systems and where GCC is used. It performs some of the same tasks as Purify, but only on code that it has compiled.
okay yes, other tools ate. But DUMA still showed up and did the work, and that counts for something π
<div align="center">
and that's the whole page, bestie!! πβ¨
this one's from 10-September-2005, and it's the DUMA(3) manual page β go forth and debug responsibly, don't ship the libduma.a, and remember: no warranty, no cap π«Άπ
</div>
π¦ where this page comes from
- debian bookworm: duma 2.5.21-6 Β· GPL-2.0-or-later
- debian trixie: duma 2.5.21-11 Β· GPL-2.0-or-later
- ubuntu jammy: duma 2.5.21-5 Β· GPL-2.0-or-later
- ubuntu noble: duma 2.5.21-8 Β· GPL-2.0-or-later
- ubuntu questing: duma 2.5.21-11
- ubuntu resolute: duma 2.5.21-11build1 Β· GPL-2.0-or-later
- ubuntu stonking: duma 2.5.21-11build1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms