xref: /xnu-11215.41.3/osfmk/kern/ipc_tt.h (revision 33de042d024d46de5ff4e89f2471de6608e37fa4)
1 /*
2  * Copyright (c) 2000-2004 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,1988,1987 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 #ifndef _KERN_IPC_TT_H_
60 #define _KERN_IPC_TT_H_
61 
62 #include <mach/boolean.h>
63 #include <mach/port.h>
64 #include <vm/vm_kern.h>
65 #include <kern/kern_types.h>
66 #include <kern/ipc_kobject.h>
67 #include <kern/task_ref.h>
68 #include <ipc/ipc_space.h>
69 #include <ipc/ipc_port.h>
70 #include <ipc/ipc_right.h>
71 #include <ipc/ipc_entry.h>
72 #include <ipc/ipc_object.h>
73 
74 
75 /* Initialize a task's IPC state */
76 extern void ipc_task_init(
77 	task_t          task,
78 	task_t          parent);
79 
80 /* Enable a task for IPC access */
81 extern void ipc_task_enable(
82 	task_t          task);
83 
84 /* Disable IPC access to a task */
85 extern void ipc_task_disable(
86 	task_t          task);
87 
88 /* Clear out a task's IPC state */
89 extern void ipc_task_reset(
90 	task_t          task);
91 
92 /* Clean up and destroy a task's IPC state */
93 extern void ipc_task_terminate(
94 	task_t          task);
95 
96 /* Setup task control port according to it's control port options */
97 extern void ipc_task_set_immovable_pinned(
98 	task_t          task);
99 
100 /* Setup thread control port according to it's owning task's port options */
101 extern void ipc_main_thread_set_immovable_pinned(
102 	thread_t          thread);
103 
104 __options_decl(ipc_thread_init_options_t, uint32_t, {
105 	IPC_THREAD_INIT_NONE       = 0x00,
106 	IPC_THREAD_INIT_MAINTHREAD = 0x01,
107 });
108 
109 __options_decl(port_intrans_options_t, uint32_t, {
110 	PORT_INTRANS_OPTIONS_NONE              = 0x0000,
111 	PORT_INTRANS_THREAD_IN_CURRENT_TASK    = 0x0001,
112 	PORT_INTRANS_THREAD_NOT_CURRENT_THREAD = 0x0002,
113 
114 	PORT_INTRANS_SKIP_TASK_EVAL            = 0x0004,
115 	PORT_INTRANS_ALLOW_CORPSE_TASK         = 0x0008,
116 });
117 
118 /* Initialize a thread's IPC state */
119 extern void ipc_thread_init(
120 	task_t          task,
121 	thread_t        thread,
122 	thread_ro_t     tro,
123 	ipc_thread_init_options_t options);
124 
125 /* Disable IPC access to a thread */
126 extern void ipc_thread_disable(
127 	thread_t        thread);
128 
129 /* Clean up and destroy a thread's IPC state */
130 extern void ipc_thread_terminate(
131 	thread_t        thread);
132 
133 /* Clear out a thread's IPC state */
134 extern void ipc_thread_reset(
135 	thread_t        thread);
136 
137 /* Return a send right for the thread's user-visible self port */
138 extern ipc_port_t retrieve_thread_self_fast(
139 	thread_t        thread);
140 
141 /* Convert from a port to a task name */
142 extern task_name_t convert_port_to_task_name(
143 	ipc_port_t      port);
144 
145 /* Convert from a port to a task name */
146 extern task_name_t convert_port_to_task_name_mig(
147 	ipc_port_t      port);
148 
149 /* Convert from a port to a task for task_policy_set(). */
150 extern task_policy_set_t convert_port_to_task_policy_set_mig(
151 	ipc_port_t      port);
152 
153 
154 /* Convert from a port to a task for task_policy_get(). */
155 extern task_policy_get_t convert_port_to_task_policy_get_mig(
156 	ipc_port_t      port);
157 
158 /* Convert from a port to a task inspect */
159 extern task_inspect_t convert_port_to_task_inspect(
160 	ipc_port_t      port);
161 
162 /* Variant for skipping task_conversion_eval() */
163 extern task_inspect_t convert_port_to_task_inspect_no_eval(
164 	ipc_port_t      port);
165 
166 /* Convert from a port to a task inspect - mig version */
167 extern task_inspect_t convert_port_to_task_inspect_mig(
168 	ipc_port_t      port);
169 
170 /* Convert from a port to a task read */
171 extern task_read_t convert_port_to_task_read(
172 	ipc_port_t      port);
173 
174 /* Convert from a port to a task read - skip eval */
175 extern task_read_t convert_port_to_task_read_no_eval(
176 	ipc_port_t      port);
177 
178 /* Convert from a port to a task read */
179 extern task_read_t convert_port_to_task_read_mig(
180 	ipc_port_t      port);
181 
182 /* Convert from a port to a task */
183 extern task_t convert_port_to_task(
184 	ipc_port_t      port);
185 
186 /* Convert from a port to a pinned task */
187 extern task_t convert_port_to_task_pinned(
188 	ipc_port_t      port);
189 
190 /* Convert from a port to a task */
191 extern task_t convert_port_to_task_mig(
192 	ipc_port_t      port);
193 
194 /* Doesn't give a +1 on task, returns current_task() or TASK_NULL */
195 extern task_t port_name_to_current_task_noref(
196 	mach_port_name_t name);
197 
198 /* Doesn't give a +1 on task, returns current_task() or TASK_NULL */
199 extern task_read_t port_name_to_current_task_read_noref(
200 	mach_port_name_t name);
201 
202 extern task_t port_name_to_task(
203 	mach_port_name_t name);
204 
205 extern task_t port_name_to_task_kernel(
206 	mach_port_name_t name);
207 
208 extern task_t port_name_to_task_external(
209 	mach_port_name_t name);
210 
211 extern task_read_t port_name_to_task_read(
212 	mach_port_name_t name);
213 
214 extern task_read_t port_name_to_task_read_and_send_right(
215 	mach_port_name_t name,
216 	ipc_port_t *kportp);
217 
218 extern task_read_t port_name_to_task_read_no_eval(
219 	mach_port_name_t name);
220 
221 extern task_t port_name_to_task_name(
222 	mach_port_name_t name);
223 
224 extern task_id_token_t port_name_to_task_id_token(
225 	mach_port_name_t name);
226 
227 extern host_t port_name_to_host(
228 	mach_port_name_t name);
229 
230 extern boolean_t ref_task_port_locked(
231 	ipc_port_t port, task_t *ptask);
232 
233 /* Convert from a port to a space */
234 extern ipc_space_t convert_port_to_space(
235 	ipc_port_t      port);
236 
237 /* Convert from a port to a space inspection right */
238 extern ipc_space_read_t convert_port_to_space_read(
239 	ipc_port_t      port);
240 /* Variant for skipping task_conversion_eval() */
241 extern ipc_space_read_t convert_port_to_space_read_no_eval(
242 	ipc_port_t      port);
243 
244 /* Convert from a port to a space inspection right */
245 extern ipc_space_inspect_t convert_port_to_space_inspect(
246 	ipc_port_t      port);
247 
248 extern boolean_t ref_space_port_locked(
249 	ipc_port_t port, ipc_space_t *pspace);
250 
251 /* Convert from a port to a map */
252 extern vm_map_t convert_port_to_map(
253 	ipc_port_t      port);
254 
255 /* Convert from a port to a map read */
256 extern vm_map_read_t convert_port_to_map_read(
257 	ipc_port_t      port);
258 
259 /* Convert from a port to a map inspect */
260 extern vm_map_inspect_t convert_port_to_map_inspect(
261 	ipc_port_t      port);
262 
263 /* Convert from a port to a thread */
264 extern thread_t convert_port_to_thread(
265 	ipc_port_t              port);
266 
267 /* Convert from a port to a thread inspect */
268 extern thread_inspect_t convert_port_to_thread_inspect(
269 	ipc_port_t              port);
270 
271 /* Convert from a port to a thread read */
272 extern thread_read_t convert_port_to_thread_read(
273 	ipc_port_t              port);
274 
275 extern thread_t port_name_to_thread(
276 	mach_port_name_t            port_name,
277 	port_intrans_options_t    options);
278 
279 /* Deallocate a space ref produced by convert_port_to_space */
280 extern void space_deallocate(
281 	ipc_space_t             space);
282 
283 extern void space_read_deallocate(
284 	ipc_space_read_t             space);
285 
286 extern void space_inspect_deallocate(
287 	ipc_space_inspect_t     space);
288 
289 extern kern_return_t thread_get_kernel_special_reply_port(void);
290 
291 extern void thread_dealloc_kernel_special_reply_port(thread_t thread);
292 
293 extern kern_return_t
294 set_exception_ports_validation(
295 	task_t                  task,
296 	exception_mask_t        exception_mask,
297 	ipc_port_t              new_port,
298 	exception_behavior_t    new_behavior,
299 	thread_state_flavor_t   new_flavor,
300 	bool hardened_exception
301 	);
302 
303 extern kern_return_t
304 thread_set_exception_ports_internal(
305 	thread_t  thread,
306 	exception_mask_t        exception_mask,
307 	ipc_port_t              new_port,
308 	exception_behavior_t    new_behavior,
309 	thread_state_flavor_t   new_flavor,
310 	boolean_t                               hardened);
311 
312 #if MACH_KERNEL_PRIVATE
313 extern void ipc_thread_port_unpin(
314 	ipc_port_t port);
315 
316 extern ipc_port_t
317 convert_task_suspension_token_to_port_external(
318 	task_suspension_token_t         task);
319 
320 extern ipc_port_t
321 convert_task_suspension_token_to_port_mig(
322 	task_suspension_token_t         task);
323 
324 extern task_suspension_token_t
325 convert_port_to_task_suspension_token_external(
326 	ipc_port_t                      port);
327 
328 extern task_suspension_token_t
329 convert_port_to_task_suspension_token_mig(
330 	ipc_port_t                      port);
331 
332 extern task_suspension_token_t
333 convert_port_to_task_suspension_token_kernel(
334 	ipc_port_t                      port);
335 
336 
337 #endif
338 
339 #endif  /* _KERN_IPC_TT_H_ */
340