-void
-vm_object_pager_create(
- register vm_object_t object)
-{
- memory_object_t pager;
- vm_object_hash_entry_t entry;
- lck_mtx_t *lck;
-#if MACH_PAGEMAP
- vm_object_size_t size;
- vm_external_map_t map;
-#endif /* MACH_PAGEMAP */
-
- XPR(XPR_VM_OBJECT, "vm_object_pager_create, object 0x%X\n",
- object, 0,0,0,0);
-
- assert(object != kernel_object);
-
- if (memory_manager_default_check() != KERN_SUCCESS)
- return;
-
- /*
- * Prevent collapse or termination by holding a paging reference
- */
-
- vm_object_paging_begin(object);
- if (object->pager_created) {
- /*
- * Someone else got to it first...
- * wait for them to finish initializing the ports
- */
- while (!object->pager_initialized) {
- vm_object_sleep(object,
- VM_OBJECT_EVENT_INITIALIZED,
- THREAD_UNINT);
- }
- vm_object_paging_end(object);
- return;
- }
-
- /*
- * Indicate that a memory object has been assigned
- * before dropping the lock, to prevent a race.
- */
-
- object->pager_created = TRUE;
- object->paging_offset = 0;
-
-#if MACH_PAGEMAP
- size = object->vo_size;
-#endif /* MACH_PAGEMAP */
- vm_object_unlock(object);
-
-#if MACH_PAGEMAP
- if (DEFAULT_PAGER_IS_ACTIVE) {
- map = vm_external_create(size);
- vm_object_lock(object);
- assert(object->vo_size == size);
- object->existence_map = map;
- vm_object_unlock(object);
- }
-#endif /* MACH_PAGEMAP */
-
- if ((uint32_t) object->vo_size != object->vo_size) {
- panic("vm_object_pager_create(): object size 0x%llx >= 4GB\n",
- (uint64_t) object->vo_size);
- }
-
- /*
- * Create the [internal] pager, and associate it with this object.
- *
- * We make the association here so that vm_object_enter()
- * can look up the object to complete initializing it. No
- * user will ever map this object.
- */
- {
- memory_object_default_t dmm;
-
- /* acquire a reference for the default memory manager */
- dmm = memory_manager_default_reference();
-
- assert(object->temporary);
-
- /* create our new memory object */
- assert((vm_size_t) object->vo_size == object->vo_size);
- (void) memory_object_create(dmm, (vm_size_t) object->vo_size,
- &pager);
-
- memory_object_default_deallocate(dmm);
- }
-
- entry = vm_object_hash_entry_alloc(pager);
-
- vm_object_lock(object);
- lck = vm_object_hash_lock_spin(pager);
- vm_object_hash_insert(entry, object);
- vm_object_hash_unlock(lck);
- vm_object_unlock(object);
-
- /*
- * A reference was returned by
- * memory_object_create(), and it is
- * copied by vm_object_enter().
- */
-
- if (vm_object_enter(pager, object->vo_size, TRUE, TRUE, FALSE) != object)
- panic("vm_object_pager_create: mismatch");
-
- /*
- * Drop the reference we were passed.
- */
- memory_object_deallocate(pager);
-
- vm_object_lock(object);
-
- /*
- * Release the paging reference
- */
- vm_object_paging_end(object);
-}
-