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);
625 return (
Heap_Block *) ((uintptr_t) block - block->prev_size);
651 uintptr_t alloc_begin,
684 block->size_and_flag =
size | flag;
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.
Definition: heapimpl.h:635
RTEMS_INLINE_ROUTINE Heap_Block * _Heap_Free_list_first(Heap_Control *heap)
Returns the first block of the free list of the heap.
Definition: heapimpl.h:475
RTEMS_INLINE_ROUTINE uintptr_t _Heap_Max(uintptr_t a, uintptr_t b)
Returns the bigger one of the two arguments.
Definition: heapimpl.h:796
Heap_Block * _Heap_Greedy_allocate_all_except_largest(Heap_Control *heap, uintptr_t *allocatable_size)
Greedily allocates all blocks except the largest free block.
Definition: heapgreedy.c:78
RTEMS_INLINE_ROUTINE Heap_Block * _Heap_Prev_block(const Heap_Block *block)
Returns the address of the previous block.
Definition: heapimpl.h:621
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:606
Heap_Resize_status
See _Heap_Resize_block().
Definition: heapimpl.h:47
bool _Heap_Free(Heap_Control *heap, void *addr)
Frees the allocated memory area.
Definition: heapfree.c:99
RTEMS_INLINE_ROUTINE void * _Heap_Allocate_aligned(Heap_Control *heap, uintptr_t size, uintptr_t alignment)
Allocates an aligned memory area.
Definition: heapimpl.h:139
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.
Definition: heapimpl.h:650
RTEMS_INLINE_ROUTINE bool _Heap_Is_free(const Heap_Block *block)
Returns if the heap block is free.
Definition: heapimpl.h:727
void _Heap_Iterate(Heap_Control *heap, Heap_Block_visitor visitor, void *visitor_arg)
Iterates over all blocks of the heap.
Definition: heapiterate.c:29
RTEMS_INLINE_ROUTINE void * _Heap_Allocate(Heap_Control *heap, uintptr_t size)
Allocates a memory area.
Definition: heapimpl.h:160
RTEMS_INLINE_ROUTINE void _Heap_Free_list_remove(Heap_Block *block)
Removes the block from the free list.
Definition: heapimpl.h:497
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.
Definition: heapimpl.h:743
unsigned p
Definition: tte.h:90
RTEMS_INLINE_ROUTINE Heap_Block * _Heap_Free_list_tail(Heap_Control *heap)
Returns the tail of the free list of the heap.
Definition: heapimpl.h:463
RTEMS_INLINE_ROUTINE void _Heap_Block_set_size(Heap_Block *block, uintptr_t size)
Sets the block size.
Definition: heapimpl.h:677
Heap_Block * _Heap_Greedy_allocate(Heap_Control *heap, const uintptr_t *block_sizes, size_t block_count)
Greedily allocates and empties the heap.
Definition: heapgreedy.c:29
void _Heap_Get_information(Heap_Control *heap, Heap_Information_block *info)
Returns information about used and free blocks for the heap.
Definition: heapgetinfo.c:45
RTEMS_INLINE_ROUTINE uintptr_t _Heap_Get_size(const Heap_Control *heap)
Returns the size of the allocatable area in bytes.
Definition: heapimpl.h:782
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:431
Information for the Assert Handler.
Description for free or used blocks.
Definition: heap.h:256
RTEMS_INLINE_ROUTINE bool _Heap_Is_prev_used(const Heap_Block *block)
Returns if the previous heap block is used.
Definition: heapimpl.h:696
void _Heap_Greedy_free(Heap_Control *heap, Heap_Block *blocks)
Frees blocks of a greedy allocation.
Definition: heapgreedy.c:96
RTEMS_INLINE_ROUTINE Heap_Block * _Heap_Free_list_head(Heap_Control *heap)
Returns the head of the free list of the heap.
Definition: heapimpl.h:451
RTEMS_INLINE_ROUTINE Heap_Block * _Heap_Free_list_last(Heap_Control *heap)
Returns the last block of the free list of the heap.
Definition: heapimpl.h:487
RTEMS_INLINE_ROUTINE bool _Heap_Is_aligned(uintptr_t value, uintptr_t alignment)
Checks if the value is aligned to the given alignment.
Definition: heapimpl.h:574
Control block used to manage a heap.
Definition: heap.h:318
RTEMS_INLINE_ROUTINE uintptr_t _Heap_Align_down(uintptr_t value, uintptr_t alignment)
Returns the aligned value, truncating.
Definition: heapimpl.h:590
uintptr_t _Heap_Initialize(Heap_Control *heap, void *area_begin, uintptr_t area_size, uintptr_t page_size)
Initializes the heap control block.
Definition: heap.c:207
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.
Definition: heapimpl.h:512
uintptr_t size
Size of the allocatable area in bytes.
Definition: heapinfo.h:60
Heap_Error_reason
The heap error reason.
Definition: heap.h:142
Heap_Block * next
Pointer to the next free block or part of the allocated area.
Definition: heap.h:304
#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:42
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.
Definition: heapresizeblock.c:86
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.
Definition: heapimpl.h:552
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:431
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.
Definition: heapimpl.h:533
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:204
unsigned size
Definition: tte.h:74
void _Heap_Get_free_information(Heap_Control *heap, Heap_Information *info)
Returns information about free blocks for the heap.
Definition: heapgetfreeinfo.c:24
Heap_Block * prev
Pointer to the previous free block or part of the allocated area.
Definition: heap.h:312
#define HEAP_PREV_BLOCK_USED
See also Heap_Block::size_and_flag.
Definition: heapimpl.h:36
bool _Heap_Size_of_alloc_area(Heap_Control *heap, void *addr, uintptr_t *size)
Returns the size of the allocatable memory area.
Definition: heapsizeofuserarea.c:24
#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:250
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:66
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.
Definition: heapallocate.c:192
RTEMS_INLINE_ROUTINE uintptr_t _Heap_Min(uintptr_t a, uintptr_t b)
Returns the smaller one of the two arguments.
Definition: heapimpl.h:810
RTEMS_INLINE_ROUTINE void _Heap_Set_last_block_size(Heap_Control *heap)
Sets the size of the last block for the heap.
Definition: heapimpl.h:765
RTEMS_INLINE_ROUTINE bool _Heap_Is_used(const Heap_Block *block)
Returns if the heap block is used.
Definition: heapimpl.h:709
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.
Definition: heap.c:170
RTEMS_INLINE_ROUTINE uintptr_t _Heap_Block_size(const Heap_Block *block)
Returns the block size.
Definition: heapimpl.h:666
bool _Heap_Walk(Heap_Control *heap, int source, bool dump)
Verifies the integrity of the heap.
Definition: heapwalk.c:312