18 #ifndef _RTEMS_SCORE_HEAPIMPL_H 19 #define _RTEMS_SCORE_HEAPIMPL_H 36 #define HEAP_PREV_BLOCK_USED ((uintptr_t) 1) 42 #define HEAP_ALLOC_BONUS sizeof(uintptr_t) 48 HEAP_RESIZE_SUCCESSFUL,
49 HEAP_RESIZE_UNSATISFIED,
50 HEAP_RESIZE_FATAL_ERROR
69 uintptr_t heap_area_begin,
70 uintptr_t heap_area_size,
72 uintptr_t min_block_size,
206 uintptr_t block_size,
243 const uintptr_t *block_sizes,
263 uintptr_t *allocatable_size
375 uintptr_t alloc_begin,
379 #ifndef HEAP_PROTECTION 380 #define _Heap_Protection_block_initialize( heap, block ) ((void) 0) 381 #define _Heap_Protection_block_check( heap, block ) ((void) 0) 382 #define _Heap_Protection_block_error( heap, block, reason ) ((void) 0) 383 #define _Heap_Protection_free_all_delayed_blocks( heap ) ((void) 0) 385 static inline void _Heap_Protection_block_initialize(
390 (*heap->Protection.block_initialize)( heap, block );
393 static inline void _Heap_Protection_block_check(
398 (*heap->Protection.block_check)( heap, block );
401 static inline void _Heap_Protection_block_error(
407 (*heap->Protection.block_error)( heap, block, reason );
410 static inline void _Heap_Protection_free_all_delayed_blocks(
Heap_Control *heap )
436 #ifdef HEAP_PROTECTION 437 heap->Protection.delayed_free_fraction = fraction;
453 return &heap->free_list;
465 return &heap->free_list;
520 new_block->
next = next;
521 new_block->
prev = prev;
523 next->
prev = new_block;
524 prev->
next = new_block;
540 new_block->
next = next;
541 new_block->
prev = block_before;
542 block_before->
next = new_block;
543 next->
prev = new_block;
559 new_block->
next = block_next;
560 new_block->
prev = prev;
561 prev->
next = new_block;
562 block_next->
prev = new_block;
579 return (value % alignment) == 0;
595 return value - (value % alignment);
611 return (
Heap_Block *) ((uintptr_t) block + offset);
651 uintptr_t alloc_begin,
748 return (uintptr_t) block >= (uintptr_t) heap->first_block
749 && (uintptr_t) block <= (uintptr_t) heap->last_block;
769 (uintptr_t) heap->first_block - (uintptr_t) heap->last_block
784 return heap->stats.
size;
798 return a > b ? a : b;
812 return a < b ? a : b;
816 #define RTEMS_HEAP_DEBUG 819 #ifdef RTEMS_HEAP_DEBUG 821 #define _HAssert( cond ) \ 824 __assert( __FILE__, __LINE__, #cond ); \ 828 #define _HAssert( cond ) ((void) 0) RTEMS_INLINE_ROUTINE uintptr_t _Heap_Alloc_area_of_block(const Heap_Block *block)
Returns the first address in the block without the heap header.
RTEMS_INLINE_ROUTINE Heap_Block * _Heap_Free_list_first(Heap_Control *heap)
Returns the first block of the free list of the heap.
RTEMS_INLINE_ROUTINE uintptr_t _Heap_Max(uintptr_t a, uintptr_t b)
Returns the bigger one of the two arguments.
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...
Heap_Block * _Heap_Greedy_allocate_all_except_largest(Heap_Control *heap, uintptr_t *allocatable_size)
Greedily allocates all blocks except the largest free block.
RTEMS_INLINE_ROUTINE Heap_Block * _Heap_Prev_block(const Heap_Block *block)
Returns the address of the previous block.
RTEMS_INLINE_ROUTINE Heap_Block * _Heap_Block_at(const Heap_Block *block, uintptr_t offset)
Returns the block which is offset away from block.
Heap_Resize_status
See _Heap_Resize_block().
bool _Heap_Free(Heap_Control *heap, void *addr)
Frees the allocated memory area.
RTEMS_INLINE_ROUTINE void * _Heap_Allocate_aligned(Heap_Control *heap, uintptr_t size, uintptr_t alignment)
Allocates an aligned memory area.
RTEMS_INLINE_ROUTINE Heap_Block * _Heap_Block_of_alloc_area(uintptr_t alloc_begin, uintptr_t page_size)
Returns the starting address of the block corresponding to the allocatable area.
RTEMS_INLINE_ROUTINE bool _Heap_Is_free(const Heap_Block *block)
Returns if the heap block is free.
void _Heap_Iterate(Heap_Control *heap, Heap_Block_visitor visitor, void *visitor_arg)
Iterates over all blocks of the heap.
RTEMS_INLINE_ROUTINE void * _Heap_Allocate(Heap_Control *heap, uintptr_t size)
Allocates a memory area.
RTEMS_INLINE_ROUTINE void _Heap_Free_list_remove(Heap_Block *block)
Removes the block from the free list.
RTEMS_INLINE_ROUTINE bool _Heap_Is_block_in_heap(const Heap_Control *heap, const Heap_Block *block)
Returns if the block is part of the heap.
RTEMS_INLINE_ROUTINE Heap_Block * _Heap_Free_list_tail(Heap_Control *heap)
Returns the tail of the free list of the heap.
RTEMS_INLINE_ROUTINE void _Heap_Block_set_size(Heap_Block *block, uintptr_t size)
Sets the block size.
Heap_Block * _Heap_Greedy_allocate(Heap_Control *heap, const uintptr_t *block_sizes, size_t block_count)
Greedily allocates and empties the heap.
void _Heap_Get_information(Heap_Control *heap, Heap_Information_block *info)
Returns information about used and free blocks for the heap.
RTEMS_INLINE_ROUTINE uintptr_t _Heap_Get_size(const Heap_Control *heap)
Returns the size of the allocatable area in bytes.
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.
Information for the Assert Handler.
Description for free or used blocks.
RTEMS_INLINE_ROUTINE bool _Heap_Is_prev_used(const Heap_Block *block)
Returns if the previous heap block is used.
void _Heap_Greedy_free(Heap_Control *heap, Heap_Block *blocks)
Frees blocks of a greedy allocation.
RTEMS_INLINE_ROUTINE Heap_Block * _Heap_Free_list_head(Heap_Control *heap)
Returns the head of the free list of the heap.
RTEMS_INLINE_ROUTINE Heap_Block * _Heap_Free_list_last(Heap_Control *heap)
Returns the last block of the free list of the heap.
RTEMS_INLINE_ROUTINE bool _Heap_Is_aligned(uintptr_t value, uintptr_t alignment)
Checks if the value is aligned to the given alignment.
Control block used to manage a heap.
RTEMS_INLINE_ROUTINE uintptr_t _Heap_Align_down(uintptr_t value, uintptr_t alignment)
Returns the aligned value, truncating.
uintptr_t _Heap_Initialize(Heap_Control *heap, void *area_begin, uintptr_t area_size, uintptr_t page_size)
Initializes the heap control block.
RTEMS_INLINE_ROUTINE void _Heap_Free_list_replace(Heap_Block *old_block, Heap_Block *new_block)
Replaces one block in the free list by another.
uintptr_t size
Size of the allocatable area in bytes.
Heap_Error_reason
The heap error reason.
Heap_Block * next
Pointer to the next free block or part of the allocated area.
#define HEAP_ALLOC_BONUS
Size of the part at the block begin which may be used for allocation in charge of the previous block...
uintptr_t prev_size
Size of the previous block or part of the allocated area of the previous block.
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.
RTEMS_INLINE_ROUTINE void _Heap_Free_list_insert_before(Heap_Block *block_next, Heap_Block *new_block)
Inserts a block before an existing block in the free list.
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...
RTEMS_INLINE_ROUTINE void _Heap_Free_list_insert_after(Heap_Block *block_before, Heap_Block *new_block)
Inserts a block after an existing block in the free list.
bool(* Heap_Block_visitor)(const Heap_Block *block, uintptr_t block_size, bool block_is_used, void *visitor_arg)
Heap block visitor.
#define RTEMS_INLINE_ROUTINE
Gives a hint to the compiler in a function declaration to inline this function.
void _Heap_Get_free_information(Heap_Control *heap, Heap_Information *info)
Returns information about free blocks for the heap.
Heap_Block * prev
Pointer to the previous free block or part of the allocated area.
#define HEAP_PREV_BLOCK_USED
See also Heap_Block::size_and_flag.
bool _Heap_Size_of_alloc_area(Heap_Control *heap, void *addr, uintptr_t *size)
Returns the size of the allocatable memory area.
#define HEAP_BLOCK_HEADER_SIZE
The block header consists of the two size fields (Heap_Block::prev_size and Heap_Block::size_and_flag...
void * _Heap_Allocate_aligned_with_boundary(Heap_Control *heap, uintptr_t size, uintptr_t alignment, uintptr_t boundary)
Allocates an aligned memory area with boundary constraint.
RTEMS_INLINE_ROUTINE uintptr_t _Heap_Min(uintptr_t a, uintptr_t b)
Returns the smaller one of the two arguments.
RTEMS_INLINE_ROUTINE void _Heap_Set_last_block_size(Heap_Control *heap)
Sets the size of the last block for the heap.
RTEMS_INLINE_ROUTINE bool _Heap_Is_used(const Heap_Block *block)
Returns if the heap block is used.
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.
RTEMS_INLINE_ROUTINE uintptr_t _Heap_Block_size(const Heap_Block *block)
Returns the block size.
bool _Heap_Walk(Heap_Control *heap, int source, bool dump)
Verifies the integrity of the heap.