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