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
;
117 queue_head_t memq
; /* Resident memory */
118 lck_rw_t Lock
; /* Synchronization */
120 vm_object_size_t size
; /* Object size (only valid
123 struct vm_page
*memq_hint
;
124 int ref_count
; /* Number of references */
126 int res_count
; /* Residency references (swap)*/
127 #endif /* TASK_SWAPPER */
128 unsigned int resident_page_count
;
129 /* number of resident pages */
130 unsigned int wired_page_count
; /* number of wired pages */
131 unsigned int reusable_page_count
;
133 struct vm_object
*copy
; /* Object that should receive
134 * a copy of my changed pages,
135 * for copy_delay, or just the
136 * temporary object that
137 * shadows this object, for
140 struct vm_object
*shadow
; /* My shadow */
141 vm_object_offset_t shadow_offset
; /* Offset into shadow */
143 memory_object_t pager
; /* Where to get data */
144 vm_object_offset_t paging_offset
; /* Offset into memory object */
145 memory_object_control_t pager_control
; /* Where data comes back */
147 memory_object_copy_strategy_t
148 copy_strategy
; /* How to handle data copy */
150 short paging_in_progress
;
151 /* The memory object ports are
152 * being used (e.g., for pagein
153 * or pageout) -- don't change
154 * any of these fields (i.e.,
155 * don't collapse, destroy or
158 short activity_in_progress
;
161 /* boolean_t array */ all_wanted
:11, /* Bit array of "want to be
162 * awakened" notations. See
163 * VM_OBJECT_EVENT_* items
165 /* boolean_t */ pager_created
:1, /* Has pager been created? */
166 /* boolean_t */ pager_initialized
:1, /* Are fields ready to use? */
167 /* boolean_t */ pager_ready
:1, /* Will pager take requests? */
169 /* boolean_t */ pager_trusted
:1,/* The pager for this object
170 * is trusted. This is true for
171 * all internal objects (backed
172 * by the default pager)
174 /* boolean_t */ can_persist
:1, /* The kernel may keep the data
175 * for this object (and rights
176 * to the memory object) after
177 * all address map references
180 /* boolean_t */ internal
:1, /* Created by the kernel (and
181 * therefore, managed by the
182 * default memory manger)
184 /* boolean_t */ temporary
:1, /* Permanent objects may be
185 * changed externally by the
186 * memory manager, and changes
187 * made in memory must be
188 * reflected back to the memory
189 * manager. Temporary objects
193 /* boolean_t */ private:1, /* magic device_pager object,
194 * holds private pages only */
195 /* boolean_t */ pageout
:1, /* pageout object. contains
196 * private pages that refer to
197 * a real memory object. */
198 /* boolean_t */ alive
:1, /* Not yet terminated */
200 /* boolean_t */ purgable
:2, /* Purgable state. See
203 /* boolean_t */ shadowed
:1, /* Shadow may exist */
204 /* boolean_t */ silent_overwrite
:1,
205 /* Allow full page overwrite
206 * without data_request if
208 /* boolean_t */ advisory_pageout
:1,
209 /* Instead of sending page
210 * via OOL, just notify
211 * pager that the kernel
212 * wants to discard it, page
213 * remains in object */
214 /* boolean_t */ true_share
:1,
215 /* This object is mapped
216 * in more than one place
217 * and hence cannot be
219 /* boolean_t */ terminating
:1,
220 /* Allows vm_object_lookup
221 * and vm_object_deallocate
222 * to special case their
223 * behavior when they are
224 * called as a result of
225 * page cleaning during
228 /* boolean_t */ named
:1, /* An enforces an internal
229 * naming convention, by
230 * calling the right routines
232 * destruction, UBC references
233 * against the vm_object are
236 /* boolean_t */ shadow_severed
:1,
237 /* When a permanent object
238 * backing a COW goes away
239 * unexpectedly. This bit
240 * allows vm_fault to return
241 * an error rather than a
244 /* boolean_t */ phys_contiguous
:1,
245 /* Memory is wired and
246 * guaranteed physically
247 * contiguous. However
248 * it is not device memory
249 * and obeys normal virtual
250 * memory rules w.r.t pmap
253 /* boolean_t */ nophyscache
:1;
254 /* When mapped at the
255 * pmap level, don't allow
256 * primary caching. (for
262 queue_chain_t cached_list
; /* Attachment point for the
263 * list of objects cached as a
264 * result of their can_persist
268 queue_head_t msr_q
; /* memory object synchronise
272 * the following fields are not protected by any locks
273 * they are updated via atomic compare and swap
275 vm_object_offset_t last_alloc
; /* last allocation offset */
276 int sequential
; /* sequential access size */
278 uint32_t pages_created
;
281 vm_external_map_t existence_map
; /* bitmap of pages written to
283 #endif /* MACH_PAGEMAP */
284 vm_offset_t cow_hint
; /* last page present in */
285 /* shadow but not in object */
287 struct vm_object
*paging_object
; /* object which pages to be
288 * swapped out are temporary
289 * put in current object
292 /* hold object lock when altering */
294 wimg_bits
:8, /* cache WIMG bits */
295 code_signed
:1, /* pages are signed and should be
296 validated; the signatures are stored
298 hashed
:1, /* object/pager entered in hash */
299 transposed
:1, /* object was transposed with another */
300 mapping_in_progress
:1, /* pager being mapped/unmapped */
305 __object2_unused_bits
:16; /* for expansion */
308 queue_head_t uplq
; /* List of outstanding upls */
309 #endif /* UPL_DEBUG */
313 * Keep track of the stack traces for the first holders
314 * of a "paging_in_progress" reference for this VM object.
316 #define VM_PIP_DEBUG_STACK_FRAMES 25 /* depth of each stack trace */
317 #define VM_PIP_DEBUG_MAX_REFS 10 /* track that many references */
318 struct __pip_backtrace
{
319 void *pip_retaddr
[VM_PIP_DEBUG_STACK_FRAMES
];
320 } pip_holders
[VM_PIP_DEBUG_MAX_REFS
];
321 #endif /* VM_PIP_DEBUG */
323 queue_chain_t objq
; /* object queue - currently used for purgable queues */
326 #define VM_OBJECT_PURGEABLE_FAULT_ERROR(object) \
327 ((object)->volatile_fault && \
328 ((object)->purgable == VM_PURGABLE_VOLATILE || \
329 (object)->purgable == VM_PURGABLE_EMPTY))
331 #define VM_PAGE_REMOVE(page) \
333 vm_page_t __page = (page); \
334 vm_object_t __object = __page->object; \
335 if (__page == __object->memq_hint) { \
336 vm_page_t __new_hint; \
337 queue_entry_t __qe; \
338 __qe = queue_next(&__page->listq); \
339 if (queue_end(&__object->memq, __qe)) { \
340 __qe = queue_prev(&__page->listq); \
341 if (queue_end(&__object->memq, __qe)) { \
345 __new_hint = (vm_page_t) __qe; \
346 __object->memq_hint = __new_hint; \
348 queue_remove(&__object->memq, __page, vm_page_t, listq); \
351 #define VM_PAGE_INSERT(page, object) \
353 vm_page_t __page = (page); \
354 vm_object_t __object = (object); \
355 queue_enter(&__object->memq, __page, vm_page_t, listq); \
356 __object->memq_hint = __page; \
360 vm_object_t kernel_object
; /* the single kernel object */
363 unsigned int vm_object_absent_max
; /* maximum number of absent pages
364 at a time for each object */
366 # define VM_MSYNC_INITIALIZED 0
367 # define VM_MSYNC_SYNCHRONIZING 1
368 # define VM_MSYNC_DONE 2
371 queue_chain_t msr_q
; /* object request queue */
372 queue_chain_t req_q
; /* vm_msync request queue */
374 vm_object_offset_t offset
;
375 vm_object_size_t length
;
376 vm_object_t object
; /* back pointer */
377 decl_lck_mtx_data(, msync_req_lock
) /* Lock for this structure */
380 typedef struct msync_req
*msync_req_t
;
381 #define MSYNC_REQ_NULL ((msync_req_t) 0)
384 extern lck_grp_t vm_map_lck_grp
;
385 extern lck_attr_t vm_map_lck_attr
;
388 * Macros to allocate and free msync_reqs
390 #define msync_req_alloc(msr) \
392 (msr) = (msync_req_t)kalloc(sizeof(struct msync_req)); \
393 lck_mtx_init(&(msr)->msync_req_lock, &vm_map_lck_grp, &vm_map_lck_attr); \
394 msr->flag = VM_MSYNC_INITIALIZED; \
397 #define msync_req_free(msr) \
398 (kfree((msr), sizeof(struct msync_req)))
400 #define msr_lock(msr) lck_mtx_lock(&(msr)->msync_req_lock)
401 #define msr_unlock(msr) lck_mtx_unlock(&(msr)->msync_req_lock)
404 * Declare procedures that operate on VM objects.
407 __private_extern__
void vm_object_bootstrap(void) __attribute__((section("__TEXT, initcode")));
409 __private_extern__
void vm_object_init(void);
411 __private_extern__
void vm_object_init_lck_grp(void);
413 __private_extern__
void vm_object_reaper_init(void);
415 __private_extern__ vm_object_t
vm_object_allocate(
416 vm_object_size_t size
);
418 __private_extern__
void _vm_object_allocate(vm_object_size_t size
,
423 __private_extern__
void vm_object_res_reference(
425 __private_extern__
void vm_object_res_deallocate(
427 #define VM_OBJ_RES_INCR(object) (object)->res_count++
428 #define VM_OBJ_RES_DECR(object) (object)->res_count--
430 #else /* TASK_SWAPPER */
432 #define VM_OBJ_RES_INCR(object)
433 #define VM_OBJ_RES_DECR(object)
434 #define vm_object_res_reference(object)
435 #define vm_object_res_deallocate(object)
437 #endif /* TASK_SWAPPER */
439 #define vm_object_reference_locked(object) \
441 vm_object_t RLObject = (object); \
442 vm_object_lock_assert_exclusive(object); \
443 assert((RLObject)->ref_count > 0); \
444 (RLObject)->ref_count++; \
445 assert((RLObject)->ref_count > 1); \
446 vm_object_res_reference(RLObject); \
450 #define vm_object_reference_shared(object) \
452 vm_object_t RLObject = (object); \
453 vm_object_lock_assert_shared(object); \
454 assert((RLObject)->ref_count > 0); \
455 OSAddAtomic(1, &(RLObject)->ref_count); \
456 assert((RLObject)->ref_count > 1); \
457 /* XXX we would need an atomic version of the following ... */ \
458 vm_object_res_reference(RLObject); \
462 __private_extern__
void vm_object_reference(
467 #define vm_object_reference(object) \
469 vm_object_t RObject = (object); \
471 vm_object_lock_shared(RObject); \
472 vm_object_reference_shared(RObject); \
473 vm_object_unlock(RObject); \
477 #endif /* MACH_ASSERT */
479 __private_extern__
void vm_object_deallocate(
482 __private_extern__ kern_return_t
vm_object_release_name(
486 __private_extern__
void vm_object_pmap_protect(
488 vm_object_offset_t offset
,
489 vm_object_size_t size
,
491 vm_map_offset_t pmap_start
,
494 __private_extern__
void vm_object_page_remove(
496 vm_object_offset_t start
,
497 vm_object_offset_t end
);
499 __private_extern__
void vm_object_deactivate_pages(
501 vm_object_offset_t offset
,
502 vm_object_size_t size
,
504 boolean_t reusable_page
);
506 __private_extern__
void vm_object_reuse_pages(
508 vm_object_offset_t start_offset
,
509 vm_object_offset_t end_offset
,
510 boolean_t allow_partial_reuse
);
512 __private_extern__
void vm_object_purge(
515 __private_extern__ kern_return_t
vm_object_purgable_control(
517 vm_purgable_t control
,
520 __private_extern__ boolean_t
vm_object_coalesce(
521 vm_object_t prev_object
,
522 vm_object_t next_object
,
523 vm_object_offset_t prev_offset
,
524 vm_object_offset_t next_offset
,
525 vm_object_size_t prev_size
,
526 vm_object_size_t next_size
);
528 __private_extern__ boolean_t
vm_object_shadow(
530 vm_object_offset_t
*offset
,
531 vm_object_size_t length
);
533 __private_extern__
void vm_object_collapse(
535 vm_object_offset_t offset
,
536 boolean_t can_bypass
);
538 __private_extern__ boolean_t
vm_object_copy_quickly(
539 vm_object_t
*_object
,
540 vm_object_offset_t src_offset
,
541 vm_object_size_t size
,
542 boolean_t
*_src_needs_copy
,
543 boolean_t
*_dst_needs_copy
);
545 __private_extern__ kern_return_t
vm_object_copy_strategically(
546 vm_object_t src_object
,
547 vm_object_offset_t src_offset
,
548 vm_object_size_t size
,
549 vm_object_t
*dst_object
,
550 vm_object_offset_t
*dst_offset
,
551 boolean_t
*dst_needs_copy
);
553 __private_extern__ kern_return_t
vm_object_copy_slowly(
554 vm_object_t src_object
,
555 vm_object_offset_t src_offset
,
556 vm_object_size_t size
,
557 boolean_t interruptible
,
558 vm_object_t
*_result_object
);
560 __private_extern__ vm_object_t
vm_object_copy_delayed(
561 vm_object_t src_object
,
562 vm_object_offset_t src_offset
,
563 vm_object_size_t size
,
564 boolean_t src_object_shared
);
568 __private_extern__ kern_return_t
vm_object_destroy(
570 kern_return_t reason
);
572 __private_extern__
void vm_object_pager_create(
575 __private_extern__
void vm_object_page_map(
577 vm_object_offset_t offset
,
578 vm_object_size_t size
,
579 vm_object_offset_t (*map_fn
)
580 (void *, vm_object_offset_t
),
583 __private_extern__ kern_return_t
vm_object_upl_request(
585 vm_object_offset_t offset
,
588 upl_page_info_t
*page_info
,
592 __private_extern__ kern_return_t
vm_object_transpose(
595 vm_object_size_t transpose_size
);
597 __private_extern__ boolean_t
vm_object_sync(
599 vm_object_offset_t offset
,
600 vm_object_size_t size
,
601 boolean_t should_flush
,
602 boolean_t should_return
,
603 boolean_t should_iosync
);
605 __private_extern__ kern_return_t
vm_object_update(
607 vm_object_offset_t offset
,
608 vm_object_size_t size
,
609 vm_object_offset_t
*error_offset
,
611 memory_object_return_t should_return
,
615 __private_extern__ kern_return_t
vm_object_lock_request(
617 vm_object_offset_t offset
,
618 vm_object_size_t size
,
619 memory_object_return_t should_return
,
625 __private_extern__ vm_object_t
vm_object_enter(
626 memory_object_t pager
,
627 vm_object_size_t size
,
630 boolean_t check_named
);
633 __private_extern__
void vm_object_cluster_size(
635 vm_object_offset_t
*start
,
637 vm_object_fault_info_t fault_info
,
638 uint32_t *io_streaming
);
640 __private_extern__ kern_return_t
vm_object_populate_with_private(
642 vm_object_offset_t offset
,
646 extern kern_return_t
adjust_vm_object_cache(
650 extern kern_return_t
vm_object_page_op(
652 vm_object_offset_t offset
,
657 extern kern_return_t
vm_object_range_op(
659 vm_object_offset_t offset_beg
,
660 vm_object_offset_t offset_end
,
665 __private_extern__
void vm_object_reap_pages(
669 #define REAP_TERMINATE 1
670 #define REAP_PURGEABLE 2
671 #define REAP_DATA_FLUSH 3
675 * Event waiting handling
678 #define VM_OBJECT_EVENT_INITIALIZED 0
679 #define VM_OBJECT_EVENT_PAGER_READY 1
680 #define VM_OBJECT_EVENT_PAGING_IN_PROGRESS 2
681 #define VM_OBJECT_EVENT_MAPPING_IN_PROGRESS 3
682 #define VM_OBJECT_EVENT_LOCK_IN_PROGRESS 4
683 #define VM_OBJECT_EVENT_UNCACHING 5
684 #define VM_OBJECT_EVENT_COPY_CALL 6
685 #define VM_OBJECT_EVENT_CACHING 7
686 #define VM_OBJECT_EVENT_UNBLOCKED 8
687 #define VM_OBJECT_EVENT_PAGING_ONLY_IN_PROGRESS 9
689 #define vm_object_assert_wait(object, event, interruptible) \
690 (((object)->all_wanted |= 1 << (event)), \
691 assert_wait((event_t)((vm_offset_t)(object)+(event)),(interruptible)))
693 #define vm_object_wait(object, event, interruptible) \
694 (vm_object_assert_wait((object),(event),(interruptible)), \
695 vm_object_unlock(object), \
696 thread_block(THREAD_CONTINUE_NULL)) \
698 #define thread_sleep_vm_object(object, event, interruptible) \
699 lck_rw_sleep(&(object)->Lock, LCK_SLEEP_DEFAULT, (event_t)(event), (interruptible))
701 #define vm_object_sleep(object, event, interruptible) \
702 (((object)->all_wanted |= 1 << (event)), \
703 thread_sleep_vm_object((object), \
704 ((vm_offset_t)(object)+(event)), (interruptible)))
706 #define vm_object_wakeup(object, event) \
708 if ((object)->all_wanted & (1 << (event))) \
709 thread_wakeup((event_t)((vm_offset_t)(object) + (event))); \
710 (object)->all_wanted &= ~(1 << (event)); \
713 #define vm_object_set_wanted(object, event) \
715 ((object)->all_wanted |= (1 << (event))); \
718 #define vm_object_wanted(object, event) \
719 ((object)->all_wanted & (1 << (event)))
722 * Routines implemented as macros
725 #include <libkern/OSDebug.h>
726 #define VM_PIP_DEBUG_BEGIN(object) \
728 int pip = ((object)->paging_in_progress + \
729 (object)->activity_in_progress); \
730 if (pip < VM_PIP_DEBUG_MAX_REFS) { \
731 (void) OSBacktrace(&(object)->pip_holders[pip].pip_retaddr[0], \
732 VM_PIP_DEBUG_STACK_FRAMES); \
735 #else /* VM_PIP_DEBUG */
736 #define VM_PIP_DEBUG_BEGIN(object)
737 #endif /* VM_PIP_DEBUG */
739 #define vm_object_activity_begin(object) \
741 vm_object_lock_assert_exclusive((object)); \
742 assert((object)->paging_in_progress >= 0); \
743 VM_PIP_DEBUG_BEGIN((object)); \
744 (object)->activity_in_progress++; \
747 #define vm_object_activity_end(object) \
749 vm_object_lock_assert_exclusive((object)); \
750 assert((object)->activity_in_progress > 0); \
751 (object)->activity_in_progress--; \
752 if ((object)->paging_in_progress == 0 && \
753 (object)->activity_in_progress == 0) \
754 vm_object_wakeup((object), \
755 VM_OBJECT_EVENT_PAGING_IN_PROGRESS); \
758 #define vm_object_paging_begin(object) \
760 vm_object_lock_assert_exclusive((object)); \
761 assert((object)->paging_in_progress >= 0); \
762 VM_PIP_DEBUG_BEGIN((object)); \
763 (object)->paging_in_progress++; \
766 #define vm_object_paging_end(object) \
768 vm_object_lock_assert_exclusive((object)); \
769 assert((object)->paging_in_progress > 0); \
770 (object)->paging_in_progress--; \
771 if ((object)->paging_in_progress == 0) { \
772 vm_object_wakeup((object), \
773 VM_OBJECT_EVENT_PAGING_ONLY_IN_PROGRESS); \
774 if ((object)->activity_in_progress == 0) \
775 vm_object_wakeup((object), \
776 VM_OBJECT_EVENT_PAGING_IN_PROGRESS); \
780 #define vm_object_paging_wait(object, interruptible) \
782 vm_object_lock_assert_exclusive((object)); \
783 while ((object)->paging_in_progress != 0 || \
784 (object)->activity_in_progress != 0) { \
787 _wr = vm_object_sleep((object), \
788 VM_OBJECT_EVENT_PAGING_IN_PROGRESS, \
791 /*XXX if ((interruptible) && (_wr != THREAD_AWAKENED))*/\
796 #define vm_object_paging_only_wait(object, interruptible) \
798 vm_object_lock_assert_exclusive((object)); \
799 while ((object)->paging_in_progress != 0) { \
802 _wr = vm_object_sleep((object), \
803 VM_OBJECT_EVENT_PAGING_ONLY_IN_PROGRESS,\
806 /*XXX if ((interruptible) && (_wr != THREAD_AWAKENED))*/\
812 #define vm_object_mapping_begin(object) \
814 vm_object_lock_assert_exclusive((object)); \
815 assert(! (object)->mapping_in_progress); \
816 (object)->mapping_in_progress = TRUE; \
819 #define vm_object_mapping_end(object) \
821 vm_object_lock_assert_exclusive((object)); \
822 assert((object)->mapping_in_progress); \
823 (object)->mapping_in_progress = FALSE; \
824 vm_object_wakeup((object), \
825 VM_OBJECT_EVENT_MAPPING_IN_PROGRESS); \
828 #define vm_object_mapping_wait(object, interruptible) \
830 vm_object_lock_assert_exclusive((object)); \
831 while ((object)->mapping_in_progress) { \
834 _wr = vm_object_sleep((object), \
835 VM_OBJECT_EVENT_MAPPING_IN_PROGRESS, \
837 /*XXX if ((interruptible) && (_wr != THREAD_AWAKENED))*/\
840 assert(!(object)->mapping_in_progress); \
845 #define OBJECT_LOCK_SHARED 0
846 #define OBJECT_LOCK_EXCLUSIVE 1
848 extern lck_grp_t vm_object_lck_grp
;
849 extern lck_grp_attr_t vm_object_lck_grp_attr
;
850 extern lck_attr_t vm_object_lck_attr
;
851 extern lck_attr_t kernel_object_lck_attr
;
853 extern vm_object_t vm_pageout_scan_wants_object
;
855 extern void vm_object_lock(vm_object_t
);
856 extern boolean_t
vm_object_lock_try(vm_object_t
);
857 extern boolean_t
_vm_object_lock_try(vm_object_t
);
858 extern boolean_t
vm_object_lock_avoid(vm_object_t
);
859 extern void vm_object_lock_shared(vm_object_t
);
860 extern boolean_t
vm_object_lock_try_shared(vm_object_t
);
863 * Object locking macros
866 #define vm_object_lock_init(object) \
867 lck_rw_init(&(object)->Lock, &vm_object_lck_grp, \
868 (((object) == kernel_object || \
869 (object) == vm_submap_object) ? \
870 &kernel_object_lck_attr : \
871 &vm_object_lck_attr))
872 #define vm_object_lock_destroy(object) lck_rw_destroy(&(object)->Lock, &vm_object_lck_grp)
874 #define vm_object_unlock(object) lck_rw_done(&(object)->Lock)
875 #define vm_object_lock_upgrade(object) lck_rw_lock_shared_to_exclusive(&(object)->Lock)
876 #define vm_object_lock_try_scan(object) _vm_object_lock_try(object)
879 * CAUTION: the following vm_object_lock_assert_held*() macros merely
880 * check if anyone is holding the lock, but the holder may not necessarily
884 #define vm_object_lock_assert_held(object) \
885 lck_rw_assert(&(object)->Lock, LCK_RW_ASSERT_HELD)
886 #define vm_object_lock_assert_shared(object) \
887 lck_rw_assert(&(object)->Lock, LCK_RW_ASSERT_SHARED)
888 #define vm_object_lock_assert_exclusive(object) \
889 lck_rw_assert(&(object)->Lock, LCK_RW_ASSERT_EXCLUSIVE)
891 #define vm_object_lock_assert_held(object)
892 #define vm_object_lock_assert_shared(object)
893 #define vm_object_lock_assert_exclusive(object)
896 #define vm_object_round_page(x) (((vm_object_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
897 #define vm_object_trunc_page(x) ((vm_object_offset_t)(x) & ~((signed)PAGE_MASK))
899 #endif /* _VM_VM_OBJECT_H_ */