if (flags & PMAP_CANFAIL)
if (flags & PMAP_CANFAIL) { simple_unlock(&pmap->pm_obj.vmobjlock);
pmap_enter(pmap, va, pa, prot, flags)	struct pmap *pmap;	vaddr_t va;	paddr_t pa;	vm_prot_t prot;	int flags;{	volatile pt_entry_t *pde;	pt_entry_t pte;	struct vm_page *pg, *ptp = NULL;	struct pv_entry *pve;	boolean_t wired = (flags & PMAP_WIRED) != 0;	DPRINTF(PDB_FOLLOW|PDB_ENTER,	    ("pmap_enter(%p, 0x%x, 0x%x, 0x%x, 0x%x)\n",	    pmap, va, pa, prot, flags));	simple_lock(&pmap->pm_obj.vmobjlock);	if (!(pde = pmap_pde_get(pmap->pm_pdir, va)) &&	    !(pde = pmap_pde_alloc(pmap, va, &ptp))) {		if (flags & PMAP_CANFAIL)			return (KERN_RESOURCE_SHORTAGE);		panic("pmap_enter: cannot allocate pde");	}	if (!ptp)		ptp = pmap_pde_ptp(pmap, pde);	if ((pte = pmap_pte_get(pde, va))) {		DPRINTF(PDB_ENTER,		    ("pmap_enter: remapping 0x%x -> 0x%x\n", pte, pa));		pmap_pte_flush(pmap, va, pte);		if (wired && !(pte & PTE_PROT(TLB_WIRED)))			pmap->pm_stats.wired_count++;		else if (!wired && (pte & PTE_PROT(TLB_WIRED)))			pmap->pm_stats.wired_count--;		if (PTE_PAGE(pte) == pa) {			DPRINTF(PDB_FOLLOW|PDB_ENTER,			    ("pmap_enter: same page\n"));			goto enter;		}		pg = PHYS_TO_VM_PAGE(PTE_PAGE(pte));		simple_lock(&pg->mdpage.pvh_lock);		pve = pmap_pv_remove(pg, pmap, va);		pg->mdpage.pvh_attrs |= pmap_pvh_attrs(pte);	} else {		DPRINTF(PDB_ENTER,		    ("pmap_enter: new mapping 0x%x -> 0x%x\n", va, pa));		pte = PTE_PROT(TLB_REFTRAP);		pve = NULL;		pmap->pm_stats.resident_count++;		if (wired)			pmap->pm_stats.wired_count++;		if (ptp)			ptp->wire_count++;	}	if (pmap_initialized && (pg = PHYS_TO_VM_PAGE(PTE_PAGE(pa)))) {		if (!pve && !(pve = pmap_pv_alloc())) {			if (flags & PMAP_CANFAIL) {				simple_unlock(&pmap->pm_obj.vmobjlock);				return (KERN_RESOURCE_SHORTAGE);			}			panic("pmap_enter: no pv entries available");		}		pmap_pv_enter(pg, pve, pmap, va, ptp);	} else if (pve)		pmap_pv_free(pve);enter:	/* preserve old ref & mod */	pte = pa | PTE_PROT(pmap_prot(pmap, prot)) |	    (pte & PTE_PROT(TLB_UNCACHABLE|TLB_DIRTY|TLB_REFTRAP));	if (wired)		pte |= PTE_PROT(TLB_WIRED);	pmap_pte_set(pde, va, pte);	simple_unlock(&pmap->pm_obj.vmobjlock);	DPRINTF(PDB_FOLLOW|PDB_ENTER, ("pmap_enter: leaving\n"));	return (0);}