xref: /xnu-11417.140.69/osfmk/ipc/ipc_right.h (revision 43a90889846e00bfb5cf1d255cdc0a701a1e05a4)
1 /*
2  * Copyright (c) 2000 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  * @OSF_COPYRIGHT@
30  */
31 /*
32  * Mach Operating System
33  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34  * All Rights Reserved.
35  *
36  * Permission to use, copy, modify and distribute this software and its
37  * documentation is hereby granted, provided that both the copyright
38  * notice and this permission notice appear in all copies of the
39  * software, derivative works or modified versions, and any portions
40  * thereof, and that both notices appear in supporting documentation.
41  *
42  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45  *
46  * Carnegie Mellon requests users of this software to return to
47  *
48  *  Software Distribution Coordinator  or  [email protected]
49  *  School of Computer Science
50  *  Carnegie Mellon University
51  *  Pittsburgh PA 15213-3890
52  *
53  * any improvements or extensions that they make and grant Carnegie Mellon
54  * the rights to redistribute these changes.
55  */
56 /*
57  */
58 /*
59  *	File:	ipc/ipc_right.h
60  *	Author:	Rich Draves
61  *	Date:	1989
62  *
63  *	Declarations of functions to manipulate IPC capabilities.
64  */
65 
66 #ifndef _IPC_IPC_RIGHT_H_
67 #define _IPC_IPC_RIGHT_H_
68 
69 #include <mach/boolean.h>
70 #include <mach/kern_return.h>
71 #include <ipc/ipc_port.h>
72 #include <ipc/ipc_entry.h>
73 
74 __BEGIN_DECLS __ASSUME_PTR_ABI_SINGLE_BEGIN
75 #pragma GCC visibility push(hidden)
76 
77 #define ipc_right_lookup_two_read       ipc_right_lookup_two_write
78 
79 extern bool service_port_defense_enabled;
80 
81 /* Find an entry in a space, given the name */
82 extern kern_return_t ipc_right_lookup_read(
83 	ipc_space_t             space,
84 	mach_port_name_t        name,
85 	ipc_entry_bits_t       *bitsp,
86 	ipc_object_t           *objectp);
87 
88 /* Find an entry in a space, given the name */
89 extern kern_return_t ipc_right_lookup_write(
90 	ipc_space_t             space,
91 	mach_port_name_t        name,
92 	ipc_entry_t            *entryp);
93 
94 /* Find two entries in a space, given two names */
95 extern kern_return_t ipc_right_lookup_two_write(
96 	ipc_space_t             space,
97 	mach_port_name_t        name1,
98 	ipc_entry_t            *entryp1,
99 	mach_port_name_t        name2,
100 	ipc_entry_t            *entryp2);
101 
102 /* Translate (space, port) -> (name, entry) */
103 extern bool          ipc_right_reverse(
104 	ipc_space_t             space,
105 	ipc_port_t              port,
106 	mach_port_name_t       *namep,
107 	ipc_entry_t            *entryp);
108 
109 /* Make a notification request, returning the previous send-once right */
110 extern kern_return_t ipc_right_request_alloc(
111 	ipc_space_t             space,
112 	mach_port_name_t        name,
113 	ipc_port_request_opts_t options,
114 	ipc_port_t              notify,
115 	ipc_port_t              *previousp);
116 
117 /* Check if an entry is being used */
118 extern bool      ipc_right_inuse(
119 	ipc_entry_t             entry);
120 
121 /* Check if the port has died */
122 extern boolean_t ipc_right_check(
123 	ipc_space_t             space,
124 	ipc_port_t              port,
125 	mach_port_name_t        name,
126 	ipc_entry_t             entry,
127 	ipc_object_copyin_flags_t flags);
128 
129 /* Clean up an entry in a dead space */
130 extern void ipc_right_terminate(
131 	ipc_space_t             space,
132 	mach_port_name_t        name,
133 	ipc_entry_t             entry);
134 
135 /* Destroy an entry in a space */
136 extern kern_return_t ipc_right_destroy(
137 	ipc_space_t             space,
138 	mach_port_name_t        name,
139 	ipc_entry_t             entry,
140 	boolean_t               check_guard,
141 	uint64_t                guard);
142 
143 /* Release a send/send-once/dead-name user reference */
144 extern kern_return_t ipc_right_dealloc(
145 	ipc_space_t             space,
146 	mach_port_name_t        name,
147 	ipc_entry_t             entry);
148 
149 /* Modify the user-reference count for a right */
150 extern kern_return_t ipc_right_delta(
151 	ipc_space_t             space,
152 	mach_port_name_t        name,
153 	ipc_entry_t             entry,
154 	mach_port_right_t       right,
155 	mach_port_delta_t       delta);
156 
157 /* Destroy a receive right; Modify ref count for send rights */
158 extern kern_return_t ipc_right_destruct(
159 	ipc_space_t             space,
160 	mach_port_name_t        name,
161 	ipc_entry_t             entry,
162 	mach_port_delta_t       srdelta,
163 	uint64_t                guard);
164 
165 /* Retrieve information about a right */
166 extern kern_return_t ipc_right_info(
167 	ipc_space_t             space,
168 	mach_port_name_t        name,
169 	ipc_entry_t             entry,
170 	mach_port_type_t       *typep,
171 	mach_port_urefs_t      *urefsp);
172 
173 /* Check if a subsequent ipc_right_copyin of the reply port will succeed */
174 extern boolean_t ipc_right_copyin_check_reply(
175 	ipc_space_t             space,
176 	mach_port_name_t        reply_name,
177 	ipc_entry_t             reply_entry,
178 	mach_msg_type_name_t    reply_type,
179 	ipc_entry_t             dest_entry,
180 	uint8_t                *reply_port_semantics_violation);
181 
182 typedef struct {
183 	ipc_port_t              icc_release_port;
184 	ipc_port_t              icc_deleted_port;
185 } ipc_copyin_cleanup_t;
186 
187 /* used if the right copied in might be a receive right */
188 typedef struct {
189 #if IMPORTANCE_INHERITANCE
190 	uint32_t                icrc_assert_count;
191 #endif /* IMPORTANCE_INHERITANCE */
192 	waitq_link_list_t       icrc_free_list;
193 	mach_msg_guarded_port_descriptor_t *icrc_guarded_desc;
194 } ipc_copyin_rcleanup_t;
195 
196 extern void          ipc_right_copyin_cleanup_destroy(
197 	ipc_copyin_cleanup_t   *icc,
198 	mach_port_name_t        name);
199 
200 extern void          ipc_right_copyin_rcleanup_init(
201 	ipc_copyin_rcleanup_t  *icrc,
202 	mach_msg_guarded_port_descriptor_t *gdesc);
203 
204 extern void          ipc_right_copyin_rcleanup_destroy(
205 	ipc_copyin_rcleanup_t  *icrc);
206 
207 /* Copyin a capability from a space */
208 extern kern_return_t ipc_right_copyin(
209 	ipc_space_t             space,
210 	mach_port_name_t        name,
211 	mach_msg_type_name_t    msgt_name,
212 	ipc_object_copyin_flags_t  flags,
213 	ipc_entry_t             entry,
214 	ipc_port_t             *portp,
215 	ipc_copyin_cleanup_t   *icc,
216 	ipc_copyin_rcleanup_t  *icrc);
217 
218 /* Copyout a capability to a space */
219 extern kern_return_t ipc_right_copyout(
220 	ipc_space_t             space,
221 	ipc_port_t              port,
222 	mach_msg_type_name_t    msgt_name,
223 	ipc_object_copyout_flags_t flags,
224 	mach_port_name_t        name,
225 	ipc_entry_t             entry,
226 	mach_msg_guarded_port_descriptor_t *gdesc);
227 
228 #pragma GCC visibility pop
229 __ASSUME_PTR_ABI_SINGLE_END __END_DECLS
230 
231 #endif  /* _IPC_IPC_RIGHT_H_ */
232