Index: vm_map.c =================================================================== --- vm_map.c +++ vm_map.c @@ -2472,9 +2472,7 @@ VM_MAP_RANGE_CHECK(map, start, end); - if (vm_map_lookup_entry(map, start, &entry)) { - vm_map_clip_start(map, entry, start); - } else { + if (!vm_map_lookup_entry(map, start, &entry)) { entry = entry->next; } @@ -2516,9 +2514,6 @@ * breakpoint on text segment) */ for (current = entry; current->start < end; current = current->next) { - - vm_map_clip_end(map, current, end); - if (set_max || ((new_prot & ~(current->protection)) & VM_PROT_WRITE) == 0 || ENTRY_CHARGED(current) || @@ -2530,7 +2525,8 @@ obj = current->object.vm_object; if (obj == NULL || (current->eflags & MAP_ENTRY_NEEDS_COPY)) { - if (!swap_reserve(current->end - current->start)) { + if (!swap_reserve(MIN(end, current->end) - + MAX(start, current->start))) { vm_map_unlock(map); return (KERN_RESOURCE_SHORTAGE); } @@ -2566,10 +2562,14 @@ } /* - * Go back and fix up protections. [Note that clipping is not - * necessary the second time.] + * Go back and fix up protections. */ + if (entry->start < start) + vm_map_clip_start(map, entry, start); for (current = entry; current->start < end; current = current->next) { + + vm_map_clip_end(map, current, end); + if ((current->eflags & MAP_ENTRY_GUARD) != 0) continue;