kduma.c |
kduma.cSummary
_DUMA_SlotStruct Slot contains all of the information about a malloc buffer except for the contents of its memory. Summary
DUMA_ALIGNMENT
DUMA_ALIGNMENT is a global variable used to control the default alignment of buffers returned by malloc(), calloc(), and realloc(). It is all-caps so that its name matches the name of the environment variable that is used to set it. This gives the programmer one less name to remember. DUMA_PROTECT_BELOW
DUMA_PROTECT_BELOW is used to modify the behavior of the allocator. When its value is non-zero, the allocator will place an inaccessable page immediately before the malloc buffer in the address space, instead of after it. Use this to detect malloc buffer under-runs, rather than over-runs. It won’t detect both at the same time, so you should test your software twice, once with this value clear, and once with it set. DUMA_PROTECT_FREE
DUMA_PROTECT_FREE is used to control the disposition of memory that is released using free(). It is all-caps so that its name matches the name of the environment variable that is used to set it. If its value is non-zero, memory released by free is made inaccessable. Any software that touches free memory will then get a segmentation fault. Depending on your application and your resources you may tell DUMA not to use this memory ever again by setting a negative value f.e. -1. You can tell DUMA to limit the sum of protected memory by setting a positive value, which is interpreted in kB. If its value is zero, freed memory will be available for reallocation, but will still be inaccessable until it is reallocated. duma_init
duma_init sets configuration settings. Can sometimes cause problems when called from _duma_init. See Also: _duma_init _duma_init
_duma_init sets up the memory allocation arena and the run-time configuration information. We will call duma_init unless DUMA_EXPLICIT_INIT is defined at compile time. See Also: duma_init allocateMoreSlots
allocateMoreSlots is called when there are only enough slot structures left to support the allocation of a single malloc buffer. See Also: _duma_allocate _duma_allocate
This is the memory allocator. When asked to allocate a buffer, allocate it in such a way that the end of the buffer is followed by an inaccessable memory page. If software overruns that buffer, it will touch the bad page and get an immediate segmentation fault. It’s then easy to zero in on the offending code with a debugger. There are a few complications. If the user asks for an odd-sized buffer, we would have to have that buffer start on an odd address if the byte after the end of the buffer was to be on the inaccessable page. Unfortunately, there is lots of software that asks for odd-sized buffers and then requires that the returned address be word-aligned, or the size of the buffer be a multiple of the word size. An example are the string-processing functions on Sun systems, which do word references to the string memory and may refer to memory up to three bytes beyond the end of the string. For this reason, I take the alignment requests to memalign() and valloc() seriously, and DUMA wastes lots of memory. See Also: _duma_deallocate _duma_deallocate
Deallocate allocated memory after running some checks, then open slot for use. Uses Page_Delete to free the underlying memory. See Also: Page_Delete _duma_allocate |
KDUMA version string
static const char version[]
DUMA_ALIGNMENT is a global variable used to control the default alignment of buffers returned by malloc(), calloc(), and realloc().
size_t DUMA_ALIGNMENT
DUMA_PROTECT_BELOW is used to modify the behavior of the allocator.
int DUMA_PROTECT_BELOW
DUMA_FILL is set to 0-255 if DUMA should fill all new allocated memory with the specified value.
int DUMA_FILL
DUMA_SLACKFILL is set to 0-255.
static int DUMA_SLACKFILL
DUMA_PROTECT_FREE is used to control the disposition of memory that is released using free().
static long DUMA_PROTECT_FREE
DUMA_MAX_ALLOC is used to control the maximum memory print of the program in total: When the sum of allocated and protected memory would exceed this value in kB, the protected memory is freed/deleted.
static long DUMA_MAX_ALLOC
DUMA_ALLOW_MALLOC_0 is set if DUMA is to allow malloc(0).
static int DUMA_ALLOW_MALLOC_0
DUMA_MALLOC_FAILEXIT controls the behaviour of DUMA when malloc() fails and would return NULL.
static int DUMA_MALLOC_FAILEXIT
DUMA_FREE_ACCESS is set if DUMA is to write access memory before freeing it.
static int DUMA_FREE_ACCESS
DUMA_SHOW_ALLOC is set if DUMA is to print all allocations and deallocations to the console.
static int DUMA_SHOW_ALLOC
_DUMA_allocList points to the array of slot structures used to manage the malloc arena.
struct _DUMA_Slot * _duma_allocList
_duma_allocListSize is the size of the allocation list.
static size_t _duma_allocListSize
slotCount is the number of Slot structures in allocationList.
static size_t slotCount
unUsedSlots is the number of Slot structures that are currently available to represent new malloc buffers.
static size_t unUsedSlots
slotsPerPage is the number of slot structures that fit in a virtual memory page.
static size_t slotsPerPage
internal variable: sum of allocated -freed +protected memory in kB
static long sumAllocatedMem
internal variable: sum of allocated memory in kB
static long sumTotalAllocatedMem
internal variable: sum of protected memory in kB
static long sumProtectedMem
internal variable: number of deallocations processed so far
static long numDeallocs
internal variable: number of allocations processed so far
static long numAllocs
Print message and halt program execution in crazy way.
void _duma_assert( const char * exprstr, const char * filename, int lineno )
duma_init sets configuration settings.
void duma_init( void )
_duma_init sets up the memory allocation arena and the run-time configuration information.
void _duma_init( void )
allocateMoreSlots is called when there are only enough slot structures left to support the allocation of a single malloc buffer.
static void allocateMoreSlots( void )
This is the memory allocator.
void * _duma_allocate( size_t alignment, size_t userSize, int protectBelow, int fillByte, int protectAllocList, enum _DUMA_Allocator allocator, enum _DUMA_FailReturn fail DUMA_PARAMLIST_FL )
Deallocate allocated memory after running some checks, then open slot for use.
void _duma_deallocate( void * address, int protectAllocList, enum _DUMA_Allocator allocator DUMA_PARAMLIST_FL )
A version of kmalloc.
void * _duma_kmalloc( size_t size, int flags DUMA_PARAMLIST_FL )
Free’s DUMA allocated memory.
static void Page_Delete( void * address, size_t size )