[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 6/7] add conversion helpers for invalid mach port names
From: |
Luca Dariz |
Subject: |
[PATCH 6/7] add conversion helpers for invalid mach port names |
Date: |
Mon, 16 Jan 2023 11:58:56 +0100 |
* include/mach/port.h: add _NAME_ variants for port NULL and DEAD and
add helpers to check for invalid port names
* ipc/port.h: add helpers to properly convert to/from invalid mach
port names.
---
include/mach/port.h | 8 ++++++--
ipc/port.h | 20 ++++++++++++++++++++
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/include/mach/port.h b/include/mach/port.h
index e38be614..c9bbcf17 100644
--- a/include/mach/port.h
+++ b/include/mach/port.h
@@ -72,9 +72,13 @@ typedef int *rpc_signature_info_t;
#define MACH_PORT_NULL 0 /* works with both user and kernel ports */
#define MACH_PORT_DEAD ((mach_port_t) ~0)
+#define MACH_PORT_NAME_NULL ((mach_port_name_t) 0)
+#define MACH_PORT_NAME_DEAD ((mach_port_name_t) ~0)
-#define MACH_PORT_VALID(name) \
- (((name) != MACH_PORT_NULL) && ((name) != MACH_PORT_DEAD))
+#define MACH_PORT_VALID(port) \
+ (((port) != MACH_PORT_NULL) && ((port) != MACH_PORT_DEAD))
+#define MACH_PORT_NAME_VALID(name) \
+ (((name) != MACH_PORT_NAME_NULL) && ((name) !=
MACH_PORT_NAME_DEAD))
/*
* These are the different rights a task may have.
diff --git a/ipc/port.h b/ipc/port.h
index 9ef586c1..c85685d7 100644
--- a/ipc/port.h
+++ b/ipc/port.h
@@ -39,6 +39,7 @@
#ifndef _IPC_PORT_H_
#define _IPC_PORT_H_
+#include <kern/debug.h>
#include <mach/port.h>
/*
@@ -83,4 +84,23 @@ typedef mach_port_name_t mach_port_gen_t; /* generation
numbers */
#define MACH_PORT_UREFS_UNDERFLOW(urefs, delta)
\
(((delta) < 0) && (-(delta) > (urefs)))
+
+static inline mach_port_t invalid_name_to_port(mach_port_name_t name)
+{
+ if (name == MACH_PORT_NAME_NULL)
+ return MACH_PORT_NULL;
+ if (name == MACH_PORT_NAME_DEAD)
+ return MACH_PORT_DEAD;
+ panic("invalid_name_to_port() called with a valid port");
+}
+
+static inline mach_port_name_t invalid_port_to_name(mach_port_t port)
+{
+ if (port == MACH_PORT_NULL)
+ return MACH_PORT_NAME_NULL;
+ if (port == MACH_PORT_DEAD)
+ return MACH_PORT_NAME_DEAD;
+ panic("invalid_port_to_name() called with a valid name");
+}
+
#endif /* _IPC_PORT_H_ */
--
2.30.2
- Re: [PATCH 3/7] update syscall signature with rpc_vm_* and mach_port_name_t, (continued)
- [PATCH 4/7] update writev syscall signature with rpc types, Luca Dariz, 2023/01/16
- [PATCH 7/7] replace mach_port_t with mach_port_name_t, Luca Dariz, 2023/01/16
- [PATCH 5/7] adjust rdxtree key to the correct size, Luca Dariz, 2023/01/16
- [PATCH 2/7] x86_64: expand and shrink messages in copy{in, out}msg routines, Luca Dariz, 2023/01/16
- [PATCH 6/7] add conversion helpers for invalid mach port names,
Luca Dariz <=