runtime_loader: fix heap address reservation

The runtime_loader previously used resize_area without properly
reserving address space first. This worked in most cases but failed when
ASLR was disabled or when address space was crowded.

* Add kHeapReservationSize constant (1MB) for virtual address space.
* Create area at exact address within reservation

fixes #19345

Change-Id: I952f11475ad041056833de6a248bfea4a9a2e397
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10360
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
Amir Ramez
2026-02-25 14:59:06 +00:00
committed by waddlesplash
parent a2443366d9
commit f04af472b4
+12 -3
View File
@@ -27,6 +27,7 @@ const static size_t kAlignment = 8;
const static size_t kInitialHeapSize = 64 * 1024;
const static size_t kHeapGrowthAlignment = 32 * 1024;
const static size_t kHeapReservationSize = 1 * 1024 * 1024;
static const char* const kLockName = "runtime_loader heap";
static recursive_lock sLock = RECURSIVE_LOCK_INITIALIZER(kLockName);
@@ -54,11 +55,19 @@ add_area(size_t size)
}
}
void* base;
void* reservedBase;
status_t status = _kern_reserve_address_range((addr_t*)&reservedBase,
B_RANDOMIZED_ANY_ADDRESS, kHeapReservationSize);
if (status != B_OK)
return status;
void* base = reservedBase;
area_id area = _kern_create_area("rld heap", &base,
B_RANDOMIZED_ANY_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
if (area < 0)
B_EXACT_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
if (area < 0) {
_kern_unreserve_address_range((addr_t)reservedBase, kHeapReservationSize);
return area;
}
sLastHeapBase = base;
sLastHeapArea = area;