PebbleOS v4.44.0-105-g1dd754433
Loading...
Searching...
No Matches
Kernel heap

Allocations from the kernel heap. More...

Functions

void pbl_malloc_init (void)
 Initialize the kernel heap.
 
struct pbl_heap * pbl_malloc_heap (void)
 Get the kernel heap.
 
void * pbl_malloc (size_t size)
 Allocate memory.
 
void * pbl_malloc_check (size_t size)
 Allocate memory, or fail with pbl_heap_oom().
 
void * pbl_zalloc (size_t size)
 Allocate zeroed memory.
 
void * pbl_zalloc_check (size_t size)
 Allocate zeroed memory, or fail with pbl_heap_oom().
 
void * pbl_calloc (size_t count, size_t size)
 Allocate a zeroed array.
 
void * pbl_calloc_check (size_t count, size_t size)
 Allocate a zeroed array, or fail with pbl_heap_oom().
 
void * pbl_realloc (void *ptr, size_t size)
 Reallocate memory.
 
char * pbl_strdup (const char *s)
 Duplicate a string.
 
char * pbl_strdup_check (const char *s)
 Duplicate a string, or fail with pbl_heap_oom().
 
void pbl_free (void *ptr)
 Free memory.
 

Detailed Description

Allocations from the kernel heap.

The kernel heap sits in kernel RAM, between the linker symbols _heap_start and _heap_end. Every function here allocates from it, whatever thread calls it, and can be used before the scheduler starts and from interrupts that may call the kernel. Other heaps are reached through their own struct pbl_heap.

The _check variants never return NULL: they call pbl_heap_oom() instead.

struct entry *e = pbl_zalloc(sizeof(*e));
if (e == NULL) {
return -ENOMEM;
}
...
pbl_free(e);
void * pbl_zalloc(size_t size)
Allocate zeroed memory.

Function Documentation

◆ pbl_calloc()

void * pbl_calloc ( size_t  count,
size_t  size 
)

Allocate a zeroed array.

Parameters
countNumber of elements.
sizeSize of an element in bytes.
Returns
Allocated memory, or NULL.

◆ pbl_calloc_check()

void * pbl_calloc_check ( size_t  count,
size_t  size 
)

Allocate a zeroed array, or fail with pbl_heap_oom().

Parameters
countNumber of elements.
sizeSize of an element in bytes.
Returns
Allocated memory; NULL only if the total size is 0.

◆ pbl_free()

void pbl_free ( void *  ptr)

Free memory.

Parameters
ptrMemory from the kernel heap, or NULL (no-op). Anything else is a fatal error.

◆ pbl_malloc()

void * pbl_malloc ( size_t  size)

Allocate memory.

Parameters
sizeNumber of bytes.
Returns
Allocated memory, or NULL.

◆ pbl_malloc_check()

void * pbl_malloc_check ( size_t  size)

Allocate memory, or fail with pbl_heap_oom().

Parameters
sizeNumber of bytes.
Returns
Allocated memory; NULL only if size is 0.

◆ pbl_malloc_heap()

struct pbl_heap * pbl_malloc_heap ( void  )

Get the kernel heap.

Returns
Kernel heap.

◆ pbl_malloc_init()

void pbl_malloc_init ( void  )

Initialize the kernel heap.

Called once at boot, before any allocation.

◆ pbl_realloc()

void * pbl_realloc ( void *  ptr,
size_t  size 
)

Reallocate memory.

Parameters
ptrMemory from the kernel heap, or NULL.
sizeNew size in bytes.
Returns
New memory, or NULL on failure (ptr is then left untouched).

◆ pbl_strdup()

char * pbl_strdup ( const char *  s)

Duplicate a string.

Parameters
sString.
Returns
Copy of s, or NULL.

◆ pbl_strdup_check()

char * pbl_strdup_check ( const char *  s)

Duplicate a string, or fail with pbl_heap_oom().

Parameters
sString.
Returns
Copy of s.

◆ pbl_zalloc()

void * pbl_zalloc ( size_t  size)

Allocate zeroed memory.

Parameters
sizeNumber of bytes.
Returns
Allocated memory, or NULL.

◆ pbl_zalloc_check()

void * pbl_zalloc_check ( size_t  size)

Allocate zeroed memory, or fail with pbl_heap_oom().

Parameters
sizeNumber of bytes.
Returns
Allocated memory; NULL only if size is 0.