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