-#ifdef notdef
-
-/*
- * Routine: vm_fault_page_overwrite
- *
- * Description:
- * A form of vm_fault_page that assumes that the
- * resulting page will be overwritten in its entirety,
- * making it unnecessary to obtain the correct *contents*
- * of the page.
- *
- * Implementation:
- * XXX Untested. Also unused. Eventually, this technology
- * could be used in vm_fault_copy() to advantage.
- */
-vm_fault_return_t
-vm_fault_page_overwrite(
- register
- vm_object_t dst_object,
- vm_object_offset_t dst_offset,
- vm_page_t *result_page) /* OUT */
-{
- register
- vm_page_t dst_page;
- kern_return_t wait_result;
-
-#define interruptible THREAD_UNINT /* XXX */
-
- while (TRUE) {
- /*
- * Look for a page at this offset
- */
-
- while ((dst_page = vm_page_lookup(dst_object, dst_offset))
- == VM_PAGE_NULL) {
- /*
- * No page, no problem... just allocate one.
- */
-
- dst_page = vm_page_alloc(dst_object, dst_offset);
- if (dst_page == VM_PAGE_NULL) {
- vm_object_unlock(dst_object);
- VM_PAGE_WAIT();
- vm_object_lock(dst_object);
- continue;
- }
-
- /*
- * Pretend that the memory manager
- * write-protected the page.
- *
- * Note that we will be asking for write
- * permission without asking for the data
- * first.
- */
-
- dst_page->overwriting = TRUE;
- dst_page->page_lock = VM_PROT_WRITE;
- dst_page->absent = TRUE;
- dst_page->unusual = TRUE;
- dst_object->absent_count++;
-
- break;
-
- /*
- * When we bail out, we might have to throw
- * away the page created here.
- */
-
-#define DISCARD_PAGE \
- MACRO_BEGIN \
- vm_object_lock(dst_object); \
- dst_page = vm_page_lookup(dst_object, dst_offset); \
- if ((dst_page != VM_PAGE_NULL) && dst_page->overwriting) \
- VM_PAGE_FREE(dst_page); \
- vm_object_unlock(dst_object); \
- MACRO_END
- }
-
- /*
- * If the page is write-protected...
- */
-
- if (dst_page->page_lock & VM_PROT_WRITE) {
- /*
- * ... and an unlock request hasn't been sent
- */
-
- if ( ! (dst_page->unlock_request & VM_PROT_WRITE)) {
- vm_prot_t u;
- kern_return_t rc;
-
- /*
- * ... then send one now.
- */
-
- if (!dst_object->pager_ready) {
- wait_result = vm_object_assert_wait(dst_object,
- VM_OBJECT_EVENT_PAGER_READY,
- interruptible);
- vm_object_unlock(dst_object);
- if (wait_result == THREAD_WAITING)
- wait_result = thread_block(THREAD_CONTINUE_NULL);
- if (wait_result != THREAD_AWAKENED) {
- DISCARD_PAGE;
- return(VM_FAULT_INTERRUPTED);
- }
- continue;
- }
-
- u = dst_page->unlock_request |= VM_PROT_WRITE;
- vm_object_unlock(dst_object);
-
- if ((rc = memory_object_data_unlock(
- dst_object->pager,
- dst_offset + dst_object->paging_offset,
- PAGE_SIZE,
- u)) != KERN_SUCCESS) {
- if (vm_fault_debug)
- printf("vm_object_overwrite: memory_object_data_unlock failed\n");
- DISCARD_PAGE;
- return((rc == MACH_SEND_INTERRUPTED) ?
- VM_FAULT_INTERRUPTED :
- VM_FAULT_MEMORY_ERROR);
- }
- vm_object_lock(dst_object);
- continue;
- }
-
- /* ... fall through to wait below */
- } else {
- /*
- * If the page isn't being used for other
- * purposes, then we're done.
- */
- if ( ! (dst_page->busy || dst_page->absent ||
- dst_page->error || dst_page->restart) )
- break;
- }
-
- wait_result = PAGE_ASSERT_WAIT(dst_page, interruptible);
- vm_object_unlock(dst_object);
- if (wait_result == THREAD_WAITING)
- wait_result = thread_block(THREAD_CONTINUE_NULL);
- if (wait_result != THREAD_AWAKENED) {
- DISCARD_PAGE;
- return(VM_FAULT_INTERRUPTED);
- }
- }
-
- *result_page = dst_page;
- return(VM_FAULT_SUCCESS);
-
-#undef interruptible
-#undef DISCARD_PAGE
-}
-
-#endif /* notdef */
-