| 1 | /* |
| 2 | * Copyright (c) 2000-2006 Apple Computer, 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 | * @OSF_COPYRIGHT@ |
| 30 | */ |
| 31 | /* |
| 32 | * Mach Operating System |
| 33 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University |
| 34 | * All Rights Reserved. |
| 35 | * |
| 36 | * Permission to use, copy, modify and distribute this software and its |
| 37 | * documentation is hereby granted, provided that both the copyright |
| 38 | * notice and this permission notice appear in all copies of the |
| 39 | * software, derivative works or modified versions, and any portions |
| 40 | * thereof, and that both notices appear in supporting documentation. |
| 41 | * |
| 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" |
| 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR |
| 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. |
| 45 | * |
| 46 | * Carnegie Mellon requests users of this software to return to |
| 47 | * |
| 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU |
| 49 | * School of Computer Science |
| 50 | * Carnegie Mellon University |
| 51 | * Pittsburgh PA 15213-3890 |
| 52 | * |
| 53 | * any improvements or extensions that they make and grant Carnegie Mellon |
| 54 | * the rights to redistribute these changes. |
| 55 | */ |
| 56 | /* |
| 57 | * NOTICE: This file was modified by McAfee Research in 2004 to introduce |
| 58 | * support for mandatory and extensible security protections. This notice |
| 59 | * is included in support of clause 2.2 (b) of the Apple Public License, |
| 60 | * Version 2.0. |
| 61 | */ |
| 62 | /* |
| 63 | */ |
| 64 | /* |
| 65 | *	File:	mach/port.h |
| 66 | * |
| 67 | *	Definition of a Mach port |
| 68 | * |
| 69 | *	Mach ports are the endpoints to Mach-implemented communications |
| 70 | *	channels (usually uni-directional message queues, but other types |
| 71 | *	also exist). |
| 72 | * |
| 73 | *	Unique collections of these endpoints are maintained for each |
| 74 | *	Mach task. Each Mach port in the task's collection is given a |
| 75 | *	[task-local] name to identify it - and the the various "rights" |
| 76 | *	held by the task for that specific endpoint. |
| 77 | * |
| 78 | *	This header defines the types used to identify these Mach ports |
| 79 | *	and the various rights associated with them. For more info see: |
| 80 | * |
| 81 | *	<mach/mach_port.h> - manipulation of port rights in a given space |
| 82 | *	<mach/message.h> - message queue [and port right passing] mechanism |
| 83 | * |
| 84 | */ |
| 85 | |
| 86 | #ifndef _MACH_PORT_H_ |
| 87 | #define _MACH_PORT_H_ |
| 88 | |
| 89 | #include <sys/cdefs.h> |
| 90 | #include <stdint.h> |
| 91 | #include <mach/boolean.h> |
| 92 | #include <mach/machine/vm_types.h> |
| 93 | |
| 94 | /* |
| 95 | * Helpers to declare and lock down the expected size for structures. |
| 96 | * Some structures must remain a constant size due to performance or ABI implications. |
| 97 | * It's not necessarily an issue if you need to bump a size passed to these macros: act judiciously. |
| 98 | */ |
| 99 | #if __arm64__ |
| 100 | #define xnu_static_assert_struct_size(name, expected_size) _Static_assert(\ |
| 101 | 	sizeof(name) == expected_size, "struct changed size unexpectedly") |
| 102 | #else /* __arm64__ */ |
| 103 | /* Don't bother trying to lock down structure sizes on !__arm64__ */ |
| 104 | #define xnu_static_assert_struct_size(name, expected_size) _Static_assert(0 == 0, "no-op assert") |
| 105 | #endif /* __arm64__ */ |
| 106 | |
| 107 | #define xnu_static_assert_struct_size_kernel_user(name, expected_kernel_size, expected_user_size) \ |
| 108 | 	xnu_static_assert_struct_size(name, expected_user_size) |
| 109 | #ifdef __LP64__ |
| 110 | #define xnu_static_assert_struct_size_kernel_user64_user32(name, _kern_size, expected_user64_size, _u32_size) \ |
| 111 | 	xnu_static_assert_struct_size(name, expected_user64_size) |
| 112 | #else /* __LP64__ */ |
| 113 | #define xnu_static_assert_struct_size_kernel_user64_user32(name, _kern_size, _u64_size, expected_user32_size) \ |
| 114 | 	xnu_static_assert_struct_size(name, expected_user32_size) |
| 115 | #endif /* __LP64__ */ |
| 116 | |
| 117 | /* |
| 118 | *	mach_port_name_t - the local identity for a Mach port |
| 119 | * |
| 120 | *	The name is Mach port namespace specific. It is used to |
| 121 | *	identify the rights held for that port by the task whose |
| 122 | *	namespace is implied [or specifically provided]. |
| 123 | * |
| 124 | *	Use of this type usually implies just a name - no rights. |
| 125 | *	See mach_port_t for a type that implies a "named right." |
| 126 | * |
| 127 | */ |
| 128 | |
| 129 | typedef natural_t mach_port_name_t; |
| 130 | typedef mach_port_name_t *mach_port_name_array_t; |
| 131 | |
| 132 | |
| 133 | /* |
| 134 | *	mach_port_t - a named port right |
| 135 | * |
| 136 | *	In user-space, "rights" are represented by the name of the |
| 137 | *	right in the Mach port namespace. Even so, this type is |
| 138 | *	presented as a unique one to more clearly denote the presence |
| 139 | *	of a right coming along with the name. |
| 140 | * |
| 141 | *	Often, various rights for a port held in a single name space |
| 142 | *	will coalesce and are, therefore, be identified by a single name |
| 143 | *	[this is the case for send and receive rights]. But not |
| 144 | *	always [send-once rights currently get a unique name for |
| 145 | *	each right]. |
| 146 | * |
| 147 | */ |
| 148 | |
| 149 | #include <sys/_types.h> |
| 150 | #include <sys/_types/_mach_port_t.h> |
| 151 | |
| 152 | |
| 153 | typedef mach_port_t *mach_port_array_t; |
| 154 | |
| 155 | /* |
| 156 | * MACH_PORT_NULL is a legal value that can be carried in messages. |
| 157 | * It indicates the absence of any port or port rights. (A port |
| 158 | * argument keeps the message from being "simple", even if the |
| 159 | * value is MACH_PORT_NULL.) The value MACH_PORT_DEAD is also a legal |
| 160 | * value that can be carried in messages. It indicates |
| 161 | * that a port right was present, but it died. |
| 162 | */ |
| 163 | |
| 164 | #define MACH_PORT_NULL 0 /* intentional loose typing */ |
| 165 | #define MACH_PORT_DEAD ((mach_port_name_t) ~0) |
| 166 | #define MACH_PORT_VALID(name) \ |
| 167 | 	 (((name) != MACH_PORT_NULL) && \ |
| 168 | 	 ((name) != MACH_PORT_DEAD)) |
| 169 | |
| 170 | |
| 171 | /* |
| 172 | *	For kernel-selected [assigned] port names, the name is |
| 173 | *	comprised of two parts: a generation number and an index. |
| 174 | *	This approach keeps the exact same name from being generated |
| 175 | *	and reused too quickly [to catch right/reference counting bugs]. |
| 176 | *	The dividing line between the constituent parts is exposed so |
| 177 | *	that efficient "mach_port_name_t to data structure pointer" |
| 178 | *	conversion implementation can be made. |
| 179 | */ |
| 180 | |
| 181 | #define MACH_PORT_INDEX(name) ((name) >> 8) |
| 182 | #define MACH_PORT_GEN(name) (((name) & 0xff) << 24) |
| 183 | #define MACH_PORT_MAKE(index, gen) (((index) << 8) | ((gen) >> 24)) |
| 184 | |
| 185 | /* |
| 186 | * These are the different rights a task may have for a port. |
| 187 | * The MACH_PORT_RIGHT_* definitions are used as arguments |
| 188 | * to mach_port_allocate, mach_port_get_refs, etc, to specify |
| 189 | * a particular right to act upon. The mach_port_names and |
| 190 | * mach_port_type calls return bitmasks using the MACH_PORT_TYPE_* |
| 191 | * definitions. This is because a single name may denote |
| 192 | * multiple rights. |
| 193 | */ |
| 194 | |
| 195 | typedef natural_t mach_port_right_t; |
| 196 | |
| 197 | #define MACH_PORT_RIGHT_SEND ((mach_port_right_t) 0) |
| 198 | #define MACH_PORT_RIGHT_RECEIVE ((mach_port_right_t) 1) |
| 199 | #define MACH_PORT_RIGHT_SEND_ONCE ((mach_port_right_t) 2) |
| 200 | #define MACH_PORT_RIGHT_PORT_SET ((mach_port_right_t) 3) |
| 201 | #define MACH_PORT_RIGHT_DEAD_NAME ((mach_port_right_t) 4) |
| 202 | #define MACH_PORT_RIGHT_LABELH ((mach_port_right_t) 5) /* obsolete right */ |
| 203 | #define MACH_PORT_RIGHT_NUMBER ((mach_port_right_t) 6) /* right not implemented */ |
| 204 | |
| 205 | #define MACH_PORT_TYPE(right) \ |
| 206 | 	((mach_port_type_t)(((mach_port_type_t) 1) \ |
| 207 | 	<< ((right) + ((mach_port_right_t) 16)))) |
| 208 | |
| 209 | typedef natural_t mach_port_type_t; |
| 210 | typedef mach_port_type_t *mach_port_type_array_t; |
| 211 | |
| 212 | #define MACH_PORT_TYPE_NONE ((mach_port_type_t) 0L) |
| 213 | #define MACH_PORT_TYPE_SEND MACH_PORT_TYPE(MACH_PORT_RIGHT_SEND) |
| 214 | #define MACH_PORT_TYPE_RECEIVE MACH_PORT_TYPE(MACH_PORT_RIGHT_RECEIVE) |
| 215 | #define MACH_PORT_TYPE_SEND_ONCE MACH_PORT_TYPE(MACH_PORT_RIGHT_SEND_ONCE) |
| 216 | #define MACH_PORT_TYPE_PORT_SET MACH_PORT_TYPE(MACH_PORT_RIGHT_PORT_SET) |
| 217 | #define MACH_PORT_TYPE_DEAD_NAME MACH_PORT_TYPE(MACH_PORT_RIGHT_DEAD_NAME) |
| 218 | #define MACH_PORT_TYPE_LABELH MACH_PORT_TYPE(MACH_PORT_RIGHT_LABELH) /* obsolete */ |
| 219 | /* Dummy type bits that mach_port_type/mach_port_names can return. */ |
| 220 | #define MACH_PORT_TYPE_DNREQUEST 0x80000000 |
| 221 | #define MACH_PORT_TYPE_SPREQUEST 0x40000000 |
| 222 | #define MACH_PORT_TYPE_SPREQUEST_DELAYED 0x20000000 |
| 223 | |
| 224 | /* Convenient combinations. */ |
| 225 | |
| 226 | #define MACH_PORT_TYPE_SEND_RECEIVE \ |
| 227 | 	(MACH_PORT_TYPE_SEND|MACH_PORT_TYPE_RECEIVE) |
| 228 | #define MACH_PORT_TYPE_SEND_RIGHTS \ |
| 229 | 	(MACH_PORT_TYPE_SEND|MACH_PORT_TYPE_SEND_ONCE) |
| 230 | #define MACH_PORT_TYPE_PORT_RIGHTS \ |
| 231 | 	(MACH_PORT_TYPE_SEND_RIGHTS|MACH_PORT_TYPE_RECEIVE) |
| 232 | #define MACH_PORT_TYPE_PORT_OR_DEAD \ |
| 233 | 	(MACH_PORT_TYPE_PORT_RIGHTS|MACH_PORT_TYPE_DEAD_NAME) |
| 234 | #define MACH_PORT_TYPE_ALL_RIGHTS \ |
| 235 | 	(MACH_PORT_TYPE_PORT_OR_DEAD|MACH_PORT_TYPE_PORT_SET) |
| 236 | |
| 237 | /* User-references for capabilities. */ |
| 238 | |
| 239 | typedef natural_t mach_port_urefs_t; |
| 240 | typedef integer_t mach_port_delta_t; /* change in urefs */ |
| 241 | |
| 242 | /* Attributes of ports. (See mach_port_get_receive_status.) */ |
| 243 | |
| 244 | typedef natural_t mach_port_seqno_t; /* sequence number */ |
| 245 | typedef natural_t mach_port_mscount_t; /* make-send count */ |
| 246 | typedef natural_t mach_port_msgcount_t; /* number of msgs */ |
| 247 | typedef natural_t mach_port_rights_t; /* number of rights */ |
| 248 | |
| 249 | /* |
| 250 | *	Are there outstanding send rights for a given port? |
| 251 | */ |
| 252 | #define MACH_PORT_SRIGHTS_NONE 0 /* no srights */ |
| 253 | #define MACH_PORT_SRIGHTS_PRESENT 1 /* srights */ |
| 254 | typedef unsigned int mach_port_srights_t; /* status of send rights */ |
| 255 | |
| 256 | typedef struct mach_port_status { |
| 257 | 	mach_port_rights_t mps_pset; /* count of containing port sets */ |
| 258 | 	mach_port_seqno_t mps_seqno; /* sequence number */ |
| 259 | 	mach_port_mscount_t mps_mscount; /* make-send count */ |
| 260 | 	mach_port_msgcount_t mps_qlimit; /* queue limit */ |
| 261 | 	mach_port_msgcount_t mps_msgcount; /* number in the queue */ |
| 262 | 	mach_port_rights_t mps_sorights; /* how many send-once rights */ |
| 263 | 	boolean_t mps_srights; /* do send rights exist? */ |
| 264 | 	boolean_t mps_pdrequest; /* port-deleted requested? */ |
| 265 | 	boolean_t mps_nsrequest; /* no-senders requested? */ |
| 266 | 	natural_t mps_flags; /* port flags */ |
| 267 | } mach_port_status_t; |
| 268 | |
| 269 | /* System-wide values for setting queue limits on a port */ |
| 270 | #define MACH_PORT_QLIMIT_ZERO (0) |
| 271 | #define MACH_PORT_QLIMIT_BASIC (5) |
| 272 | #define MACH_PORT_QLIMIT_SMALL (16) |
| 273 | #define MACH_PORT_QLIMIT_LARGE (1024) |
| 274 | #define MACH_PORT_QLIMIT_KERNEL (65534) |
| 275 | #define MACH_PORT_QLIMIT_MIN MACH_PORT_QLIMIT_ZERO |
| 276 | #define MACH_PORT_QLIMIT_DEFAULT MACH_PORT_QLIMIT_BASIC |
| 277 | #define MACH_PORT_QLIMIT_MAX MACH_PORT_QLIMIT_LARGE |
| 278 | |
| 279 | typedef struct mach_port_limits { |
| 280 | 	mach_port_msgcount_t mpl_qlimit; /* number of msgs */ |
| 281 | } mach_port_limits_t; |
| 282 | |
| 283 | /* Possible values for mps_flags (part of mach_port_status_t) */ |
| 284 | #define MACH_PORT_STATUS_FLAG_TEMPOWNER 0x01 |
| 285 | #define MACH_PORT_STATUS_FLAG_GUARDED 0x02 |
| 286 | #define MACH_PORT_STATUS_FLAG_STRICT_GUARD 0x04 |
| 287 | #define MACH_PORT_STATUS_FLAG_IMP_DONATION 0x08 |
| 288 | #define MACH_PORT_STATUS_FLAG_REVIVE 0x10 |
| 289 | #define MACH_PORT_STATUS_FLAG_TASKPTR 0x20 |
| 290 | #define MACH_PORT_STATUS_FLAG_GUARD_IMMOVABLE_RECEIVE 0x40 |
| 291 | #define MACH_PORT_STATUS_FLAG_NO_GRANT 0x80 /* Obsolete */ |
| 292 | |
| 293 | typedef struct mach_port_info_ext { |
| 294 | 	mach_port_status_t mpie_status; |
| 295 | 	mach_port_msgcount_t mpie_boost_cnt; |
| 296 | 	uint32_t reserved[6]; |
| 297 | } mach_port_info_ext_t; |
| 298 | |
| 299 | typedef struct mach_port_guard_info { |
| 300 | 	uint64_t mpgi_guard; /* guard value */ |
| 301 | } mach_port_guard_info_t; |
| 302 | |
| 303 | typedef integer_t *mach_port_info_t; /* varying array of natural_t */ |
| 304 | |
| 305 | /* Flavors for mach_port_get/set/assert_attributes() */ |
| 306 | typedef int mach_port_flavor_t; |
| 307 | #define MACH_PORT_LIMITS_INFO 1 /* uses mach_port_limits_t */ |
| 308 | #define MACH_PORT_RECEIVE_STATUS 2 /* uses mach_port_status_t */ |
| 309 | #define MACH_PORT_DNREQUESTS_SIZE 3 /* info is int */ |
| 310 | #define MACH_PORT_TEMPOWNER 4 /* indicates receive right will be reassigned to another task */ |
| 311 | #define MACH_PORT_IMPORTANCE_RECEIVER 5 /* indicates recieve right accepts priority donation */ |
| 312 | #define MACH_PORT_DENAP_RECEIVER 6 /* indicates receive right accepts de-nap donation */ |
| 313 | #define MACH_PORT_INFO_EXT 7 /* uses mach_port_info_ext_t */ |
| 314 | #define MACH_PORT_GUARD_INFO 8 /* asserts if the strict guard value is correct */ |
| 315 | #define MACH_PORT_SERVICE_THROTTLED 9 /* info is an integer that indicates if service port is throttled or not */ |
| 316 | |
| 317 | #define MACH_PORT_LIMITS_INFO_COUNT ((natural_t) \ |
| 318 | 	(sizeof(mach_port_limits_t)/sizeof(natural_t))) |
| 319 | #define MACH_PORT_RECEIVE_STATUS_COUNT ((natural_t) \ |
| 320 | 	(sizeof(mach_port_status_t)/sizeof(natural_t))) |
| 321 | #define MACH_PORT_DNREQUESTS_SIZE_COUNT 1 |
| 322 | #define MACH_PORT_INFO_EXT_COUNT ((natural_t) \ |
| 323 | 	(sizeof(mach_port_info_ext_t)/sizeof(natural_t))) |
| 324 | #define MACH_PORT_GUARD_INFO_COUNT ((natural_t) \ |
| 325 | 	(sizeof(mach_port_guard_info_t)/sizeof(natural_t))) |
| 326 | #define MACH_PORT_SERVICE_THROTTLED_COUNT 1 |
| 327 | |
| 328 | /* |
| 329 | * Structure used to pass information about port allocation requests. |
| 330 | * Must be padded to 64-bits total length. |
| 331 | */ |
| 332 | typedef struct mach_port_qos { |
| 333 | 	unsigned int name:1; /* name given */ |
| 334 | 	unsigned int prealloc:1; /* prealloced message */ |
| 335 | 	boolean_t pad1:30; |
| 336 | 	natural_t len; |
| 337 | } mach_port_qos_t; |
| 338 | |
| 339 | /* |
| 340 | * Structure used to pass information about the service port |
| 341 | */ |
| 342 | #define MACH_SERVICE_PORT_INFO_STRING_NAME_MAX_BUF_LEN 255 /* Maximum length of the port string name buffer */ |
| 343 | |
| 344 | typedef struct mach_service_port_info { |
| 345 | 	char mspi_string_name[MACH_SERVICE_PORT_INFO_STRING_NAME_MAX_BUF_LEN]; /* Service port's string name */ |
| 346 | 	uint8_t mspi_domain_type; /* Service port domain */ |
| 347 | } mach_service_port_info_data_t; |
| 348 | |
| 349 | #define MACH_SERVICE_PORT_INFO_COUNT ((char) \ |
| 350 | 	(sizeof(mach_service_port_info_data_t)/sizeof(char))) |
| 351 | |
| 352 | typedef struct mach_service_port_info * mach_service_port_info_t; |
| 353 | |
| 354 | /* |
| 355 | * Platform binaries are not allowed to send OOL port array to any port. |
| 356 | * |
| 357 | * MACH_MSG_OOL_PORTS_DESCRIPTOR are allowed to be sent ONLY to receive |
| 358 | * rights that are explicitly allow to receive that descriptor. |
| 359 | * |
| 360 | * Such ports have a dedicated port type, and are created using the |
| 361 | * MPO_CONNECTION_PORT_WITH_PORT_ARRAY flag. |
| 362 | * |
| 363 | * Creation of such ports requires the binary to have the following entitlement. |
| 364 | */ |
| 365 | #define MACH_PORT_CONNECTION_PORT_WITH_PORT_ARRAY "com.apple.developer.allow-connection-port-with-port-array" |
| 366 | |
| 367 | /* Allows 1p process to create weak reply port */ |
| 368 | #define MACH_PORT_WEAK_REPLY_ENTITLEMENT "com.apple.private.allow-weak-reply-port" |
| 369 | |
| 370 | /* |
| 371 | * Flags for mach_port_options (used for |
| 372 | * invocation of mach_port_construct). |
| 373 | * Indicates attributes to be set for the newly |
| 374 | * allocated port. |
| 375 | */ |
| 376 | |
| 377 | /* MPO options flags */ |
| 378 | #define MPO_CONTEXT_AS_GUARD 0x01 /* Add guard to the port */ |
| 379 | #define MPO_QLIMIT 0x02 /* Set qlimit for the port msg queue */ |
| 380 | #define MPO_TEMPOWNER 0x04 /* Set the tempowner bit of the port */ |
| 381 | #define MPO_IMPORTANCE_RECEIVER 0x08 /* Mark the port as importance receiver */ |
| 382 | #define MPO_INSERT_SEND_RIGHT 0x10 /* Insert a send right for the port */ |
| 383 | #define MPO_STRICT 0x20 /* Apply strict guarding for port */ |
| 384 | #define MPO_DENAP_RECEIVER 0x40 /* Mark the port as App de-nap receiver */ |
| 385 | #define MPO_IMMOVABLE_RECEIVE 0x80 /* Mark the port as immovable; protected by the guard context */ |
| 386 | #define MPO_FILTER_MSG 0x100 /* Allow message filtering */ |
| 387 | #define MPO_TG_BLOCK_TRACKING 0x200 /* Track blocking relationship for thread group during sync IPC */ |
| 388 | #define MPO_ENFORCE_REPLY_PORT_SEMANTICS 0x2000 /* When talking to this port, local port of mach msg needs to follow reply port semantics.*/ |
| 389 | /* This service port has requested security hardening */ |
| 390 | #define MPO_STRICT_SERVICE_PORT (MPO_SERVICE_PORT | MPO_ENFORCE_REPLY_PORT_SEMANTICS) |
| 391 | |
| 392 | #define MPO_OPTIONS_MASK \ |
| 393 | (MPO_CONTEXT_AS_GUARD | \ |
| 394 | MPO_QLIMIT | \ |
| 395 | MPO_TEMPOWNER | \ |
| 396 | MPO_IMPORTANCE_RECEIVER | \ |
| 397 | MPO_INSERT_SEND_RIGHT | \ |
| 398 | MPO_STRICT | \ |
| 399 | MPO_DENAP_RECEIVER | \ |
| 400 | MPO_IMMOVABLE_RECEIVE | \ |
| 401 | MPO_FILTER_MSG | \ |
| 402 | MPO_TG_BLOCK_TRACKING | \ |
| 403 | MPO_ENFORCE_REPLY_PORT_SEMANTICS) |
| 404 | |
| 405 | /* MPO port type flags */ |
| 406 | #define MPO_MAKE_PORT_TYPE(a, b) (((a & 0x7) << 14) | ((b & 0x7) << 10)) |
| 407 | #define MPO_PORT_TYPE_MASK MPO_MAKE_PORT_TYPE(0x7, 0x7) /* 0x1dc00 */ |
| 408 | /* These need to be defined for libxpc and other clients who `#ifdef` */ |
| 409 | 	#define MPO_PORT MPO_PORT |
| 410 | 	#define MPO_SERVICE_PORT MPO_SERVICE_PORT |
| 411 | 	#define MPO_CONNECTION_PORT MPO_CONNECTION_PORT |
| 412 | 	#define MPO_REPLY_PORT MPO_REPLY_PORT |
| 413 | 	#define MPO_WEAK_REPLY_PORT MPO_WEAK_REPLY_PORT |
| 414 | 	#define MPO_NOTIFICATION_PORT MPO_NOTIFICATION_PORT |
| 415 | 	#define MPO_EXCEPTION_PORT MPO_EXCEPTION_PORT |
| 416 | 	#define MPO_CONNECTION_PORT_WITH_PORT_ARRAY MPO_CONNECTION_PORT_WITH_PORT_ARRAY |
| 417 | __options_decl(mpo_flags_t, uint32_t, { |
| 418 | 	/* Your classic IOT_PORT, an uninteresting message queue */ |
| 419 | 	MPO_PORT = MPO_MAKE_PORT_TYPE(0, 0), /* 0x0 */ |
| 420 | 	/* Create a service port with the given name; should be used only by launchd */ |
| 421 | 	MPO_SERVICE_PORT = MPO_MAKE_PORT_TYPE(0, 1), /* 0x400 */ |
| 422 | 	/* Derive new peer connection port from a given service port */ |
| 423 | 	MPO_CONNECTION_PORT = MPO_MAKE_PORT_TYPE(0, 2), /* 0x800 */ |
| 424 | 	/* Designate port as a reply port */ |
| 425 | 	MPO_REPLY_PORT = MPO_MAKE_PORT_TYPE(0, 4), /* 0x1000 */ |
| 426 | 	/* Designate port as a weak (fake) reply port */ |
| 427 | 	MPO_WEAK_REPLY_PORT = MPO_MAKE_PORT_TYPE(1, 0), /* 0x4000 */ |
| 428 | 	/* Designate port as a notification port */ |
| 429 | 	MPO_NOTIFICATION_PORT = MPO_MAKE_PORT_TYPE(1, 1), /* 0x4400 */ |
| 430 | 	/* Used for hardened exceptions - immovable */ |
| 431 | 	MPO_EXCEPTION_PORT = MPO_MAKE_PORT_TYPE(2, 0), /* 0x8000 */ |
| 432 | 	/* Can receive OOL port array descriptors */ |
| 433 | 	MPO_CONNECTION_PORT_WITH_PORT_ARRAY = MPO_MAKE_PORT_TYPE(4, 0), /* 0x10000 */ |
| 434 | }); |
| 435 | |
| 436 | /* For bincompat: weak reply port used to be called provisional reply port */ |
| 437 | #define MPO_PROVISIONAL_REPLY_PORT MPO_WEAK_REPLY_PORT |
| 438 | |
| 439 | #define MPO_UNUSED_BITS ~(MPO_OPTIONS_MASK | MPO_PORT_TYPE_MASK) |
| 440 | |
| 441 | /* Denotes an anonymous service */ |
| 442 | #define MPO_ANONYMOUS_SERVICE (MACH_PORT_DEAD - 1) |
| 443 | |
| 444 | /* |
| 445 | * Structure to define optional attributes for a newly |
| 446 | * constructed port. |
| 447 | */ |
| 448 | typedef struct mach_port_options { |
| 449 | 	uint32_t flags; |
| 450 | 	mach_port_limits_t mpl; /* Message queue limit for port */ |
| 451 | 	union { |
| 452 | 		uint64_t reserved[2]; /* Reserved */ |
| 453 | 		mach_port_name_t work_interval_port; /* Work interval port */ |
| 454 | 		mach_service_port_info_t service_port_info; /* Service port (MPO_SERVICE_PORT) */ |
| 455 | 		mach_port_name_t service_port_name; /* Service port (MPO_CONNECTION_PORT) */ |
| 456 | 	}; |
| 457 | }mach_port_options_t; |
| 458 | |
| 459 | typedef mach_port_options_t *mach_port_options_ptr_t; |
| 460 | |
| 461 | /* Mach Port Guarding definitions */ |
| 462 | |
| 463 | /* |
| 464 | * EXC_GUARD represents a guard violation for both |
| 465 | * mach ports and file descriptors. GUARD_TYPE_ is used |
| 466 | * to differentiate among them. |
| 467 | */ |
| 468 | #define GUARD_TYPE_MACH_PORT 0x1 |
| 469 | |
| 470 | /* |
| 471 | * Reasons for exception for a guarded mach port |
| 472 | * |
| 473 | * Arguments are documented in doc/mach_ipc/guard_exceptions.md, |
| 474 | * please update when adding a new type. |
| 475 | * |
| 476 | * Note: these had been designed as bitfields, |
| 477 | * hence the weird spaced values, |
| 478 | * but are truly an enum, please add new values in the "holes". |
| 479 | */ |
| 480 | enum mach_port_guard_exception_codes { |
| 481 | 	kGUARD_EXC_NONE = 0, /* never sent */ |
| 482 | 	kGUARD_EXC_DESTROY = 1, |
| 483 | 	kGUARD_EXC_MOD_REFS = 2, |
| 484 | 	kGUARD_EXC_INVALID_OPTIONS = 3, |
| 485 | 	kGUARD_EXC_SET_CONTEXT = 4, |
| 486 | 	kGUARD_EXC_THREAD_SET_STATE = 5, |
| 487 | 	kGUARD_EXC_EXCEPTION_BEHAVIOR_ENFORCE = 6, |
| 488 | 	kGUARD_EXC_SERVICE_PORT_VIOLATION_FATAL = 7, |
| 489 | 	kGUARD_EXC_UNGUARDED = 8, |
| 490 | 	kGUARD_EXC_KOBJECT_REPLY_PORT_SEMANTICS = 9, |
| 491 | 	kGUARD_EXC_REQUIRE_REPLY_PORT_SEMANTICS = 10, |
| 492 | 	kGUARD_EXC_INCORRECT_GUARD = 16, |
| 493 | 	kGUARD_EXC_IMMOVABLE = 32, |
| 494 | 	kGUARD_EXC_STRICT_REPLY = 64, |
| 495 | 	kGUARD_EXC_INVALID_NOTIFICATION_REQ = 65, |
| 496 | 	kGUARD_EXC_INVALID_MPO_ENTITLEMENT = 66, |
| 497 | 	kGUARD_EXC_DESCRIPTOR_VIOLATION = 67, |
| 498 | 	kGUARD_EXC_MSG_FILTERED = 128, |
| 499 | 	/* start of [optionally] non-fatal guards */ |
| 500 | 	kGUARD_EXC_INVALID_RIGHT = 256, |
| 501 | 	kGUARD_EXC_INVALID_NAME = 512, |
| 502 | 	kGUARD_EXC_INVALID_VALUE = 1u << 10, |
| 503 | 	kGUARD_EXC_INVALID_ARGUMENT = 1u << 11, /* really kGUARD_EXC_ALREADY_GUARDED */ |
| 504 | 	kGUARD_EXC_RIGHT_EXISTS = 1u << 12, /* unused */ |
| 505 | 	kGUARD_EXC_KERN_NO_SPACE = 1u << 13, /* unused */ |
| 506 | 	kGUARD_EXC_KERN_FAILURE = 1u << 14, /* really kGUARD_EXC_INVALID_PDREQUEST */ |
| 507 | 	kGUARD_EXC_KERN_RESOURCE = 1u << 15, /* unused */ |
| 508 | 	kGUARD_EXC_SEND_INVALID_REPLY = 1u << 16, |
| 509 | 	kGUARD_EXC_SEND_INVALID_VOUCHER = 1u << 17, |
| 510 | 	kGUARD_EXC_SEND_INVALID_RIGHT = 1u << 18, |
| 511 | 	kGUARD_EXC_RCV_INVALID_NAME = 1u << 19, |
| 512 | 	/* start of always non-fatal guards */ |
| 513 | 	kGUARD_EXC_RCV_GUARDED_DESC = 0x00100000, /* for development only */ |
| 514 | 	kGUARD_EXC_SERVICE_PORT_VIOLATION_NON_FATAL = 0x00100001, /* unused */ |
| 515 | 	kGUARD_EXC_INVALID_NOTIFICATION_PORT = 0x00100006, |
| 516 | 	kGUARD_EXC_MACH_EXC_THREAD_SET_STATE = 0x00100007, |
| 517 | 	kGUARD_EXC_CV_NOTIFICATION_PORT_REQ = 0x00100008, |
| 518 | 	kGUARD_EXC_WEAK_REPLY_PORT = 0x00100002, /* unused */ |
| 519 | 	kGUARD_EXC_OOL_PORT_ARRAY_CREATION = 0x00100003, /* unused */ |
| 520 | 	kGUARD_EXC_MOVE_WEAK_REPLY_PORT = 0x00100004, |
| 521 | 	kGUARD_EXC_REPLY_PORT_SINGLE_SO_RIGHT = 0x00100005, |
| 522 | 	kGUARD_EXC_MOD_REFS_NON_FATAL = 1u << 21, |
| 523 | 	kGUARD_EXC_IMMOVABLE_NON_FATAL = 1u << 22, /* unused */ |
| 524 | }; |
| 525 | |
| 526 | #define MAX_FATAL_kGUARD_EXC_CODE kGUARD_EXC_MSG_FILTERED |
| 527 | #define MAX_OPTIONAL_kGUARD_EXC_CODE kGUARD_EXC_RCV_INVALID_NAME |
| 528 | |
| 529 | /* Temporary! Should be removed after rdar://166892063 */ |
| 530 | #define kGUARD_EXC_PROVISIONAL_REPLY_PORT kGUARD_EXC_WEAK_REPLY_PORT |
| 531 | #define kGUARD_EXC_MOVE_PROVISIONAL_REPLY_PORT kGUARD_EXC_MOVE_WEAK_REPLY_PORT |
| 532 | |
| 533 | |
| 534 | /* |
| 535 | * Mach port guard flags. |
| 536 | */ |
| 537 | #define MPG_FLAGS_NONE 0x00 |
| 538 | |
| 539 | /* |
| 540 | * These flags are used as bits in the subcode of kGUARD_EXC_STRICT_REPLY exceptions. |
| 541 | */ |
| 542 | #define MPG_FLAGS_STRICT_REPLY_INVALID_VOUCHER 0x04 |
| 543 | #define MPG_FLAGS_STRICT_REPLY_MISMATCHED_PERSONA 0x10 |
| 544 | |
| 545 | /* |
| 546 | * These flags are used as bits in the subcode of kGUARD_EXC_MOD_REFS exceptions. |
| 547 | */ |
| 548 | #define MPG_FLAGS_MOD_REFS_PINNED_DEALLOC 0x01 |
| 549 | #define MPG_FLAGS_MOD_REFS_PINNED_DESTROY 0x02 |
| 550 | #define MPG_FLAGS_MOD_REFS_PINNED_COPYIN 0x03 |
| 551 | |
| 552 | /* |
| 553 | * These flags are used as bits in the subcode of kGUARD_EXC_INVALID_RIGHT exceptions. |
| 554 | */ |
| 555 | #define MPG_FLAGS_INVALID_RIGHT_RECV 0x01 /* does not have receive right */ |
| 556 | #define MPG_FLAGS_INVALID_RIGHT_DELTA 0x02 /* ipc_right_delta() */ |
| 557 | #define MPG_FLAGS_INVALID_RIGHT_DESTRUCT 0x03 /* ipc_right_destruct() */ |
| 558 | #define MPG_FLAGS_INVALID_RIGHT_COPYIN 0x04 /* ipc_right_copyin() */ |
| 559 | #define MPG_FLAGS_INVALID_RIGHT_DEALLOC 0x05 /* ipc_right_dealloc() */ |
| 560 | #define MPG_FLAGS_INVALID_RIGHT_DEALLOC_KERNEL 0x06 /* mach_port_deallocate_kernel() */ |
| 561 | #define MPG_FLAGS_INVALID_RIGHT_TRANSLATE_PORT 0x07 /* port in ipc_object_translate_port_pset() */ |
| 562 | #define MPG_FLAGS_INVALID_RIGHT_TRANSLATE_PSET 0x08 /* pset in ipc_object_translate_port_pset() */ |
| 563 | |
| 564 | /* |
| 565 | * These flags are used as bits in the subcode of kGUARD_EXC_INVALID_VALUE exceptions. |
| 566 | */ |
| 567 | #define MPG_FLAGS_INVALID_VALUE_PEEK 0x01 /* mach_port_peek() */ |
| 568 | #define MPG_FLAGS_INVALID_VALUE_DELTA 0x02 /* ipc_right_delta() */ |
| 569 | #define MPG_FLAGS_INVALID_VALUE_DESTRUCT 0x03 /* ipc_right_destruct() */ |
| 570 | |
| 571 | /* |
| 572 | * These flags are used as bits in the subcode of kGUARD_EXC_KERN_FAILURE exceptions. |
| 573 | */ |
| 574 | #define MPG_FLAGS_KERN_FAILURE_TASK 0x01 /* task other than launchd arm pd on service ports */ |
| 575 | #define MPG_FLAGS_KERN_FAILURE_NOTIFY_TYPE 0x02 /* not using IOT_NOTIFICATION_PORT for pd notification */ |
| 576 | #define MPG_FLAGS_KERN_FAILURE_NOTIFY_RECV 0x03 /* notification port not owned by launchd */ |
| 577 | #define MPG_FLAGS_KERN_FAILURE_MULTI_NOTI 0x04 /* register multiple pd notification */ |
| 578 | |
| 579 | /* |
| 580 | * These flags are used as bits in the subcode of kGUARD_EXC_SEND_INVALID_RIGHT exceptions. |
| 581 | */ |
| 582 | #define MPG_FLAGS_SEND_INVALID_RIGHT_PORT 0x01 /* ipc_kmsg_copyin_port_descriptor() */ |
| 583 | #define MPG_FLAGS_SEND_INVALID_RIGHT_OOL_PORT 0x02 /* ipc_kmsg_copyin_ool_ports_descriptor() */ |
| 584 | #define MPG_FLAGS_SEND_INVALID_RIGHT_GUARDED 0x03 /* ipc_kmsg_copyin_guarded_port_descriptor */ |
| 585 | |
| 586 | /* |
| 587 | * These flags are used as bits in the subcode of kGUARD_EXC_INVALID_OPTIONS exceptions. |
| 588 | */ |
| 589 | #define MPG_FLAGS_INVALID_OPTIONS_OOL_DISP 0x01 /* ipc_kmsg_copyin_ool_ports_descriptor() */ |
| 590 | #define MPG_FLAGS_INVALID_OPTIONS_OOL_ARRAYS 0x02 /* ipc_validate_kmsg_header_from_user() */ |
| 591 | #define MPG_FLAGS_INVALID_OPTIONS_OOL_RIGHT 0x03 /* ipc_validate_kmsg_header_from_user() */ |
| 592 | |
| 593 | /* |
| 594 | * Flags for mach_port_guard_with_flags. These flags extend |
| 595 | * the attributes associated with a guarded port. |
| 596 | */ |
| 597 | #define MPG_STRICT 0x01 /* Apply strict guarding for a port */ |
| 598 | #define MPG_IMMOVABLE_RECEIVE 0x02 /* Receive right cannot be moved out of the space */ |
| 599 | |
| 600 | #if !__DARWIN_UNIX03 && !defined(_NO_PORT_T_FROM_MACH) |
| 601 | /* |
| 602 | * Mach 3.0 renamed everything to have mach_ in front of it. |
| 603 | * These types and macros are provided for backward compatibility |
| 604 | *	but are deprecated. |
| 605 | */ |
| 606 | typedef mach_port_t port_t; |
| 607 | typedef mach_port_name_t port_name_t; |
| 608 | typedef mach_port_name_t *port_name_array_t; |
| 609 | |
| 610 | #define PORT_NULL ((port_t) 0) |
| 611 | #define PORT_DEAD ((port_t) ~0) |
| 612 | #define PORT_VALID(name) \ |
| 613 | 	 ((port_t)(name) != PORT_NULL && (port_t)(name) != PORT_DEAD) |
| 614 | |
| 615 | #endif /* !__DARWIN_UNIX03 && !_NO_PORT_T_FROM_MACH */ |
| 616 | |
| 617 | #endif /* _MACH_PORT_H_ */ |