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