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