Changeset b2a0214 in rtems


Ignore:
Timestamp:
Jun 7, 2010, 9:35:01 AM (9 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
77787df
Parents:
b0e81c96
Message:

2010-06-07 Sebastian Huber <sebastian.huber@…>

  • score/include/rtems/score/heap.h: Declare _Heap_Get_first_and_last_block(). Removed Heap_Extend_status. Changed return type of _Heap_Extend() to bool.
  • score/inline/rtems/score/heap.inl: Define _Heap_Set_last_block_size().
  • score/src/heap.c: Define and use _Heap_Get_first_and_last_block().
  • score/src/heapgetinfo.c: Removed assert statements. Do not count the last block. This ensures that all size values are an integral multiple of the page size which is consistent with the other statistics.
  • score/src/heapextend.c: Implemented support for scattered heap areas.
  • score/src/heapwalk.c: Dump also last block. Changes for new first and last block values.
  • ./score/src/pheapextend.c, rtems/src/regionextend.c: Update for _Heap_Extend() changes.
Location:
cpukit
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    rb0e81c96 rb2a0214  
     12010-06-07      Sebastian Huber <sebastian.huber@embedded-brains.de>
     2
     3        * score/include/rtems/score/heap.h: Declare
     4        _Heap_Get_first_and_last_block().  Removed Heap_Extend_status.
     5        Changed return type of _Heap_Extend() to bool.
     6        * score/inline/rtems/score/heap.inl: Define
     7        _Heap_Set_last_block_size().
     8        * score/src/heap.c: Define and use _Heap_Get_first_and_last_block().
     9        * score/src/heapgetinfo.c: Removed assert statements.  Do not count
     10        the last block.  This ensures that all size values are an integral
     11        multiple of the page size which is consistent with the other
     12        statistics.
     13        * score/src/heapextend.c: Implemented support for scattered heap
     14        areas.
     15        * score/src/heapwalk.c: Dump also last block.  Changes for new first
     16        and last block values.
     17        * ./score/src/pheapextend.c, rtems/src/regionextend.c: Update for
     18        _Heap_Extend() changes.
     19
    1202010-06-03      Chris Johns <chrisj@rtems.org>
    221
  • cpukit/rtems/src/regionextend.c

    rb0e81c96 rb2a0214  
    5050{
    5151  uintptr_t           amount_extended;
    52   Heap_Extend_status  heap_status;
     52  bool                extend_ok;
    5353  Objects_Locations   location;
    5454  rtems_status_code   return_status;
     
    6565      case OBJECTS_LOCAL:
    6666
    67         heap_status = _Heap_Extend(
     67        extend_ok = _Heap_Extend(
    6868          &the_region->Memory,
    6969          starting_address,
     
    7272        );
    7373
    74         if ( heap_status == HEAP_EXTEND_SUCCESSFUL ) {
     74        if ( extend_ok ) {
    7575          the_region->length                += amount_extended;
    7676          the_region->maximum_segment_size  += amount_extended;
    7777          return_status = RTEMS_SUCCESSFUL;
    78         } else if ( heap_status == HEAP_EXTEND_ERROR ) {
     78        } else {
    7979          return_status = RTEMS_INVALID_ADDRESS;
    80         } else /* if ( heap_status ==  HEAP_EXTEND_NOT_IMPLEMENTED ) */ {
    81           return_status = RTEMS_NOT_IMPLEMENTED;
    8280        }
    8381        break;
  • cpukit/score/include/rtems/score/heap.h

    rb0e81c96 rb2a0214  
    9393 *   <tr>
    9494 *     <td>first_block->prev_size</td>
    95  *     <td colspan=2>page size (the value is arbitrary)</td>
     95 *     <td colspan=2>
     96 *       subordinate heap area end address (this will be used to maintain a
     97 *       linked list of scattered heap areas)
     98 *     </td>
    9699 *   </tr>
    97100 *   <tr>
     
    312315
    313316/**
    314  * @brief See _Heap_Extend().
    315  */
    316 typedef enum {
    317   HEAP_EXTEND_SUCCESSFUL,
    318   HEAP_EXTEND_ERROR,
    319   HEAP_EXTEND_NOT_IMPLEMENTED
    320 } Heap_Extend_status;
    321 
    322 /**
    323317 * @brief See _Heap_Resize_block().
    324318 */
     
    330324
    331325/**
     326 * @brief Gets the first and last block for the heap area with begin
     327 * @a heap_area_begin and size @a heap_area_size.
     328 *
     329 * A page size of @a page_size and minimal block size of @a min_block_size will
     330 * be used for calculation.
     331 *
     332 * Nothing will be written to this area.
     333 *
     334 * In case of success the pointers to the first and last block will be returned
     335 * via @a first_block_ptr and @a last_block_ptr.
     336 *
     337 * Returns @c true if the area is big enough, and @c false otherwise.
     338 */
     339bool _Heap_Get_first_and_last_block(
     340  uintptr_t heap_area_begin,
     341  uintptr_t heap_area_size,
     342  uintptr_t page_size,
     343  uintptr_t min_block_size,
     344  Heap_Block **first_block_ptr,
     345  Heap_Block **last_block_ptr
     346);
     347
     348/**
    332349 * @brief Initializes the heap control block @a heap to manage the area
    333350 * starting at @a area_begin of size @a area_size bytes.
     
    351368 *
    352369 * The extended space available for allocation will be returned in
    353  * @a amount_extended.
    354  *
    355  * The memory area must start at the end of the currently used memory area.
    356  */
    357 Heap_Extend_status _Heap_Extend(
     370 * @a amount_extended.  This pointer may be @c NULL.
     371 *
     372 * The memory area must be big enough to contain some maintainance blocks.  It
     373 * must not overlap parts of the current heap areas.  Disconnected subordinate
     374 * heap areas will lead to used blocks which cover the gaps.
     375 *
     376 * Returns @c true in case of success, and @c false otherwise.
     377 */
     378bool _Heap_Extend(
    358379  Heap_Control *heap,
    359380  void *area_begin,
     
    369390 *
    370391 * If the boundary parameter @a boundary is not equal to zero, the allocated
    371  * memory area will fulfill a boundary constraint.  The boudnary value
     392 * memory area will fulfill a boundary constraint.  The boundary value
    372393 * specifies the set of addresses which are aligned by the boundary value.  The
    373394 * interior of the allocated memory area will not contain an element of this
  • cpukit/score/inline/rtems/score/heap.inl

    rb0e81c96 rb2a0214  
    201201
    202202/**
     203 * @brief Sets the size of the last block for heap @a heap.
     204 *
     205 * The next block of the last block will be the first block.  Since the first
     206 * block indicates that the previous block is used, this ensures that the last
     207 * block appears as used for the _Heap_Is_used() and _Heap_Is_free() functions.
     208 *
     209 * This feature will be used to terminate the scattered heap area list.  See
     210 * also _Heap_Extend().
     211 */
     212RTEMS_INLINE_ROUTINE void _Heap_Set_last_block_size( Heap_Control *heap )
     213{
     214  _Heap_Block_set_size(
     215    heap->last_block,
     216    (uintptr_t) heap->first_block - (uintptr_t) heap->last_block
     217  );
     218}
     219
     220/**
    203221 * @brief Returns the size of the allocatable area in bytes.
    204222 *
  • cpukit/score/src/heap.c

    rb0e81c96 rb2a0214  
    1111 *  On-Line Applications Research Corporation (OAR).
    1212 *
    13  *  Copyright (c) 2009 embedded brains GmbH.
     13 *  Copyright (c) 2009, 2010 embedded brains GmbH.
    1414 *
    1515 *  The license and distribution terms for this file may be
     
    124124 */
    125125
    126 uintptr_t _Heap_Initialize(
    127   Heap_Control *heap,
    128   void *heap_area_begin_ptr,
     126bool _Heap_Get_first_and_last_block(
     127  uintptr_t heap_area_begin,
    129128  uintptr_t heap_area_size,
    130   uintptr_t page_size
    131 )
    132 {
    133   Heap_Statistics *const stats = &heap->stats;
    134   uintptr_t const heap_area_begin = (uintptr_t) heap_area_begin_ptr;
     129  uintptr_t page_size,
     130  uintptr_t min_block_size,
     131  Heap_Block **first_block_ptr,
     132  Heap_Block **last_block_ptr
     133)
     134{
    135135  uintptr_t const heap_area_end = heap_area_begin + heap_area_size;
    136   uintptr_t alloc_area_begin = heap_area_begin + HEAP_BLOCK_HEADER_SIZE;
    137   uintptr_t alloc_area_size = 0;
    138   uintptr_t first_block_begin = 0;
    139   uintptr_t first_block_size = 0;
    140   uintptr_t min_block_size = 0;
    141   uintptr_t overhead = 0;
    142   Heap_Block *first_block = NULL;
    143   Heap_Block *last_block = NULL;
    144 
    145   if ( page_size == 0 ) {
    146     page_size = CPU_ALIGNMENT;
    147   } else {
    148     page_size = _Heap_Align_up( page_size, CPU_ALIGNMENT );
    149 
    150     if ( page_size < CPU_ALIGNMENT ) {
    151       /* Integer overflow */
    152       return 0;
    153     }
    154   }
    155   min_block_size = _Heap_Align_up( sizeof( Heap_Block ), page_size );
    156 
    157   alloc_area_begin = _Heap_Align_up( alloc_area_begin, page_size );
    158   first_block_begin = alloc_area_begin - HEAP_BLOCK_HEADER_SIZE;
    159   overhead = HEAP_BLOCK_HEADER_SIZE + (first_block_begin - heap_area_begin);
    160   first_block_size = heap_area_size - overhead;
    161   first_block_size = _Heap_Align_down ( first_block_size, page_size );
    162   alloc_area_size = first_block_size - HEAP_BLOCK_HEADER_SIZE;
     136  uintptr_t const alloc_area_begin =
     137    _Heap_Align_up( heap_area_begin + HEAP_BLOCK_HEADER_SIZE, page_size );
     138  uintptr_t const first_block_begin =
     139    alloc_area_begin - HEAP_BLOCK_HEADER_SIZE;
     140  uintptr_t const overhead =
     141    HEAP_BLOCK_HEADER_SIZE + (first_block_begin - heap_area_begin);
     142  uintptr_t const first_block_size =
     143    _Heap_Align_down( heap_area_size - overhead, page_size );
     144  Heap_Block *const first_block = (Heap_Block *) first_block_begin;
     145  Heap_Block *const last_block =
     146    _Heap_Block_at( first_block, first_block_size );
    163147
    164148  if (
     
    168152  ) {
    169153    /* Invalid area or area too small */
     154    return false;
     155  }
     156
     157  *first_block_ptr = first_block;
     158  *last_block_ptr = last_block;
     159
     160  return true;
     161}
     162
     163uintptr_t _Heap_Initialize(
     164  Heap_Control *heap,
     165  void *heap_area_begin_ptr,
     166  uintptr_t heap_area_size,
     167  uintptr_t page_size
     168)
     169{
     170  Heap_Statistics *const stats = &heap->stats;
     171  uintptr_t const heap_area_begin = (uintptr_t) heap_area_begin_ptr;
     172  uintptr_t const heap_area_end = heap_area_begin + heap_area_size;
     173  uintptr_t first_block_begin = 0;
     174  uintptr_t first_block_size = 0;
     175  uintptr_t last_block_begin = 0;
     176  uintptr_t min_block_size = 0;
     177  bool area_ok = false;
     178  Heap_Block *first_block = NULL;
     179  Heap_Block *last_block = NULL;
     180
     181  if ( page_size == 0 ) {
     182    page_size = CPU_ALIGNMENT;
     183  } else {
     184    page_size = _Heap_Align_up( page_size, CPU_ALIGNMENT );
     185
     186    if ( page_size < CPU_ALIGNMENT ) {
     187      /* Integer overflow */
     188      return 0;
     189    }
     190  }
     191  min_block_size = _Heap_Align_up( sizeof( Heap_Block ), page_size );
     192
     193  area_ok = _Heap_Get_first_and_last_block(
     194    heap_area_begin,
     195    heap_area_size,
     196    page_size,
     197    min_block_size,
     198    &first_block,
     199    &last_block
     200  );
     201  if ( !area_ok ) {
    170202    return 0;
    171203  }
    172204
     205  first_block_begin = (uintptr_t) first_block;
     206  last_block_begin = (uintptr_t) last_block;
     207  first_block_size = last_block_begin - first_block_begin;
     208
    173209  /* First block */
    174   first_block = (Heap_Block *) first_block_begin;
    175   first_block->prev_size = page_size;
     210  first_block->prev_size = heap_area_end;
    176211  first_block->size_and_flag = first_block_size | HEAP_PREV_BLOCK_USED;
    177212  first_block->next = _Heap_Free_list_tail( heap );
    178213  first_block->prev = _Heap_Free_list_head( heap );
    179 
    180   /*
    181    * Last block.
    182    *
    183    * The next block of the last block is the first block.  Since the first
    184    * block indicates that the previous block is used, this ensures that the
    185    * last block appears as used for the _Heap_Is_used() and _Heap_Is_free()
    186    * functions.
    187    */
    188   last_block = _Heap_Block_at( first_block, first_block_size );
    189   last_block->prev_size = first_block_size;
    190   last_block->size_and_flag = first_block_begin - (uintptr_t) last_block;
    191214
    192215  /* Heap control */
     
    199222  _Heap_Free_list_head( heap )->next = first_block;
    200223  _Heap_Free_list_tail( heap )->prev = first_block;
     224
     225  /* Last block */
     226  last_block->prev_size = first_block_size;
     227  last_block->size_and_flag = 0;
     228  _Heap_Set_last_block_size( heap );
    201229
    202230  /* Statistics */
     
    223251  );
    224252
    225   return alloc_area_size;
     253  return first_block_size;
    226254}
    227255
  • cpukit/score/src/heapextend.c

    rb0e81c96 rb2a0214  
    1111 *  On-Line Applications Research Corporation (OAR).
    1212 *
     13 *  Copyright (c) 2010 embedded brains GmbH.
     14 *
    1315 *  The license and distribution terms for this file may be
    1416 *  found in the file LICENSE in this distribution or at
     
    2628#include <rtems/score/heap.h>
    2729
    28 Heap_Extend_status _Heap_Extend(
     30static void _Heap_Free_block( Heap_Control *heap, Heap_Block *block )
     31{
     32  Heap_Statistics *const stats = &heap->stats;
     33
     34  /* Statistics */
     35  ++stats->used_blocks;
     36  --stats->frees;
     37
     38  _Heap_Free( heap, (void *) _Heap_Alloc_area_of_block( block ));
     39}
     40
     41static void _Heap_Merge_below(
    2942  Heap_Control *heap,
    30   void *area_begin_ptr,
    31   uintptr_t area_size,
    32   uintptr_t *amount_extended
     43  uintptr_t extend_area_begin,
     44  Heap_Block *first_block
     45)
     46{
     47  uintptr_t const page_size = heap->page_size;
     48  uintptr_t const new_first_block_alloc_begin =
     49    _Heap_Align_up( extend_area_begin + HEAP_BLOCK_HEADER_SIZE, page_size );
     50  uintptr_t const new_first_block_begin =
     51    new_first_block_alloc_begin - HEAP_BLOCK_HEADER_SIZE;
     52  uintptr_t const first_block_begin = (uintptr_t) first_block;
     53  uintptr_t const new_first_block_size =
     54    first_block_begin - new_first_block_begin;
     55  Heap_Block *const new_first_block = (Heap_Block *) new_first_block_begin;
     56
     57  new_first_block->prev_size = first_block->prev_size;
     58  new_first_block->size_and_flag = new_first_block_size | HEAP_PREV_BLOCK_USED;
     59
     60  _Heap_Free_block( heap, new_first_block );
     61}
     62
     63static void _Heap_Merge_above(
     64  Heap_Control *heap,
     65  Heap_Block *last_block,
     66  uintptr_t extend_area_end
     67)
     68{
     69  uintptr_t const page_size = heap->page_size;
     70  uintptr_t const last_block_begin = (uintptr_t) last_block;
     71  uintptr_t const last_block_new_size = _Heap_Align_down(
     72    extend_area_end - last_block_begin - HEAP_BLOCK_HEADER_SIZE,
     73    page_size
     74  );
     75  Heap_Block *const new_last_block =
     76    _Heap_Block_at( last_block, last_block_new_size );
     77
     78  new_last_block->size_and_flag =
     79    (last_block->size_and_flag - last_block_new_size)
     80      | HEAP_PREV_BLOCK_USED;
     81
     82  _Heap_Block_set_size( last_block, last_block_new_size );
     83
     84  _Heap_Free_block( heap, last_block );
     85}
     86
     87static void _Heap_Link_below(
     88  Heap_Block *link,
     89  Heap_Block *last_block
     90)
     91{
     92  uintptr_t const last_block_begin = (uintptr_t) last_block;
     93  uintptr_t const link_begin = (uintptr_t) link;
     94
     95  last_block->size_and_flag =
     96    (link_begin - last_block_begin) | HEAP_PREV_BLOCK_USED;
     97}
     98
     99static void _Heap_Link_above(
     100  Heap_Block *link,
     101  Heap_Block *first_block,
     102  Heap_Block *last_block
     103)
     104{
     105  uintptr_t const link_begin = (uintptr_t) link;
     106  uintptr_t const first_block_begin = (uintptr_t) first_block;
     107
     108  _Heap_Block_set_size( link, first_block_begin - link_begin );
     109
     110  last_block->size_and_flag |= HEAP_PREV_BLOCK_USED;
     111}
     112
     113bool _Heap_Extend(
     114  Heap_Control *heap,
     115  void *extend_area_begin_ptr,
     116  uintptr_t extend_area_size,
     117  uintptr_t *extended_size_ptr
    33118)
    34119{
    35120  Heap_Statistics *const stats = &heap->stats;
    36   uintptr_t const area_begin = (uintptr_t) area_begin_ptr;
    37   uintptr_t const heap_area_begin = heap->area_begin;
    38   uintptr_t const heap_area_end = heap->area_end;
    39   uintptr_t const new_heap_area_end = heap_area_end + area_size;
    40   uintptr_t extend_size = 0;
    41   Heap_Block *const last_block = heap->last_block;
    42 
    43   /*
    44    *  There are five possibilities for the location of starting
    45    *  address:
    46    *
    47    *    1. non-contiguous lower address     (NOT SUPPORTED)
    48    *    2. contiguous lower address         (NOT SUPPORTED)
    49    *    3. in the heap                      (ERROR)
    50    *    4. contiguous higher address        (SUPPORTED)
    51    *    5. non-contiguous higher address    (NOT SUPPORTED)
    52    *
    53    *  As noted, this code only supports (4).
    54    */
    55 
    56   if ( area_begin >= heap_area_begin && area_begin < heap_area_end ) {
    57     return HEAP_EXTEND_ERROR; /* case 3 */
    58   } else if ( area_begin != heap_area_end ) {
    59     return HEAP_EXTEND_NOT_IMPLEMENTED; /* cases 1, 2, and 5 */
    60   }
    61 
    62   /*
    63    *  Currently only case 4 should make it to this point.
    64    *  The basic trick is to make the extend area look like a used
    65    *  block and free it.
    66    */
    67 
    68   heap->area_end = new_heap_area_end;
    69 
    70   extend_size = new_heap_area_end
    71     - (uintptr_t) last_block - HEAP_BLOCK_HEADER_SIZE;
    72   extend_size = _Heap_Align_down( extend_size, heap->page_size );
    73 
    74   *amount_extended = extend_size;
    75 
    76   if( extend_size >= heap->min_block_size ) {
    77     Heap_Block *const new_last_block = _Heap_Block_at( last_block, extend_size );
    78 
    79     _Heap_Block_set_size( last_block, extend_size );
    80 
    81     new_last_block->size_and_flag =
    82       ((uintptr_t) heap->first_block - (uintptr_t) new_last_block)
    83         | HEAP_PREV_BLOCK_USED;
    84 
    85     heap->last_block = new_last_block;
    86 
    87     /* Statistics */
    88     stats->size += extend_size;
    89     ++stats->used_blocks;
    90     --stats->frees; /* Do not count subsequent call as actual free() */
    91 
    92     _Heap_Free( heap, (void *) _Heap_Alloc_area_of_block( last_block ));
    93   }
    94 
    95   return HEAP_EXTEND_SUCCESSFUL;
    96 }
     121  Heap_Block *const first_block = heap->first_block;
     122  Heap_Block *start_block = first_block;
     123  Heap_Block *merge_below_block = NULL;
     124  Heap_Block *merge_above_block = NULL;
     125  Heap_Block *link_below_block = NULL;
     126  Heap_Block *link_above_block = NULL;
     127  Heap_Block *extend_first_block = NULL;
     128  Heap_Block *extend_last_block = NULL;
     129  uintptr_t const page_size = heap->page_size;
     130  uintptr_t const min_block_size = heap->min_block_size;
     131  uintptr_t const extend_area_begin = (uintptr_t) extend_area_begin_ptr;
     132  uintptr_t const extend_area_end = extend_area_begin + extend_area_size;
     133  uintptr_t const free_size = stats->free_size;
     134  uintptr_t extend_first_block_size = 0;
     135  uintptr_t extended_size = 0;
     136  bool extend_area_ok = false;
     137
     138  if ( extend_area_end < extend_area_begin ) {
     139    return false;
     140  }
     141
     142  extend_area_ok = _Heap_Get_first_and_last_block(
     143    extend_area_begin,
     144    extend_area_size,
     145    page_size,
     146    min_block_size,
     147    &extend_first_block,
     148    &extend_last_block
     149  );
     150  if (!extend_area_ok ) {
     151    /* For simplicity we reject extend areas that are too small */
     152    return false;
     153  }
     154
     155  do {
     156    uintptr_t const sub_area_begin = (start_block != first_block) ?
     157      (uintptr_t) start_block : heap->area_begin;
     158    uintptr_t const sub_area_end = start_block->prev_size;
     159    Heap_Block *const end_block =
     160      _Heap_Block_of_alloc_area( sub_area_end, page_size );
     161
     162    if (
     163      sub_area_end > extend_area_begin && extend_area_end > sub_area_begin
     164    ) {
     165      return false;
     166    }
     167
     168    if ( extend_area_end == sub_area_begin ) {
     169      merge_below_block = start_block;
     170    } else if ( extend_area_end < sub_area_end ) {
     171      link_below_block = start_block;
     172    }
     173
     174    if ( sub_area_end == extend_area_begin ) {
     175      start_block->prev_size = extend_area_end;
     176
     177      merge_above_block = end_block;
     178    } else if ( sub_area_end < extend_area_begin ) {
     179      link_above_block = end_block;
     180    }
     181
     182    start_block = _Heap_Block_at( end_block, _Heap_Block_size( end_block ) );
     183  } while ( start_block != first_block );
     184
     185  if ( extend_area_begin < heap->area_begin ) {
     186    heap->area_begin = extend_area_begin;
     187  } else if ( heap->area_end < extend_area_end ) {
     188    heap->area_end = extend_area_end;
     189  }
     190
     191  extend_first_block_size =
     192    (uintptr_t) extend_last_block - (uintptr_t) extend_first_block;
     193
     194  extend_first_block->prev_size = extend_area_end;
     195  extend_first_block->size_and_flag =
     196    extend_first_block_size | HEAP_PREV_BLOCK_USED;
     197
     198  extend_last_block->prev_size = extend_first_block_size;
     199  extend_last_block->size_and_flag = 0;
     200
     201  if ( (uintptr_t) extend_first_block < (uintptr_t) heap->first_block ) {
     202    heap->first_block = extend_first_block;
     203  } else if ( (uintptr_t) extend_last_block > (uintptr_t) heap->last_block ) {
     204    heap->last_block = extend_last_block;
     205  }
     206
     207  if ( merge_below_block != NULL ) {
     208    _Heap_Merge_below( heap, extend_area_begin, merge_below_block );
     209  } else if ( link_below_block != NULL ) {
     210    _Heap_Link_below(
     211      link_below_block,
     212      extend_last_block
     213    );
     214  }
     215
     216  if ( merge_above_block != NULL ) {
     217    _Heap_Merge_above( heap, merge_above_block, extend_area_end );
     218  } else if ( link_above_block != NULL ) {
     219    _Heap_Link_above(
     220      link_above_block,
     221      extend_first_block,
     222      extend_last_block
     223    );
     224  }
     225
     226  if ( merge_below_block == NULL && merge_above_block == NULL ) {
     227    _Heap_Free_block( heap, extend_first_block );
     228  }
     229
     230  _Heap_Set_last_block_size( heap );
     231
     232  extended_size = stats->free_size - free_size;
     233
     234  /* Statistics */
     235  stats->size += extended_size;
     236
     237  if ( extended_size_ptr != NULL )
     238    *extended_size_ptr = extended_size;
     239
     240  return true;
     241}
  • cpukit/score/src/heapgetinfo.c

    rb0e81c96 rb2a0214  
    2222#endif
    2323
     24#include <string.h>
     25
    2426#include <rtems/system.h>
    2527#include <rtems/score/sysstate.h>
     
    3436  Heap_Block *const end = the_heap->last_block;
    3537
    36   _HAssert(the_block->prev_size == the_heap->page_size);
    37   _HAssert(_Heap_Is_prev_used(the_block));
    38 
    39   the_info->Free.number  = 0;
    40   the_info->Free.total   = 0;
    41   the_info->Free.largest = 0;
    42   the_info->Used.number  = 0;
    43   the_info->Used.total   = 0;
    44   the_info->Used.largest = 0;
     38  memset(the_info, 0, sizeof(*the_info));
    4539
    4640  while ( the_block != end ) {
     
    6155    the_block = next_block;
    6256  }
    63 
    64   /*
    65    *  Handle the last dummy block. Don't consider this block to be
    66    *  "used" as client never allocated it. Make 'Used.total' contain this
    67    *  blocks' overhead though.
    68    */
    69   the_info->Used.total += HEAP_BLOCK_HEADER_SIZE;
    7057}
  • cpukit/score/src/heapwalk.c

    rb0e81c96 rb2a0214  
    218218  }
    219219
    220   if ( first_block->prev_size != page_size ) {
    221     (*printer)(
    222       source,
    223       true,
    224       "first block: prev size %u != page size %u\n",
    225       first_block->prev_size,
    226       page_size
    227     );
    228 
    229     return false;
    230   }
    231 
    232220  if ( _Heap_Is_free( last_block ) ) {
    233221    (*printer)(
     
    235223      true,
    236224      "last block: is free\n"
     225    );
     226
     227    return false;
     228  }
     229
     230  if (
     231    _Heap_Block_at( last_block, _Heap_Block_size( last_block ) ) != first_block
     232  ) {
     233    (*printer)(
     234      source,
     235      true,
     236      "last block: next block is not the first block\n"
    237237    );
    238238
     
    261261    source,
    262262    false,
    263     "block 0x%08x: prev 0x%08x%s, next 0x%08x%s\n",
     263    "block 0x%08x: size %u, prev 0x%08x%s, next 0x%08x%s\n",
    264264    block,
     265    block_size,
    265266    block->prev,
    266267    block->prev == first_free_block ?
    267       " (= first)"
     268      " (= first free)"
    268269        : (block->prev == free_list_head ? " (= head)" : ""),
    269270    block->next,
    270271    block->next == last_free_block ?
    271       " (= last)"
     272      " (= last free)"
    272273        : (block->next == free_list_tail ? " (= tail)" : "")
    273274  );
     
    320321  uintptr_t const page_size = heap->page_size;
    321322  uintptr_t const min_block_size = heap->min_block_size;
     323  Heap_Block *const first_block = heap->first_block;
    322324  Heap_Block *const last_block = heap->last_block;
    323   Heap_Block *block = heap->first_block;
     325  Heap_Block *block = first_block;
    324326  Heap_Walk_printer printer = dump ?
    325327    _Heap_Walk_print : _Heap_Walk_print_nothing;
     
    333335  }
    334336
    335   while ( block != last_block ) {
     337  do {
    336338    uintptr_t const block_begin = (uintptr_t) block;
    337339    uintptr_t const block_size = _Heap_Block_size( block );
     
    339341    Heap_Block *const next_block = _Heap_Block_at( block, block_size );
    340342    uintptr_t const next_block_begin = (uintptr_t) next_block;
    341 
    342     if ( prev_used ) {
    343       (*printer)(
    344         source,
    345         false,
    346         "block 0x%08x: size %u\n",
     343    bool const is_not_last_block = block != last_block;
     344
     345    if ( !_Heap_Is_block_in_heap( heap, next_block ) ) {
     346      (*printer)(
     347        source,
     348        true,
     349        "block 0x%08x: next block 0x%08x not in heap\n",
     350        block,
     351        next_block
     352      );
     353
     354      return false;
     355    }
     356
     357    if ( !_Heap_Is_aligned( block_size, page_size ) && is_not_last_block ) {
     358      (*printer)(
     359        source,
     360        true,
     361        "block 0x%08x: block size %u not page aligned\n",
    347362        block,
    348363        block_size
    349364      );
    350     } else {
    351       (*printer)(
    352         source,
    353         false,
    354         "block 0x%08x: size %u, prev_size %u\n",
    355         block,
    356         block_size,
    357         block->prev_size
    358       );
    359     }
    360 
    361     if ( !_Heap_Is_block_in_heap( heap, next_block ) ) {
    362       (*printer)(
    363         source,
    364         true,
    365         "block 0x%08x: next block 0x%08x not in heap\n",
    366         block,
    367         next_block
    368       );
    369 
    370       return false;
    371     }
    372 
    373     if ( !_Heap_Is_aligned( block_size, page_size ) ) {
    374       (*printer)(
    375         source,
    376         true,
    377         "block 0x%08x: block size %u not page aligned\n",
    378         block,
    379         block_size
    380       );
    381 
    382       return false;
    383     }
    384 
    385     if ( block_size < min_block_size ) {
     365
     366      return false;
     367    }
     368
     369    if ( block_size < min_block_size && is_not_last_block ) {
    386370      (*printer)(
    387371        source,
     
    396380    }
    397381
    398     if ( next_block_begin <= block_begin ) {
     382    if ( next_block_begin <= block_begin && is_not_last_block ) {
    399383      (*printer)(
    400384        source,
     
    412396        return false;
    413397      }
     398    } else if (prev_used) {
     399      (*printer)(
     400        source,
     401        false,
     402        "block 0x%08x: size %u\n",
     403        block,
     404        block_size
     405      );
     406    } else {
     407      (*printer)(
     408        source,
     409        false,
     410        "block 0x%08x: size %u, prev_size %u\n",
     411        block,
     412        block_size,
     413        block->prev_size
     414      );
    414415    }
    415416
    416417    block = next_block;
    417   }
     418  } while ( block != first_block );
    418419
    419420  return true;
  • cpukit/score/src/pheapextend.c

    rb0e81c96 rb2a0214  
    3131)
    3232{
    33   Heap_Extend_status status;
    34   uintptr_t           amount_extended;
     33  bool      extend_ok;
     34  uintptr_t amount_extended;
    3535
    3636  _RTEMS_Lock_allocator();
    37     status = _Heap_Extend(the_heap, starting_address, size, &amount_extended);
     37    extend_ok = _Heap_Extend(the_heap, starting_address, size, &amount_extended);
    3838  _RTEMS_Unlock_allocator();
    39   return (status == HEAP_EXTEND_SUCCESSFUL);
     39  return extend_ok;
    4040}
    4141
Note: See TracChangeset for help on using the changeset viewer.