]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/ipc/ipc_notify.c
xnu-2782.10.72.tar.gz
[apple/xnu.git] / osfmk / ipc / ipc_notify.c
index e00829214b1e4dc34b898dfd081149c697ab9357..498401cc005555bc9e63e1f606324c7b2806178d 100644 (file)
@@ -1,16 +1,19 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  * This file contains Original Code and/or Modifications of Original Code
  * as defined in and that are subject to the Apple Public Source License
  * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
+ * 
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
  * 
  * The Original Code and all software distributed under the License are
  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
@@ -20,7 +23,7 @@
  * Please see the License for the specific language governing rights and
  * limitations under the License.
  * 
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 /*
  * @OSF_COPYRIGHT@
  *     Notification-sending functions.
  */
 
-#include <mach_rt.h>
-
 #include <mach/port.h>
 #include <mach/message.h>
-#include <mach/notify.h>
-#include <kern/assert.h>
+#include <mach/mach_notify.h>
 #include <kern/misc_protos.h>
-#include <ipc/ipc_kmsg.h>
-#include <ipc/ipc_mqueue.h>
 #include <ipc/ipc_notify.h>
 #include <ipc/ipc_port.h>
 
 /*
- * Forward declarations
- */
-void ipc_notify_init_port_deleted(
-       mach_port_deleted_notification_t        *n);
-
-void ipc_notify_init_port_destroyed(
-       mach_port_destroyed_notification_t      *n);
-
-void ipc_notify_init_no_senders(
-       mach_no_senders_notification_t          *n);
-
-void ipc_notify_init_send_once(
-       mach_send_once_notification_t           *n);
-
-void ipc_notify_init_dead_name(
-       mach_dead_name_notification_t           *n);
-
-mach_port_deleted_notification_t       ipc_notify_port_deleted_template;
-mach_port_destroyed_notification_t     ipc_notify_port_destroyed_template;
-mach_no_senders_notification_t         ipc_notify_no_senders_template;
-mach_send_once_notification_t          ipc_notify_send_once_template;
-mach_dead_name_notification_t          ipc_notify_dead_name_template;
-
-/*
- *     Routine:        ipc_notify_init_port_deleted
- *     Purpose:
- *             Initialize a template for port-deleted notifications.
- */
-
-void
-ipc_notify_init_port_deleted(
-       mach_port_deleted_notification_t        *n)
-{
-       mach_msg_header_t *m = &n->not_header;
-
-       m->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, 0);
-       m->msgh_local_port = MACH_PORT_NULL;
-       m->msgh_remote_port = MACH_PORT_NULL;
-       m->msgh_id = MACH_NOTIFY_PORT_DELETED;
-       m->msgh_size = ((int)sizeof *n) - sizeof(mach_msg_format_0_trailer_t);
-
-       n->not_port = MACH_PORT_NULL;
-       n->NDR = NDR_record;
-       n->trailer.msgh_seqno = 0;
-       n->trailer.msgh_sender = KERNEL_SECURITY_TOKEN;
-       n->trailer.msgh_trailer_type = MACH_MSG_TRAILER_FORMAT_0;
-       n->trailer.msgh_trailer_size = MACH_MSG_TRAILER_MINIMUM_SIZE;
-}
-
-/*
- *     Routine:        ipc_notify_init_port_destroyed
- *     Purpose:
- *             Initialize a template for port-destroyed notifications.
- */
-
-void
-ipc_notify_init_port_destroyed(
-       mach_port_destroyed_notification_t      *n)
-{
-       mach_msg_header_t *m = &n->not_header;
-
-       m->msgh_bits = MACH_MSGH_BITS_COMPLEX |
-               MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, 0);
-       m->msgh_local_port = MACH_PORT_NULL;
-       m->msgh_remote_port = MACH_PORT_NULL;
-       m->msgh_id = MACH_NOTIFY_PORT_DESTROYED;
-       m->msgh_size = ((int)sizeof *n) - sizeof(mach_msg_format_0_trailer_t);
-
-       n->not_body.msgh_descriptor_count = 1;
-       n->not_port.disposition = MACH_MSG_TYPE_PORT_RECEIVE;
-       n->not_port.name = MACH_PORT_NULL;
-       n->not_port.type = MACH_MSG_PORT_DESCRIPTOR;
-       n->trailer.msgh_seqno = 0;
-       n->trailer.msgh_sender = KERNEL_SECURITY_TOKEN;
-       n->trailer.msgh_trailer_type = MACH_MSG_TRAILER_FORMAT_0;
-       n->trailer.msgh_trailer_size = MACH_MSG_TRAILER_MINIMUM_SIZE;
-}
-
-/*
- *     Routine:        ipc_notify_init_no_senders
- *     Purpose:
- *             Initialize a template for no-senders notifications.
- */
-
-void
-ipc_notify_init_no_senders(
-       mach_no_senders_notification_t  *n)
-{
-       mach_msg_header_t *m = &n->not_header;
-
-       m->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, 0);
-       m->msgh_local_port = MACH_PORT_NULL;
-       m->msgh_remote_port = MACH_PORT_NULL;
-       m->msgh_id = MACH_NOTIFY_NO_SENDERS;
-       m->msgh_size = ((int)sizeof *n) - sizeof(mach_msg_format_0_trailer_t);
-
-       n->NDR = NDR_record;
-       n->trailer.msgh_seqno = 0;
-       n->trailer.msgh_sender = KERNEL_SECURITY_TOKEN;
-       n->trailer.msgh_trailer_type = MACH_MSG_TRAILER_FORMAT_0;
-       n->trailer.msgh_trailer_size = MACH_MSG_TRAILER_MINIMUM_SIZE;
-       n->not_count = 0;
-}
-
-/*
- *     Routine:        ipc_notify_init_send_once
- *     Purpose:
- *             Initialize a template for send-once notifications.
- */
-
-void
-ipc_notify_init_send_once(
-       mach_send_once_notification_t   *n)
-{
-       mach_msg_header_t *m = &n->not_header;
-
-       m->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, 0);
-       m->msgh_local_port = MACH_PORT_NULL;
-       m->msgh_remote_port = MACH_PORT_NULL;
-       m->msgh_id = MACH_NOTIFY_SEND_ONCE;
-       m->msgh_size = ((int)sizeof *n) - sizeof(mach_msg_format_0_trailer_t);
-       n->trailer.msgh_seqno = 0;
-       n->trailer.msgh_sender = KERNEL_SECURITY_TOKEN;
-       n->trailer.msgh_trailer_type = MACH_MSG_TRAILER_FORMAT_0;
-       n->trailer.msgh_trailer_size = MACH_MSG_TRAILER_MINIMUM_SIZE;
-}
-
-/*
- *     Routine:        ipc_notify_init_dead_name
- *     Purpose:
- *             Initialize a template for dead-name notifications.
- */
-
-void
-ipc_notify_init_dead_name(
-       mach_dead_name_notification_t   *n)
-{
-       mach_msg_header_t *m = &n->not_header;
-
-       m->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, 0);
-       m->msgh_local_port = MACH_PORT_NULL;
-       m->msgh_remote_port = MACH_PORT_NULL;
-       m->msgh_id = MACH_NOTIFY_DEAD_NAME;
-       m->msgh_size = ((int)sizeof *n) - sizeof(mach_msg_format_0_trailer_t);
-
-       n->not_port = MACH_PORT_NULL;
-       n->NDR = NDR_record;
-       n->trailer.msgh_seqno = 0;
-       n->trailer.msgh_sender = KERNEL_SECURITY_TOKEN;
-       n->trailer.msgh_trailer_type = MACH_MSG_TRAILER_FORMAT_0;
-       n->trailer.msgh_trailer_size = MACH_MSG_TRAILER_MINIMUM_SIZE;
-}
-
-/*
- *     Routine:        ipc_notify_init
+ *     Routine:        ipc_notify_port_deleted
  *     Purpose:
- *             Initialize the notification subsystem.
+ *             Send a port-deleted notification.
+ *     Conditions:
+ *             Nothing locked.
+ *             Consumes a ref/soright for port.
  */
 
 void
