diff options
author | Luca Dariz <luca@orpolo.org> | 2023-01-16 11:58:56 +0100 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2023-01-18 02:27:34 +0100 |
commit | f056fcda8bf9a5c375b20ef3803718187d9d4211 (patch) | |
tree | 0d27ca3eb403ad77ff3587436325f3c62da16a82 /ipc | |
parent | 027cf6671fad35d663f25c58430cd8fc6a45e181 (diff) | |
download | gnumach-f056fcda8bf9a5c375b20ef3803718187d9d4211.tar.gz gnumach-f056fcda8bf9a5c375b20ef3803718187d9d4211.tar.bz2 gnumach-f056fcda8bf9a5c375b20ef3803718187d9d4211.zip |
add conversion helpers for invalid mach port names
* 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.
Message-Id: <20230116105857.240210-7-luca@orpolo.org>
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/port.h | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -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_ */ |