PebbleOS v4.47.0-512-g5285d4236
Loading...
Searching...
No Matches
heap.h File Reference
#include <stddef.h>
#include <stdint.h>

Data Structures

struct  pbl_heap_lock
 Locking of a heap. More...
 
struct  pbl_heap
 Heap. More...
 

Typedefs

typedef void(* pbl_heap_error_handler_t) (void *ptr)
 Handler of a heap error, called with the pointer being freed (double free) or the block where corruption was found.
 
typedef void(* pbl_heap_dump_cb_t) (const char *line, void *arg)
 Receives one line of a heap dump, with the heap locked.
 

Functions

void pbl_heap_init (struct pbl_heap *heap, void *start, void *end, bool fuzz_on_free)
 Initialize a heap over a memory region, zeroing it.
 
void pbl_heap_set_lock (struct pbl_heap *heap, struct pbl_heap_lock lock)
 Make a heap thread safe with a lock.
 
void pbl_heap_set_double_free_handler (struct pbl_heap *heap, pbl_heap_error_handler_t handler)
 Set the function called on a double free, instead of asserting.
 
void pbl_heap_set_corruption_handler (struct pbl_heap *heap, pbl_heap_error_handler_t handler)
 Set the function called when corruption is detected, instead of asserting.
 
void * pbl_heap_alloc (struct pbl_heap *heap, size_t size, uintptr_t caller)
 Allocate memory.
 
void * pbl_heap_zalloc (struct pbl_heap *heap, size_t size, uintptr_t caller)
 Allocate zeroed memory.
 
void * pbl_heap_calloc (struct pbl_heap *heap, size_t count, size_t size, uintptr_t caller)
 Allocate a zeroed array.
 
void * pbl_heap_realloc (struct pbl_heap *heap, void *ptr, size_t size, uintptr_t caller)
 Reallocate memory.
 
char * pbl_heap_strdup (struct pbl_heap *heap, const char *s, uintptr_t caller)
 Duplicate a string.
 
void pbl_heap_free (struct pbl_heap *heap, void *ptr, uintptr_t caller)
 Free memory, merging it with adjacent free blocks.
 
void pbl_heap_oom (struct pbl_heap *heap, size_t size, uintptr_t caller)
 Report an allocation failure the caller cannot recover from.
 
void pbl_heap_oom_handler (struct pbl_heap *heap, size_t size, uintptr_t caller)
 Handle an allocation failure the caller cannot recover from.
 
bool pbl_heap_contains (const struct pbl_heap *heap, const void *ptr)
 Check whether an address is within a heap.
 
bool pbl_heap_is_allocated (struct pbl_heap *heap, void *ptr)
 Check whether a pointer is an allocated block of a heap.
 
size_t pbl_heap_size (const struct pbl_heap *heap)
 Get the size of a heap.
 
size_t pbl_heap_used (const struct pbl_heap *heap)
 Get the number of allocated bytes, including block headers.
 
size_t pbl_heap_min_headroom (const struct pbl_heap *heap)
 Get the smallest amount of free memory the heap has had.
 
void pbl_heap_reset_high_water_mark (struct pbl_heap *heap)
 Restart the high water mark from the current usage.
 
void pbl_heap_stats (struct pbl_heap *heap, unsigned int *used, unsigned int *free, unsigned int *max_free)
 Walk a heap to calculate its usage.
 
void pbl_heap_dump (struct pbl_heap *heap, pbl_heap_dump_cb_t cb, void *arg)
 Dump every block and the heap totals, one line at a time.