summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/heapsizeofuserarea.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2005-01-20 18:22:29 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2005-01-20 18:22:29 +0000
commit962e894f4ed0836a5aad472805682bb2f2c90201 (patch)
tree2bb745c9bed1353cb59f88e00da9962e649009bf /cpukit/score/src/heapsizeofuserarea.c
parent2005-01-20 Joel Sherrill <joel@OARcorp.com> (diff)
downloadrtems-962e894f4ed0836a5aad472805682bb2f2c90201.tar.bz2
2005-01-20 Sergei Organov <osv@topconrd.ru>
PR 536/rtems Heap manager re-implementation to consume less memory and still satisfy alignment requirements. * score/src/heap.c, score/src/heapallocate.c, score/src/heapextend.c, score/src/heapfree.c, score/src/heapgetinfo.c, score/src/heapgetfreeinfo.c, core/src/heapsizeofuserarea.c, score/src/heapwalk.c, core/macros/rtems/score/heap.inl, score/inline/rtems/score/heap.inl, score/include/rtems/score/heap.h: Reimplemented. * score/src/heapallocatealigned.c: new file * score/Makefile.am: HEAP_C_FILES: add score/src/heapallocatealigned.c
Diffstat (limited to 'cpukit/score/src/heapsizeofuserarea.c')
-rw-r--r--cpukit/score/src/heapsizeofuserarea.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/cpukit/score/src/heapsizeofuserarea.c b/cpukit/score/src/heapsizeofuserarea.c
index 3321816c4a..002e815bd5 100644
--- a/cpukit/score/src/heapsizeofuserarea.c
+++ b/cpukit/score/src/heapsizeofuserarea.c
@@ -20,12 +20,14 @@
*
* _Heap_Size_of_user_area
*
- * This kernel routine returns the size of the memory area
- * given heap block.
+ * This kernel routine sets '*size' to the size of the block of memory
+ * which begins at 'starting_address'.
+ * It returns TRUE if the 'starting_address' is in the heap, and FALSE
+ * otherwise.
*
* Input parameters:
* the_heap - pointer to heap header
- * starting_address - starting address of the memory block to free.
+ * starting_address - starting address of the memory block
* size - pointer to size of area
*
* Output parameters:
@@ -37,7 +39,7 @@
boolean _Heap_Size_of_user_area(
Heap_Control *the_heap,
void *starting_address,
- uint32_t *size
+ size_t *size
)
{
Heap_Block *the_block;
@@ -48,22 +50,32 @@ boolean _Heap_Size_of_user_area(
starting_address, (void *)the_heap->start, (void *)the_heap->final ) )
return( FALSE );
- the_block = _Heap_User_block_at( starting_address );
-
- if ( !_Heap_Is_block_in( the_heap, the_block ) )
- return( FALSE );
+ _Heap_Start_of_block( the_heap, starting_address, &the_block );
- if ( _Heap_Is_block_free( the_block ) )
+ if ( !_Heap_Is_block_in( the_heap, the_block ) )
return( FALSE );
the_size = _Heap_Block_size( the_block );
next_block = _Heap_Block_at( the_block, the_size );
- if ( !_Heap_Is_block_in( the_heap, next_block ) ||
- (the_block->front_flag != next_block->back_flag) )
+ if (
+ !_Heap_Is_block_in( the_heap, next_block ) ||
+ !_Heap_Is_prev_used( next_block )
+ )
return( FALSE );
- *size = the_size;
+ /* 'starting_address' could be greater than 'the_block' address plus
+ HEAP_BLOCK_USER_OFFSET as _Heap_Allocate_aligned() may produce such user
+ pointers. To get rid of this offset we calculate user size as difference
+ between the end of 'the_block' (='next_block') and 'starting_address'
+ and then add correction equal to the offset of the 'size' field of the
+ 'Heap_Block' structure. The correction is due to the fact that
+ 'prev_size' field of the next block is actually used as user accessible
+ area of 'the_block'. */
+
+ *size = _Addresses_Subtract ( next_block, starting_address )
+ + HEAP_BLOCK_HEADER_OFFSET;
+
return( TRUE );
}