Allocations from the kernel heap.
More...
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.
if (e == NULL) {
return -ENOMEM;
}
...
pbl_free(e);
void * pbl_zalloc(size_t size)
Allocate zeroed memory.
◆ pbl_calloc()
| void * pbl_calloc |
( |
size_t |
count, |
|
|
size_t |
size |
|
) |
| |
Allocate a zeroed array.
- Parameters
-
| count | Number of elements. |
| size | Size 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
-
| count | Number of elements. |
| size | Size 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
-
| ptr | Memory 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
-
- Returns
- Allocated memory, or NULL.
◆ pbl_malloc_check()
| void * pbl_malloc_check |
( |
size_t |
size | ) |
|
Allocate memory, or fail with pbl_heap_oom().
- Parameters
-
- 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
-
| ptr | Memory from the kernel heap, or NULL. |
| size | New 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
-
- 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
-
- Returns
- Copy of
s.
◆ pbl_zalloc()
| void * pbl_zalloc |
( |
size_t |
size | ) |
|
Allocate zeroed memory.
- Parameters
-
- 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
-
- Returns
- Allocated memory; NULL only if
size is 0.