18 #ifndef _RTEMS_SCORE_HEAPIMPL_H 19 #define _RTEMS_SCORE_HEAPIMPL_H 35 #define HEAP_PREV_BLOCK_USED ((uintptr_t) 1) 41 #define HEAP_ALLOC_BONUS sizeof(uintptr_t) 47 HEAP_RESIZE_SUCCESSFUL,
48 HEAP_RESIZE_UNSATISFIED,
49 HEAP_RESIZE_FATAL_ERROR
67 uintptr_t heap_area_begin,
68 uintptr_t heap_area_size,
70 uintptr_t min_block_size,
174 uintptr_t block_size,
202 const uintptr_t *block_sizes,
217 uintptr_t *allocatable_size
305 uintptr_t alloc_begin,
309 #ifndef HEAP_PROTECTION 310 #define _Heap_Protection_block_initialize( heap, block ) ((void) 0) 311 #define _Heap_Protection_block_check( heap, block ) ((void) 0) 312 #define _Heap_Protection_block_error( heap, block ) ((void) 0) 313 #define _Heap_Protection_free_all_delayed_blocks( heap ) ((void) 0) 315 static inline void _Heap_Protection_block_initialize(
320 (*heap->Protection.block_initialize)( heap, block );
323 static inline void _Heap_Protection_block_check(
328 (*heap->Protection.block_check)( heap, block );
331 static inline void _Heap_Protection_block_error(
336 (*heap->Protection.block_error)( heap, block );
339 static inline void _Heap_Protection_free_all_delayed_blocks(
Heap_Control *heap )
365 #ifdef HEAP_PROTECTION 366 heap->Protection.delayed_free_fraction = fraction;
375 return &heap->free_list;
380 return &heap->free_list;
385 return _Heap_Free_list_head(heap)->
next;
390 return _Heap_Free_list_tail(heap)->
prev;
410 new_block->
next = next;
411 new_block->
prev = prev;
413 next->
prev = new_block;
414 prev->
next = new_block;
424 new_block->
next = next;
425 new_block->
prev = block_before;
426 block_before->
next = new_block;
427 next->
prev = new_block;
437 new_block->
next = block_next;
438 new_block->
prev = prev;
439 prev->
next = new_block;
440 block_next->
prev = new_block;
448 return (value % alignment) == 0;
456 return value - (value % alignment);
467 return (
Heap_Block *) ((uintptr_t) block + offset);
485 uintptr_t alloc_begin,
489 return (
Heap_Block *) (_Heap_Align_down( alloc_begin, page_size )
520 return _Heap_Is_prev_used( next_block );
527 return !_Heap_Is_used( block );
535 return (uintptr_t) block >= (uintptr_t) heap->first_block
536 && (uintptr_t) block <= (uintptr_t) heap->last_block;
552 _Heap_Block_set_size(
554 (uintptr_t) heap->first_block - (uintptr_t) heap->last_block
565 return heap->stats.
size;
570 return a > b ? a : b;
575 return a < b ? a : b;
579 #define RTEMS_HEAP_DEBUG 582 #ifdef RTEMS_HEAP_DEBUG 584 #define _HAssert( cond ) \ 587 __assert( __FILE__, __LINE__, #cond ); \ 591 #define _HAssert( cond ) ((void) 0) bool _Heap_Walk(Heap_Control *heap, int source, bool dump)
Walks the heap heap to verify its integrity.
Definition: heapwalk.c:312
uintptr_t size_and_flag
Contains the size of the current block and a flag which indicates if the previous block is free or us...
Definition: heap.h:226
void _Heap_Iterate(Heap_Control *heap, Heap_Block_visitor visitor, void *visitor_arg)
Iterates over all blocks of the heap.
Definition: heapiterate.c:29
Heap_Block * _Heap_Greedy_allocate_all_except_largest(Heap_Control *heap, uintptr_t *allocatable_size)
Greedy allocate all blocks except the largest free block.
Definition: heapgreedy.c:78
void * _Heap_Allocate_aligned_with_boundary(Heap_Control *heap, uintptr_t size, uintptr_t alignment, uintptr_t boundary)
Allocates a memory area of size size bytes from the heap heap.
Definition: heapallocate.c:188
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
RTEMS_INLINE_ROUTINE void _Heap_Set_last_block_size(Heap_Control *heap)
Sets the size of the last block for heap heap.
Definition: heapimpl.h:550
uintptr_t _Heap_Initialize(Heap_Control *heap, void *area_begin, uintptr_t area_size, uintptr_t page_size)
Initializes the heap control block heap to manage the area starting at area_begin of size area_size b...
Definition: heap.c:201
void _Heap_Get_information(Heap_Control *heap, Heap_Information_block *info)
Returns information about used and free blocks for the heap heap in info.
Definition: heapgetinfo.c:45
unsigned p
Definition: tte.h:90
Heap_Resize_status _Heap_Resize_block(Heap_Control *heap, void *addr, uintptr_t size, uintptr_t *old_size, uintptr_t *new_size)
Resizes the block of the allocated memory area starting at addr.
Definition: heapresizeblock.c:86
void _Heap_Greedy_free(Heap_Control *heap, Heap_Block *blocks)
Frees blocks of a greedy allocation.
Definition: heapgreedy.c:96
Description for free or used blocks.
Definition: heap.h:193
RTEMS_INLINE_ROUTINE void * _Heap_Allocate(Heap_Control *heap, uintptr_t size)
See _Heap_Allocate_aligned_with_boundary() with alignment and boundary equals zero.
Definition: heapimpl.h:135
RTEMS_INLINE_ROUTINE void * _Heap_Allocate_aligned(Heap_Control *heap, uintptr_t size, uintptr_t alignment)
See _Heap_Allocate_aligned_with_boundary() with boundary equals zero.
Definition: heapimpl.h:122
Heap_Resize_status
See _Heap_Resize_block().
Definition: heapimpl.h:46
#define HEAP_PREV_BLOCK_USED
See also Heap_Block::size_and_flag.
Definition: heapimpl.h:35
#define HEAP_BLOCK_HEADER_SIZE
The block header consists of the two size fields (Heap_Block::prev_size and Heap_Block::size_and_flag...
Definition: heap.h:187
bool _Heap_Get_first_and_last_block(uintptr_t heap_area_begin, uintptr_t heap_area_size, uintptr_t page_size, uintptr_t min_block_size, Heap_Block **first_block_ptr, Heap_Block **last_block_ptr)
Gets the first and last block for the heap area with begin heap_area_begin and size heap_area_size...
Definition: heap.c:164
void _Heap_Get_free_information(Heap_Control *heap, Heap_Information *info)
Returns information about free blocks for the heap heap in info.
Definition: heapgetfreeinfo.c:24
RTEMS_INLINE_ROUTINE uintptr_t _Heap_Get_size(const Heap_Control *heap)
Returns the size of the allocatable area in bytes.
Definition: heapimpl.h:563
Heap_Block * _Heap_Block_allocate(Heap_Control *heap, Heap_Block *block, uintptr_t alloc_begin, uintptr_t alloc_size)
Allocates the memory area starting at alloc_begin of size alloc_size bytes in the block block...
Definition: heap.c:429
Control block used to manage a heap.
Definition: heap.h:255
#define HEAP_ALLOC_BONUS
Size of the part at the block begin which may be used for allocation in charge of the previous block...
Definition: heapimpl.h:41
uintptr_t size
Size of the allocatable area in bytes.
Definition: heapinfo.h:60
Heap_Block * next
Pointer to the next free block or part of the allocated area.
Definition: heap.h:241
Heap_Block * _Heap_Greedy_allocate(Heap_Control *heap, const uintptr_t *block_sizes, size_t block_count)
Greedy allocate that empties the heap.
Definition: heapgreedy.c:29
uintptr_t prev_size
Size of the previous block or part of the allocated area of the previous block.
Definition: heap.h:207
bool(* Heap_Block_visitor)(const Heap_Block *block, uintptr_t block_size, bool block_is_used, void *visitor_arg)
Heap block visitor.
Definition: heapimpl.h:172
RTEMS_INLINE_ROUTINE Heap_Block * _Heap_Block_at(const Heap_Block *block, uintptr_t offset)
Returns the block which is offset away from block.
Definition: heapimpl.h:462
unsigned size
Definition: tte.h:74
Heap_Block * prev
Pointer to the previous free block or part of the allocated area.
Definition: heap.h:249
bool _Heap_Free(Heap_Control *heap, void *addr)
Frees the allocated memory area starting at addr in the heap heap.
Definition: heapfree.c:99
RTEMS_INLINE_ROUTINE void _Heap_Protection_set_delayed_free_fraction(Heap_Control *heap, uintptr_t fraction)
Sets the fraction of delayed free blocks that is actually freed during memory shortage.
Definition: heapimpl.h:360
bool _Heap_Size_of_alloc_area(Heap_Control *heap, void *addr, uintptr_t *size)
Returns the size of the allocatable memory area starting at addr in size.
Definition: heapsizeofuserarea.c:24