-ipc_notify_init(void)
+ipc_notify_port_deleted(
+       ipc_port_t              port,
+       mach_port_name_t        name)
 {
-       ipc_notify_init_port_deleted(&ipc_notify_port_deleted_template);
-       ipc_notify_init_port_destroyed(&ipc_notify_port_destroyed_template);
-       ipc_notify_init_no_senders(&ipc_notify_no_senders_template);
-       ipc_notify_init_send_once(&ipc_notify_send_once_template);
-       ipc_notify_init_dead_name(&ipc_notify_dead_name_template);
+       (void)mach_notify_port_deleted(port, name);
+       /* send-once right consumed */
 }
 
 /*
- *     Routine:        ipc_notify_port_deleted
+ *     Routine:        ipc_notify_send_possible
  *     Purpose:
- *             Send a port-deleted notification.
+ *             Send a send-possible notification.
  *     Conditions:
  *             Nothing locked.
  *             Consumes a ref/soright for port.
  */
 
 void
-ipc_notify_port_deleted(
+ipc_notify_send_possible(
        ipc_port_t              port,
        mach_port_name_t        name)
 {
-       ipc_kmsg_t kmsg;
-       mach_port_deleted_notification_t *n;
-
-       kmsg = ipc_kmsg_alloc(sizeof *n);
-       if (kmsg == IKM_NULL) {
-               printf("dropped port-deleted (0x%08x, 0x%x)\n", port, name);
-               ipc_port_release_sonce(port);
-               return;
-       }
-
-       n = (mach_port_deleted_notification_t *) &kmsg->ikm_header;
-       *n = ipc_notify_port_deleted_template;
-
-       n->not_header.msgh_remote_port = port;
-       n->not_port = name;
-
-       ipc_kmsg_send_always(kmsg);
+       (void)mach_notify_send_possible(port, name);
+       /* send-once right consumed */
 }
 
 /*
@@ -292,25 +123,8 @@ ipc_notify_port_destroyed(
        ipc_port_t      port,
        ipc_port_t      right)
 {
-       ipc_kmsg_t kmsg;
-       mach_port_destroyed_notification_t *n;
-
-       kmsg = ipc_kmsg_alloc(sizeof *n);
-       if (kmsg == IKM_NULL) {
-               printf("dropped port-destroyed (0x%08x, 0x%08x)\n",
-                      port, right);
-               ipc_port_release_sonce(port);
-               ipc_port_release_receive(right);
-               return;
-       }
-
-       n = (mach_port_destroyed_notification_t *) &kmsg->ikm_header;
-       *n = ipc_notify_port_destroyed_template;
-
-       n->not_header.msgh_remote_port = port;
-       n->not_port.name = right;
-
-       ipc_kmsg_send_always(kmsg);
+       mach_notify_port_destroyed(port, right);
+       /* send-once and receive rights consumed */
 }
 
 /*
@@ -327,23 +141,8 @@ ipc_notify_no_senders(
        ipc_port_t              port,
        mach_port_mscount_t     mscount)
 {
-       ipc_kmsg_t kmsg;
-       mach_no_senders_notification_t *n;
-
-       kmsg = ipc_kmsg_alloc(sizeof *n);
-       if (kmsg == IKM_NULL) {
-               printf("dropped no-senders (0x%08x, %u)\n", port, mscount);
-               ipc_port_release_sonce(port);
-               return;
-       }
-
-       n = (mach_no_senders_notification_t *) &kmsg->ikm_header;
-       *n = ipc_notify_no_senders_template;
-
-       n->not_header.msgh_remote_port = port;
-       n->not_count = mscount;
-
-       ipc_kmsg_send_always(kmsg);
+       (void)mach_notify_no_senders(port, mscount);
+       /* send-once right consumed */
 }
 
 /*
@@ -359,22 +158,8 @@ void
 ipc_notify_send_once(
        ipc_port_t      port)
 {
-       ipc_kmsg_t kmsg;
-       mach_send_once_notification_t *n;
-
-       kmsg = ipc_kmsg_alloc(sizeof *n);
-       if (kmsg == IKM_NULL) {
-               printf("dropped send-once (0x%08x)\n", port);
-               ipc_port_release_sonce(port);
-               return;
-       }
-
-       n = (mach_send_once_notification_t *) &kmsg->ikm_header;
-       *n = ipc_notify_send_once_template;
-
-        n->not_header.msgh_remote_port = port;
-
-       ipc_kmsg_send_always(kmsg);
+       (void)mach_notify_send_once(port);
+       /* send-once right consumed */
 }
 
 /*
@@ -391,21 +176,6 @@ ipc_notify_dead_name(
        ipc_port_t              port,
        mach_port_name_t        name)
 {
-       ipc_kmsg_t kmsg;
-       mach_dead_name_notification_t *n;
-
-       kmsg = ipc_kmsg_alloc(sizeof *n);
-       if (kmsg == IKM_NULL) {
-               printf("dropped dead-name (0x%08x, 0x%x)\n", port, name);
-               ipc_port_release_sonce(port);
-               return;
-       }
-
-       n = (mach_dead_name_notification_t *) &kmsg->ikm_header;
-       *n = ipc_notify_dead_name_template;
-
-       n->not_header.msgh_remote_port = port;
-       n->not_port = name;
-
-       ipc_kmsg_send_always(kmsg);
+       (void)mach_notify_dead_name(port, name);
+       /* send-once right consumed */
 }