+ kr = vm_map_find_space(map, &newaddr, newsize, (vm_offset_t) 0,
+ &newentry);
+ if (kr != KERN_SUCCESS) {
+ vm_object_lock(object);
+ for(offset = oldsize;
+ offset<newsize; offset+=PAGE_SIZE) {
+ if ((mem = vm_page_lookup(object, offset)) != VM_PAGE_NULL) {
+ vm_page_lock_queues();
+ vm_page_free(mem);
+ vm_page_unlock_queues();
+ }
+ }
+ object->size = oldsize;
+ vm_object_unlock(object);
+ vm_object_deallocate(object);
+ return kr;
+ }
+ newentry->object.vm_object = object;
+ newentry->offset = 0;
+ assert (newentry->wired_count == 0);
+
+
+ /* add an extra reference in case we have someone doing an */
+ /* unexpected deallocate */
+ vm_object_reference(object);