2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
53 * File: vm/memory_object.c
54 * Author: Michael Wayne Young
56 * External memory management interface control functions.
59 #include <advisory_pageout.h>
62 * Interface dependencies:
65 #include <mach/std_types.h> /* For pointer_t */
66 #include <mach/mach_types.h>
69 #include <mach/kern_return.h>
70 #include <mach/memory_object.h>
71 #include <mach/memory_object_default.h>
72 #include <mach/memory_object_control_server.h>
73 #include <mach/host_priv_server.h>
74 #include <mach/boolean.h>
75 #include <mach/vm_prot.h>
76 #include <mach/message.h>
79 * Implementation dependencies:
81 #include <string.h> /* For memcpy() */
84 #include <kern/host.h>
85 #include <kern/thread.h> /* For current_thread() */
86 #include <kern/ipc_mig.h>
87 #include <kern/misc_protos.h>
89 #include <vm/vm_object.h>
90 #include <vm/vm_fault.h>
91 #include <vm/memory_object.h>
92 #include <vm/vm_page.h>
93 #include <vm/vm_pageout.h>
94 #include <vm/pmap.h> /* For pmap_clear_modify */
95 #include <vm/vm_kern.h> /* For kernel_map, vm_move */
96 #include <vm/vm_map.h> /* For vm_map_pageable */
99 #include <vm/vm_external.h>
100 #endif /* MACH_PAGEMAP */
103 memory_object_default_t memory_manager_default
= MEMORY_OBJECT_DEFAULT_NULL
;
104 vm_size_t memory_manager_default_cluster
= 0;
105 decl_mutex_data(, memory_manager_default_lock
)
108 * Forward ref to file-local function:
111 vm_object_update(vm_object_t
, vm_object_offset_t
,
112 vm_size_t
, memory_object_return_t
, int, vm_prot_t
);
116 * Routine: memory_object_should_return_page
119 * Determine whether the given page should be returned,
120 * based on the page's state and on the given return policy.
122 * We should return the page if one of the following is true:
124 * 1. Page is dirty and should_return is not RETURN_NONE.
125 * 2. Page is precious and should_return is RETURN_ALL.
126 * 3. Should_return is RETURN_ANYTHING.
128 * As a side effect, m->dirty will be made consistent
129 * with pmap_is_modified(m), if should_return is not
130 * MEMORY_OBJECT_RETURN_NONE.
133 #define memory_object_should_return_page(m, should_return) \
134 (should_return != MEMORY_OBJECT_RETURN_NONE && \
135 (((m)->dirty || ((m)->dirty = pmap_is_modified((m)->phys_addr))) || \
136 ((m)->precious && (should_return) == MEMORY_OBJECT_RETURN_ALL) || \
137 (should_return) == MEMORY_OBJECT_RETURN_ANYTHING))
139 typedef int memory_object_lock_result_t
;
141 #define MEMORY_OBJECT_LOCK_RESULT_DONE 0
142 #define MEMORY_OBJECT_LOCK_RESULT_MUST_BLOCK 1
143 #define MEMORY_OBJECT_LOCK_RESULT_MUST_CLEAN 2
144 #define MEMORY_OBJECT_LOCK_RESULT_MUST_RETURN 3
146 memory_object_lock_result_t
memory_object_lock_page(
148 memory_object_return_t should_return
,
149 boolean_t should_flush
,
153 * Routine: memory_object_lock_page
156 * Perform the appropriate lock operations on the
157 * given page. See the description of
158 * "memory_object_lock_request" for the meanings
161 * Returns an indication that the operation
162 * completed, blocked, or that the page must
165 memory_object_lock_result_t
166 memory_object_lock_page(
168 memory_object_return_t should_return
,
169 boolean_t should_flush
,
172 XPR(XPR_MEMORY_OBJECT
,
173 "m_o_lock_page, page 0x%X rtn %d flush %d prot %d\n",
174 (integer_t
)m
, should_return
, should_flush
, prot
, 0);
177 * If we cannot change access to the page,
178 * either because a mapping is in progress
179 * (busy page) or because a mapping has been
180 * wired, then give up.
183 if (m
->busy
|| m
->cleaning
)
184 return(MEMORY_OBJECT_LOCK_RESULT_MUST_BLOCK
);
187 * Don't worry about pages for which the kernel
188 * does not have any data.
191 if (m
->absent
|| m
->error
|| m
->restart
) {
192 if(m
->error
&& should_flush
) {
193 /* dump the page, pager wants us to */
194 /* clean it up and there is no */
195 /* relevant data to return */
196 if(m
->wire_count
== 0) {
198 return(MEMORY_OBJECT_LOCK_RESULT_DONE
);
201 return(MEMORY_OBJECT_LOCK_RESULT_DONE
);
205 assert(!m
->fictitious
);
207 if (m
->wire_count
!= 0) {
209 * If no change would take place
210 * anyway, return successfully.
214 * No change to page lock [2 checks] AND
215 * Should not return page
217 * XXX This doesn't handle sending a copy of a wired
218 * XXX page to the pager, but that will require some
219 * XXX significant surgery.
222 (m
->page_lock
== prot
|| prot
== VM_PROT_NO_CHANGE
) &&
223 ! memory_object_should_return_page(m
, should_return
)) {
226 * Restart page unlock requests,
227 * even though no change took place.
228 * [Memory managers may be expecting
229 * to see new requests.]
231 m
->unlock_request
= VM_PROT_NONE
;
234 return(MEMORY_OBJECT_LOCK_RESULT_DONE
);
237 return(MEMORY_OBJECT_LOCK_RESULT_MUST_BLOCK
);
241 * If the page is to be flushed, allow
242 * that to be done as part of the protection.
251 * If we are decreasing permission, do it now;
252 * let the fault handler take care of increases
253 * (pmap_page_protect may not increase protection).
256 if (prot
!= VM_PROT_NO_CHANGE
) {
257 if ((m
->page_lock
^ prot
) & prot
) {
258 pmap_page_protect(m
->phys_addr
, VM_PROT_ALL
& ~prot
);
261 /* code associated with the vestigial
262 * memory_object_data_unlock
265 m
->lock_supplied
= TRUE
;
266 if (prot
!= VM_PROT_NONE
)
272 * Restart any past unlock requests, even if no
273 * change resulted. If the manager explicitly
274 * requested no protection change, then it is assumed
275 * to be remembering past requests.
278 m
->unlock_request
= VM_PROT_NONE
;
284 * Handle page returning.
287 if (memory_object_should_return_page(m
, should_return
)) {
290 * If we weren't planning
291 * to flush the page anyway,
292 * we may need to remove the
293 * page from the pageout
294 * system and from physical
298 vm_page_lock_queues();
299 VM_PAGE_QUEUES_REMOVE(m
);
300 vm_page_unlock_queues();
303 pmap_page_protect(m
->phys_addr
, VM_PROT_NONE
);
306 return(MEMORY_OBJECT_LOCK_RESULT_MUST_CLEAN
);
308 return(MEMORY_OBJECT_LOCK_RESULT_MUST_RETURN
);
318 extern boolean_t vm_page_deactivate_hint
;
321 * XXX Make clean but not flush a paging hint,
322 * and deactivate the pages. This is a hack
323 * because it overloads flush/clean with
324 * implementation-dependent meaning. This only
325 * happens to pages that are already clean.
328 if (vm_page_deactivate_hint
&&
329 (should_return
!= MEMORY_OBJECT_RETURN_NONE
)) {
330 vm_page_lock_queues();
331 vm_page_deactivate(m
);
332 vm_page_unlock_queues();
336 return(MEMORY_OBJECT_LOCK_RESULT_DONE
);
339 #define LIST_REQ_PAGEOUT_PAGES(object, data_cnt, action, po) \
343 register vm_page_t hp; \
345 vm_object_unlock(object); \
347 (void) memory_object_data_return(object->pager, \
350 (action == MEMORY_OBJECT_LOCK_RESULT_MUST_CLEAN), \
353 vm_object_lock(object); \
357 * Routine: memory_object_lock_request [user interface]
360 * Control use of the data associated with the given
361 * memory object. For each page in the given range,
362 * perform the following operations, in order:
363 * 1) restrict access to the page (disallow
364 * forms specified by "prot");
365 * 2) return data to the manager (if "should_return"
366 * is RETURN_DIRTY and the page is dirty, or
367 * "should_return" is RETURN_ALL and the page
368 * is either dirty or precious); and,
369 * 3) flush the cached copy (if "should_flush"
371 * The set of pages is defined by a starting offset
372 * ("offset") and size ("size"). Only pages with the
373 * same page alignment as the starting offset are
376 * A single acknowledgement is sent (to the "reply_to"
377 * port) when these actions are complete. If successful,
378 * the naked send right for reply_to is consumed.
382 memory_object_lock_request(
383 memory_object_control_t control
,
384 memory_object_offset_t offset
,
385 memory_object_size_t size
,
386 memory_object_return_t should_return
,
391 vm_object_offset_t original_offset
= offset
;
392 boolean_t should_flush
=flags
& MEMORY_OBJECT_DATA_FLUSH
;
394 XPR(XPR_MEMORY_OBJECT
,
395 "m_o_lock_request, control 0x%X off 0x%X size 0x%X flags %X prot %X\n",
396 (integer_t
)control
, offset
, size
,
397 (((should_return
&1)<<1)|should_flush
), prot
);
400 * Check for bogus arguments.
402 object
= memory_object_control_to_vm_object(control
);
403 if (object
== VM_OBJECT_NULL
)
404 return (KERN_INVALID_ARGUMENT
);
406 if ((prot
& ~VM_PROT_ALL
) != 0 && prot
!= VM_PROT_NO_CHANGE
)
407 return (KERN_INVALID_ARGUMENT
);
409 size
= round_page(size
);
412 * Lock the object, and acquire a paging reference to
413 * prevent the memory_object reference from being released.
415 vm_object_lock(object
);
416 vm_object_paging_begin(object
);
417 offset
-= object
->paging_offset
;
419 (void)vm_object_update(object
,
420 offset
, size
, should_return
, flags
, prot
);
422 vm_object_paging_end(object
);
423 vm_object_unlock(object
);
425 return (KERN_SUCCESS
);
429 * memory_object_release_name: [interface]
431 * Enforces name semantic on memory_object reference count decrement
432 * This routine should not be called unless the caller holds a name
433 * reference gained through the memory_object_named_create or the
434 * memory_object_rename call.
435 * If the TERMINATE_IDLE flag is set, the call will return if the
436 * reference count is not 1. i.e. idle with the only remaining reference
438 * If the decision is made to proceed the name field flag is set to
439 * false and the reference count is decremented. If the RESPECT_CACHE
440 * flag is set and the reference count has gone to zero, the
441 * memory_object is checked to see if it is cacheable otherwise when
442 * the reference count is zero, it is simply terminated.
446 memory_object_release_name(
447 memory_object_control_t control
,
452 object
= memory_object_control_to_vm_object(control
);
453 if (object
== VM_OBJECT_NULL
)
454 return (KERN_INVALID_ARGUMENT
);
456 return vm_object_release_name(object
, flags
);
462 * Routine: memory_object_destroy [user interface]
464 * Shut down a memory object, despite the
465 * presence of address map (or other) references
469 memory_object_destroy(
470 memory_object_control_t control
,
471 kern_return_t reason
)
475 object
= memory_object_control_to_vm_object(control
);
476 if (object
== VM_OBJECT_NULL
)
477 return (KERN_INVALID_ARGUMENT
);
479 return (vm_object_destroy(object
, reason
));
483 * Routine: vm_object_sync
485 * Kernel internal function to synch out pages in a given
486 * range within an object to its memory manager. Much the
487 * same as memory_object_lock_request but page protection
490 * If the should_flush and should_return flags are true pages
491 * are flushed, that is dirty & precious pages are written to
492 * the memory manager and then discarded. If should_return
493 * is false, only precious pages are returned to the memory
496 * If should flush is false and should_return true, the memory
497 * manager's copy of the pages is updated. If should_return
498 * is also false, only the precious pages are updated. This
499 * last option is of limited utility.
502 * FALSE if no pages were returned to the pager
509 vm_object_offset_t offset
,
511 boolean_t should_flush
,
512 boolean_t should_return
)
517 "vm_o_sync, object 0x%X, offset 0x%X size 0x%x flush %d rtn %d\n",
518 (integer_t
)object
, offset
, size
, should_flush
, should_return
);
521 * Lock the object, and acquire a paging reference to
522 * prevent the memory_object and control ports from
525 vm_object_lock(object
);
526 vm_object_paging_begin(object
);
528 rv
= vm_object_update(object
, offset
, size
,
530 MEMORY_OBJECT_RETURN_ALL
:
531 MEMORY_OBJECT_RETURN_NONE
,
533 MEMORY_OBJECT_DATA_FLUSH
: 0,
537 vm_object_paging_end(object
);
538 vm_object_unlock(object
);
543 * Routine: vm_object_update
545 * Work function for m_o_lock_request(), vm_o_sync().
547 * Called with object locked and paging ref taken.
551 register vm_object_t object
,
552 register vm_object_offset_t offset
,
553 register vm_size_t size
,
554 memory_object_return_t should_return
,
558 register vm_page_t m
;
559 vm_page_t holding_page
;
560 vm_size_t original_size
= size
;
561 vm_object_offset_t paging_offset
= 0;
562 vm_object_t copy_object
;
563 vm_size_t data_cnt
= 0;
564 vm_object_offset_t last_offset
= offset
;
565 memory_object_lock_result_t page_lock_result
;
566 memory_object_lock_result_t pageout_action
;
567 boolean_t data_returned
= FALSE
;
568 boolean_t update_cow
;
569 boolean_t should_flush
= flags
& MEMORY_OBJECT_DATA_FLUSH
;
570 boolean_t pending_pageout
= FALSE
;
573 * To avoid blocking while scanning for pages, save
574 * dirty pages to be cleaned all at once.
576 * XXXO A similar strategy could be used to limit the
577 * number of times that a scan must be restarted for
578 * other reasons. Those pages that would require blocking
579 * could be temporarily collected in another list, or
580 * their offsets could be recorded in a small array.
584 * XXX NOTE: May want to consider converting this to a page list
585 * XXX vm_map_copy interface. Need to understand object
586 * XXX coalescing implications before doing so.
589 update_cow
= ((flags
& MEMORY_OBJECT_DATA_FLUSH
)
590 && (!(flags
& MEMORY_OBJECT_DATA_NO_CHANGE
) &&
591 !(flags
& MEMORY_OBJECT_DATA_PURGE
)))
592 || (flags
& MEMORY_OBJECT_COPY_SYNC
);
595 if((((copy_object
= object
->copy
) != NULL
) && update_cow
) ||
596 (flags
& MEMORY_OBJECT_DATA_SYNC
)) {
599 vm_object_offset_t copy_offset
;
603 kern_return_t error
= 0;
605 if(copy_object
!= NULL
) {
606 /* translate offset with respect to shadow's offset */
607 copy_offset
= (offset
>= copy_object
->shadow_offset
)?
608 offset
- copy_object
->shadow_offset
:
609 (vm_object_offset_t
) 0;
610 if(copy_offset
> copy_object
->size
)
611 copy_offset
= copy_object
->size
;
613 /* clip size with respect to shadow offset */
614 copy_size
= (offset
>= copy_object
->shadow_offset
) ?
615 size
: size
- (copy_object
->shadow_offset
- offset
);
620 copy_size
= ((copy_offset
+ copy_size
)
621 <= copy_object
->size
) ?
622 copy_size
: copy_object
->size
- copy_offset
;
624 /* check for a copy_offset which is beyond the end of */
625 /* the copy_object */
631 vm_object_unlock(object
);
632 vm_object_lock(copy_object
);
634 copy_object
= object
;
636 copy_size
= offset
+ size
;
637 copy_offset
= offset
;
640 vm_object_paging_begin(copy_object
);
641 for (i
=copy_offset
; i
<copy_size
; i
+=PAGE_SIZE
) {
642 RETRY_COW_OF_LOCK_REQUEST
:
643 prot
= VM_PROT_WRITE
|VM_PROT_READ
;
644 switch (vm_fault_page(copy_object
, i
,
645 VM_PROT_WRITE
|VM_PROT_READ
,
649 copy_offset
+copy_size
,
650 VM_BEHAVIOR_SEQUENTIAL
,
659 case VM_FAULT_SUCCESS
:
662 page
->object
, top_page
);
663 PAGE_WAKEUP_DONE(page
);
664 vm_page_lock_queues();
665 if (!page
->active
&& !page
->inactive
)
666 vm_page_activate(page
);
667 vm_page_unlock_queues();
668 vm_object_lock(copy_object
);
669 vm_object_paging_begin(copy_object
);
671 PAGE_WAKEUP_DONE(page
);
672 vm_page_lock_queues();
673 if (!page
->active
&& !page
->inactive
)
674 vm_page_activate(page
);
675 vm_page_unlock_queues();
679 prot
= VM_PROT_WRITE
|VM_PROT_READ
;
680 vm_object_lock(copy_object
);
681 vm_object_paging_begin(copy_object
);
682 goto RETRY_COW_OF_LOCK_REQUEST
;
683 case VM_FAULT_INTERRUPTED
:
684 prot
= VM_PROT_WRITE
|VM_PROT_READ
;
685 vm_object_lock(copy_object
);
686 vm_object_paging_begin(copy_object
);
687 goto RETRY_COW_OF_LOCK_REQUEST
;
688 case VM_FAULT_MEMORY_SHORTAGE
:
690 prot
= VM_PROT_WRITE
|VM_PROT_READ
;
691 vm_object_lock(copy_object
);
692 vm_object_paging_begin(copy_object
);
693 goto RETRY_COW_OF_LOCK_REQUEST
;
694 case VM_FAULT_FICTITIOUS_SHORTAGE
:
695 vm_page_more_fictitious();
696 prot
= VM_PROT_WRITE
|VM_PROT_READ
;
697 vm_object_lock(copy_object
);
698 vm_object_paging_begin(copy_object
);
699 goto RETRY_COW_OF_LOCK_REQUEST
;
700 case VM_FAULT_MEMORY_ERROR
:
701 vm_object_lock(object
);
702 goto BYPASS_COW_COPYIN
;
706 vm_object_paging_end(copy_object
);
707 if(copy_object
!= object
) {
708 vm_object_unlock(copy_object
);
709 vm_object_lock(object
);
712 if((flags
& (MEMORY_OBJECT_DATA_SYNC
| MEMORY_OBJECT_COPY_SYNC
))) {
715 if(((copy_object
= object
->copy
) != NULL
) &&
716 (flags
& MEMORY_OBJECT_DATA_PURGE
)) {
717 copy_object
->shadow_severed
= TRUE
;
718 copy_object
->shadowed
= FALSE
;
719 copy_object
->shadow
= NULL
;
720 /* delete the ref the COW was holding on the target object */
721 vm_object_deallocate(object
);
727 size
-= PAGE_SIZE
, offset
+= PAGE_SIZE_64
)
730 * Limit the number of pages to be cleaned at once.
732 if (pending_pageout
&&
733 data_cnt
>= PAGE_SIZE
* DATA_WRITE_MAX
)
735 LIST_REQ_PAGEOUT_PAGES(object
, data_cnt
,
736 pageout_action
, paging_offset
);
738 pending_pageout
= FALSE
;
741 while ((m
= vm_page_lookup(object
, offset
)) != VM_PAGE_NULL
) {
742 page_lock_result
= memory_object_lock_page(m
, should_return
,
745 XPR(XPR_MEMORY_OBJECT
,
746 "m_o_update: lock_page, obj 0x%X offset 0x%X result %d\n",
747 (integer_t
)object
, offset
, page_lock_result
, 0, 0);
749 switch (page_lock_result
)
751 case MEMORY_OBJECT_LOCK_RESULT_DONE
:
753 * End of a cluster of dirty pages.
755 if(pending_pageout
) {
756 LIST_REQ_PAGEOUT_PAGES(object
,
757 data_cnt
, pageout_action
,
760 pending_pageout
= FALSE
;
765 case MEMORY_OBJECT_LOCK_RESULT_MUST_BLOCK
:
767 * Since it is necessary to block,
768 * clean any dirty pages now.
770 if(pending_pageout
) {
771 LIST_REQ_PAGEOUT_PAGES(object
,
772 data_cnt
, pageout_action
,
774 pending_pageout
= FALSE
;
779 PAGE_SLEEP(object
, m
, THREAD_UNINT
);
782 case MEMORY_OBJECT_LOCK_RESULT_MUST_CLEAN
:
783 case MEMORY_OBJECT_LOCK_RESULT_MUST_RETURN
:
785 * The clean and return cases are similar.
790 * if this would form a discontiguous block,
791 * clean the old pages and start anew.
796 * Mark the page busy since we unlock the
800 if (pending_pageout
&&
801 (last_offset
!= offset
||
802 pageout_action
!= page_lock_result
)) {
803 LIST_REQ_PAGEOUT_PAGES(object
,
804 data_cnt
, pageout_action
,
806 pending_pageout
= FALSE
;
810 holding_page
= VM_PAGE_NULL
;
812 PAGE_SLEEP(object
, m
, THREAD_UNINT
);
815 if(!pending_pageout
) {
816 pending_pageout
= TRUE
;
817 pageout_action
= page_lock_result
;
818 paging_offset
= offset
;
821 vm_page_lock_queues();
822 m
->list_req_pending
= TRUE
;
827 vm_page_unlock_queues();
830 * Clean but do not flush
832 vm_page_lock_queues();
833 m
->list_req_pending
= TRUE
;
835 vm_page_unlock_queues();
838 vm_object_unlock(object
);
841 data_cnt
+= PAGE_SIZE
;
842 last_offset
= offset
+ PAGE_SIZE_64
;
843 data_returned
= TRUE
;
845 vm_object_lock(object
);
853 * We have completed the scan for applicable pages.
854 * Clean any pages that have been saved.
856 if (pending_pageout
) {
857 LIST_REQ_PAGEOUT_PAGES(object
,
858 data_cnt
, pageout_action
, paging_offset
);
860 return (data_returned
);
864 * Routine: memory_object_synchronize_completed [user interface]
866 * Tell kernel that previously synchronized data
867 * (memory_object_synchronize) has been queue or placed on the
870 * Note: there may be multiple synchronize requests for a given
871 * memory object outstanding but they will not overlap.
875 memory_object_synchronize_completed(
876 memory_object_control_t control
,
877 memory_object_offset_t offset
,
883 XPR(XPR_MEMORY_OBJECT
,
884 "m_o_sync_completed, object 0x%X, offset 0x%X length 0x%X\n",
885 (integer_t
)object
, offset
, length
, 0, 0);
888 * Look for bogus arguments
891 object
= memory_object_control_to_vm_object(control
);
892 if (object
== VM_OBJECT_NULL
)
893 return (KERN_INVALID_ARGUMENT
);
895 vm_object_lock(object
);
898 * search for sync request structure
900 queue_iterate(&object
->msr_q
, msr
, msync_req_t
, msr_q
) {
901 if (msr
->offset
== offset
&& msr
->length
== length
) {
902 queue_remove(&object
->msr_q
, msr
, msync_req_t
, msr_q
);
907 if (queue_end(&object
->msr_q
, (queue_entry_t
)msr
)) {
908 vm_object_unlock(object
);
909 return KERN_INVALID_ARGUMENT
;
913 vm_object_unlock(object
);
914 msr
->flag
= VM_MSYNC_DONE
;
916 thread_wakeup((event_t
) msr
);
919 }/* memory_object_synchronize_completed */
922 vm_object_set_attributes_common(
925 memory_object_copy_strategy_t copy_strategy
,
927 vm_size_t cluster_size
,
928 boolean_t silent_overwrite
,
929 boolean_t advisory_pageout
)
931 boolean_t object_became_ready
;
933 XPR(XPR_MEMORY_OBJECT
,
934 "m_o_set_attr_com, object 0x%X flg %x strat %d\n",
935 (integer_t
)object
, (may_cache
&1)|((temporary
&1)<1), copy_strategy
, 0, 0);
937 if (object
== VM_OBJECT_NULL
)
938 return(KERN_INVALID_ARGUMENT
);
941 * Verify the attributes of importance
944 switch(copy_strategy
) {
945 case MEMORY_OBJECT_COPY_NONE
:
946 case MEMORY_OBJECT_COPY_DELAY
:
949 return(KERN_INVALID_ARGUMENT
);
952 #if !ADVISORY_PAGEOUT
953 if (silent_overwrite
|| advisory_pageout
)
954 return(KERN_INVALID_ARGUMENT
);
956 #endif /* !ADVISORY_PAGEOUT */
961 if (cluster_size
!= 0) {
962 int pages_per_cluster
;
963 pages_per_cluster
= atop(cluster_size
);
965 * Cluster size must be integral multiple of page size,
966 * and be a power of 2 number of pages.
968 if ((cluster_size
& (PAGE_SIZE
-1)) ||
969 ((pages_per_cluster
-1) & pages_per_cluster
))
970 return KERN_INVALID_ARGUMENT
;
973 vm_object_lock(object
);
976 * Copy the attributes
978 assert(!object
->internal
);
979 object_became_ready
= !object
->pager_ready
;
980 object
->copy_strategy
= copy_strategy
;
981 object
->can_persist
= may_cache
;
982 object
->temporary
= temporary
;
983 object
->silent_overwrite
= silent_overwrite
;
984 object
->advisory_pageout
= advisory_pageout
;
985 if (cluster_size
== 0)
986 cluster_size
= PAGE_SIZE
;
987 object
->cluster_size
= cluster_size
;
989 assert(cluster_size
>= PAGE_SIZE
&&
990 cluster_size
% PAGE_SIZE
== 0);
993 * Wake up anyone waiting for the ready attribute
994 * to become asserted.
997 if (object_became_ready
) {
998 object
->pager_ready
= TRUE
;
999 vm_object_wakeup(object
, VM_OBJECT_EVENT_PAGER_READY
);
1002 vm_object_unlock(object
);
1004 return(KERN_SUCCESS
);
1008 * Set the memory object attribute as provided.
1010 * XXX This routine cannot be completed until the vm_msync, clean
1011 * in place, and cluster work is completed. See ifdef notyet
1012 * below and note that vm_object_set_attributes_common()
1013 * may have to be expanded.
1016 memory_object_change_attributes(
1017 memory_object_control_t control
,
1018 memory_object_flavor_t flavor
,
1019 memory_object_info_t attributes
,
1020 mach_msg_type_number_t count
)
1023 kern_return_t result
= KERN_SUCCESS
;
1024 boolean_t temporary
;
1025 boolean_t may_cache
;
1026 boolean_t invalidate
;
1027 vm_size_t cluster_size
;
1028 memory_object_copy_strategy_t copy_strategy
;
1029 boolean_t silent_overwrite
;
1030 boolean_t advisory_pageout
;
1032 object
= memory_object_control_to_vm_object(control
);
1033 if (object
== VM_OBJECT_NULL
)
1034 return (KERN_INVALID_ARGUMENT
);
1036 vm_object_lock(object
);
1038 temporary
= object
->temporary
;
1039 may_cache
= object
->can_persist
;
1040 copy_strategy
= object
->copy_strategy
;
1041 silent_overwrite
= object
->silent_overwrite
;
1042 advisory_pageout
= object
->advisory_pageout
;
1044 invalidate
= object
->invalidate
;
1046 cluster_size
= object
->cluster_size
;
1047 vm_object_unlock(object
);
1050 case OLD_MEMORY_OBJECT_BEHAVIOR_INFO
:
1052 old_memory_object_behave_info_t behave
;
1054 if (count
!= OLD_MEMORY_OBJECT_BEHAVE_INFO_COUNT
) {
1055 result
= KERN_INVALID_ARGUMENT
;
1059 behave
= (old_memory_object_behave_info_t
) attributes
;
1061 temporary
= behave
->temporary
;
1062 invalidate
= behave
->invalidate
;
1063 copy_strategy
= behave
->copy_strategy
;
1068 case MEMORY_OBJECT_BEHAVIOR_INFO
:
1070 memory_object_behave_info_t behave
;
1072 if (count
!= MEMORY_OBJECT_BEHAVE_INFO_COUNT
) {
1073 result
= KERN_INVALID_ARGUMENT
;
1077 behave
= (memory_object_behave_info_t
) attributes
;
1079 temporary
= behave
->temporary
;
1080 invalidate
= behave
->invalidate
;
1081 copy_strategy
= behave
->copy_strategy
;
1082 silent_overwrite
= behave
->silent_overwrite
;
1083 advisory_pageout
= behave
->advisory_pageout
;
1087 case MEMORY_OBJECT_PERFORMANCE_INFO
:
1089 memory_object_perf_info_t perf
;
1091 if (count
!= MEMORY_OBJECT_PERF_INFO_COUNT
) {
1092 result
= KERN_INVALID_ARGUMENT
;
1096 perf
= (memory_object_perf_info_t
) attributes
;
1098 may_cache
= perf
->may_cache
;
1099 cluster_size
= round_page(perf
->cluster_size
);
1104 case OLD_MEMORY_OBJECT_ATTRIBUTE_INFO
:
1106 old_memory_object_attr_info_t attr
;
1108 if (count
!= OLD_MEMORY_OBJECT_ATTR_INFO_COUNT
) {
1109 result
= KERN_INVALID_ARGUMENT
;
1113 attr
= (old_memory_object_attr_info_t
) attributes
;
1115 may_cache
= attr
->may_cache
;
1116 copy_strategy
= attr
->copy_strategy
;
1117 cluster_size
= page_size
;
1122 case MEMORY_OBJECT_ATTRIBUTE_INFO
:
1124 memory_object_attr_info_t attr
;
1126 if (count
!= MEMORY_OBJECT_ATTR_INFO_COUNT
) {
1127 result
= KERN_INVALID_ARGUMENT
;
1131 attr
= (memory_object_attr_info_t
) attributes
;
1133 copy_strategy
= attr
->copy_strategy
;
1134 may_cache
= attr
->may_cache_object
;
1135 cluster_size
= attr
->cluster_size
;
1136 temporary
= attr
->temporary
;
1142 result
= KERN_INVALID_ARGUMENT
;
1146 if (result
!= KERN_SUCCESS
)
1149 if (copy_strategy
== MEMORY_OBJECT_COPY_TEMPORARY
) {
1150 copy_strategy
= MEMORY_OBJECT_COPY_DELAY
;
1157 * XXX may_cache may become a tri-valued variable to handle
1158 * XXX uncache if not in use.
1160 return (vm_object_set_attributes_common(object
,
1170 memory_object_get_attributes(
1171 memory_object_control_t control
,
1172 memory_object_flavor_t flavor
,
1173 memory_object_info_t attributes
, /* pointer to OUT array */
1174 mach_msg_type_number_t
*count
) /* IN/OUT */
1176 kern_return_t ret
= KERN_SUCCESS
;
1179 object
= memory_object_control_to_vm_object(control
);
1180 if (object
== VM_OBJECT_NULL
)
1181 return (KERN_INVALID_ARGUMENT
);
1183 vm_object_lock(object
);
1186 case OLD_MEMORY_OBJECT_BEHAVIOR_INFO
:
1188 old_memory_object_behave_info_t behave
;
1190 if (*count
< OLD_MEMORY_OBJECT_BEHAVE_INFO_COUNT
) {
1191 ret
= KERN_INVALID_ARGUMENT
;
1195 behave
= (old_memory_object_behave_info_t
) attributes
;
1196 behave
->copy_strategy
= object
->copy_strategy
;
1197 behave
->temporary
= object
->temporary
;
1198 #if notyet /* remove when vm_msync complies and clean in place fini */
1199 behave
->invalidate
= object
->invalidate
;
1201 behave
->invalidate
= FALSE
;
1204 *count
= OLD_MEMORY_OBJECT_BEHAVE_INFO_COUNT
;
1208 case MEMORY_OBJECT_BEHAVIOR_INFO
:
1210 memory_object_behave_info_t behave
;
1212 if (*count
< MEMORY_OBJECT_BEHAVE_INFO_COUNT
) {
1213 ret
= KERN_INVALID_ARGUMENT
;
1217 behave
= (memory_object_behave_info_t
) attributes
;
1218 behave
->copy_strategy
= object
->copy_strategy
;
1219 behave
->temporary
= object
->temporary
;
1220 #if notyet /* remove when vm_msync complies and clean in place fini */
1221 behave
->invalidate
= object
->invalidate
;
1223 behave
->invalidate
= FALSE
;
1225 behave
->advisory_pageout
= object
->advisory_pageout
;
1226 behave
->silent_overwrite
= object
->silent_overwrite
;
1227 *count
= MEMORY_OBJECT_BEHAVE_INFO_COUNT
;
1231 case MEMORY_OBJECT_PERFORMANCE_INFO
:
1233 memory_object_perf_info_t perf
;
1235 if (*count
< MEMORY_OBJECT_PERF_INFO_COUNT
) {
1236 ret
= KERN_INVALID_ARGUMENT
;
1240 perf
= (memory_object_perf_info_t
) attributes
;
1241 perf
->cluster_size
= object
->cluster_size
;
1242 perf
->may_cache
= object
->can_persist
;
1244 *count
= MEMORY_OBJECT_PERF_INFO_COUNT
;
1248 case OLD_MEMORY_OBJECT_ATTRIBUTE_INFO
:
1250 old_memory_object_attr_info_t attr
;
1252 if (*count
< OLD_MEMORY_OBJECT_ATTR_INFO_COUNT
) {
1253 ret
= KERN_INVALID_ARGUMENT
;
1257 attr
= (old_memory_object_attr_info_t
) attributes
;
1258 attr
->may_cache
= object
->can_persist
;
1259 attr
->copy_strategy
= object
->copy_strategy
;
1261 *count
= OLD_MEMORY_OBJECT_ATTR_INFO_COUNT
;
1265 case MEMORY_OBJECT_ATTRIBUTE_INFO
:
1267 memory_object_attr_info_t attr
;
1269 if (*count
< MEMORY_OBJECT_ATTR_INFO_COUNT
) {
1270 ret
= KERN_INVALID_ARGUMENT
;
1274 attr
= (memory_object_attr_info_t
) attributes
;
1275 attr
->copy_strategy
= object
->copy_strategy
;
1276 attr
->cluster_size
= object
->cluster_size
;
1277 attr
->may_cache_object
= object
->can_persist
;
1278 attr
->temporary
= object
->temporary
;
1280 *count
= MEMORY_OBJECT_ATTR_INFO_COUNT
;
1285 ret
= KERN_INVALID_ARGUMENT
;
1289 vm_object_unlock(object
);
1296 * Routine: memory_object_upl_request [interface]
1298 * Cause the population of a portion of a vm_object.
1299 * Depending on the nature of the request, the pages
1300 * returned may be contain valid data or be uninitialized.
1305 memory_object_upl_request(
1306 memory_object_control_t control
,
1307 memory_object_offset_t offset
,
1310 upl_page_info_array_t user_page_list
,
1311 unsigned int *page_list_count
,
1316 object
= memory_object_control_to_vm_object(control
);
1317 if (object
== VM_OBJECT_NULL
)
1318 return (KERN_INVALID_ARGUMENT
);
1320 return vm_object_upl_request(object
,
1330 * Routine: memory_object_super_upl_request [interface]
1332 * Cause the population of a portion of a vm_object
1333 * in much the same way as memory_object_upl_request.
1334 * Depending on the nature of the request, the pages
1335 * returned may be contain valid data or be uninitialized.
1336 * However, the region may be expanded up to the super
1337 * cluster size provided.
1341 memory_object_super_upl_request(
1342 memory_object_control_t control
,
1343 memory_object_offset_t offset
,
1345 vm_size_t super_cluster
,
1347 upl_page_info_t
*user_page_list
,
1348 unsigned int *page_list_count
,
1353 object
= memory_object_control_to_vm_object(control
);
1354 if (object
== VM_OBJECT_NULL
)
1355 return (KERN_INVALID_ARGUMENT
);
1357 return vm_object_super_upl_request(object
,
1367 int vm_stat_discard_cleared_reply
= 0;
1368 int vm_stat_discard_cleared_unset
= 0;
1369 int vm_stat_discard_cleared_too_late
= 0;
1374 * Routine: host_default_memory_manager [interface]
1376 * set/get the default memory manager port and default cluster
1379 * If successful, consumes the supplied naked send right.
1382 host_default_memory_manager(
1383 host_priv_t host_priv
,
1384 memory_object_default_t
*default_manager
,
1385 vm_size_t cluster_size
)
1387 memory_object_default_t current_manager
;
1388 memory_object_default_t new_manager
;
1389 memory_object_default_t returned_manager
;
1391 if (host_priv
== HOST_PRIV_NULL
)
1392 return(KERN_INVALID_HOST
);
1394 assert(host_priv
== &realhost
);
1396 new_manager
= *default_manager
;
1397 mutex_lock(&memory_manager_default_lock
);
1398 current_manager
= memory_manager_default
;
1400 if (new_manager
== MEMORY_OBJECT_DEFAULT_NULL
) {
1402 * Retrieve the current value.
1404 memory_object_default_reference(current_manager
);
1405 returned_manager
= current_manager
;
1408 * Retrieve the current value,
1409 * and replace it with the supplied value.
1410 * We return the old reference to the caller
1411 * but we have to take a reference on the new
1415 returned_manager
= current_manager
;
1416 memory_manager_default
= new_manager
;
1417 memory_object_default_reference(new_manager
);
1419 if (cluster_size
% PAGE_SIZE
!= 0) {
1421 mutex_unlock(&memory_manager_default_lock
);
1422 return KERN_INVALID_ARGUMENT
;
1424 cluster_size
= round_page(cluster_size
);
1427 memory_manager_default_cluster
= cluster_size
;
1430 * In case anyone's been waiting for a memory
1431 * manager to be established, wake them up.
1434 thread_wakeup((event_t
) &memory_manager_default
);
1437 mutex_unlock(&memory_manager_default_lock
);
1439 *default_manager
= returned_manager
;
1440 return(KERN_SUCCESS
);
1444 * Routine: memory_manager_default_reference
1446 * Returns a naked send right for the default
1447 * memory manager. The returned right is always
1448 * valid (not IP_NULL or IP_DEAD).
1451 __private_extern__ memory_object_default_t
1452 memory_manager_default_reference(
1453 vm_size_t
*cluster_size
)
1455 memory_object_default_t current_manager
;
1457 mutex_lock(&memory_manager_default_lock
);
1458 current_manager
= memory_manager_default
;
1459 while (current_manager
== MEMORY_OBJECT_DEFAULT_NULL
) {
1462 res
= thread_sleep_mutex((event_t
) &memory_manager_default
,
1463 &memory_manager_default_lock
,
1465 assert(res
== THREAD_AWAKENED
);
1466 current_manager
= memory_manager_default
;
1468 memory_object_default_reference(current_manager
);
1469 *cluster_size
= memory_manager_default_cluster
;
1470 mutex_unlock(&memory_manager_default_lock
);
1472 return current_manager
;
1476 * Routine: memory_manager_default_check
1479 * Check whether a default memory manager has been set
1480 * up yet, or not. Returns KERN_SUCCESS if dmm exists,
1481 * and KERN_FAILURE if dmm does not exist.
1483 * If there is no default memory manager, log an error,
1484 * but only the first time.
1487 __private_extern__ kern_return_t
1488 memory_manager_default_check(void)
1490 memory_object_default_t current
;
1492 mutex_lock(&memory_manager_default_lock
);
1493 current
= memory_manager_default
;
1494 if (current
== MEMORY_OBJECT_DEFAULT_NULL
) {
1495 static boolean_t logged
; /* initialized to 0 */
1496 boolean_t complain
= !logged
;
1498 mutex_unlock(&memory_manager_default_lock
);
1500 printf("Warning: No default memory manager\n");
1501 return(KERN_FAILURE
);
1503 mutex_unlock(&memory_manager_default_lock
);
1504 return(KERN_SUCCESS
);
1508 __private_extern__
void
1509 memory_manager_default_init(void)
1511 memory_manager_default
= MEMORY_OBJECT_DEFAULT_NULL
;
1512 mutex_init(&memory_manager_default_lock
, ETAP_VM_MEMMAN
);
1517 memory_object_deactivate_pages(
1519 vm_object_offset_t offset
,
1520 vm_object_size_t size
,
1521 boolean_t kill_page
)
1523 vm_object_t orig_object
;
1524 int pages_moved
= 0;
1525 int pages_found
= 0;
1528 * entered with object lock held, acquire a paging reference to
1529 * prevent the memory_object and control ports from
1532 orig_object
= object
;
1535 register vm_page_t m
;
1536 vm_object_offset_t toffset
;
1537 vm_object_size_t tsize
;
1539 vm_object_paging_begin(object
);
1540 vm_page_lock_queues();
1542 for (tsize
= size
, toffset
= offset
; tsize
; tsize
-= PAGE_SIZE
, toffset
+= PAGE_SIZE
) {
1544 if ((m
= vm_page_lookup(object
, toffset
)) != VM_PAGE_NULL
) {
1548 if ((m
->wire_count
== 0) && (!m
->private) && (!m
->gobbled
) && (!m
->busy
)) {
1550 m
->reference
= FALSE
;
1551 pmap_clear_reference(m
->phys_addr
);
1553 if ((kill_page
) && (object
->internal
)) {
1554 m
->precious
= FALSE
;
1556 pmap_clear_modify(m
->phys_addr
);
1557 vm_external_state_clr(object
->existence_map
, offset
);
1559 VM_PAGE_QUEUES_REMOVE(m
);
1564 m
, vm_page_t
, pageq
);
1567 &vm_page_queue_inactive
,
1568 m
, vm_page_t
, pageq
);
1573 vm_page_inactive_count
++;
1579 vm_page_unlock_queues();
1580 vm_object_paging_end(object
);
1582 if (object
->shadow
) {
1583 vm_object_t tmp_object
;
1587 offset
+= object
->shadow_offset
;
1589 tmp_object
= object
->shadow
;
1590 vm_object_lock(tmp_object
);
1592 if (object
!= orig_object
)
1593 vm_object_unlock(object
);
1594 object
= tmp_object
;
1598 if (object
!= orig_object
)
1599 vm_object_unlock(object
);
1602 /* Allow manipulation of individual page state. This is actually part of */
1603 /* the UPL regimen but takes place on the object rather than on a UPL */
1606 memory_object_page_op(
1607 memory_object_control_t control
,
1608 memory_object_offset_t offset
,
1610 vm_offset_t
*phys_entry
,
1617 object
= memory_object_control_to_vm_object(control
);
1618 if (object
== VM_OBJECT_NULL
)
1619 return (KERN_INVALID_ARGUMENT
);
1621 vm_object_lock(object
);
1623 if(ops
& UPL_POP_PHYSICAL
) {
1624 if(object
->phys_contiguous
) {
1626 *phys_entry
= (vm_offset_t
)
1627 object
->shadow_offset
;
1629 vm_object_unlock(object
);
1630 return KERN_SUCCESS
;
1632 vm_object_unlock(object
);
1633 return KERN_INVALID_OBJECT
;
1638 if(object
->phys_contiguous
) {
1639 vm_object_unlock(object
);
1640 return KERN_INVALID_OBJECT
;
1643 if((dst_page
= vm_page_lookup(object
,offset
)) == VM_PAGE_NULL
) {
1644 vm_object_unlock(object
);
1645 return KERN_FAILURE
;
1648 /* Sync up on getting the busy bit */
1649 if((dst_page
->busy
|| dst_page
->cleaning
) &&
1650 (((ops
& UPL_POP_SET
) &&
1651 (ops
& UPL_POP_BUSY
)) || (ops
& UPL_POP_DUMP
))) {
1652 /* someone else is playing with the page, we will */
1654 PAGE_SLEEP(object
, dst_page
, THREAD_UNINT
);
1658 if (ops
& UPL_POP_DUMP
) {
1659 vm_page_lock_queues();
1660 vm_page_free(dst_page
);
1661 vm_page_unlock_queues();
1668 /* Get the condition of flags before requested ops */
1669 /* are undertaken */
1671 if(dst_page
->dirty
) *flags
|= UPL_POP_DIRTY
;
1672 if(dst_page
->pageout
) *flags
|= UPL_POP_PAGEOUT
;
1673 if(dst_page
->precious
) *flags
|= UPL_POP_PRECIOUS
;
1674 if(dst_page
->absent
) *flags
|= UPL_POP_ABSENT
;
1675 if(dst_page
->busy
) *flags
|= UPL_POP_BUSY
;
1678 *phys_entry
= dst_page
->phys_addr
;
1680 /* The caller should have made a call either contingent with */
1681 /* or prior to this call to set UPL_POP_BUSY */
1682 if(ops
& UPL_POP_SET
) {
1683 /* The protection granted with this assert will */
1684 /* not be complete. If the caller violates the */
1685 /* convention and attempts to change page state */
1686 /* without first setting busy we may not see it */
1687 /* because the page may already be busy. However */
1688 /* if such violations occur we will assert sooner */
1690 assert(dst_page
->busy
|| (ops
& UPL_POP_BUSY
));
1691 if (ops
& UPL_POP_DIRTY
) dst_page
->dirty
= TRUE
;
1692 if (ops
& UPL_POP_PAGEOUT
) dst_page
->pageout
= TRUE
;
1693 if (ops
& UPL_POP_PRECIOUS
) dst_page
->precious
= TRUE
;
1694 if (ops
& UPL_POP_ABSENT
) dst_page
->absent
= TRUE
;
1695 if (ops
& UPL_POP_BUSY
) dst_page
->busy
= TRUE
;
1698 if(ops
& UPL_POP_CLR
) {
1699 assert(dst_page
->busy
);
1700 if (ops
& UPL_POP_DIRTY
) dst_page
->dirty
= FALSE
;
1701 if (ops
& UPL_POP_PAGEOUT
) dst_page
->pageout
= FALSE
;
1702 if (ops
& UPL_POP_PRECIOUS
) dst_page
->precious
= FALSE
;
1703 if (ops
& UPL_POP_ABSENT
) dst_page
->absent
= FALSE
;
1704 if (ops
& UPL_POP_BUSY
) {
1705 dst_page
->busy
= FALSE
;
1706 PAGE_WAKEUP(dst_page
);
1712 vm_object_unlock(object
);
1713 return KERN_SUCCESS
;
1717 static zone_t mem_obj_control_zone
;
1719 __private_extern__
void
1720 memory_object_control_bootstrap(void)
1724 i
= (vm_size_t
) sizeof (struct memory_object_control
);
1725 mem_obj_control_zone
= zinit (i
, 8192*i
, 4096, "mem_obj_control");
1729 __private_extern__ memory_object_control_t
1730 memory_object_control_allocate(
1733 memory_object_control_t control
;
1735 control
= (memory_object_control_t
)zalloc(mem_obj_control_zone
);
1736 if (control
!= MEMORY_OBJECT_CONTROL_NULL
)
1737 control
->object
= object
;
1741 __private_extern__
void
1742 memory_object_control_collapse(
1743 memory_object_control_t control
,
1746 assert((control
->object
!= VM_OBJECT_NULL
) &&
1747 (control
->object
!= object
));
1748 control
->object
= object
;
1751 __private_extern__ vm_object_t
1752 memory_object_control_to_vm_object(
1753 memory_object_control_t control
)
1755 if (control
== MEMORY_OBJECT_CONTROL_NULL
)
1756 return VM_OBJECT_NULL
;
1758 return (control
->object
);
1761 memory_object_control_t
1762 convert_port_to_mo_control(
1765 return MEMORY_OBJECT_CONTROL_NULL
;
1770 convert_mo_control_to_port(
1771 memory_object_control_t control
)
1773 return MACH_PORT_NULL
;
1777 memory_object_control_reference(
1778 memory_object_control_t control
)
1784 * We only every issue one of these references, so kill it
1785 * when that gets released (should switch the real reference
1786 * counting in true port-less EMMI).
1789 memory_object_control_deallocate(
1790 memory_object_control_t control
)
1792 zfree(mem_obj_control_zone
, (vm_offset_t
)control
);
1796 memory_object_control_disable(
1797 memory_object_control_t control
)
1799 assert(control
->object
!= VM_OBJECT_NULL
);
1800 control
->object
= VM_OBJECT_NULL
;
1804 memory_object_default_reference(
1805 memory_object_default_t dmm
)
1807 ipc_port_make_send(dmm
);
1811 memory_object_default_deallocate(
1812 memory_object_default_t dmm
)
1814 ipc_port_release_send(dmm
);
1818 convert_port_to_memory_object(
1821 return (MEMORY_OBJECT_NULL
);
1826 convert_memory_object_to_port(
1827 memory_object_t object
)
1829 return (MACH_PORT_NULL
);
1833 /* remove after component interface available */
1834 extern int vnode_pager_workaround
;
1835 extern int device_pager_workaround
;
1839 /* Routine memory_object_reference */
1840 void memory_object_reference(
1841 memory_object_t memory_object
)
1843 extern void dp_memory_object_reference(memory_object_t
);
1846 extern void vnode_pager_reference(memory_object_t
);
1847 extern void device_pager_reference(memory_object_t
);
1849 if(memory_object
->pager
== &vnode_pager_workaround
) {
1850 vnode_pager_reference(memory_object
);
1851 } else if(memory_object
->pager
== &device_pager_workaround
) {
1852 device_pager_reference(memory_object
);
1855 dp_memory_object_reference(memory_object
);
1858 /* Routine memory_object_deallocate */
1859 void memory_object_deallocate(
1860 memory_object_t memory_object
)
1862 extern void dp_memory_object_deallocate(memory_object_t
);
1865 extern void vnode_pager_deallocate(memory_object_t
);
1866 extern void device_pager_deallocate(memory_object_t
);
1868 if(memory_object
->pager
== &vnode_pager_workaround
) {
1869 vnode_pager_deallocate(memory_object
);
1870 } else if(memory_object
->pager
== &device_pager_workaround
) {
1871 device_pager_deallocate(memory_object
);
1874 dp_memory_object_deallocate(memory_object
);
1878 /* Routine memory_object_init */
1879 kern_return_t memory_object_init
1881 memory_object_t memory_object
,
1882 memory_object_control_t memory_control
,
1883 vm_size_t memory_object_page_size
1886 extern kern_return_t
dp_memory_object_init(memory_object_t
,
1887 memory_object_control_t
,
1890 extern kern_return_t
vnode_pager_init(memory_object_t
,
1891 memory_object_control_t
,
1893 extern kern_return_t
device_pager_init(memory_object_t
,
1894 memory_object_control_t
,
1897 if(memory_object
->pager
== &vnode_pager_workaround
) {
1898 return vnode_pager_init(memory_object
,
1900 memory_object_page_size
);
1901 } else if(memory_object
->pager
== &device_pager_workaround
) {
1902 return device_pager_init(memory_object
,
1904 memory_object_page_size
);
1907 return dp_memory_object_init(memory_object
,
1909 memory_object_page_size
);
1912 /* Routine memory_object_terminate */
1913 kern_return_t memory_object_terminate
1915 memory_object_t memory_object
1918 extern kern_return_t
dp_memory_object_terminate(memory_object_t
);
1921 extern kern_return_t
vnode_pager_terminate(memory_object_t
);
1922 extern kern_return_t
device_pager_terminate(memory_object_t
);
1924 if(memory_object
->pager
== &vnode_pager_workaround
) {
1925 return vnode_pager_terminate(memory_object
);
1926 } else if(memory_object
->pager
== &device_pager_workaround
) {
1927 return device_pager_terminate(memory_object
);
1930 return dp_memory_object_terminate(memory_object
);
1933 /* Routine memory_object_data_request */
1934 kern_return_t memory_object_data_request
1936 memory_object_t memory_object
,
1937 memory_object_offset_t offset
,
1939 vm_prot_t desired_access
1942 extern kern_return_t
dp_memory_object_data_request(memory_object_t
,
1943 memory_object_offset_t
, vm_size_t
, vm_prot_t
);
1946 extern kern_return_t
vnode_pager_data_request(memory_object_t
,
1947 memory_object_offset_t
, vm_size_t
, vm_prot_t
);
1948 extern kern_return_t
device_pager_data_request(memory_object_t
,
1949 memory_object_offset_t
, vm_size_t
, vm_prot_t
);
1951 if (memory_object
->pager
== &vnode_pager_workaround
) {
1952 return vnode_pager_data_request(memory_object
,
1956 } else if (memory_object
->pager
== &device_pager_workaround
) {
1957 return device_pager_data_request(memory_object
,
1963 return dp_memory_object_data_request(memory_object
,
1969 /* Routine memory_object_data_return */
1970 kern_return_t memory_object_data_return
1972 memory_object_t memory_object
,
1973 memory_object_offset_t offset
,
1976 boolean_t kernel_copy
1979 extern kern_return_t
dp_memory_object_data_return(memory_object_t
,
1980 memory_object_offset_t
,
1985 extern kern_return_t
vnode_pager_data_return(memory_object_t
,
1986 memory_object_offset_t
,
1990 extern kern_return_t
device_pager_data_return(memory_object_t
,
1991 memory_object_offset_t
,
1996 if (memory_object
->pager
== &vnode_pager_workaround
) {
1997 return vnode_pager_data_return(memory_object
,
2002 } else if (memory_object
->pager
== &device_pager_workaround
) {
2003 return device_pager_data_return(memory_object
,
2010 return dp_memory_object_data_return(memory_object
,
2017 /* Routine memory_object_data_initialize */
2018 kern_return_t memory_object_data_initialize
2020 memory_object_t memory_object
,
2021 memory_object_offset_t offset
,
2026 extern kern_return_t
dp_memory_object_data_initialize(memory_object_t
,
2027 memory_object_offset_t
,
2030 extern kern_return_t
vnode_pager_data_initialize(memory_object_t
,
2031 memory_object_offset_t
,
2033 extern kern_return_t
device_pager_data_initialize(memory_object_t
,
2034 memory_object_offset_t
,
2037 if (memory_object
->pager
== &vnode_pager_workaround
) {
2038 return vnode_pager_data_initialize(memory_object
,
2041 } else if (memory_object
->pager
== &device_pager_workaround
) {
2042 return device_pager_data_initialize(memory_object
,
2047 return dp_memory_object_data_initialize(memory_object
,
2052 /* Routine memory_object_data_unlock */
2053 kern_return_t memory_object_data_unlock
2055 memory_object_t memory_object
,
2056 memory_object_offset_t offset
,
2058 vm_prot_t desired_access
2061 extern kern_return_t
dp_memory_object_data_unlock(memory_object_t
,
2062 memory_object_offset_t
,
2066 extern kern_return_t
vnode_pager_data_unlock(memory_object_t
,
2067 memory_object_offset_t
,
2070 extern kern_return_t
device_pager_data_unlock(memory_object_t
,
2071 memory_object_offset_t
,
2075 if (memory_object
->pager
== &vnode_pager_workaround
) {
2076 return vnode_pager_data_unlock(memory_object
,
2080 } else if (memory_object
->pager
== &device_pager_workaround
) {
2081 return device_pager_data_unlock(memory_object
,
2087 return dp_memory_object_data_unlock(memory_object
,
2094 /* Routine memory_object_synchronize */
2095 kern_return_t memory_object_synchronize
2097 memory_object_t memory_object
,
2098 memory_object_offset_t offset
,
2100 vm_sync_t sync_flags
2103 extern kern_return_t
dp_memory_object_data_synchronize(memory_object_t
,
2104 memory_object_offset_t
,
2108 extern kern_return_t
vnode_pager_data_synchronize(memory_object_t
,
2109 memory_object_offset_t
,
2112 extern kern_return_t
device_pager_data_synchronize(memory_object_t
,
2113 memory_object_offset_t
,
2117 if (memory_object
->pager
== &vnode_pager_workaround
) {
2118 return vnode_pager_synchronize(
2123 } else if (memory_object
->pager
== &device_pager_workaround
) {
2124 return device_pager_synchronize(
2131 return dp_memory_object_synchronize(
2138 /* Routine memory_object_unmap */
2139 kern_return_t memory_object_unmap
2141 memory_object_t memory_object
2144 extern kern_return_t
dp_memory_object_unmap(memory_object_t
);
2146 extern kern_return_t
vnode_pager_unmap(memory_object_t
);
2147 extern kern_return_t
device_pager_unmap(memory_object_t
);
2149 if (memory_object
->pager
== &vnode_pager_workaround
) {
2150 return vnode_pager_unmap(memory_object
);
2151 } else if (memory_object
->pager
== &device_pager_workaround
) {
2152 return device_pager_unmap(memory_object
);
2155 return dp_memory_object_unmap(memory_object
);
2158 /* Routine memory_object_create */
2159 kern_return_t memory_object_create
2161 memory_object_default_t default_memory_manager
,
2162 vm_size_t new_memory_object_size
,
2163 memory_object_t
*new_memory_object
2166 extern kern_return_t
default_pager_memory_object_create(memory_object_default_t
,
2170 return default_pager_memory_object_create(default_memory_manager
,
2171 new_memory_object_size
,