38#ifndef _RTEMS_SCORE_HEAPIMPL_H
39#define _RTEMS_SCORE_HEAPIMPL_H
56#define HEAP_PREV_BLOCK_USED ((uintptr_t) 1)
62#define HEAP_ALLOC_BONUS sizeof(uintptr_t)
68 HEAP_RESIZE_SUCCESSFUL,
69 HEAP_RESIZE_UNSATISFIED,
70 HEAP_RESIZE_FATAL_ERROR
89 uintptr_t heap_area_begin,
90 uintptr_t heap_area_size,
92 uintptr_t min_block_size,
159static inline void *_Heap_Allocate_aligned(
180static inline void *_Heap_Allocate(
Heap_Control *heap, uintptr_t size )
226 uintptr_t block_size,
263 const uintptr_t *block_sizes,
283 uintptr_t *allocatable_size
395 uintptr_t alloc_begin,
399#ifndef HEAP_PROTECTION
400 #define _Heap_Protection_block_initialize( heap, block ) ((void) 0)
401 #define _Heap_Protection_block_check( heap, block ) ((void) 0)
402 #define _Heap_Protection_block_error( heap, block, reason ) ((void) 0)
403 #define _Heap_Protection_free_all_delayed_blocks( heap ) ((void) 0)
405 static inline void _Heap_Protection_block_initialize(
410 (*heap->Protection.block_initialize)( heap, block );
413 static inline void _Heap_Protection_block_check(
418 (*heap->Protection.block_check)( heap, block );
421 static inline void _Heap_Protection_block_error(
427 (*heap->Protection.block_error)( heap, block, reason );
430 void _Heap_Protection_free_all_delayed_blocks(
Heap_Control *heap );
443static inline void _Heap_Protection_set_delayed_free_fraction(
448#ifdef HEAP_PROTECTION
449 heap->Protection.delayed_free_fraction = fraction;
465 return &heap->free_list;
477 return &heap->free_list;
489 return _Heap_Free_list_head(heap)->
next;
501 return _Heap_Free_list_tail(heap)->
prev;
509static inline void _Heap_Free_list_remove(
Heap_Block *block )
524static inline void _Heap_Free_list_replace(
532 new_block->
next = next;
533 new_block->
prev = prev;
535 next->prev = new_block;
536 prev->
next = new_block;
545static inline void _Heap_Free_list_insert_after(
552 new_block->
next = next;
553 new_block->
prev = block_before;
554 block_before->
next = new_block;
555 next->prev = new_block;
564static inline void _Heap_Free_list_insert_before(
571 new_block->
next = block_next;
572 new_block->
prev = prev;
573 prev->
next = new_block;
574 block_next->
prev = new_block;
586static inline bool _Heap_Is_aligned(
591 return (value % alignment) == 0;
602static inline uintptr_t _Heap_Align_down(
607 return value - (value % alignment);
623 return (
Heap_Block *) ((uintptr_t) block + offset);
637 return (
Heap_Block *) ((uintptr_t) block - block->prev_size);
647static inline uintptr_t _Heap_Alloc_area_of_block(
662static inline Heap_Block *_Heap_Block_of_alloc_area(
663 uintptr_t alloc_begin,
667 return (
Heap_Block *) (_Heap_Align_down( alloc_begin, page_size )
678static inline uintptr_t _Heap_Block_size(
const Heap_Block *block )
680 return block->size_and_flag & ~HEAP_PREV_BLOCK_USED;
689static inline void _Heap_Block_set_size(
696 block->size_and_flag = size | flag;
708static inline bool _Heap_Is_prev_used(
const Heap_Block *block )
721static inline bool _Heap_Is_used(
726 _Heap_Block_at( block, _Heap_Block_size( block ) );
728 return _Heap_Is_prev_used( next_block );
739static inline bool _Heap_Is_free(
743 return !_Heap_Is_used( block );
755static inline bool _Heap_Is_block_in_heap(
760 return (uintptr_t) block >= (uintptr_t) heap->first_block
761 && (uintptr_t) block <= (uintptr_t) heap->last_block;
777static inline void _Heap_Set_last_block_size(
Heap_Control *heap )
779 _Heap_Block_set_size(
781 (uintptr_t) heap->first_block - (uintptr_t) heap->last_block
794static inline uintptr_t _Heap_Get_size(
const Heap_Control *heap )
796 return heap->stats.
size;
808static inline uintptr_t _Heap_Max( uintptr_t a, uintptr_t b )
810 return a > b ? a : b;
822static inline uintptr_t _Heap_Min( uintptr_t a, uintptr_t b )
824 return a < b ? a : b;
828 #define RTEMS_HEAP_DEBUG
831#ifdef RTEMS_HEAP_DEBUG
833 #define _HAssert( cond ) \
836 __assert( __FILE__, __LINE__, #cond ); \
840 #define _HAssert( cond ) ((void) 0)
This header file provides the interfaces of the Assert Handler.
void _Heap_Greedy_free(Heap_Control *heap, Heap_Block *blocks)
Frees blocks of a greedy allocation.
Definition: heapgreedy.c:111
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:93
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:451
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:190
#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:271
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:221
void _Heap_Iterate(Heap_Control *heap, Heap_Block_visitor visitor, void *visitor_arg)
Iterates over all blocks of the heap.
Definition: heapiterate.c:43
void _Heap_Get_information(Heap_Control *heap, Heap_Information_block *info)
Returns information about used and free blocks for the heap.
Definition: heapgetinfo.c:65
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:106
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:44
bool _Heap_Walk(Heap_Control *heap, int source, bool dump)
Verifies the integrity of the heap.
Definition: heapwalk.c:332
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:44
Heap_Error_reason
The heap error reason.
Definition: heap.h:163
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:224
bool _Heap_Free(Heap_Control *heap, void *addr)
Frees the allocated memory area.
Definition: heapfree.c:119
Heap_Resize_status
See _Heap_Resize_block().
Definition: heapimpl.h:67
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:227
#define HEAP_PREV_BLOCK_USED
See also Heap_Block::size_and_flag.
Definition: heapimpl.h:56
void _Heap_Get_free_information(Heap_Control *heap, Heap_Information *info)
Returns information about free blocks for the heap.
Definition: heapgetfreeinfo.c:44
This header file provides interfaces of the Heap Handler which are used by the implementation and the...
Description for free or used blocks.
Definition: heap.h:277
Heap_Block * prev
Pointer to the previous free block or part of the allocated area.
Definition: heap.h:333
Heap_Block * next
Pointer to the next free block or part of the allocated area.
Definition: heap.h:325
Control block used to manage a heap.
Definition: heap.h:339
uintptr_t size
Size of the allocatable area in bytes.
Definition: heapinfo.h:80