Skip to content

Commit

Permalink
[UMM-53] Add UMM_CHECK_INITIALIZED() macro
Browse files Browse the repository at this point in the history
  • Loading branch information
rhempel committed May 2, 2021
1 parent 61a4358 commit 7405db5
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 23 deletions.
Binary file added src/.umm_malloc_cfg.h.swo
Binary file not shown.
6 changes: 2 additions & 4 deletions src/umm_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
UMM_HEAP_INFO ummHeapInfo;

void *umm_info(void *ptr, bool force) {
if (UMM_HEAP == NULL) {
umm_init();
}

uint16_t blockNo = 0;

UMM_CHECK_INITIALIZED();

/* Protect the critical section... */
UMM_CRITICAL_ENTRY();

Expand Down
4 changes: 1 addition & 3 deletions src/umm_integrity.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ bool umm_integrity_check(void) {
uint16_t prev;
uint16_t cur;

if (UMM_HEAP == NULL) {
umm_init();
}
UMM_CHECK_INITIALIZED();

/* Iterate through all free blocks */
prev = 0;
Expand Down
12 changes: 3 additions & 9 deletions src/umm_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,7 @@ static void umm_free_core(void *ptr) {

void umm_free(void *ptr) {

if (UMM_HEAP == NULL) {
umm_init();
}
UMM_CHECK_INITIALIZED();

/* If we're being asked to free a NULL pointer, well that's just silly! */

Expand Down Expand Up @@ -501,9 +499,7 @@ void *umm_malloc(size_t size) {

void *ptr = NULL;

if (UMM_HEAP == NULL) {
umm_init();
}
UMM_CHECK_INITIALIZED();

/*
* the very first thing we do is figure out if we're being asked to allocate
Expand Down Expand Up @@ -542,9 +538,7 @@ void *umm_realloc(void *ptr, size_t size) {

size_t curSize;

if (UMM_HEAP == NULL) {
umm_init();
}
UMM_CHECK_INITIALIZED();

/*
* This code looks after the case of a NULL value for ptr. The ANSI C
Expand Down
31 changes: 27 additions & 4 deletions src/umm_malloc_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
* sure that the configuration makes sense. For example the UMM_BLOCK_BODY_SIZE
* is a minimum of 8 and a multiple of 4.
*
* UMM_TEST_BUILD
*
* Set this if you want to compile in the test suite
*
* UMM_BLOCK_BODY_SIZE
*
* Defines the umm_block[].body size - it is 8 by default
Expand Down Expand Up @@ -82,6 +78,16 @@
* Setting this at compile time will automatically set UMM_INFO.
* Note that enabling this define will add a slight runtime penalty.
*
* UMM_CHECK_INITIALIZED
*
* Set if you want to be able to verify that the heap is intialized
* before any operation - the default is no check. You may set the
* UMM_CHECK_INITIALIZED macro to the following provided macros, or
* write your own handler:
*
* UMM_INIT_IF_UNINITIALIZED
* UMM_HANG_IF_UNINITIALIZED
*
* UMM_INTEGRITY_CHECK
*
* Set if you want to be able to verify that the heap is semantically correct
Expand All @@ -106,6 +112,9 @@
* Set n to a value from 0 to 6 depending on how verbose you want the debug
* log to be
*
* UMM_TEST_BUILD
*
* Set this if you want to compile in the test suite
* ----------------------------------------------------------------------------
*
* Support for this library in a multitasking environment is provided when
Expand All @@ -128,6 +137,20 @@

/* -------------------------------------------------------------------------- */

#ifndef UMM_INIT_IF_UNINITIALIZED
#define UMM_INIT_IF_UNINITIALIZED() do { if (UMM_HEAP == NULL) { umm_init(); } } while(0)
#endif

#ifndef UMM_HANG_IF_UNINITIALIZED
#define UMM_HANG_IF_UNINITIALIZED() do { if (UMM_HEAP == NULL) { while(1) {} } } while(0)
#endif

#ifndef UMM_CHECK_INITIALIZED
#define UMM_CHECK_INITIALIZED()
#endif

/* -------------------------------------------------------------------------- */

#ifndef UMM_BLOCK_BODY_SIZE
#define UMM_BLOCK_BODY_SIZE (8)
#endif
Expand Down
4 changes: 1 addition & 3 deletions src/umm_poison.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ bool umm_poison_check(void) {
bool ok = true;
unsigned short int cur;

if (UMM_HEAP == NULL) {
umm_init();
}
UMM_CHECK_INITIALIZED();

/* Now iterate through the blocks list */
cur = UMM_NBLOCK(0) & UMM_BLOCKNO_MASK;
Expand Down

0 comments on commit 7405db5

Please sign in to comment.