source: rtems/cpukit/score/src/heapsizeofuserarea.c @ 962e894f

4.104.114.84.95
Last change on this file since 962e894f was 962e894f, checked in by Joel Sherrill <joel.sherrill@…>, on 01/20/05 at 18:22:29

2005-01-20 Sergei Organov <osv@…>

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
  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 *  Heap Handler
3 *
4 *  COPYRIGHT (c) 1989-1999.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14
15#include <rtems/system.h>
16#include <rtems/score/sysstate.h>
17#include <rtems/score/heap.h>
18
19/*PAGE
20 *
21 *  _Heap_Size_of_user_area
22 *
23 *  This kernel routine sets '*size' to the size of the block of memory
24 *  which begins at 'starting_address'.
25 *  It returns TRUE if the 'starting_address' is in the heap, and FALSE
26 *  otherwise.
27 *
28 *  Input parameters:
29 *    the_heap         - pointer to heap header
30 *    starting_address - starting address of the memory block
31 *    size             - pointer to size of area
32 *
33 *  Output parameters:
34 *    size  - size of area filled in
35 *    TRUE  - if starting_address is valid heap address
36 *    FALSE - if starting_address is invalid heap address
37 */
38
39boolean _Heap_Size_of_user_area(
40  Heap_Control        *the_heap,
41  void                *starting_address,
42  size_t              *size
43)
44{
45  Heap_Block        *the_block;
46  Heap_Block        *next_block;
47  uint32_t           the_size;
48
49  if ( !_Addresses_Is_in_range(
50         starting_address, (void *)the_heap->start, (void *)the_heap->final ) )
51    return( FALSE );
52
53  _Heap_Start_of_block( the_heap, starting_address, &the_block );
54
55  if ( !_Heap_Is_block_in( the_heap, the_block ) )
56    return( FALSE );
57
58  the_size   = _Heap_Block_size( the_block );
59  next_block = _Heap_Block_at( the_block, the_size );
60
61  if (
62    !_Heap_Is_block_in( the_heap, next_block ) ||
63    !_Heap_Is_prev_used( next_block )
64  )
65    return( FALSE );
66
67  /* 'starting_address' could be greater than 'the_block' address plus
68     HEAP_BLOCK_USER_OFFSET as _Heap_Allocate_aligned() may produce such user
69     pointers. To get rid of this offset we calculate user size as difference
70     between the end of 'the_block' (='next_block') and 'starting_address'
71     and then add correction equal to the offset of the 'size' field of the
72     'Heap_Block' structure. The correction is due to the fact that
73     'prev_size' field of the next block is actually used as user accessible
74     area of 'the_block'. */
75
76  *size = _Addresses_Subtract ( next_block, starting_address )
77    + HEAP_BLOCK_HEADER_OFFSET;
78
79  return( TRUE );
80}
81
Note: See TracBrowser for help on using the repository browser.