diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index ae45ccc704..1cc7ad3de2 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -1022,8 +1022,8 @@ find_reserved_area(vm_address_space* addressSpace, addr_t start, next = addressSpace->areas; while (next != NULL) { if (next->base <= start - && next->base + next->size > start + (size - 1)) { - // this area covers the requested range + && next->base + (next->size - 1) >= start + (size - 1)) { + // This area covers the requested range if (next->id != RESERVED_AREA_ID) { // but it's not reserved space, it's a real area return B_BAD_VALUE; @@ -1039,7 +1039,7 @@ find_reserved_area(vm_address_space* addressSpace, addr_t start, if (next == NULL) return B_ENTRY_NOT_FOUND; - // now we have to transfer the requested part of the reserved + // Now we have to transfer the requested part of the reserved // range to the new area - and remove, resize or split the old // reserved area. @@ -1126,7 +1126,7 @@ find_and_insert_area_slot(vm_address_space* addressSpace, addr_t start, || start + (size - 1) > end) return B_BAD_ADDRESS; - if (addressSpec == B_EXACT_ADDRESS) { + if (addressSpec == B_EXACT_ADDRESS && area->id != RESERVED_AREA_ID) { // search for a reserved area status_t status = find_reserved_area(addressSpace, start, size, area); if (status == B_OK || status == B_BAD_VALUE) @@ -1206,7 +1206,7 @@ second_chance: foundSpot = true; area->base = alignedBase; break; - } else { + } else if (area->id != RESERVED_AREA_ID) { // We didn't find a free spot - if there are any reserved areas, // we can now test those for free space // TODO: it would make sense to start with the biggest of them diff --git a/src/tests/system/kernel/reserved_areas_test.cpp b/src/tests/system/kernel/reserved_areas_test.cpp index b569b805ba..a19981b6d9 100644 --- a/src/tests/system/kernel/reserved_areas_test.cpp +++ b/src/tests/system/kernel/reserved_areas_test.cpp @@ -1,3 +1,9 @@ +/* + * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ + + //! Test application that reproduces bug #4778. @@ -43,18 +49,17 @@ area_creator(void*) base = (void*)0x60000000; status = _kern_reserve_address_range((addr_t*)&base, B_BASE_ADDRESS, 128 * 1024 * 1024); - if (status != B_OK) - snooze(10000000LL); addressSpec = status == B_OK ? B_EXACT_ADDRESS : B_BASE_ADDRESS; -printf("\naddress spec = %lx, base %p (status %s)\n", addressSpec, base, strerror(status)); + printf("\naddress spec = %lx, base %p (status %s)\n", addressSpec, + base, strerror(status)); } area_id area = create_area(readOnly ? "read-only memory" : "r/w memory", &base, addressSpec, B_PAGE_SIZE * 4, B_NO_LOCK, B_READ_AREA | (readOnly ? 0 : B_WRITE_AREA)); if (area >= 0) { -printf("new %s area %ld at %p\n", readOnly ? "read-only" : "r/w", area, base); -// putchar('#'); + printf("new %s area %ld at %p\n", readOnly ? "read-only" : "r/w", + area, base); } else break;