|
miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
|
Boundary-tag kernel heap allocator at HEAP_START (0xFFFF820000000000). More...
Functions | |
| void | heap_init (void) |
| Maps the first heap page at HEAP_START via vmm_map_page() and writes the initial free-block boundary tag covering the entire heap region. Must be called exactly once during boot before any call to kmalloc(). Called by kernel_main() after vmm setup. | |
| void * | kmalloc (size_t size) |
| Uses a first-fit boundary-tag strategy. Acquires heap_lock (spinlock_irqsave) before scanning. Maps additional pages via vmm_map_page() if the current heap extent is exhausted (up to HEAP_MAX). | |
| void | kfree (void *ptr) |
| Marks the block free in its boundary tag and coalesces adjacent free blocks (forward and backward). Acquires heap_lock before modifying heap state. | |
| size_t | heap_free_bytes (void) |
| Walks the boundary-tag chain and sums the sizes of all free blocks. O(n) in the number of heap blocks. Intended for diagnostic/debug output only. | |
Boundary-tag kernel heap allocator at HEAP_START (0xFFFF820000000000).
Implements a simple first-fit boundary-tag heap that grows upward from HEAP_START. Maximum size is HEAP_MAX - HEAP_START = 4 MiB. Not thread-safe on its own; callers must hold heap_lock (a spinlock in heap.c) in SMP context.
| size_t heap_free_bytes | ( | void | ) |
Walks the boundary-tag chain and sums the sizes of all free blocks. O(n) in the number of heap blocks. Intended for diagnostic/debug output only.
heap_free_bytes() - Query the total free bytes currently available in the heap.


| void heap_init | ( | void | ) |
Maps the first heap page at HEAP_START via vmm_map_page() and writes the initial free-block boundary tag covering the entire heap region. Must be called exactly once during boot before any call to kmalloc(). Called by kernel_main() after vmm setup.
heap_init() - Initialise the kernel heap allocator.


| void kfree | ( | void * | ptr | ) |
Marks the block free in its boundary tag and coalesces adjacent free blocks (forward and backward). Acquires heap_lock before modifying heap state.
kfree() - Return a kmalloc'd allocation to the kernel heap free list.
| ptr | Pointer returned by a previous kmalloc() call. Passing NULL is a no-op. |


| void * kmalloc | ( | size_t | size | ) |
Uses a first-fit boundary-tag strategy. Acquires heap_lock (spinlock_irqsave) before scanning. Maps additional pages via vmm_map_page() if the current heap extent is exhausted (up to HEAP_MAX).
kmalloc() - Allocate @size bytes from the kernel heap.
| size | Number of bytes to allocate. Rounded up to 8-byte alignment internally. |

