]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/vm/vm_map_store.c
xnu-4570.20.62.tar.gz
[apple/xnu.git] / osfmk / vm / vm_map_store.c
index 58148a96475935f257adedf52987277bc8f8a399..26b3477a4671e079a9b6a5d828ee298d0096fefe 100644 (file)
  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 
+#include <kern/backtrace.h>
+#include <mach/sdt.h>
 #include <vm/vm_map_store.h>
+#include <vm/vm_pageout.h> /* for vm_debug_events */
 
 #if MACH_ASSERT
 boolean_t
@@ -36,25 +39,41 @@ first_free_is_valid_store( vm_map_t map )
 }
 #endif
 
+boolean_t
+vm_map_store_has_RB_support( struct vm_map_header *hdr )
+{
+       if ((void*)hdr->rb_head_store.rbh_root == (void*)(int)SKIP_RB_TREE) {
+               return FALSE;
+       }
+       return TRUE;
+}
+
 void
 vm_map_store_init( struct vm_map_header *hdr )
 {
        vm_map_store_init_ll( hdr );
 #ifdef VM_MAP_STORE_USE_RB
-       vm_map_store_init_rb( hdr );
+       if (vm_map_store_has_RB_support( hdr )) {
+               vm_map_store_init_rb( hdr );
+       }
 #endif
 }
 
 boolean_t
 vm_map_store_lookup_entry(
-       register vm_map_t               map,
-       register vm_map_offset_t        address,
+       vm_map_t                map,
+       vm_map_offset_t         address,
        vm_map_entry_t          *entry)         /* OUT */
 {
 #ifdef VM_MAP_STORE_USE_LL
        return (vm_map_store_lookup_entry_ll( map, address, entry ));
 #elif defined VM_MAP_STORE_USE_RB
-       return (vm_map_store_lookup_entry_rb( map, address, entry ));
+       if (vm_map_store_has_RB_support( &map->hdr )) {
+               return (vm_map_store_lookup_entry_rb( map, address, entry ));
+       } else {
+               panic("VM map lookups need RB tree support.\n");
+               return FALSE; /* For compiler warning.*/
+       }
 #endif
 }
 
@@ -65,7 +84,7 @@ vm_map_store_update( vm_map_t map, vm_map_entry_t entry, int update_type )
                case VM_MAP_ENTRY_CREATE:
                        break;
                case VM_MAP_ENTRY_DELETE:
