diff --git a/photon/libc/sys/horizon/heap.c b/photon/libc/sys/horizon/heap.c index ce5c076..de9c736 100644 --- a/photon/libc/sys/horizon/heap.c +++ b/photon/libc/sys/horizon/heap.c @@ -9,6 +9,9 @@ #include #include +/* 1 GiB */ +#define HEAP_REGION_SZ 0x40000000 + #define ROUND_UP(x, b) x += (b) - ((x) % (b)) static uintptr_t heap_start = 0; @@ -16,17 +19,24 @@ static uintptr_t heap_end = 0; static uintptr_t heap_alloc_point = 0; static size_t heap_sz = 0; static mx_handle_t heap_vmo = MX_NULL_HANDLE; +static mx_handle_t heap_vmar = MX_NULL_HANDLE; void __crt_heap_init(size_t sz) { - mx_status_t status = mx_vmo_create( + mx_handle_t root_vmar = mx_bootstrap_handle_get(MX_B_VMAR_ROOT); + mx_vaddr_t heap = 0; + + mx_status_t status = mx_vmar_allocate(root_vmar, + MX_VM_CAN_MAP_READ | MX_VM_CAN_MAP_WRITE | MX_VM_CAN_MAP_SPECIFIC, + 0, HEAP_REGION_SZ, &heap_vmar, &heap); + + status = mx_vmo_create( 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_bootstrap_handle_get(MX_B_VMAR_ROOT), - MX_VM_PERM_READ | MX_VM_PERM_WRITE, + mx_vmar_map(heap_vmar, + MX_VM_PERM_READ | MX_VM_PERM_WRITE | MX_VM_SPECIFIC, 0, heap_vmo, 0, sz, &heap); @@ -57,10 +67,10 @@ void *__crt_heap_extend(size_t sz) mx_vmo_set_size(heap_vmo, heap_sz + sz); mx_vaddr_t vmar_base, alloc_base; - mx_vmar_bounds(mx_bootstrap_handle_get(MX_B_VMAR_ROOT), &vmar_base, NULL); + mx_vmar_bounds(heap_vmar, &vmar_base, NULL); size_t offset = heap_end - vmar_base; - mx_status_t err = mx_vmar_map(mx_bootstrap_handle_get(MX_B_VMAR_ROOT), + mx_status_t err = mx_vmar_map(heap_vmar, MX_VM_PERM_READ | MX_VM_PERM_WRITE | MX_VM_SPECIFIC, offset, heap_vmo, heap_sz, sz, &alloc_base);