summaryrefslogtreecommitdiff
path: root/libports
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2021-08-05 18:36:30 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2022-08-10 22:12:25 +0200
commit2c6c2b011eda70abac23c6ff9702917485f9ed3b (patch)
tree6e4f3f48eb7e0374c684318670984e9e71c9d15c /libports
parent009ef29d60bb83dd6fdaeb647e27b3e0e385a733 (diff)
libports: Add ports_request_dead_name_notification ()
This significantly cuts down the boilerplate of requesting dead-name notifications.
Diffstat (limited to 'libports')
-rw-r--r--libports/Makefile2
-rw-r--r--libports/ports.h8
-rw-r--r--libports/request-notification.c54
3 files changed, 63 insertions, 1 deletions
diff --git a/libports/Makefile b/libports/Makefile
index 9b483e61..c67d8fec 100644
--- a/libports/Makefile
+++ b/libports/Makefile
@@ -36,7 +36,7 @@ SRCS = create-bucket.c create-class.c \
interrupt-operation.c interrupt-on-notify.c interrupt-notified-rpcs.c \
dead-name.c create-port.c import-port.c default-uninhibitable-rpcs.c \
claim-right.c transfer-right.c create-port-noinstall.c create-internal.c \
- interrupted.c extern-inline.c port-deref-deferred.c
+ interrupted.c extern-inline.c port-deref-deferred.c request-notification.c
installhdrs = ports.h port-deref-deferred.h
diff --git a/libports/ports.h b/libports/ports.h
index f8ce9b6c..2d6f6a60 100644
--- a/libports/ports.h
+++ b/libports/ports.h
@@ -322,6 +322,14 @@ void ports_port_deref_weak (void *port);
__pi ? (__pi->bucket->notify_port == __pi) : 0; \
})
+/* Request a dead-name notification for NAME on behalf of OBJECT.
+ If PREVIOUS is null, deallocate any previously registered port,
+ otherwise return it. If OBJECT is null, cancel the previously
+ registered notification. */
+error_t ports_request_dead_name_notification (void *object,
+ mach_port_t name,
+ mach_port_t *previous);
+
/* The user is responsible for listening for no senders notifications;
when one arrives, call this routine for the PORT the message was
sent to, providing the MSCOUNT from the notification. */
diff --git a/libports/request-notification.c b/libports/request-notification.c
new file mode 100644
index 00000000..c7a7ca25
--- /dev/null
+++ b/libports/request-notification.c
@@ -0,0 +1,54 @@
+/* Request dead-name notifications
+
+ Copyright (C) 2021 Free Software Foundation, Inc.
+
+ Written by Sergey Bugaev <bugaevc@gmail.com>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "ports.h"
+#include <mach/notify.h>
+
+error_t
+ports_request_dead_name_notification (void *object, mach_port_t name,
+ mach_port_t *previous)
+{
+ error_t err;
+ mach_port_t notify_port;
+ mach_port_t prev;
+
+ if (object)
+ notify_port = ports_port_notify_right (object);
+ else
+ notify_port = MACH_PORT_NULL;
+
+ err = mach_port_request_notification (mach_task_self (), name,
+ MACH_NOTIFY_DEAD_NAME, 1,
+ notify_port,
+ MACH_MSG_TYPE_MAKE_SEND_ONCE,
+ &prev);
+ if (err)
+ return err;
+
+ if (previous != NULL)
+ *previous = prev;
+ else if (MACH_PORT_VALID (prev))
+ {
+ err = mach_port_deallocate (mach_task_self (), prev);
+ assert_perror_backtrace (err);
+ }
+
+ return 0;
+}