* unlock what we locked, unlock the maps and return
* unlock everything and return
uvm_loanentry(ufi, output, flags)	struct uvm_faultinfo *ufi;	void ***output;	int flags;{	vaddr_t curaddr = ufi->orig_rvaddr;	vsize_t togo = ufi->size;	struct vm_aref *aref = &ufi->entry->aref;	struct uvm_object *uobj = ufi->entry->object.uvm_obj;	struct vm_anon *anon;	int rv, result = 0;	/*	 * lock us the rest of the way down (we unlock before return)	 */	if (aref->ar_amap)		amap_lock(aref->ar_amap);	if (uobj)		simple_lock(&uobj->vmobjlock);	/*	 * loop until done	 */	while (togo) {		/*		 * find the page we want.   check the anon layer first.		 */		if (aref->ar_amap) {			anon = amap_lookup(aref, curaddr - ufi->entry->start);		} else {			anon = NULL;		}		/* locked: map, amap, uobj */		if (anon) {			rv = uvm_loananon(ufi, output, flags, anon);		} else if (uobj) {			rv = uvm_loanuobj(ufi, output, flags, curaddr);		} else if (UVM_ET_ISCOPYONWRITE(ufi->entry)) {			rv = uvm_loanzero(ufi, output, flags);		} else {			rv = -1;	/* null map entry... fail now */		}		/* locked: if (rv > 0) => map, amap, uobj  [o.w. unlocked] */		/* total failure */		if (rv < 0)			return(-1);		/* everything unlocked */		/* relock failed, need to do another lookup */		if (rv == 0)			return(result);		/* everything unlocked */		/*		 * got it... advance to next page		 */		result++;		togo -= PAGE_SIZE;		curaddr += PAGE_SIZE;	}	/*	 * unlock what we locked, unlock the maps and return	 */	if (aref->ar_amap)		amap_unlock(aref->ar_amap);	if (uobj)		simple_unlock(&uobj->vmobjlock);	uvmfault_unlockmaps(ufi, FALSE);	return(result);}