FreeBSD/sys/i386/i386/pmap.c
/*
 * pmap_protect_pde: do the things to protect a 4mpage in a process
 */
do the things to protect a 4mpage in a process
do the things to protect a 4mpage in a process
static boolean_t
pmap_protect_pde(pmap_t pmap, pd_entry_t *pde, vm_offset_t sva, vm_prot_t prot)
{
	pd_entry_t newpde, oldpde;
	vm_offset_t eva, va;
	vm_page_t m;
	boolean_t anychanged;
	PMAP_LOCK_ASSERT(pmap, MA_OWNED);
	KASSERT((sva & PDRMASK) == 0,
	    ("pmap_protect_pde: sva is not 4mpage aligned"));
	anychanged = FALSE;
retry:
	oldpde = newpde = *pde;
	if (oldpde & PG_MANAGED) {
		eva = sva + NBPDR;
		for (va = sva, m = PHYS_TO_VM_PAGE(oldpde & PG_PS_FRAME);
		    va < eva; va += PAGE_SIZE, m++)
			if ((oldpde & (PG_M | PG_RW)) == (PG_M | PG_RW))
				vm_page_dirty(m);
	}
	if ((prot & VM_PROT_WRITE) == 0)
		newpde &= ~(PG_RW | PG_M);
#if defined(PAE) || defined(PAE_TABLES)
	if ((prot & VM_PROT_EXECUTE) == 0)
		newpde |= pg_nx;
#endif
	if (newpde != oldpde) {
		if (!pde_cmpset(pde, oldpde, newpde))
			goto retry;
		if (oldpde & PG_G)
			pmap_invalidate_page(pmap, sva);
		else
			anychanged = TRUE;
	}
	return (anychanged);
}
static boolean_t pmap_protect_pde ( pmap_t pmap , pd_entry_t * pde , vm_offset_t sva , vm_prot_t prot ) { pd_entry_t newpde , oldpde ; vm_offset_t eva , va ; vm_page_t m ; boolean_t anychanged ; PMAP_LOCK_ASSERT ( pmap , MA_OWNED ) ; KASSERT ( ( sva & PDRMASK ) == 0 , ( " " ) ) ; anychanged = FALSE ; retry : oldpde = newpde = * pde ; if ( oldpde & PG_MANAGED ) { eva = sva + NBPDR ; for ( va = sva , m = PHYS_TO_VM_PAGE ( oldpde & PG_PS_FRAME ) ; va < eva ; va += PAGE_SIZE , m ++ ) if ( ( oldpde & ( PG_M | PG_RW ) ) == ( PG_M | PG_RW ) ) vm_page_dirty ( m ) ; } if ( ( prot & VM_PROT_WRITE ) == 0 ) newpde &= ~ ( PG_RW | PG_M ) ; #if defined ( PAE ) || defined ( PAE_TABLES ) if ( ( prot & VM_PROT_EXECUTE ) == 0 ) newpde |= pg_nx ; #endif if ( newpde != oldpde ) { if ( ! pde_cmpset ( pde , oldpde , newpde ) ) goto retry ; if ( oldpde & PG_G ) pmap_invalidate_page ( pmap , sva ) ; else anychanged = TRUE ; } return ( anychanged ) ; }
pmap_protect_pde: do the things to protect a 4mpage in a process
pmap_protect_pde : do the things to protect a 4mpage in a process