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