-                       if((entry) == (map)->first_free) {
+                       if((map->holelistenabled == FALSE) && ((entry) == (map)->first_free)) {
                                (map)->first_free = vm_map_to_entry(map);
                        }
                        if((entry) == (map)->hint) {
@@ -79,9 +98,28 @@ vm_map_store_update( vm_map_t map, vm_map_entry_t entry, int update_type )
 
 void   vm_map_store_copy_insert( vm_map_t map, vm_map_entry_t after_where, vm_map_copy_t copy)
 {
+       if (__improbable(vm_debug_events)) {
+               vm_map_entry_t entry;
+               for (entry = vm_map_copy_first_entry(copy); entry != vm_map_copy_to_entry(copy); entry = entry->vme_next) {
+                       DTRACE_VM4(map_entry_link_copy, vm_map_t, map, vm_map_entry_t, entry, vm_address_t, entry->links.start, vm_address_t, entry->links.end);
+               }
+       }
+
+       if (map->holelistenabled) {
+               vm_map_entry_t entry = NULL;
+
+               entry = vm_map_copy_first_entry(copy);
+               while (entry != vm_map_copy_to_entry(copy)) {
+                       vm_map_store_update_first_free(map, entry, TRUE);
+                       entry = entry->vme_next;
+               }
+       }
+
        vm_map_store_copy_insert_ll(map, after_where, copy);
 #ifdef VM_MAP_STORE_USE_RB
-       vm_map_store_copy_insert_rb(map, after_where, copy);
+       if (vm_map_store_has_RB_support( &map->hdr )) {
+               vm_map_store_copy_insert_rb(map, after_where, copy);
+       }
 #endif
 }
 
@@ -101,9 +139,19 @@ void       vm_map_store_copy_insert( vm_map_t map, vm_map_entry_t after_where, vm_map_
 void
 _vm_map_store_entry_link( struct vm_map_header * mapHdr, vm_map_entry_t after_where, vm_map_entry_t entry)
 {
+       assert(entry->vme_start < entry->vme_end);
+       if (__improbable(vm_debug_events))
+               DTRACE_VM4(map_entry_link, vm_map_t, (char *)mapHdr - sizeof (lck_rw_t), vm_map_entry_t, entry, vm_address_t, entry->links.start, vm_address_t, entry->links.end);
+
        vm_map_store_entry_link_ll(mapHdr, after_where, entry);
 #ifdef VM_MAP_STORE_USE_RB
-       vm_map_store_entry_link_rb(mapHdr, after_where, entry);
+       if (vm_map_store_has_RB_support( mapHdr )) {
+               vm_map_store_entry_link_rb(mapHdr, after_where, entry);
+       }
+#endif
+#if MAP_ENTRY_INSERTION_DEBUG
+       backtrace(&entry->vme_insertion_bt[0],
+                 (sizeof (entry->vme_insertion_bt) / sizeof (uintptr_t)));
 #endif
 }
 
@@ -121,7 +169,9 @@ vm_map_store_entry_link( vm_map_t map, vm_map_entry_t after_where, vm_map_entry_
        } else {
                update_first_free_ll(VMEL_map, VMEL_map->first_free);
 #ifdef VM_MAP_STORE_USE_RB
-               update_first_free_rb(VMEL_map, VMEL_map->first_free);
+               if (vm_map_store_has_RB_support( &VMEL_map->hdr )) {
+                       update_first_free_rb(VMEL_map, entry, TRUE);
+               }
 #endif
        }
 }
@@ -129,9 +179,14 @@ vm_map_store_entry_link( vm_map_t map, vm_map_entry_t after_where, vm_map_entry_
 void
 _vm_map_store_entry_unlink( struct vm_map_header * mapHdr, vm_map_entry_t entry)
 {
+       if (__improbable(vm_debug_events))
+               DTRACE_VM4(map_entry_unlink, vm_map_t, (char *)mapHdr - sizeof (lck_rw_t), vm_map_entry_t, entry, vm_address_t, entry->links.start, vm_address_t, entry->links.end);
+
        vm_map_store_entry_unlink_ll(mapHdr, entry);
 #ifdef VM_MAP_STORE_USE_RB
-       vm_map_store_entry_unlink_rb(mapHdr, entry);
+       if (vm_map_store_has_RB_support( mapHdr )) {
+               vm_map_store_entry_unlink_rb(mapHdr, entry);
+       }
 #endif
 }
 
@@ -139,20 +194,25 @@ void
 vm_map_store_entry_unlink( vm_map_t map, vm_map_entry_t entry)
 {
        vm_map_t VMEU_map;
-       vm_map_entry_t VMEU_entry;
-       vm_map_entry_t VMEU_first_free;
+       vm_map_entry_t VMEU_entry = NULL;
+       vm_map_entry_t VMEU_first_free = NULL;
        VMEU_map = (map);
        VMEU_entry = (entry);
-       if (VMEU_entry->vme_start <= VMEU_map->first_free->vme_start){
-               VMEU_first_free = VMEU_entry->vme_prev;         
-       } else  {
-               VMEU_first_free = VMEU_map->first_free;
+
+       if (map->holelistenabled == FALSE) {
+               if (VMEU_entry->vme_start <= VMEU_map->first_free->vme_start){
+                       VMEU_first_free = VMEU_entry->vme_prev;
+               } else  {
+                       VMEU_first_free = VMEU_map->first_free;
+               }
        }
-       
        _vm_map_store_entry_unlink(&VMEU_map->hdr, VMEU_entry);
+       vm_map_store_update( map, entry, VM_MAP_ENTRY_DELETE);
        update_first_free_ll(VMEU_map, VMEU_first_free);
 #ifdef VM_MAP_STORE_USE_RB
-       update_first_free_rb(VMEU_map, VMEU_first_free);
+       if (vm_map_store_has_RB_support( &VMEU_map->hdr )) {
+               update_first_free_rb(VMEU_map, entry, FALSE);
+       }
 #endif
 }
 
@@ -162,15 +222,19 @@ vm_map_store_copy_reset( vm_map_copy_t copy,vm_map_entry_t entry)
        int nentries = copy->cpy_hdr.nentries;
        vm_map_store_copy_reset_ll(copy, entry, nentries);
 #ifdef VM_MAP_STORE_USE_RB
-       vm_map_store_copy_reset_rb(copy, entry, nentries);
+       if (vm_map_store_has_RB_support( &copy->c_u.hdr )) {
+               vm_map_store_copy_reset_rb(copy, entry, nentries);
+       }
 #endif
 }
 
 void
-vm_map_store_update_first_free( vm_map_t map, vm_map_entry_t first_free)
+vm_map_store_update_first_free( vm_map_t map, vm_map_entry_t first_free_entry, boolean_t new_entry_creation)
 {
-       update_first_free_ll(map, first_free);
+       update_first_free_ll(map, first_free_entry);
 #ifdef VM_MAP_STORE_USE_RB
-       update_first_free_rb(map, first_free);
+       if (vm_map_store_has_RB_support( &map->hdr )) {
+               update_first_free_rb(map, first_free_entry, new_entry_creation);
+       }
 #endif
 }