xref: /xnu-11215.41.3/osfmk/mach/task.defs (revision 33de042d024d46de5ff4e89f2471de6608e37fa4)
1/*
2 * Copyright (c) 2000-2007 Apple 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_FREE_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:	mach/mach_port.defs
60 *	Author:	Rich Draves
61 *
62 *	Exported kernel calls.
63 */
64
65subsystem
66#if	KERNEL_SERVER || KOBJECT_SERVER
67	KernelServer
68#endif	/* KERNEL_SERVER || KOBJECT_SERVER */
69	  task 3400;
70
71#include <mach/std_types.defs>
72#include <mach/mach_types.defs>
73#include <mach_debug/mach_debug_types.defs>
74
75#if !KERNEL && !LIBSYSCALL_INTERFACE
76#define PREFIX(NAME) _kernelrpc_ ## NAME
77#else
78#define PREFIX(NAME) NAME
79#endif
80
81/*
82 * Sandbox builds task.defs with KERNEL_SERVER defined when generating the map
83 * of MIG routine names to message IDs.
84 * The MIG routine names need to be kept stable so as to not break Sandbox
85 * profiles.
86 */
87#if	KERNEL_SERVER && !SANDBOX_COMPILER
88#define MIG_SERVER_SUFFIX(NAME) NAME ## _mig
89#else
90#define MIG_SERVER_SUFFIX(NAME) NAME
91#endif
92
93
94/*
95 * OBSOLETE interfaces, removed from kernel
96 */
97#if KERNEL_SERVER
98skip; /* task_create */
99#else
100routine task_create(
101		target_task	: task_t;
102		ledgers		: ledger_array_t;
103		inherit_memory	: boolean_t;
104	out	child_task	: task_t);
105#endif
106
107/*
108 *	Destroy the target task, causing all of its threads
109 *	to be destroyed, all of its IPC rights to be deallocated,
110 *	and all of its address space to be deallocated.
111 */
112routine task_terminate(
113		target_task	: task_t);
114
115/*
116 *	Returns the set of threads belonging to the target task.
117 *  [Polymorphic] This routine returns thread port with the same
118 *  flavor as that of the task port passed in.
119 */
120routine
121#ifdef KERNEL_SERVER
122task_threads_from_user(
123		port		: mach_port_t;
124#else
125task_threads(
126		target_task	: task_inspect_t;
127#endif
128	out	act_list	: thread_act_array_t);
129
130
131/*
132 *	Stash a handful of ports for the target task; child
133 *	tasks inherit this stash at task_create time.
134 */
135#if LIBSYSCALL_INTERFACE
136routine	mach_ports_register(
137		target_task	: task_t;
138		init_port_set	: mach_port_array_t =
139					^array[] of mach_port_t);
140#else
141routine	_kernelrpc_mach_ports_register3(
142		target_task	: task_t;
143		port1           : mach_port_t;
144		port2           : mach_port_t;
145		port3           : mach_port_t);
146#endif
147
148/*
149 *	Retrieve the stashed ports for the target task.
150 */
151#if LIBSYSCALL_INTERFACE
152routine	mach_ports_lookup(
153		target_task	: task_t;
154	out	init_port_set	: mach_port_array_t =
155					^array[] of mach_port_t);
156#else
157routine	_kernelrpc_mach_ports_lookup3(
158		target_task	: task_t;
159	out	port1		: mach_port_t;
160	out	port2		: mach_port_t;
161	out	port3		: mach_port_t);
162#endif
163
164/*
165 *      Returns information about the target task.
166 */
167#ifdef KERNEL_SERVER
168routine task_info_from_user(
169                target_task     : mach_port_t;
170                flavor          : task_flavor_t;
171        out     task_info_out   : task_info_t, CountInOut);
172#else
173routine task_info(
174                target_task     : task_name_t;
175                flavor          : task_flavor_t;
176        out     task_info_out   : task_info_t, CountInOut);
177
178#endif
179
180/*
181 * Set task information.
182 */
183routine	task_set_info(
184		target_task	: task_t;
185		flavor		: task_flavor_t;
186		task_info_in	: task_info_t);
187
188/*
189 *	Increment the suspend count for the target task.
190 *	No threads within a task may run when the suspend
191 *	count for that task is non-zero.
192 */
193routine	task_suspend(
194		target_task	: task_read_t);
195
196
197/*
198 *	Decrement the suspend count for the target task,
199 *	if the count is currently non-zero.  If the resulting
200 *	suspend	count is zero, then threads within the task
201 *	that also have non-zero suspend counts may execute.
202 */
203routine	task_resume(
204		target_task	: task_read_t);
205
206/*
207 *	Returns the current value of the selected special port
208 *	associated with the target task.
209 */
210routine
211#ifdef KERNEL_SERVER
212task_get_special_port_from_user(
213		port		: mach_port_t;
214#else
215task_get_special_port(
216		task		: task_inspect_t;
217#endif
218		which_port	: int;
219	out	special_port	: mach_port_t);
220
221
222/*
223 *	Set one of the special ports associated with the
224 *	target task.
225 */
226routine
227#if	KERNEL_SERVER && !SANDBOX_COMPILER
228task_set_special_port_from_user(
229#else
230task_set_special_port(
231#endif
232		task		: task_t;
233		which_port	: int;
234		special_port	: mach_port_t);
235
236/*
237 *	Create a new thread within the target task, returning
238 *	the port representing the first thr_act in that new thread.  The
239 *	initial execution state of the thread is undefined.
240 */
241routine
242#ifdef KERNEL_SERVER
243thread_create_from_user(
244#else
245thread_create(
246#endif
247		parent_task	: task_t;
248	out	child_act	: thread_act_t);
249
250/*
251 *      Create a new thread within the target task, returning
252 *      the port representing that new thread.  The new thread
253 *	is not suspended; its initial execution state is given
254 *	by flavor and new_state. Returns the port representing
255 *	the new thread.
256 */
257routine
258#ifdef KERNEL_SERVER
259thread_create_running_from_user(
260#else
261thread_create_running(
262#endif
263                parent_task     : task_t;
264                flavor          : thread_state_flavor_t;
265                new_state       : thread_state_t;
266        out     child_act       : thread_act_t);
267
268/*
269 * Set an exception handler for a task on one or more exception types.
270 * These handlers are invoked for all threads in the task if there are
271 * no thread-specific exception handlers or those handlers returned an
272 * error.
273 */
274routine	task_set_exception_ports(
275		task		: task_t;
276		exception_mask	: exception_mask_t;
277		new_port	: mach_port_t;
278		behavior	: exception_behavior_t;
279		new_flavor	: thread_state_flavor_t);
280
281
282/*
283 * Lookup some of the old exception handlers for a task
284 */
285routine
286#if KERNEL_SERVER
287task_get_exception_ports_from_user(
288		port        : mach_port_t;
289#else
290task_get_exception_ports(
291		task		: task_t;
292#endif
293		exception_mask	: exception_mask_t;
294	  out	masks		: exception_mask_array_t;
295	  out	old_handlers	: exception_handler_array_t, SameCount;
296	  out	old_behaviors	: exception_behavior_array_t, SameCount;
297	  out	old_flavors	: exception_flavor_array_t, SameCount);
298
299
300/*
301 * Set an exception handler for a thread on one or more exception types.
302 * At the same time, return the previously defined exception handlers for
303 * those types.
304 */
305routine	task_swap_exception_ports(
306		task		: task_t;
307		exception_mask	: exception_mask_t;
308		new_port	: mach_port_t;
309		behavior	: exception_behavior_t;
310		new_flavor	: thread_state_flavor_t;
311	  out	masks		: exception_mask_array_t;
312	  out	old_handlers	: exception_handler_array_t, SameCount;
313	  out	old_behaviors	: exception_behavior_array_t, SameCount;
314	  out	old_flavors	: exception_flavor_array_t, SameCount);
315
316/*
317 * OBSOLETE interfaces, removed from kernel
318 */
319#if KERNEL_SERVER
320skip;
321skip;
322#else
323routine lock_set_create(
324		task		: task_t;
325	out	new_lock_set	: lock_set_t;
326		n_ulocks	: int;
327		policy		: int);
328
329routine lock_set_destroy(
330		task		: task_t;
331		lock_set	: lock_set_t);
332#endif
333
334/*
335 * Create and destroy semaphore synchronizers on a
336 * per-task basis (i.e. the task owns them).
337 */
338
339routine semaphore_create(
340		task		: task_t;
341	out	semaphore	: semaphore_t;
342		policy		: int;
343		value		: int);
344
345routine semaphore_destroy(
346		task		: task_t;
347		semaphore	: semaphore_consume_ref_t);
348
349/*
350 * Set/get policy information for a task.
351 * (Approved Mac OS X microkernel interface)
352 */
353
354routine task_policy_set(
355	task			: task_policy_set_t;
356	flavor			: task_policy_flavor_t;
357	policy_info		: task_policy_t);
358
359routine task_policy_get(
360	task			: task_policy_get_t;
361	flavor			: task_policy_flavor_t;
362out	policy_info		: task_policy_t, CountInOut;
363inout	get_default		: boolean_t);
364
365/*
366 *	OBSOLETE interfaces, removed from kernel.
367 */
368#if KERNEL_SERVER
369skip; /* task_sample */
370skip; /* task_policy */
371skip; /* task_set_emulation */
372skip; /* task_get_emulation_vector */
373skip; /* task_set_emulation_vector */
374skip; /* task_set_ras_pc */
375skip; /* task_zone_info */
376skip; /* task_assign */
377skip; /* task_assign_default */
378skip; /* task_get_assignment */
379skip; /* task_set_policy */
380#else
381routine task_sample(
382		task		: task_t;
383		reply		: mach_port_make_send_t);
384
385routine task_policy(
386	task			: task_t;
387	policy			: policy_t;
388	base			: policy_base_t;
389	set_limit		: boolean_t;
390	change			: boolean_t);
391
392routine task_set_emulation(
393		target_port	: task_t;
394		routine_entry_pt: vm_address_t;
395		routine_number  : int);
396
397routine task_get_emulation_vector(
398		task		: task_t;
399	out	vector_start	: int;
400	out	emulation_vector: emulation_vector_t);
401
402routine task_set_emulation_vector(
403		task		: task_t;
404		vector_start	: int;
405		emulation_vector: emulation_vector_t);
406
407
408routine task_set_ras_pc(
409		target_task     : task_t;
410		basepc          : vm_address_t;
411		boundspc        : vm_address_t);
412
413routine task_zone_info(
414		target_task	: task_inspect_t;
415	out	names		: mach_zone_name_array_t,
416					Dealloc;
417	out	info		: task_zone_info_array_t,
418					Dealloc);
419
420routine task_assign(
421		task		: task_t;
422		new_set		: processor_set_t;
423		assign_threads	: boolean_t);
424
425routine task_assign_default(
426		task		: task_t;
427		assign_threads	: boolean_t);
428
429routine task_get_assignment(
430		task		: task_inspect_t;
431	out	assigned_set	: processor_set_name_t);
432
433routine task_set_policy(
434	task			: task_t;
435	pset			: processor_set_t;
436	policy			: policy_t;
437	base			: policy_base_t;
438	limit			: policy_limit_t;
439	change			: boolean_t);
440#endif
441
442/*
443 * Read the selected state which is to be installed on new
444 * threads in the task as they are created.
445 */
446routine task_get_state(
447		task		: task_read_t;
448		flavor		: thread_state_flavor_t;
449	out	old_state	: thread_state_t, CountInOut);
450
451/*
452 * Set the selected state information to be installed on
453 * all subsequently created threads in the task.
454 */
455routine	task_set_state(
456		task		: task_t;
457		flavor		: thread_state_flavor_t;
458		new_state	: thread_state_t);
459
460/*
461 * Change the task's physical footprint limit (in MB).
462 */
463routine task_set_phys_footprint_limit(
464		task		: task_t;
465		new_limit	: int;
466	out old_limit	: int);
467
468routine MIG_SERVER_SUFFIX(task_suspend2)(
469		target_task : task_read_t;
470	out suspend_token : task_suspension_token_t);
471
472routine MIG_SERVER_SUFFIX(task_resume2)(
473		suspend_token : task_suspension_token_t);
474
475routine task_purgable_info(
476		task 		: task_inspect_t;
477	out	stats		: task_purgable_info_t);
478
479routine task_get_mach_voucher(
480		task		: task_read_t;
481		which		: mach_voucher_selector_t;
482	out	voucher		: ipc_voucher_t);
483
484routine task_set_mach_voucher(
485		task		: task_t;
486		voucher		: ipc_voucher_t);
487
488routine task_swap_mach_voucher(
489		task		: task_t;
490		new_voucher	: ipc_voucher_t;
491	inout	old_voucher	: ipc_voucher_t);
492
493routine task_generate_corpse(
494		task		:task_read_t;
495	out	corpse_task_port:mach_port_t);
496
497routine task_map_corpse_info(
498		task		:task_t;
499		corspe_task	:task_read_t;
500	out	kcd_addr_begin	:vm_address_t;
501	out	kcd_size	:uint32_t);
502
503routine task_register_dyld_image_infos(
504        task            :task_t;
505        dyld_images     :dyld_kernel_image_info_array_t);
506
507routine task_unregister_dyld_image_infos(
508        task            :task_t;
509        dyld_images     :dyld_kernel_image_info_array_t);
510
511routine task_get_dyld_image_infos(
512        task            :task_read_t;
513    out dyld_images     :dyld_kernel_image_info_array_t);
514
515routine task_register_dyld_shared_cache_image_info(
516        task                :task_t;
517        dyld_cache_image    :dyld_kernel_image_info_t;
518        no_cache            :boolean_t;
519        private_cache       :boolean_t);
520
521routine task_register_dyld_set_dyld_state(
522        task           :task_t;
523        dyld_state     :uint8_t);
524
525routine task_register_dyld_get_process_state(
526        task                :task_t;
527    out dyld_process_state  :dyld_kernel_process_info_t);
528
529routine task_map_corpse_info_64(
530		task		:task_t;
531		corspe_task	:task_read_t;
532	out	kcd_addr_begin	:mach_vm_address_t;
533	out	kcd_size	:mach_vm_size_t);
534
535routine task_inspect(
536	    task     : task_inspect_t;
537	    flavor   : task_inspect_flavor_t;
538	out info_out : task_inspect_info_t, CountInOut);
539
540routine task_get_exc_guard_behavior(
541		task	 : task_inspect_t;
542	out behavior : task_exc_guard_behavior_t);
543
544routine task_set_exc_guard_behavior(
545		task	 : task_t;
546		behavior : task_exc_guard_behavior_t);
547
548skip;
549
550#if KERNEL || (!KERNEL && !LIBSYSCALL_INTERFACE)
551routine PREFIX(mach_task_is_self)(
552		task     : task_name_t;
553	out is_self  : boolean_t);
554#else
555	/* Do not generate header, use the one in mach_init.h */
556	skip;
557#endif
558
559routine task_dyld_process_info_notify_register(
560		target_task : task_read_t;
561		notify   	: mach_port_make_send_t);
562
563routine task_create_identity_token(
564	    task     : task_t;
565	out	token    : task_id_token_t);
566
567routine task_identity_token_get_task_port(
568	    token    : task_id_token_t;
569		flavor   : task_flavor_t;
570	out task_port: mach_port_t);
571
572routine task_dyld_process_info_notify_deregister(
573		target_task : task_read_t;
574		notify   	: mach_port_name_t);
575
576routine task_get_exception_ports_info(
577		port : mach_port_t;
578		exception_mask	: exception_mask_t;
579	out	masks		: exception_mask_array_t;
580	out	old_handlers_info	: exception_handler_info_array_t, SameCount;
581	out	old_behaviors	: exception_behavior_array_t, SameCount;
582	out	old_flavors	: exception_flavor_array_t, SameCount);
583
584routine task_test_sync_upcall(
585	task	: task_t;
586	port	: mach_port_t);
587
588routine task_set_corpse_forking_behavior(
589		task	 : task_t;
590		behavior : task_corpse_forking_behavior_t);
591
592routine task_test_async_upcall_propagation(
593	task	: task_t;
594	port	: mach_port_t;
595	qos	: int;
596	iotier	: int);
597
598routine task_map_kcdata_object_64(
599		task		:task_t;
600		kcdata_object	:kcdata_object_t;
601	out	kcd_addr_begin	:mach_vm_address_t;
602	out	kcd_size	:mach_vm_size_t);
603
604/*
605 * When used in conjunction with thread_adopt_exception_handler, we call this a
606 * hardened mach exception handler, and it adds additional security guarantees to this exception port:
607 *		1. Enforces only a subset of exceptions, behaviours, and flavors
608 *			may be used with this port
609 *      2. The `new_exception_port` must be created using MPO_EXCEPTION_PORT (implicitly immovable)
610 *      3. When using *STATE* behaviors of exception handling, only the PC is allowed to be set.
611 *		4. Setting the PC in an exception handler must be signed using a diversifier of
612 *			signed_pc_key (if non-zero). You can pre-sign your PC
613 *			state and then throw away the key to ensure that only a limited
614 *			set of PC's may be used with this exception handler
615 *      5. Calling `[task,thread,host]_set_exception_ports` if you have the IPC_ONLY_ONE_EXCEPTION_PORT
616 *			entitlement is disallowed, and you must use this hardened exception flow.
617 *		If used with the traditional set_exception_ports functions, these
618 *		security guarantees do not apply.
619 *		You can only call this once per task.
620 *
621 *      See tests/ipc/hardened_exceptions.c for examples.
622 */
623routine task_register_hardened_exception_handler(
624			task : task_t;
625			signed_pc_key : uint32_t;
626			exceptions_allowed : exception_mask_t;
627			behaviors_allowed : exception_behavior_t;
628			flavors_allowed	: thread_state_flavor_t;
629			new_exception_port : mach_port_t);
630
631
632/* vim: set ft=c : */
633
634