From 28071cd3c613a8143ef262d290c1be0610b8750c Mon Sep 17 00:00:00 2001 From: Max Wash Date: Thu, 11 Mar 2021 10:12:33 +0000 Subject: [PATCH] Fixed incorrect heap bounds --- photon/libc/sys/magenta/heap.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/photon/libc/sys/magenta/heap.c b/photon/libc/sys/magenta/heap.c index 9a2d590..56c8cfb 100644 --- a/photon/libc/sys/magenta/heap.c +++ b/photon/libc/sys/magenta/heap.c @@ -14,19 +14,20 @@ static uintptr_t heap_alloc_point = 0; static size_t heap_sz = 0; static mx_handle_t heap_vmo = MX_NULL_HANDLE; -void __crt_heap_init(size_t heap_sz) +void __crt_heap_init(size_t sz) { mx_status_t status = mx_vmo_create( - heap_sz, + sz, MX_VM_CAN_MAP_READ | MX_VM_CAN_MAP_WRITE | MX_VM_CAN_MAP_SPECIFIC, &heap_vmo); mx_vaddr_t heap = 0; mx_vmar_map(mx_get_startup_handle(MX_B_VMAR_ROOT), MX_VM_PERM_READ | MX_VM_PERM_WRITE, - 0, heap_vmo, 0, heap_sz, + 0, heap_vmo, 0, sz, &heap); + heap_sz = sz; heap_start = heap; heap_end = heap + heap_sz; heap_alloc_point = heap_start; @@ -41,20 +42,20 @@ void *__crt_heap_extend(size_t sz) sz += MX_PAGE_SIZE; } + if (!sz) { + return (void *)heap_end; + } + if (!heap_start) { __crt_heap_init(sz); return (void *)heap_start; } - if (!sz) { - return (void *)heap_end; - } - mx_vmo_set_size(heap_vmo, heap_sz + sz); mx_vaddr_t vmar_base, alloc_base; mx_vmar_bounds(mx_get_startup_handle(MX_B_VMAR_ROOT), &vmar_base, NULL); - mx_vaddr_t offset = heap_end - vmar_base; + size_t offset = heap_end - vmar_base; mx_vmar_map(mx_get_startup_handle(MX_B_VMAR_ROOT), MX_VM_PERM_READ | MX_VM_PERM_WRITE | MX_VM_SPECIFIC,