2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34 * All Rights Reserved.
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
60 * Author: Avadis Tevanian, Jr., Michael Wayne Young
63 * Virtual memory object module definitions.
66 #ifndef _VM_VM_OBJECT_H_
67 #define _VM_VM_OBJECT_H_
69 #include <mach_pagemap.h>
70 #include <task_swapper.h>
72 #include <mach/kern_return.h>
73 #include <mach/boolean.h>
74 #include <mach/memory_object_types.h>
75 #include <mach/port.h>
76 #include <mach/vm_prot.h>
77 #include <mach/vm_param.h>
78 #include <mach/machine/vm_types.h>
79 #include <kern/queue.h>
80 #include <kern/lock.h>
81 #include <kern/locks.h>
82 #include <kern/assert.h>
83 #include <kern/misc_protos.h>
84 #include <kern/macro_help.h>
85 #include <ipc/ipc_types.h>
89 #include <vm/vm_external.h>
90 #endif /* MACH_PAGEMAP */
92 #include <vm/vm_options.h>
99 * vm_object_t Virtual memory object.
100 * vm_object_fault_info_t Used to determine cluster size.
103 struct vm_object_fault_info
{
106 vm_size_t cluster_size
;
107 vm_behavior_t behavior
;
108 vm_map_offset_t lo_offset
;
109 vm_map_offset_t hi_offset
;
112 boolean_t mark_zf_absent
;
118 queue_head_t memq
; /* Resident memory */
119 lck_rw_t Lock
; /* Synchronization */
121 vm_object_size_t size
; /* Object size (only valid
124 struct vm_page
*memq_hint
;
125 int ref_count
; /* Number of references */
127 int res_count
; /* Residency references (swap)*/
128 #endif /* TASK_SWAPPER */
129 unsigned int resident_page_count
;
130 /* number of resident pages */
131 unsigned int wired_page_count
; /* number of wired pages */
132 unsigned int reusable_page_count
;
134 struct vm_object
*copy
; /* Object that should receive
135 * a copy of my changed pages,
136 * for copy_delay, or just the
137 * temporary object that
138 * shadows this object, for
141 struct vm_object
*shadow
; /* My shadow */
142 vm_object_offset_t shadow_offset
; /* Offset into shadow */
144 memory_object_t pager
; /* Where to get data */
145 vm_object_offset_t paging_offset
; /* Offset into memory object */
146 memory_object_control_t pager_control
; /* Where data comes back */
148 memory_object_copy_strategy_t
149 copy_strategy
; /* How to handle data copy */
151 short paging_in_progress
;
152 /* The memory object ports are
153 * being used (e.g., for pagein
154 * or pageout) -- don't change
155 * any of these fields (i.e.,
156 * don't collapse, destroy or
159 short activity_in_progress
;
162 /* boolean_t array */ all_wanted
:11, /* Bit array of "want to be
163 * awakened" notations. See
164 * VM_OBJECT_EVENT_* items
166 /* boolean_t */ pager_created
:1, /* Has pager been created? */
167 /* boolean_t */ pager_initialized
:1, /* Are fields ready to use? */
168 /* boolean_t */ pager_ready
:1, /* Will pager take requests? */
170 /* boolean_t */ pager_trusted
:1,/* The pager for this object
171 * is trusted. This is true for
172 * all internal objects (backed
173 * by the default pager)
175 /* boolean_t */ can_persist
:1, /* The kernel may keep the data
176 * for this object (and rights
177 * to the memory object) after
178 * all address map references
181 /* boolean_t */ internal
:1, /* Created by the kernel (and
182 * therefore, managed by the
183 * default memory manger)
185 /* boolean_t */ temporary
:1, /* Permanent objects may be
186 * changed externally by the
187 * memory manager, and changes
188 * made in memory must be
189 * reflected back to the memory
190 * manager. Temporary objects
194 /* boolean_t */ private:1, /* magic device_pager object,
195 * holds private pages only */
196 /* boolean_t */ pageout
:1, /* pageout object. contains
197 * private pages that refer to
198 * a real memory object. */
199 /* boolean_t */ alive
:1, /* Not yet terminated */
201 /* boolean_t */ purgable
:2, /* Purgable state. See
204 /* boolean_t */ shadowed
:1, /* Shadow may exist */
205 /* boolean_t */ silent_overwrite
:1,
206 /* Allow full page overwrite
207 * without data_request if
209 /* boolean_t */ advisory_pageout
:1,
210 /* Instead of sending page
211 * via OOL, just notify
212 * pager that the kernel
213 * wants to discard it, page
214 * remains in object */
215 /* boolean_t */ true_share
:1,
216 /* This object is mapped
217 * in more than one place
218 * and hence cannot be
220 /* boolean_t */ terminating
:1,
221 /* Allows vm_object_lookup
222 * and vm_object_deallocate
223 * to special case their
224 * behavior when they are
225 * called as a result of
226 * page cleaning during
229 /* boolean_t */ named
:1, /* An enforces an internal
230 * naming convention, by
231 * calling the right routines
233 * destruction, UBC references
234 * against the vm_object are
237 /* boolean_t */ shadow_severed
:1,
238 /* When a permanent object
239 * backing a COW goes away
240 * unexpectedly. This bit
241 * allows vm_fault to return
242 * an error rather than a
245 /* boolean_t */ phys_contiguous
:1,
246 /* Memory is wired and
247 * guaranteed physically
248 * contiguous. However
249 * it is not device memory
250 * and obeys normal virtual
251 * memory rules w.r.t pmap
254 /* boolean_t */ nophyscache
:1;
255 /* When mapped at the
256 * pmap level, don't allow
257 * primary caching. (for
263 queue_chain_t cached_list
; /* Attachment point for the
264 * list of objects cached as a
265 * result of their can_persist
269 queue_head_t msr_q
; /* memory object synchronise
273 * the following fields are not protected by any locks
274 * they are updated via atomic compare and swap
276 vm_object_offset_t last_alloc
; /* last allocation offset */
277 int sequential
; /* sequential access size */
279 uint32_t pages_created
;
282 vm_external_map_t existence_map
; /* bitmap of pages written to
284 #endif /* MACH_PAGEMAP */
285 vm_offset_t cow_hint
; /* last page present in */
286 /* shadow but not in object */
288 struct vm_object
*paging_object
; /* object which pages to be
289 * swapped out are temporary
290 * put in current object
293 /* hold object lock when altering */
295 wimg_bits
:8, /* cache WIMG bits */
296 code_signed
:1, /* pages are signed and should be
297 validated; the signatures are stored
299 hashed
:1, /* object/pager entered in hash */
300 transposed
:1, /* object was transposed with another */
301 mapping_in_progress
:1, /* pager being mapped/unmapped */
306 __object2_unused_bits
:16; /* for expansion */
309 queue_head_t uplq
; /* List of outstanding upls */
310 #endif /* UPL_DEBUG */
314 * Keep track of the stack traces for the first holders
315 * of a "paging_in_progress" reference for this VM object.
317 #define VM_PIP_DEBUG_STACK_FRAMES 25 /* depth of each stack trace */
318 #define VM_PIP_DEBUG_MAX_REFS 10 /* track that many references */
319 struct __pip_backtrace
{
320 void *pip_retaddr
[VM_PIP_DEBUG_STACK_FRAMES
];
321 } pip_holders
[VM_PIP_DEBUG_MAX_REFS
];
322 #endif /* VM_PIP_DEBUG */
324 queue_chain_t objq
; /* object queue - currently used for purgable queues */
327 #define VM_OBJECT_PURGEABLE_FAULT_ERROR(object) \
328 ((object)->volatile_fault && \
329 ((object)->purgable == VM_PURGABLE_VOLATILE || \
330 (object)->purgable == VM_PURGABLE_EMPTY))
332 #define VM_PAGE_REMOVE(page) \
334 vm_page_t __page = (page); \
335 vm_object_t __object = __page->object; \
336 if (__page == __object->memq_hint) { \
337 vm_page_t __new_hint; \
338 queue_entry_t __qe; \
339 __qe = queue_next(&__page->listq); \
340 if (queue_end(&__object->memq, __qe)) { \
341 __qe = queue_prev(&__page->listq); \
342 if (queue_end(&__object->memq, __qe)) { \
346 __new_hint = (vm_page_t) __qe; \
347 __object->memq_hint = __new_hint; \
349 queue_remove(&__object->memq, __page, vm_page_t, listq); \
352 #define VM_PAGE_INSERT(page, object) \
354 vm_page_t __page = (page); \
355 vm_object_t __object = (object); \
356 queue_enter(&__object->memq, __page, vm_page_t, listq); \
357 __object->memq_hint = __page; \
361 vm_object_t kernel_object
; /* the single kernel object */
364 unsigned int vm_object_absent_max
; /* maximum number of absent pages
365 at a time for each object */
367 # define VM_MSYNC_INITIALIZED 0
368 # define VM_MSYNC_SYNCHRONIZING 1
369 # define VM_MSYNC_DONE 2
372 queue_chain_t msr_q
; /* object request queue */
373 queue_chain_t req_q
; /* vm_msync request queue */
375 vm_object_offset_t offset
;
376 vm_object_size_t length
;
377 vm_object_t object
; /* back pointer */
378 decl_lck_mtx_data(, msync_req_lock
) /* Lock for this structure */
381 typedef struct msync_req
*msync_req_t
;
382 #define MSYNC_REQ_NULL ((msync_req_t) 0)
385 extern lck_grp_t vm_map_lck_grp
;
386 extern lck_attr_t vm_map_lck_attr
;
389 * Macros to allocate and free msync_reqs
391 #define msync_req_alloc(msr) \
393 (msr) = (msync_req_t)kalloc(sizeof(struct msync_req)); \
394 lck_mtx_init(&(msr)->msync_req_lock, &vm_map_lck_grp, &vm_map_lck_attr); \
395 msr->flag = VM_MSYNC_INITIALIZED; \
398 #define msync_req_free(msr) \
399 (kfree((msr), sizeof(struct msync_req)))
401 #define msr_lock(msr) lck_mtx_lock(&(msr)->msync_req_lock)
402 #define msr_unlock(msr) lck_mtx_unlock(&(msr)->msync_req_lock)
405 * Declare procedures that operate on VM objects.
408 __private_extern__
void vm_object_bootstrap(void) __attribute__((section("__TEXT, initcode")));
410 __private_extern__
void vm_object_init(void);
412 __private_extern__
void vm_object_init_lck_grp(void);
414 __private_extern__
void vm_object_reaper_init(void);
416 __private_extern__ vm_object_t
vm_object_allocate(
417 vm_object_size_t size
);
419 __private_extern__
void _vm_object_allocate(vm_object_size_t size
,
424 __private_extern__
void vm_object_res_reference(
426 __private_extern__
void vm_object_res_deallocate(
428 #define VM_OBJ_RES_INCR(object) (object)->res_count++
429 #define VM_OBJ_RES_DECR(object) (object)->res_count--
431 #else /* TASK_SWAPPER */
433 #define VM_OBJ_RES_INCR(object)
434 #define VM_OBJ_RES_DECR(object)
435 #define vm_object_res_reference(object)
436 #define vm_object_res_deallocate(object)
438 #endif /* TASK_SWAPPER */
440 #define vm_object_reference_locked(object) \
442 vm_object_t RLObject = (object); \
443 vm_object_lock_assert_exclusive(object); \
444 assert((RLObject)->ref_count > 0); \
445 (RLObject)->ref_count++; \
446 assert((RLObject)->ref_count > 1); \
447 vm_object_res_reference(RLObject); \
451 #define vm_object_reference_shared(object) \
453 vm_object_t RLObject = (object); \
454 vm_object_lock_assert_shared(object); \
455 assert((RLObject)->ref_count > 0); \
456 OSAddAtomic(1, &(RLObject)->ref_count); \
457 assert((RLObject)->ref_count > 1); \
458 /* XXX we would need an atomic version of the following ... */ \
459 vm_object_res_reference(RLObject); \
463 __private_extern__
void vm_object_reference(
468 #define vm_object_reference(object) \
470 vm_object_t RObject = (object); \
472 vm_object_lock_shared(RObject); \
473 vm_object_reference_shared(RObject); \
474 vm_object_unlock(RObject); \
478 #endif /* MACH_ASSERT */
480 __private_extern__
void vm_object_deallocate(
483 __private_extern__ kern_return_t
vm_object_release_name(
487 __private_extern__
void vm_object_pmap_protect(
489 vm_object_offset_t offset
,
490 vm_object_size_t size
,
492 vm_map_offset_t pmap_start
,
495 __private_extern__
void vm_object_page_remove(
497 vm_object_offset_t start
,
498 vm_object_offset_t end
);
500 __private_extern__
void vm_object_deactivate_pages(
502 vm_object_offset_t offset
,
503 vm_object_size_t size
,
505 boolean_t reusable_page
);
507 __private_extern__
void vm_object_reuse_pages(
509 vm_object_offset_t start_offset
,
510 vm_object_offset_t end_offset
,
511 boolean_t allow_partial_reuse
);
513 __private_extern__
void vm_object_purge(
516 __private_extern__ kern_return_t
vm_object_purgable_control(
518 vm_purgable_t control
,
521 __private_extern__ boolean_t
vm_object_coalesce(
522 vm_object_t prev_object
,
523 vm_object_t next_object
,
524 vm_object_offset_t prev_offset
,
525 vm_object_offset_t next_offset
,
526 vm_object_size_t prev_size
,
527 vm_object_size_t next_size
);
529 __private_extern__ boolean_t
vm_object_shadow(
531 vm_object_offset_t
*offset
,
532 vm_object_size_t length
);
534 __private_extern__
void vm_object_collapse(
536 vm_object_offset_t offset
,
537 boolean_t can_bypass
);
539 __private_extern__ boolean_t
vm_object_copy_quickly(
540 vm_object_t
*_object
,
541 vm_object_offset_t src_offset
,
542 vm_object_size_t size
,
543 boolean_t
*_src_needs_copy
,
544 boolean_t
*_dst_needs_copy
);
546 __private_extern__ kern_return_t
vm_object_copy_strategically(
547 vm_object_t src_object
,
548 vm_object_offset_t src_offset
,
549 vm_object_size_t size
,
550 vm_object_t
*dst_object
,
551 vm_object_offset_t
*dst_offset
,
552 boolean_t
*dst_needs_copy
);
554 __private_extern__ kern_return_t
vm_object_copy_slowly(
555 vm_object_t src_object
,
556 vm_object_offset_t src_offset
,
557 vm_object_size_t size
,
558 boolean_t interruptible
,
559 vm_object_t
*_result_object
);
561 __private_extern__ vm_object_t
vm_object_copy_delayed(
562 vm_object_t src_object
,
563 vm_object_offset_t src_offset
,
564 vm_object_size_t size
,
565 boolean_t src_object_shared
);
569 __private_extern__ kern_return_t
vm_object_destroy(
571 kern_return_t reason
);
573 __private_extern__
void vm_object_pager_create(
576 __private_extern__
void vm_object_page_map(
578 vm_object_offset_t offset
,
579 vm_object_size_t size
,
580 vm_object_offset_t (*map_fn
)
581 (void *, vm_object_offset_t
),
584 __private_extern__ kern_return_t
vm_object_upl_request(
586 vm_object_offset_t offset
,
589 upl_page_info_t
*page_info
,
593 __private_extern__ kern_return_t
vm_object_transpose(
596 vm_object_size_t transpose_size
);
598 __private_extern__ boolean_t
vm_object_sync(
600 vm_object_offset_t offset
,
601 vm_object_size_t size
,
602 boolean_t should_flush
,
603 boolean_t should_return
,
604 boolean_t should_iosync
);
606 __private_extern__ kern_return_t
vm_object_update(
608 vm_object_offset_t offset
,
609 vm_object_size_t size
,
610 vm_object_offset_t
*error_offset
,
612 memory_object_return_t should_return
,
616 __private_extern__ kern_return_t
vm_object_lock_request(
618 vm_object_offset_t offset
,
619 vm_object_size_t size
,
620 memory_object_return_t should_return
,
626 __private_extern__ vm_object_t
vm_object_enter(
627 memory_object_t pager
,
628 vm_object_size_t size
,
631 boolean_t check_named
);
634 __private_extern__
void vm_object_cluster_size(
636 vm_object_offset_t
*start
,
638 vm_object_fault_info_t fault_info
,
639 uint32_t *io_streaming
);
641 __private_extern__ kern_return_t
vm_object_populate_with_private(
643 vm_object_offset_t offset
,
647 extern kern_return_t
adjust_vm_object_cache(
651 extern kern_return_t
vm_object_page_op(
653 vm_object_offset_t offset
,
658 extern kern_return_t
vm_object_range_op(
660 vm_object_offset_t offset_beg
,
661 vm_object_offset_t offset_end
,
666 __private_extern__
void vm_object_reap_pages(
670 #define REAP_TERMINATE 1
671 #define REAP_PURGEABLE 2
672 #define REAP_DATA_FLUSH 3
676 * Event waiting handling
679 #define VM_OBJECT_EVENT_INITIALIZED 0
680 #define VM_OBJECT_EVENT_PAGER_READY 1
681 #define VM_OBJECT_EVENT_PAGING_IN_PROGRESS 2
682 #define VM_OBJECT_EVENT_MAPPING_IN_PROGRESS 3
683 #define VM_OBJECT_EVENT_LOCK_IN_PROGRESS 4
684 #define VM_OBJECT_EVENT_UNCACHING 5
685 #define VM_OBJECT_EVENT_COPY_CALL 6
686 #define VM_OBJECT_EVENT_CACHING 7
687 #define VM_OBJECT_EVENT_UNBLOCKED 8
688 #define VM_OBJECT_EVENT_PAGING_ONLY_IN_PROGRESS 9
690 #define vm_object_assert_wait(object, event, interruptible) \
691 (((object)->all_wanted |= 1 << (event)), \
692 assert_wait((event_t)((vm_offset_t)(object)+(event)),(interruptible)))
694 #define vm_object_wait(object, event, interruptible) \
695 (vm_object_assert_wait((object),(event),(interruptible)), \
696 vm_object_unlock(object), \
697 thread_block(THREAD_CONTINUE_NULL)) \
699 #define thread_sleep_vm_object(object, event, interruptible) \
700 lck_rw_sleep(&(object)->Lock, LCK_SLEEP_DEFAULT, (event_t)(event), (interruptible))
702 #define vm_object_sleep(object, event, interruptible) \
703 (((object)->all_wanted |= 1 << (event)), \
704 thread_sleep_vm_object((object), \
705 ((vm_offset_t)(object)+(event)), (interruptible)))
707 #define vm_object_wakeup(object, event) \
709 if ((object)->all_wanted & (1 << (event))) \
710 thread_wakeup((event_t)((vm_offset_t)(object) + (event))); \
711 (object)->all_wanted &= ~(1 << (event)); \
714 #define vm_object_set_wanted(object, event) \
716 ((object)->all_wanted |= (1 << (event))); \
719 #define vm_object_wanted(object, event) \
720 ((object)->all_wanted & (1 << (event)))
723 * Routines implemented as macros
726 #include <libkern/OSDebug.h>
727 #define VM_PIP_DEBUG_BEGIN(object) \
729 int pip = ((object)->paging_in_progress + \
730 (object)->activity_in_progress); \
731 if (pip < VM_PIP_DEBUG_MAX_REFS) { \
732 (void) OSBacktrace(&(object)->pip_holders[pip].pip_retaddr[0], \
733 VM_PIP_DEBUG_STACK_FRAMES); \
736 #else /* VM_PIP_DEBUG */
737 #define VM_PIP_DEBUG_BEGIN(object)
738 #endif /* VM_PIP_DEBUG */
740 #define vm_object_activity_begin(object) \
742 vm_object_lock_assert_exclusive((object)); \
743 assert((object)->paging_in_progress >= 0); \
744 VM_PIP_DEBUG_BEGIN((object)); \
745 (object)->activity_in_progress++; \
748 #define vm_object_activity_end(object) \
750 vm_object_lock_assert_exclusive((object)); \
751 assert((object)->activity_in_progress > 0); \
752 (object)->activity_in_progress--; \
753 if ((object)->paging_in_progress == 0 && \
754 (object)->activity_in_progress == 0) \
755 vm_object_wakeup((object), \
756 VM_OBJECT_EVENT_PAGING_IN_PROGRESS); \
759 #define vm_object_paging_begin(object) \
761 vm_object_lock_assert_exclusive((object)); \
762 assert((object)->paging_in_progress >= 0); \
763 VM_PIP_DEBUG_BEGIN((object)); \
764 (object)->paging_in_progress++; \
767 #define vm_object_paging_end(object) \
769 vm_object_lock_assert_exclusive((object)); \
770 assert((object)->paging_in_progress > 0); \
771 (object)->paging_in_progress--; \
772 if ((object)->paging_in_progress == 0) { \
773 vm_object_wakeup((object), \
774 VM_OBJECT_EVENT_PAGING_ONLY_IN_PROGRESS); \
775 if ((object)->activity_in_progress == 0) \
776 vm_object_wakeup((object), \
777 VM_OBJECT_EVENT_PAGING_IN_PROGRESS); \
781 #define vm_object_paging_wait(object, interruptible) \
783 vm_object_lock_assert_exclusive((object)); \
784 while ((object)->paging_in_progress != 0 || \
785 (object)->activity_in_progress != 0) { \
788 _wr = vm_object_sleep((object), \
789 VM_OBJECT_EVENT_PAGING_IN_PROGRESS, \
792 /*XXX if ((interruptible) && (_wr != THREAD_AWAKENED))*/\
797 #define vm_object_paging_only_wait(object, interruptible) \
799 vm_object_lock_assert_exclusive((object)); \
800 while ((object)->paging_in_progress != 0) { \
803 _wr = vm_object_sleep((object), \
804 VM_OBJECT_EVENT_PAGING_ONLY_IN_PROGRESS,\
807 /*XXX if ((interruptible) && (_wr != THREAD_AWAKENED))*/\
813 #define vm_object_mapping_begin(object) \
815 vm_object_lock_assert_exclusive((object)); \
816 assert(! (object)->mapping_in_progress); \
817 (object)->mapping_in_progress = TRUE; \
820 #define vm_object_mapping_end(object) \
822 vm_object_lock_assert_exclusive((object)); \
823 assert((object)->mapping_in_progress); \
824 (object)->mapping_in_progress = FALSE; \
825 vm_object_wakeup((object), \
826 VM_OBJECT_EVENT_MAPPING_IN_PROGRESS); \
829 #define vm_object_mapping_wait(object, interruptible) \
831 vm_object_lock_assert_exclusive((object)); \
832 while ((object)->mapping_in_progress) { \
835 _wr = vm_object_sleep((object), \
836 VM_OBJECT_EVENT_MAPPING_IN_PROGRESS, \
838 /*XXX if ((interruptible) && (_wr != THREAD_AWAKENED))*/\
841 assert(!(object)->mapping_in_progress); \
846 #define OBJECT_LOCK_SHARED 0
847 #define OBJECT_LOCK_EXCLUSIVE 1
849 extern lck_grp_t vm_object_lck_grp
;
850 extern lck_grp_attr_t vm_object_lck_grp_attr
;
851 extern lck_attr_t vm_object_lck_attr
;
852 extern lck_attr_t kernel_object_lck_attr
;
854 extern vm_object_t vm_pageout_scan_wants_object
;
856 extern void vm_object_lock(vm_object_t
);
857 extern boolean_t
vm_object_lock_try(vm_object_t
);
858 extern boolean_t
_vm_object_lock_try(vm_object_t
);
859 extern boolean_t
vm_object_lock_avoid(vm_object_t
);
860 extern void vm_object_lock_shared(vm_object_t
);
861 extern boolean_t
vm_object_lock_try_shared(vm_object_t
);
864 * Object locking macros
867 #define vm_object_lock_init(object) \
868 lck_rw_init(&(object)->Lock, &vm_object_lck_grp, \
869 (((object) == kernel_object || \
870 (object) == vm_submap_object) ? \
871 &kernel_object_lck_attr : \
872 &vm_object_lck_attr))
873 #define vm_object_lock_destroy(object) lck_rw_destroy(&(object)->Lock, &vm_object_lck_grp)
875 #define vm_object_unlock(object) lck_rw_done(&(object)->Lock)
876 #define vm_object_lock_upgrade(object) lck_rw_lock_shared_to_exclusive(&(object)->Lock)
877 #define vm_object_lock_try_scan(object) _vm_object_lock_try(object)
880 * CAUTION: the following vm_object_lock_assert_held*() macros merely
881 * check if anyone is holding the lock, but the holder may not necessarily
885 #define vm_object_lock_assert_held(object) \
886 lck_rw_assert(&(object)->Lock, LCK_RW_ASSERT_HELD)
887 #define vm_object_lock_assert_shared(object) \
888 lck_rw_assert(&(object)->Lock, LCK_RW_ASSERT_SHARED)
889 #define vm_object_lock_assert_exclusive(object) \
890 lck_rw_assert(&(object)->Lock, LCK_RW_ASSERT_EXCLUSIVE)
892 #define vm_object_lock_assert_held(object)
893 #define vm_object_lock_assert_shared(object)
894 #define vm_object_lock_assert_exclusive(object)
897 #define vm_object_round_page(x) (((vm_object_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
898 #define vm_object_trunc_page(x) ((vm_object_offset_t)(x) & ~((signed)PAGE_MASK))
900 #endif /* _VM_VM_OBJECT_H_ */