| 1 | /* |
| 2 | * Copyright (c) 2016 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
| 5 | * |
| 6 | * This file contains Original Code and/or Modifications of Original Code |
| 7 | * as defined in and that are subject to the Apple Public Source License |
| 8 | * Version 2.0 (the 'License'). You may not use this file except in |
| 9 | * compliance with the License. The rights granted to you under the License |
| 10 | * may not be used to create, or enable the creation or redistribution of, |
| 11 | * unlawful or unlicensed copies of an Apple operating system, or to |
| 12 | * circumvent, violate, or enable the circumvention or violation of, any |
| 13 | * terms of an Apple operating system software license agreement. |
| 14 | * |
| 15 | * Please obtain a copy of the License at |
| 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. |
| 17 | * |
| 18 | * The Original Code and all software distributed under the License are |
| 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
| 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
| 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
| 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
| 23 | * Please see the License for the specific language governing rights and |
| 24 | * limitations under the License. |
| 25 | * |
| 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
| 27 | */ |
| 28 | /* |
| 29 | * Mach Operating System |
| 30 | * Copyright (c) 1989 Carnegie-Mellon University |
| 31 | * Copyright (c) 1988 Carnegie-Mellon University |
| 32 | * Copyright (c) 1987 Carnegie-Mellon University |
| 33 | * All rights reserved. The CMU software License Agreement specifies |
| 34 | * the terms and conditions for use and redistribution. |
| 35 | */ |
| 36 | |
| 37 | /* |
| 38 | * EXC_GUARD related macros, namespace etc. |
| 39 | */ |
| 40 | |
| 41 | #ifndef _EXC_GUARD_H_ |
| 42 | #define _EXC_GUARD_H_ |
| 43 | |
| 44 | /* |
| 45 | * EXC_GUARD exception code namespace. |
| 46 | * |
| 47 | * code: |
| 48 | * +-------------------+----------------+--------------+ |
| 49 | * |[63:61] guard type | [60:32] flavor | [31:0] target| |
| 50 | * +-------------------+----------------+--------------+ |
| 51 | * |
| 52 | * subcode: |
| 53 | * +---------------------------------------------------+ |
| 54 | * |[63:0] guard identifier | |
| 55 | * +---------------------------------------------------+ |
| 56 | */ |
| 57 | |
| 58 | #define EXC_GUARD_DECODE_GUARD_TYPE(code) \ |
| 59 | ((((uint64_t)(code)) >> 61) & 0x7ull) |
| 60 | #define EXC_GUARD_DECODE_GUARD_FLAVOR(code) \ |
| 61 | ((((uint64_t)(code)) >> 32) & 0x1fffffff) |
| 62 | #define EXC_GUARD_DECODE_GUARD_TARGET(code) \ |
| 63 | ((uint32_t)(code)) |
| 64 | |
| 65 | /* EXC_GUARD types */ |
| 66 | |
| 67 | #define GUARD_TYPE_NONE 0x0 |
| 68 | |
| 69 | /* |
| 70 | * Mach port guards use the exception codes like this: |
| 71 | * |
| 72 | * code: |
| 73 | * +-----------------------------+----------------+-----------------+ |
| 74 | * |[63:61] GUARD_TYPE_MACH_PORT | [60:32] flavor | [31:0] port name| |
| 75 | * +-----------------------------+----------------+-----------------+ |
| 76 | * |
| 77 | * subcode: |
| 78 | * +----------------------------------------------------------------+ |
| 79 | * |[63:0] guard identifier | |
| 80 | * +----------------------------------------------------------------+ |
| 81 | */ |
| 82 | |
| 83 | #define GUARD_TYPE_MACH_PORT 0x1 /* guarded mach port */ |
| 84 | |
| 85 | /* |
| 86 | * File descriptor guards use the exception codes this: |
| 87 | * |
| 88 | * code: |
| 89 | * +-----------------------------+----------------+-----------------+ |
| 90 | * |[63:61] GUARD_TYPE_FD | [60:32] flavor | [31:0] fd | |
| 91 | * +-----------------------------+----------------+-----------------+ |
| 92 | * |
| 93 | * subcode: |
| 94 | * +----------------------------------------------------------------+ |
| 95 | * |[63:0] guard identifier | |
| 96 | * +----------------------------------------------------------------+ |
| 97 | */ |
| 98 | |
| 99 | #define GUARD_TYPE_FD 0x2 /* guarded file descriptor */ |
| 100 | |
| 101 | /* |
| 102 | * User generated guards use the exception codes this: |
| 103 | * |
| 104 | * code: |
| 105 | * +-----------------------------+----------------+-----------------+ |
| 106 | * |[63:61] GUARD_TYPE_USER | [60:32] unused | [31:0] namespc | |
| 107 | * +-----------------------------+----------------+-----------------+ |
| 108 | * |
| 109 | * subcode: |
| 110 | * +----------------------------------------------------------------+ |
| 111 | * |[63:0] reason_code | |
| 112 | * +----------------------------------------------------------------+ |
| 113 | */ |
| 114 | |
| 115 | #define GUARD_TYPE_USER 0x3 /* Userland assertions */ |
| 116 | |
| 117 | /* |
| 118 | * Vnode guards use the exception codes like this: |
| 119 | * |
| 120 | * code: |
| 121 | * +-----------------------------+----------------+-----------------+ |
| 122 | * |[63:61] GUARD_TYPE_VN | [60:32] flavor | [31:0] pid | |
| 123 | * +-----------------------------+----------------+-----------------+ |
| 124 | * |
| 125 | * subcode: |
| 126 | * +----------------------------------------------------------------+ |
| 127 | * |[63:0] guard identifier | |
| 128 | * +----------------------------------------------------------------+ |
| 129 | */ |
| 130 | |
| 131 | #define GUARD_TYPE_VN 0x4 /* guarded vnode */ |
| 132 | |
| 133 | /* |
| 134 | * VM guards use the exception codes like this: |
| 135 | * |
| 136 | * code: |
| 137 | * +-------------------------------+----------------+-----------------+ |
| 138 | * |[63:61] GUARD_TYPE_VIRT_MEMORY | [60:32] flavor | [31:0] unused | |
| 139 | * +-------------------------------+----------------+-----------------+ |
| 140 | * |
| 141 | * subcode: |
| 142 | * +----------------------------------------------------------------+ |
| 143 | * |[63:0] offset | |
| 144 | * +----------------------------------------------------------------+ |
| 145 | */ |
| 146 | |
| 147 | #define GUARD_TYPE_VIRT_MEMORY 0x5 /* VM operation violating guard */ |
| 148 | |
| 149 | /* |
| 150 | * Rejected syscalls use the exception codes like this: |
| 151 | * |
| 152 | * code: |
| 153 | * +-------------------------------+----------------+------------------+ |
| 154 | * |[63:61] GUARD_TYPE_REJECTED_SC | [60:32] unused | [31:0] mach_trap | |
| 155 | * +-------------------------------+----------------+------------------+ |
| 156 | * |
| 157 | * subcode: |
| 158 | * +----------------------------------------------------------------+ |
| 159 | * |[63:0] syscall (if mach_trap field is 0), or mach trap number | |
| 160 | * +----------------------------------------------------------------+ |
| 161 | */ |
| 162 | |
| 163 | #define GUARD_TYPE_REJECTED_SC 0x6 /* rejected system call trap */ |
| 164 | |
| 165 | #ifdef KERNEL |
| 166 | |
| 167 | #define EXC_GUARD_ENCODE_TYPE(code, type) \ |
| 168 | ((code) |= (((uint64_t)(type) & 0x7ull) << 61)) |
| 169 | #define EXC_GUARD_ENCODE_FLAVOR(code, flavor) \ |
| 170 | ((code) |= (((uint64_t)(flavor) & 0x1fffffffull) << 32)) |
| 171 | #define EXC_GUARD_ENCODE_TARGET(code, target) \ |
| 172 | ((code) |= (((uint64_t)(target) & 0xffffffffull))) |
| 173 | |
| 174 | #endif /* KERNEL */ |
| 175 | |
| 176 | #endif /* _EXC_GUARD_H_ */ |
| 177 | |