Reference

memalloc(3)

allocate classified memory preclassify vreclassify sreclassify - reclassify memory set_memblock_max, xrealloc, xfree - administrate classified memory

NAME

pmalloc, vmalloc, smalloc - allocate classified memory
preclassify vreclassify sreclassify - reclassify memory
set_memblock_max, xrealloc, xfree - administrate classified memory

SYNOPSIS

#include <peks.h>

void *pmalloc (size_t size),
     *vmalloc (size_t size),
     *smalloc (size_t size);

void preclassify (void *mem_ptr),
     vreclassify (void *mem_ptr),
     sreclassify (void *mem_ptr);

unsigned set_memblock_max (size_t max_size);

void *xrealloc (void *mem_ptr, size_t new_size);

void xfree (void *mem_ptr);

DESCRIPTION

The functions here provide a substitute for the standard dynamic memory functions malloc(), calloc(), free(), and realloc(). Although based on those functions, the new memory functions must not be intermixed with them: allocating memory with pmalloc() and freeing it with free() (or vv.) results in undefined system behavior and leads most certainly to a program crash.

Classified memory as allocated with pmalloc(), vmalloc(), end smalloc() comes in three flavours: public, private, and secure. All memory allocated by any of the classified memory functions is zero-initialized. The allocator functions accept 0 as a valid size argument.

Public memory allocated with pmalloc() is the same zero-initialized memory type calloc() would return, as well. The only difference is, that it cannot be reclassified (using vreclassify() for instance) and must be deallocated with free() instad of xfree().

Private memory allocated with pmalloc() is zero-initialized and will be overwritten in xfree() before given back to the operating system.

Secure memory allocated with smalloc() is handled similar to private memory but will be overwritten with random data when deallocated in xfree().

The functions preclassify(), vreclassify(), and sreclassify() reschedule the clean up procedure in xfree() to work as public, private, or secure. Argument is a memory pointer as returned from any of the allocator functions (for instance pmalloc()) for classified memory.

With xrealloc(), a memory block already allocated will be changed, or reallocated. When the memory block is extended, the new part will be zero-initialized, when it is shrunk, the deallocated part will be treated as in xfree(). The re-allocator function accepts 0 as a valid new_size argument.

All functions that return a memory pointer will not work with sizes larger than an implementation dependent default value, currently 1MBytes. With the function set_memblock_max() this maximal block size can be increased, or decreased. Function argument max_size is the new limit, to be suggested.

RETURN VALUE

All functions that return a memory pointer will never return NULL. A condition that would result in a NULL pointer causes the program to abort.

The function set_memblock_max() returns the size of the maximal data block that could be allocated when the function was invoked.

CAVEAT

Using xmalloc() for a non-public memory block will always return a new memory area while the old one is freed.

ENVIRONMENT VARIABLES

HOME

The path to the user's home directory.

SEE ALSO

malloc(3), calloc(3), free(3), realloc(3)

AUTHOR

The peks package where these functions belong to was written by Jordan Hrycaj <[email protected]>, originally to support the nessus security scanner.