]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
39037602 | 2 | * Copyright (c) 2000-2016 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
2d21ac55 A |
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. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
0a7de745 | 31 | /* |
1c79356b A |
32 | * Mach Operating System |
33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
0a7de745 | 35 | * |
1c79356b A |
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. | |
0a7de745 | 41 | * |
1c79356b A |
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. | |
0a7de745 | 45 | * |
1c79356b | 46 | * Carnegie Mellon requests users of this software to return to |
0a7de745 | 47 | * |
1c79356b A |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
0a7de745 | 52 | * |
1c79356b A |
53 | * any improvements or extensions that they make and grant Carnegie Mellon |
54 | * the rights to redistribute these changes. | |
55 | */ | |
2d21ac55 A |
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 | */ | |
1c79356b A |
62 | /* |
63 | */ | |
64 | /* | |
65 | * File: ipc/ipc_port.h | |
66 | * Author: Rich Draves | |
67 | * Date: 1989 | |
68 | * | |
69 | * Definitions for ports. | |
70 | */ | |
71 | ||
0a7de745 | 72 | #ifndef _IPC_IPC_PORT_H_ |
1c79356b A |
73 | #define _IPC_IPC_PORT_H_ |
74 | ||
39037602 | 75 | #ifdef MACH_KERNEL_PRIVATE |
b0d623f7 | 76 | |
1c79356b A |
77 | #include <mach_assert.h> |
78 | #include <mach_debug.h> | |
79 | ||
91447636 | 80 | #include <mach/mach_types.h> |
1c79356b A |
81 | #include <mach/boolean.h> |
82 | #include <mach/kern_return.h> | |
1c79356b | 83 | #include <mach/port.h> |
1c79356b | 84 | |
fe8ab488 | 85 | #include <kern/assert.h> |
91447636 | 86 | #include <kern/kern_types.h> |
d9a64523 | 87 | #include <kern/turnstile.h> |
91447636 A |
88 | |
89 | #include <ipc/ipc_types.h> | |
1c79356b A |
90 | #include <ipc/ipc_object.h> |
91 | #include <ipc/ipc_mqueue.h> | |
1c79356b A |
92 | #include <ipc/ipc_space.h> |
93 | ||
2d21ac55 A |
94 | #include <security/_label.h> |
95 | ||
1c79356b A |
96 | /* |
97 | * A receive right (port) can be in four states: | |
98 | * 1) dead (not active, ip_timestamp has death time) | |
99 | * 2) in a space (ip_receiver_name != 0, ip_receiver points | |
100 | * to the space but doesn't hold a ref for it) | |
101 | * 3) in transit (ip_receiver_name == 0, ip_destination points | |
102 | * to the destination port and holds a ref for it) | |
103 | * 4) in limbo (ip_receiver_name == 0, ip_destination == IP_NULL) | |
104 | * | |
105 | * If the port is active, and ip_receiver points to some space, | |
106 | * then ip_receiver_name != 0, and that space holds receive rights. | |
107 | * If the port is not active, then ip_timestamp contains a timestamp | |
108 | * taken when the port was destroyed. | |
109 | */ | |
110 | ||
94ff46dc A |
111 | struct task_watchport_elem; |
112 | ||
1c79356b A |
113 | typedef unsigned int ipc_port_timestamp_t; |
114 | ||
1c79356b | 115 | struct ipc_port { |
1c79356b | 116 | /* |
b0d623f7 A |
117 | * Initial sub-structure in common with ipc_pset |
118 | * First element is an ipc_object second is a | |
119 | * message queue | |
1c79356b A |
120 | */ |
121 | struct ipc_object ip_object; | |
b0d623f7 | 122 | struct ipc_mqueue ip_messages; |
1c79356b A |
123 | |
124 | union { | |
f427ee49 A |
125 | struct ipc_space * receiver; |
126 | struct ipc_port * destination; | |
1c79356b A |
127 | ipc_port_timestamp_t timestamp; |
128 | } data; | |
129 | ||
f427ee49 | 130 | /* update host_request_notification if this union is changed */ |
39236c6e | 131 | union { |
f427ee49 A |
132 | ipc_kobject_t XNU_PTRAUTH_SIGNED_PTR("ipc_port.kobject") kobject; |
133 | ipc_kobject_label_t XNU_PTRAUTH_SIGNED_PTR("ipc_port.kolabel") kolabel; | |
fe8ab488 | 134 | ipc_importance_task_t imp_task; |
d9a64523 A |
135 | ipc_port_t sync_inheritor_port; |
136 | struct knote *sync_inheritor_knote; | |
137 | struct turnstile *sync_inheritor_ts; | |
39236c6e | 138 | } kdata; |
d9a64523 | 139 | |
39236c6e A |
140 | struct ipc_port *ip_nsrequest; |
141 | struct ipc_port *ip_pdrequest; | |
142 | struct ipc_port_request *ip_requests; | |
5ba3f43e A |
143 | union { |
144 | struct ipc_kmsg *premsg; | |
d9a64523 | 145 | struct turnstile *send_turnstile; |
5ba3f43e | 146 | } kdata2; |
6d2010ae | 147 | |
3e170ce0 A |
148 | mach_vm_address_t ip_context; |
149 | ||
0a7de745 A |
150 | natural_t ip_sprequests:1, /* send-possible requests outstanding */ |
151 | ip_spimportant:1, /* ... at least one is importance donating */ | |
152 | ip_impdonation:1, /* port supports importance donation */ | |
153 | ip_tempowner:1, /* dont give donations to current receiver */ | |
154 | ip_guarded:1, /* port guarded (use context value as guard) */ | |
155 | ip_strict_guard:1, /* Strict guarding; Prevents user manipulation of context values directly */ | |
156 | ip_specialreply:1, /* port is a special reply port */ | |
cb323159 A |
157 | ip_sync_link_state:3, /* link the port to destination port/ Workloop */ |
158 | ip_sync_bootstrap_checkin:1,/* port part of sync bootstrap checkin, push on thread doing the checkin */ | |
159 | ip_immovable_receive:1, /* the receive right cannot be moved out of a space, until it is destroyed */ | |
160 | ip_no_grant:1, /* Port wont accept complex messages containing (ool) port descriptors */ | |
161 | ip_immovable_send:1, /* No send(once) rights to this port can be moved out of a space */ | |
f427ee49 A |
162 | ip_tg_block_tracking:1, /* Track blocking relationship between thread groups during sync IPC */ |
163 | ip_impcount:17; /* number of importance donations in nested queue */ | |
39037602 | 164 | |
1c79356b A |
165 | mach_port_mscount_t ip_mscount; |
166 | mach_port_rights_t ip_srights; | |
167 | mach_port_rights_t ip_sorights; | |
168 | ||
0a7de745 A |
169 | #if MACH_ASSERT |
170 | #define IP_NSPARES 4 | |
171 | #define IP_CALLSTACK_MAX 16 | |
3e170ce0 | 172 | /* queue_chain_t ip_port_links;*//* all allocated ports */ |
0a7de745 A |
173 | thread_t ip_thread; /* who made me? thread context */ |
174 | unsigned long ip_timetrack; /* give an idea of "when" created */ | |
175 | uintptr_t ip_callstack[IP_CALLSTACK_MAX]; /* stack trace */ | |
176 | unsigned long ip_spares[IP_NSPARES]; /* for debugging */ | |
177 | #endif /* MACH_ASSERT */ | |
d9a64523 | 178 | #if DEVELOPMENT || DEBUG |
0a7de745 A |
179 | uint8_t ip_srp_lost_link:1, /* special reply port turnstile link chain broken */ |
180 | ip_srp_msg_sent:1; /* special reply port msg sent */ | |
d9a64523 | 181 | #endif |
813fb2f6 | 182 | }; |
1c79356b A |
183 | |
184 | ||
0a7de745 | 185 | #define ip_references ip_object.io_references |
1c79356b | 186 | |
0a7de745 A |
187 | #define ip_receiver_name ip_messages.imq_receiver_name |
188 | #define ip_in_pset ip_messages.imq_in_pset | |
cb323159 | 189 | #define ip_reply_context ip_messages.imq_context |
39236c6e | 190 | |
0a7de745 A |
191 | #define ip_receiver data.receiver |
192 | #define ip_destination data.destination | |
193 | #define ip_timestamp data.timestamp | |
1c79356b | 194 | |
0a7de745 | 195 | #define ip_kobject kdata.kobject |
ea3f0419 | 196 | #define ip_kolabel kdata.kolabel |
0a7de745 A |
197 | #define ip_imp_task kdata.imp_task |
198 | #define ip_sync_inheritor_port kdata.sync_inheritor_port | |
199 | #define ip_sync_inheritor_knote kdata.sync_inheritor_knote | |
200 | #define ip_sync_inheritor_ts kdata.sync_inheritor_ts | |
5ba3f43e | 201 | |
0a7de745 A |
202 | #define ip_premsg kdata2.premsg |
203 | #define ip_send_turnstile kdata2.send_turnstile | |
d9a64523 | 204 | |
0a7de745 | 205 | #define port_send_turnstile(port) (IP_PREALLOC(port) ? (port)->ip_premsg->ikm_turnstile : (port)->ip_send_turnstile) |
d9a64523 A |
206 | |
207 | #define set_port_send_turnstile(port, value) \ | |
208 | MACRO_BEGIN \ | |
209 | if (IP_PREALLOC(port)) { \ | |
0a7de745 | 210 | (port)->ip_premsg->ikm_turnstile = (value); \ |
d9a64523 | 211 | } else { \ |
0a7de745 | 212 | (port)->ip_send_turnstile = (value); \ |
d9a64523 | 213 | } \ |
5ba3f43e A |
214 | MACRO_END |
215 | ||
d9a64523 A |
216 | #define port_send_turnstile_address(port) \ |
217 | (IP_PREALLOC(port) ? &((port)->ip_premsg->ikm_turnstile) : &((port)->ip_send_turnstile)) | |
218 | ||
cb323159 | 219 | #define port_rcv_turnstile_address(port) \ |
94ff46dc | 220 | &(port)->ip_messages.imq_wait_queue.waitq_ts |
d9a64523 A |
221 | |
222 | ||
223 | /* | |
cb323159 | 224 | * SYNC IPC state flags for special reply port/ rcv right. |
d9a64523 A |
225 | * |
226 | * PORT_SYNC_LINK_ANY | |
227 | * Special reply port is not linked to any other port | |
228 | * or WL and linkage should be allowed. | |
229 | * | |
230 | * PORT_SYNC_LINK_PORT | |
231 | * Special reply port is linked to the port and | |
232 | * ip_sync_inheritor_port contains the inheritor | |
233 | * port. | |
234 | * | |
235 | * PORT_SYNC_LINK_WORKLOOP_KNOTE | |
236 | * Special reply port is linked to a WL (via a knote). | |
237 | * ip_sync_inheritor_knote contains a pointer to the knote | |
238 | * the port is stashed on. | |
239 | * | |
240 | * PORT_SYNC_LINK_WORKLOOP_STASH | |
241 | * Special reply port is linked to a WL (via a knote stash). | |
242 | * ip_sync_inheritor_ts contains a pointer to the turnstile with a +1 | |
243 | * the port is stashed on. | |
244 | * | |
245 | * PORT_SYNC_LINK_NO_LINKAGE | |
246 | * Message sent to special reply port, do | |
247 | * not allow any linkages till receive is | |
248 | * complete. | |
cb323159 A |
249 | * |
250 | * PORT_SYNC_LINK_RCV_THREAD | |
251 | * Receive right copied out as a part of bootstrap check in, | |
252 | * push on the thread which copied out the port. | |
d9a64523 A |
253 | */ |
254 | #define PORT_SYNC_LINK_ANY (0) | |
255 | #define PORT_SYNC_LINK_PORT (0x1) | |
256 | #define PORT_SYNC_LINK_WORKLOOP_KNOTE (0x2) | |
257 | #define PORT_SYNC_LINK_WORKLOOP_STASH (0x3) | |
258 | #define PORT_SYNC_LINK_NO_LINKAGE (0x4) | |
cb323159 | 259 | #define PORT_SYNC_LINK_RCV_THREAD (0x5) |
b0d623f7 | 260 | |
0a7de745 A |
261 | #define IP_NULL IPC_PORT_NULL |
262 | #define IP_DEAD IPC_PORT_DEAD | |
263 | #define IP_VALID(port) IPC_PORT_VALID(port) | |
1c79356b | 264 | |
cb323159 A |
265 | #define ip_object_to_port(io) __container_of(io, struct ipc_port, ip_object) |
266 | #define ip_to_object(port) (&(port)->ip_object) | |
267 | #define ip_active(port) io_active(ip_to_object(port)) | |
268 | #define ip_lock_init(port) io_lock_init(ip_to_object(port)) | |
269 | #define ip_lock_held(port) io_lock_held(ip_to_object(port)) | |
270 | #define ip_lock(port) io_lock(ip_to_object(port)) | |
271 | #define ip_lock_try(port) io_lock_try(ip_to_object(port)) | |
272 | #define ip_lock_held_kdp(port) io_lock_held_kdp(ip_to_object(port)) | |
273 | #define ip_unlock(port) io_unlock(ip_to_object(port)) | |
1c79356b | 274 | |
cb323159 A |
275 | #define ip_reference(port) io_reference(ip_to_object(port)) |
276 | #define ip_release(port) io_release(ip_to_object(port)) | |
1c79356b | 277 | |
39037602 | 278 | /* get an ipc_port pointer from an ipc_mqueue pointer */ |
0a7de745 A |
279 | #define ip_from_mq(mq) \ |
280 | __container_of(mq, struct ipc_port, ip_messages) | |
39037602 | 281 | |
0a7de745 A |
282 | #define ip_reference_mq(mq) ip_reference(ip_from_mq(mq)) |
283 | #define ip_release_mq(mq) ip_release(ip_from_mq(mq)) | |
39037602 | 284 | |
cb323159 A |
285 | #define ip_kotype(port) io_kotype(ip_to_object(port)) |
286 | #define ip_is_kobject(port) io_is_kobject(ip_to_object(port)) | |
ea3f0419 A |
287 | #define ip_is_kolabeled(port) io_is_kolabeled(ip_to_object(port)) |
288 | #define ip_get_kobject(port) ipc_kobject_get(port) | |
289 | #define ip_label_check(space, port, msgt_name) \ | |
290 | (!ip_is_kolabeled(port) || ipc_kobject_label_check((space), (port), (msgt_name))) | |
1c79356b | 291 | |
0a7de745 A |
292 | #define ip_full_kernel(port) imq_full_kernel(&(port)->ip_messages) |
293 | #define ip_full(port) imq_full(&(port)->ip_messages) | |
6d2010ae | 294 | |
f427ee49 A |
295 | /* Bits reserved in IO_BITS_PORT_INFO are defined here */ |
296 | ||
1c79356b A |
297 | /* |
298 | * JMM - Preallocation flag | |
299 | * This flag indicates that there is a message buffer preallocated for this | |
300 | * port and we should use that when sending (from the kernel) rather than | |
301 | * allocate a new one. This avoids deadlocks during notification message | |
302 | * sends by critical system threads (which may be needed to free memory and | |
303 | * therefore cannot be blocked waiting for memory themselves). | |
304 | */ | |
0a7de745 | 305 | #define IP_BIT_PREALLOC 0x00008000 /* preallocated mesg */ |
cb323159 | 306 | #define IP_PREALLOC(port) ((port)->ip_object.io_bits & IP_BIT_PREALLOC) |
1c79356b | 307 | |
0a7de745 A |
308 | #define IP_SET_PREALLOC(port, kmsg) \ |
309 | MACRO_BEGIN \ | |
cb323159 | 310 | (port)->ip_object.io_bits |= IP_BIT_PREALLOC; \ |
0a7de745 | 311 | (port)->ip_premsg = (kmsg); \ |
1c79356b A |
312 | MACRO_END |
313 | ||
0a7de745 A |
314 | #define IP_CLEAR_PREALLOC(port, kmsg) \ |
315 | MACRO_BEGIN \ | |
316 | assert((port)->ip_premsg == kmsg); \ | |
cb323159 | 317 | (port)->ip_object.io_bits &= ~IP_BIT_PREALLOC; \ |
0a7de745 | 318 | (port)->ip_premsg = IKM_NULL; \ |
1c79356b A |
319 | MACRO_END |
320 | ||
f427ee49 A |
321 | /* |
322 | * This flag indicates that the port has opted into message filtering based | |
323 | * on a policy defined in the Sandbox. | |
324 | */ | |
325 | #define IP_BIT_FILTER_MSG 0x00001000 | |
326 | #define ip_enforce_msg_filtering(port) (((port)->ip_object.io_bits & IP_BIT_FILTER_MSG) != 0) | |
327 | ||
6d2010ae | 328 | /* JMM - address alignment/packing for LP64 */ |
91447636 | 329 | struct ipc_port_request { |
1c79356b A |
330 | union { |
331 | struct ipc_port *port; | |
332 | ipc_port_request_index_t index; | |
333 | } notify; | |
334 | ||
335 | union { | |
336 | mach_port_name_t name; | |
337 | struct ipc_table_size *size; | |
338 | } name; | |
91447636 | 339 | }; |
1c79356b | 340 | |
0a7de745 A |
341 | #define ipr_next notify.index |
342 | #define ipr_size name.size | |
1c79356b | 343 | |
0a7de745 A |
344 | #define ipr_soright notify.port |
345 | #define ipr_name name.name | |
1c79356b | 346 | |
6d2010ae A |
347 | /* |
348 | * Use the low bits in the ipr_soright to specify the request type | |
349 | */ | |
0a7de745 A |
350 | #define IPR_SOR_SPARM_MASK 1 /* send-possible armed */ |
351 | #define IPR_SOR_SPREQ_MASK 2 /* send-possible requested */ | |
352 | #define IPR_SOR_SPBIT_MASK 3 /* combo */ | |
353 | #define IPR_SOR_SPARMED(sor) (((uintptr_t)(sor) & IPR_SOR_SPARM_MASK) != 0) | |
354 | #define IPR_SOR_SPREQ(sor) (((uintptr_t)(sor) & IPR_SOR_SPREQ_MASK) != 0) | |
355 | #define IPR_SOR_PORT(sor) ((ipc_port_t)((uintptr_t)(sor) & ~IPR_SOR_SPBIT_MASK)) | |
356 | #define IPR_SOR_MAKE(p, m) ((ipc_port_t)((uintptr_t)(p) | (m))) | |
6d2010ae | 357 | |
0a7de745 A |
358 | extern lck_grp_t ipc_lck_grp; |
359 | extern lck_attr_t ipc_lck_attr; | |
b0d623f7 | 360 | |
1c79356b A |
361 | /* |
362 | * Taking the ipc_port_multiple lock grants the privilege | |
363 | * to lock multiple ports at once. No ports must locked | |
364 | * when it is taken. | |
365 | */ | |
366 | ||
fe8ab488 | 367 | extern lck_spin_t ipc_port_multiple_lock_data; |
316670eb | 368 | |
0a7de745 | 369 | #define ipc_port_multiple_lock() \ |
2a1bd2d3 | 370 | lck_spin_lock_grp(&ipc_port_multiple_lock_data, &ipc_lck_grp) |
316670eb | 371 | |
0a7de745 | 372 | #define ipc_port_multiple_unlock() \ |
2a1bd2d3 A |
373 | lck_spin_unlock(&ipc_port_multiple_lock_data) |
374 | ||
375 | /* | |
376 | * Search for the end of the chain (a port not in transit), | |
377 | * acquiring locks along the way. | |
378 | */ | |
379 | extern boolean_t ipc_port_destination_chain_lock( | |
380 | ipc_port_t port, | |
381 | ipc_port_t *base); | |
1c79356b A |
382 | |
383 | /* | |
384 | * The port timestamp facility provides timestamps | |
385 | * for port destruction. It is used to serialize | |
386 | * mach_port_names with port death. | |
387 | */ | |
388 | ||
1c79356b A |
389 | extern ipc_port_timestamp_t ipc_port_timestamp_data; |
390 | ||
1c79356b A |
391 | /* Retrieve a port timestamp value */ |
392 | extern ipc_port_timestamp_t ipc_port_timestamp(void); | |
393 | ||
394 | /* | |
395 | * Compares two timestamps, and returns TRUE if one | |
396 | * happened before two. Note that this formulation | |
397 | * works when the timestamp wraps around at 2^32, | |
398 | * as long as one and two aren't too far apart. | |
399 | */ | |
400 | ||
0a7de745 | 401 | #define IP_TIMESTAMP_ORDER(one, two) ((int) ((one) - (two)) < 0) |
1c79356b | 402 | |
cb323159 A |
403 | static inline void |
404 | require_ip_active(ipc_port_t port) | |
405 | { | |
406 | if (!ip_active(port)) { | |
407 | panic("Using inactive port %p", port); | |
408 | } | |
409 | } | |
410 | ||
411 | static inline kern_return_t | |
412 | ipc_port_translate( | |
413 | ipc_space_t space, | |
414 | mach_port_name_t name, | |
415 | mach_port_right_t right, | |
416 | ipc_port_t *portp) | |
417 | { | |
418 | ipc_object_t object; | |
419 | kern_return_t kr; | |
420 | ||
421 | kr = ipc_object_translate(space, name, right, &object); | |
422 | *portp = (kr == KERN_SUCCESS) ? ip_object_to_port(object) : IP_NULL; | |
423 | return kr; | |
424 | } | |
425 | ||
0a7de745 | 426 | #define ipc_port_translate_receive(space, name, portp) \ |
cb323159 | 427 | ipc_port_translate((space), (name), MACH_PORT_RIGHT_RECEIVE, portp) |
1c79356b | 428 | |
0a7de745 | 429 | #define ipc_port_translate_send(space, name, portp) \ |
cb323159 | 430 | ipc_port_translate((space), (name), MACH_PORT_RIGHT_SEND, portp) |
1c79356b | 431 | |
6d2010ae | 432 | /* Allocate a notification request slot */ |
39236c6e A |
433 | #if IMPORTANCE_INHERITANCE |
434 | extern kern_return_t | |
435 | ipc_port_request_alloc( | |
0a7de745 A |
436 | ipc_port_t port, |
437 | mach_port_name_t name, | |
438 | ipc_port_t soright, | |
439 | boolean_t send_possible, | |
440 | boolean_t immediate, | |
441 | ipc_port_request_index_t *indexp, | |
442 | boolean_t *importantp); | |
39236c6e | 443 | #else |
1c79356b | 444 | extern kern_return_t |
6d2010ae | 445 | ipc_port_request_alloc( |
0a7de745 A |
446 | ipc_port_t port, |
447 | mach_port_name_t name, | |
448 | ipc_port_t soright, | |
449 | boolean_t send_possible, | |
450 | boolean_t immediate, | |
451 | ipc_port_request_index_t *indexp); | |
39236c6e | 452 | #endif /* IMPORTANCE_INHERITANCE */ |
1c79356b | 453 | |
6d2010ae A |
454 | /* Grow one of a port's tables of notifcation requests */ |
455 | extern kern_return_t ipc_port_request_grow( | |
0a7de745 A |
456 | ipc_port_t port, |
457 | ipc_table_elems_t target_size); | |
1c79356b | 458 | |
6d2010ae A |
459 | /* Return the type(s) of notification requests outstanding */ |
460 | extern mach_port_type_t ipc_port_request_type( | |
0a7de745 A |
461 | ipc_port_t port, |
462 | mach_port_name_t name, | |
463 | ipc_port_request_index_t index); | |
1c79356b | 464 | |
6d2010ae A |
465 | /* Cancel a notification request and return the send-once right */ |
466 | extern ipc_port_t ipc_port_request_cancel( | |
0a7de745 A |
467 | ipc_port_t port, |
468 | mach_port_name_t name, | |
469 | ipc_port_request_index_t index); | |
6d2010ae A |
470 | |
471 | /* Arm any delayed send-possible notification */ | |
39236c6e | 472 | extern boolean_t ipc_port_request_sparm( |
39037602 A |
473 | ipc_port_t port, |
474 | mach_port_name_t name, | |
475 | ipc_port_request_index_t index, | |
476 | mach_msg_option_t option, | |
f427ee49 | 477 | mach_msg_priority_t priority); |
6d2010ae | 478 | |
1c79356b A |
479 | /* Make a port-deleted request */ |
480 | extern void ipc_port_pdrequest( | |
0a7de745 A |
481 | ipc_port_t port, |
482 | ipc_port_t notify, | |
483 | ipc_port_t *previousp); | |
1c79356b A |
484 | |
485 | /* Make a no-senders request */ | |
486 | extern void ipc_port_nsrequest( | |
0a7de745 A |
487 | ipc_port_t port, |
488 | mach_port_mscount_t sync, | |
489 | ipc_port_t notify, | |
490 | ipc_port_t *previousp); | |
491 | ||
1c79356b | 492 | /* Prepare a receive right for transmission/destruction */ |
39037602 | 493 | extern boolean_t ipc_port_clear_receiver( |
0a7de745 A |
494 | ipc_port_t port, |
495 | boolean_t should_destroy); | |
1c79356b | 496 | |
94ff46dc | 497 | __options_decl(ipc_port_init_flags_t, uint32_t, { |
f427ee49 A |
498 | IPC_PORT_INIT_NONE = 0x00000000, |
499 | IPC_PORT_INIT_MAKE_SEND_RIGHT = 0x00000001, | |
500 | IPC_PORT_INIT_MESSAGE_QUEUE = 0x00000002, | |
501 | IPC_PORT_INIT_SPECIAL_REPLY = 0x00000004, | |
502 | IPC_PORT_INIT_FILTER_MESSAGE = 0x00000008, | |
503 | IPC_PORT_INIT_TG_BLOCK_TRACKING = 0x00000010, | |
94ff46dc A |
504 | }); |
505 | ||
1c79356b A |
506 | /* Initialize a newly-allocated port */ |
507 | extern void ipc_port_init( | |
0a7de745 A |
508 | ipc_port_t port, |
509 | ipc_space_t space, | |
94ff46dc | 510 | ipc_port_init_flags_t flags, |
0a7de745 | 511 | mach_port_name_t name); |
1c79356b A |
512 | |
513 | /* Allocate a port */ | |
514 | extern kern_return_t ipc_port_alloc( | |
0a7de745 | 515 | ipc_space_t space, |
94ff46dc | 516 | ipc_port_init_flags_t flags, |
0a7de745 A |
517 | mach_port_name_t *namep, |
518 | ipc_port_t *portp); | |
1c79356b A |
519 | |
520 | /* Allocate a port, with a specific name */ | |
521 | extern kern_return_t ipc_port_alloc_name( | |
0a7de745 | 522 | ipc_space_t space, |
94ff46dc | 523 | ipc_port_init_flags_t flags, |
0a7de745 A |
524 | mach_port_name_t name, |
525 | ipc_port_t *portp); | |
1c79356b A |
526 | |
527 | /* Generate dead name notifications */ | |
528 | extern void ipc_port_dnnotify( | |
0a7de745 | 529 | ipc_port_t port); |
6d2010ae A |
530 | |
531 | /* Generate send-possible notifications */ | |
532 | extern void ipc_port_spnotify( | |
0a7de745 | 533 | ipc_port_t port); |
1c79356b A |
534 | |
535 | /* Destroy a port */ | |
536 | extern void ipc_port_destroy( | |
0a7de745 | 537 | ipc_port_t port); |
1c79356b | 538 | |
0a7de745 A |
539 | /* Check if queueing "port" in a message for "dest" would create a circular |
540 | * group of ports and messages */ | |
1c79356b A |
541 | extern boolean_t |
542 | ipc_port_check_circularity( | |
0a7de745 A |
543 | ipc_port_t port, |
544 | ipc_port_t dest); | |
1c79356b | 545 | |
39236c6e | 546 | #if IMPORTANCE_INHERITANCE |
4bd07ac2 A |
547 | |
548 | enum { | |
549 | IPID_OPTION_NORMAL = 0, /* normal boost */ | |
550 | IPID_OPTION_SENDPOSSIBLE = 1, /* send-possible induced boost */ | |
551 | }; | |
552 | ||
5ba3f43e | 553 | /* link the destination port with special reply port */ |
d9a64523 A |
554 | void |
555 | ipc_port_link_special_reply_port( | |
5ba3f43e | 556 | ipc_port_t special_reply_port, |
cb323159 A |
557 | ipc_port_t dest_port, |
558 | boolean_t sync_bootstrap_checkin); | |
d9a64523 A |
559 | |
560 | #define IPC_PORT_ADJUST_SR_NONE 0 | |
cb323159 A |
561 | #define IPC_PORT_ADJUST_SR_ALLOW_SYNC_LINKAGE 0x1 |
562 | #define IPC_PORT_ADJUST_SR_LINK_WORKLOOP 0x2 | |
563 | #define IPC_PORT_ADJUST_UNLINK_THREAD 0x4 | |
0a7de745 A |
564 | #define IPC_PORT_ADJUST_SR_RECEIVED_MSG 0x8 |
565 | #define IPC_PORT_ADJUST_SR_ENABLE_EVENT 0x10 | |
cb323159 | 566 | #define IPC_PORT_ADJUST_RESET_BOOSTRAP_CHECKIN 0x20 |
d9a64523 A |
567 | |
568 | void | |
cb323159 | 569 | ipc_special_reply_port_bits_reset(ipc_port_t special_reply_port); |
d9a64523 A |
570 | |
571 | void | |
cb323159 | 572 | ipc_special_reply_port_msg_sent(ipc_port_t special_reply_port); |
d9a64523 A |
573 | |
574 | void | |
cb323159 | 575 | ipc_special_reply_port_msg_sent(ipc_port_t special_reply_port); |
5ba3f43e | 576 | |
d9a64523 | 577 | /* Adjust special reply port linkage */ |
cb323159 A |
578 | void |
579 | ipc_port_adjust_special_reply_port_locked( | |
5ba3f43e A |
580 | ipc_port_t special_reply_port, |
581 | struct knote *kn, | |
d9a64523 A |
582 | uint8_t flags, |
583 | boolean_t get_turnstile); | |
5ba3f43e | 584 | |
cb323159 A |
585 | void |
586 | ipc_port_adjust_sync_link_state_locked( | |
587 | ipc_port_t port, | |
588 | int sync_link_state, | |
589 | turnstile_inheritor_t inheritor); | |
590 | ||
d9a64523 | 591 | /* Adjust special reply port linkage */ |
5ba3f43e | 592 | void |
d9a64523 | 593 | ipc_port_adjust_special_reply_port( |
5ba3f43e | 594 | ipc_port_t special_reply_port, |
94ff46dc | 595 | uint8_t flags); |
5ba3f43e | 596 | |
cb323159 A |
597 | void |
598 | ipc_port_adjust_port_locked( | |
599 | ipc_port_t port, | |
600 | struct knote *kn, | |
601 | boolean_t sync_bootstrap_checkin); | |
602 | ||
603 | void | |
604 | ipc_port_clear_sync_rcv_thread_boost_locked( | |
605 | ipc_port_t port); | |
606 | ||
607 | kern_return_t | |
608 | ipc_port_add_watchport_elem_locked( | |
609 | ipc_port_t port, | |
610 | struct task_watchport_elem *watchport_elem, | |
611 | struct task_watchport_elem **old_elem); | |
612 | ||
613 | kern_return_t | |
614 | ipc_port_clear_watchport_elem_internal_conditional_locked( | |
615 | ipc_port_t port, | |
616 | struct task_watchport_elem *watchport_elem); | |
617 | ||
618 | kern_return_t | |
619 | ipc_port_replace_watchport_elem_conditional_locked( | |
620 | ipc_port_t port, | |
621 | struct task_watchport_elem *old_watchport_elem, | |
622 | struct task_watchport_elem *new_watchport_elem); | |
623 | ||
624 | struct task_watchport_elem * | |
625 | ipc_port_clear_watchport_elem_internal( | |
626 | ipc_port_t port); | |
5ba3f43e | 627 | |
d9a64523 A |
628 | void |
629 | ipc_port_send_turnstile_prepare(ipc_port_t port); | |
5ba3f43e | 630 | |
5ba3f43e | 631 | void |
d9a64523 A |
632 | ipc_port_send_turnstile_complete(ipc_port_t port); |
633 | ||
634 | struct waitq * | |
635 | ipc_port_rcv_turnstile_waitq(struct waitq *waitq); | |
636 | ||
fe8ab488 A |
637 | /* apply importance delta to port only */ |
638 | extern mach_port_delta_t | |
639 | ipc_port_impcount_delta( | |
0a7de745 A |
640 | ipc_port_t port, |
641 | mach_port_delta_t delta, | |
642 | ipc_port_t base); | |
fe8ab488 A |
643 | |
644 | /* apply importance delta to port, and return task importance for update */ | |
645 | extern boolean_t | |
646 | ipc_port_importance_delta_internal( | |
0a7de745 A |
647 | ipc_port_t port, |
648 | natural_t options, | |
649 | mach_port_delta_t *deltap, | |
650 | ipc_importance_task_t *imp_task); | |
fe8ab488 A |
651 | |
652 | /* Apply an importance delta to a port and reflect change in receiver task */ | |
39236c6e A |
653 | extern boolean_t |
654 | ipc_port_importance_delta( | |
0a7de745 A |
655 | ipc_port_t port, |
656 | natural_t options, | |
657 | mach_port_delta_t delta); | |
39236c6e A |
658 | #endif /* IMPORTANCE_INHERITANCE */ |
659 | ||
0b4e3aa0 A |
660 | /* Make a naked send right from a receive right - port locked and active */ |
661 | extern ipc_port_t ipc_port_make_send_locked( | |
0a7de745 | 662 | ipc_port_t port); |
0b4e3aa0 | 663 | |
1c79356b A |
664 | /* Make a naked send right from a receive right */ |
665 | extern ipc_port_t ipc_port_make_send( | |
0a7de745 | 666 | ipc_port_t port); |
1c79356b | 667 | |
cb323159 A |
668 | /* Make a naked send right from another naked send right - port locked and active */ |
669 | extern void ipc_port_copy_send_locked( | |
670 | ipc_port_t port); | |
671 | ||
1c79356b A |
672 | /* Make a naked send right from another naked send right */ |
673 | extern ipc_port_t ipc_port_copy_send( | |
0a7de745 | 674 | ipc_port_t port); |
1c79356b A |
675 | |
676 | /* Copyout a naked send right */ | |
677 | extern mach_port_name_t ipc_port_copyout_send( | |
0a7de745 A |
678 | ipc_port_t sright, |
679 | ipc_space_t space); | |
1c79356b | 680 | |
f427ee49 A |
681 | extern void ipc_port_thread_group_blocked( |
682 | ipc_port_t port); | |
683 | ||
684 | extern void ipc_port_thread_group_unblocked(void); | |
685 | ||
b0d623f7 A |
686 | #endif /* MACH_KERNEL_PRIVATE */ |
687 | ||
688 | #if KERNEL_PRIVATE | |
689 | ||
1c79356b A |
690 | /* Release a (valid) naked send right */ |
691 | extern void ipc_port_release_send( | |
0a7de745 | 692 | ipc_port_t port); |
1c79356b | 693 | |
316670eb A |
694 | extern void ipc_port_reference( |
695 | ipc_port_t port); | |
696 | ||
697 | extern void ipc_port_release( | |
698 | ipc_port_t port); | |
699 | ||
b0d623f7 A |
700 | #endif /* KERNEL_PRIVATE */ |
701 | ||
39037602 | 702 | #ifdef MACH_KERNEL_PRIVATE |
b0d623f7 | 703 | |
316670eb A |
704 | /* Make a naked send-once right from a locked and active receive right */ |
705 | extern ipc_port_t ipc_port_make_sonce_locked( | |
0a7de745 | 706 | ipc_port_t port); |
316670eb | 707 | |
1c79356b A |
708 | /* Make a naked send-once right from a receive right */ |
709 | extern ipc_port_t ipc_port_make_sonce( | |
0a7de745 | 710 | ipc_port_t port); |
1c79356b A |
711 | |
712 | /* Release a naked send-once right */ | |
713 | extern void ipc_port_release_sonce( | |
0a7de745 | 714 | ipc_port_t port); |
1c79356b A |
715 | |
716 | /* Release a naked (in limbo or in transit) receive right */ | |
717 | extern void ipc_port_release_receive( | |
0a7de745 | 718 | ipc_port_t port); |
6d2010ae A |
719 | |
720 | /* finalize the destruction of a port before it gets freed */ | |
721 | extern void ipc_port_finalize( | |
0a7de745 | 722 | ipc_port_t port); |
1c79356b A |
723 | |
724 | /* Allocate a port in a special space */ | |
725 | extern ipc_port_t ipc_port_alloc_special( | |
94ff46dc A |
726 | ipc_space_t space, |
727 | ipc_port_init_flags_t flags); | |
1c79356b A |
728 | |
729 | /* Deallocate a port in a special space */ | |
730 | extern void ipc_port_dealloc_special( | |
0a7de745 A |
731 | ipc_port_t port, |
732 | ipc_space_t space); | |
1c79356b | 733 | |
0a7de745 | 734 | #if MACH_ASSERT |
1c79356b A |
735 | /* Track low-level port deallocation */ |
736 | extern void ipc_port_track_dealloc( | |
0a7de745 | 737 | ipc_port_t port); |
0a7de745 | 738 | #endif /* MACH_ASSERT */ |
1c79356b | 739 | |
cb323159 A |
740 | extern void ipc_port_recv_update_inheritor(ipc_port_t port, |
741 | struct turnstile *turnstile, | |
742 | turnstile_update_flags_t flags); | |
743 | ||
744 | extern void ipc_port_send_update_inheritor(ipc_port_t port, | |
745 | struct turnstile *turnstile, | |
746 | turnstile_update_flags_t flags); | |
d9a64523 | 747 | |
f427ee49 A |
748 | extern int |
749 | ipc_special_reply_get_pid_locked(ipc_port_t port); | |
750 | ||
0a7de745 | 751 | #define ipc_port_alloc_kernel() \ |
94ff46dc | 752 | ipc_port_alloc_special(ipc_space_kernel, IPC_PORT_INIT_NONE) |
0a7de745 A |
753 | #define ipc_port_dealloc_kernel(port) \ |
754 | ipc_port_dealloc_special((port), ipc_space_kernel) | |
1c79356b | 755 | |
0a7de745 | 756 | #define ipc_port_alloc_reply() \ |
94ff46dc | 757 | ipc_port_alloc_special(ipc_space_reply, IPC_PORT_INIT_MESSAGE_QUEUE) |
0a7de745 A |
758 | #define ipc_port_dealloc_reply(port) \ |
759 | ipc_port_dealloc_special((port), ipc_space_reply) | |
1c79356b | 760 | |
b0d623f7 A |
761 | #endif /* MACH_KERNEL_PRIVATE */ |
762 | ||
0a7de745 | 763 | #endif /* _IPC_IPC_PORT_H_ */ |