From afde37ff9b417de6e7e4b348a4df556c4d25de6f Mon Sep 17 00:00:00 2001 From: Alex Smith Date: Sun, 29 Jul 2012 14:31:11 +0100 Subject: [PATCH] Prevent allocating address 0 when inserting an area with B_ANY_ADDRESS. The USER_BASE_ANY definition exists to specify where to start searching for B_ANY_ADDRESS allocations, but this was not being used correctly. On x86_64, this was causing the runtime loader's heap to be allocated at address 0 so NULL pointer accesses were not getting caught. --- src/system/kernel/vm/VMUserAddressSpace.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/system/kernel/vm/VMUserAddressSpace.cpp b/src/system/kernel/vm/VMUserAddressSpace.cpp index 1420e447e5..32730a41cb 100644 --- a/src/system/kernel/vm/VMUserAddressSpace.cpp +++ b/src/system/kernel/vm/VMUserAddressSpace.cpp @@ -461,8 +461,8 @@ VMUserAddressSpace::_InsertAreaSlot(addr_t start, addr_t size, addr_t end, bool foundSpot = false; TRACE(("VMUserAddressSpace::_InsertAreaSlot: address space %p, start " - "0x%lx, size %ld, end 0x%lx, addressSpec %ld, area %p\n", this, start, - size, end, addressSpec, area)); + "0x%lx, size %ld, end 0x%lx, addressSpec %" B_PRIu32 ", area %p\n", + this, start, size, end, addressSpec, area)); // do some sanity checking if (start < fBase || size == 0 || end > fEndAddress @@ -514,8 +514,8 @@ second_chance: // find a hole big enough for a new area if (last == NULL) { // see if we can build it at the beginning of the virtual map - addr_t alignedBase = ROUNDUP(fBase, alignment); - if (is_valid_spot(fBase, alignedBase, size, + addr_t alignedBase = ROUNDUP(start, alignment); + if (is_valid_spot(start, alignedBase, size, next == NULL ? end : next->Base())) { foundSpot = true; area->SetBase(alignedBase);