summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/heapsizeofuserarea.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2009-08-26 12:00:24 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2009-08-26 12:00:24 +0000
commit371cea31d3cffb1e1d2ae2e865d1e9a462a3fbd6 (patch)
treec407c96dda4ebe8580df10d35a12bc20dd8bc221 /cpukit/score/src/heapsizeofuserarea.c
parentAdd mpfr_provided for openSUSE 11.0 + 11.1 (diff)
downloadrtems-371cea31d3cffb1e1d2ae2e865d1e9a462a3fbd6.tar.bz2
2009-08-24 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
* 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.
Diffstat (limited to 'cpukit/score/src/heapsizeofuserarea.c')
-rw-r--r--cpukit/score/src/heapsizeofuserarea.c91
1 files changed, 38 insertions, 53 deletions
diff --git a/cpukit/score/src/heapsizeofuserarea.c b/cpukit/score/src/heapsizeofuserarea.c
index a9a276fabc..be51255eee 100644
--- a/cpukit/score/src/heapsizeofuserarea.c
+++ b/cpukit/score/src/heapsizeofuserarea.c
@@ -19,69 +19,54 @@
#include <rtems/score/sysstate.h>
#include <rtems/score/heap.h>
-/*PAGE
- *
- * _Heap_Size_of_user_area
- *
- * 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
- * size - pointer to size of area
- *
- * Output parameters:
- * size - size of area filled in
- * true - if starting_address is valid heap address
- * false - if starting_address is invalid heap address
- */
-
-bool _Heap_Size_of_user_area(
- Heap_Control *the_heap,
- void *starting_address,
- intptr_t *size
+bool _Heap_Size_of_alloc_area(
+ Heap_Control *heap,
+ void *alloc_area_begin_ptr,
+ uintptr_t *size
)
{
- Heap_Block *the_block;
- Heap_Block *next_block;
- uint32_t the_size;
+ uintptr_t alloc_area_begin = (uintptr_t) alloc_area_begin_ptr;
+ Heap_Block *block =
+ _Heap_Block_of_alloc_area( alloc_area_begin, heap->page_size );
+ Heap_Block *next_block = NULL;
+ uintptr_t block_size = 0;
- if ( !_Addresses_Is_in_range(
- starting_address, (void *)the_heap->start, (void *)the_heap->final ) )
- return( false );
+ if (
+ !_Addresses_Is_in_range( alloc_area_begin_ptr, heap->start, heap->final )
+ ) {
+ return false;
+ }
- _Heap_Start_of_block( the_heap, starting_address, &the_block );
- _HAssert(_Heap_Is_block_in( the_heap, the_block ));
- if ( !_Heap_Is_block_in( the_heap, the_block ) )
- return( false );
+ _HAssert(_Heap_Is_block_in_heap( heap, block ));
+ if ( !_Heap_Is_block_in_heap( heap, block ) ) {
+ return false;
+ }
- the_size = _Heap_Block_size( the_block );
- next_block = _Heap_Block_at( the_block, the_size );
+ block_size = _Heap_Block_size( block );
+ next_block = _Heap_Block_at( block, block_size );
- _HAssert(_Heap_Is_block_in( the_heap, next_block ));
- _HAssert(_Heap_Is_prev_used( next_block ));
+ _HAssert( _Heap_Is_block_in_heap( heap, next_block ));
+ _HAssert( _Heap_Is_prev_used( next_block ));
if (
- !_Heap_Is_block_in( the_heap, next_block ) ||
+ !_Heap_Is_block_in_heap( heap, next_block ) ||
!_Heap_Is_prev_used( next_block )
- )
- return( false );
-
- /* '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'. */
+ ) {
+ return false;
+ }
- *size = _Addresses_Subtract ( next_block, starting_address )
- + HEAP_BLOCK_HEADER_OFFSET;
+ /*
+ * 'alloc_area_begin' could be greater than 'block' address plus
+ * HEAP_BLOCK_ALLOC_AREA_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 'block' (='next_block') and
+ * 'alloc_area_begin' 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 'block'.
+ */
+ *size = (uintptr_t) next_block - alloc_area_begin + HEAP_BLOCK_SIZE_OFFSET;
- return( true );
+ return true;
}