+/* Mach Port Guarding definitions */
+
+/*
+ * Flags for mach_port_options (used for
+ * invocation of mach_port_construct).
+ * Indicates attributes to be set for the newly
+ * allocated port.
+ */
+#define MPO_CONTEXT_AS_GUARD 0x01 /* Add guard to the port */
+#define MPO_QLIMIT 0x02 /* Set qlimit for the port msg queue */
+#define MPO_TEMPOWNER 0x04 /* Set the tempowner bit of the port */
+#define MPO_IMPORTANCE_RECEIVER 0x08 /* Mark the port as importance receiver */
+#define MPO_INSERT_SEND_RIGHT 0x10 /* Insert a send right for the port */
+#define MPO_STRICT 0x20 /* Apply strict guarding for port */
+#define MPO_DENAP_RECEIVER 0x40 /* Mark the port as App de-nap receiver */
+/*
+ * Structure to define optional attributes for a newly
+ * constructed port.
+ */
+typedef struct mach_port_options {
+ uint32_t flags; /* Flags defining attributes for port */
+ mach_port_limits_t mpl; /* Message queue limit for port */
+ uint64_t reserved[2]; /* Reserved */
+}mach_port_options_t;
+
+typedef mach_port_options_t *mach_port_options_ptr_t;
+
+/*
+ * EXC_GUARD represents a guard violation for both
+ * mach ports and file descriptors. GUARD_TYPE_ is used
+ * to differentiate among them.
+ */
+#define GUARD_TYPE_MACH_PORT 0x1
+
+/* Reasons for exception for a guarded mach port */
+enum mach_port_guard_exception_codes {
+ kGUARD_EXC_DESTROY = 1u << 0,
+ kGUARD_EXC_MOD_REFS = 1u << 1,
+ kGUARD_EXC_SET_CONTEXT = 1u << 2,
+ kGUARD_EXC_UNGUARDED = 1u << 3,
+ kGUARD_EXC_INCORRECT_GUARD = 1u << 4,
+ /* start of non-fatal guards */
+ kGUARD_EXC_INVALID_RIGHT = 1u << 8,
+ kGUARD_EXC_INVALID_NAME = 1u << 9,
+ kGUARD_EXC_INVALID_VALUE = 1u << 10,
+ kGUARD_EXC_INVALID_ARGUMENT = 1u << 11,
+ kGUARD_EXC_RIGHT_EXISTS = 1u << 12,
+ kGUARD_EXC_KERN_NO_SPACE = 1u << 13,
+ kGUARD_EXC_KERN_FAILURE = 1u << 14,
+ kGUARD_EXC_KERN_RESOURCE = 1u << 15,
+ kGUARD_EXC_SEND_INVALID_REPLY = 1u << 16,
+ kGUARD_EXC_SEND_INVALID_VOUCHER = 1u << 16,
+ kGUARD_EXC_SEND_INVALID_RIGHT = 1u << 17,
+ kGUARD_EXC_RCV_INVALID_NAME = 1u << 18,
+ kGUARD_EXC_RCV_INVALID_NOTIFY = 1u << 19
+};
+
+#if !__DARWIN_UNIX03 && !defined(_NO_PORT_T_FROM_MACH)
+/*
+ * Mach 3.0 renamed everything to have mach_ in front of it.
+ * These types and macros are provided for backward compatibility
+ * but are deprecated.
+ */
+typedef mach_port_t port_t;
+typedef mach_port_name_t port_name_t;
+typedef mach_port_name_t *port_name_array_t;
+
+#define PORT_NULL ((port_t) 0)
+#define PORT_DEAD ((port_t) ~0)
+#define PORT_VALID(name) \
+ ((port_t)(name) != PORT_NULL && (port_t)(name) != PORT_DEAD)
+
+#endif /* !__DARWIN_UNIX03 && !_NO_PORT_T_FROM_MACH */
+
+#endif /* _MACH_PORT_H_ */