123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- /*
- * Mach Operating System
- * Copyright (c) 1991,1990,1989 Carnegie Mellon University
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
- * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie Mellon
- * the rights to redistribute these changes.
- */
- /*
- * File: ipc/ipc_notify.c
- * Author: Rich Draves
- * Date: 1989
- *
- * Notification-sending functions.
- */
-
- #pragma GCC diagnostic error "-Wundef"
-
- #include <glue/gnulinux.h>
- #include <kern/printf.h>
- #include <mach/port.h>
- #include <mach/message.h>
- #include <mach/notify.h>
- #include <kern/assert.h>
- #include <ipc/ipc_kmsg.h>
- #include <ipc/ipc_mqueue.h>
- #include <ipc/ipc_notify.h>
- #include <ipc/ipc_port.h>
- #include <ipc/ipc_machdep.h>
- mach_port_deleted_notification_t ipc_notify_port_deleted_template;
- mach_msg_accepted_notification_t ipc_notify_msg_accepted_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;
- #define NOTIFY_MSGH_SEQNO 0
- /*
- * 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;
- mach_msg_type_t *t = &n->not_type;
- m->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, 0);
- m->msgh_size = sizeof *n;
- m->msgh_seqno = NOTIFY_MSGH_SEQNO;
- m->msgh_local_port = MACH_PORT_NULL;
- m->msgh_remote_port = MACH_PORT_NULL;
- m->msgh_id = MACH_NOTIFY_PORT_DELETED;
- t->msgt_name = MACH_MSG_TYPE_PORT_NAME;
- t->msgt_size = PORT_T_SIZE_IN_BITS;
- t->msgt_number = 1;
- t->msgt_inline = TRUE;
- t->msgt_longform = FALSE;
- t->msgt_deallocate = FALSE;
- t->msgt_unused = 0;
- n->not_port = MACH_PORT_NULL;
- }
- /*
- * Routine: ipc_notify_init_msg_accepted
- * Purpose:
- * Initialize a template for msg-accepted notifications.
- */
- void
- ipc_notify_init_msg_accepted(mach_msg_accepted_notification_t *n)
- {
- mach_msg_header_t *m = &n->not_header;
- mach_msg_type_t *t = &n->not_type;
- m->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, 0);
- m->msgh_size = sizeof *n;
- m->msgh_seqno = NOTIFY_MSGH_SEQNO;
- m->msgh_local_port = MACH_PORT_NULL;
- m->msgh_remote_port = MACH_PORT_NULL;
- m->msgh_id = MACH_NOTIFY_MSG_ACCEPTED;
- t->msgt_name = MACH_MSG_TYPE_PORT_NAME;
- t->msgt_size = PORT_T_SIZE_IN_BITS;
- t->msgt_number = 1;
- t->msgt_inline = TRUE;
- t->msgt_longform = FALSE;
- t->msgt_deallocate = FALSE;
- t->msgt_unused = 0;
- n->not_port = MACH_PORT_NULL;
- }
- /*
- * 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;
- mach_msg_type_t *t = &n->not_type;
- m->msgh_bits = MACH_MSGH_BITS_COMPLEX |
- MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, 0);
- m->msgh_size = sizeof *n;
- m->msgh_seqno = NOTIFY_MSGH_SEQNO;
- m->msgh_local_port = MACH_PORT_NULL;
- m->msgh_remote_port = MACH_PORT_NULL;
- m->msgh_id = MACH_NOTIFY_PORT_DESTROYED;
- t->msgt_name = MACH_MSG_TYPE_PORT_RECEIVE;
- t->msgt_size = PORT_T_SIZE_IN_BITS;
- t->msgt_number = 1;
- t->msgt_inline = TRUE;
- t->msgt_longform = FALSE;
- t->msgt_deallocate = FALSE;
- t->msgt_unused = 0;
- n->not_port = MACH_PORT_NULL;
- }
- /*
- * 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;
- mach_msg_type_t *t = &n->not_type;
- m->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, 0);
- m->msgh_size = sizeof *n;
- m->msgh_seqno = NOTIFY_MSGH_SEQNO;
- m->msgh_local_port = MACH_PORT_NULL;
- m->msgh_remote_port = MACH_PORT_NULL;
- m->msgh_id = MACH_NOTIFY_NO_SENDERS;
- t->msgt_name = MACH_MSG_TYPE_INTEGER_32;
- t->msgt_size = PORT_T_SIZE_IN_BITS;
- t->msgt_number = 1;
- t->msgt_inline = TRUE;
- t->msgt_longform = FALSE;
- t->msgt_deallocate = FALSE;
- t->msgt_unused = 0;
- 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_size = sizeof *n;
- m->msgh_seqno = NOTIFY_MSGH_SEQNO;
- m->msgh_local_port = MACH_PORT_NULL;
- m->msgh_remote_port = MACH_PORT_NULL;
- m->msgh_id = MACH_NOTIFY_SEND_ONCE;
- }
- /*
- * 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;
- mach_msg_type_t *t = &n->not_type;
- m->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_PORT_SEND_ONCE, 0);
- m->msgh_size = sizeof *n;
- m->msgh_seqno = NOTIFY_MSGH_SEQNO;
- m->msgh_local_port = MACH_PORT_NULL;
- m->msgh_remote_port = MACH_PORT_NULL;
- m->msgh_id = MACH_NOTIFY_DEAD_NAME;
- t->msgt_name = MACH_MSG_TYPE_PORT_NAME;
- t->msgt_size = PORT_T_SIZE_IN_BITS;
- t->msgt_number = 1;
- t->msgt_inline = TRUE;
- t->msgt_longform = FALSE;
- t->msgt_deallocate = FALSE;
- t->msgt_unused = 0;
- n->not_port = MACH_PORT_NULL;
- }
- /*
- * Routine: ipc_notify_init
- * Purpose:
- * Initialize the notification subsystem.
- */
- void
- ipc_notify_init(void)
- {
- ipc_notify_init_port_deleted(&ipc_notify_port_deleted_template);
- ipc_notify_init_msg_accepted(&ipc_notify_msg_accepted_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);
- }
- /*
- * Routine: ipc_notify_port_deleted
- * Purpose:
- * Send a port-deleted notification.
- * Conditions:
- * Nothing locked.
- * Consumes a ref/soright for port.
- */
- void
- ipc_notify_port_deleted(
- ipc_port_t port,
- mach_port_t name)
- {
- ipc_kmsg_t kmsg;
- mach_port_deleted_notification_t *n;
- kmsg = ikm_alloc(sizeof *n);
- if (kmsg == IKM_NULL) {
- printf("dropped port-deleted (0x%p, 0x%lx)\n", port, name);
- ipc_port_release_sonce(port);
- return;
- }
- ikm_init(kmsg, sizeof *n);
- n = (mach_port_deleted_notification_t *) &kmsg->ikm_header;
- *n = ipc_notify_port_deleted_template;
- n->not_header.msgh_remote_port = (mach_port_t) port;
- n->not_port = name;
- ipc_mqueue_send_always(kmsg);
- }
- /*
- * Routine: ipc_notify_msg_accepted
- * Purpose:
- * Send a msg-accepted notification.
- * Conditions:
- * Nothing locked.
- * Consumes a ref/soright for port.
- */
- void
- ipc_notify_msg_accepted(
- ipc_port_t port,
- mach_port_t name)
- {
- ipc_kmsg_t kmsg;
- mach_msg_accepted_notification_t *n;
- kmsg = ikm_alloc(sizeof *n);
- if (kmsg == IKM_NULL) {
- printf("dropped msg-accepted (0x%p, 0x%lx)\n", port, name);
- ipc_port_release_sonce(port);
- return;
- }
- ikm_init(kmsg, sizeof *n);
- n = (mach_msg_accepted_notification_t *) &kmsg->ikm_header;
- *n = ipc_notify_msg_accepted_template;
- n->not_header.msgh_remote_port = (mach_port_t) port;
- n->not_port = name;
- ipc_mqueue_send_always(kmsg);
- }
- /*
- * Routine: ipc_notify_port_destroyed
- * Purpose:
- * Send a port-destroyed notification.
- * Conditions:
- * Nothing locked.
- * Consumes a ref/soright for port.
- * Consumes a ref for right, which should be a receive right
- * prepped for placement into a message. (In-transit,
- * or in-limbo if a circularity was detected.)
- */
- void
- ipc_notify_port_destroyed(
- ipc_port_t port,
- ipc_port_t right)
- {
- ipc_kmsg_t kmsg;
- mach_port_destroyed_notification_t *n;
- kmsg = ikm_alloc(sizeof *n);
- if (kmsg == IKM_NULL) {
- printf("dropped port-destroyed (0x%p, 0x%p)\n",
- port, right);
- ipc_port_release_sonce(port);
- ipc_port_release_receive(right);
- return;
- }
- ikm_init(kmsg, sizeof *n);
- n = (mach_port_destroyed_notification_t *) &kmsg->ikm_header;
- *n = ipc_notify_port_destroyed_template;
- n->not_header.msgh_remote_port = (mach_port_t) port;
- n->not_port = (mach_port_t) right;
- ipc_mqueue_send_always(kmsg);
- }
- /*
- * Routine: ipc_notify_no_senders
- * Purpose:
- * Send a no-senders notification.
- * Conditions:
- * Nothing locked.
- * Consumes a ref/soright for port.
- */
- void
- ipc_notify_no_senders(
- ipc_port_t port,
- mach_port_mscount_t mscount)
- {
- ipc_kmsg_t kmsg;
- mach_no_senders_notification_t *n;
- kmsg = ikm_alloc(sizeof *n);
- if (kmsg == IKM_NULL) {
- printf("dropped no-senders (0x%p, %u)\n", port, mscount);
- ipc_port_release_sonce(port);
- return;
- }
- ikm_init(kmsg, sizeof *n);
- n = (mach_no_senders_notification_t *) &kmsg->ikm_header;
- *n = ipc_notify_no_senders_template;
- n->not_header.msgh_remote_port = (mach_port_t) port;
- n->not_count = mscount;
- ipc_mqueue_send_always(kmsg);
- }
- /*
- * Routine: ipc_notify_send_once
- * Purpose:
- * Send a send-once notification.
- * Conditions:
- * Nothing locked.
- * Consumes a ref/soright for port.
- */
- void
- ipc_notify_send_once(ipc_port_t port)
- {
- ipc_kmsg_t kmsg;
- mach_send_once_notification_t *n;
- kmsg = ikm_alloc(sizeof *n);
- if (kmsg == IKM_NULL) {
- printf("dropped send-once (0x%p)\n", port);
- ipc_port_release_sonce(port);
- return;
- }
- ikm_init(kmsg, sizeof *n);
- n = (mach_send_once_notification_t *) &kmsg->ikm_header;
- *n = ipc_notify_send_once_template;
- n->not_header.msgh_remote_port = (mach_port_t) port;
- ipc_mqueue_send_always(kmsg);
- }
- /*
- * Routine: ipc_notify_dead_name
- * Purpose:
- * Send a dead-name notification.
- * Conditions:
- * Nothing locked.
- * Consumes a ref/soright for port.
- */
- void
- ipc_notify_dead_name(
- ipc_port_t port,
- mach_port_t name)
- {
- ipc_kmsg_t kmsg;
- mach_dead_name_notification_t *n;
- kmsg = ikm_alloc(sizeof *n);
- if (kmsg == IKM_NULL) {
- printf("dropped dead-name (0x%p, 0x%lx)\n", port, name);
- ipc_port_release_sonce(port);
- return;
- }
- ikm_init(kmsg, sizeof *n);
- n = (mach_dead_name_notification_t *) &kmsg->ikm_header;
- *n = ipc_notify_dead_name_template;
- n->not_header.msgh_remote_port = (mach_port_t) port;
- n->not_port = name;
- ipc_mqueue_send_always(kmsg);
- }
|