struct vm_map_entry *entry;
vm_map_entry_t entry;
amap_extend(entry, addsize)	struct vm_map_entry *entry;	vsize_t addsize;{	struct vm_amap *amap = entry->aref.ar_amap;	int slotoff = entry->aref.ar_pageoff;	int slotmapped, slotadd, slotneed;#ifdef UVM_AMAP_PPREF	int *newppref, *oldppref;#endif	u_int *newsl, *newbck, *oldsl, *oldbck;	struct vm_anon **newover, **oldover;	int slotadded;	UVMHIST_FUNC("amap_extend"); UVMHIST_CALLED(maphist);	UVMHIST_LOG(maphist, "  (entry=0x%x, addsize=0x%x)", entry,addsize,0,0);	/*	 * first, determine how many slots we need in the amap.  don't	 * forget that ar_pageoff could be non-zero: this means that	 * there are some unused slots before us in the amap.	 */	amap_lock(amap);					/* lock! */	AMAP_B2SLOT(slotmapped, entry->end - entry->start); /* slots mapped */	AMAP_B2SLOT(slotadd, addsize);			/* slots to add */	slotneed = slotoff + slotmapped + slotadd;	/*	 * case 1: we already have enough slots in the map and thus	 * only need to bump the reference counts on the slots we are	 * adding.	 */	if (amap->am_nslot >= slotneed) {#ifdef UVM_AMAP_PPREF		if (amap->am_ppref && amap->am_ppref != PPREF_NONE) {			amap_pp_adjref(amap, slotoff + slotmapped, slotadd, 1);		}#endif		amap_unlock(amap);		UVMHIST_LOG(maphist,"<- done (case 1), amap = 0x%x, sltneed=%d",		    amap, slotneed, 0, 0);		return;				/* done! */	}	/*	 * case 2: we pre-allocated slots for use and we just need to	 * bump nslot up to take account for these slots.	 */	if (amap->am_maxslot >= slotneed) {#ifdef UVM_AMAP_PPREF		if (amap->am_ppref && amap->am_ppref != PPREF_NONE) {			if ((slotoff + slotmapped) < amap->am_nslot)				amap_pp_adjref(amap, slotoff + slotmapped,				    (amap->am_nslot - (slotoff + slotmapped)),				    1);			pp_setreflen(amap->am_ppref, amap->am_nslot, 1,			   slotneed - amap->am_nslot);		}#endif		amap->am_nslot = slotneed;		amap_unlock(amap);		/*		 * no need to zero am_anon since that was done at		 * alloc time and we never shrink an allocation.		 */		UVMHIST_LOG(maphist,"<- done (case 2), amap = 0x%x, slotneed=%d",		    amap, slotneed, 0, 0);		return;	}	/*	 * case 3: we need to malloc a new amap and copy all the amap	 * data over from old amap to the new one.	 *	 * XXXCDC: could we take advantage of a kernel realloc()?	 */	amap_unlock(amap);	/* unlock in case we sleep in malloc */#ifdef UVM_AMAP_PPREF	newppref = NULL;	if (amap->am_ppref && amap->am_ppref != PPREF_NONE) {		newppref = malloc(slotneed * sizeof(int), M_UVMAMAP, M_NOWAIT);		if (newppref == NULL) {			/* give up if malloc fails */			free(amap->am_ppref, M_UVMAMAP);			amap->am_ppref = PPREF_NONE;		}	}#endif	newsl = malloc(slotneed * sizeof(int), M_UVMAMAP, M_WAITOK);	newbck = malloc(slotneed * sizeof(int), M_UVMAMAP, M_WAITOK);	newover = malloc(slotneed * sizeof(struct vm_anon *),	    M_UVMAMAP, M_WAITOK);	amap_lock(amap);			/* re-lock! */	KASSERT(amap->am_maxslot < slotneed);	/*	 * now copy everything over to new malloc'd areas...	 */	slotadded = slotneed - amap->am_nslot;	/* do am_slots */	oldsl = amap->am_slots;	memcpy(newsl, oldsl, sizeof(int) * amap->am_nused);	amap->am_slots = newsl;	/* do am_anon */	oldover = amap->am_anon;	memcpy(newover, oldover, sizeof(struct vm_anon *) * amap->am_nslot);	memset(newover + amap->am_nslot, 0, sizeof(struct vm_anon *) * slotadded);	amap->am_anon = newover;	/* do am_bckptr */	oldbck = amap->am_bckptr;	memcpy(newbck, oldbck, sizeof(int) * amap->am_nslot);	memset(newbck + amap->am_nslot, 0, sizeof(int) * slotadded); /* XXX: needed? */	amap->am_bckptr = newbck;#ifdef UVM_AMAP_PPREF	/* do ppref */	oldppref = amap->am_ppref;	if (newppref) {		memcpy(newppref, oldppref, sizeof(int) * amap->am_nslot);		memset(newppref + amap->am_nslot, 0, sizeof(int) * slotadded);		amap->am_ppref = newppref;		if ((slotoff + slotmapped) < amap->am_nslot)			amap_pp_adjref(amap, slotoff + slotmapped,			    (amap->am_nslot - (slotoff + slotmapped)), 1);		pp_setreflen(newppref, amap->am_nslot, 1, slotadded);	}#endif	/* update master values */	amap->am_nslot = slotneed;	amap->am_maxslot = slotneed;	/* unlock */	amap_unlock(amap);	/* and free */	free(oldsl, M_UVMAMAP);	free(oldbck, M_UVMAMAP);	free(oldover, M_UVMAMAP);#ifdef UVM_AMAP_PPREF	if (oldppref && oldppref != PPREF_NONE)		free(oldppref, M_UVMAMAP);#endif	UVMHIST_LOG(maphist,"<- done (case 3), amap = 0x%x, slotneed=%d",	    amap, slotneed, 0, 0);}