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