|
miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
|
#include <miniOS/mm/heap.h>#include <miniOS/mm/pmm.h>#include <miniOS/mm/vmm.h>#include <miniOS/types.h>#include <miniOS/arch/x86_64/spinlock.h>
Classes | |
| struct | heap_hdr |
| struct | heap_ftr |
Macros | |
| #define | HEAP_START 0xFFFF820000000000ULL |
| #define | HEAP_MAX (HEAP_START + 64ULL * 1024 * 1024) /* 64MB limit */ |
| #define | HDR_SIZE 16ULL /* sizeof aligned header */ |
| #define | FTR_SIZE 8ULL /* sizeof footer */ |
| #define | OVERHEAD (HDR_SIZE + FTR_SIZE) |
| #define | MIN_BLOCK 32ULL /* minimum allocation unit (8 bytes of usable payload) */ |
Functions | |
| static struct heap_ftr * | blk_ftr (struct heap_hdr *hdr) |
| static struct heap_hdr * | blk_next (struct heap_hdr *hdr) |
| static void * | blk_payload (struct heap_hdr *hdr) |
| static struct heap_hdr * | hdr_from_payload (void *ptr) |
| static void | blk_init (uint64_t addr, size_t payload_size, uint8_t used) |
| static struct heap_hdr * | heap_expand (void) |
| 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. | |
Variables | |
| static uint64_t | heap_top = 0 |
| static spinlock_t | heap_lock = SPINLOCK_INIT |
| #define FTR_SIZE 8ULL /* sizeof footer */ |
| #define HDR_SIZE 16ULL /* sizeof aligned header */ |
| #define HEAP_MAX (HEAP_START + 64ULL * 1024 * 1024) /* 64MB limit */ |
| #define HEAP_START 0xFFFF820000000000ULL |
| #define MIN_BLOCK 32ULL /* minimum allocation unit (8 bytes of usable payload) */ |




|
inlinestatic |

|
inlinestatic |

|
static |


|
static |
|
static |