Changeset dea3eccb in rtems


Ignore:
Timestamp:
Sep 6, 2009, 3:24:08 PM (10 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, master
Children:
f6a41d2
Parents:
6685aa09
Message:

2009-09-06 Sebastian Huber <Sebastian.Huber@…>

  • libcsupport/src/free.c, libmisc/stackchk/check.c, rtems/include/rtems/rtems/region.h, rtems/src/regioncreate.c, rtems/src/regionextend.c, rtems/src/regiongetinfo.c, rtems/src/regiongetsegment.c, rtems/src/regiongetsegmentsize.c, rtems/src/regionresizesegment.c, score/src/pheapallocate.c, score/src/pheapallocatealigned.c, score/src/pheapextend.c, score/src/pheapfree.c, score/src/pheapgetblocksize.c, score/src/pheapgetfreeinfo.c, score/src/pheapgetinfo.c, score/src/pheapgetsize.c, score/src/pheapinit.c, score/src/pheapresizeblock.c, score/src/pheapwalk.c: Update for heap API changes.
  • score/include/rtems/score/apimutex.h, score/include/rtems/score/object.h: Documentation.
  • score/include/rtems/score/heap.h, score/include/rtems/score/protectedheap.h, score/inline/rtems/score/heap.inl, score/src/heap.c, score/src/heapallocate.c, score/src/heapallocatealigned.c, score/src/heapextend.c, score/src/heapfree.c, score/src/heapgetfreeinfo.c, score/src/heapgetinfo.c, score/src/heapresizeblock.c, score/src/heapsizeofuserarea.c, score/src/heapwalk.c: Overall cleanup. Added boundary constraint to allocation function. More changes follow.
Location:
cpukit
Files:
36 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r6685aa09 rdea3eccb  
     12009-09-06      Sebastian Huber <Sebastian.Huber@embedded-brains.de>
     2
     3        * libcsupport/src/free.c, libmisc/stackchk/check.c,
     4        rtems/include/rtems/rtems/region.h, rtems/src/regioncreate.c,
     5        rtems/src/regionextend.c, rtems/src/regiongetinfo.c,
     6        rtems/src/regiongetsegment.c, rtems/src/regiongetsegmentsize.c,
     7        rtems/src/regionresizesegment.c, score/src/pheapallocate.c,
     8        score/src/pheapallocatealigned.c, score/src/pheapextend.c,
     9        score/src/pheapfree.c, score/src/pheapgetblocksize.c,
     10        score/src/pheapgetfreeinfo.c, score/src/pheapgetinfo.c,
     11        score/src/pheapgetsize.c, score/src/pheapinit.c,
     12        score/src/pheapresizeblock.c, score/src/pheapwalk.c:
     13        Update for heap API changes.
     14        * score/include/rtems/score/apimutex.h,
     15        score/include/rtems/score/object.h: Documentation.
     16        * score/include/rtems/score/heap.h,
     17        score/include/rtems/score/protectedheap.h,
     18        score/inline/rtems/score/heap.inl, score/src/heap.c,
     19        score/src/heapallocate.c, score/src/heapallocatealigned.c,
     20        score/src/heapextend.c, score/src/heapfree.c,
     21        score/src/heapgetfreeinfo.c, score/src/heapgetinfo.c,
     22        score/src/heapresizeblock.c, score/src/heapsizeofuserarea.c,
     23        score/src/heapwalk.c: Overall cleanup. Added boundary constraint to
     24        allocation function. More changes follow.
     25
    1262009-09-04      Sebastian Huber <Sebastian.Huber@embedded-brains.de>
    227
  • cpukit/libcsupport/src/free.c

    r6685aa09 rdea3eccb  
    6060    printk( "Program heap: free of bad pointer %p -- range %p - %p \n",
    6161      ptr,
    62       RTEMS_Malloc_Heap->begin,
    63       RTEMS_Malloc_Heap->end
     62      RTEMS_Malloc_Heap->area_begin,
     63      RTEMS_Malloc_Heap->area_end
    6464    );
    6565  }
  • cpukit/libmisc/stackchk/check.c

    r6685aa09 rdea3eccb  
    9393#else
    9494  #define Stack_check_Get_pattern_area( _the_stack ) \
    95     ((Stack_check_Control *) ((char *)(_the_stack)->area + HEAP_LAST_BLOCK_OVERHEAD))
     95    ((Stack_check_Control *) ((char *)(_the_stack)->area + HEAP_BLOCK_HEADER_SIZE))
    9696
    9797  #define Stack_check_Calculate_used( _low, _size, _high_water) \
  • cpukit/rtems/include/rtems/rtems/region.h

    r6685aa09 rdea3eccb  
    7070  Thread_queue_Control  Wait_queue;            /* waiting threads        */
    7171  void                 *starting_address;      /* physical start addr    */
    72   intptr_t              length;                /* physical length(bytes) */
    73   uint32_t              page_size;             /* in bytes               */
    74   intptr_t              maximum_segment_size;  /* in bytes               */
     72  uintptr_t             length;                /* physical length(bytes) */
     73  uintptr_t             page_size;             /* in bytes               */
     74  uintptr_t             maximum_segment_size;  /* in bytes               */
    7575  rtems_attribute       attribute_set;
    7676  uint32_t              number_of_used_blocks; /* blocks allocated       */
     
    105105  rtems_name          name,
    106106  void               *starting_address,
    107   intptr_t            length,
    108   uint32_t            page_size,
    109   rtems_attribute  attribute_set,
     107  uintptr_t           length,
     108  uintptr_t           page_size,
     109  rtems_attribute     attribute_set,
    110110  Objects_Id         *id
    111111);
     
    122122  Objects_Id          id,
    123123  void               *starting_address,
    124   intptr_t            length
     124  uintptr_t           length
    125125);
    126126
     
    185185rtems_status_code rtems_region_get_segment(
    186186  Objects_Id         id,
    187   intptr_t           size,
     187  uintptr_t          size,
    188188  rtems_option       option_set,
    189189  rtems_interval     timeout,
    190   void              **segment
     190  void             **segment
    191191);
    192192
     
    200200  Objects_Id         id,
    201201  void              *segment,
    202   intptr_t          *size
     202  uintptr_t         *size
    203203);
    204204
     
    242242  Objects_Id  id,
    243243  void       *segment,
    244   intptr_t    size,
    245   intptr_t   *old_size
     244  uintptr_t   size,
     245  uintptr_t  *old_size
    246246);
    247247
  • cpukit/rtems/src/regioncreate.c

    r6685aa09 rdea3eccb  
    5151  rtems_name          name,
    5252  void               *starting_address,
    53   intptr_t            length,
    54   uint32_t            page_size,
     53  uintptr_t           length,
     54  uintptr_t           page_size,
    5555  rtems_attribute     attribute_set,
    5656  Objects_Id         *id
  • cpukit/rtems/src/regionextend.c

    r6685aa09 rdea3eccb  
    4646  Objects_Id          id,
    4747  void               *starting_address,
    48   intptr_t            length
     48  uintptr_t           length
    4949)
    5050{
    51   intptr_t            amount_extended;
     51  uintptr_t           amount_extended;
    5252  Heap_Extend_status  heap_status;
    5353  Objects_Locations   location;
  • cpukit/rtems/src/regiongetinfo.c

    r6685aa09 rdea3eccb  
    6161
    6262      case OBJECTS_LOCAL:
    63         if ( _Heap_Get_information( &the_region->Memory, the_info ) !=
    64              HEAP_GET_INFORMATION_SUCCESSFUL )
    65           return_status = RTEMS_INVALID_ADDRESS;
    66         else
    67           return_status = RTEMS_SUCCESSFUL;
     63        _Heap_Get_information( &the_region->Memory, the_info );
     64        return_status = RTEMS_SUCCESSFUL;
    6865        break;
    6966
  • cpukit/rtems/src/regiongetsegment.c

    r6685aa09 rdea3eccb  
    4848rtems_status_code rtems_region_get_segment(
    4949  Objects_Id         id,
    50   intptr_t           size,
     50  uintptr_t          size,
    5151  rtems_option       option_set,
    5252  rtems_interval     timeout,
  • cpukit/rtems/src/regiongetsegmentsize.c

    r6685aa09 rdea3eccb  
    4646  Objects_Id         id,
    4747  void              *segment,
    48   intptr_t          *size
     48  uintptr_t         *size
    4949)
    5050{
  • cpukit/rtems/src/regionresizesegment.c

    r6685aa09 rdea3eccb  
    4747  Objects_Id  id,
    4848  void       *segment,
    49   intptr_t    size,
    50   intptr_t   *old_size
     49  uintptr_t   size,
     50  uintptr_t  *old_size
    5151)
    5252{
    53   intptr_t                 avail_size;
     53  uintptr_t                avail_size;
    5454  Objects_Locations        location;
    55   intptr_t                 osize;
     55  uintptr_t                osize;
    5656  rtems_status_code        return_status = RTEMS_INTERNAL_ERROR;
    5757  Heap_Resize_status       status;
  • cpukit/score/include/rtems/score/apimutex.h

    r6685aa09 rdea3eccb  
    11/**
    2  *  @file  rtems/score/apimutex.h
     2 * @file
    33 *
    4  *  This include file contains all the constants and structures associated
    5  *  with the API Mutex Handler.  This handler is used by API level
    6  *  routines to manage mutual exclusion.
     4 * @ingroup ScoreAPIMutex
     5 *
     6 * @brief API Mutex Handler API.
    77 */
    88
     
    2121#define _RTEMS_SCORE_APIMUTEX_H
    2222
    23 /**
    24  *  @defgroup ScoreAPIMutex API Mutex Handler
    25  *
    26  *  This handler encapsulates functionality which provides mutexes to be used
    27  *  in the implementation of API functionality.
    28  */
    29 /**@{*/
    30 
    3123#ifdef __cplusplus
    3224extern "C" {
    3325#endif
     26
     27/**
     28 * @defgroup ScoreAPIMutex API Mutex Handler
     29 *
     30 * @ingroup Score
     31 *
     32 * @brief Provides routines to ensure mutual exclusion on API level.
     33 *
     34 * @{
     35 */
    3436
    3537#include <rtems/score/coremutex.h>
     
    3840
    3941/**
    40  *  The following defines the control block used to manage each API mutex.
    41  *  An API Mutex is an aggregration of an Object and a SuperCore Mutex.
     42 * @brief Control block used to manage each API mutex.
    4243 */
    4344typedef struct {
    44   /** This field allows each API Mutex to be a full-fledged RTEMS object. */
    45   Objects_Control       Object;
    46   /** This field contains the SuperCore mutex information. */
    47   CORE_mutex_Control    Mutex;
    48 }   API_Mutex_Control;
     45  /**
     46   * @brief Allows each API Mutex to be a full-fledged RTEMS object.
     47   */
     48  Objects_Control Object;
     49
     50  /**
     51   * Contains the SuperCore mutex information.
     52   */
     53  CORE_mutex_Control Mutex;
     54} API_Mutex_Control;
    4955
    5056/**
    51  *  The following variable is the information control block used to manage
    52  *  this class of objects.
     57 * @brief Information control block used to manage this class of objects.
    5358 */
    54 SCORE_EXTERN Objects_Information  _API_Mutex_Information;
     59SCORE_EXTERN Objects_Information _API_Mutex_Information;
    5560
    5661/**
    57  *  This routine performs the initialization necessary for this handler.
     62 * @brief Performs the initialization necessary for this handler.
    5863 *
    59  *  @param[in] maximum_mutexes is the maximum number of API mutexes
    60  *         that may exist at any time
     64 * The value @a maximum_mutexes is the maximum number of API mutexes that may
     65 * exist at any time.
    6166 */
    62 void _API_Mutex_Initialization(
    63   uint32_t maximum_mutexes
    64 );
     67void _API_Mutex_Initialization( uint32_t maximum_mutexes );
    6568
    6669/**
    67  *  This routine allocates an API mutex from the inactive set.
    68  *
    69  *  @param[out] the_mutex will contain the allocated mutex.
     70 * @brief Allocates an API mutex from the inactive set and returns it in
     71 * @a mutex.
    7072 */
    71 void _API_Mutex_Allocate(
    72   API_Mutex_Control **the_mutex
    73 );
     73void _API_Mutex_Allocate( API_Mutex_Control **mutex );
    7474
    7575/**
    76  *  This routine acquires the specified API mutex.
    77  *
    78  *  @param[in] the_mutex is the mutex to acquire.
     76 * @brief Acquires the specified API mutex @a mutex.
    7977 */
    80 void _API_Mutex_Lock(
    81   API_Mutex_Control *the_mutex
    82 );
     78void _API_Mutex_Lock( API_Mutex_Control *mutex );
    8379
    8480/**
    85  *  This routine releases the specified API mutex.
    86  *
    87  *  @param[in] the_mutex is the mutex to release.
     81 * @brief Releases the specified API mutex @a mutex.
    8882 */
    89 void _API_Mutex_Unlock(
    90   API_Mutex_Control *the_mutex
    91 );
     83void _API_Mutex_Unlock( API_Mutex_Control *mutex );
     84
     85/** @} */
    9286
    9387/**
    94  *  This variable points to the API Mutex instance that is used
    95  *  to protect all memory allocation and deallocation in RTEMS.
     88 * @defgroup ScoreAllocatorMutex RTEMS Allocator Mutex
    9689 *
    97  *  @note When the APIs all use this for allocation and deallocation
    98  *  protection, then this possibly should be renamed and moved to a
    99  *  higher level in the hierarchy.
     90 * @ingroup ScoreAPIMutex
     91 *
     92 * @brief Protection for all memory allocations and deallocations in RTEMS.
     93 *
     94 * When the APIs all use this for allocation and deallocation protection, then
     95 * this possibly should be renamed and moved to a higher level in the
     96 * hierarchy.
     97 *
     98 * @{
    10099 */
    101 SCORE_EXTERN API_Mutex_Control  *_RTEMS_Allocator_Mutex;
    102100
    103 /**
    104  *  This macro locks the RTEMS Allocation Mutex.
    105  *
    106  *  @see _RTEMS_Allocator_Mutex
    107  */
     101SCORE_EXTERN API_Mutex_Control *_RTEMS_Allocator_Mutex;
     102
    108103#define _RTEMS_Lock_allocator() \
    109104  _API_Mutex_Lock( _RTEMS_Allocator_Mutex )
    110105
    111 /**
    112  *  This macro unlocks the RTEMS Allocation Mutex.
    113  *
    114  *  @see _RTEMS_Allocator_Mutex
    115  */
    116106#define _RTEMS_Unlock_allocator() \
    117107  _API_Mutex_Unlock( _RTEMS_Allocator_Mutex )
    118108
    119 /*
    120  *  There are no inlines for this handler.
    121  */
    122 
    123 #ifndef __RTEMS_APPLICATION__
    124 /* #include <rtems/score/apimutex.inl> */
    125 #endif
     109/** @} */
    126110
    127111#ifdef __cplusplus
     
    129113#endif
    130114
    131 /*!@}*/
    132 
    133115#endif
    134116/*  end of include file */
  • cpukit/score/include/rtems/score/heap.h

    r6685aa09 rdea3eccb  
    22 * @file
    33 *
    4  * Heap Handler API.
     4 * @ingroup ScoreHeap
     5 *
     6 * @brief Heap Handler API.
    57 */
    68
     
    2628 * @defgroup ScoreHeap Heap Handler
    2729 *
    28  * The Heap Handler provides a heap.
     30 * @ingroup Score
     31 *
     32 * @brief The Heap Handler provides a heap.
    2933 *
    3034 * A heap is a doubly linked list of variable size blocks which are allocated
     
    3438 * area.  A heap control structure contains control information for the heap.
    3539 *
    36  * FIXME: The alignment routines could be made faster should we require only
    37  * powers of two to be supported both for 'page_size' and for 'alignment'
    38  * arguments. However, both workspace and malloc heaps are initialized with
    39  * CPU_HEAP_ALIGNMENT as 'page_size', and while all the BSPs seem to use
     40 * The alignment routines could be made faster should we require only powers of
     41 * two to be supported both for page size, alignment and boundary arguments.
     42 * However, both workspace and malloc heaps are initialized with
     43 * CPU_HEAP_ALIGNMENT as page size, and while all the BSPs seem to use
    4044 * CPU_ALIGNMENT (that is power of two) as CPU_HEAP_ALIGNMENT, for whatever
    4145 * reason CPU_HEAP_ALIGNMENT is only required to be multiple of CPU_ALIGNMENT
     
    4347 *
    4448 * There are two kinds of blocks.  One sort describes a free block from which
    45  * we can allocate memory.  The other blocks are used and contain allocated
    46  * memory.  The free blocks are accessible via a list of free blocks.
     49 * we can allocate memory.  The other blocks are used and provide an allocated
     50 * memory area.  The free blocks are accessible via a list of free blocks.
     51 *
     52 * Blocks or areas cover a continuous set of memory addresses. They have a
     53 * begin and end address.  The end address is not part of the set.  The size of
     54 * a block or area equals the distance between the begin and end address in
     55 * units of bytes.
    4756 *
    4857 * Free blocks look like:
     
    8493 *   <tr><th>Label</th><th colspan=2>Content</th></tr>
    8594 *   <tr><td>heap->begin</td><td colspan=2>heap area begin address</td></tr>
    86  *   <tr><td>first_block->prev_size</td><td colspan=2>arbitrary value</td></tr>
     95 *   <tr>
     96 *     <td>first_block->prev_size</td>
     97 *     <td colspan=2>page size (the value is arbitrary)</td>
     98 *   </tr>
    8799 *   <tr>
    88100 *     <td>first_block->size</td>
     
    101113 *   <tr>
    102114 *     <td>second_block->size</td>
    103  *     <td colspan=2>arbitrary size | @c HEAP_PREV_BLOCK_FREE</td>
     115 *     <td colspan=2>page size (the value is arbitrary)</td>
    104116 *   </tr>
    105117 *   <tr><td>heap->end</td><td colspan=2>heap area end address</td></tr>
     
    108120 * @{
    109121 */
     122
     123/**
     124 * @brief See also @ref Heap_Block.size_and_flag.
     125 */
     126#define HEAP_PREV_BLOCK_USED ((uintptr_t) 1)
     127
     128/**
     129 * @brief Offset from the block begin up to the block size field
     130 * (@ref Heap_Block.size_and_flag).
     131 */
     132#define HEAP_BLOCK_SIZE_OFFSET sizeof(uintptr_t)
     133
     134/**
     135 * @brief The block header consists of the two size fields
     136 * (@ref Heap_Block.prev_size and @ref Heap_Block.size_and_flag).
     137 */
     138#define HEAP_BLOCK_HEADER_SIZE (sizeof(uintptr_t) * 2)
    110139
    111140/**
     
    120149   * indicated by a cleared @c HEAP_PREV_BLOCK_USED flag in the
    121150   * @a size_and_flag field of the current block.
     151   *
     152   * In a used block only the @a size_and_flag field needs to be valid.  The
     153   * @a prev_size field of the current block is maintained by the previous
     154   * block.  The current block can use the @a prev_size field in the next block
     155   * for allocation.
    122156   */
    123157  uintptr_t prev_size;
     
    158192} Heap_Block;
    159193
    160 #define HEAP_PREV_BLOCK_USED ((uintptr_t) 1)
    161 
    162 #define HEAP_PREV_BLOCK_FREE ((uintptr_t) 0)
    163 
    164 /**
    165  * @brief Offset from the block begin up to the block size field.
    166  */
    167 #define HEAP_BLOCK_SIZE_OFFSET (sizeof(uintptr_t))
    168 
    169 /**
    170  * @brief Offset from the block begin up to the allocated area begin.
    171  */
    172 #define HEAP_BLOCK_ALLOC_AREA_OFFSET (sizeof(uintptr_t) * 2)
    173 
    174 #define HEAP_BLOCK_USED_OVERHEAD (sizeof(uintptr_t) * 2)
    175 
    176 #define HEAP_LAST_BLOCK_OVERHEAD HEAP_BLOCK_ALLOC_AREA_OFFSET
    177 
    178 /**
    179  *  Run-time heap statistics.
    180  *
    181  *  @note (double)searches/allocs gives mean number of searches per alloc while
    182  *        max_search gives maximum number of searches ever performed on a
    183  *        single call to alloc.
    184  *
    185  *  @note the statistics is always gathered. I believe the imposed overhead is
    186  *        rather small. Feel free to make it compile-time option if you think
    187  *        the overhead is too high for your application.
     194/**
     195 * @brief Run-time heap statistics.
     196 *
     197 * The value @a searches / @a allocs gives the mean number of searches per
     198 * allocation, while @a max_search gives maximum number of searches ever
     199 * performed on a single allocation call.
    188200 */
    189201typedef struct {
    190   /** instance number of this heap */
     202  /**
     203   * @brief Instance number of this heap.
     204   */
    191205  uint32_t instance;
    192   /** the size of the memory for heap */
     206
     207  /**
     208   * @brief The size of the memory for heap.
     209   */
    193210  uintptr_t size;
    194   /** current free size */
     211
     212  /**
     213   * @brief Current free size.
     214   */
    195215  uintptr_t free_size;
    196   /** minimum free size ever */
     216
     217  /**
     218   * @brief Minimum free size ever.
     219   */
    197220  uintptr_t min_free_size;
    198   /** current number of free blocks */
     221
     222  /**
     223   * @brief Current number of free blocks.
     224   */
    199225  uint32_t free_blocks;
    200   /** maximum number of free blocks ever */
     226
     227  /**
     228   * @brief Maximum number of free blocks ever.
     229   */
    201230  uint32_t max_free_blocks;
    202   /** current number of used blocks */
     231
     232  /**
     233   * @brief Current number of used blocks.
     234   */
    203235  uint32_t used_blocks;
    204   /** maximum number of blocks searched ever */
     236
     237  /**
     238   * @brief Maximum number of blocks searched ever.
     239   */
    205240  uint32_t max_search;
    206   /** total number of successful calls to alloc */
     241
     242  /**
     243   * @brief Total number of successful calls to alloc.
     244   */
    207245  uint32_t allocs;
    208   /** total number of searches ever */
     246
     247  /**
     248   * @brief Total number of searches ever.
     249   */
    209250  uint32_t searches;
    210   /** total number of suceessful calls to free */
     251
     252  /**
     253   * @brief Total number of suceessful calls to free.
     254   */
    211255  uint32_t frees;
    212   /** total number of successful resizes */
     256
     257  /**
     258   * @brief Total number of successful resizes.
     259   */
    213260  uint32_t resizes;
    214261} Heap_Statistics;
    215262
    216263/**
    217  *  Control block used to manage each heap.
     264 * @brief Control block used to manage a heap.
    218265 */
    219266typedef struct {
    220   /** head and tail of circular list of free blocks */
    221267  Heap_Block free_list;
    222   /** allocation unit and alignment */
    223268  uintptr_t page_size;
    224   /** minimum block size aligned on page_size */
    225269  uintptr_t min_block_size;
    226   /** first address of memory for the heap */
    227   uintptr_t begin;
    228   /** first address past end of memory for the heap */
    229   uintptr_t end;
    230   /** first valid block address in the heap */
    231   Heap_Block *start;
    232   /** last valid block address in the heap */
    233   Heap_Block *final;
    234   /** run-time statistics */
     270  uintptr_t area_begin;
     271  uintptr_t area_end;
     272  Heap_Block *first_block;
     273  Heap_Block *last_block;
    235274  Heap_Statistics stats;
    236275} Heap_Control;
    237276
    238277/**
    239  *  Status codes for _Heap_Extend
     278 * @brief Information about blocks.
     279 */
     280typedef struct {
     281  /**
     282   * @brief Number of blocks of this type.
     283   */
     284  uint32_t number;
     285
     286  /**
     287   * @brief Largest block of this type.
     288   */
     289  uint32_t largest;
     290
     291  /**
     292   * @brief Total size of the blocks of this type.
     293   */
     294  uint32_t total;
     295} Heap_Information;
     296
     297/**
     298 * @brief Information block returned by _Heap_Get_information().
     299 */
     300typedef struct {
     301  Heap_Information Free;
     302  Heap_Information Used;
     303} Heap_Information_block;
     304
     305/**
     306 * @brief See _Heap_Extend().
    240307 */
    241308typedef enum {
     
    246313
    247314/**
    248  *  Status codes for _Heap_Resize_block
     315 * @brief See _Heap_Resize_block().
    249316 */
    250317typedef enum {
     
    255322
    256323/**
    257  *  Status codes for _Heap_Get_information
    258  */
    259 typedef enum {
    260   HEAP_GET_INFORMATION_SUCCESSFUL = 0,
    261   HEAP_GET_INFORMATION_BLOCK_ERROR
    262 } Heap_Get_information_status;
    263 
    264 /**
    265  *  Information block returned by the Heap routines used to
    266  *  obtain heap information.  This information is returned about
    267  *  either free or used blocks.
    268  */
    269 typedef struct {
    270   /** Number of blocks of this type. */
    271   uint32_t number;
    272   /** Largest blocks of this type. */
    273   uint32_t largest;
    274   /** Total size of the blocks of this type. */
    275   uint32_t total;
    276 } Heap_Information;
    277 
    278 /**
    279  *  Information block returned by _Heap_Get_information
    280  */
    281 typedef struct {
    282   /** This field is information on the used blocks in the heap. */
    283   Heap_Information Free;
    284   /** This field is information on the used blocks in the heap. */
    285   Heap_Information Used;
    286 } Heap_Information_block;
    287 
    288 /**
    289  * Initializes the @a heap control block to manage the area starting at
    290  * @a area_begin of @a area_size bytes.
     324 * @brief Initializes the heap control block @a heap to manage the area
     325 * starting at @a area_begin of size @a area_size bytes.
    291326 *
    292327 * Blocks of memory are allocated from the heap in multiples of @a page_size
     
    304339
    305340/**
    306  *  This routine grows @a heap memory area using the size bytes which
    307  *  begin at @a starting_address.
    308  *
    309  *  @param[in] heap is the heap to operate upon
    310  *  @param[in] starting_address is the starting address of the memory
    311  *         to add to the heap
    312  *  @param[in] size is the size in bytes of the memory area to add
    313  *  @param[in] amount_extended points to a user area to return the
    314  *  @return a status indicating success or the reason for failure
    315  *  @return *size filled in with the amount of memory added to the heap
     341 * @brief Extends the memory area of the heap @a heap using the memory area
     342 * starting at @a area_begin of size @a area_size bytes.
     343 *
     344 * The extended space available for allocation will be returned in
     345 * @a amount_extended.
     346 *
     347 * The memory area must start at the end of the currently used memory area.
    316348 */
    317349Heap_Extend_status _Heap_Extend(
     
    323355
    324356/**
    325  *  This function attempts to allocate a block of @a size bytes from
    326  *  @a heap.  If insufficient memory is free in @a heap to allocate
    327  *  a block of the requested size, then NULL is returned.
    328  *
    329  *  @param[in] heap is the heap to operate upon
    330  *  @param[in] size is the amount of memory to allocate in bytes
    331  *  @return NULL if unsuccessful and a pointer to the block if successful
    332  */
    333 void *_Heap_Allocate( Heap_Control *heap, uintptr_t size );
    334 
    335 /**
    336  *  This function attempts to allocate a memory block of @a size bytes from
    337  *  @a heap so that the start of the user memory is aligned on the
    338  *  @a alignment boundary. If @a alignment is 0, it is set to CPU_ALIGNMENT.
    339  *  Any other value of @a alignment is taken "as is", i.e., even odd
    340  *  alignments are possible.
    341  *  Returns pointer to the start of the memory block if success, NULL if
    342  *  failure.
    343  *
    344  *  @param[in] heap is the heap to operate upon
    345  *  @param[in] size is the amount of memory to allocate in bytes
    346  *  @param[in] alignment the required alignment
    347  *  @return NULL if unsuccessful and a pointer to the block if successful
    348  */
    349 void *_Heap_Allocate_aligned(
     357 * @brief Allocates a memory area of size @a size bytes.
     358 *
     359 * If the alignment parameter @a alignment is not equal to zero, the allocated
     360 * memory area will begin at an address aligned by this value.
     361 *
     362 * If the boundary parameter @a boundary is not equal to zero, the allocated
     363 * memory area will fulfill a boundary constraint.  The boudnary value
     364 * specifies the set of addresses which are aligned by the boundary value.  The
     365 * interior of the allocated memory area will not contain an element of this
     366 * set.  The begin or end address of the area may be a member of the set.
     367 *
     368 * A size value of zero will return a unique address which may be freed with
     369 * _Heap_Free().
     370 *
     371 * Returns a pointer to the begin of the allocated memory area, or @c NULL if
     372 * no memory is available or the parameters are inconsistent.
     373 */
     374void *_Heap_Allocate_aligned_with_boundary(
    350375  Heap_Control *heap,
    351376  uintptr_t size,
    352   uintptr_t alignment
    353 );
    354 
    355 /**
    356  *  This function sets @a size to the size of the block of allocatable area
    357  *  which begins at @a starting_address. The size returned in @a *size could
    358  *  be greater than the size requested for allocation.
    359  *  Returns true if the @a starting_address is in the heap, and false
    360  *  otherwise.
    361  *
    362  *  @param[in] heap is the heap to operate upon
    363  *  @param[in] starting_address is the starting address of the user block
    364  *         to obtain the size of
    365  *  @param[in] size points to a user area to return the size in
    366  *  @return true if successfully able to determine the size, false otherwise
    367  *  @return *size filled in with the size of the user area for this block
     377  uintptr_t alignment,
     378  uintptr_t boundary
     379);
     380
     381#define _Heap_Allocate_aligned( heap, size, alignment ) \
     382  _Heap_Allocate_aligned_with_boundary( heap, size, alignment, 0 )
     383
     384#define _Heap_Allocate( heap, size ) \
     385  _Heap_Allocate_aligned_with_boundary( heap, size, 0, 0 )
     386
     387/**
     388 * @brief Frees the allocated memory area starting at @a addr in the heap
     389 * @a heap.
     390 *
     391 * Inappropriate values for @a addr may corrupt the heap.
     392 *
     393 * Returns @c true in case of success, and @c false otherwise.
     394 */
     395bool _Heap_Free( Heap_Control *heap, void *addr );
     396
     397/**
     398 * @brief Walks the heap @a heap to verify its integrity.
     399 *
     400 * If @a dump is @c true, then diagnostic messages will be printed to standard
     401 * output.  In this case @a source is used to mark the output lines.
     402 *
     403 * Returns @c true if no errors occured, and @c false if the heap is corrupt.
     404 */
     405bool _Heap_Walk(
     406  Heap_Control *heap,
     407  int source,
     408  bool dump
     409);
     410
     411/**
     412 * @brief Returns information about used and free blocks for the heap @a heap
     413 * in @a info.
     414 */
     415void _Heap_Get_information(
     416  Heap_Control *heap,
     417  Heap_Information_block *info
     418);
     419
     420/**
     421 * @brief Returns information about free blocks for the heap @a heap in
     422 * @a info.
     423 */
     424void _Heap_Get_free_information(
     425  Heap_Control *heap,
     426  Heap_Information *info
     427);
     428
     429/**
     430 * @brief Returns the size of the allocatable memory area starting at @a addr
     431 * in @a size.
     432 *
     433 * The size value may be greater than the initially requested size in
     434 * _Heap_Allocate_aligned_with_boundary().
     435 *
     436 * Inappropriate values for @a addr will not corrupt the heap, but may yield
     437 * invalid size values.
     438 *
     439 * Returns @a true if successful, and @c false otherwise.
    368440 */
    369441bool _Heap_Size_of_alloc_area(
    370442  Heap_Control *heap,
    371   void *area_begin,
     443  void *addr,
    372444  uintptr_t *size
    373445);
    374446
    375447/**
    376  *  This function tries to resize in place the block that is pointed to by the
    377  *  @a starting_address to the new @a size.
    378  *
    379  *  @param[in] heap is the heap to operate upon
    380  *  @param[in] starting_address is the starting address of the user block
    381  *         to be resized
    382  *  @param[in] size is the new size
    383  *  @param[in] old_mem_size points to a user area to return the size of the
    384  *         user memory area of the block before resizing.
    385  *  @param[in] avail_mem_size points to a user area to return the size of
    386  *         the user memory area of the free block that has been enlarged or
    387  *         created due to resizing, 0 if none.
    388  *  @return HEAP_RESIZE_SUCCESSFUL if successfully able to resize the block,
    389  *          HEAP_RESIZE_UNSATISFIED if the block can't be resized in place,
    390  *          HEAP_RESIZE_FATAL_ERROR if failure
    391  *  @return *old_mem_size filled in with the size of the user memory area of
    392  *          the block before resizing.
    393  *  @return *avail_mem_size filled in with the size of the user memory area
    394  *          of the free block that has been enlarged or created due to
    395  *          resizing, 0 if none.
     448 * @brief Resizes the block of the allocated memory area starting at @a addr.
     449 *
     450 * The new memory area will have a size of at least @a size bytes.  A resize
     451 * may be impossible and depends on the current heap usage.
     452 *
     453 * The size available for allocation in the current block before the resize
     454 * will be returned in @a old_size.  The size available for allocation in
     455 * the resized block will be returned in @a new_size.  If the resize was not
     456 * successful, then a value of zero will be returned in @a new_size.
     457 *
     458 * Inappropriate values for @a addr may corrupt the heap.
    396459 */
    397460Heap_Resize_status _Heap_Resize_block(
    398461  Heap_Control *heap,
    399   void         *starting_address,
    400   uintptr_t      size,
    401   uintptr_t     *old_mem_size,
    402   uintptr_t     *avail_mem_size
    403 );
    404 
    405 /**
    406  *  This routine returns the block of memory which begins
    407  *  at @a alloc_area_begin to @a heap.  Any coalescing which is
    408  *  possible with the freeing of this routine is performed.
    409  *
    410  *  @param[in] heap is the heap to operate upon
    411  *  @param[in] start_address is the starting address of the user block
    412  *         to free
    413  *  @return true if successfully freed, false otherwise
    414  */
    415 bool _Heap_Free( Heap_Control *heap, void *alloc_area_begin );
    416 
    417 /**
    418  *  This routine walks the heap to verify its integrity.
    419  *
    420  *  @param[in] heap is the heap to operate upon
    421  *  @param[in] source is a user specified integer which may be used to
    422  *         indicate where in the application this was invoked from
    423  *  @param[in] do_dump is set to true if errors should be printed
    424  *  @return true if the test passed fine, false otherwise.
    425  */
    426 bool _Heap_Walk(
    427   Heap_Control *heap,
    428   int           source,
    429   bool          do_dump
    430 );
    431 
    432 /**
    433  *  This routine walks the heap and tots up the free and allocated
    434  *  sizes.
    435  *
    436  *  @param[in] heap pointer to heap header
    437  *  @param[in] the_info pointer to a status information area
    438  *  @return *the_info is filled with status information
    439  *  @return 0=success, otherwise heap is corrupt.
    440  */
    441 Heap_Get_information_status _Heap_Get_information(
    442   Heap_Control            *heap,
    443   Heap_Information_block  *the_info
    444 );
    445 
    446 /**
    447  *  This heap routine returns information about the free blocks
    448  *  in the specified heap.
    449  *
    450  *  @param[in] heap pointer to heap header.
    451  *  @param[in] info pointer to the free block information.
    452  *
    453  *  @return free block information filled in.
    454  */
    455 void _Heap_Get_free_information(
    456   Heap_Control        *heap,
    457   Heap_Information    *info
     462  void *addr,
     463  uintptr_t size,
     464  uintptr_t *old_size,
     465  uintptr_t *new_size
    458466);
    459467
     
    463471
    464472/**
    465  * @brief Returns the minimal block size for a block which may contain an area
    466  * of size @a alloc_size for allocation, or zero in case of an overflow.
    467  *
    468  * Uses the heap values @a page_size and @a min_block_size.
    469  */
    470 uintptr_t _Heap_Calc_block_size(
    471   uintptr_t alloc_size,
    472   uintptr_t page_size,
    473   uintptr_t min_block_size
    474 );
    475 
    476 /**
    477  *  This method allocates a block of size @a alloc_size from @a the_block
    478  *  belonging to @a heap. Split @a the_block if possible, otherwise
    479  *  allocate it entirely.  When split, make the lower part used, and leave
    480  *  the upper part free.
    481  *
    482  *  This is an internal routines used by _Heap_Allocate() and
    483  *  _Heap_Allocate_aligned().  Refer to 'heap.c' for details.
    484  *
    485  *  @param[in] heap is the heap to operate upon
    486  *  @param[in] the_block is the block to allocates the requested size from
    487  *  @param[in] alloc_size is the requested number of bytes to take out of
    488  *         the block
    489  *
    490  *  @return This methods returns the size of the allocated block.
    491  */
    492 uintptr_t _Heap_Block_allocate(
     473 * @brief Allocates the memory area starting at @a alloc_begin of size
     474 * @a alloc_size bytes in the block @a block.
     475 *
     476 * The block may be split up into multiple blocks.
     477 *
     478 * Inappropriate values for @a alloc_begin or @a alloc_size may corrupt the
     479 * heap.
     480 *
     481 * Returns the block containing the allocated memory area.
     482 */
     483Heap_Block *_Heap_Block_allocate(
    493484  Heap_Control *heap,
    494485  Heap_Block *block,
     486  uintptr_t alloc_begin,
    495487  uintptr_t alloc_size
    496488);
  • cpukit/score/include/rtems/score/object.h

    r6685aa09 rdea3eccb  
    2929extern "C" {
    3030#endif
     31
     32/**
     33 * @defgroup Score SuperCore
     34 *
     35 * @brief Provides services for all APIs.
     36 */
    3137
    3238/**
  • cpukit/score/include/rtems/score/protectedheap.h

    r6685aa09 rdea3eccb  
    11/**
    2  *  @file  rtems/score/protectedheap.h
     2 * @file
    33 *
    4  *  This include file contains the information pertaining to the
    5  *  Protected Heap Handler.
     4 * @ingroup ScoreProtHeap
    65 *
     6 * @brief Protected Heap Handler API.
     7 */
     8
     9/*
    710 *  COPYRIGHT (c) 1989-2007.
    811 *  On-Line Applications Research Corporation (OAR).
     
    2124#include <rtems/score/apimutex.h>
    2225
    23 /**
    24  *  @defgroup ScoreProtHeap Protected Heap Handler
    25  *
    26  *  This handler encapsulates functionality which provides the foundation
    27  *  Protected Heap services.
    28  *
    29  *  It is a simple wrapper for the help with the addition of the
    30  *  allocation mutex being used for protection.
    31  */
    32 /**@{*/
    33 
    3426#ifdef __cplusplus
    3527extern "C" {
     
    3729
    3830/**
    39  *  This routine initializes @a the_heap record to manage the
    40  *  contiguous heap of @a size bytes which starts at @a starting_address.
    41  *  Blocks of memory are allocated from the heap in multiples of
    42  *  @a page_size byte units. If @a page_size is 0 or is not multiple of
    43  *  CPU_ALIGNMENT, it's aligned up to the nearest CPU_ALIGNMENT boundary.
     31 * @defgroup ScoreProtHeap Protected Heap Handler
    4432 *
    45  *  @param[in] the_heap is the heap to operate upon
    46  *  @param[in] starting_address is the starting address of the memory for
    47  *         the heap
    48  *  @param[in] size is the size in bytes of the memory area for the heap
    49  *  @param[in] page_size is the size in bytes of the allocation unit
     33 * @ingroup ScoreHeap
    5034 *
    51  *  @return This method returns the maximum memory available.  If
    52  *          unsuccessful, 0 will be returned.
     35 * @brief Provides protected heap services.
     36 *
     37 * The @ref ScoreAllocatorMutex is used to protect the heap accesses.
     38 *
     39 * @{
    5340 */
    54 static inline uint32_t _Protected_heap_Initialize(
    55   Heap_Control *the_heap,
    56   void         *starting_address,
    57   intptr_t      size,
    58   uint32_t      page_size
     41
     42/**
     43 * @brief See _Heap_Initialize().
     44 */
     45RTEMS_INLINE_ROUTINE uintptr_t _Protected_heap_Initialize(
     46  Heap_Control *heap,
     47  void *area_begin,
     48  uintptr_t area_size,
     49  uintptr_t page_size
    5950)
    6051{
    61   return _Heap_Initialize( the_heap, starting_address, size, page_size );
     52  return _Heap_Initialize( heap, area_begin, area_size, page_size );
    6253}
    6354
    6455/**
    65  *  This routine grows @a the_heap memory area using the size bytes which
    66  *  begin at @a starting_address.
     56 * @brief See _Heap_Extend().
    6757 *
    68  *  @param[in] the_heap is the heap to operate upon
    69  *  @param[in] starting_address is the starting address of the memory
    70  *         to add to the heap
    71  *  @param[in] size is the size in bytes of the memory area to add
    72  *  @return a status indicating success or the reason for failure
     58 * Returns @a true in case of success, and @a false otherwise.
    7359 */
    7460bool _Protected_heap_Extend(
    75   Heap_Control *the_heap,
    76   void         *starting_address,
    77   intptr_t      size
     61  Heap_Control *heap,
     62  void *area_begin,
     63  uintptr_t area_size
    7864);
    7965
    8066/**
    81  *  This function attempts to allocate a block of @a size bytes from
    82  *  @a the_heap.  If insufficient memory is free in @a the_heap to allocate
    83  *  a block of the requested size, then NULL is returned.
    84  *
    85  *  @param[in] the_heap is the heap to operate upon
    86  *  @param[in] size is the amount of memory to allocate in bytes
    87  *  @return NULL if unsuccessful and a pointer to the block if successful
     67 * @brief See _Heap_Allocate_aligned_with_boundary().
    8868 */
    8969void *_Protected_heap_Allocate(
    90   Heap_Control *the_heap,
    91   intptr_t      size
     70  Heap_Control *heap,
     71  uintptr_t size
    9272);
    9373
    9474/**
    95  *  This function attempts to allocate a memory block of @a size bytes from
    96  *  @a the_heap so that the start of the user memory is aligned on the
    97  *  @a alignment boundary. If @a alignment is 0, it is set to CPU_ALIGNMENT.
    98  *  Any other value of @a alignment is taken "as is", i.e., even odd
    99  *  alignments are possible.
    100  *  Returns pointer to the start of the memory block if success, NULL if
    101  *  failure.
    102  *
    103  *  @param[in] the_heap is the heap to operate upon
    104  *  @param[in] size is the amount of memory to allocate in bytes
    105  *  @param[in] alignment the required alignment
    106  *  @return NULL if unsuccessful and a pointer to the block if successful
     75 * @brief See _Heap_Allocate_aligned_with_boundary().
    10776 */
    10877void *_Protected_heap_Allocate_aligned(
    109   Heap_Control *the_heap,
    110   intptr_t      size,
    111   uint32_t      alignment
     78  Heap_Control *heap,
     79  uintptr_t size,
     80  uintptr_t alignment
    11281);
    11382
    11483/**
    115  *  This function sets @a *size to the size of the block of user memory
    116  *  which begins at @a starting_address. The size returned in @a *size could
    117  *  be greater than the size requested for allocation.
    118  *  Returns true if the @a starting_address is in the heap, and false
    119  *  otherwise.
    120  *
    121  *  @param[in] the_heap is the heap to operate upon
    122  *  @param[in] starting_address is the starting address of the user block
    123  *         to obtain the size of
    124  *  @param[in] size points to a user area to return the size in
    125  *  @return true if successfully able to determine the size, false otherwise
    126  *  @return *size filled in with the size of the user area for this block
     84 * @brief See _Heap_Size_of_alloc_area().
    12785 */
    12886bool _Protected_heap_Get_block_size(
    129   Heap_Control        *the_heap,
    130   void                *starting_address,
    131   intptr_t            *size
     87  Heap_Control *heap,
     88  void *addr,
     89  uintptr_t *size
    13290);
    13391
    13492/**
    135  *  This function tries to resize in place the block that is pointed to by the
    136  *  @a starting_address to the new @a size.
     93 * @brief See _Heap_Resize_block().
    13794 *
    138  *  @param[in] the_heap is the heap to operate upon
    139  *  @param[in] starting_address is the starting address of the user block
    140  *         to be resized
    141  *  @param[in] size is the new size
    142  *
    143  *  @return true if successfully able to resize the block.
    144  *          false if the block can't be resized in place.
     95 * Returns @a true in case of success, and @a false otherwise.
    14596 */
    14697bool _Protected_heap_Resize_block(
    147   Heap_Control *the_heap,
    148   void         *starting_address,
    149   intptr_t      size
     98  Heap_Control *heap,
     99  void *addr,
     100  uintptr_t size
    150101);
    151102
    152103/**
    153  *  This routine returns the block of memory which begins
    154  *  at @a starting_address to @a the_heap.  Any coalescing which is
    155  *  possible with the freeing of this routine is performed.
     104 * @brief See _Heap_Free().
    156105 *
    157  *  @param[in] the_heap is the heap to operate upon
    158  *  @param[in] start_address is the starting address of the user block
    159  *         to free
    160  *  @return true if successfully freed, false otherwise
     106 * Returns @a true in case of success, and @a false otherwise.
    161107 */
    162 bool _Protected_heap_Free(
    163   Heap_Control *the_heap,
    164   void         *start_address
     108bool _Protected_heap_Free( Heap_Control *heap, void *addr );
     109
     110/**
     111 * @brief See _Heap_Walk().
     112 */
     113bool _Protected_heap_Walk( Heap_Control *heap, int source, bool dump );
     114
     115/**
     116 * @brief See _Heap_Get_information().
     117 *
     118 * Returns @a true in case of success, and @a false otherwise.
     119 */
     120bool _Protected_heap_Get_information(
     121  Heap_Control *heap,
     122  Heap_Information_block *info
    165123);
    166124
    167125/**
    168  *  This routine walks the heap to verify its integrity.
     126 * @brief See _Heap_Get_free_information().
    169127 *
    170  *  @param[in] the_heap is the heap to operate upon
    171  *  @param[in] source is a user specified integer which may be used to
    172  *         indicate where in the application this was invoked from
    173  *  @param[in] do_dump is set to true if errors should be printed
    174  *  @return true if the test passed fine, false otherwise.
     128 * Returns @a true in case of success, and @a false otherwise.
    175129 */
    176 bool _Protected_heap_Walk(
    177   Heap_Control *the_heap,
    178   int           source,
    179   bool          do_dump
     130bool _Protected_heap_Get_free_information(
     131  Heap_Control *heap,
     132  Heap_Information *info
    180133);
    181134
    182135/**
    183  *  This routine walks the heap and tots up the free and allocated
    184  *  sizes.
    185  *
    186  *  @param[in] the_heap pointer to heap header
    187  *  @param[in] the_info pointer to a status information area
    188  *
    189  *  @return true if successfully able to return information
     136 * @brief See _Heap_Get_size().
    190137 */
    191 bool _Protected_heap_Get_information(
    192   Heap_Control            *the_heap,
    193   Heap_Information_block  *the_info
    194 );
     138uintptr_t _Protected_heap_Get_size( Heap_Control *heap );
    195139
    196 /**
    197  *  This heap routine returns information about the free blocks
    198  *  in the specified heap.
    199  *
    200  *  @param[in] the_heap pointer to heap header.
    201  *  @param[in] info pointer to the free block information.
    202  *
    203  *  @return free block information filled in.
    204  */
    205 bool _Protected_heap_Get_free_information(
    206   Heap_Control        *the_heap,
    207   Heap_Information    *info
    208 );
    209 
    210 /**
    211  *  This function returns the maximum size of the protected heap.
    212  *
    213  *  @param[in] the_heap points to the heap being operated upon
    214  *
    215  *  @return This method returns the total amount of memory
    216  *          allocated to the heap.
    217  */
    218 uint32_t _Protected_heap_Get_size(
    219   Heap_Control        *the_heap
    220 );
     140/** @} */
    221141
    222142#ifdef __cplusplus
     
    224144#endif
    225145
    226 /**@}*/
    227 
    228146#endif
    229147/* end of include file */
  • cpukit/score/inline/rtems/score/heap.inl

    r6685aa09 rdea3eccb  
    1 /** 
     1/**
    22 * @file
    33 *
    4  * @brief Static inline implementations of the inlined routines from the heap
    5  * handler.
     4 * @ingroup ScoreHeap
     5 *
     6 * @brief Heap Handler API.
    67 */
    78
     
    2728
    2829/**
    29  * @addtogroup ScoreHeap 
     30 * @addtogroup ScoreHeap
    3031 *
    3132 * @{
     
    4243}
    4344
    44 RTEMS_INLINE_ROUTINE Heap_Block *_Heap_First_free_block( Heap_Control *heap )
     45RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Free_list_first( Heap_Control *heap )
    4546{
    4647  return _Heap_Free_list_head(heap)->next;
    4748}
    4849
    49 RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Last_free_block( Heap_Control *heap )
     50RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Free_list_last( Heap_Control *heap )
    5051{
    5152  return _Heap_Free_list_tail(heap)->prev;
    5253}
    5354
    54 RTEMS_INLINE_ROUTINE void _Heap_Block_remove_from_free_list( Heap_Block *block )
     55RTEMS_INLINE_ROUTINE void _Heap_Free_list_remove( Heap_Block *block )
    5556{
    5657  Heap_Block *next = block->next;
     
    6162}
    6263
    63 RTEMS_INLINE_ROUTINE void _Heap_Block_replace_in_free_list(
     64RTEMS_INLINE_ROUTINE void _Heap_Free_list_replace(
    6465  Heap_Block *old_block,
    6566  Heap_Block *new_block
     
    7677}
    7778
    78 RTEMS_INLINE_ROUTINE void _Heap_Block_insert_after(
    79   Heap_Block *prev_block,
     79RTEMS_INLINE_ROUTINE void _Heap_Free_list_insert_after(
     80  Heap_Block *block_before,
    8081  Heap_Block *new_block
    8182)
    8283{
    83   Heap_Block *next = prev_block->next;
     84  Heap_Block *next = block_before->next;
    8485
    8586  new_block->next = next;
    86   new_block->prev = prev_block;
    87   prev_block->next = new_block;
     87  new_block->prev = block_before;
     88  block_before->next = new_block;
    8889  next->prev = new_block;
    8990}
     
    123124 */
    124125RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Block_at(
    125   const Heap_Block *block,
     126  Heap_Block *block,
    126127  uintptr_t offset
    127128)
     
    130131}
    131132
    132 /**
    133  * @brief Returns the begin of the allocatable area of @a block.
    134  */
    135133RTEMS_INLINE_ROUTINE uintptr_t _Heap_Alloc_area_of_block(
    136   Heap_Block *block
     134  const Heap_Block *block
    137135)
    138136{
    139   return (uintptr_t) block + HEAP_BLOCK_ALLOC_AREA_OFFSET;
     137  return (uintptr_t) block + HEAP_BLOCK_HEADER_SIZE;
    140138}
    141139
    142 /**
    143  * @brief Returns the block associated with the allocatable area starting at
    144  * @a alloc_area_begin inside a heap with a page size of @a page_size.
    145  */
    146140RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Block_of_alloc_area(
    147   uintptr_t alloc_area_begin,
     141  uintptr_t alloc_begin,
    148142  uintptr_t page_size
    149143)
    150144{
    151   return (Heap_Block *) (_Heap_Align_down( alloc_area_begin, page_size )
    152     - HEAP_BLOCK_ALLOC_AREA_OFFSET);
     145  return (Heap_Block *) (_Heap_Align_down( alloc_begin, page_size )
     146    - HEAP_BLOCK_HEADER_SIZE);
    153147}
    154148
    155 RTEMS_INLINE_ROUTINE bool _Heap_Is_prev_used( Heap_Block *block )
     149RTEMS_INLINE_ROUTINE bool _Heap_Is_prev_used( const Heap_Block *block )
    156150{
    157151  return block->size_and_flag & HEAP_PREV_BLOCK_USED;
    158152}
    159153
    160 RTEMS_INLINE_ROUTINE uintptr_t _Heap_Block_size( Heap_Block *block )
     154RTEMS_INLINE_ROUTINE uintptr_t _Heap_Block_size( const Heap_Block *block )
    161155{
    162156  return block->size_and_flag & ~HEAP_PREV_BLOCK_USED;
     
    164158
    165159RTEMS_INLINE_ROUTINE bool _Heap_Is_block_in_heap(
    166   Heap_Control *heap,
    167   Heap_Block *block
     160  const Heap_Control *heap,
     161  const Heap_Block *block
    168162)
    169163{
    170   return _Addresses_Is_in_range( block, heap->start, heap->final );
     164  return (uintptr_t) block >= (uintptr_t) heap->first_block
     165    && (uintptr_t) block <= (uintptr_t) heap->last_block;
    171166}
    172167
    173168/**
    174  * @brief Returns the maximum size of the heap.
     169 * @brief Returns the heap area size.
    175170 */
    176 RTEMS_INLINE_ROUTINE uintptr_t _Heap_Get_size( Heap_Control *heap )
     171RTEMS_INLINE_ROUTINE uintptr_t _Heap_Get_size( const Heap_Control *heap )
    177172{
    178   return (uintptr_t) heap->end - (uintptr_t) heap->begin;
     173  return heap->area_end - heap->area_begin;
     174}
     175
     176RTEMS_INLINE_ROUTINE uintptr_t _Heap_Max( uintptr_t a, uintptr_t b )
     177{
     178  return a > b ? a : b;
     179}
     180
     181RTEMS_INLINE_ROUTINE uintptr_t _Heap_Min( uintptr_t a, uintptr_t b )
     182{
     183  return a < b ? a : b;
    179184}
    180185
  • cpukit/score/src/heap.c

    r6685aa09 rdea3eccb  
     1/**
     2 * @file
     3 *
     4 * @ingroup ScoreHeap
     5 *
     6 * @brief Heap Handler implementation.
     7 */
     8
    19/*
    2  *  Heap Handler
    3  *
    410 *  COPYRIGHT (c) 1989-2009.
    511 *  On-Line Applications Research Corporation (OAR).
     12 *
     13 *  Copyright (c) 2009 embedded brains GmbH.
    614 *
    715 *  The license and distribution terms for this file may be
     
    1826#include <rtems/system.h>
    1927#include <rtems/score/heap.h>
     28
     29#if CPU_ALIGNMENT == 0 || CPU_ALIGNMENT % 4 != 0
     30  #error "invalid CPU_ALIGNMENT value"
     31#endif
    2032
    2133static uint32_t instance = 0;
     
    114126uintptr_t _Heap_Initialize(
    115127  Heap_Control *heap,
    116   void *area_begin,
    117   uintptr_t area_size,
     128  void *heap_area_begin_ptr,
     129  uintptr_t heap_area_size,
    118130  uintptr_t page_size
    119131)
    120132{
    121   Heap_Statistics * const stats = &heap->stats;
    122   uintptr_t heap_area_begin = (uintptr_t) area_begin;
    123   uintptr_t heap_area_end = heap_area_begin + area_size;
    124   uintptr_t alloc_area_begin = heap_area_begin + HEAP_BLOCK_ALLOC_AREA_OFFSET;
     133  Heap_Statistics *const stats = &heap->stats;
     134  uintptr_t const heap_area_begin = (uintptr_t) heap_area_begin_ptr;
     135  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;
    125137  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;
    126141  uintptr_t overhead = 0;
    127142  Heap_Block *first_block = NULL;
     
    133148    page_size = _Heap_Align_up( page_size, CPU_ALIGNMENT );
    134149  }
    135 
    136   heap->min_block_size = _Heap_Align_up( sizeof( Heap_Block ), page_size );
     150  min_block_size = _Heap_Align_up( sizeof( Heap_Block ), page_size );
    137151
    138152  alloc_area_begin = _Heap_Align_up( alloc_area_begin, page_size );
    139   overhead = HEAP_LAST_BLOCK_OVERHEAD
    140     + (alloc_area_begin - HEAP_BLOCK_ALLOC_AREA_OFFSET - heap_area_begin);
    141   alloc_area_size = _Heap_Align_down ( area_size - overhead, page_size );
     153  first_block_begin = alloc_area_begin - HEAP_BLOCK_HEADER_SIZE;
     154  overhead = HEAP_BLOCK_HEADER_SIZE + (first_block_begin - heap_area_begin);
     155  first_block_size = heap_area_size - overhead;
     156  first_block_size = _Heap_Align_down ( first_block_size, page_size );
     157  alloc_area_size = first_block_size - HEAP_BLOCK_HEADER_SIZE;
    142158
    143159  if (
    144160    heap_area_end < heap_area_begin
    145       || area_size < overhead
    146       || alloc_area_size == 0
     161      || heap_area_size <= overhead
     162      || first_block_size < min_block_size
    147163  ) {
    148164    /* Invalid area or area too small */
     
    150166  }
    151167
    152   heap->page_size = page_size;
    153   heap->begin = heap_area_begin;
    154   heap->end = heap_area_end;
    155 
    156168  /* First block */
    157   first_block = _Heap_Block_of_alloc_area( alloc_area_begin, page_size );
     169  first_block = (Heap_Block *) first_block_begin;
    158170  first_block->prev_size = page_size;
    159   first_block->size_and_flag = alloc_area_size | HEAP_PREV_BLOCK_USED;
     171  first_block->size_and_flag = first_block_size | HEAP_PREV_BLOCK_USED;
    160172  first_block->next = _Heap_Free_list_tail( heap );
    161173  first_block->prev = _Heap_Free_list_head( heap );
     174
     175  /* Second and last block */
     176  second_block = _Heap_Block_at( first_block, first_block_size );
     177  second_block->prev_size = first_block_size;
     178  second_block->size_and_flag = page_size;
     179
     180  /* Heap control */
     181  heap->page_size = page_size;
     182  heap->min_block_size = min_block_size;
     183  heap->area_begin = heap_area_begin;
     184  heap->area_end = heap_area_end;
     185  heap->first_block = first_block;
     186  heap->last_block = second_block;
    162187  _Heap_Free_list_head( heap )->next = first_block;
    163188  _Heap_Free_list_tail( heap )->prev = first_block;
    164   heap->start = first_block;
    165 
    166   /* Second and last block */
    167   second_block = _Heap_Block_at( first_block, alloc_area_size );
    168   second_block->prev_size = alloc_area_size;
    169   second_block->size_and_flag = page_size | HEAP_PREV_BLOCK_FREE;
    170   heap->final = second_block;
    171189
    172190  /* Statistics */
    173   stats->size = area_size;
    174   stats->free_size = alloc_area_size;
    175   stats->min_free_size = alloc_area_size;
     191  stats->size = heap_area_size;
     192  stats->free_size = first_block_size;
     193  stats->min_free_size = first_block_size;
    176194  stats->free_blocks = 1;
    177195  stats->max_free_blocks = 1;
     
    184202  stats->instance = instance++;
    185203
    186   _HAssert( _Heap_Is_aligned( CPU_ALIGNMENT, 4 ));
    187   _HAssert( _Heap_Is_aligned( heap->page_size, CPU_ALIGNMENT ));
    188   _HAssert( _Heap_Is_aligned( heap->min_block_size, page_size ));
     204  _HAssert( _Heap_Is_aligned( CPU_ALIGNMENT, 4 ) );
     205  _HAssert( _Heap_Is_aligned( heap->page_size, CPU_ALIGNMENT ) );
     206  _HAssert( _Heap_Is_aligned( heap->min_block_size, page_size ) );
    189207  _HAssert(
    190208    _Heap_Is_aligned( _Heap_Alloc_area_of_block( first_block ), page_size )
     
    194212  );
    195213
     214  if ( !_Heap_Walk( heap, 0, false ) ) {
     215    _Heap_Walk( heap, 0, true );
     216  }
     217
    196218  return alloc_area_size;
    197219}
    198220
    199 uintptr_t _Heap_Calc_block_size(
    200   uintptr_t alloc_size,
    201   uintptr_t page_size,
    202   uintptr_t min_block_size)
    203 {
    204   uintptr_t block_size =
    205     _Heap_Align_up( alloc_size + HEAP_BLOCK_USED_OVERHEAD, page_size );
    206 
    207   if (block_size < min_block_size) {
    208     block_size = min_block_size;
    209   }
    210 
    211   if (block_size > alloc_size) {
    212     return block_size;
    213   } else {
    214     /* Integer overflow occured */
    215     return 0;
    216   }
    217 }
    218 
    219 uintptr_t _Heap_Block_allocate(
     221static Heap_Block *_Heap_Block_split(
    220222  Heap_Control *heap,
    221223  Heap_Block *block,
     
    223225)
    224226{
    225   Heap_Statistics * const stats = &heap->stats;
     227  uintptr_t const page_size = heap->page_size;
     228  uintptr_t const min_block_size = heap->min_block_size;
     229  uintptr_t const min_alloc_size = min_block_size - HEAP_BLOCK_HEADER_SIZE;
     230
    226231  uintptr_t const block_size = _Heap_Block_size( block );
    227   uintptr_t const unused_size = block_size - alloc_size;
    228   Heap_Block *next_block = _Heap_Block_at( block, block_size );
    229 
    230   _HAssert( _Heap_Is_aligned( block_size, heap->page_size ));
    231   _HAssert( _Heap_Is_aligned( alloc_size, heap->page_size ));
    232   _HAssert( alloc_size <= block_size );
    233   _HAssert( _Heap_Is_prev_used( block ));
    234 
    235   if (unused_size >= heap->min_block_size) {
    236     /*
    237      * Split the block so that the upper part is still free, and the lower part
    238      * becomes used.  This is slightly less optimal than leaving the lower part
    239      * free as it requires replacing block in the free blocks list, but it
    240      * makes it possible to reuse this code in the _Heap_Resize_block().
    241      */
    242     Heap_Block *new_block = _Heap_Block_at( block, alloc_size );
    243     block->size_and_flag = alloc_size | HEAP_PREV_BLOCK_USED;
    244     new_block->size_and_flag = unused_size | HEAP_PREV_BLOCK_USED;
    245     next_block->prev_size = unused_size;
    246     _Heap_Block_replace_in_free_list( block, new_block );
     232
     233  uintptr_t const used_size =
     234    _Heap_Max( alloc_size, min_alloc_size ) + HEAP_BLOCK_HEADER_SIZE;
     235  uintptr_t const used_block_size = _Heap_Align_up( used_size, page_size );
     236
     237  uintptr_t const free_size = block_size + HEAP_BLOCK_SIZE_OFFSET - used_size;
     238  uintptr_t const free_size_limit = min_block_size + HEAP_BLOCK_SIZE_OFFSET;
     239
     240  Heap_Block *const next_block = _Heap_Block_at( block, block_size );
     241
     242  _HAssert( used_size <= block_size + HEAP_BLOCK_SIZE_OFFSET );
     243  _HAssert( used_size + free_size == block_size + HEAP_BLOCK_SIZE_OFFSET );
     244
     245  if ( free_size >= free_size_limit ) {
     246    uintptr_t const free_block_size = block_size - used_block_size;
     247    Heap_Block *const free_block = _Heap_Block_at( block, used_block_size );
     248
     249    _HAssert( used_block_size + free_block_size == block_size );
     250
     251    block->size_and_flag = used_block_size
     252      | (block->size_and_flag & HEAP_PREV_BLOCK_USED);
     253    free_block->size_and_flag = free_block_size | HEAP_PREV_BLOCK_USED;
     254    next_block->prev_size = free_block_size;
     255
     256    return free_block;
    247257  } else {
    248258    next_block->size_and_flag |= HEAP_PREV_BLOCK_USED;
    249     alloc_size = block_size;
    250     _Heap_Block_remove_from_free_list( block );
     259
     260    return NULL;
     261  }
     262}
     263
     264static Heap_Block *_Heap_Block_allocate_from_begin(
     265  Heap_Control *heap,
     266  Heap_Block *block,
     267  uintptr_t alloc_size
     268)
     269{
     270  Heap_Block *const free_block = _Heap_Block_split( heap, block, alloc_size );
     271
     272  if ( free_block != NULL ) {
     273    _Heap_Free_list_replace( block, free_block );
     274  } else {
     275    Heap_Statistics *const stats = &heap->stats;
     276
     277    _Heap_Free_list_remove( block );
    251278
    252279    /* Statistics */
     
    254281  }
    255282
     283  return block;
     284}
     285
     286static Heap_Block *_Heap_Block_allocate_from_end(
     287  Heap_Control *heap,
     288  Heap_Block *block,
     289  uintptr_t alloc_begin,
     290  uintptr_t alloc_size
     291)
     292{
     293  uintptr_t const block_begin = (uintptr_t) block;
     294  uintptr_t block_size = _Heap_Block_size( block );
     295  uintptr_t block_end = block_begin + block_size;
     296
     297  Heap_Block *const new_block =
     298    _Heap_Block_of_alloc_area( alloc_begin, heap->page_size );
     299  uintptr_t const new_block_begin = (uintptr_t) new_block;
     300  uintptr_t const new_block_size = block_end - new_block_begin;
     301
     302  Heap_Block *free_block = NULL;
     303
     304  block_end = new_block_begin;
     305  block_size = block_end - block_begin;
     306
     307  _HAssert( block_size >= heap->min_block_size );
     308  _HAssert( new_block_size >= heap->min_block_size );
     309
     310  block->size_and_flag = block_size | HEAP_PREV_BLOCK_USED;
     311  new_block->prev_size = block_size;
     312  new_block->size_and_flag = new_block_size;
     313
     314  free_block = _Heap_Block_split( heap, new_block, alloc_size );
     315  if ( free_block != NULL ) {
     316    _Heap_Free_list_insert_after( block, free_block );
     317  }
     318
     319  return new_block;
     320}
     321
     322Heap_Block *_Heap_Block_allocate(
     323  Heap_Control *heap,
     324  Heap_Block *block,
     325  uintptr_t alloc_begin,
     326  uintptr_t alloc_size
     327)
     328{
     329  Heap_Statistics *const stats = &heap->stats;
     330  uintptr_t const alloc_area_begin = _Heap_Alloc_area_of_block( block );
     331  uintptr_t const alloc_area_offset = alloc_begin - alloc_area_begin;
     332
     333  _HAssert( _Heap_Is_prev_used( block ) );
     334  _HAssert( alloc_area_begin <= alloc_begin );
     335
     336  if ( alloc_area_offset < heap->page_size ) {
     337    alloc_size += alloc_area_offset;
     338
     339    block = _Heap_Block_allocate_from_begin( heap, block, alloc_size );
     340  } else {
     341    block = _Heap_Block_allocate_from_end( heap, block, alloc_begin, alloc_size );
     342  }
     343
    256344  /* Statistics */
    257345  ++stats->used_blocks;
    258   stats->free_size -= alloc_size;
    259   if(stats->min_free_size > stats->free_size) {
     346  stats->free_size -= _Heap_Block_size( block );
     347  if ( stats->min_free_size > stats->free_size ) {
    260348    stats->min_free_size = stats->free_size;
    261349  }
    262350
    263   return alloc_size;
    264 }
     351  return block;
     352}
  • cpukit/score/src/heapallocate.c

    r6685aa09 rdea3eccb  
     1/**
     2 * @file
     3 *
     4 * @ingroup ScoreHeap
     5 *
     6 * @brief Heap Handler implementation.
     7 */
     8
    19/*
    2  *  Heap Handler
    3  *
    410 *  COPYRIGHT (c) 1989-1999.
    511 *  On-Line Applications Research Corporation (OAR).
     12 *
     13 *  Copyright (c) 2009 embedded brains GmbH.
    614 *
    715 *  The license and distribution terms for this file may be
     
    2028#include <rtems/score/heap.h>
    2129
    22 void *_Heap_Allocate( Heap_Control *heap, uintptr_t size )
     30#ifdef RTEMS_HEAP_DEBUG
     31  static void _Heap_Check_allocation(
     32    const Heap_Control *heap,
     33    const Heap_Block *block,
     34    uintptr_t alloc_begin,
     35    uintptr_t alloc_size,
     36    uintptr_t alignment,
     37    uintptr_t boundary
     38  )
     39  {
     40    uintptr_t const min_block_size = heap->min_block_size;
     41    uintptr_t const page_size = heap->page_size;
     42
     43    uintptr_t const block_begin = (uintptr_t) block;
     44    uintptr_t const block_size = _Heap_Block_size( block );
     45    uintptr_t const block_end = block_begin + block_size;
     46
     47    uintptr_t const alloc_end = alloc_begin + alloc_size;
     48
     49    uintptr_t const alloc_area_begin = _Heap_Alloc_area_of_block( block );
     50    uintptr_t const alloc_area_offset = alloc_begin - alloc_area_begin;
     51    uintptr_t const alloc_area_size = alloc_area_offset + alloc_size;
     52
     53    _HAssert( block_size >= min_block_size );
     54    _HAssert( block_begin < block_end );
     55    _HAssert(
     56      _Heap_Is_aligned( block_begin + HEAP_BLOCK_HEADER_SIZE, page_size )
     57    );
     58    _HAssert(
     59      _Heap_Is_aligned( block_size, page_size )
     60    );
     61
     62    _HAssert( alloc_end <= block_end + HEAP_BLOCK_SIZE_OFFSET );
     63    _HAssert( alloc_area_begin == block_begin + HEAP_BLOCK_HEADER_SIZE);
     64    _HAssert( alloc_area_offset < page_size );
     65
     66    _HAssert( _Heap_Is_aligned( alloc_area_begin, page_size ) );
     67    if ( alignment == 0 ) {
     68      _HAssert( alloc_begin == alloc_area_begin );
     69    } else {
     70      _HAssert( _Heap_Is_aligned( alloc_begin, alignment ) );
     71    }
     72
     73    if ( boundary != 0 ) {
     74      uintptr_t boundary_line = _Heap_Align_down( alloc_end, boundary );
     75
     76      _HAssert( alloc_size <= boundary );
     77      _HAssert( boundary_line <= alloc_begin || alloc_end <= boundary_line );
     78    }
     79  }
     80#else
     81  #define _Heap_Check_allocation( h, b, ab, as, ag, bd ) ((void) 0)
     82#endif
     83
     84static uintptr_t _Heap_Check_block(
     85  const Heap_Control *heap,
     86  const Heap_Block *block,
     87  uintptr_t alloc_size,
     88  uintptr_t alignment,
     89  uintptr_t boundary
     90)
     91{
     92  uintptr_t const page_size = heap->page_size;
     93  uintptr_t const min_block_size = heap->min_block_size;
     94
     95  uintptr_t const block_begin = (uintptr_t) block;
     96  uintptr_t const block_size = _Heap_Block_size( block );
     97  uintptr_t const block_end = block_begin + block_size;
     98
     99  uintptr_t const alloc_begin_floor = _Heap_Alloc_area_of_block( block );
     100  uintptr_t const alloc_begin_ceiling = block_end - min_block_size
     101    + HEAP_BLOCK_HEADER_SIZE + page_size - 1;
     102
     103  uintptr_t alloc_end = block_end + HEAP_BLOCK_SIZE_OFFSET;
     104  uintptr_t alloc_begin = alloc_end - alloc_size;
     105
     106  alloc_begin = _Heap_Align_down( alloc_begin, alignment );
     107
     108  /* Ensure that the we have a valid new block at the end */
     109  if ( alloc_begin > alloc_begin_ceiling ) {
     110    alloc_begin = _Heap_Align_down( alloc_begin_ceiling, alignment );
     111  }
     112
     113  alloc_end = alloc_begin + alloc_size;
     114
     115  /* Ensure boundary constaint */
     116  if ( boundary != 0 ) {
     117    uintptr_t const boundary_floor = alloc_begin_floor + alloc_size;
     118    uintptr_t boundary_line = _Heap_Align_down( alloc_end, boundary );
     119
     120    while ( alloc_begin < boundary_line && boundary_line < alloc_end ) {
     121      if ( boundary_line < boundary_floor ) {
     122        return 0;
     123      }
     124      alloc_begin = boundary_line - alloc_size;
     125      alloc_begin = _Heap_Align_down( alloc_begin, alignment );
     126      alloc_end = alloc_begin + alloc_size;
     127      boundary_line = _Heap_Align_down( alloc_end, boundary );
     128    }
     129  }
     130
     131  /* Ensure that the we have a valid new block at the beginning */
     132  if ( alloc_begin >= alloc_begin_floor ) {
     133    uintptr_t const alloc_block_begin =
     134      (uintptr_t) _Heap_Block_of_alloc_area( alloc_begin, page_size );
     135    uintptr_t const free_size = alloc_block_begin - block_begin;
     136
     137    if ( free_size >= min_block_size || free_size == 0 ) {
     138      return alloc_begin;
     139    }
     140  }
     141
     142  return 0;
     143}
     144
     145void *_Heap_Allocate_aligned_with_boundary(
     146  Heap_Control *heap,
     147  uintptr_t alloc_size,
     148  uintptr_t alignment,
     149  uintptr_t boundary
     150)
    23151{
    24152  Heap_Statistics *const stats = &heap->stats;
    25   Heap_Block * const tail = _Heap_Free_list_tail( heap );
    26   Heap_Block *block = _Heap_First_free_block( heap );
     153  Heap_Block *const free_list_tail = _Heap_Free_list_tail( heap );
     154  Heap_Block *block = _Heap_Free_list_first( heap );
     155  uintptr_t const block_size_floor = alloc_size + HEAP_BLOCK_HEADER_SIZE
     156    - HEAP_BLOCK_SIZE_OFFSET;
     157  uintptr_t const page_size = heap->page_size;
     158  uintptr_t alloc_begin = 0;
    27159  uint32_t search_count = 0;
    28   void *alloc_area_begin_ptr = NULL;
    29 
    30   size = _Heap_Calc_block_size( size, heap->page_size, heap->min_block_size );
    31   if( size == 0 ) {
     160
     161  if ( block_size_floor < alloc_size ) {
     162    /* Integer overflow occured */
    32163    return NULL;
    33164  }
    34165
    35   /*
    36    * Find large enough free block.
    37    *
    38    * Do not bother to mask out the HEAP_PREV_BLOCK_USED bit as it will not
    39    * change the result of the size comparison.
    40    */
    41   while (block != tail && block->size_and_flag < size) {
    42     _HAssert( _Heap_Is_prev_used( block ));
     166  if ( boundary != 0 ) {
     167    if ( boundary < alloc_size ) {
     168      return NULL;
     169    }
     170
     171    if ( alignment == 0 ) {
     172      alignment = page_size;
     173    }
     174  }
     175
     176  while ( block != free_list_tail ) {
     177    _HAssert( _Heap_Is_prev_used( block ) );
     178
     179    /* Statistics */
     180    ++search_count;
     181
     182    /*
     183     * The HEAP_PREV_BLOCK_USED flag is always set in the block size_and_flag
     184     * field.  Thus the value is about one unit larger than the real block
     185     * size.  The greater than operator takes this into account.
     186     */
     187    if ( block->size_and_flag > block_size_floor ) {
     188      if ( alignment == 0 ) {
     189        alloc_begin = _Heap_Alloc_area_of_block( block );
     190      } else {
     191        alloc_begin = _Heap_Check_block(
     192          heap,
     193          block,
     194          alloc_size,
     195          alignment,
     196          boundary
     197        );
     198      }
     199    }
     200
     201    if ( alloc_begin != 0 ) {
     202      break;
     203    }
    43204
    44205    block = block->next;
    45     ++search_count;
    46   }
    47 
    48   if (block != tail) {
    49     _Heap_Block_allocate( heap, block, size );
    50 
    51     alloc_area_begin_ptr = (void *) _Heap_Alloc_area_of_block( block );
    52 
    53     _HAssert( _Heap_Is_aligned( (uintptr_t) alloc_area_begin_ptr, heap->page_size ));
     206  }
     207
     208  if ( alloc_begin != 0 ) {
     209    block = _Heap_Block_allocate( heap, block, alloc_begin, alloc_size );
     210
     211    _Heap_Check_allocation(
     212      heap,
     213      block,
     214      alloc_begin,
     215      alloc_size,
     216      alignment,
     217      boundary
     218    );
    54219
    55220    /* Statistics */
    56     ++stats->allocs;
    57221    stats->searches += search_count;
    58222  }
    59223
    60224  /* Statistics */
    61   if (stats->max_search < search_count) {
     225  if ( stats->max_search < search_count ) {
    62226    stats->max_search = search_count;
    63227  }
    64228
    65   return alloc_area_begin_ptr;
     229  return (void *) alloc_begin;
    66230}
  • cpukit/score/src/heapallocatealigned.c

    r6685aa09 rdea3eccb  
     1#if 0
    12/*
    23 *  Heap Handler
     
    3233{
    3334  uintptr_t const user_area = _Heap_Alloc_area_of_block(the_block);
    34   uintptr_t const block_end = the_block
     35  uintptr_t const block_end = (uintptr_t) the_block
    3536    + _Heap_Block_size(the_block) + HEAP_BLOCK_SIZE_OFFSET;
    3637  uintptr_t const user_end = aligned_user_addr + size;
    37   uintptr_t const heap_start = (uintptr_t) the_heap->start + HEAP_LAST_BLOCK_OVERHEAD;
     38  uintptr_t const heap_start = (uintptr_t) the_heap->start + HEAP_BLOCK_HEADER_SIZE;
    3839  uintptr_t const heap_end = (uintptr_t) the_heap->final
    3940    + HEAP_BLOCK_SIZE_OFFSET;
     
    9899       used as a separate free block. Change 'alloc_size' to the size of the
    99100       block and remove the block from the list of free blocks. */
    100     _Heap_Block_remove_from_free_list(the_block);
     101    _Heap_Free_list_remove(the_block);
    101102    alloc_size = block_size;
    102103    stats->free_blocks -= 1;
     
    158159  /* Find large enough free block that satisfies the alignment requirements. */
    159160
    160   for (the_block = _Heap_First_free_block(the_heap), search_count = 0;
     161  for (the_block = _Heap_Free_list_first(the_heap), search_count = 0;
    161162      the_block != tail;
    162163      the_block = the_block->next, ++search_count)
     
    221222           to be allocated and perform allocation. */
    222223        uintptr_t const alloc_size =
    223             block_end - user_addr + HEAP_BLOCK_ALLOC_AREA_OFFSET;
     224            block_end - user_addr + HEAP_BLOCK_HEADER_SIZE;
    224225
    225226        _HAssert(_Heap_Is_aligned(aligned_user_addr, alignment));
     
    245246  return user_ptr;
    246247}
     248#endif
  • cpukit/score/src/heapextend.c

    r6685aa09 rdea3eccb  
     1/**
     2 * @file
     3 *
     4 * @ingroup ScoreHeap
     5 *
     6 * @brief Heap Handler implementation.
     7 */
     8
    19/*
    2  *  Heap Handler
    3  *
    410 *  COPYRIGHT (c) 1989-1999.
    511 *  On-Line Applications Research Corporation (OAR).
     
    2935  Heap_Statistics *const stats = &heap->stats;
    3036  uintptr_t const area_begin = (uintptr_t) area_begin_ptr;
    31   uintptr_t const heap_area_begin = heap->begin;
    32   uintptr_t const heap_area_end = heap->end;
     37  uintptr_t const heap_area_begin = heap->area_begin;
     38  uintptr_t const heap_area_end = heap->area_end;
    3339  uintptr_t const new_heap_area_end = heap_area_end + area_size;
    3440  uintptr_t extend_size = 0;
    35   Heap_Block *const old_final = heap->final;
     41  Heap_Block *const old_final = heap->last_block;
    3642  Heap_Block *new_final = NULL;
    3743
     
    6167   */
    6268
    63   heap->end = new_heap_area_end;
     69  heap->area_end = new_heap_area_end;
    6470
    6571  extend_size = new_heap_area_end
    66     - (uintptr_t) old_final - HEAP_LAST_BLOCK_OVERHEAD;
     72    - (uintptr_t) old_final - HEAP_BLOCK_HEADER_SIZE;
    6773  extend_size = _Heap_Align_down( extend_size, heap->page_size );
    6874
     
    7581    new_final->size_and_flag = heap->page_size | HEAP_PREV_BLOCK_USED;
    7682
    77     heap->final = new_final;
     83    heap->last_block = new_final;
    7884
    7985    stats->size += area_size;
  • cpukit/score/src/heapfree.c

    r6685aa09 rdea3eccb  
     1/**
     2 * @file
     3 *
     4 * @ingroup ScoreHeap
     5 *
     6 * @brief Heap Handler implementation.
     7 */
     8
    19/*
    2  *  Heap Handler
    3  *
    410 *  COPYRIGHT (c) 1989-2007.
    511 *  On-Line Applications Research Corporation (OAR).
     
    2026#include <rtems/score/heap.h>
    2127
    22 bool _Heap_Free( Heap_Control *heap, void *alloc_area_begin_ptr )
     28bool _Heap_Free( Heap_Control *heap, void *alloc_begin_ptr )
    2329{
    2430  Heap_Statistics *const stats = &heap->stats;
    25   uintptr_t alloc_area_begin = (uintptr_t) alloc_area_begin_ptr;
     31  uintptr_t alloc_begin = (uintptr_t) alloc_begin_ptr;
    2632  Heap_Block *block =
    27     _Heap_Block_of_alloc_area( alloc_area_begin, heap->page_size );
     33    _Heap_Block_of_alloc_area( alloc_begin, heap->page_size );
    2834  Heap_Block *next_block = NULL;
    2935  uintptr_t block_size = 0;
     
    3137  bool next_is_free = false;
    3238
    33   if (
    34     !_Addresses_Is_in_range( alloc_area_begin_ptr, heap->start, heap->final)
    35   ) {
    36     _HAssert( alloc_area_begin_ptr != NULL );
    37     return false;
    38   }
    39 
    4039  if ( !_Heap_Is_block_in_heap( heap, block ) ) {
    41     _HAssert( false );
    4240    return false;
    4341  }
     
    5755
    5856  next_block_size = _Heap_Block_size( next_block );
    59   next_is_free = next_block != heap->final
     57  next_is_free = next_block != heap->last_block
    6058    && !_Heap_Is_prev_used( _Heap_Block_at( next_block, next_block_size ));
    6159
     
    7876    if ( next_is_free ) {       /* coalesce both */
    7977      uintptr_t const size = block_size + prev_size + next_block_size;
    80       _Heap_Block_remove_from_free_list( next_block );
     78      _Heap_Free_list_remove( next_block );
    8179      stats->free_blocks -= 1;
    8280      prev_block->size_and_flag = size | HEAP_PREV_BLOCK_USED;
     
    9290  } else if ( next_is_free ) {    /* coalesce next */
    9391    uintptr_t const size = block_size + next_block_size;
    94     _Heap_Block_replace_in_free_list( next_block, block );
     92    _Heap_Free_list_replace( next_block, block );
    9593    block->size_and_flag = size | HEAP_PREV_BLOCK_USED;
    9694    next_block  = _Heap_Block_at( block, size );
     
    9997    /* Add 'block' to the head of the free blocks list as it tends to
    10098       produce less fragmentation than adding to the tail. */
    101     _Heap_Block_insert_after( _Heap_Free_list_head( heap), block );
     99    _Heap_Free_list_insert_after( _Heap_Free_list_head( heap), block );
    102100    block->size_and_flag = block_size | HEAP_PREV_BLOCK_USED;
    103101    next_block->size_and_flag &= ~HEAP_PREV_BLOCK_USED;
  • cpukit/score/src/heapgetfreeinfo.c

    r6685aa09 rdea3eccb  
     1/**
     2 * @file
     3 *
     4 * @ingroup ScoreHeap
     5 *
     6 * @brief Heap Handler implementation.
     7 */
     8
    19/*
    2  *  Heap Handler
    3  *
    410 *  COPYRIGHT (c) 1989-2004.
    511 *  On-Line Applications Research Corporation (OAR).
     
    2026#include <rtems/score/heap.h>
    2127
    22 /*PAGE
    23  *
    24  *  _Heap_Get_free_information
    25  *
    26  *  This heap routine returns information about the free blocks
    27  *  in the specified heap.
    28  *
    29  *  Input parameters:
    30  *    the_heap  - pointer to heap header.
    31  *    info      - pointer to the free block information.
    32  *
    33  *  Output parameters:
    34  *    returns - free block information filled in.
    35  */
    36 
    3728void _Heap_Get_free_information(
    3829  Heap_Control        *the_heap,
     
    4738  info->total = 0;
    4839
    49   for(the_block = _Heap_First_free_block(the_heap);
     40  for(the_block = _Heap_Free_list_first(the_heap);
    5041      the_block != tail;
    5142      the_block = the_block->next)
  • cpukit/score/src/heapgetinfo.c

    r6685aa09 rdea3eccb  
     1/**
     2 * @file
     3 *
     4 * @ingroup ScoreHeap
     5 *
     6 * @brief Heap Handler implementation.
     7 */
     8
    19/*
    2  *  Heap Handler
    3  *
    410 *  COPYRIGHT (c) 1989-2009.
    511 *  On-Line Applications Research Corporation (OAR).
     
    2026#include <rtems/score/heap.h>
    2127
    22 /*
    23  *  _Heap_Get_information
    24  *
    25  *  This kernel routine walks the heap and tots up the free and allocated
    26  *  sizes.  Derived from _Heap_Walk.
    27  *
    28  *  Input parameters:
    29  *    the_heap  - pointer to heap header
    30  *    the_info  - pointer for information to be returned
    31  *
    32  *  Output parameters:
    33  *    *the_info  - contains information about heap
    34  *    return 0=success, otherwise heap is corrupt.
    35  */
    36 Heap_Get_information_status _Heap_Get_information(
     28void _Heap_Get_information(
    3729  Heap_Control            *the_heap,
    3830  Heap_Information_block  *the_info
    3931)
    4032{
    41   Heap_Block *the_block = the_heap->start;
    42   Heap_Block *const end = the_heap->final;
     33  Heap_Block *the_block = the_heap->first_block;
     34  Heap_Block *const end = the_heap->last_block;
    4335
    4436  _HAssert(the_block->prev_size == the_heap->page_size);
     
    5345
    5446  while ( the_block != end ) {
    55     uint32_t const     the_size = _Heap_Block_size(the_block);
     47    uintptr_t const     the_size = _Heap_Block_size(the_block);
    5648    Heap_Block *const  next_block = _Heap_Block_at(the_block, the_size);
    5749    Heap_Information  *info;
     
    7567   *  blocks' overhead though.
    7668   */
    77   the_info->Used.total += HEAP_LAST_BLOCK_OVERHEAD;
    78 
    79   return HEAP_GET_INFORMATION_SUCCESSFUL;
     69  the_info->Used.total += HEAP_BLOCK_HEADER_SIZE;
    8070}
  • cpukit/score/src/heapresizeblock.c

    r6685aa09 rdea3eccb  
     1/**
     2 * @file
     3 *
     4 * @ingroup ScoreHeap
     5 *
     6 * @brief Heap Handler implementation.
     7 */
     8
    19/*
    2  *  Heap Handler
    3  *
    410 *  COPYRIGHT (c) 1989-1999.
    511 *  On-Line Applications Research Corporation (OAR).
     
    2228Heap_Resize_status _Heap_Resize_block(
    2329  Heap_Control *heap,
    24   void         *alloc_area_begin_ptr,
    25   uintptr_t      size,
    26   uintptr_t     *old_mem_size,
    27   uintptr_t     *avail_mem_size
     30  void *alloc_begin_ptr,
     31  uintptr_t new_alloc_size,
     32  uintptr_t *old_size,
     33  uintptr_t *new_size
    2834)
    2935{
    30   uintptr_t alloc_area_begin = (uintptr_t) alloc_area_begin_ptr;
    31   Heap_Block *block;
    32   Heap_Block *next_block;
    33   uintptr_t   next_block_size;
    34   bool       next_is_used;
    35   Heap_Block *next_next_block;
    36   uintptr_t   old_block_size;
    37   uintptr_t   old_user_size;
    38   uintptr_t   prev_used_flag;
    3936  Heap_Statistics *const stats = &heap->stats;
    4037  uintptr_t const min_block_size = heap->min_block_size;
    4138  uintptr_t const page_size = heap->page_size;
     39  uintptr_t const alloc_begin = (uintptr_t) alloc_begin_ptr;
     40  Heap_Block *const block = _Heap_Block_of_alloc_area( alloc_begin, page_size );
     41  Heap_Block *next_block = NULL;
     42  Heap_Block *next_next_block = NULL;
     43  uintptr_t block_size = 0;
     44  uintptr_t block_end = 0;
     45  uintptr_t next_block_size = 0;
     46  bool next_block_is_used = false;;
     47  uintptr_t alloc_size = 0;
     48  uintptr_t prev_block_used_flag = 0;
    4249
    43   *old_mem_size = 0;
    44   *avail_mem_size = 0;
     50  *old_size = 0;
     51  *new_size = 0;
    4552
    46   block = _Heap_Block_of_alloc_area(alloc_area_begin, heap->page_size);
    47   _HAssert(_Heap_Is_block_in_heap(heap, block));
    48   if (!_Heap_Is_block_in_heap(heap, block))
     53  if ( !_Heap_Is_block_in_heap( heap, block ) ) {
    4954    return HEAP_RESIZE_FATAL_ERROR;
     55  }
    5056
    51   prev_used_flag = block->size_and_flag & HEAP_PREV_BLOCK_USED;
    52   old_block_size = _Heap_Block_size(block);
    53   next_block = _Heap_Block_at(block, old_block_size);
     57  block_size = _Heap_Block_size( block );
     58  block_end = (uintptr_t) block + block_size;
     59  prev_block_used_flag = block->size_and_flag & HEAP_PREV_BLOCK_USED;
     60  next_block = _Heap_Block_at( block, block_size );
    5461
    55   _HAssert(_Heap_Is_block_in_heap(heap, next_block));
    56   _HAssert(_Heap_Is_prev_used(next_block));
    57   if ( !_Heap_Is_block_in_heap(heap, next_block) ||
    58        !_Heap_Is_prev_used(next_block))
    59     return HEAP_RESIZE_FATAL_ERROR;
     62  _HAssert( _Heap_Is_block_in_heap( heap, next_block ) );
     63  _HAssert( _Heap_Is_prev_used( next_block ) );
    6064
    61   next_block_size = _Heap_Block_size(next_block);
    62   next_next_block = _Heap_Block_at(next_block, next_block_size);
    63   next_is_used    = (next_block == heap->final) ||
    64                      _Heap_Is_prev_used(next_next_block);
     65  next_block_size = _Heap_Block_size( next_block );
     66  next_next_block = _Heap_Block_at( next_block, next_block_size );
    6567
    66   /* See _Heap_Size_of_alloc_area() source for explanations */
    67   old_user_size = (uintptr_t) next_block - alloc_area_begin
    68     + HEAP_BLOCK_SIZE_OFFSET;
     68  _HAssert(
     69    next_block == heap->last_block
     70      || _Heap_Is_block_in_heap( heap, next_next_block )
     71  );
    6972
    70   *old_mem_size = old_user_size;
     73  next_block_is_used = next_block == heap->last_block
     74    || _Heap_Is_prev_used( next_next_block );
    7175
    72   if (size > old_user_size) {
    73     /* Need to extend the block: allocate part of the next block and then
    74        merge 'block' and allocated block together. */
    75     if (next_is_used)    /* Next block is in use, -- no way to extend */
     76  alloc_size = block_end - alloc_begin + HEAP_BLOCK_SIZE_OFFSET;
     77
     78  *old_size = alloc_size;
     79
     80  if ( new_alloc_size > alloc_size ) {
     81    /*
     82     * Need to extend the block: allocate part of the next block and then
     83     * merge the blocks.
     84     */
     85    if ( next_block_is_used ) {
    7686      return HEAP_RESIZE_UNSATISFIED;
    77     else {
     87    } else {
    7888      uintptr_t add_block_size =
    79         _Heap_Align_up(size - old_user_size, page_size);
    80       if (add_block_size < min_block_size)
     89        _Heap_Align_up( new_alloc_size - alloc_size, page_size );
     90
     91      if ( add_block_size < min_block_size ) {
    8192        add_block_size = min_block_size;
    82       if (add_block_size > next_block_size)
    83         return HEAP_RESIZE_UNSATISFIED; /* Next block is too small or none. */
    84       add_block_size =
    85         _Heap_Block_allocate(heap, next_block, add_block_size);
    86       /* Merge two subsequent blocks */
    87       block->size_and_flag = (old_block_size + add_block_size) | prev_used_flag;
     93      }
     94
     95      if ( add_block_size > next_block_size ) {
     96        return HEAP_RESIZE_UNSATISFIED;
     97      }
     98
     99      next_block = _Heap_Block_allocate(
     100        heap,
     101        next_block,
     102        _Heap_Alloc_area_of_block( next_block ),
     103        add_block_size - HEAP_BLOCK_HEADER_SIZE
     104      );
     105
     106      /* Merge the blocks */
     107      block->size_and_flag = ( block_size + _Heap_Block_size( next_block ) )
     108        | prev_block_used_flag;
     109
     110      /* Statistics */
    88111      --stats->used_blocks;
    89112    }
    90113  } else {
    91 
    92114    /* Calculate how much memory we could free */
    93115    uintptr_t free_block_size =
    94       _Heap_Align_down(old_user_size - size, page_size);
     116      _Heap_Align_down( alloc_size - new_alloc_size, page_size );
    95117
    96     if (free_block_size > 0) {
     118    if ( free_block_size > 0 ) {
     119      /*
     120       * To free some memory the block should be shortened so that it can can
     121       * hold 'new_alloc_size' user bytes and still remain not shorter than
     122       * 'min_block_size'.
     123       */
     124      uintptr_t new_block_size = block_size - free_block_size;
    97125
    98       /* To free some memory the block should be shortened so that it can
    99          can hold 'size' user bytes and still remain not shorter than
    100          'min_block_size'. */
     126      if ( new_block_size < min_block_size ) {
     127        uintptr_t const delta = min_block_size - new_block_size;
    101128
    102       uintptr_t new_block_size = old_block_size - free_block_size;
     129        _HAssert( free_block_size >= delta );
    103130
    104       if (new_block_size < min_block_size) {
    105         uintptr_t delta = min_block_size - new_block_size;
    106         _HAssert(free_block_size >= delta);
    107131        free_block_size -= delta;
    108         if (free_block_size == 0) {
     132
     133        if ( free_block_size == 0 ) {
     134          /* Statistics */
    109135          ++stats->resizes;
     136
    110137          return HEAP_RESIZE_SUCCESSFUL;
    111138        }
     139
    112140        new_block_size += delta;
    113141      }
    114142
    115       _HAssert(new_block_size >= min_block_size);
    116       _HAssert(new_block_size + free_block_size == old_block_size);
    117       _HAssert(_Heap_Is_aligned(new_block_size, page_size));
    118       _HAssert(_Heap_Is_aligned(free_block_size, page_size));
     143      _HAssert( new_block_size >= min_block_size );
     144      _HAssert( new_block_size + free_block_size == block_size );
     145      _HAssert( _Heap_Is_aligned( new_block_size, page_size ) );
     146      _HAssert( _Heap_Is_aligned( free_block_size, page_size ) );
    119147
    120       if (!next_is_used) {
    121         /* Extend the next block to the low addresses by 'free_block_size' */
     148      if ( !next_block_is_used ) {
     149        /* Extend the next block */
    122150        Heap_Block *const new_next_block =
    123           _Heap_Block_at(block, new_block_size);
     151          _Heap_Block_at( block, new_block_size );
    124152        uintptr_t const new_next_block_size =
    125153          next_block_size + free_block_size;
    126         _HAssert(_Heap_Is_block_in_heap(heap, next_next_block));
    127         block->size_and_flag = new_block_size | prev_used_flag;
    128         new_next_block->size_and_flag = new_next_block_size | HEAP_PREV_BLOCK_USED;
     154
     155        _HAssert( _Heap_Is_block_in_heap( heap, next_next_block ) );
     156
     157        block->size_and_flag = new_block_size | prev_block_used_flag;
     158        new_next_block->size_and_flag =
     159          new_next_block_size | HEAP_PREV_BLOCK_USED;
    129160        next_next_block->prev_size = new_next_block_size;
    130         _Heap_Block_replace_in_free_list(next_block, new_next_block);
    131         heap->stats.free_size += free_block_size;
    132         *avail_mem_size = new_next_block_size - HEAP_BLOCK_USED_OVERHEAD;
    133161
    134       } else if (free_block_size >= min_block_size) {
    135         /* Split the block into 2 used  parts, then free the second one. */
    136         block->size_and_flag = new_block_size | prev_used_flag;
    137         next_block = _Heap_Block_at(block, new_block_size);
     162        _Heap_Free_list_replace( next_block, new_next_block );
     163
     164        *new_size = new_next_block_size - HEAP_BLOCK_SIZE_OFFSET;
     165
     166        /* Statistics */
     167        stats->free_size += free_block_size;
     168      } else if ( free_block_size >= min_block_size ) {
     169        /* Split the block into two used parts, then free the second one */
     170        block->size_and_flag = new_block_size | prev_block_used_flag;
     171        next_block = _Heap_Block_at( block, new_block_size );
    138172        next_block->size_and_flag = free_block_size | HEAP_PREV_BLOCK_USED;
     173
     174        _Heap_Free( heap, (void *) _Heap_Alloc_area_of_block( next_block ) );
     175
     176        *new_size = free_block_size - HEAP_BLOCK_SIZE_OFFSET;
     177
     178        /* Statistics */
    139179        ++stats->used_blocks; /* We have created used block */
    140         --stats->frees;       /* Don't count next call in stats */
    141         _Heap_Free(heap, (void *) _Heap_Alloc_area_of_block(next_block));
    142         *avail_mem_size = free_block_size - HEAP_BLOCK_USED_OVERHEAD;
     180        --stats->frees; /* Do not count next call in stats */
    143181      }
    144182    }
    145183  }
    146184
     185  /* Statistics */
    147186  ++stats->resizes;
     187
    148188  return HEAP_RESIZE_SUCCESSFUL;
    149189}
  • cpukit/score/src/heapsizeofuserarea.c

    r6685aa09 rdea3eccb  
     1/**
     2 * @file
     3 *
     4 * @ingroup ScoreHeap
     5 *
     6 * @brief Heap Handler implementation.
     7 */
     8
    19/*
    2  *  Heap Handler
    3  *
    410 *  COPYRIGHT (c) 1989-1999.
    511 *  On-Line Applications Research Corporation (OAR).
     
    2228bool _Heap_Size_of_alloc_area(
    2329  Heap_Control *heap,
    24   void *alloc_area_begin_ptr,
    25   uintptr_t *size
     30  void *alloc_begin_ptr,
     31  uintptr_t *alloc_size
    2632)
    2733{
    28   uintptr_t alloc_area_begin = (uintptr_t) alloc_area_begin_ptr;
    29   Heap_Block *block =
    30     _Heap_Block_of_alloc_area( alloc_area_begin, heap->page_size );
     34  uintptr_t const page_size = heap->page_size;
     35  uintptr_t const alloc_begin = (uintptr_t) alloc_begin_ptr;
     36  Heap_Block *block = _Heap_Block_of_alloc_area( alloc_begin, page_size );
    3137  Heap_Block *next_block = NULL;
    3238  uintptr_t block_size = 0;
    3339
    34   if (
    35     !_Addresses_Is_in_range( alloc_area_begin_ptr, heap->start, heap->final )
    36   ) {
    37     return false;
    38   }
    39 
    40 
    41   _HAssert(_Heap_Is_block_in_heap( heap, block ));
    4240  if ( !_Heap_Is_block_in_heap( heap, block ) ) {
    4341    return false;
     
    4745  next_block = _Heap_Block_at( block, block_size );
    4846
    49   _HAssert( _Heap_Is_block_in_heap( heap, next_block ));
    50   _HAssert( _Heap_Is_prev_used( next_block ));
    5147  if (
    52     !_Heap_Is_block_in_heap( heap, next_block ) ||
    53     !_Heap_Is_prev_used( next_block )
     48    !_Heap_Is_block_in_heap( heap, next_block )
     49      || !_Heap_Is_prev_used( next_block )
    5450  ) {
    5551    return false;
    5652  }
    5753
    58   /*
    59    * 'alloc_area_begin' could be greater than 'block' address plus
    60    * HEAP_BLOCK_ALLOC_AREA_OFFSET as _Heap_Allocate_aligned() may produce such
    61    * user pointers. To get rid of this offset we calculate user size as
    62    * difference between the end of 'block' (='next_block') and
    63    * 'alloc_area_begin' and then add correction equal to the offset of the
    64    * 'size' field of the 'Heap_Block' structure. The correction is due to the
    65    * fact that 'prev_size' field of the next block is actually used as user
    66    * accessible area of 'block'.
    67    */
    68   *size = (uintptr_t) next_block - alloc_area_begin + HEAP_BLOCK_SIZE_OFFSET;
     54  *alloc_size = (uintptr_t) next_block + HEAP_BLOCK_SIZE_OFFSET - alloc_begin;
    6955
    7056  return true;
  • cpukit/score/src/heapwalk.c

    r6685aa09 rdea3eccb  
     1/**
     2 * @file
     3 *
     4 * @ingroup ScoreHeap
     5 *
     6 * @brief Heap Handler implementation.
     7 */
     8
    19/*
    2  *  Heap Handler
    3  *
    4  *  COPYRIGHT (c) 1989-2007.
    5  *  On-Line Applications Research Corporation (OAR).
     10 *  COPYRIGHT ( c ) 1989-2007.
     11 *  On-Line Applications Research Corporation ( OAR ).
    612 *
    713 *  The license and distribution terms for this file may be
     
    2329#include <rtems/bspIo.h>
    2430
    25 #if defined(__GNUC__)
    26   #define DO_NOT_INLINE __attribute__((__noinline__))
    27 #else
    28   #define DO_NOT_INLINE
    29 #endif
    30 /*
    31  *  Helper to avoid introducing even more branches and paths in this
    32  *  code to do coverage analysis on.
    33  *
    34  *  We do not want this inlined.
    35  */
    36 static void hw_nl(
    37   int    error,
    38   bool   do_dump
    39 ) DO_NOT_INLINE;
    40 
    41 /*PAGE
    42  *
    43  *  _Heap_Walk
    44  *
    45  *  This kernel routine walks the heap and verifies its correctness.
    46  *
    47  *  Input parameters:
    48  *    the_heap  - pointer to heap header
    49  *    source    - a numeric indicator of the invoker of this routine
    50  *    do_dump   - when true print the information
    51  *
    52  *  Output parameters: NONE
    53  */
    54 
    55 bool _Heap_Walk(
    56   Heap_Control  *the_heap,
    57   int            source,
    58   bool           do_dump
     31static void _Heap_Walk_printk( int source, bool dump, bool error, const char *fmt, ... )
     32{
     33  if ( dump ) {
     34    va_list ap;
     35
     36    if ( error ) {
     37      printk( "FAIL[%d]: ", source );
     38    } else {
     39      printk( "PASS[%d]: ", source );
     40    }
     41
     42    va_start( ap, fmt );
     43    vprintk( fmt, ap );
     44    va_end( ap );
     45  }
     46}
     47
     48static bool _Heap_Walk_check_free_list(
     49  int source,
     50  bool dump,
     51  Heap_Control *heap
    5952)
    6053{
    61   Heap_Block *the_block = the_heap->start;
    62   Heap_Block *const end = the_heap->final;
    63   Heap_Block *const tail = _Heap_Free_list_tail(the_heap);
    64   int error = 0;
    65   int passes = 0;
    66 
    67   /* FIXME: Why is this disabled? */
    68   do_dump = false;
    69 
    70   /* FIXME: Why is this disabled? */
    71   /*
    72    * We don't want to allow walking the heap until we have
    73    * transferred control to the user task so we watch the
    74    * system state.
    75    */
    76 
    77 /*
    78   if ( !_System_state_Is_up( _System_state_Get() ) )
    79     return true;
    80 */
    81 
    82   /* FIXME: Reason for this? */
    83   if (source < 0)
    84     source = (int) the_heap->stats.instance;
    85 
    86   if (do_dump)
    87     printk("\nPASS: %d start %p final %p first %p last %p begin %p end %p\n",
    88       source, the_block, end,
    89       _Heap_First_free_block(the_heap), _Heap_Last_free_block(the_heap),
    90       the_heap->begin, the_heap->end);
    91 
    92   /*
    93    * Handle the 1st block
    94    */
    95 
    96   if (!_Heap_Is_prev_used(the_block)) {
    97     printk("PASS: %d !HEAP_PREV_BLOCK_USED flag of 1st block isn't set\n", source);
    98     error = 1;
    99   }
    100 
    101   if (the_block->prev_size != the_heap->page_size) {
    102     printk("PASS: %d !prev_size of 1st block isn't page_size\n", source);
    103     error = 1;
    104   }
    105 
    106   while ( the_block != end ) {
    107     uint32_t const the_size = _Heap_Block_size(the_block);
    108     Heap_Block *const next_block = _Heap_Block_at(the_block, the_size);
    109     bool    prev_used = _Heap_Is_prev_used(the_block);
    110 
    111     if (do_dump) {
    112       printk("PASS: %d block %p size %d(%c)",
    113         source, the_block, the_size, (prev_used ? 'U' : 'F'));
    114       if (prev_used)
    115         printk(" prev_size %d", the_block->prev_size);
    116       else
    117         printk(" (prev_size) %d", the_block->prev_size);
    118     }
    119 
    120 
    121     if (!_Addresses_Is_aligned(next_block) ) {
    122       printk("PASS: %d next_block %p is not aligned\n", source, next_block);
    123       error = 1;
    124       break;
    125     }
    126    
    127     if (!_Heap_Is_prev_used(next_block)) {
    128       if (do_dump)
    129         printk( " prev %p next %p", the_block->prev, the_block->next);
    130       if (_Heap_Block_size(the_block) != next_block->prev_size) {
    131         if (do_dump) printk("\n");
    132         printk("PASS: %d !front and back sizes don't match", source);
    133         error = 1;
    134       }
    135       if (!prev_used) {
    136        
    137         hw_nl(do_dump, error);
    138         printk("PASS: %d !two consecutive blocks are free", source);
    139         error = 1;
    140       }
    141 
    142       { /* Check if 'the_block' is in the free block list */
    143         Heap_Block* block = _Heap_First_free_block(the_heap);
    144         if (!_Addresses_Is_aligned(block) ) {
    145           printk(
    146             "PASS: %d first free block %p is not aligned\n", source, block);
    147           error = 1;
    148           break;
    149         }
    150         while(block != the_block && block != tail) {
    151           if (!_Addresses_Is_aligned(block) ) {
    152             printk(
    153               "PASS: %d a free block %p is not aligned\n", source, block);
    154             error = 1;
    155             break;
    156           }
    157           if (!_Heap_Is_block_in_heap(the_heap, block)) {
    158             printk("PASS: %d a free block %p is not in heap\n", source, block);
    159             error = 1;
    160             break;
    161           }
    162           block = block->next;
    163         }
    164         if (block != the_block) {
    165           hw_nl(do_dump, error);
    166           printk("PASS: %d !the_block not in the free list", source);
    167           error = 1;
    168         }
    169       }
    170 
    171     }
    172     hw_nl(do_dump, error);
    173 
    174     if (the_size < the_heap->min_block_size) {
    175       printk("PASS: %d !block size is too small\n", source);
    176       error = 1;
    177       break;
    178     }
    179     if (!_Heap_Is_aligned( the_size, the_heap->page_size)) {
    180       printk("PASS: %d !block size is misaligned\n", source);
    181       error = 1;
    182     }
    183 
    184     if (++passes > (do_dump ? 10 : 0) && error)
    185       break;
    186 
    187     the_block = next_block;
    188   }
    189 
    190   if (the_block != end) {
    191     printk("PASS: %d !last block address isn't equal to 'final' %p %p\n",
    192       source, the_block, end);
    193     error = 1;
    194   }
    195 
    196   if (_Heap_Block_size(the_block) != the_heap->page_size) {
    197     printk("PASS: %d !last block's size isn't page_size (%d != %d)\n", source,
    198            _Heap_Block_size(the_block), the_heap->page_size);
    199     error = 1;
    200   }
    201 
    202   if (do_dump && error)
    203     _Internal_error_Occurred( INTERNAL_ERROR_CORE, true, 0xffff0000 );
    204 
    205   return error;
    206 
     54  const Heap_Block *const free_list_tail = _Heap_Free_list_tail( heap );
     55  const Heap_Block *const first_free_block = _Heap_Free_list_first( heap );
     56  const Heap_Block *free_block = first_free_block;
     57  uintptr_t const page_size = heap->page_size;
     58  uintptr_t const loop_limit =
     59    ((uintptr_t) heap->last_block - (uintptr_t) heap->first_block)
     60      / heap->min_block_size;
     61  uintptr_t loop_counter = 0;
     62
     63  while ( free_block != free_list_tail && loop_counter < loop_limit ) {
     64    if ( !_Heap_Is_block_in_heap( heap, free_block ) ) {
     65      _Heap_Walk_printk(
     66        source,
     67        dump,
     68        true,
     69        "free block 0x%08x: not in heap\n",
     70        free_block
     71      );
     72
     73      return false;
     74    }
     75
     76    if (
     77      !_Heap_Is_aligned( _Heap_Alloc_area_of_block( free_block ), page_size )
     78    ) {
     79      _Heap_Walk_printk(
     80        source,
     81        dump,
     82        true,
     83        "free block 0x%08x: alloc area not page aligned\n",
     84        free_block
     85      );
     86
     87      return false;
     88    }
     89
     90    ++loop_counter;
     91
     92    free_block = free_block->next;
     93  }
     94
     95  if ( loop_counter >= loop_limit ) {
     96    _Heap_Walk_printk(
     97      source,
     98      dump,
     99      true,
     100      "free list contains a loop\n"
     101    );
     102
     103    return false;
     104  }
     105
     106  return true;
    207107}
    208108
    209 /*
    210  *  This method exists to simplify branch paths in the generated code above.
    211  */
    212 static void hw_nl(
    213   int            error,
    214   bool           do_dump
     109static bool _Heap_Walk_is_in_free_list(
     110  Heap_Control *heap,
     111  Heap_Block *block
    215112)
    216113{
    217   if (do_dump || error) printk("\n");
     114  const Heap_Block *const free_list_tail = _Heap_Free_list_tail( heap );
     115  const Heap_Block *free_block = _Heap_Free_list_first( heap );
     116
     117  while ( free_block != free_list_tail ) {
     118    if ( free_block == block ) {
     119      return true;
     120    }
     121    free_block = free_block->next;
     122  }
     123
     124  return false;
    218125}
     126
     127static bool _Heap_Walk_check_control(
     128  int source,
     129  bool dump,
     130  Heap_Control *heap
     131)
     132{
     133  uintptr_t const page_size = heap->page_size;
     134  uintptr_t const min_block_size = heap->min_block_size;
     135  Heap_Block *const free_list_tail = _Heap_Free_list_tail( heap );
     136  Heap_Block *const free_list_head = _Heap_Free_list_head( heap );
     137  Heap_Block *const first_free_block = _Heap_Free_list_first( heap );
     138  Heap_Block *const last_free_block = _Heap_Free_list_last( heap );
     139  Heap_Block *const first_block = heap->first_block;
     140  Heap_Block *const last_block = heap->last_block;
     141
     142  _Heap_Walk_printk(
     143    source,
     144    dump,
     145    false,
     146    "page size %u, min block size %u\n"
     147      "\tarea begin 0x%08x, area end 0x%08x\n"
     148      "\tfirst block 0x%08x, last block 0x%08x\n"
     149      "\tfirst free 0x%08x, last free 0x%08x\n",
     150    page_size, min_block_size,
     151    heap->area_begin, heap->area_end,
     152    first_block, last_block,
     153    first_free_block, last_free_block
     154  );
     155
     156  if ( page_size == 0 ) {
     157    _Heap_Walk_printk( source, dump, true, "page size is zero\n" );
     158
     159    return false;
     160  }
     161
     162  if ( !_Addresses_Is_aligned( (void *) page_size ) ) {
     163    _Heap_Walk_printk(
     164      source,
     165      dump,
     166      true,
     167      "page size %u not CPU aligned\n",
     168      page_size
     169    );
     170
     171    return false;
     172  }
     173
     174  if ( !_Heap_Is_aligned( min_block_size, page_size ) ) {
     175    _Heap_Walk_printk(
     176      source,
     177      dump,
     178      true,
     179      "min block size %u not page aligned\n",
     180      min_block_size
     181    );
     182
     183    return false;
     184  }
     185
     186  if (
     187    first_free_block != free_list_head
     188      && !_Addresses_Is_aligned( first_free_block )
     189  ) {
     190    _Heap_Walk_printk(
     191      source,
     192      dump,
     193      true,
     194      "first free block: 0x%08x not CPU aligned\n",
     195      first_free_block
     196    );
     197
     198    return false;
     199  }
     200
     201  if (
     202    last_free_block != free_list_tail
     203      && !_Addresses_Is_aligned( last_free_block )
     204  ) {
     205    _Heap_Walk_printk(
     206      source,
     207      dump,
     208      true,
     209      "last free block: 0x%08x not CPU aligned\n",
     210      last_free_block
     211    );
     212   
     213    return false;
     214  }
     215
     216  if (
     217    !_Heap_Is_aligned( _Heap_Alloc_area_of_block( first_block ), page_size )
     218  ) {
     219    _Heap_Walk_printk(
     220      source,
     221      dump,
     222      true,
     223      "first block: 0x%08x not page aligned\n",
     224      first_block
     225    );
     226
     227    return false;
     228  }
     229
     230  if (
     231    !_Heap_Is_aligned( _Heap_Alloc_area_of_block( last_block ), page_size )
     232  ) {
     233    _Heap_Walk_printk(
     234      source,
     235      dump,
     236      true,
     237      "last block: 0x%08x not page aligned\n",
     238      last_block
     239    );
     240
     241    return false;
     242  }
     243
     244  if ( !_Heap_Is_prev_used( first_block ) ) {
     245    _Heap_Walk_printk(
     246      source,
     247      dump,
     248      true,
     249      "first block: HEAP_PREV_BLOCK_USED is cleared\n"
     250    );
     251  }
     252
     253  if ( first_block->prev_size != page_size ) {
     254    _Heap_Walk_printk(
     255      source,
     256      dump,
     257      true,
     258      "first block: prev size %u != page size %u\n",
     259      first_block->prev_size,
     260      page_size
     261    );
     262  }
     263
     264  return _Heap_Walk_check_free_list( source, dump, heap );
     265}
     266
     267bool _Heap_Walk(
     268  Heap_Control *heap,
     269  int source,
     270  bool dump
     271)
     272{
     273  uintptr_t const page_size = heap->page_size;
     274  uintptr_t const min_block_size = heap->min_block_size;
     275  Heap_Block *const free_list_tail = _Heap_Free_list_tail( heap );
     276  Heap_Block *const free_list_head = _Heap_Free_list_head( heap );
     277  Heap_Block *const first_free_block = _Heap_Free_list_first( heap );
     278  Heap_Block *const last_free_block = _Heap_Free_list_last( heap );
     279  Heap_Block *const last_block = heap->last_block;
     280  Heap_Block *block = heap->first_block;
     281  bool error = false;
     282
     283  if ( !_System_state_Is_up( _System_state_Get() ) ) {
     284    return true;
     285  }
     286
     287  if ( !_Heap_Walk_check_control( source, dump, heap ) ) {
     288    return false;
     289  }
     290
     291  while ( block != last_block && _Addresses_Is_aligned( block ) ) {
     292    uintptr_t const block_begin = (uintptr_t) block;
     293    uintptr_t const block_size = _Heap_Block_size( block );
     294    bool const prev_used = _Heap_Is_prev_used( block );
     295    Heap_Block *const next_block = _Heap_Block_at( block, block_size );
     296    uintptr_t const next_block_begin = (uintptr_t) next_block;
     297
     298    if ( prev_used ) {
     299      _Heap_Walk_printk(
     300        source,
     301        dump,
     302        error,
     303        "block 0x%08x: size %u\n",
     304        block,
     305        block_size
     306      );
     307    } else {
     308      _Heap_Walk_printk(
     309        source,
     310        dump,
     311        error,
     312        "block 0x%08x: size %u, prev_size %u\n",
     313        block,
     314        block_size,
     315        block->prev_size
     316      );
     317    }
     318
     319    if (
     320      !_Heap_Is_aligned( block_begin + HEAP_BLOCK_HEADER_SIZE, page_size )
     321    ) {
     322      error = true;
     323      _Heap_Walk_printk(
     324        source,
     325        dump,
     326        error,
     327        "block 0x%08x: not page (%u) aligned\n",
     328        block,
     329        page_size
     330      );
     331      break;
     332    }
     333
     334    if ( !_Heap_Is_aligned( block_size, page_size ) ) {
     335      error = true;
     336      _Heap_Walk_printk(
     337        source,
     338        dump,
     339        error,
     340        "block 0x%08x: block size %u not page (%u) aligned\n",
     341        block,
     342        block_size,
     343        page_size
     344      );
     345      break;
     346    }
     347
     348    if ( block_size < min_block_size ) {
     349      error = true;
     350      _Heap_Walk_printk(
     351        source,
     352        dump,
     353        error,
     354        "block 0x%08x: size %u < min block size %u\n",
     355        block,
     356        block_size,
     357        min_block_size
     358      );
     359      break;
     360    }
     361
     362    if ( next_block_begin <= block_begin ) {
     363      error = true;
     364      _Heap_Walk_printk(
     365        source,
     366        dump,
     367        error,
     368        "block 0x%08x: next block 0x%08x is not a successor\n",
     369        block,
     370        next_block
     371      );
     372      break;
     373    }
     374   
     375    if ( !_Heap_Is_prev_used( next_block ) ) {
     376      _Heap_Walk_printk(
     377        source,
     378        dump,
     379        error,
     380        "block 0x%08x: prev 0x%08x%s, next 0x%08x%s\n",
     381        block,
     382        block->prev,
     383        block->prev == first_free_block ?
     384          " (= first)"
     385            : (block->prev == free_list_head ? " (= head)" : ""),
     386        block->next,
     387        block->next == last_free_block ?
     388          " (= last)"
     389            : (block->next == free_list_tail ? " (= tail)" : "")
     390      );
     391
     392      if ( block_size != next_block->prev_size ) {
     393        error = true;
     394        _Heap_Walk_printk(
     395          source,
     396          dump,
     397          error,
     398          "block 0x%08x: size %u != size %u (in next block 0x%08x)\n",
     399          block,
     400          block_size,
     401          next_block->prev_size,
     402          next_block
     403        );
     404      }
     405
     406      if ( !prev_used ) {
     407        error = true;
     408        _Heap_Walk_printk(
     409          source,
     410          dump,
     411          error,
     412          "block 0x%08x: two consecutive blocks are free\n",
     413          block
     414        );
     415      }
     416
     417      if ( !_Heap_Walk_is_in_free_list( heap, block ) ) {
     418        error = true;
     419        _Heap_Walk_printk(
     420          source,
     421          dump,
     422          error,
     423          "block 0x%08x: free block not in free list\n",
     424          block
     425        );
     426      }
     427    }
     428
     429    block = next_block;
     430  }
     431
     432  if ( !_Addresses_Is_aligned( block ) ) {
     433    error = true;
     434    _Heap_Walk_printk(
     435      source,
     436      dump,
     437      error,
     438      "block 0x%08x: not CPU aligned\n",
     439      block
     440    );
     441
     442    return false;
     443  }
     444
     445  if ( block == last_block ) {
     446    uintptr_t const block_size = _Heap_Block_size( block );
     447
     448    if ( block_size != page_size ) {
     449      error = true;
     450      _Heap_Walk_printk(
     451        source,
     452        dump,
     453        error,
     454        "last block 0x%08x: size %u != page size %u\n",
     455        block,
     456        block_size,
     457        page_size
     458      );
     459    }
     460  } else {
     461    error = true;
     462    _Heap_Walk_printk(
     463      source,
     464      dump,
     465      error,
     466      "last block 0x%08x != last block 0x%08x\n",
     467      block,
     468      last_block
     469    );
     470  }
     471
     472  return !error;
     473}
  • cpukit/score/src/pheapallocate.c

    r6685aa09 rdea3eccb  
    11/**
     2 * @file
     3 *
     4 * @ingroup ScoreProtHeap
     5 *
     6 * @brief Protected Heap Handler implementation.
     7 */
     8
     9/*
    210 *  COPYRIGHT (c) 1989-2007.
    311 *  On-Line Applications Research Corporation (OAR).
     
    1927void *_Protected_heap_Allocate(
    2028  Heap_Control *the_heap,
    21   intptr_t      size
     29  uintptr_t     size
    2230)
    2331{
  • cpukit/score/src/pheapallocatealigned.c

    r6685aa09 rdea3eccb  
    11/**
     2 * @file
     3 *
     4 * @ingroup ScoreProtHeap
     5 *
     6 * @brief Protected Heap Handler implementation.
     7 */
     8
     9/*
    210 *  COPYRIGHT (c) 1989-2007.
    311 *  On-Line Applications Research Corporation (OAR).
     
    1927void *_Protected_heap_Allocate_aligned(
    2028  Heap_Control *the_heap,
    21   intptr_t      size,
    22   uint32_t      alignment
     29  uintptr_t     size,
     30  uintptr_t     alignment
    2331)
    2432{
  • cpukit/score/src/pheapextend.c

    r6685aa09 rdea3eccb  
    11/**
     2 * @file
     3 *
     4 * @ingroup ScoreProtHeap
     5 *
     6 * @brief Protected Heap Handler implementation.
     7 */
     8
     9/*
    210 *  COPYRIGHT (c) 1989-2007.
    311 *  On-Line Applications Research Corporation (OAR).
     
    2028  Heap_Control *the_heap,
    2129  void         *starting_address,
    22   intptr_t      size
     30  uintptr_t     size
    2331)
    2432{
    2533  Heap_Extend_status status;
    26   intptr_t           amount_extended;
     34  uintptr_t           amount_extended;
    2735
    2836  _RTEMS_Lock_allocator();
  • cpukit/score/src/pheapfree.c

    r6685aa09 rdea3eccb  
    11/**
     2 * @file
     3 *
     4 * @ingroup ScoreProtHeap
     5 *
     6 * @brief Protected Heap Handler implementation.
     7 */
     8
     9/*
    210 *  COPYRIGHT (c) 1989-2007.
    311 *  On-Line Applications Research Corporation (OAR).
  • cpukit/score/src/pheapgetblocksize.c

    r6685aa09 rdea3eccb  
    11/**
     2 * @file
     3 *
     4 * @ingroup ScoreProtHeap
     5 *
     6 * @brief Protected Heap Handler implementation.
     7 */
     8
     9/*
    210 *  COPYRIGHT (c) 1989-2007.
    311 *  On-Line Applications Research Corporation (OAR).
     
    2028  Heap_Control        *the_heap,
    2129  void                *starting_address,
    22   intptr_t            *size
     30  uintptr_t           *size
    2331)
    2432{
    25   bool    status;
     33  bool status;
    2634
    2735  _RTEMS_Lock_allocator();
  • cpukit/score/src/pheapgetfreeinfo.c

    r6685aa09 rdea3eccb  
    11/**
     2 * @file
     3 *
     4 * @ingroup ScoreProtHeap
     5 *
     6 * @brief Protected Heap Handler implementation.
     7 */
     8
     9/*
    210 *  COPYRIGHT (c) 1989-2007.
    311 *  On-Line Applications Research Corporation (OAR).
  • cpukit/score/src/pheapgetinfo.c

    r6685aa09 rdea3eccb  
    11/**
     2 * @file
     3 *
     4 * @ingroup ScoreProtHeap
     5 *
     6 * @brief Protected Heap Handler implementation.
     7 */
     8
     9/*
    210 *  COPYRIGHT (c) 1989-2007.
    311 *  On-Line Applications Research Corporation (OAR).
     
    2230)
    2331{
    24   Heap_Get_information_status status;
    25 
    2632  if ( !the_heap )
    2733    return false;
     
    3137
    3238  _RTEMS_Lock_allocator();
    33     status = _Heap_Get_information( the_heap, the_info );
     39    _Heap_Get_information( the_heap, the_info );
    3440  _RTEMS_Unlock_allocator();
    3541
    36   if ( status == HEAP_GET_INFORMATION_SUCCESSFUL )
    37     return true;
    38 
    39   return false;
     42  return true;
    4043}
  • cpukit/score/src/pheapgetsize.c

    r6685aa09 rdea3eccb  
    11/**
     2 * @file
     3 *
     4 * @ingroup ScoreProtHeap
     5 *
     6 * @brief Protected Heap Handler implementation.
     7 */
     8
     9/*
    210 *  COPYRIGHT (c) 1989-2009.
    311 *  On-Line Applications Research Corporation (OAR).
     
    1725#include <rtems/score/protectedheap.h>
    1826
    19 uint32_t _Protected_heap_Get_size(
     27uintptr_t _Protected_heap_Get_size(
    2028  Heap_Control *the_heap
    2129)
  • cpukit/score/src/pheapinit.c

    r6685aa09 rdea3eccb  
    11/**
     2 * @file
     3 *
     4 * @ingroup ScoreProtHeap
     5 *
     6 * @brief Protected Heap Handler implementation.
     7 */
     8
     9/*
    210 *  COPYRIGHT (c) 1989-2007.
    311 *  On-Line Applications Research Corporation (OAR).
  • cpukit/score/src/pheapresizeblock.c

    r6685aa09 rdea3eccb  
    11/**
     2 * @file
     3 *
     4 * @ingroup ScoreProtHeap
     5 *
     6 * @brief Protected Heap Handler implementation.
     7 */
     8
     9/*
    210 *  COPYRIGHT (c) 1989-2007.
    311 *  On-Line Applications Research Corporation (OAR).
     
    2028  Heap_Control *the_heap,
    2129  void         *starting_address,
    22   intptr_t      size
     30  uintptr_t     size
    2331)
    2432{
    2533  Heap_Resize_status status;
    26   intptr_t           old_mem_size;
    27   intptr_t           avail_mem_size;
     34  uintptr_t          old_mem_size;
     35  uintptr_t          avail_mem_size;
    2836
    2937  _RTEMS_Lock_allocator();
  • cpukit/score/src/pheapwalk.c

    r6685aa09 rdea3eccb  
    11/**
     2 * @file
     3 *
     4 * @ingroup ScoreProtHeap
     5 *
     6 * @brief Protected Heap Handler implementation.
     7 */
     8
     9/*
    210 *  COPYRIGHT (c) 1989-2007.
    311 *  On-Line Applications Research Corporation (OAR).
Note: See TracChangeset for help on using the changeset viewer.