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 * mach_port_name_t - the local identity for a Mach port 96 * 97 * The name is Mach port namespace specific. It is used to 98 * identify the rights held for that port by the task whose 99 * namespace is implied [or specifically provided]. 100 * 101 * Use of this type usually implies just a name - no rights. 102 * See mach_port_t for a type that implies a "named right." 103 * 104 */ 105 106typedef natural_t mach_port_name_t; 107typedef mach_port_name_t *mach_port_name_array_t; 108 109#ifdef KERNEL 110 111/* 112 * mach_port_t - a named port right 113 * 114 * In the kernel, "rights" are represented [named] by pointers to 115 * the ipc port object in question. There is no port namespace for the 116 * rights to be collected. 117 * 118 * Actually, there is namespace for the kernel task. But most kernel 119 * code - including, but not limited to, Mach IPC code - lives in the 120 * limbo between the current user-level task and the "next" task. Very 121 * little of the kernel code runs in full kernel task context. So very 122 * little of it gets to use the kernel task's port name space. 123 * 124 * Because of this implementation approach, all in-kernel rights for 125 * a given port coalesce [have the same name/pointer]. The actual 126 * references are counted in the port itself. It is up to the kernel 127 * code in question to "just remember" how many [and what type of] 128 * rights it holds and handle them appropriately. 129 * 130 */ 131 132#ifndef MACH_KERNEL_PRIVATE 133/* 134 * For kernel code that resides outside of Mach proper, we opaque the 135 * port structure definition. 136 */ 137struct ipc_port ; 138 139#endif /* MACH_KERNEL_PRIVATE */ 140 141typedef struct ipc_port *ipc_port_t; 142 143#define IPC_PORT_NULL ((ipc_port_t) 0) 144#define IPC_PORT_DEAD ((ipc_port_t)~0) 145#define IPC_PORT_VALID(port) \ 146 ((port) != IPC_PORT_NULL && (port) != IPC_PORT_DEAD) 147 148typedef ipc_port_t mach_port_t; 149 150#else /* KERNEL */ 151 152/* 153 * mach_port_t - a named port right 154 * 155 * In user-space, "rights" are represented by the name of the 156 * right in the Mach port namespace. Even so, this type is 157 * presented as a unique one to more clearly denote the presence 158 * of a right coming along with the name. 159 * 160 * Often, various rights for a port held in a single name space 161 * will coalesce and are, therefore, be identified by a single name 162 * [this is the case for send and receive rights]. But not 163 * always [send-once rights currently get a unique name for 164 * each right]. 165 * 166 */ 167 168#ifndef _MACH_PORT_T 169#define _MACH_PORT_T 170typedef mach_port_name_t mach_port_t; 171#endif 172 173#endif /* KERNEL */ 174 175typedef mach_port_t *mach_port_array_t; 176 177/* 178 * MACH_PORT_NULL is a legal value that can be carried in messages. 179 * It indicates the absence of any port or port rights. (A port 180 * argument keeps the message from being "simple", even if the 181 * value is MACH_PORT_NULL.) The value MACH_PORT_DEAD is also a legal 182 * value that can be carried in messages. It indicates 183 * that a port right was present, but it died. 184 */ 185 186#define MACH_PORT_NULL 0 /* intentional loose typing */ 187#define MACH_PORT_DEAD ((mach_port_name_t) ~0) 188#define MACH_PORT_VALID(name) \ 189 (((name) != MACH_PORT_NULL) && \ 190 ((name) != MACH_PORT_DEAD)) 191 192 193/* 194 * For kernel-selected [assigned] port names, the name is 195 * comprised of two parts: a generation number and an index. 196 * This approach keeps the exact same name from being generated 197 * and reused too quickly [to catch right/reference counting bugs]. 198 * The dividing line between the constituent parts is exposed so 199 * that efficient "mach_port_name_t to data structure pointer" 200 * conversion implementation can be made. But it is possible 201 * for user-level code to assign their own names to Mach ports. 202 * These are not required to participate in this algorithm. So 203 * care should be taken before "assuming" this model. 204 * 205 */ 206 207#ifndef NO_PORT_GEN 208 209#define MACH_PORT_INDEX(name) ((name) >> 8) 210#define MACH_PORT_GEN(name) (((name) & 0xff) << 24) 211#define MACH_PORT_MAKE(index, gen) \ 212 (((index) << 8) | (gen) >> 24) 213 214#else /* NO_PORT_GEN */ 215 216#define MACH_PORT_INDEX(name) (name) 217#define MACH_PORT_GEN(name) (0) 218#define MACH_PORT_MAKE(index, gen) (index) 219 220#endif /* NO_PORT_GEN */ 221 222 223/* 224 * These are the different rights a task may have for a port. 225 * The MACH_PORT_RIGHT_* definitions are used as arguments 226 * to mach_port_allocate, mach_port_get_refs, etc, to specify 227 * a particular right to act upon. The mach_port_names and 228 * mach_port_type calls return bitmasks using the MACH_PORT_TYPE_* 229 * definitions. This is because a single name may denote 230 * multiple rights. 231 */ 232 233typedef natural_t mach_port_right_t; 234 235#define MACH_PORT_RIGHT_SEND ((mach_port_right_t) 0) 236#define MACH_PORT_RIGHT_RECEIVE ((mach_port_right_t) 1) 237#define MACH_PORT_RIGHT_SEND_ONCE ((mach_port_right_t) 2) 238#define MACH_PORT_RIGHT_PORT_SET ((mach_port_right_t) 3) 239#define MACH_PORT_RIGHT_DEAD_NAME ((mach_port_right_t) 4) 240#define MACH_PORT_RIGHT_LABELH ((mach_port_right_t) 5) 241#define MACH_PORT_RIGHT_NUMBER ((mach_port_right_t) 6) 242 243typedef natural_t mach_port_type_t; 244typedef mach_port_type_t *mach_port_type_array_t; 245 246#define MACH_PORT_TYPE(right) \ 247 ((mach_port_type_t)(((mach_port_type_t) 1) \ 248 << ((right) + ((mach_port_right_t) 16)))) 249#define MACH_PORT_TYPE_NONE ((mach_port_type_t) 0L) 250#define MACH_PORT_TYPE_SEND MACH_PORT_TYPE(MACH_PORT_RIGHT_SEND) 251#define MACH_PORT_TYPE_RECEIVE MACH_PORT_TYPE(MACH_PORT_RIGHT_RECEIVE) 252#define MACH_PORT_TYPE_SEND_ONCE MACH_PORT_TYPE(MACH_PORT_RIGHT_SEND_ONCE) 253#define MACH_PORT_TYPE_PORT_SET MACH_PORT_TYPE(MACH_PORT_RIGHT_PORT_SET) 254#define MACH_PORT_TYPE_DEAD_NAME MACH_PORT_TYPE(MACH_PORT_RIGHT_DEAD_NAME) 255#define MACH_PORT_TYPE_LABELH MACH_PORT_TYPE(MACH_PORT_RIGHT_LABELH) 256 257/* Convenient combinations. */ 258 259#define MACH_PORT_TYPE_SEND_RECEIVE \ 260 (MACH_PORT_TYPE_SEND|MACH_PORT_TYPE_RECEIVE) 261#define MACH_PORT_TYPE_SEND_RIGHTS \ 262 (MACH_PORT_TYPE_SEND|MACH_PORT_TYPE_SEND_ONCE) 263#define MACH_PORT_TYPE_PORT_RIGHTS \ 264 (MACH_PORT_TYPE_SEND_RIGHTS|MACH_PORT_TYPE_RECEIVE) 265#define MACH_PORT_TYPE_PORT_OR_DEAD \ 266 (MACH_PORT_TYPE_PORT_RIGHTS|MACH_PORT_TYPE_DEAD_NAME) 267#define MACH_PORT_TYPE_ALL_RIGHTS \ 268 (MACH_PORT_TYPE_PORT_OR_DEAD|MACH_PORT_TYPE_PORT_SET) 269 270/* Dummy type bits that mach_port_type/mach_port_names can return. */ 271 272#define MACH_PORT_TYPE_DNREQUEST 0x80000000 273 274/* User-references for capabilities. */ 275 276typedef natural_t mach_port_urefs_t; 277typedef integer_t mach_port_delta_t; /* change in urefs */ 278 279/* Attributes of ports. (See mach_port_get_receive_status.) */ 280 281typedef natural_t mach_port_seqno_t; /* sequence number */ 282typedef natural_t mach_port_mscount_t; /* make-send count */ 283typedef natural_t mach_port_msgcount_t; /* number of msgs */ 284typedef natural_t mach_port_rights_t; /* number of rights */ 285 286/* 287 * Are there outstanding send rights for a given port? 288 */ 289#define MACH_PORT_SRIGHTS_NONE 0 /* no srights */ 290#define MACH_PORT_SRIGHTS_PRESENT 1 /* srights */ 291typedef unsigned int mach_port_srights_t; /* status of send rights */ 292 293typedef struct mach_port_status { 294 mach_port_rights_t mps_pset; /* count of containing port sets */ 295 mach_port_seqno_t mps_seqno; /* sequence number */ 296 mach_port_mscount_t mps_mscount; /* make-send count */ 297 mach_port_msgcount_t mps_qlimit; /* queue limit */ 298 mach_port_msgcount_t mps_msgcount; /* number in the queue */ 299 mach_port_rights_t mps_sorights; /* how many send-once rights */ 300 boolean_t mps_srights; /* do send rights exist? */ 301 boolean_t mps_pdrequest; /* port-deleted requested? */ 302 boolean_t mps_nsrequest; /* no-senders requested? */ 303 natural_t mps_flags; /* port flags */ 304} mach_port_status_t; 305 306/* System-wide values for setting queue limits on a port */ 307#define MACH_PORT_QLIMIT_ZERO ((mach_port_msgcount_t) 0) 308#define MACH_PORT_QLIMIT_BASIC ((mach_port_msgcount_t) 5) 309#define MACH_PORT_QLIMIT_SMALL ((mach_port_msgcount_t) 16) 310#define MACH_PORT_QLIMIT_LARGE ((mach_port_msgcount_t) 1024) 311#define MACH_PORT_QLIMIT_KERNEL ((mach_port_msgcount_t) 65536) 312#define MACH_PORT_QLIMIT_MIN MACH_PORT_QLIMIT_ZERO 313#define MACH_PORT_QLIMIT_DEFAULT MACH_PORT_QLIMIT_BASIC 314#define MACH_PORT_QLIMIT_MAX MACH_PORT_QLIMIT_LARGE 315 316typedef struct mach_port_limits { 317 mach_port_msgcount_t mpl_qlimit; /* number of msgs */ 318} mach_port_limits_t; 319 320typedef integer_t *mach_port_info_t; /* varying array of natural_t */ 321 322/* Flavors for mach_port_get/set_attributes() */ 323typedef int mach_port_flavor_t; 324#define MACH_PORT_LIMITS_INFO 1 /* uses mach_port_status_t */ 325#define MACH_PORT_RECEIVE_STATUS 2 /* uses mach_port_limits_t */ 326#define MACH_PORT_DNREQUESTS_SIZE 3 /* info is int */ 327 328#define MACH_PORT_LIMITS_INFO_COUNT ((natural_t) \ 329 (sizeof(mach_port_limits_t)/sizeof(natural_t))) 330#define MACH_PORT_RECEIVE_STATUS_COUNT ((natural_t) \ 331 (sizeof(mach_port_status_t)/sizeof(natural_t))) 332#define MACH_PORT_DNREQUESTS_SIZE_COUNT 1 333 334/* 335 * Structure used to pass information about port allocation requests. 336 * Must be padded to 64-bits total length. 337 */ 338typedef struct mach_port_qos { 339 unsigned int name:1; /* name given */ 340 unsigned int prealloc:1; /* prealloced message */ 341 boolean_t pad1:30; 342 natural_t len; 343} mach_port_qos_t; 344 345#if !__DARWIN_UNIX03 && !defined(_NO_PORT_T_FROM_MACH) 346/* 347 * Mach 3.0 renamed everything to have mach_ in front of it. 348 * These types and macros are provided for backward compatibility 349 * but are deprecated. 350 */ 351typedef mach_port_t port_t; 352typedef mach_port_name_t port_name_t; 353typedef mach_port_name_t *port_name_array_t; 354 355#define PORT_NULL ((port_t) 0) 356#define PORT_DEAD ((port_t) ~0) 357#define PORT_VALID(name) \ 358 ((port_t)(name) != PORT_NULL && (port_t)(name) != PORT_DEAD) 359 360#endif /* !__DARWIN_UNIX03 && !_NO_PORT_T_FROM_MACH */ 361 362#endif /* _MACH_PORT_H_ */ 363