The "m" Package

These routines are meant to provide a better memory allocation service than the malloc(3) call. The supplied allocation and deallocation routines perform periodic checks to see if array boundaries have been overrun. A set of memory manipulation and error message routines are also provided in this package.

Library: karma
Link With: -lkarma

Functions

m_test_accessTest if a block of memory is accessible.
m_allocAllocate Virtual Memory.
m_freeFree Virtual Memory.
m_error_notifyPrint memory error notification message.
m_abortPrint memory error notification message and abort.
m_verify_memory_integrityPeriodically verify memory integrity.
m_clearClear a block of memory
m_copyCopy a block of memory.
m_copy_blocksCopy multiple blocks of data.
m_copy_and_swap_blocksCopy and byte-swap multiple blocks of data.
m_fillFill memory blocks with a specified value.
m_cmpCompare two blocks of memory.
m_dupDuplicate a block of memory into a freshly allocated block.
m_alloc_scratchAllocate a block of scratch memory.
m_free_scratchFree the scratch memory.
m_map_fdMap a file descriptor
m_unmapUnmap a region of memory.
m_shm_test_if_availableTest if shared memory available.
m_shm_allocAllocate a shared memory segment.
m_shm_deleteDelete a shared memory segment.
m_shm_attachAttach a shared memory segment to the process address space.
m_shm_detachDetach a shared memory segment from the process address space.


Functions


EXPERIMENTAL FUNCTION: subject to change without notice

flag m_test_access (void *start, uaddr size, flag read, flag write)

Test if a block of memory is accessible.

Parameters:

Returns: TRUE if the all requested tests succeeded, else FALSE if any test failed.
Multithreading Level: Unsafe
Note:


void * m_alloc (uaddr size)

Allocate Virtual Memory.

Parameters:

Returns: A pointer to the memory on success, else NULL.
Multithreading Level: Safe under POSIX threads.
Note:


void m_free (void *ptr)

Free Virtual Memory.

Parameters:

Returns: Nothing.
Multithreading Level: Safe.
Note:


void m_error_notify (char *function_name, char *purpose)

Print memory error notification message.

Parameters:

Returns: Nothing.
Multithreading Level: Unsafe


void m_abort (char *name, char *reason)

Print memory error notification message and abort.

Parameters:

Returns: Nothing. The process aborts.
Multithreading Level: Unsafe


unsigned int m_verify_memory_integrity (flag force)

Periodically verify memory integrity.

Parameters:

Returns: The number of corrupted blocks.
Multithreading Level: Safe.


void m_clear (void *ptr, uaddr length)

Clear a block of memory

Parameters:

Returns: Nothing.
Multithreading Level: Unsafe
Note:


void m_copy (void *dest, CONST void *source, uaddr length)

Copy a block of memory.

Parameters:

Returns: Nothing.
Multithreading Level: Unsafe
Note:


void m_copy_blocks (void *dest, CONST void *source, unsigned int dest_stride, unsigned int source_stride, unsigned int block_size, unsigned int num_blocks)

Copy multiple blocks of data.

Parameters:

Returns: Nothing.
Multithreading Level: Unsafe


void m_copy_and_swap_blocks (void *dest, CONST void *source, uaddr dest_stride, uaddr source_stride, uaddr block_size, uaddr num_blocks)

Copy and byte-swap multiple blocks of data.

Parameters:

Returns: Nothing.
Multithreading Level: Unsafe


void m_fill (void *dest, uaddr stride, CONST void *source, uaddr size, unsigned int num)

Fill memory blocks with a specified value.

Parameters:

Returns: Nothing.
Multithreading Level: Unsafe


flag m_cmp (CONST void *block1, CONST void *block2, uaddr length)

Compare two blocks of memory.

Parameters:

Returns: TRUE if the blocks are equal, else FALSE.
Multithreading Level: Unsafe
Note:


void * m_dup (CONST void *original, uaddr size)

Duplicate a block of memory into a freshly allocated block.

Parameters:

Returns: A pointer to a freshly allocated block which contains identical data as the orginal on success, else NULL.
Multithreading Level: Unsafe


void * m_alloc_scratch (uaddr size, char *function_name)

This routine will allocate a block of scratch memory, which may be re-used by many different routines. The block is reserved until a call is made to m_free_scratch.

Parameters:

Returns: A pointer on success to a dynamically allocated block of memory which is valid until the next call to this routine, else NULL.
Multithreading Level: Unsafe


void m_free_scratch ()

Free the scratch memory.

Parameters:

Returns: Nothing.
Multithreading Level: Unsafe


EXPERIMENTAL FUNCTION: subject to change without notice

void * m_map_fd (int *fd, uaddr size, flag writable, flag update_on_write, flag warn_unsupported)

Map a file descriptor

Parameters:

Returns: A pointer to the mapped file on success, else NULL.
Multithreading Level: Unsafe
Note:


EXPERIMENTAL FUNCTION: subject to change without notice

flag m_unmap (void *addr, uaddr size)

Unmap a region of memory.

Parameters:

Returns: TRUE on success, else FALSE.
Multithreading Level: Unsafe


EXPERIMENTAL FUNCTION: subject to change without notice

flag m_shm_test_if_available ()

Test if shared memory available.

Parameters:

Returns: TRUE if shared memory is available, else FALSE.
Multithreading Level: Unsafe


EXPERIMENTAL FUNCTION: subject to change without notice

int m_shm_alloc (uaddr size, mode_t prot)

Allocate a shared memory segment.

Parameters:

Returns: The shared memory ID on success, else -1.
Multithreading Level: Unsafe


EXPERIMENTAL FUNCTION: subject to change without notice

void m_shm_delete (int shmid)

Delete a shared memory segment.

Parameters:

Returns: Nothing.
Multithreading Level: Unsafe


EXPERIMENTAL FUNCTION: subject to change without notice

void * m_shm_attach (int shmid, flag reattach, flag writable)

Attach a shared memory segment to the process address space.

Parameters:

Returns: The address at which the segment was attached on success, else NULL.
Multithreading Level: Unsafe


EXPERIMENTAL FUNCTION: subject to change without notice

flag m_shm_detach (void *addr)

Detach a shared memory segment from the process address space.

Parameters:

Returns: TRUE on success, else FALSE.
Multithreading Level: Unsafe


Back to Karma Home Page
Contact: Richard Gooch
Web Development: Ariel Internet Services