2 * Copyright (c) 2000-2005 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@
23 #include <sys/errno.h>
25 #include <mach/mach_types.h>
26 #include <mach/mach_traps.h>
27 #include <mach/host_priv.h>
28 #include <mach/kern_return.h>
29 #include <mach/memory_object_control.h>
30 #include <mach/memory_object_types.h>
31 #include <mach/port.h>
32 #include <mach/policy.h>
34 #include <mach/thread_act.h>
36 #include <kern/host.h>
37 #include <kern/thread.h>
39 #include <ipc/ipc_port.h>
40 #include <ipc/ipc_space.h>
42 #include <default_pager/default_pager_types.h>
43 #include <default_pager/default_pager_object_server.h>
45 #include <vm/vm_map.h>
46 #include <vm/vm_pageout.h>
47 #include <vm/memory_object.h>
48 #include <vm/vm_pageout.h>
49 #include <vm/vm_protos.h>
51 /* BSD VM COMPONENT INTERFACES */
71 return(map
->hdr
.nentries
);
75 mach_get_vm_start(vm_map_t map
)
77 return( vm_map_first_entry(map
)->vme_start
);
81 mach_get_vm_end(vm_map_t map
)
83 return( vm_map_last_entry(map
)->vme_end
);
87 * Legacy routines to get the start and end for a vm_map_t. They
88 * return them in the vm_offset_t format. So, they should only be
89 * called on maps that are the same size as the kernel map for
96 return(CAST_DOWN(vm_offset_t
, vm_map_first_entry(map
)->vme_start
));
103 return(CAST_DOWN(vm_offset_t
, vm_map_last_entry(map
)->vme_end
));
110 const struct memory_object_pager_ops vnode_pager_ops
= {
111 vnode_pager_reference
,
112 vnode_pager_deallocate
,
114 vnode_pager_terminate
,
115 vnode_pager_data_request
,
116 vnode_pager_data_return
,
117 vnode_pager_data_initialize
,
118 vnode_pager_data_unlock
,
119 vnode_pager_synchronize
,
124 typedef struct vnode_pager
{
125 memory_object_pager_ops_t pager_ops
; /* == &vnode_pager_ops */
126 unsigned int pager_ikot
; /* JMM: fake ip_kotype() */
127 unsigned int ref_count
; /* reference count */
128 memory_object_control_t control_handle
; /* mem object control handle */
129 struct vnode
*vnode_handle
; /* vnode handle */
134 trigger_name_to_port( /* forward */
138 vnode_pager_cluster_read( /* forward */
144 vnode_pager_cluster_write( /* forward */
148 vm_object_offset_t
*,
154 vnode_object_create( /* forward */
158 vnode_pager_lookup( /* forward */
161 zone_t vnode_pager_zone
;
164 #define VNODE_PAGER_NULL ((vnode_pager_t) 0)
166 /* TODO: Should be set dynamically by vnode_pager_init() */
167 #define CLUSTER_SHIFT 1
169 /* TODO: Should be set dynamically by vnode_pager_bootstrap() */
170 #define MAX_VNODE 10000
176 #define PAGER_ALL 0xffffffff
177 #define PAGER_INIT 0x00000001
178 #define PAGER_PAGEIN 0x00000002
180 #define PAGER_DEBUG(LEVEL, A) {if ((pagerdebug & LEVEL)==LEVEL){printf A;}}
182 #define PAGER_DEBUG(LEVEL, A)
186 * Routine: macx_triggers
188 * Syscall interface to set the call backs for low and
193 struct macx_triggers_args
*args
)
195 int hi_water
= args
->hi_water
;
196 int low_water
= args
->low_water
;
197 int flags
= args
->flags
;
198 mach_port_t trigger_name
= args
->alert_port
;
200 memory_object_default_t default_pager
;
201 ipc_port_t trigger_port
;
203 default_pager
= MEMORY_OBJECT_DEFAULT_NULL
;
204 kr
= host_default_memory_manager(host_priv_self(),
206 if(kr
!= KERN_SUCCESS
) {
210 if ((flags
& SWAP_ENCRYPT_ON
) &&
211 (flags
& SWAP_ENCRYPT_OFF
)) {
212 /* can't have it both ways */
216 if (default_pager_init_flag
== 0) {
217 start_def_pager(NULL
);
218 default_pager_init_flag
= 1;
221 if (flags
& SWAP_ENCRYPT_ON
) {
222 /* ENCRYPTED SWAP: tell default_pager to encrypt */
223 default_pager_triggers(default_pager
,
227 } else if (flags
& SWAP_ENCRYPT_OFF
) {
228 /* ENCRYPTED SWAP: tell default_pager not to encrypt */
229 default_pager_triggers(default_pager
,
235 if (flags
& HI_WAT_ALERT
) {
236 trigger_port
= trigger_name_to_port(trigger_name
);
237 if(trigger_port
== NULL
) {
240 /* trigger_port is locked and active */
241 ipc_port_make_send_locked(trigger_port
);
243 default_pager_triggers(default_pager
,
245 HI_WAT_ALERT
, trigger_port
);
248 if (flags
& LO_WAT_ALERT
) {
249 trigger_port
= trigger_name_to_port(trigger_name
);
250 if(trigger_port
== NULL
) {
253 /* trigger_port is locked and active */
254 ipc_port_make_send_locked(trigger_port
);
255 /* and now its unlocked */
256 default_pager_triggers(default_pager
,
258 LO_WAT_ALERT
, trigger_port
);
262 * Set thread scheduling priority and policy for the current thread
263 * it is assumed for the time being that the thread setting the alert
264 * is the same one which will be servicing it.
266 * XXX This does not belong in the kernel XXX
269 thread_precedence_policy_data_t pre
;
270 thread_extended_policy_data_t ext
;
272 ext
.timeshare
= FALSE
;
273 pre
.importance
= INT32_MAX
;
275 thread_policy_set(current_thread(),
276 THREAD_EXTENDED_POLICY
,
277 (thread_policy_t
)&ext
,
278 THREAD_EXTENDED_POLICY_COUNT
);
280 thread_policy_set(current_thread(),
281 THREAD_PRECEDENCE_POLICY
,
282 (thread_policy_t
)&pre
,
283 THREAD_PRECEDENCE_POLICY_COUNT
);
286 current_thread()->options
|= TH_OPT_VMPRIV
;
295 trigger_name_to_port(
296 mach_port_t trigger_name
)
298 ipc_port_t trigger_port
;
301 if (trigger_name
== 0)
304 space
= current_space();
305 if(ipc_port_translate_receive(space
, (mach_port_name_t
)trigger_name
,
306 &trigger_port
) != KERN_SUCCESS
)
312 extern int uiomove64(addr64_t
, int, void *);
316 memory_object_control_uiomove(
317 memory_object_control_t control
,
318 memory_object_offset_t offset
,
331 vm_page_t page_run
[MAX_RUN
];
334 object
= memory_object_control_to_vm_object(control
);
335 if (object
== VM_OBJECT_NULL
) {
338 assert(!object
->internal
);
340 vm_object_lock(object
);
342 if (mark_dirty
&& object
->copy
!= VM_OBJECT_NULL
) {
344 * We can't modify the pages without honoring
345 * copy-on-write obligations first, so fall off
346 * this optimized path and fall back to the regular
349 vm_object_unlock(object
);
353 while (io_requested
&& retval
== 0) {
355 cur_needed
= (start_offset
+ io_requested
+ (PAGE_SIZE
- 1)) / PAGE_SIZE
;
357 if (cur_needed
> MAX_RUN
)
358 cur_needed
= MAX_RUN
;
360 for (cur_run
= 0; cur_run
< cur_needed
; ) {
362 if ((dst_page
= vm_page_lookup(object
, offset
)) == VM_PAGE_NULL
)
365 * Sync up on getting the busy bit
367 if ((dst_page
->busy
|| dst_page
->cleaning
)) {
369 * someone else is playing with the page... if we've
370 * already collected pages into this run, go ahead
371 * and process now, we can't block on this
372 * page while holding other pages in the BUSY state
373 * otherwise we will wait
377 PAGE_SLEEP(object
, dst_page
, THREAD_UNINT
);
381 * this routine is only called when copying
382 * to/from real files... no need to consider
383 * encrypted swap pages
385 assert(!dst_page
->encrypted
);
388 dst_page
->dirty
= TRUE
;
389 dst_page
->busy
= TRUE
;
391 page_run
[cur_run
++] = dst_page
;
393 offset
+= PAGE_SIZE_64
;
397 * we hit a 'hole' in the cache
398 * we bail at this point
399 * we'll unlock the object below
402 vm_object_unlock(object
);
404 for (i
= 0; i
< cur_run
; i
++) {
406 dst_page
= page_run
[i
];
408 if ((xsize
= PAGE_SIZE
- start_offset
) > io_requested
)
409 xsize
= io_requested
;
411 if ( (retval
= uiomove64((addr64_t
)(((addr64_t
)(dst_page
->phys_page
) << 12) + start_offset
), xsize
, uio
)) )
414 io_requested
-= xsize
;
417 vm_object_lock(object
);
419 for (i
= 0; i
< cur_run
; i
++) {
420 dst_page
= page_run
[i
];
422 PAGE_WAKEUP_DONE(dst_page
);
425 vm_object_unlock(object
);
435 vnode_pager_bootstrap(void)
437 register vm_size_t size
;
439 size
= (vm_size_t
) sizeof(struct vnode_pager
);
440 vnode_pager_zone
= zinit(size
, (vm_size_t
) MAX_VNODE
*size
,
441 PAGE_SIZE
, "vnode pager structures");
443 apple_protect_pager_bootstrap();
444 #endif /* __i386__ */
454 __unused memory_object_t pager
)
456 vnode_pager_t vnode_object
;
458 vnode_object
= vnode_object_create(vp
);
459 if (vnode_object
== VNODE_PAGER_NULL
)
460 panic("vnode_pager_setup: vnode_object_create() failed");
461 return((memory_object_t
)vnode_object
);
468 vnode_pager_init(memory_object_t mem_obj
,
469 memory_object_control_t control
,
475 vnode_pager_t vnode_object
;
477 memory_object_attr_info_data_t attributes
;
480 PAGER_DEBUG(PAGER_ALL
, ("vnode_pager_init: %p, %p, %x\n", mem_obj
, control
, pg_size
));
482 if (control
== MEMORY_OBJECT_CONTROL_NULL
)
483 return KERN_INVALID_ARGUMENT
;
485 vnode_object
= vnode_pager_lookup(mem_obj
);
487 memory_object_control_reference(control
);
489 vnode_object
->control_handle
= control
;
491 attributes
.copy_strategy
= MEMORY_OBJECT_COPY_DELAY
;
492 /* attributes.cluster_size = (1 << (CLUSTER_SHIFT + PAGE_SHIFT));*/
493 attributes
.cluster_size
= (1 << (PAGE_SHIFT
));
494 attributes
.may_cache_object
= TRUE
;
495 attributes
.temporary
= TRUE
;
497 kr
= memory_object_change_attributes(
499 MEMORY_OBJECT_ATTRIBUTE_INFO
,
500 (memory_object_info_t
) &attributes
,
501 MEMORY_OBJECT_ATTR_INFO_COUNT
);
502 if (kr
!= KERN_SUCCESS
)
503 panic("vnode_pager_init: memory_object_change_attributes() failed");
505 return(KERN_SUCCESS
);
512 vnode_pager_data_return(
513 memory_object_t mem_obj
,
514 memory_object_offset_t offset
,
516 memory_object_offset_t
*resid_offset
,
518 __unused boolean_t dirty
,
519 __unused boolean_t kernel_copy
,
522 register vnode_pager_t vnode_object
;
524 vnode_object
= vnode_pager_lookup(mem_obj
);
526 vnode_pager_cluster_write(vnode_object
, offset
, data_cnt
, resid_offset
, io_error
, upl_flags
);
532 vnode_pager_data_initialize(
533 __unused memory_object_t mem_obj
,
534 __unused memory_object_offset_t offset
,
535 __unused vm_size_t data_cnt
)
537 panic("vnode_pager_data_initialize");
542 vnode_pager_data_unlock(
543 __unused memory_object_t mem_obj
,
544 __unused memory_object_offset_t offset
,
545 __unused vm_size_t size
,
546 __unused vm_prot_t desired_access
)
552 vnode_pager_get_object_size(
553 memory_object_t mem_obj
,
554 memory_object_offset_t
*length
)
556 vnode_pager_t vnode_object
;
558 if (mem_obj
->mo_pager_ops
!= &vnode_pager_ops
) {
560 return KERN_INVALID_ARGUMENT
;
563 vnode_object
= vnode_pager_lookup(mem_obj
);
565 *length
= vnode_pager_get_filesize(vnode_object
->vnode_handle
);
570 vnode_pager_get_object_pathname(
571 memory_object_t mem_obj
,
575 vnode_pager_t vnode_object
;
577 if (mem_obj
->mo_pager_ops
!= &vnode_pager_ops
) {
578 return KERN_INVALID_ARGUMENT
;
581 vnode_object
= vnode_pager_lookup(mem_obj
);
583 return vnode_pager_get_pathname(vnode_object
->vnode_handle
,
589 vnode_pager_get_object_filename(
590 memory_object_t mem_obj
,
593 vnode_pager_t vnode_object
;
595 if (mem_obj
->mo_pager_ops
!= &vnode_pager_ops
) {
596 return KERN_INVALID_ARGUMENT
;
599 vnode_object
= vnode_pager_lookup(mem_obj
);
601 return vnode_pager_get_filename(vnode_object
->vnode_handle
,
609 vnode_pager_data_request(
610 memory_object_t mem_obj
,
611 memory_object_offset_t offset
,
616 vm_prot_t protection_required
)
618 register vnode_pager_t vnode_object
;
620 PAGER_DEBUG(PAGER_ALL
, ("vnode_pager_data_request: %x, %x, %x, %x\n", mem_obj
, offset
, length
, protection_required
));
622 vnode_object
= vnode_pager_lookup(mem_obj
);
624 PAGER_DEBUG(PAGER_PAGEIN
, ("vnode_pager_data_request: %x, %x, %x, %x, vnode_object %x\n", mem_obj
, offset
, length
, protection_required
, vnode_object
));
626 return vnode_pager_cluster_read(vnode_object
, offset
, length
);
633 vnode_pager_reference(
634 memory_object_t mem_obj
)
636 register vnode_pager_t vnode_object
;
637 unsigned int new_ref_count
;
639 vnode_object
= vnode_pager_lookup(mem_obj
);
640 new_ref_count
= hw_atomic_add(&vnode_object
->ref_count
, 1);
641 assert(new_ref_count
> 1);
648 vnode_pager_deallocate(
649 memory_object_t mem_obj
)
651 register vnode_pager_t vnode_object
;
653 PAGER_DEBUG(PAGER_ALL
, ("vnode_pager_deallocate: %x\n", mem_obj
));
655 vnode_object
= vnode_pager_lookup(mem_obj
);
657 if (hw_atomic_sub(&vnode_object
->ref_count
, 1) == 0) {
658 if (vnode_object
->vnode_handle
!= NULL
) {
659 vnode_pager_vrele(vnode_object
->vnode_handle
);
661 zfree(vnode_pager_zone
, vnode_object
);
670 vnode_pager_terminate(
674 memory_object_t mem_obj
)
676 PAGER_DEBUG(PAGER_ALL
, ("vnode_pager_terminate: %x\n", mem_obj
));
678 return(KERN_SUCCESS
);
685 vnode_pager_synchronize(
686 memory_object_t mem_obj
,
687 memory_object_offset_t offset
,
689 __unused vm_sync_t sync_flags
)
691 register vnode_pager_t vnode_object
;
693 PAGER_DEBUG(PAGER_ALL
, ("vnode_pager_synchronize: %x\n", mem_obj
));
695 vnode_object
= vnode_pager_lookup(mem_obj
);
697 memory_object_synchronize_completed(vnode_object
->control_handle
, offset
, length
);
699 return (KERN_SUCCESS
);
707 memory_object_t mem_obj
)
709 register vnode_pager_t vnode_object
;
711 PAGER_DEBUG(PAGER_ALL
, ("vnode_pager_unmap: %x\n", mem_obj
));
713 vnode_object
= vnode_pager_lookup(mem_obj
);
715 ubc_unmap(vnode_object
->vnode_handle
);
724 vnode_pager_cluster_write(
725 vnode_pager_t vnode_object
,
726 vm_object_offset_t offset
,
728 vm_object_offset_t
* resid_offset
,
737 if (upl_flags
& UPL_MSYNC
) {
739 upl_flags
|= UPL_VNODE_PAGER
;
741 if ( (upl_flags
& UPL_IOSYNC
) && io_error
)
742 upl_flags
|= UPL_KEEPCACHED
;
747 size
= (cnt
< (PAGE_SIZE
* MAX_UPL_TRANSFER
)) ? cnt
: (PAGE_SIZE
* MAX_UPL_TRANSFER
); /* effective max */
749 request_flags
= UPL_RET_ONLY_DIRTY
| UPL_COPYOUT_FROM
| UPL_CLEAN_IN_PLACE
|
750 UPL_SET_INTERNAL
| UPL_SET_LITE
;
752 kr
= memory_object_upl_request(vnode_object
->control_handle
,
753 offset
, size
, &upl
, NULL
, NULL
, request_flags
);
754 if (kr
!= KERN_SUCCESS
)
755 panic("vnode_pager_cluster_write: upl request failed\n");
757 vnode_pageout(vnode_object
->vnode_handle
,
758 upl
, (vm_offset_t
)0, offset
, size
, upl_flags
, &errno
);
760 if ( (upl_flags
& UPL_KEEPCACHED
) ) {
761 if ( (*io_error
= errno
) )
768 *resid_offset
= offset
;
771 vm_object_offset_t vnode_size
;
772 vm_object_offset_t base_offset
;
774 vm_page_t target_page
;
778 * this is the pageout path
780 vnode_size
= vnode_pager_get_filesize(vnode_object
->vnode_handle
);
782 if (vnode_size
> (offset
+ PAGE_SIZE
)) {
784 * preset the maximum size of the cluster
785 * and put us on a nice cluster boundary...
786 * and then clip the size to insure we
787 * don't request past the end of the underlying file
789 size
= PAGE_SIZE
* MAX_UPL_TRANSFER
;
790 base_offset
= offset
& ~((signed)(size
- 1));
792 if ((base_offset
+ size
) > vnode_size
)
793 size
= round_page_32(((vm_size_t
)(vnode_size
- base_offset
)));
796 * we've been requested to page out a page beyond the current
797 * end of the 'file'... don't try to cluster in this case...
798 * we still need to send this page through because it might
799 * be marked precious and the underlying filesystem may need
800 * to do something with it (besides page it out)...
802 base_offset
= offset
;
805 object
= memory_object_control_to_vm_object(vnode_object
->control_handle
);
807 if (object
== VM_OBJECT_NULL
)
808 panic("vnode_pager_cluster_write: NULL vm_object in control handle\n");
810 request_flags
= UPL_NOBLOCK
| UPL_FOR_PAGEOUT
| UPL_CLEAN_IN_PLACE
|
811 UPL_RET_ONLY_DIRTY
| UPL_COPYOUT_FROM
|
812 UPL_SET_INTERNAL
| UPL_SET_LITE
;
814 vm_object_lock(object
);
816 if ((target_page
= vm_page_lookup(object
, offset
)) != VM_PAGE_NULL
) {
818 * only pick up pages whose ticket number matches
819 * the ticket number of the page orginally targeted
822 ticket
= target_page
->page_ticket
;
824 request_flags
|= ((ticket
<< UPL_PAGE_TICKET_SHIFT
) & UPL_PAGE_TICKET_MASK
);
826 vm_object_unlock(object
);
828 vm_object_upl_request(object
, base_offset
, size
,
829 &upl
, NULL
, NULL
, request_flags
);
831 panic("vnode_pager_cluster_write: upl request failed\n");
833 vnode_pageout(vnode_object
->vnode_handle
,
834 upl
, (vm_offset_t
)0, upl
->offset
, upl
->size
, UPL_VNODE_PAGER
, NULL
);
843 vnode_pager_cluster_read(
844 vnode_pager_t vnode_object
,
845 vm_object_offset_t offset
,
851 assert(! (cnt
& PAGE_MASK
));
853 kret
= vnode_pagein(vnode_object
->vnode_handle
,
861 if(kret == PAGER_ABSENT) {
862 Need to work out the defs here, 1 corresponds to PAGER_ABSENT
863 defined in bsd/vm/vm_pager.h However, we should not be including
864 that file here it is a layering violation.
869 unsigned int count
= 0;
872 uplflags
= (UPL_NO_SYNC
|
876 kr
= memory_object_upl_request(vnode_object
->control_handle
,
878 &upl
, NULL
, &count
, uplflags
);
879 if (kr
== KERN_SUCCESS
) {
884 * We couldn't gather the page list, probably
885 * because the memory object doesn't have a link
886 * to a VM object anymore (forced unmount, for
887 * example). Just return an error to the vm_fault()
888 * path and let it handle it.
904 vnode_pager_release_from_cache(
907 memory_object_free_from_cache(
908 &realhost
, &vnode_pager_ops
, cnt
);
918 register vnode_pager_t vnode_object
;
920 vnode_object
= (struct vnode_pager
*) zalloc(vnode_pager_zone
);
921 if (vnode_object
== VNODE_PAGER_NULL
)
922 return(VNODE_PAGER_NULL
);
925 * The vm_map call takes both named entry ports and raw memory
926 * objects in the same parameter. We need to make sure that
927 * vm_map does not see this object as a named entry port. So,
928 * we reserve the second word in the object for a fake ip_kotype
929 * setting - that will tell vm_map to use it as a memory object.
931 vnode_object
->pager_ops
= &vnode_pager_ops
;
932 vnode_object
->pager_ikot
= IKOT_MEMORY_OBJECT
;
933 vnode_object
->ref_count
= 1;
934 vnode_object
->control_handle
= MEMORY_OBJECT_CONTROL_NULL
;
935 vnode_object
->vnode_handle
= vp
;
937 return(vnode_object
);
945 memory_object_t name
)
947 vnode_pager_t vnode_object
;
949 vnode_object
= (vnode_pager_t
)name
;
950 assert(vnode_object
->pager_ops
== &vnode_pager_ops
);
951 return (vnode_object
);
955 /*********************** proc_info implementation *************/
957 #include <sys/bsdtask_info.h>
959 static int fill_vnodeinfoforaddr( vm_map_entry_t entry
, uint32_t * vnodeaddr
, uint32_t * vid
);
963 fill_procregioninfo(task_t task
, uint64_t arg
, struct proc_regioninfo_internal
*pinfo
, uint32_t *vnodeaddr
, uint32_t *vid
)
966 vm_map_t map
= task
->map
;
967 vm_map_offset_t address
= (vm_map_offset_t
)arg
;
968 vm_map_entry_t tmp_entry
;
969 vm_map_entry_t entry
;
970 vm_map_offset_t start
;
971 vm_region_extended_info_data_t extended
;
972 vm_region_top_info_data_t top
;
975 if (map
== VM_MAP_NULL
)
978 vm_map_lock_read(map
);
981 if (!vm_map_lookup_entry(map
, start
, &tmp_entry
)) {
982 if ((entry
= tmp_entry
->vme_next
) == vm_map_to_entry(map
)) {
983 vm_map_unlock_read(map
);
990 start
= entry
->vme_start
;
992 pinfo
->pri_offset
= entry
->offset
;
993 pinfo
->pri_protection
= entry
->protection
;
994 pinfo
->pri_max_protection
= entry
->max_protection
;
995 pinfo
->pri_inheritance
= entry
->inheritance
;
996 pinfo
->pri_behavior
= entry
->behavior
;
997 pinfo
->pri_user_wired_count
= entry
->user_wired_count
;
998 pinfo
->pri_user_tag
= entry
->alias
;
1000 if (entry
->is_sub_map
) {
1001 pinfo
->pri_flags
|= PROC_REGION_SUBMAP
;
1003 if (entry
->is_shared
)
1004 pinfo
->pri_flags
|= PROC_REGION_SHARED
;
1008 extended
.protection
= entry
->protection
;
1009 extended
.user_tag
= entry
->alias
;
1010 extended
.pages_resident
= 0;
1011 extended
.pages_swapped_out
= 0;
1012 extended
.pages_shared_now_private
= 0;
1013 extended
.pages_dirtied
= 0;
1014 extended
.external_pager
= 0;
1015 extended
.shadow_depth
= 0;
1017 vm_map_region_walk(map
, start
, entry
, entry
->offset
, entry
->vme_end
- start
, &extended
);
1019 if (extended
.external_pager
&& extended
.ref_count
== 2 && extended
.share_mode
== SM_SHARED
)
1020 extended
.share_mode
= SM_PRIVATE
;
1022 top
.private_pages_resident
= 0;
1023 top
.shared_pages_resident
= 0;
1024 vm_map_region_top_walk(entry
, &top
);
1027 pinfo
->pri_pages_resident
= extended
.pages_resident
;
1028 pinfo
->pri_pages_shared_now_private
= extended
.pages_shared_now_private
;
1029 pinfo
->pri_pages_swapped_out
= extended
.pages_swapped_out
;
1030 pinfo
->pri_pages_dirtied
= extended
.pages_dirtied
;
1031 pinfo
->pri_ref_count
= extended
.ref_count
;
1032 pinfo
->pri_shadow_depth
= extended
.shadow_depth
;
1033 pinfo
->pri_share_mode
= extended
.share_mode
;
1035 pinfo
->pri_private_pages_resident
= top
.private_pages_resident
;
1036 pinfo
->pri_shared_pages_resident
= top
.shared_pages_resident
;
1037 pinfo
->pri_obj_id
= top
.obj_id
;
1039 pinfo
->pri_address
= (uint64_t)start
;
1040 pinfo
->pri_size
= (uint64_t)(entry
->vme_end
- start
);
1041 pinfo
->pri_depth
= 0;
1043 if ((vnodeaddr
!= 0) && (entry
->is_sub_map
== 0)) {
1044 *vnodeaddr
= (uint32_t)0;
1046 if (fill_vnodeinfoforaddr(entry
, vnodeaddr
, vid
) ==0) {
1047 vm_map_unlock_read(map
);
1052 vm_map_unlock_read(map
);
1057 fill_vnodeinfoforaddr(
1058 vm_map_entry_t entry
,
1059 uint32_t * vnodeaddr
,
1062 vm_object_t top_object
, object
;
1063 memory_object_t memory_object
;
1064 memory_object_pager_ops_t pager_ops
;
1069 if (entry
->is_sub_map
) {
1073 * The last object in the shadow chain has the
1074 * relevant pager information.
1076 top_object
= entry
->object
.vm_object
;
1077 if (top_object
== VM_OBJECT_NULL
) {
1078 object
= VM_OBJECT_NULL
;
1081 vm_object_lock(top_object
);
1082 for (object
= top_object
, shadow_depth
= 0;
1083 object
->shadow
!= VM_OBJECT_NULL
;
1084 object
= object
->shadow
, shadow_depth
++) {
1085 vm_object_lock(object
->shadow
);
1086 vm_object_unlock(object
);
1091 if (object
== VM_OBJECT_NULL
) {
1093 } else if (object
->internal
) {
1094 vm_object_unlock(object
);
1096 } else if (! object
->pager_ready
||
1097 object
->terminating
||
1099 vm_object_unlock(object
);
1102 memory_object
= object
->pager
;
1103 pager_ops
= memory_object
->mo_pager_ops
;
1104 if (pager_ops
== &vnode_pager_ops
) {
1105 kr
= vnode_pager_get_object_vnode(
1108 if (kr
!= KERN_SUCCESS
) {
1109 vm_object_unlock(object
);
1113 vm_object_unlock(object
);
1117 vm_object_unlock(object
);
1122 vnode_pager_get_object_vnode (
1123 memory_object_t mem_obj
,
1124 uint32_t * vnodeaddr
,
1127 vnode_pager_t vnode_object
;
1129 vnode_object
= vnode_pager_lookup(mem_obj
);
1130 if (vnode_object
->vnode_handle
) {
1131 *vnodeaddr
= (uint32_t)vnode_object
->vnode_handle
;
1132 *vid
= (uint32_t)vnode_vid((void *)vnode_object
->vnode_handle
);
1134 return(KERN_SUCCESS
);
1137 return(KERN_FAILURE
);