if (islocked == FALSE)
if ((lockflags & UVM_LK_ENTER) == 0)
uvm_map_pageable(map, start, end, new_pageable, islocked)	vm_map_t map;	vaddr_t start, end;	boolean_t new_pageable, islocked;{	vm_map_entry_t entry, start_entry, failed_entry;	int rv;#ifdef DIAGNOSTIC	u_int timestamp_save;#endif	UVMHIST_FUNC("uvm_map_pageable"); UVMHIST_CALLED(maphist);	UVMHIST_LOG(maphist,"(map=0x%x,start=0x%x,end=0x%x,new_pageable=0x%x)",	map, start, end, new_pageable);#ifdef DIAGNOSTIC	if ((map->flags & VM_MAP_PAGEABLE) == 0)		panic("uvm_map_pageable: map %p not pageable", map);#endif	if (islocked == FALSE)		vm_map_lock(map);	VM_MAP_RANGE_CHECK(map, start, end);	/* 	 * only one pageability change may take place at one time, since	 * uvm_fault_wire assumes it will be called only once for each	 * wiring/unwiring.  therefore, we have to make sure we're actually	 * changing the pageability for the entire region.  we do so before	 * making any changes.  	 */	if (uvm_map_lookup_entry(map, start, &start_entry) == FALSE) {		vm_map_unlock(map);	 		UVMHIST_LOG(maphist,"<- done (INVALID ARG)",0,0,0,0);		return (KERN_INVALID_ADDRESS);	}	entry = start_entry;	/* 	 * handle wiring and unwiring separately.	 */	if (new_pageable) {		/* unwire */		UVM_MAP_CLIP_START(map, entry, start);		/*		 * unwiring.  first ensure that the range to be unwired is		 * really wired down and that there are no holes.  		 */		while ((entry != &map->header) && (entry->start < end)) {			if (entry->wired_count == 0 ||			    (entry->end < end &&			     (entry->next == &map->header ||			      entry->next->start > entry->end))) {				vm_map_unlock(map);				UVMHIST_LOG(maphist,				    "<- done (INVALID UNWIRE ARG)",0,0,0,0);				return (KERN_INVALID_ARGUMENT);			}			entry = entry->next;		}		/* 		 * POSIX 1003.1b - a single munlock call unlocks a region,		 * regardless of the number of mlock calls made on that		 * region.		 */		entry = start_entry;		while ((entry != &map->header) && (entry->start < end)) {			UVM_MAP_CLIP_END(map, entry, end);			if (VM_MAPENT_ISWIRED(entry))				uvm_map_entry_unwire(map, entry);			entry = entry->next;		}		vm_map_unlock(map);		UVMHIST_LOG(maphist,"<- done (OK UNWIRE)",0,0,0,0);		return(KERN_SUCCESS);		/*		 * end of unwire case!		 */	}	/*	 * wire case: in two passes [XXXCDC: ugly block of code here]	 *	 * 1: holding the write lock, we create any anonymous maps that need	 *    to be created.  then we clip each map entry to the region to	 *    be wired and increment its wiring count.  	 *	 * 2: we downgrade to a read lock, and call uvm_fault_wire to fault	 *    in the pages for any newly wired area (wired_count == 1).	 *	 *    downgrading to a read lock for uvm_fault_wire avoids a possible	 *    deadlock with another thread that may have faulted on one of	 *    the pages to be wired (it would mark the page busy, blocking	 *    us, then in turn block on the map lock that we hold).  because	 *    of problems in the recursive lock package, we cannot upgrade	 *    to a write lock in vm_map_lookup.  thus, any actions that	 *    require the write lock must be done beforehand.  because we	 *    keep the read lock on the map, the copy-on-write status of the	 *    entries we modify here cannot change.	 */	while ((entry != &map->header) && (entry->start < end)) {		if (VM_MAPENT_ISWIRED(entry) == 0) { /* not already wired? */			/* 			 * perform actions of vm_map_lookup that need the			 * write lock on the map: create an anonymous map			 * for a copy-on-write region, or an anonymous map			 * for a zero-fill region.  (XXXCDC: submap case			 * ok?)			 */			if (!UVM_ET_ISSUBMAP(entry)) {  /* not submap */				if (UVM_ET_ISNEEDSCOPY(entry) && 				    ((entry->protection & VM_PROT_WRITE) ||				     (entry->object.uvm_obj == NULL))) {					amap_copy(map, entry, M_WAITOK, TRUE,					    start, end); 					/* XXXCDC: wait OK? */				}			}		}		UVM_MAP_CLIP_START(map, entry, start);		UVM_MAP_CLIP_END(map, entry, end);		entry->wired_count++;		/*		 * Check for holes 		 */		if (entry->protection == VM_PROT_NONE ||		    (entry->end < end &&		     (entry->next == &map->header ||		      entry->next->start > entry->end))) {			/*			 * found one.  amap creation actions do not need to			 * be undone, but the wired counts need to be restored. 			 */			while (entry != &map->header && entry->end > start) {				entry->wired_count--;				entry = entry->prev;			}			vm_map_unlock(map);			UVMHIST_LOG(maphist,"<- done (INVALID WIRE)",0,0,0,0);			return (KERN_INVALID_ARGUMENT);		}		entry = entry->next;	}	/*	 * Pass 2.	 */#ifdef DIAGNOSTIC	timestamp_save = map->timestamp;#endif	vm_map_busy(map);	vm_map_downgrade(map);	rv = 0;	entry = start_entry;	while (entry != &map->header && entry->start < end) {		if (entry->wired_count == 1) {			rv = uvm_fault_wire(map, entry->start, entry->end,			    entry->protection);			if (rv) {				/*				 * wiring failed.  break out of the loop.				 * we'll clean up the map below, once we				 * have a write lock again.				 */				break;			}		}		entry = entry->next;	}	if (rv) {        /* failed? */		/*		 * Get back to an exclusive (write) lock.		 */		vm_map_upgrade(map);		vm_map_unbusy(map);#ifdef DIAGNOSTIC		if (timestamp_save != map->timestamp)			panic("uvm_map_pageable: stale map");#endif		/*		 * first drop the wiring count on all the entries		 * which haven't actually been wired yet.		 */		failed_entry = entry;		while (entry != &map->header && entry->start < end) {			entry->wired_count--;			entry = entry->next;		}		/*		 * now, unwire all the entries that were successfully		 * wired above.		 */		entry = start_entry;		while (entry != failed_entry) {			entry->wired_count--;			if (VM_MAPENT_ISWIRED(entry) == 0)				uvm_map_entry_unwire(map, entry);			entry = entry->next;		}		vm_map_unlock(map);		UVMHIST_LOG(maphist, "<- done (RV=%d)", rv,0,0,0);		return(rv);	}	/* We are holding a read lock here. */	vm_map_unbusy(map);	vm_map_unlock_read(map);		UVMHIST_LOG(maphist,"<- done (OK WIRE)",0,0,0,0);	return(KERN_SUCCESS);}