From 5ad5f57a76c54161ca20356490ae81df37eec6f8 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sun, 15 Mar 2026 09:42:03 +0000 Subject: [PATCH] lib: c: update libheap to use new address-space api --- lib/libc/malloc/heap.c | 21 +++++++++++---------- lib/libc/malloc/include/heap/_liballoc.h | 1 - lib/libc/malloc/include/heap/heap.h | 1 - 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/libc/malloc/heap.c b/lib/libc/malloc/heap.c index 8445c7c..fc3f712 100644 --- a/lib/libc/malloc/heap.c +++ b/lib/libc/malloc/heap.c @@ -38,14 +38,10 @@ static kern_status_t init_heap_region(heap_t *heap) task_get_address_space(self, &address_space); kern_handle_close(self); - kern_status_t status = vm_region_create( + kern_status_t status = address_space_reserve( address_space, - "libc-heap", - 9, - VM_REGION_ANY_OFFSET, + MAP_ADDRESS_ANY, HEAP_REGION_SIZE, - VM_PROT_READ | VM_PROT_WRITE | VM_PROT_USER, - &heap->heap_region, &heap->heap_base); kern_handle_close(address_space); @@ -72,9 +68,14 @@ static kern_status_t expand_heap(heap_t *heap) virt_addr_t base = 0; - status = vm_region_map_relative( - heap->heap_region, - heap->heap_sys_alloc, + kern_handle_t self, address_space; + task_self(&self); + task_get_address_space(self, &address_space); + kern_handle_close(self); + + status = address_space_map( + address_space, + heap->heap_base + heap->heap_sys_alloc, vmo, 0, HEAP_EXPAND_INCREMENT, @@ -90,7 +91,7 @@ static kern_status_t expand_heap(heap_t *heap) void *heap_expand(heap_t *heap, size_t size) { kern_status_t status = KERN_OK; - if (heap->heap_region == KERN_HANDLE_INVALID) { + if (!heap->heap_base) { status = init_heap_region(heap); } diff --git a/lib/libc/malloc/include/heap/_liballoc.h b/lib/libc/malloc/include/heap/_liballoc.h index 965a268..aebb6b2 100644 --- a/lib/libc/malloc/include/heap/_liballoc.h +++ b/lib/libc/malloc/include/heap/_liballoc.h @@ -6,7 +6,6 @@ struct liballoc_minor; #define HEAP_INIT \ { \ - .heap_region = KERN_HANDLE_INVALID, \ .heap_liballoc = { \ .l_pageSize = 4096, \ .l_pageCount = 16, \ diff --git a/lib/libc/malloc/include/heap/heap.h b/lib/libc/malloc/include/heap/heap.h index 7ae8f7b..bb7475d 100644 --- a/lib/libc/malloc/include/heap/heap.h +++ b/lib/libc/malloc/include/heap/heap.h @@ -12,7 +12,6 @@ typedef enum heap_result { } heap_result_t; typedef struct heap { - kern_handle_t heap_region; /* amount of space requested from the heap by the user */ size_t heap_req_alloc; /* amount of space requested from the system by the heap */