From 371cea31d3cffb1e1d2ae2e865d1e9a462a3fbd6 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 26 Aug 2009 12:00:24 +0000 Subject: 2009-08-24 Sebastian Huber * libmisc/stackchk/check.c, rtems/src/regionreturnsegment.c, rtems/src/regiongetsegmentsize.c, src/heapalignupuptr.c, src/heapallocatealigned.c, src/heapallocate.c, src/heap.c, src/heapextend.c, src/heapfree.c, src/heapgetfreeinfo.c, src/heapgetinfo.c, src/heapresizeblock.c, src/heapsizeofuserarea.c, src/heapwalk.c, src/pheapgetblocksize.c, inline/rtems/score/heap.inl, include/rtems/score/heap.h: Overall cleanup. Changed all types for addresses, sizes, offsets and alignments to uintptr_t. Reformatted. Added variables for clarity. Renamed various objects. Enabled _HAssert() for all instances. More changes follow. --- cpukit/score/src/heapextend.c | 85 +++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 51 deletions(-) (limited to 'cpukit/score/src/heapextend.c') diff --git a/cpukit/score/src/heapextend.c b/cpukit/score/src/heapextend.c index 340fc84db2..bb3f301235 100644 --- a/cpukit/score/src/heapextend.c +++ b/cpukit/score/src/heapextend.c @@ -19,38 +19,21 @@ #include #include -/*PAGE - * - * _Heap_Extend - * - * This routine grows the_heap memory area using the size bytes which - * begin at starting_address. - * - * Input parameters: - * the_heap - pointer to heap header. - * starting_address - pointer to the memory area. - * size - size in bytes of the memory block to allocate. - * - * Output parameters: - * *amount_extended - amount of memory added to the_heap - */ - Heap_Extend_status _Heap_Extend( - Heap_Control *the_heap, - void *starting_address, - intptr_t size, - intptr_t *amount_extended + Heap_Control *heap, + void *area_begin_ptr, + uintptr_t area_size, + uintptr_t *amount_extended ) { - uint32_t the_size; - Heap_Statistics *const stats = &the_heap->stats; - - /* - * The overhead was taken from the original heap memory. - */ - - Heap_Block *old_final; - Heap_Block *new_final; + Heap_Statistics *const stats = &heap->stats; + uintptr_t const area_begin = (uintptr_t) area_begin_ptr; + uintptr_t const heap_area_begin = heap->begin; + uintptr_t const heap_area_end = heap->end; + uintptr_t const new_heap_area_end = heap_area_end + area_size; + uintptr_t extend_size = 0; + Heap_Block *const old_final = heap->final; + Heap_Block *new_final = NULL; /* * There are five possibilities for the location of starting @@ -65,13 +48,11 @@ Heap_Extend_status _Heap_Extend( * As noted, this code only supports (4). */ - if ( starting_address >= the_heap->begin && /* case 3 */ - starting_address < the_heap->end - ) - return HEAP_EXTEND_ERROR; - - if ( starting_address != the_heap->end ) - return HEAP_EXTEND_NOT_IMPLEMENTED; /* cases 1, 2, and 5 */ + if ( area_begin >= heap_area_begin && area_begin < heap_area_end ) { + return HEAP_EXTEND_ERROR; /* case 3 */ + } else if ( area_begin != heap_area_end ) { + return HEAP_EXTEND_NOT_IMPLEMENTED; /* cases 1, 2, and 5 */ + } /* * Currently only case 4 should make it to this point. @@ -79,26 +60,28 @@ Heap_Extend_status _Heap_Extend( * block and free it. */ - old_final = the_heap->final; - the_heap->end = _Addresses_Add_offset( the_heap->end, size ); - the_size = _Addresses_Subtract( the_heap->end, old_final ) - HEAP_OVERHEAD; - _Heap_Align_down( &the_size, the_heap->page_size ); + heap->end = new_heap_area_end; + + extend_size = new_heap_area_end + - (uintptr_t) old_final - HEAP_LAST_BLOCK_OVERHEAD; + extend_size = _Heap_Align_down( extend_size, heap->page_size ); - *amount_extended = size; + *amount_extended = extend_size; - if( the_size < the_heap->min_block_size ) - return HEAP_EXTEND_SUCCESSFUL; + if( extend_size >= heap->min_block_size ) { + old_final->size_and_flag = extend_size + | (old_final->size_and_flag & HEAP_PREV_BLOCK_USED); + new_final = _Heap_Block_at( old_final, extend_size ); + new_final->size_and_flag = heap->page_size | HEAP_PREV_BLOCK_USED; - old_final->size = the_size | (old_final->size & HEAP_PREV_USED); - new_final = _Heap_Block_at( old_final, the_size ); - new_final->size = HEAP_PREV_USED; - the_heap->final = new_final; + heap->final = new_final; - stats->size += size; - stats->used_blocks += 1; - stats->frees -= 1; /* Don't count subsequent call as actual free() */ + stats->size += area_size; + ++stats->used_blocks; + --stats->frees; /* Do not count subsequent call as actual free() */ - _Heap_Free( the_heap, _Heap_User_area( old_final ) ); + _Heap_Free( heap, (void *) _Heap_Alloc_area_of_block( old_final )); + } return HEAP_EXTEND_SUCCESSFUL; } -- cgit v1.2.3