static bool restoreFromZapped( cv_t *cv ) { unsigned elm_size; free_t *free_list; free_t *curr_zapped; free_t *next_zapped; // we now check to make sure freed carve blocks have not been modified // but during PCH writing, we intentionally modify a free block to // distinguish them from allocated blocks thus we have to keep them // out of the free list until we can re-zap them elm_size = cv->elm_size; free_list = cv->free_list; curr_zapped = cv->zapped_free_list; if( curr_zapped != NULL ) { cv->zapped_free_list = NULL; do { next_zapped = curr_zapped->next_free; DbgZapFreed( curr_zapped, elm_size ); _ADD_TO_FREE( free_list, curr_zapped ); curr_zapped = next_zapped; } while( curr_zapped != NULL ); cv->free_list = free_list; return( true ); } return( false ); }
static void PCHTrashAlreadyRead( void ) /*************************************/ { if( ioBuffer != NULL && ioBuffer < pch_buff_cur ) { unsigned amt = pch_buff_cur - ioBuffer; DbgZapFreed( ioBuffer, amt ); } }
void _VstkPushZapPop( VSTK_CTL *stack ) { VSTK_BLK *blk; // - current block void *cur; // - current entry size_t size; // - block size // NYI: zap on block transitions blk = stack->top; if( blk != NULL ) { cur = stack->current; if( cur != NULL ) { if( cur != blk->data ) { size = stack->size; cur = ((char*) cur ) - size; DbgZapFreed( cur, size ); } } } }
static void MakeFreeList( cv_t *cv, blk_t *newblk, unsigned offset ) /******************************************************************/ { unsigned elm_size; char * top_elm; char * bottom_elm; char * free_elm; free_t * free_list; elm_size = cv->elm_size; bottom_elm = newblk->data + offset; top_elm = newblk->data + cv->blk_top; free_list = cv->free_list; free_elm = top_elm; do { /* free_list must be maintained in order */ free_elm -= elm_size; DbgZapFreed( free_elm, elm_size ); _ADD_TO_FREE( free_list, free_elm ); } while( free_elm != bottom_elm ); cv->free_list = free_list; }
void CarveDebugFree( carve_t cv, void *elm ) { free_t *check; blk_t *block; char *compare; char *start; unsigned esize; /* make sure object hasn't been freed before */ for( check = cv->free_list; check != NULL; check = check->next_free ) { if( elm == (void *)check ) { LnkFatal( "carve: freed object was previously freed" ); } } /* make sure object is from this carve allocator */ for( block = cv->blk_list; block != NULL; block = block->next ) { start = block->data; compare = (char *)start + cv->blk_top; #if ! ( defined(__COMPACT__) || defined(__LARGE__) ) /* quick check */ if( elm < start || elm > compare ) { continue; } #endif esize = cv->elm_size; for(;;) { if( compare == start ) break; compare = (char *)compare - esize; if( elm == compare ) break; } if( elm == compare ) break; } if( block == NULL ) { LnkFatal( "carve: freed object was never allocated" ); } DbgZapFreed( elm, cv->elm_size ); }