1 /*
2 * Copyright (c) 2000-2019 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 #ifndef _IPC_IPC_SERVICE_PORT_H_
30 #define _IPC_IPC_SERVICE_PORT_H_
31
32 #include <mach/std_types.h>
33 #include <mach/port.h>
34 #include <mach/mach_eventlink_types.h>
35 #include <mach_assert.h>
36
37 #include <mach/mach_types.h>
38 #include <mach/boolean.h>
39 #include <mach/kern_return.h>
40
41 #include <kern/assert.h>
42 #include <kern/kern_types.h>
43
44 #include <ipc/ipc_types.h>
45 #include <ipc/ipc_object.h>
46 #include <ipc/ipc_port.h>
47 #include <kern/waitq.h>
48 #include <os/refcnt.h>
49
50 #ifdef MACH_KERNEL_PRIVATE
51
52 __options_decl(ipc_service_port_label_flags_t, uint16_t, {
53 ISPL_FLAGS_SPECIAL_PDREQUEST = 1,/* Special port destroyed notification for service ports */
54 ISPL_FLAGS_SEND_PD_NOTIFICATION = 1 << 1,/* Port destroyed notification is being sent */
55 ISPL_FLAGS_BOOTSTRAP_PORT = 1 << 2,
56 });
57
58 struct ipc_service_port_label {
59 void * XNU_PTRAUTH_SIGNED_PTR("ipc_service_port_label.ispl_sblabel") ispl_sblabel; /* points to the Sandbox's message filtering data structure */
60 mach_port_context_t ispl_launchd_context; /* context used to guard the port, specific to launchd */
61 mach_port_name_t ispl_launchd_name; /* port name in launchd's ipc space */
62 ipc_service_port_label_flags_t ispl_flags;
63 #if CONFIG_SERVICE_PORT_INFO
64 uint8_t ispl_domain; /* launchd domain */
65 char *ispl_service_name; /* string name used to identify the service port */
66 #endif /* CONFIG_SERVICE_PORT_INFO */
67 };
68
69 typedef struct ipc_service_port_label* ipc_service_port_label_t;
70
71 #define IPC_SERVICE_PORT_LABEL_NULL ((ipc_service_port_label_t)NULL)
72
73 /*
74 * These ispl_flags based macros/functions should be called with the port lock held
75 */
76 #define ipc_service_port_label_is_special_pdrequest(port_splabel) \
77 (((port_splabel)->ispl_flags & ISPL_FLAGS_SPECIAL_PDREQUEST) == ISPL_FLAGS_SPECIAL_PDREQUEST)
78
79 #define ipc_service_port_label_is_pd_notification(port_splabel) \
80 (((port_splabel)->ispl_flags & ISPL_FLAGS_SEND_PD_NOTIFICATION) == ISPL_FLAGS_SEND_PD_NOTIFICATION)
81
82 #define ipc_service_port_label_is_bootstrap_port(port_splabel) \
83 (((port_splabel)->ispl_flags & ISPL_FLAGS_BOOTSTRAP_PORT) == ISPL_FLAGS_BOOTSTRAP_PORT)
84
85 static inline void
ipc_service_port_label_set_flag(ipc_service_port_label_t port_splabel,ipc_service_port_label_flags_t flag)86 ipc_service_port_label_set_flag(ipc_service_port_label_t port_splabel, ipc_service_port_label_flags_t flag)
87 {
88 assert(port_splabel != IPC_SERVICE_PORT_LABEL_NULL);
89 port_splabel->ispl_flags |= flag;
90 }
91
92 static inline void
ipc_service_port_label_clear_flag(ipc_service_port_label_t port_splabel,ipc_service_port_label_flags_t flag)93 ipc_service_port_label_clear_flag(ipc_service_port_label_t port_splabel, ipc_service_port_label_flags_t flag)
94 {
95 assert(port_splabel != IPC_SERVICE_PORT_LABEL_NULL);
96 port_splabel->ispl_flags &= ~flag;
97 }
98
99 /* Function declarations */
100 kern_return_t
101 ipc_service_port_label_alloc(mach_service_port_info_t sp_info, void **port_label_ptr);
102
103 void
104 ipc_service_port_label_dealloc(void * ip_splabel, bool service_port);
105
106 kern_return_t
107 ipc_service_port_derive_sblabel(mach_port_name_t service_port_name, void **sblabel_ptr, bool *filter_msgs);
108
109 void *
110 ipc_service_port_get_sblabel(ipc_port_t port);
111
112 void
113 ipc_service_port_label_set_attr(ipc_service_port_label_t port_splabel, mach_port_name_t name, mach_port_context_t context);
114
115 void
116 ipc_service_port_label_get_attr(ipc_service_port_label_t port_splabel, mach_port_name_t *name, mach_port_context_t *context);
117
118 #if CONFIG_SERVICE_PORT_INFO
119 void
120 ipc_service_port_label_get_info(ipc_service_port_label_t port_splabel, mach_service_port_info_t info);
121 #endif /* CONFIG_SERVICE_PORT_INFO */
122
123 #endif /* MACH_KERNEL_PRIVATE */
124 #endif /* _IPC_IPC_SERVICE_PORT_H_ */
125