struct vm_map_entry *entry, *next, *tmp;
vm_map_entry_t entry, next, tmp;
uvm_map_findspace(map, hint, length, result, uobj, uoffset, align, flags)	struct vm_map *map;	vaddr_t hint;	vsize_t length;	vaddr_t *result; /* OUT */	struct uvm_object *uobj;	voff_t uoffset;	vsize_t align;	int flags;{	struct vm_map_entry *entry, *next, *tmp;	vaddr_t end, orig_hint;	UVMHIST_FUNC("uvm_map_findspace");	UVMHIST_CALLED(maphist);	UVMHIST_LOG(maphist, "(map=0x%x, hint=0x%x, len=%d, flags=0x%x)",		    map, hint, length, flags);	KASSERT((align & (align - 1)) == 0);	KASSERT((flags & UVM_FLAG_FIXED) == 0 || align == 0);	/*	 * remember the original hint.  if we are aligning, then we	 * may have to try again with no alignment constraint if	 * we fail the first time.	 */	orig_hint = hint;	if (hint < map->min_offset) {	/* check ranges ... */		if (flags & UVM_FLAG_FIXED) {			UVMHIST_LOG(maphist,"<- VA below map range",0,0,0,0);			return(NULL);		}		hint = map->min_offset;	}	if (hint > map->max_offset) {		UVMHIST_LOG(maphist,"<- VA 0x%x > range [0x%x->0x%x]",				hint, map->min_offset, map->max_offset, 0);		return(NULL);	}	/*	 * Look for the first possible address; if there's already	 * something at this address, we have to start after it.	 */	if ((flags & UVM_FLAG_FIXED) == 0 && hint == map->min_offset) {		if ((entry = map->first_free) != &map->header)			hint = entry->end;	} else {		if (uvm_map_lookup_entry(map, hint, &tmp)) {			/* "hint" address already in use ... */			if (flags & UVM_FLAG_FIXED) {				UVMHIST_LOG(maphist,"<- fixed & VA in use",				    0, 0, 0, 0);				return(NULL);			}			hint = tmp->end;		}		entry = tmp;	}	/*	 * Look through the rest of the map, trying to fit a new region in	 * the gap between existing regions, or after the very last region.	 * note: entry->end   = base VA of current gap,	 *	 next->start  = VA of end of current gap	 */	for (;; hint = (entry = next)->end) {		/*		 * Find the end of the proposed new region.  Be sure we didn't		 * go beyond the end of the map, or wrap around the address;		 * if so, we lose.  Otherwise, if this is the last entry, or		 * if the proposed new region fits before the next entry, we		 * win.		 */#ifdef PMAP_PREFER		/*		 * push hint forward as needed to avoid VAC alias problems.		 * we only do this if a valid offset is specified.		 */		if ((flags & UVM_FLAG_FIXED) == 0 &&		    uoffset != UVM_UNKNOWN_OFFSET)			PMAP_PREFER(uoffset, &hint);#endif		if (align != 0) {			if ((hint & (align - 1)) != 0)				hint = roundup(hint, align);			/*			 * XXX Should we PMAP_PREFER() here again?			 */		}		end = hint + length;		if (end > map->max_offset || end < hint) {			UVMHIST_LOG(maphist,"<- failed (off end)", 0,0,0,0);			if (align != 0) {				UVMHIST_LOG(maphist,				    "calling recursively, no align",				    0,0,0,0);				return (uvm_map_findspace(map, orig_hint,				    length, result, uobj, uoffset, 0, flags));			}			return (NULL);		}		next = entry->next;		if (next == &map->header || next->start >= end)			break;		if (flags & UVM_FLAG_FIXED) {			UVMHIST_LOG(maphist,"<- fixed mapping failed", 0,0,0,0);			return(NULL); /* only one shot at it ... */		}	}	SAVE_HINT(map, map->hint, entry);	*result = hint;	UVMHIST_LOG(maphist,"<- got it!  (result=0x%x)", hint, 0,0,0);	return (entry);}