uvm_unmap_remove(kernel_map, kva, kva + chunksz, &dead_entries);
(void)uvm_unmap_remove(kernel_map, kva, kva+chunksz, &dead_entries);
uvm_io(map, uio)	struct vm_map *map;	struct uio *uio;{	vaddr_t baseva, endva, pageoffset, kva;	vsize_t chunksz, togo, sz;	struct vm_map_entry *dead_entries;	int error;	/*	 * step 0: sanity checks and set up for copy loop.  start with a	 * large chunk size.  if we have trouble finding vm space we will	 * reduce it.	 */	if (uio->uio_resid == 0)		return(0);	togo = uio->uio_resid;	baseva = (vaddr_t) uio->uio_offset;	endva = baseva + (togo - 1);	if (endva < baseva)   /* wrap around? */		return(EIO);	if (baseva >= VM_MAXUSER_ADDRESS)		return(0);	if (endva >= VM_MAXUSER_ADDRESS)		/* EOF truncate */		togo = togo - (endva - VM_MAXUSER_ADDRESS + 1);	pageoffset = baseva & PAGE_MASK;	baseva = trunc_page(baseva);	chunksz = min(round_page(togo + pageoffset), MAXBSIZE);	error = 0;	/*	 * step 1: main loop...  while we've got data to move	 */	for (/*null*/; togo > 0 ; pageoffset = 0) {		/*		 * step 2: extract mappings from the map into kernel_map		 */		error = uvm_map_extract(map, baseva, chunksz, kernel_map, &kva,			    UVM_EXTRACT_QREF | UVM_EXTRACT_CONTIG |			    UVM_EXTRACT_FIXPROT);		if (error) {			/* retry with a smaller chunk... */			if (error == ENOMEM && chunksz > PAGE_SIZE) {				chunksz = trunc_page(chunksz / 2);				if (chunksz < PAGE_SIZE)					chunksz = PAGE_SIZE;				continue;			}			break;		}		/*		 * step 3: move a chunk of data		 */		sz = chunksz - pageoffset;		if (sz > togo)			sz = togo;		error = uiomove((caddr_t) (kva + pageoffset), sz, uio);		togo -= sz;		baseva += chunksz;		/*		 * step 4: unmap the area of kernel memory		 */		vm_map_lock(kernel_map);		uvm_unmap_remove(kernel_map, kva, kva + chunksz, &dead_entries);		vm_map_unlock(kernel_map);		if (dead_entries != NULL)			uvm_unmap_detach(dead_entries, AMAP_REFALL);		/*		 * We defer checking the error return from uiomove until		 * here so that we won't leak memory.		 */		if (error)			break;	}	/*	 * done	 */	return (error);}