2 * Copyright (c) 2000-2016 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
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.
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.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
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,
61 * Copyright (c) 2005 SPARTA, Inc.
66 * File: kern/ipc_kobject.c
70 * Functions for letting a port represent a kernel object.
73 #include <mach_debug.h>
74 #include <mach_ipc_test.h>
76 #include <mach/port.h>
77 #include <mach/kern_return.h>
78 #include <mach/message.h>
79 #include <mach/mig_errors.h>
80 #include <mach/notify.h>
82 #include <mach/vm_param.h>
84 #include <mach/mach_vm_server.h>
85 #include <mach/mach_port_server.h>
86 #include <mach/mach_host_server.h>
87 #include <mach/host_priv_server.h>
88 #include <mach/host_security_server.h>
89 #include <mach/clock_server.h>
90 #include <mach/clock_priv_server.h>
91 #include <mach/lock_set_server.h>
92 #include <mach/memory_entry_server.h>
93 #include <mach/memory_object_control_server.h>
94 #include <mach/memory_object_default_server.h>
95 #include <mach/processor_server.h>
96 #include <mach/processor_set_server.h>
97 #include <mach/task_server.h>
98 #include <mach/mach_voucher_server.h>
99 #include <mach/mach_voucher_attr_control_server.h>
101 #include <mach/vm32_map_server.h>
103 #include <mach/thread_act_server.h>
104 #include <mach/restartable_server.h>
106 #include <mach/exc_server.h>
107 #include <mach/mach_exc_server.h>
109 #include <device/device_types.h>
110 #include <device/device_server.h>
112 #include <UserNotification/UNDReplyServer.h>
115 #include <mach/arcade_register_server.h>
119 #include <kern/audit_sessionport.h>
122 #if MACH_MACHINE_ROUTINES
123 #include <machine/machine_routines.h>
124 #endif /* MACH_MACHINE_ROUTINES */
126 #include <uk_xkern/xk_uproxy_server.h>
127 #endif /* XK_PROXY */
129 #include <kern/ipc_tt.h>
130 #include <kern/ipc_mig.h>
131 #include <kern/ipc_misc.h>
132 #include <kern/ipc_kobject.h>
133 #include <kern/host_notify.h>
134 #include <kern/mk_timer.h>
135 #include <kern/misc_protos.h>
138 #include <kern/arcade.h>
139 #endif /* CONFIG_ARCADE */
141 #include <ipc/ipc_kmsg.h>
142 #include <ipc/ipc_port.h>
143 #include <ipc/ipc_voucher.h>
144 #include <kern/sync_sema.h>
145 #include <kern/counters.h>
146 #include <kern/work_interval.h>
148 #include <vm/vm_protos.h>
150 #include <security/mac_mach_internal.h>
152 extern char *proc_name_address(void *p
);
153 extern int proc_pid(void *p
);
156 * Routine: ipc_kobject_notify
158 * Deliver notifications to kobjects that care about them.
162 mach_msg_header_t
*request_header
,
163 mach_msg_header_t
*reply_header
);
167 mig_routine_t routine
;
170 mach_counter_t callcount
;
174 #define MAX_MIG_ENTRIES 1031
175 #define MIG_HASH(x) (x)
178 #define max(a, b) (((a) > (b)) ? (a) : (b))
181 static mig_hash_t mig_buckets
[MAX_MIG_ENTRIES
];
182 static int mig_table_max_displ
;
183 static mach_msg_size_t mig_reply_size
= sizeof(mig_reply_error_t
);
187 const struct mig_subsystem
*mig_e
[] = {
188 (const struct mig_subsystem
*)&mach_vm_subsystem
,
189 (const struct mig_subsystem
*)&mach_port_subsystem
,
190 (const struct mig_subsystem
*)&mach_host_subsystem
,
191 (const struct mig_subsystem
*)&host_priv_subsystem
,
192 (const struct mig_subsystem
*)&host_security_subsystem
,
193 (const struct mig_subsystem
*)&clock_subsystem
,
194 (const struct mig_subsystem
*)&clock_priv_subsystem
,
195 (const struct mig_subsystem
*)&processor_subsystem
,
196 (const struct mig_subsystem
*)&processor_set_subsystem
,
197 (const struct mig_subsystem
*)&is_iokit_subsystem
,
198 (const struct mig_subsystem
*)&lock_set_subsystem
,
199 (const struct mig_subsystem
*)&task_subsystem
,
200 (const struct mig_subsystem
*)&thread_act_subsystem
,
202 (const struct mig_subsystem
*)&vm32_map_subsystem
,
204 (const struct mig_subsystem
*)&UNDReply_subsystem
,
205 (const struct mig_subsystem
*)&mach_voucher_subsystem
,
206 (const struct mig_subsystem
*)&mach_voucher_attr_control_subsystem
,
207 (const struct mig_subsystem
*)&memory_entry_subsystem
,
208 (const struct mig_subsystem
*)&task_restartable_subsystem
,
211 (const struct mig_subsystem
*)&do_uproxy_xk_uproxy_subsystem
,
212 #endif /* XK_PROXY */
213 #if MACH_MACHINE_ROUTINES
214 (const struct mig_subsystem
*)&MACHINE_SUBSYSTEM
,
215 #endif /* MACH_MACHINE_ROUTINES */
217 (const struct mig_subsystem
*)&mcmsg_info_subsystem
,
218 #endif /* MCMSG && iPSC860 */
219 (const struct mig_subsystem
*)&catch_exc_subsystem
,
220 (const struct mig_subsystem
*)&catch_mach_exc_subsystem
,
222 (const struct mig_subsystem
*)&arcade_register_subsystem
,
229 unsigned int i
, n
= sizeof(mig_e
) / sizeof(const struct mig_subsystem
*);
231 mach_msg_id_t j
, pos
, nentry
, range
;
233 for (i
= 0; i
< n
; i
++) {
234 range
= mig_e
[i
]->end
- mig_e
[i
]->start
;
235 if (!mig_e
[i
]->start
|| range
< 0) {
236 panic("the msgh_ids in mig_e[] aren't valid!");
239 for (j
= 0; j
< range
; j
++) {
240 if (mig_e
[i
]->routine
[j
].stub_routine
) {
241 /* Only put real entries in the table */
242 nentry
= j
+ mig_e
[i
]->start
;
243 for (pos
= MIG_HASH(nentry
) % MAX_MIG_ENTRIES
, howmany
= 1;
244 mig_buckets
[pos
].num
;
245 pos
++, pos
= pos
% MAX_MIG_ENTRIES
, howmany
++) {
246 if (mig_buckets
[pos
].num
== nentry
) {
247 printf("message id = %d\n", nentry
);
248 panic("multiple entries with the same msgh_id");
250 if (howmany
== MAX_MIG_ENTRIES
) {
251 panic("the mig dispatch table is too small");
255 mig_buckets
[pos
].num
= nentry
;
256 mig_buckets
[pos
].routine
= mig_e
[i
]->routine
[j
].stub_routine
;
257 if (mig_e
[i
]->routine
[j
].max_reply_msg
) {
258 mig_buckets
[pos
].size
= mig_e
[i
]->routine
[j
].max_reply_msg
;
260 mig_buckets
[pos
].size
= mig_e
[i
]->maxsize
;
263 mig_table_max_displ
= max(howmany
, mig_table_max_displ
);
267 printf("mig_table_max_displ = %d\n", mig_table_max_displ
);
272 * Routine: ipc_kobject_server
274 * Handle a message sent to the kernel.
275 * Generates a reply message.
276 * Version for Untyped IPC.
284 mach_msg_option_t __unused option
)
286 mach_msg_size_t reply_size
;
289 ipc_port_t replyp
= IPC_PORT_NULL
;
290 mach_msg_format_0_trailer_t
*trailer
;
292 task_t task
= TASK_NULL
;
294 boolean_t exec_token_changed
= FALSE
;
295 int request_msgh_id
= request
->ikm_header
->msgh_id
;
300 port
= request
->ikm_header
->msgh_remote_port
;
301 if (IP_VALID(port
)) {
302 ikot
= ip_kotype(port
);
306 if (ikot
== IKOT_UEXT_OBJECT
) {
307 kr
= uext_server(request
, &reply
);
308 if ((MIG_NO_REPLY
== kr
) || (KERN_SUCCESS
== kr
)) {
309 ipc_kmsg_trace_send(request
, option
);
314 * Find corresponding mig_hash entry if any
317 unsigned int i
= (unsigned int)MIG_HASH(request_msgh_id
);
318 int max_iter
= mig_table_max_displ
;
321 ptr
= &mig_buckets
[i
++ % MAX_MIG_ENTRIES
];
322 } while (request_msgh_id
!= ptr
->num
&& ptr
->num
&& --max_iter
);
324 if (!ptr
->routine
|| request_msgh_id
!= ptr
->num
) {
325 ptr
= (mig_hash_t
*)0;
326 reply_size
= mig_reply_size
;
328 reply_size
= ptr
->size
;
335 /* round up for trailer size */
336 reply_size
+= MAX_TRAILER_SIZE
;
337 reply
= ipc_kmsg_alloc(reply_size
);
339 if (reply
== IKM_NULL
) {
340 printf("ipc_kobject_server: dropping request\n");
341 ipc_kmsg_trace_send(request
, option
);
342 ipc_kmsg_destroy(request
);
347 * Initialize reply message.
350 #define InP ((mach_msg_header_t *) request->ikm_header)
351 #define OutP ((mig_reply_error_t *) reply->ikm_header)
354 * MIG should really assure no data leakage -
355 * but until it does, pessimistically zero the
356 * whole reply buffer.
358 bzero((void *)OutP
, reply_size
);
360 OutP
->NDR
= NDR_record
;
361 OutP
->Head
.msgh_size
= sizeof(mig_reply_error_t
);
363 OutP
->Head
.msgh_bits
=
364 MACH_MSGH_BITS_SET(MACH_MSGH_BITS_LOCAL(InP
->msgh_bits
), 0, 0, 0);
365 OutP
->Head
.msgh_remote_port
= InP
->msgh_local_port
;
366 OutP
->Head
.msgh_local_port
= MACH_PORT_NULL
;
367 OutP
->Head
.msgh_voucher_port
= MACH_PORT_NULL
;
368 OutP
->Head
.msgh_id
= InP
->msgh_id
+ 100;
375 * Find the routine to call, and call it
376 * to perform the kernel function
378 ipc_kmsg_trace_send(request
, option
);
382 * Check if the port is a task port, if its a task port then
383 * snapshot the task exec token before the mig routine call.
385 if (ikot
== IKOT_TASK
) {
386 task
= convert_port_to_task_with_exec_token(port
, &exec_token
);
389 (*ptr
->routine
)(request
->ikm_header
, reply
->ikm_header
);
391 /* Check if the exec token changed during the mig routine */
392 if (task
!= TASK_NULL
) {
393 if (exec_token
!= task
->exec_token
) {
394 exec_token_changed
= TRUE
;
396 task_deallocate(task
);
399 kernel_task
->messages_received
++;
401 if (!ipc_kobject_notify(request
->ikm_header
, reply
->ikm_header
)) {
402 #if DEVELOPMENT || DEBUG
403 printf("ipc_kobject_server: bogus kernel message, id=%d\n",
404 request
->ikm_header
->msgh_id
);
405 #endif /* DEVELOPMENT || DEBUG */
406 _MIG_MSGID_INVALID(request
->ikm_header
->msgh_id
);
408 ((mig_reply_error_t
*) reply
->ikm_header
)->RetCode
411 kernel_task
->messages_received
++;
414 kernel_task
->messages_sent
++;
417 if (!(reply
->ikm_header
->msgh_bits
& MACH_MSGH_BITS_COMPLEX
) &&
418 ((mig_reply_error_t
*) reply
->ikm_header
)->RetCode
!= KERN_SUCCESS
) {
419 kr
= ((mig_reply_error_t
*) reply
->ikm_header
)->RetCode
;
426 * Destroy destination. The following code differs from
427 * ipc_object_destroy in that we release the send-once
428 * right instead of generating a send-once notification
429 * (which would bring us here again, creating a loop).
430 * It also differs in that we only expect send or
431 * send-once rights, never receive rights.
433 * We set msgh_remote_port to IP_NULL so that the kmsg
434 * destroy routines don't try to destroy the port twice.
436 switch (MACH_MSGH_BITS_REMOTE(request
->ikm_header
->msgh_bits
)) {
437 case MACH_MSG_TYPE_PORT_SEND
:
438 ipc_port_release_send(request
->ikm_header
->msgh_remote_port
);
439 request
->ikm_header
->msgh_remote_port
= IP_NULL
;
442 case MACH_MSG_TYPE_PORT_SEND_ONCE
:
443 ipc_port_release_sonce(request
->ikm_header
->msgh_remote_port
);
444 request
->ikm_header
->msgh_remote_port
= IP_NULL
;
448 panic("ipc_kobject_server: strange destination rights");
452 * Destroy voucher. The kernel MIG servers never take ownership
453 * of vouchers sent in messages. Swallow any such rights here.
455 if (IP_VALID(request
->ikm_voucher
)) {
456 assert(MACH_MSG_TYPE_PORT_SEND
==
457 MACH_MSGH_BITS_VOUCHER(request
->ikm_header
->msgh_bits
));
458 ipc_port_release_send(request
->ikm_voucher
);
459 request
->ikm_voucher
= IP_NULL
;
462 if ((kr
== KERN_SUCCESS
) || (kr
== MIG_NO_REPLY
)) {
464 * The server function is responsible for the contents
465 * of the message. The reply port right is moved
466 * to the reply message, and we have deallocated
467 * the destination port right, so we just need
470 ipc_kmsg_free(request
);
473 * The message contents of the request are intact.
474 * Destroy everthing except the reply port right,
475 * which is needed in the reply message.
477 request
->ikm_header
->msgh_local_port
= MACH_PORT_NULL
;
478 ipc_kmsg_destroy(request
);
481 if (kr
== MIG_NO_REPLY
) {
483 * The server function will send a reply message
484 * using the reply port right, which it has saved.
488 ipc_kmsg_free(reply
);
494 replyp
= reply
->ikm_header
->msgh_remote_port
;
497 if (!IP_VALID(replyp
)) {
499 * Can't queue the reply message if the destination
500 * (the reply port) isn't valid.
503 ipc_kmsg_destroy(reply
);
506 } else if (replyp
->ip_receiver
== ipc_space_kernel
) {
508 * Don't send replies to kobject kernel ports
510 #if DEVELOPMENT || DEBUG
511 printf("%s: refusing to send reply to kobject %d port (id:%d)\n",
512 __func__
, ip_kotype(replyp
), request_msgh_id
);
513 #endif /* DEVELOPMENT || DEBUG */
514 ipc_kmsg_destroy(reply
);
518 /* Fail the MIG call if the task exec token changed during the call */
519 if (kr
== KERN_SUCCESS
&& exec_token_changed
) {
521 * Create a new reply msg with error and destroy the old reply msg.
523 ipc_kmsg_t new_reply
= ipc_kmsg_alloc(reply_size
);
525 if (new_reply
== IKM_NULL
) {
526 printf("ipc_kobject_server: dropping request\n");
527 ipc_kmsg_destroy(reply
);
531 * Initialize the new reply message.
534 #define OutP_new ((mig_reply_error_t *) new_reply->ikm_header)
535 #define OutP_old ((mig_reply_error_t *) reply->ikm_header)
537 bzero((void *)OutP_new
, reply_size
);
539 OutP_new
->NDR
= OutP_old
->NDR
;
540 OutP_new
->Head
.msgh_size
= sizeof(mig_reply_error_t
);
541 OutP_new
->Head
.msgh_bits
= OutP_old
->Head
.msgh_bits
& ~MACH_MSGH_BITS_COMPLEX
;
542 OutP_new
->Head
.msgh_remote_port
= OutP_old
->Head
.msgh_remote_port
;
543 OutP_new
->Head
.msgh_local_port
= MACH_PORT_NULL
;
544 OutP_new
->Head
.msgh_voucher_port
= MACH_PORT_NULL
;
545 OutP_new
->Head
.msgh_id
= OutP_old
->Head
.msgh_id
;
547 /* Set the error as KERN_INVALID_TASK */
548 OutP_new
->RetCode
= KERN_INVALID_TASK
;
555 * Destroy everything in reply except the reply port right,
556 * which is needed in the new reply message.
558 reply
->ikm_header
->msgh_remote_port
= MACH_PORT_NULL
;
559 ipc_kmsg_destroy(reply
);
564 trailer
= (mach_msg_format_0_trailer_t
*)
565 ((vm_offset_t
)reply
->ikm_header
+ (int)reply
->ikm_header
->msgh_size
);
567 trailer
->msgh_sender
= KERNEL_SECURITY_TOKEN
;
568 trailer
->msgh_trailer_type
= MACH_MSG_TRAILER_FORMAT_0
;
569 trailer
->msgh_trailer_size
= MACH_MSG_TRAILER_MINIMUM_SIZE
;
575 * Routine: ipc_kobject_set
577 * Make a port represent a kernel object of the given type.
578 * The caller is responsible for handling refs for the
579 * kernel object, if necessary.
581 * Nothing locked. The port must be active if setting
582 * a kobject linkage. Clearing a linkage is OK on an
588 ipc_kobject_t kobject
,
589 ipc_kobject_type_t type
)
592 ipc_kobject_set_atomically(port
, kobject
, type
);
597 ipc_kobject_set_atomically(
599 ipc_kobject_t kobject
,
600 ipc_kobject_type_t type
)
602 assert(type
== IKOT_NONE
|| ip_active(port
));
604 port
->ip_spares
[2] = (port
->ip_object
.io_bits
& IO_BITS_KOTYPE
);
605 #endif /* MACH_ASSERT */
606 port
->ip_object
.io_bits
= (port
->ip_object
.io_bits
& ~IO_BITS_KOTYPE
) | type
;
607 port
->ip_kobject
= kobject
;
608 if (type
!= IKOT_NONE
) {
609 /* Once set, this bit can never be unset */
610 port
->ip_object
.io_bits
|= IO_BITS_KOBJECT
;
615 * Routine: ipc_kobject_alloc_port
617 * Allocate a kobject port in the kernel space of the specified type.
619 * This function never fails.
622 * No locks held (memory is allocated)
625 ipc_kobject_alloc_port(
626 ipc_kobject_t kobject
,
627 ipc_kobject_type_t type
,
628 ipc_kobject_alloc_options_t options
)
630 ipc_port_init_flags_t flags
;
634 if (options
& IPC_KOBJECT_ALLOC_IN_TRANSIT
) {
635 /* kobject port intended to be copied out to user-space */
636 flags
= IPC_PORT_INIT_MESSAGE_QUEUE
;
639 /* true kernel-bound kobject port */
640 flags
= IPC_PORT_INIT_NONE
;
641 space
= ipc_space_kernel
;
643 port
= ipc_port_alloc_special(space
, flags
);
644 if (port
== IP_NULL
) {
645 panic("ipc_kobject_alloc_port(): failed to allocate port");
648 ipc_kobject_set_atomically(port
, kobject
, type
);
650 if (options
& IPC_KOBJECT_ALLOC_MAKE_SEND
) {
651 ipc_port_make_send_locked(port
);
654 if (options
& IPC_KOBJECT_ALLOC_IN_TRANSIT
) {
655 /* reset the port like it has been copied in circularity checked */
656 if (options
& IPC_KOBJECT_ALLOC_NSREQUEST
) {
657 panic("ipc_kobject_alloc_port(): invalid option for user-space port");
659 port
->ip_mscount
= 0;
660 assert(port
->ip_tempowner
== 0);
661 assert(port
->ip_receiver
== IS_NULL
);
662 port
->ip_receiver
= IS_NULL
;
663 port
->ip_receiver_name
= MACH_PORT_NULL
;
665 if (options
& IPC_KOBJECT_ALLOC_NSREQUEST
) {
666 ipc_port_make_sonce_locked(port
);
667 port
->ip_nsrequest
= port
;
670 if (options
& IPC_KOBJECT_ALLOC_IMMOVABLE_SEND
) {
671 port
->ip_immovable_send
= 1;
673 if (options
& IPC_KOBJECT_ALLOC_NO_GRANT
) {
674 port
->ip_no_grant
= 1;
681 * Routine: ipc_kobject_make_send_lazy_alloc_port
683 * Make a send once for a kobject port.
685 * A location owning this port is passed in port_store.
686 * If no port exists, a port is made lazily.
688 * A send right is made for the port, and if this is the first one
689 * (possibly not for the first time), then the no-more-senders
690 * notification is rearmed.
692 * When a notification is armed, the kobject must donate
693 * one of its references to the port. It is expected
694 * the no-more-senders notification will consume this reference.
697 * TRUE if a notification was armed
701 * Nothing is locked, memory can be allocated.
702 * The caller must be able to donate a kobject reference to the port.
705 ipc_kobject_make_send_lazy_alloc_port(
706 ipc_port_t
*port_store
,
707 ipc_kobject_t kobject
,
708 ipc_kobject_type_t type
)
710 ipc_port_t port
, previous
;
711 boolean_t rc
= FALSE
;
713 port
= os_atomic_load(port_store
, dependency
);
715 if (!IP_VALID(port
)) {
716 port
= ipc_kobject_alloc_port(kobject
, type
,
717 IPC_KOBJECT_ALLOC_MAKE_SEND
| IPC_KOBJECT_ALLOC_NSREQUEST
);
718 if (os_atomic_cmpxchgv(port_store
, IP_NULL
, port
, &previous
, release
)) {
722 // undo what ipc_kobject_alloc_port() did above
723 port
->ip_nsrequest
= IP_NULL
;
724 port
->ip_mscount
= 0;
725 port
->ip_sorights
= 0;
726 port
->ip_srights
= 0;
729 ipc_port_dealloc_kernel(port
);
735 ipc_port_make_send_locked(port
);
736 if (port
->ip_srights
== 1) {
737 ipc_port_make_sonce_locked(port
);
738 assert(port
->ip_nsrequest
== IP_NULL
);
739 port
->ip_nsrequest
= port
;
748 * Routine: ipc_kobject_destroy
750 * Release any kernel object resources associated
751 * with the port, which is being destroyed.
753 * This should only be needed when resources are
754 * associated with a user's port. In the normal case,
755 * when the kernel is the receiver, the code calling
756 * ipc_port_dealloc_kernel should clean up the resources.
758 * The port is not locked, but it is dead.
765 switch (ip_kotype(port
)) {
767 mk_timer_port_destroy(port
);
770 case IKOT_NAMED_ENTRY
:
771 mach_destroy_memory_entry(port
);
774 case IKOT_HOST_NOTIFY
:
775 host_notify_port_destroy(port
);
786 mach_msg_header_t
*request_header
,
787 mach_msg_header_t
*reply_header
)
789 mach_msg_max_trailer_t
* trailer
;
790 ipc_port_t port
= request_header
->msgh_remote_port
;
792 ((mig_reply_error_t
*) reply_header
)->RetCode
= MIG_NO_REPLY
;
794 trailer
= (mach_msg_max_trailer_t
*)
795 ((vm_offset_t
)request_header
+ request_header
->msgh_size
);
798 * The kobject notification is privileged and can change the
799 * refcount on kernel-internal objects - make sure
800 * that the message wasn't faked!
802 if (0 != bcmp(&trailer
->msgh_audit
, &KERNEL_AUDIT_TOKEN
,
803 sizeof(trailer
->msgh_audit
))) {
806 if (0 != bcmp(&trailer
->msgh_sender
, &KERNEL_SECURITY_TOKEN
,
807 sizeof(trailer
->msgh_sender
))) {
811 switch (request_header
->msgh_id
) {
812 case MACH_NOTIFY_NO_SENDERS
:
813 switch (ip_kotype(port
)) {
815 ipc_voucher_notify(request_header
);
818 case IKOT_VOUCHER_ATTR_CONTROL
:
819 ipc_voucher_attr_control_notify(request_header
);
823 semaphore_notify(request_header
);
827 task_port_notify(request_header
);
830 case IKOT_NAMED_ENTRY
:
834 * Bring the sequence number and mscount in
835 * line with ipc_port_destroy assertion.
837 port
->ip_mscount
= 0;
838 port
->ip_messages
.imq_seqno
= 0;
839 ipc_port_destroy(port
); /* releases lock */
844 request_header
->msgh_remote_port
,
845 (mach_port_mscount_t
)
846 ((mach_no_senders_notification_t
*)
847 request_header
)->not_count
);
848 reply_header
->msgh_remote_port
= MACH_PORT_NULL
;
852 case IKOT_AU_SESSIONPORT
:
853 audit_session_nosenders(request_header
);
857 fileport_notify(request_header
);
860 case IKOT_WORK_INTERVAL
:
861 work_interval_port_notify(request_header
);
866 case MACH_NOTIFY_PORT_DELETED
:
867 case MACH_NOTIFY_PORT_DESTROYED
:
868 case MACH_NOTIFY_SEND_ONCE
:
869 case MACH_NOTIFY_DEAD_NAME
:
875 switch (ip_kotype(port
)) {
877 case IKOT_IOKIT_OBJECT
:
878 case IKOT_IOKIT_CONNECT
:
879 case IKOT_IOKIT_IDENT
:
880 case IKOT_UEXT_OBJECT
:
882 return iokit_notify(request_header
);
885 case IKOT_TASK_RESUME
:
887 return task_suspension_notify(request_header
);