+/*
+ * IMPORTANT:
+ * The "alias" field can be updated while holding the VM map lock
+ * "shared". It's OK as along as it's the only field that can be
+ * updated without the VM map "exclusive" lock.
+ */
+#define VME_OBJECT(entry) ((entry)->vme_object.vmo_object)
+#define VME_OBJECT_SET(entry, object) \
+ MACRO_BEGIN \
+ (entry)->vme_object.vmo_object = (object); \
+ MACRO_END
+#define VME_SUBMAP(entry) ((entry)->vme_object.vmo_submap)
+#define VME_SUBMAP_SET(entry, submap) \
+ MACRO_BEGIN \
+ (entry)->vme_object.vmo_submap = (submap); \
+ MACRO_END
+#define VME_OFFSET(entry) ((entry)->vme_offset & ~PAGE_MASK)
+#define VME_OFFSET_SET(entry, offset) \
+ MACRO_BEGIN \
+ int __alias; \
+ __alias = VME_ALIAS((entry)); \
+ assert((offset & PAGE_MASK) == 0); \
+ (entry)->vme_offset = offset | __alias; \
+ MACRO_END
+#define VME_OBJECT_SHADOW(entry, length) \
+ MACRO_BEGIN \
+ vm_object_t __object; \
+ vm_object_offset_t __offset; \
+ __object = VME_OBJECT((entry)); \
+ __offset = VME_OFFSET((entry)); \
+ vm_object_shadow(&__object, &__offset, (length)); \
+ if (__object != VME_OBJECT((entry))) { \
+ VME_OBJECT_SET((entry), __object); \
+ (entry)->use_pmap = TRUE; \
+ } \
+ if (__offset != VME_OFFSET((entry))) { \
+ VME_OFFSET_SET((entry), __offset); \
+ } \
+ MACRO_END
+
+#define VME_ALIAS_MASK (PAGE_MASK)
+#define VME_ALIAS(entry) ((unsigned int)((entry)->vme_offset & VME_ALIAS_MASK))
+#define VME_ALIAS_SET(entry, alias) \
+ MACRO_BEGIN \
+ vm_map_offset_t __offset; \
+ __offset = VME_OFFSET((entry)); \
+ (entry)->vme_offset = __offset | ((alias) & VME_ALIAS_MASK); \
+ MACRO_END
+
+/*
+ * FOOTPRINT ACCOUNTING:
+ * The "memory footprint" is better described in the pmap layer.
+ *
+ * At the VM level, these 2 vm_map_entry_t fields are relevant:
+ * iokit_mapped:
+ * For an "iokit_mapped" entry, we add the size of the entry to the
+ * footprint when the entry is entered into the map and we subtract that
+ * size when the entry is removed. No other accounting should take place.
+ * "use_pmap" should be FALSE but is not taken into account.
+ * use_pmap: (only when is_sub_map is FALSE)
+ * This indicates if we should ask the pmap layer to account for pages
+ * in this mapping. If FALSE, we expect that another form of accounting
+ * is being used (e.g. "iokit_mapped" or the explicit accounting of
+ * non-volatile purgable memory).
+ *
+ * So the logic is mostly:
+ * if entry->is_sub_map == TRUE
+ * anything in a submap does not count for the footprint
+ * else if entry->iokit_mapped == TRUE
+ * footprint includes the entire virtual size of this entry
+ * else if entry->use_pmap == FALSE
+ * tell pmap NOT to account for pages being pmap_enter()'d from this
+ * mapping (i.e. use "alternate accounting")
+ * else
+ * pmap will account for pages being pmap_enter()'d from this mapping
+ * as it sees fit (only if anonymous, etc...)
+ */
+