-
-/*
- * kmem_io_object_trunc:
- *
- * Truncate an object vm_map_copy_t.
- * Called by the scatter/gather list network code to remove pages from
- * the tail end of a packet. Also unwires the objects pages.
- */
-
-kern_return_t
-kmem_io_object_trunc(copy, new_size)
- vm_map_copy_t copy; /* IN/OUT copy object */
- register vm_size_t new_size; /* IN new object size */
-{
- register vm_size_t offset, old_size;
-
- assert(copy->type == VM_MAP_COPY_OBJECT);
-
- old_size = (vm_size_t)round_page_64(copy->size);
- copy->size = new_size;
- new_size = round_page_32(new_size);
-
- vm_object_lock(copy->cpy_object);
- vm_object_page_remove(copy->cpy_object,
- (vm_object_offset_t)new_size, (vm_object_offset_t)old_size);
- for (offset = 0; offset < new_size; offset += PAGE_SIZE) {
- register vm_page_t mem;
-
- if ((mem = vm_page_lookup(copy->cpy_object,
- (vm_object_offset_t)offset)) == VM_PAGE_NULL)
- panic("kmem_io_object_trunc: unable to find object page");
-
- /*
- * Make sure these pages are marked dirty
- */
- mem->dirty = TRUE;
- vm_page_lock_queues();
- vm_page_unwire(mem);
- vm_page_unlock_queues();
- }
- copy->cpy_object->size = new_size; /* adjust size of object */
- vm_object_unlock(copy->cpy_object);
- return(KERN_SUCCESS);
-}
-
-/*
- * kmem_io_object_deallocate:
- *
- * Free an vm_map_copy_t.
- * Called by the scatter/gather list network code to free a packet.
- */
-
-void
-kmem_io_object_deallocate(
- vm_map_copy_t copy) /* IN/OUT copy object */
-{
- kern_return_t ret;
-
- /*
- * Clear out all the object pages (this will leave an empty object).
- */
- ret = kmem_io_object_trunc(copy, 0);
- if (ret != KERN_SUCCESS)
- panic("kmem_io_object_deallocate: unable to truncate object");