PebbleOS
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
heap.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Data Structures

struct  HeapLockImpl
 Locking of a heap. More...
 
struct  Heap
 Heap state. More...
 

Typedefs

typedef void(* LockFunction) (void *)
 Lock function of a heap, called with HeapLockImpl::lock_context.
 
typedef void(* UnlockFunction) (void *)
 Unlock function of a heap, called with HeapLockImpl::lock_context.
 
typedef void(* DoubleFreeHandler) (void *)
 Handler of a double free, called with the pointer being freed.
 
typedef void(* CorruptionHandler) (void *)
 Handler of a corrupted heap, called with the block where corruption was found.
 

Functions

void heap_init (Heap *const heap, void *start, void *end, bool fuzz_on_free)
 Initialize a heap over a memory region, zeroing it.
 
void heap_set_lock_impl (Heap *heap, HeapLockImpl lock_impl)
 Make a heap thread safe with a lock.
 
void heap_set_double_free_handler (Heap *heap, DoubleFreeHandler double_free_handler)
 Set the function called on a double free, instead of asserting.
 
void heap_set_corruption_handler (Heap *heap, CorruptionHandler corruption_handler)
 Set the function called when corruption is detected, instead of asserting.
 
void * heap_malloc (Heap *const heap, unsigned long nbytes, uintptr_t client_pc)
 Allocate memory.
 
void heap_free (Heap *const heap, void *ptr, uintptr_t client_pc)
 Free memory, merging it with adjacent free blocks.
 
void * heap_realloc (Heap *const heap, void *ptr, unsigned long nbytes, uintptr_t client_pc)
 Reallocate memory.
 
void * heap_zalloc (Heap *const heap, size_t size, uintptr_t client_pc)
 Allocate zeroed memory.
 
void * heap_calloc (Heap *const heap, size_t count, size_t size, uintptr_t client_pc)
 Allocate a zeroed array.
 
bool heap_contains_address (Heap *const heap, void *ptr)
 Check whether an address is within a heap.
 
bool heap_is_allocated (Heap *const heap, void *ptr)
 Check whether a pointer is an allocated block of a heap.
 
size_t heap_size (const Heap *heap)
 Get the size of a heap.
 
uint32_t heap_get_minimum_headroom (Heap *heap)
 Get the smallest amount of free memory the heap has had.
 
void heap_calc_totals (Heap *const heap, unsigned int *used, unsigned int *free, unsigned int *max_free)
 Calculate the current memory usage of a heap, for debugging.
 
void heap_dump_malloc_instrumentation_to_dbgserial (Heap *heap)
 Dump every block and the heap totals to the debug serial port.