]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/pmap_common.c
xnu-2422.115.4.tar.gz
[apple/xnu.git] / osfmk / i386 / pmap_common.c
index d81248dae7cbef4921a1beef11f91d5e43e9c817..4bf41195e1cccb8a6cc76d8f4c8ee2c07d931b1c 100644 (file)
  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 #include <vm/pmap.h>
+#include <kern/ledger.h>
 #include <i386/pmap_internal.h>
 
+
 /*
  *     Each entry in the pv_head_table is locked by a bit in the
  *     pv_lock_table.  The lock bits are accessed by the physical
@@ -137,7 +139,7 @@ pmap_is_noencrypt(ppnum_t pn)
        pai = ppn_to_pai(pn);
 
        if (!IS_MANAGED_PAGE(pai))
-               return (TRUE);
+               return (FALSE);
 
        if (pmap_phys_attributes[pai] & PHYS_NOENCRYPT)
                return (TRUE);
@@ -171,11 +173,17 @@ pmap_clear_noencrypt(ppnum_t pn)
        pai = ppn_to_pai(pn);
 
        if (IS_MANAGED_PAGE(pai)) {
-               LOCK_PVH(pai);
+               /*
+                * synchronization at VM layer prevents PHYS_NOENCRYPT
+                * from changing state, so we don't need the lock to inspect
+                */
+               if (pmap_phys_attributes[pai] & PHYS_NOENCRYPT) {
+                       LOCK_PVH(pai);
 
-               pmap_phys_attributes[pai] &= ~PHYS_NOENCRYPT;
+                       pmap_phys_attributes[pai] &= ~PHYS_NOENCRYPT;
 
-               UNLOCK_PVH(pai);
+                       UNLOCK_PVH(pai);
+               }
        }
 }
 
@@ -386,7 +394,7 @@ pmap_set_modify(ppnum_t pn)
 void
 pmap_clear_modify(ppnum_t pn)
 {
-       phys_attribute_clear(pn, PHYS_MODIFIED);
+       phys_attribute_clear(pn, PHYS_MODIFIED, 0, NULL);
 }
 
 /*
@@ -414,7 +422,7 @@ pmap_is_modified(ppnum_t pn)
 void
 pmap_clear_reference(ppnum_t pn)
 {
-       phys_attribute_clear(pn, PHYS_REFERENCED);
+       phys_attribute_clear(pn, PHYS_REFERENCED, 0, NULL);
 }
 
 void
@@ -460,6 +468,18 @@ pmap_get_refmod(ppnum_t pn)
        return (retval);
 }
 
+
+void
+pmap_clear_refmod_options(ppnum_t pn, unsigned int mask, unsigned int options, void *arg)
+{
+        unsigned int  x86Mask;
+
+        x86Mask = (   ((mask &   VM_MEM_MODIFIED)?   PHYS_MODIFIED : 0)
+                     | ((mask & VM_MEM_REFERENCED)? PHYS_REFERENCED : 0));
+
+        phys_attribute_clear(pn, x86Mask, options, arg);
+}
+
 /*
  * pmap_clear_refmod(phys, mask)
  *  clears the referenced and modified bits as specified by the mask
@@ -472,12 +492,19 @@ pmap_clear_refmod(ppnum_t pn, unsigned int mask)
 
        x86Mask = (   ((mask &   VM_MEM_MODIFIED)?   PHYS_MODIFIED : 0)
                    | ((mask & VM_MEM_REFERENCED)? PHYS_REFERENCED : 0));
-       phys_attribute_clear(pn, x86Mask);
+
+       phys_attribute_clear(pn, x86Mask, 0, NULL);
+}
+
+unsigned int
+pmap_disconnect(ppnum_t pa)
+{
+       return (pmap_disconnect_options(pa, 0, NULL));
 }
 
 /*
  *     Routine:
- *             pmap_disconnect
+ *             pmap_disconnect_options
  *
  *     Function:
  *             Disconnect all mappings for this page and return reference and change status
@@ -485,14 +512,14 @@ pmap_clear_refmod(ppnum_t pn, unsigned int mask)
  *
  */
 unsigned int
-pmap_disconnect(ppnum_t pa)
+pmap_disconnect_options(ppnum_t pa, unsigned int options, void *arg)
 {
        unsigned refmod, vmrefmod = 0;
 
-       pmap_page_protect(pa, 0);               /* disconnect the page */
+       pmap_page_protect_options(pa, 0, options, arg);         /* disconnect the page */
 
        pmap_assert(pa != vm_page_fictitious_addr);
-       if ((pa == vm_page_guard_addr) || !IS_MANAGED_PAGE(pa))
+       if ((pa == vm_page_guard_addr) || !IS_MANAGED_PAGE(pa) || (options & PMAP_OPTIONS_NOREFMOD))
                return 0;
        refmod = pmap_phys_attributes[pa] & (PHYS_MODIFIED | PHYS_REFERENCED);