xref: /xnu-11215.61.5/osfmk/mach/vm_prot.h (revision 4f1223e81cd707a65cc109d0b8ad6653699da3c4)
1*4f1223e8SApple OSS Distributions /*
2*4f1223e8SApple OSS Distributions  * Copyright (c) 2000-2021 Apple Computer, Inc. All rights reserved.
3*4f1223e8SApple OSS Distributions  *
4*4f1223e8SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*4f1223e8SApple OSS Distributions  *
6*4f1223e8SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*4f1223e8SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*4f1223e8SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*4f1223e8SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*4f1223e8SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*4f1223e8SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*4f1223e8SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*4f1223e8SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*4f1223e8SApple OSS Distributions  *
15*4f1223e8SApple OSS Distributions  * Please obtain a copy of the License at
16*4f1223e8SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*4f1223e8SApple OSS Distributions  *
18*4f1223e8SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*4f1223e8SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*4f1223e8SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*4f1223e8SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*4f1223e8SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*4f1223e8SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*4f1223e8SApple OSS Distributions  * limitations under the License.
25*4f1223e8SApple OSS Distributions  *
26*4f1223e8SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*4f1223e8SApple OSS Distributions  */
28*4f1223e8SApple OSS Distributions /*
29*4f1223e8SApple OSS Distributions  * @OSF_COPYRIGHT@
30*4f1223e8SApple OSS Distributions  */
31*4f1223e8SApple OSS Distributions /*
32*4f1223e8SApple OSS Distributions  * Mach Operating System
33*4f1223e8SApple OSS Distributions  * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34*4f1223e8SApple OSS Distributions  * All Rights Reserved.
35*4f1223e8SApple OSS Distributions  *
36*4f1223e8SApple OSS Distributions  * Permission to use, copy, modify and distribute this software and its
37*4f1223e8SApple OSS Distributions  * documentation is hereby granted, provided that both the copyright
38*4f1223e8SApple OSS Distributions  * notice and this permission notice appear in all copies of the
39*4f1223e8SApple OSS Distributions  * software, derivative works or modified versions, and any portions
40*4f1223e8SApple OSS Distributions  * thereof, and that both notices appear in supporting documentation.
41*4f1223e8SApple OSS Distributions  *
42*4f1223e8SApple OSS Distributions  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43*4f1223e8SApple OSS Distributions  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44*4f1223e8SApple OSS Distributions  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45*4f1223e8SApple OSS Distributions  *
46*4f1223e8SApple OSS Distributions  * Carnegie Mellon requests users of this software to return to
47*4f1223e8SApple OSS Distributions  *
48*4f1223e8SApple OSS Distributions  *  Software Distribution Coordinator  or  [email protected]
49*4f1223e8SApple OSS Distributions  *  School of Computer Science
50*4f1223e8SApple OSS Distributions  *  Carnegie Mellon University
51*4f1223e8SApple OSS Distributions  *  Pittsburgh PA 15213-3890
52*4f1223e8SApple OSS Distributions  *
53*4f1223e8SApple OSS Distributions  * any improvements or extensions that they make and grant Carnegie Mellon
54*4f1223e8SApple OSS Distributions  * the rights to redistribute these changes.
55*4f1223e8SApple OSS Distributions  */
56*4f1223e8SApple OSS Distributions /*
57*4f1223e8SApple OSS Distributions  */
58*4f1223e8SApple OSS Distributions /*
59*4f1223e8SApple OSS Distributions  *	File:	mach/vm_prot.h
60*4f1223e8SApple OSS Distributions  *	Author:	Avadis Tevanian, Jr., Michael Wayne Young
61*4f1223e8SApple OSS Distributions  *
62*4f1223e8SApple OSS Distributions  *	Virtual memory protection definitions.
63*4f1223e8SApple OSS Distributions  *
64*4f1223e8SApple OSS Distributions  */
65*4f1223e8SApple OSS Distributions 
66*4f1223e8SApple OSS Distributions #ifndef _MACH_VM_PROT_H_
67*4f1223e8SApple OSS Distributions #define _MACH_VM_PROT_H_
68*4f1223e8SApple OSS Distributions 
69*4f1223e8SApple OSS Distributions /*
70*4f1223e8SApple OSS Distributions  *	Types defined:
71*4f1223e8SApple OSS Distributions  *
72*4f1223e8SApple OSS Distributions  *	vm_prot_t		VM protection values.
73*4f1223e8SApple OSS Distributions  */
74*4f1223e8SApple OSS Distributions 
75*4f1223e8SApple OSS Distributions typedef int             vm_prot_t;
76*4f1223e8SApple OSS Distributions 
77*4f1223e8SApple OSS Distributions /*
78*4f1223e8SApple OSS Distributions  *	Protection values, defined as bits within the vm_prot_t type
79*4f1223e8SApple OSS Distributions  *
80*4f1223e8SApple OSS Distributions  *  When making a new VM_PROT_*, update tests vm_parameter_validation_[user|kern]
81*4f1223e8SApple OSS Distributions  *  and their expected results; they deliberately call VM functions with invalid
82*4f1223e8SApple OSS Distributions  *  vm_prot values and you may be turning one of those invalid protections valid.
83*4f1223e8SApple OSS Distributions  */
84*4f1223e8SApple OSS Distributions 
85*4f1223e8SApple OSS Distributions #define VM_PROT_NONE    ((vm_prot_t) 0x00)
86*4f1223e8SApple OSS Distributions 
87*4f1223e8SApple OSS Distributions #define VM_PROT_READ    ((vm_prot_t) 0x01)      /* read permission */
88*4f1223e8SApple OSS Distributions #define VM_PROT_WRITE   ((vm_prot_t) 0x02)      /* write permission */
89*4f1223e8SApple OSS Distributions #define VM_PROT_EXECUTE ((vm_prot_t) 0x04)      /* execute permission */
90*4f1223e8SApple OSS Distributions 
91*4f1223e8SApple OSS Distributions /*
92*4f1223e8SApple OSS Distributions  *	The default protection for newly-created virtual memory
93*4f1223e8SApple OSS Distributions  */
94*4f1223e8SApple OSS Distributions 
95*4f1223e8SApple OSS Distributions #define VM_PROT_DEFAULT (VM_PROT_READ|VM_PROT_WRITE)
96*4f1223e8SApple OSS Distributions 
97*4f1223e8SApple OSS Distributions /*
98*4f1223e8SApple OSS Distributions  *	The maximum privileges possible, for parameter checking.
99*4f1223e8SApple OSS Distributions  */
100*4f1223e8SApple OSS Distributions 
101*4f1223e8SApple OSS Distributions #define VM_PROT_ALL     (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE)
102*4f1223e8SApple OSS Distributions 
103*4f1223e8SApple OSS Distributions /*
104*4f1223e8SApple OSS Distributions  *	This is an alias to VM_PROT_EXECUTE to identify callers that
105*4f1223e8SApple OSS Distributions  *	want to allocate an hardware assisted Read-only/read-write
106*4f1223e8SApple OSS Distributions  *	trusted path in userland.
107*4f1223e8SApple OSS Distributions  */
108*4f1223e8SApple OSS Distributions #define        VM_PROT_RORW_TP                 (VM_PROT_EXECUTE)
109*4f1223e8SApple OSS Distributions 
110*4f1223e8SApple OSS Distributions /*
111*4f1223e8SApple OSS Distributions  *	An invalid protection value.
112*4f1223e8SApple OSS Distributions  *	Used only by memory_object_lock_request to indicate no change
113*4f1223e8SApple OSS Distributions  *	to page locks.  Using -1 here is a bad idea because it
114*4f1223e8SApple OSS Distributions  *	looks like VM_PROT_ALL and then some.
115*4f1223e8SApple OSS Distributions  */
116*4f1223e8SApple OSS Distributions 
117*4f1223e8SApple OSS Distributions #define VM_PROT_NO_CHANGE_LEGACY       ((vm_prot_t) 0x08)
118*4f1223e8SApple OSS Distributions #define VM_PROT_NO_CHANGE              ((vm_prot_t) 0x01000000)
119*4f1223e8SApple OSS Distributions 
120*4f1223e8SApple OSS Distributions /*
121*4f1223e8SApple OSS Distributions  *      When a caller finds that he cannot obtain write permission on a
122*4f1223e8SApple OSS Distributions  *      mapped entry, the following flag can be used.  The entry will
123*4f1223e8SApple OSS Distributions  *      be made "needs copy" effectively copying the object (using COW),
124*4f1223e8SApple OSS Distributions  *      and write permission will be added to the maximum protections
125*4f1223e8SApple OSS Distributions  *      for the associated entry.
126*4f1223e8SApple OSS Distributions  */
127*4f1223e8SApple OSS Distributions 
128*4f1223e8SApple OSS Distributions #define VM_PROT_COPY            ((vm_prot_t) 0x10)
129*4f1223e8SApple OSS Distributions 
130*4f1223e8SApple OSS Distributions 
131*4f1223e8SApple OSS Distributions /*
132*4f1223e8SApple OSS Distributions  *	Another invalid protection value.
133*4f1223e8SApple OSS Distributions  *	Used only by memory_object_data_request upon an object
134*4f1223e8SApple OSS Distributions  *	which has specified a copy_call copy strategy. It is used
135*4f1223e8SApple OSS Distributions  *	when the kernel wants a page belonging to a copy of the
136*4f1223e8SApple OSS Distributions  *	object, and is only asking the object as a result of
137*4f1223e8SApple OSS Distributions  *	following a shadow chain. This solves the race between pages
138*4f1223e8SApple OSS Distributions  *	being pushed up by the memory manager and the kernel
139*4f1223e8SApple OSS Distributions  *	walking down the shadow chain.
140*4f1223e8SApple OSS Distributions  */
141*4f1223e8SApple OSS Distributions 
142*4f1223e8SApple OSS Distributions #define VM_PROT_WANTS_COPY      ((vm_prot_t) 0x10)
143*4f1223e8SApple OSS Distributions 
144*4f1223e8SApple OSS Distributions #ifdef PRIVATE
145*4f1223e8SApple OSS Distributions /*
146*4f1223e8SApple OSS Distributions  *	The caller wants this memory region treated as if it had a valid
147*4f1223e8SApple OSS Distributions  *	code signature.
148*4f1223e8SApple OSS Distributions  */
149*4f1223e8SApple OSS Distributions 
150*4f1223e8SApple OSS Distributions #define VM_PROT_TRUSTED         ((vm_prot_t) 0x20)
151*4f1223e8SApple OSS Distributions #endif /* PRIVATE */
152*4f1223e8SApple OSS Distributions 
153*4f1223e8SApple OSS Distributions /*
154*4f1223e8SApple OSS Distributions  *      Another invalid protection value.
155*4f1223e8SApple OSS Distributions  *	Indicates that the other protection bits are to be applied as a mask
156*4f1223e8SApple OSS Distributions  *	against the actual protection bits of the map entry.
157*4f1223e8SApple OSS Distributions  */
158*4f1223e8SApple OSS Distributions #define VM_PROT_IS_MASK         ((vm_prot_t) 0x40)
159*4f1223e8SApple OSS Distributions 
160*4f1223e8SApple OSS Distributions /*
161*4f1223e8SApple OSS Distributions  * Another invalid protection value to support execute-only protection.
162*4f1223e8SApple OSS Distributions  * VM_PROT_STRIP_READ is a special marker that tells mprotect to not
163*4f1223e8SApple OSS Distributions  * set VM_PROT_READ. We have to do it this way because existing code
164*4f1223e8SApple OSS Distributions  * expects the system to set VM_PROT_READ if VM_PROT_EXECUTE is set.
165*4f1223e8SApple OSS Distributions  * VM_PROT_EXECUTE_ONLY is just a convenience value to indicate that
166*4f1223e8SApple OSS Distributions  * the memory should be executable and explicitly not readable. It will
167*4f1223e8SApple OSS Distributions  * be ignored on platforms that do not support this type of protection.
168*4f1223e8SApple OSS Distributions  */
169*4f1223e8SApple OSS Distributions #define VM_PROT_STRIP_READ              ((vm_prot_t) 0x80)
170*4f1223e8SApple OSS Distributions #define VM_PROT_EXECUTE_ONLY    (VM_PROT_EXECUTE|VM_PROT_STRIP_READ)
171*4f1223e8SApple OSS Distributions 
172*4f1223e8SApple OSS Distributions #ifdef PRIVATE
173*4f1223e8SApple OSS Distributions /*
174*4f1223e8SApple OSS Distributions  * When using VM_PROT_COPY, fail instead of copying an executable mapping,
175*4f1223e8SApple OSS Distributions  * since that could cause code-signing violations.
176*4f1223e8SApple OSS Distributions  */
177*4f1223e8SApple OSS Distributions #define VM_PROT_COPY_FAIL_IF_EXECUTABLE ((vm_prot_t)0x100)
178*4f1223e8SApple OSS Distributions #endif /* PRIVATE */
179*4f1223e8SApple OSS Distributions 
180*4f1223e8SApple OSS Distributions /*
181*4f1223e8SApple OSS Distributions  * Another invalid protection value to support pager TPRO protection.
182*4f1223e8SApple OSS Distributions  * VM_PROT_TPRO is a special marker that tells the a pager to
183*4f1223e8SApple OSS Distributions  * set TPRO flags on a given entry. We do it this way to prevent
184*4f1223e8SApple OSS Distributions  * bloating the pager structures and it allows dyld to pass through
185*4f1223e8SApple OSS Distributions  * this flag in lieue of specifying explicit VM flags, allowing us to handle
186*4f1223e8SApple OSS Distributions  * the final permissions internally.
187*4f1223e8SApple OSS Distributions  */
188*4f1223e8SApple OSS Distributions #define VM_PROT_TPRO                    ((vm_prot_t) 0x200)
189*4f1223e8SApple OSS Distributions 
190*4f1223e8SApple OSS Distributions #if defined(__x86_64__)
191*4f1223e8SApple OSS Distributions /*
192*4f1223e8SApple OSS Distributions  * Another invalid protection value to support specifying different
193*4f1223e8SApple OSS Distributions  * execute permissions for user- and supervisor- modes.  When
194*4f1223e8SApple OSS Distributions  * MBE is enabled in a VM, VM_PROT_EXECUTE is used to indicate
195*4f1223e8SApple OSS Distributions  * supervisor-mode execute permission, and VM_PROT_UEXEC specifies
196*4f1223e8SApple OSS Distributions  * user-mode execute permission.  Currently only used by the
197*4f1223e8SApple OSS Distributions  * x86 Hypervisor kext.
198*4f1223e8SApple OSS Distributions  */
199*4f1223e8SApple OSS Distributions #define VM_PROT_UEXEC                   ((vm_prot_t) 0x8)     /* User-mode Execute Permission */
200*4f1223e8SApple OSS Distributions 
201*4f1223e8SApple OSS Distributions #define VM_PROT_ALLEXEC                 (VM_PROT_EXECUTE | VM_PROT_UEXEC)
202*4f1223e8SApple OSS Distributions #else
203*4f1223e8SApple OSS Distributions #define VM_PROT_ALLEXEC                 (VM_PROT_EXECUTE)
204*4f1223e8SApple OSS Distributions #endif /* defined(__x86_64__) */
205*4f1223e8SApple OSS Distributions 
206*4f1223e8SApple OSS Distributions 
207*4f1223e8SApple OSS Distributions #endif  /* _MACH_VM_PROT_H_ */
208