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 Software.Distribution@CS.CMU.EDU
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 */
76extern void ipc_task_init(
77 task_t task,
78 task_t parent);
79
80/* Enable a task for IPC access */
81extern void ipc_task_enable(
82 task_t task);
83
84/* Disable IPC access to a task */
85extern void ipc_task_disable(
86 task_t task);
87
88/* Clear out a task's IPC state */
89extern void ipc_task_reset(
90 task_t task);
91
92/* Clean up and destroy a task's IPC state */
93extern void ipc_task_terminate(
94 task_t task);
95
96/* Setup task control port according to it's control port options */
97extern 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 */
101extern 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 */
119extern 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 */
126extern void ipc_thread_disable(
127 thread_t thread);
128
129/* Clean up and destroy a thread's IPC state */
130extern void ipc_thread_terminate(
131 thread_t thread);
132
133/* Clear out a thread's IPC state */
134extern void ipc_thread_reset(
135 thread_t thread);
136
137/* Return a send right for the thread's user-visible self port */
138extern ipc_port_t retrieve_thread_self_fast(
139 thread_t thread);
140
141/* Convert from a port to a task name */
142extern task_name_t convert_port_to_task_name(
143 ipc_port_t port);
144
145/* Convert from a port to a task name */
146extern 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(). */
150extern 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(). */
155extern 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 */
159extern task_inspect_t convert_port_to_task_inspect(
160 ipc_port_t port);
161
162/* Variant for skipping task_conversion_eval() */
163extern 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 */
167extern task_inspect_t convert_port_to_task_inspect_mig(
168 ipc_port_t port);
169
170/* Convert from a port to a task read */
171extern task_read_t convert_port_to_task_read(
172 ipc_port_t port);
173
174/* Convert from a port to a task read */
175extern task_read_t convert_port_to_task_read_mig(
176 ipc_port_t port);
177
178/* Convert from a port to a task */
179extern task_t convert_port_to_task(
180 ipc_port_t port);
181
182/* Convert from a port to a pinned task */
183extern task_t convert_port_to_task_pinned(
184 ipc_port_t port);
185
186/* Convert from a port to a task */
187extern task_t convert_port_to_task_mig(
188 ipc_port_t port);
189
190/* Doesn't give a +1 on task, returns current_task() or TASK_NULL */
191extern task_t port_name_to_current_task_noref(
192 mach_port_name_t name);
193
194/* Doesn't give a +1 on task, returns current_task() or TASK_NULL */
195extern task_read_t port_name_to_current_task_read_noref(
196 mach_port_name_t name);
197
198extern task_t port_name_to_task(
199 mach_port_name_t name);
200
201extern task_t port_name_to_task_kernel(
202 mach_port_name_t name);
203
204extern task_t port_name_to_task_external(
205 mach_port_name_t name);
206
207extern task_read_t port_name_to_task_read(
208 mach_port_name_t name);
209
210extern task_read_t port_name_to_task_read_no_eval(
211 mach_port_name_t name);
212
213extern task_t port_name_to_task_name(
214 mach_port_name_t name);
215
216extern task_id_token_t port_name_to_task_id_token(
217 mach_port_name_t name);
218
219extern host_t port_name_to_host(
220 mach_port_name_t name);
221
222extern boolean_t ref_task_port_locked(
223 ipc_port_t port, task_t *ptask);
224
225/* Convert from a port to a space */
226extern ipc_space_t convert_port_to_space(
227 ipc_port_t port);
228
229/* Convert from a port to a space inspection right */
230extern ipc_space_read_t convert_port_to_space_read(
231 ipc_port_t port);
232/* Variant for skipping task_conversion_eval() */
233extern ipc_space_read_t convert_port_to_space_read_no_eval(
234 ipc_port_t port);
235
236/* Convert from a port to a space inspection right */
237extern ipc_space_inspect_t convert_port_to_space_inspect(
238 ipc_port_t port);
239
240extern boolean_t ref_space_port_locked(
241 ipc_port_t port, ipc_space_t *pspace);
242
243/* Convert from a port to a map */
244extern vm_map_t convert_port_to_map(
245 ipc_port_t port);
246
247/* Convert from a port to a map read */
248extern vm_map_read_t convert_port_to_map_read(
249 ipc_port_t port);
250
251/* Convert from a port to a map inspect */
252extern vm_map_inspect_t convert_port_to_map_inspect(
253 ipc_port_t port);
254
255/* Convert from a port to a thread */
256extern thread_t convert_port_to_thread(
257 ipc_port_t port);
258
259/* Convert from a port to a thread inspect */
260extern thread_inspect_t convert_port_to_thread_inspect(
261 ipc_port_t port);
262
263/* Convert from a port to a thread read */
264extern thread_read_t convert_port_to_thread_read(
265 ipc_port_t port);
266
267extern thread_t port_name_to_thread(
268 mach_port_name_t port_name,
269 port_intrans_options_t options);
270
271/* Deallocate a space ref produced by convert_port_to_space */
272extern void space_deallocate(
273 ipc_space_t space);
274
275extern void space_read_deallocate(
276 ipc_space_read_t space);
277
278extern void space_inspect_deallocate(
279 ipc_space_inspect_t space);
280
281extern kern_return_t thread_get_kernel_special_reply_port(void);
282
283extern void thread_dealloc_kernel_special_reply_port(thread_t thread);
284
285extern boolean_t set_exception_behavior_allowed(const ipc_port_t new_port, int new_behavior,
286 const task_t excepting_task, const exception_mask_t mask, const char *level);
287
288#if MACH_KERNEL_PRIVATE
289extern void ipc_thread_port_unpin(
290 ipc_port_t port);
291
292extern ipc_port_t
293convert_task_suspension_token_to_port_external(
294 task_suspension_token_t task);
295
296extern ipc_port_t
297convert_task_suspension_token_to_port_mig(
298 task_suspension_token_t task);
299
300extern task_suspension_token_t
301convert_port_to_task_suspension_token_external(
302 ipc_port_t port);
303
304extern task_suspension_token_t
305convert_port_to_task_suspension_token_mig(
306 ipc_port_t port);
307
308extern task_suspension_token_t
309convert_port_to_task_suspension_token_kernel(
310 ipc_port_t port);
311
312
313#endif
314
315#endif /* _KERN_IPC_TT_H_ */
316