xref: /xnu-10063.121.3/osfmk/vm/vm_fault.h (revision 2c2f96dc2b9a4408a43d3150ae9c105355ca3daa)
1*2c2f96dcSApple OSS Distributions /*
2*2c2f96dcSApple OSS Distributions  * Copyright (c) 2000-2020 Apple Computer, Inc. All rights reserved.
3*2c2f96dcSApple OSS Distributions  *
4*2c2f96dcSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*2c2f96dcSApple OSS Distributions  *
6*2c2f96dcSApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*2c2f96dcSApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*2c2f96dcSApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*2c2f96dcSApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*2c2f96dcSApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*2c2f96dcSApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*2c2f96dcSApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*2c2f96dcSApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*2c2f96dcSApple OSS Distributions  *
15*2c2f96dcSApple OSS Distributions  * Please obtain a copy of the License at
16*2c2f96dcSApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*2c2f96dcSApple OSS Distributions  *
18*2c2f96dcSApple OSS Distributions  * The Original Code and all software distributed under the License are
19*2c2f96dcSApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*2c2f96dcSApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*2c2f96dcSApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*2c2f96dcSApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*2c2f96dcSApple OSS Distributions  * Please see the License for the specific language governing rights and
24*2c2f96dcSApple OSS Distributions  * limitations under the License.
25*2c2f96dcSApple OSS Distributions  *
26*2c2f96dcSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*2c2f96dcSApple OSS Distributions  */
28*2c2f96dcSApple OSS Distributions /*
29*2c2f96dcSApple OSS Distributions  * @OSF_COPYRIGHT@
30*2c2f96dcSApple OSS Distributions  */
31*2c2f96dcSApple OSS Distributions /*
32*2c2f96dcSApple OSS Distributions  * Mach Operating System
33*2c2f96dcSApple OSS Distributions  * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34*2c2f96dcSApple OSS Distributions  * All Rights Reserved.
35*2c2f96dcSApple OSS Distributions  *
36*2c2f96dcSApple OSS Distributions  * Permission to use, copy, modify and distribute this software and its
37*2c2f96dcSApple OSS Distributions  * documentation is hereby granted, provided that both the copyright
38*2c2f96dcSApple OSS Distributions  * notice and this permission notice appear in all copies of the
39*2c2f96dcSApple OSS Distributions  * software, derivative works or modified versions, and any portions
40*2c2f96dcSApple OSS Distributions  * thereof, and that both notices appear in supporting documentation.
41*2c2f96dcSApple OSS Distributions  *
42*2c2f96dcSApple OSS Distributions  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43*2c2f96dcSApple OSS Distributions  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44*2c2f96dcSApple OSS Distributions  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45*2c2f96dcSApple OSS Distributions  *
46*2c2f96dcSApple OSS Distributions  * Carnegie Mellon requests users of this software to return to
47*2c2f96dcSApple OSS Distributions  *
48*2c2f96dcSApple OSS Distributions  *  Software Distribution Coordinator  or  [email protected]
49*2c2f96dcSApple OSS Distributions  *  School of Computer Science
50*2c2f96dcSApple OSS Distributions  *  Carnegie Mellon University
51*2c2f96dcSApple OSS Distributions  *  Pittsburgh PA 15213-3890
52*2c2f96dcSApple OSS Distributions  *
53*2c2f96dcSApple OSS Distributions  * any improvements or extensions that they make and grant Carnegie Mellon
54*2c2f96dcSApple OSS Distributions  * the rights to redistribute these changes.
55*2c2f96dcSApple OSS Distributions  */
56*2c2f96dcSApple OSS Distributions /*
57*2c2f96dcSApple OSS Distributions  */
58*2c2f96dcSApple OSS Distributions /*
59*2c2f96dcSApple OSS Distributions  *	File:	vm/vm_fault.h
60*2c2f96dcSApple OSS Distributions  *
61*2c2f96dcSApple OSS Distributions  *	Page fault handling module declarations.
62*2c2f96dcSApple OSS Distributions  */
63*2c2f96dcSApple OSS Distributions 
64*2c2f96dcSApple OSS Distributions #ifndef _VM_VM_FAULT_H_
65*2c2f96dcSApple OSS Distributions #define _VM_VM_FAULT_H_
66*2c2f96dcSApple OSS Distributions 
67*2c2f96dcSApple OSS Distributions #include <mach/mach_types.h>
68*2c2f96dcSApple OSS Distributions #include <mach/kern_return.h>
69*2c2f96dcSApple OSS Distributions #include <mach/boolean.h>
70*2c2f96dcSApple OSS Distributions #include <mach/vm_prot.h>
71*2c2f96dcSApple OSS Distributions #include <mach/vm_param.h>
72*2c2f96dcSApple OSS Distributions #include <mach/vm_behavior.h>
73*2c2f96dcSApple OSS Distributions 
74*2c2f96dcSApple OSS Distributions #ifdef  KERNEL_PRIVATE
75*2c2f96dcSApple OSS Distributions 
76*2c2f96dcSApple OSS Distributions typedef kern_return_t   vm_fault_return_t;
77*2c2f96dcSApple OSS Distributions 
78*2c2f96dcSApple OSS Distributions #define VM_FAULT_SUCCESS                0
79*2c2f96dcSApple OSS Distributions #define VM_FAULT_RETRY                  1
80*2c2f96dcSApple OSS Distributions #define VM_FAULT_INTERRUPTED            2
81*2c2f96dcSApple OSS Distributions #define VM_FAULT_MEMORY_SHORTAGE        3
82*2c2f96dcSApple OSS Distributions #define VM_FAULT_MEMORY_ERROR           5
83*2c2f96dcSApple OSS Distributions #define VM_FAULT_SUCCESS_NO_VM_PAGE     6       /* success but no VM page */
84*2c2f96dcSApple OSS Distributions 
85*2c2f96dcSApple OSS Distributions /*
86*2c2f96dcSApple OSS Distributions  *	Page fault handling based on vm_map (or entries therein)
87*2c2f96dcSApple OSS Distributions  */
88*2c2f96dcSApple OSS Distributions 
89*2c2f96dcSApple OSS Distributions extern kern_return_t vm_fault(
90*2c2f96dcSApple OSS Distributions 	vm_map_t        map,
91*2c2f96dcSApple OSS Distributions 	vm_map_offset_t vaddr,
92*2c2f96dcSApple OSS Distributions 	vm_prot_t       fault_type,
93*2c2f96dcSApple OSS Distributions 	boolean_t       change_wiring,
94*2c2f96dcSApple OSS Distributions #if XNU_KERNEL_PRIVATE
95*2c2f96dcSApple OSS Distributions 	vm_tag_t        wire_tag,                   /* if wiring must pass tag != VM_KERN_MEMORY_NONE */
96*2c2f96dcSApple OSS Distributions #endif
97*2c2f96dcSApple OSS Distributions 	int             interruptible,
98*2c2f96dcSApple OSS Distributions 	pmap_t          pmap,
99*2c2f96dcSApple OSS Distributions 	vm_map_offset_t pmap_addr)
100*2c2f96dcSApple OSS Distributions #if XNU_KERNEL_PRIVATE
101*2c2f96dcSApple OSS Distributions __XNU_INTERNAL(vm_fault)
102*2c2f96dcSApple OSS Distributions #endif
103*2c2f96dcSApple OSS Distributions ;
104*2c2f96dcSApple OSS Distributions 
105*2c2f96dcSApple OSS Distributions extern void vm_pre_fault(vm_map_offset_t, vm_prot_t);
106*2c2f96dcSApple OSS Distributions 
107*2c2f96dcSApple OSS Distributions #ifdef  MACH_KERNEL_PRIVATE
108*2c2f96dcSApple OSS Distributions 
109*2c2f96dcSApple OSS Distributions #include <vm/vm_page.h>
110*2c2f96dcSApple OSS Distributions #include <vm/vm_object.h>
111*2c2f96dcSApple OSS Distributions #include <vm/vm_map.h>
112*2c2f96dcSApple OSS Distributions 
113*2c2f96dcSApple OSS Distributions extern void vm_fault_init(void);
114*2c2f96dcSApple OSS Distributions 
115*2c2f96dcSApple OSS Distributions /* exported kext version */
116*2c2f96dcSApple OSS Distributions extern kern_return_t vm_fault_external(
117*2c2f96dcSApple OSS Distributions 	vm_map_t        map,
118*2c2f96dcSApple OSS Distributions 	vm_map_offset_t vaddr,
119*2c2f96dcSApple OSS Distributions 	vm_prot_t       fault_type,
120*2c2f96dcSApple OSS Distributions 	boolean_t       change_wiring,
121*2c2f96dcSApple OSS Distributions 	int             interruptible,
122*2c2f96dcSApple OSS Distributions 	pmap_t          caller_pmap,
123*2c2f96dcSApple OSS Distributions 	vm_map_offset_t caller_pmap_addr);
124*2c2f96dcSApple OSS Distributions 
125*2c2f96dcSApple OSS Distributions /*
126*2c2f96dcSApple OSS Distributions  *	Page fault handling based on vm_object only.
127*2c2f96dcSApple OSS Distributions  */
128*2c2f96dcSApple OSS Distributions 
129*2c2f96dcSApple OSS Distributions extern vm_fault_return_t vm_fault_page(
130*2c2f96dcSApple OSS Distributions 	/* Arguments: */
131*2c2f96dcSApple OSS Distributions 	vm_object_t     first_object,           /* Object to begin search */
132*2c2f96dcSApple OSS Distributions 	vm_object_offset_t first_offset,        /* Offset into object */
133*2c2f96dcSApple OSS Distributions 	vm_prot_t       fault_type,             /* What access is requested */
134*2c2f96dcSApple OSS Distributions 	boolean_t       must_be_resident,        /* Must page be resident? */
135*2c2f96dcSApple OSS Distributions 	boolean_t       caller_lookup,          /* caller looked up page */
136*2c2f96dcSApple OSS Distributions 	/* Modifies in place: */
137*2c2f96dcSApple OSS Distributions 	vm_prot_t       *protection,            /* Protection for mapping */
138*2c2f96dcSApple OSS Distributions 	vm_page_t       *result_page,           /* Page found, if successful */
139*2c2f96dcSApple OSS Distributions 	/* Returns: */
140*2c2f96dcSApple OSS Distributions 	vm_page_t       *top_page,              /* Page in top object, if
141*2c2f96dcSApple OSS Distributions                                                  * not result_page.  */
142*2c2f96dcSApple OSS Distributions 	int             *type_of_fault,         /* if non-zero, return COW, zero-filled, etc...
143*2c2f96dcSApple OSS Distributions                                                  * used by kernel trace point in vm_fault */
144*2c2f96dcSApple OSS Distributions 	/* More arguments: */
145*2c2f96dcSApple OSS Distributions 	kern_return_t   *error_code,            /* code if page is in error */
146*2c2f96dcSApple OSS Distributions 	boolean_t       no_zero_fill,           /* don't fill absent pages */
147*2c2f96dcSApple OSS Distributions 	vm_object_fault_info_t fault_info);
148*2c2f96dcSApple OSS Distributions 
149*2c2f96dcSApple OSS Distributions extern void vm_fault_cleanup(
150*2c2f96dcSApple OSS Distributions 	vm_object_t     object,
151*2c2f96dcSApple OSS Distributions 	vm_page_t       top_page);
152*2c2f96dcSApple OSS Distributions 
153*2c2f96dcSApple OSS Distributions extern kern_return_t vm_fault_wire(
154*2c2f96dcSApple OSS Distributions 	vm_map_t        map,
155*2c2f96dcSApple OSS Distributions 	vm_map_entry_t  entry,
156*2c2f96dcSApple OSS Distributions 	vm_prot_t       prot,
157*2c2f96dcSApple OSS Distributions 	vm_tag_t        wire_tag,
158*2c2f96dcSApple OSS Distributions 	pmap_t          pmap,
159*2c2f96dcSApple OSS Distributions 	vm_map_offset_t pmap_addr,
160*2c2f96dcSApple OSS Distributions 	ppnum_t         *physpage_p);
161*2c2f96dcSApple OSS Distributions 
162*2c2f96dcSApple OSS Distributions extern void vm_fault_unwire(
163*2c2f96dcSApple OSS Distributions 	vm_map_t        map,
164*2c2f96dcSApple OSS Distributions 	vm_map_entry_t  entry,
165*2c2f96dcSApple OSS Distributions 	boolean_t       deallocate,
166*2c2f96dcSApple OSS Distributions 	pmap_t          pmap,
167*2c2f96dcSApple OSS Distributions 	vm_map_offset_t pmap_addr,
168*2c2f96dcSApple OSS Distributions 	vm_map_offset_t end_addr);
169*2c2f96dcSApple OSS Distributions 
170*2c2f96dcSApple OSS Distributions extern kern_return_t    vm_fault_copy(
171*2c2f96dcSApple OSS Distributions 	vm_object_t             src_object,
172*2c2f96dcSApple OSS Distributions 	vm_object_offset_t      src_offset,
173*2c2f96dcSApple OSS Distributions 	vm_map_size_t           *copy_size,             /* INOUT */
174*2c2f96dcSApple OSS Distributions 	vm_object_t             dst_object,
175*2c2f96dcSApple OSS Distributions 	vm_object_offset_t      dst_offset,
176*2c2f96dcSApple OSS Distributions 	vm_map_t                dst_map,
177*2c2f96dcSApple OSS Distributions 	vm_map_version_t         *dst_version,
178*2c2f96dcSApple OSS Distributions 	int                     interruptible);
179*2c2f96dcSApple OSS Distributions 
180*2c2f96dcSApple OSS Distributions extern kern_return_t vm_fault_enter(
181*2c2f96dcSApple OSS Distributions 	vm_page_t m,
182*2c2f96dcSApple OSS Distributions 	pmap_t pmap,
183*2c2f96dcSApple OSS Distributions 	vm_map_offset_t vaddr,
184*2c2f96dcSApple OSS Distributions 	vm_map_size_t fault_page_size,
185*2c2f96dcSApple OSS Distributions 	vm_map_offset_t fault_phys_offset,
186*2c2f96dcSApple OSS Distributions 	vm_prot_t prot,
187*2c2f96dcSApple OSS Distributions 	vm_prot_t fault_type,
188*2c2f96dcSApple OSS Distributions 	boolean_t wired,
189*2c2f96dcSApple OSS Distributions 	boolean_t change_wiring,
190*2c2f96dcSApple OSS Distributions 	vm_tag_t  wire_tag,             /* if wiring must pass tag != VM_KERN_MEMORY_NONE */
191*2c2f96dcSApple OSS Distributions 	vm_object_fault_info_t fault_info,
192*2c2f96dcSApple OSS Distributions 	boolean_t *need_retry,
193*2c2f96dcSApple OSS Distributions 	int *type_of_fault,
194*2c2f96dcSApple OSS Distributions 	uint8_t *object_lock_type);
195*2c2f96dcSApple OSS Distributions 
196*2c2f96dcSApple OSS Distributions extern vm_offset_t kdp_lightweight_fault(
197*2c2f96dcSApple OSS Distributions 	vm_map_t map,
198*2c2f96dcSApple OSS Distributions 	vm_offset_t cur_target_addr);
199*2c2f96dcSApple OSS Distributions 
200*2c2f96dcSApple OSS Distributions #endif  /* MACH_KERNEL_PRIVATE */
201*2c2f96dcSApple OSS Distributions 
202*2c2f96dcSApple OSS Distributions #if XNU_KERNEL_PRIVATE
203*2c2f96dcSApple OSS Distributions 
204*2c2f96dcSApple OSS Distributions boolean_t NEED_TO_HARD_THROTTLE_THIS_TASK(void);
205*2c2f96dcSApple OSS Distributions 
206*2c2f96dcSApple OSS Distributions #endif
207*2c2f96dcSApple OSS Distributions 
208*2c2f96dcSApple OSS Distributions #endif  /* KERNEL_PRIVATE */
209*2c2f96dcSApple OSS Distributions 
210*2c2f96dcSApple OSS Distributions #endif  /* _VM_VM_FAULT_H_ */
211