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 void _Heap_Protection_free_all_delayed_blocks(
Heap_Control *heap );
428#ifdef HEAP_PROTECTION
429 heap->Protection.delayed_free_fraction = fraction;
445 return &heap->free_list;
457 return &heap->free_list;
512 new_block->
next = next;
513 new_block->
prev = prev;
515 next->prev = new_block;
516 prev->
next = new_block;
532 new_block->
next = next;
533 new_block->
prev = block_before;
534 block_before->
next = new_block;
535 next->prev = new_block;
551 new_block->
next = block_next;
552 new_block->
prev = prev;
553 prev->
next = new_block;
554 block_next->
prev = new_block;
571 return (value % alignment) == 0;
587 return value - (value % alignment);
603 return (
Heap_Block *) ((uintptr_t) block + offset);
617 return (
Heap_Block *) ((uintptr_t) block - block->prev_size);
643 uintptr_t alloc_begin,
660 return block->size_and_flag & ~HEAP_PREV_BLOCK_USED;
676 block->size_and_flag =
size | flag;
740 return (uintptr_t) block >= (uintptr_t) heap->first_block
741 && (uintptr_t) block <= (uintptr_t) heap->last_block;
761 (uintptr_t) heap->first_block - (uintptr_t) heap->last_block
776 return heap->stats.
size;
790 return a > b ? a : b;
804 return a < b ? a : b;
808 #define RTEMS_HEAP_DEBUG
811#ifdef RTEMS_HEAP_DEBUG
813 #define _HAssert( cond ) \
816 __assert( __FILE__, __LINE__, #cond ); \
820 #define _HAssert( cond ) ((void) 0)
Information for the Assert Handler.
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:66
void _Heap_Greedy_free(Heap_Control *heap, Heap_Block *blocks)
Frees blocks of a greedy allocation.
Definition: heapgreedy.c:96
RTEMS_INLINE_ROUTINE uintptr_t _Heap_Min(uintptr_t a, uintptr_t b)
Returns the smaller one of the two arguments.
Definition: heapimpl.h:802
RTEMS_INLINE_ROUTINE uintptr_t _Heap_Block_size(const Heap_Block *block)
Returns the block size.
Definition: heapimpl.h:658
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:627
RTEMS_INLINE_ROUTINE uintptr_t _Heap_Align_down(uintptr_t value, uintptr_t alignment)
Returns the aligned value, truncating.
Definition: heapimpl.h:582
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
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 Heap_Block * _Heap_Free_list_head(Heap_Control *heap)
Returns the head of the free list of the heap.
Definition: heapimpl.h:443
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_Max(uintptr_t a, uintptr_t b)
Returns the bigger one of the two arguments.
Definition: heapimpl.h:788
#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
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:201
RTEMS_INLINE_ROUTINE uintptr_t _Heap_Get_size(const Heap_Control *heap)
Returns the size of the allocatable area in bytes.
Definition: heapimpl.h:774
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_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:544
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 Heap_Block * _Heap_Free_list_tail(Heap_Control *heap)
Returns the tail of the free list of the heap.
Definition: heapimpl.h:455
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:566
RTEMS_INLINE_ROUTINE Heap_Block * _Heap_Prev_block(const Heap_Block *block)
Returns the address of the previous block.
Definition: heapimpl.h:613
RTEMS_INLINE_ROUTINE bool _Heap_Is_used(const Heap_Block *block)
Returns if the heap block is used.
Definition: heapimpl.h:701
RTEMS_INLINE_ROUTINE void _Heap_Free_list_remove(Heap_Block *block)
Removes the block from the free list.
Definition: heapimpl.h:489
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:525
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:598
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
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
bool _Heap_Walk(Heap_Control *heap, int source, bool dump)
Verifies the integrity of the heap.
Definition: heapwalk.c:312
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
Heap_Error_reason
The heap error reason.
Definition: heap.h:142
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:479
RTEMS_INLINE_ROUTINE void * _Heap_Allocate(Heap_Control *heap, uintptr_t size)
Allocates a memory area.
Definition: heapimpl.h:160
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
bool _Heap_Free(Heap_Control *heap, void *addr)
Frees the allocated memory area.
Definition: heapfree.c:99
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:735
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:467
Heap_Resize_status
See _Heap_Resize_block().
Definition: heapimpl.h:47
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_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:642
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:423
#define HEAP_PREV_BLOCK_USED
See also Heap_Block::size_and_flag.
Definition: heapimpl.h:36
RTEMS_INLINE_ROUTINE bool _Heap_Is_prev_used(const Heap_Block *block)
Returns if the previous heap block is used.
Definition: heapimpl.h:688
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:504
RTEMS_INLINE_ROUTINE bool _Heap_Is_free(const Heap_Block *block)
Returns if the heap block is free.
Definition: heapimpl.h:719
RTEMS_INLINE_ROUTINE void _Heap_Block_set_size(Heap_Block *block, uintptr_t size)
Sets the block size.
Definition: heapimpl.h:669
void _Heap_Get_free_information(Heap_Control *heap, Heap_Information *info)
Returns information about free blocks for the heap.
Definition: heapgetfreeinfo.c:24
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:757
Description for free or used blocks.
Definition: heap.h:256
Heap_Block * prev
Pointer to the previous free block or part of the allocated area.
Definition: heap.h:312
Heap_Block * next
Pointer to the next free block or part of the allocated area.
Definition: heap.h:304
Control block used to manage a heap.
Definition: heap.h:318
uintptr_t size
Size of the allocatable area in bytes.
Definition: heapinfo.h:60
unsigned size
Definition: tte.h:1