xref: /xnu-10002.1.13/osfmk/ipc/ipc_service_port.h (revision 1031c584a5e37aff177559b9f69dbd3c8c3fd30a)
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 	ISPL_FLAGS_THROTTLED              = (1 << 3),/* Service throttled by launchd */
57 });
58 
59 struct ipc_service_port_label {
60 	void * XNU_PTRAUTH_SIGNED_PTR("ipc_service_port_label.ispl_sblabel") ispl_sblabel; /* points to the Sandbox's message filtering data structure */
61 	mach_port_context_t               ispl_launchd_context;     /* context used to guard the port, specific to launchd */
62 	mach_port_name_t                  ispl_launchd_name;        /* port name in launchd's ipc space */
63 	ipc_service_port_label_flags_t    ispl_flags;
64 #if CONFIG_SERVICE_PORT_INFO
65 	uint8_t             ispl_domain;             /* launchd domain */
66 	char                *ispl_service_name;       /* string name used to identify the service port */
67 #endif /* CONFIG_SERVICE_PORT_INFO */
68 };
69 
70 typedef struct ipc_service_port_label* ipc_service_port_label_t;
71 
72 #define IPC_SERVICE_PORT_LABEL_NULL ((ipc_service_port_label_t)NULL)
73 
74 /*
75  * These ispl_flags based macros/functions should be called with the port lock held
76  */
77 #define ipc_service_port_label_is_special_pdrequest(port_splabel) \
78     (((port_splabel)->ispl_flags & ISPL_FLAGS_SPECIAL_PDREQUEST) == ISPL_FLAGS_SPECIAL_PDREQUEST)
79 
80 #define ipc_service_port_label_is_pd_notification(port_splabel) \
81     (((port_splabel)->ispl_flags & ISPL_FLAGS_SEND_PD_NOTIFICATION) == ISPL_FLAGS_SEND_PD_NOTIFICATION)
82 
83 #define ipc_service_port_label_is_bootstrap_port(port_splabel) \
84     (((port_splabel)->ispl_flags & ISPL_FLAGS_BOOTSTRAP_PORT) == ISPL_FLAGS_BOOTSTRAP_PORT)
85 
86 #define ipc_service_port_label_is_throttled(port_splabel) \
87 	(((port_splabel)->ispl_flags & ISPL_FLAGS_THROTTLED) == ISPL_FLAGS_THROTTLED)
88 
89 static inline void
ipc_service_port_label_set_flag(ipc_service_port_label_t port_splabel,ipc_service_port_label_flags_t flag)90 ipc_service_port_label_set_flag(ipc_service_port_label_t port_splabel, ipc_service_port_label_flags_t flag)
91 {
92 	assert(port_splabel != IPC_SERVICE_PORT_LABEL_NULL);
93 	port_splabel->ispl_flags |= flag;
94 }
95 
96 static inline void
ipc_service_port_label_clear_flag(ipc_service_port_label_t port_splabel,ipc_service_port_label_flags_t flag)97 ipc_service_port_label_clear_flag(ipc_service_port_label_t port_splabel, ipc_service_port_label_flags_t flag)
98 {
99 	assert(port_splabel != IPC_SERVICE_PORT_LABEL_NULL);
100 	port_splabel->ispl_flags &= ~flag;
101 }
102 
103 /* Function declarations */
104 kern_return_t
105 ipc_service_port_label_alloc(mach_service_port_info_t sp_info, void **port_label_ptr);
106 
107 void
108 ipc_service_port_label_dealloc(void * ip_splabel, bool service_port);
109 
110 kern_return_t
111 ipc_service_port_derive_sblabel(mach_port_name_t service_port_name, void **sblabel_ptr, bool *filter_msgs);
112 
113 void *
114 ipc_service_port_get_sblabel(ipc_port_t port);
115 
116 void
117 ipc_service_port_label_set_attr(ipc_service_port_label_t port_splabel, mach_port_name_t name, mach_port_context_t context);
118 
119 void
120 ipc_service_port_label_get_attr(ipc_service_port_label_t port_splabel, mach_port_name_t *name, mach_port_context_t *context);
121 
122 #if CONFIG_SERVICE_PORT_INFO
123 void
124 ipc_service_port_label_get_info(ipc_service_port_label_t port_splabel, mach_service_port_info_t info);
125 #endif /* CONFIG_SERVICE_PORT_INFO */
126 
127 #endif /* MACH_KERNEL_PRIVATE */
128 #endif /* _IPC_IPC_SERVICE_PORT_H_ */
129