int main(int argc, char **argv) { register_signalhandlers(); ControlBlock controlBlock = ControlBlock(); while (doRun) { controlBlock.update(); bcm2835_delay(50); } return 0; }
/* ============================================================================= Function: TestAll // local // Author: Rammi Date: 16.11.1995 Return: --- Parameter: file file pos where lib function was called Purpose: Test all allocated blocks for inconsistencies ============================================================================= */ static void TestAll(const char *file) { begin *B; /* Block iterator */ int i; /* Hash iterator */ /* make sure everything is initialized */ if (!Global.isInitialized) { Initialize(); } for (i = 0; i < HASHSIZE; i++) { B = Chain[i].Next; /* === Once around the circle === */ while (B != &Chain[i]) { ControlBlock(B, file); B = B->Next; } } }
/* ============================================================================= Function: Rmalloc_retag // external // Author: Rammi Date: 12/12/1997 Return: the pointer p for possible chaining Parameter: p pointer to allocated block (user) file called from Purpose: Change file position in header. ============================================================================= */ void * Rmalloc_retag(void *p, const char *file) { if (p) { if (!Global.isInitialized) { fprintf(stderr, HEAD "Calling RM_RETAG without having allocated block via rmalloc in\n%s", file); abort(); } begin *info = (begin *)(((char *)p)-START_SPACE); /* --- test integrity --- */ ControlBlock(info, file); /* --- change file pos --- */ info->File = file; } return p; }
/* ============================================================================= Function: Rmalloc_set_flags // external // Author: Rammi Date: 12/12/1997 Return: the pointer p for possible chaining Parameter: p pointer to allocated block (user) flags Flags to set file called from Purpose: Set flags in header ============================================================================= */ void * Rmalloc_set_flags(void *p, unsigned flags, const char *file) { #ifdef WITH_FLAGS if (p) { if (!Global.isInitialized) { fprintf(stderr, HEAD "Calling RM_SET without having allocated block via rmalloc in\n%s", file); abort(); } begin *info = (begin *)(((char *)p)-START_SPACE); /* --- test integrity --- */ ControlBlock(info, file); /* --- change flags --- */ info->Flags |= flags; } #endif return p; }
/* ============================================================================= Function: DelBlk // local // Author: Rammi Date: 16.11.1995 Return: --- Parameter: Blk block to remove file called from Purpose: Remove block from list. React angry if block is unknown ============================================================================= */ static void DelBlk(begin *Blk, const char *file) { begin *B; /* run var */ int hash = HASH(Blk); /* hash val */ if (!Global.isInitialized) { fprintf(stderr, HEAD "Calling free without having allocated block via rmalloc\n" "in call from %s", file); abort(); } /* look if block is known */ for (B = Chain[hash].Next; B != &Chain[hash]; B = B->Next) { if (B == Blk) { goto found_actual_block; /* friendly goto */ } } /* not found */ fprintf(stderr, HEAD "Double or false delete\n" "\tHeap adress of block: %p\n" "\tDetected in %s\n", ((char *)Blk)+START_SPACE, file); { void (*old_sigsegv_handler)(int) = SIG_DFL; void (*old_sigbus_handler)(int) = SIG_DFL; if (setjmp(errorbuf)) { /* uh oh, we got a kick in the ass */ signal(SIGSEGV, old_sigsegv_handler); signal(SIGBUS, old_sigbus_handler); } else { /* --- the following is dangerous! So catch signals --- */ old_sigsegv_handler = signal(SIGSEGV, FatalSignal); old_sigbus_handler = signal(SIGBUS, FatalSignal); if (IsPossibleFilePos(Blk->File, Blk->Size)) { fprintf(stderr, "\tTrying identification (may be incorrect!):\n" "\t\tAllocated in %s [%u Bytes]\n", Blk->File, (unsigned) Blk->Size); } signal(SIGSEGV, old_sigsegv_handler); signal(SIGBUS, old_sigbus_handler); } } abort(); /* die loud */ found_actual_block: #if RM_TEST_DEPTH > 1 /* check everything */ TestAll(file); #else /* test integrity of actual block */ ControlBlock(Blk, file); #endif /* remove: */ Blk->Next->Prev = Blk->Prev; Blk->Prev->Next = Blk->Next; Global.BlockCount--; #ifdef ELOQUENT fprintf(stderr, HEAD "Delete: %d Bytes allocated in %s (from %s)\n", Blk->Size, Blk->File, file); #ifdef WITH_FLAGS if (Blk->Flags & RM_STRING) { char *c; /* look for eos */ for (c = (char *)Blk + START_SPACE; c - (char *)Blk + START_SPACE < Blk->Size; c++) { if (!*c) { fprintf(stderr, HEAD "\tContains string: \"%s\"\n", (char *)Blk + START_SPACE); goto found_old_block; } } /* not found */ fprintf(stderr, HEAD "\tContains string without null byte\n"); found_old_block: ; } #endif /* WITH_FLAGS */ #endif /* ELOQUENT */ #ifdef WITH_FLAGS if (Blk->Flags & RM_STATIC) { fprintf(stderr, HEAD "WARNING: freeing block marked as STATIC (in %s)\n", file); } #endif /* WITH_FLAGS */ }