]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/task.h
xnu-1504.15.3.tar.gz
[apple/xnu.git] / osfmk / kern / task.h
CommitLineData
1c79356b 1/*
b0d623f7 2 * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * @OSF_FREE_COPYRIGHT@
30 */
31/*
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988 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 * File: task.h
60 * Author: Avadis Tevanian, Jr.
61 *
62 * This file contains the structure definitions for tasks.
63 *
64 */
65/*
66 * Copyright (c) 1993 The University of Utah and
67 * the Computer Systems Laboratory (CSL). All rights reserved.
68 *
69 * Permission to use, copy, modify and distribute this software and its
70 * documentation is hereby granted, provided that both the copyright
71 * notice and this permission notice appear in all copies of the
72 * software, derivative works or modified versions, and any portions
73 * thereof, and that both notices appear in supporting documentation.
74 *
75 * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
76 * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
77 * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
78 *
79 * CSL requests users of this software to return to csl-dist@cs.utah.edu any
80 * improvements that they make and grant CSL redistribution rights.
81 *
82 */
2d21ac55
A
83/*
84 * NOTICE: This file was modified by McAfee Research in 2004 to introduce
85 * support for mandatory and extensible security protections. This notice
86 * is included in support of clause 2.2 (b) of the Apple Public License,
87 * Version 2.0.
88 * Copyright (c) 2005 SPARTA, Inc.
89 */
1c79356b
A
90
91#ifndef _KERN_TASK_H_
92#define _KERN_TASK_H_
93
94#include <kern/kern_types.h>
95#include <mach/mach_types.h>
91447636 96#include <sys/cdefs.h>
9bccf70c
A
97
98#ifdef MACH_KERNEL_PRIVATE
99
1c79356b
A
100#include <mach/boolean.h>
101#include <mach/port.h>
102#include <mach/time_value.h>
103#include <mach/message.h>
104#include <mach/mach_param.h>
105#include <mach/task_info.h>
106#include <mach/exception_types.h>
0c530ab8 107#include <machine/task.h>
91447636
A
108
109#include <kern/cpu_data.h>
1c79356b
A
110#include <kern/queue.h>
111#include <kern/exception.h>
112#include <kern/lock.h>
91447636 113#include <kern/thread.h>
2d21ac55
A
114#include <security/_label.h>
115#include <ipc/ipc_labelh.h>
1c79356b 116
91447636 117struct task {
1c79356b 118 /* Synchronization/destruction information */
b0d623f7 119 decl_lck_mtx_data(,lock) /* Task's lock */
2d21ac55 120 uint32_t ref_count; /* Number of references to me */
1c79356b 121 boolean_t active; /* Task has not been terminated */
b0d623f7 122 boolean_t halting; /* Task is being halted */
1c79356b
A
123
124 /* Miscellaneous */
125 vm_map_t map; /* Address space description */
2d21ac55 126 queue_chain_t tasks; /* global list of tasks */
1c79356b 127 void *user_data; /* Arbitrary data settable via IPC */
1c79356b 128
55e303ae 129 /* Threads in this task */
2d21ac55 130 queue_head_t threads;
b0d623f7
A
131
132 processor_set_t pset_hint;
133 struct affinity_space *affinity_space;
134
2d21ac55
A
135 int thread_count;
136 uint32_t active_thread_count;
b0d623f7 137 int suspend_count; /* Internal scheduling only */
1c79356b
A
138
139 /* User-visible scheduling information */
140 integer_t user_stop_count; /* outstanding stops */
141
0b4e3aa0 142 task_role_t role;
1c79356b 143
0b4e3aa0
A
144 integer_t priority; /* base priority for threads */
145 integer_t max_priority; /* maximum priority for threads */
1c79356b 146
55e303ae 147 /* Task security and audit tokens */
1c79356b 148 security_token_t sec_token;
55e303ae 149 audit_token_t audit_token;
1c79356b
A
150
151 /* Statistics */
91447636
A
152 uint64_t total_user_time; /* terminated threads only */
153 uint64_t total_system_time;
1c79356b 154
2d21ac55
A
155 /* Virtual timers */
156 uint32_t vtimers;
1c79356b
A
157
158 /* IPC structures */
b0d623f7 159 decl_lck_mtx_data(,itk_lock_data)
1c79356b 160 struct ipc_port *itk_self; /* not a right, doesn't hold ref */
0c530ab8 161 struct ipc_port *itk_nself; /* not a right, doesn't hold ref */
1c79356b
A
162 struct ipc_port *itk_sself; /* a send right */
163 struct exception_action exc_actions[EXC_TYPES_COUNT];
164 /* a send right each valid element */
165 struct ipc_port *itk_host; /* a send right */
166 struct ipc_port *itk_bootstrap; /* a send right */
2d21ac55
A
167 struct ipc_port *itk_seatbelt; /* a send right */
168 struct ipc_port *itk_gssd; /* yet another send right */
169 struct ipc_port *itk_task_access; /* and another send right */
1c79356b
A
170 struct ipc_port *itk_registered[TASK_PORT_REGISTER_MAX];
171 /* all send rights */
172
173 struct ipc_space *itk_space;
174
1c79356b
A
175 /* Synchronizer ownership information */
176 queue_head_t semaphore_list; /* list of owned semaphores */
177 queue_head_t lock_set_list; /* list of owned lock sets */
178 int semaphores_owned; /* number of semaphores owned */
179 int lock_sets_owned; /* number of lock sets owned */
180
91447636 181 /* Ledgers */
1c79356b
A
182 struct ipc_port *wired_ledger_port;
183 struct ipc_port *paged_ledger_port;
91447636
A
184 unsigned int priv_flags; /* privilege resource flags */
185#define VM_BACKING_STORE_PRIV 0x1
0c530ab8
A
186
187 MACHINE_TASK
1c79356b 188
1c79356b
A
189 integer_t faults; /* faults counter */
190 integer_t pageins; /* pageins counter */
191 integer_t cow_faults; /* copy on write fault counter */
192 integer_t messages_sent; /* messages sent counter */
193 integer_t messages_received; /* messages received counter */
194 integer_t syscalls_mach; /* mach system call counter */
195 integer_t syscalls_unix; /* unix system call counter */
2d21ac55
A
196 uint32_t c_switch; /* total context switches */
197 uint32_t p_switch; /* total processor switches */
198 uint32_t ps_switch; /* total pset switches */
1c79356b
A
199#ifdef MACH_BSD
200 void *bsd_info;
201#endif
2d21ac55 202 struct vm_shared_region *shared_region;
55e303ae
A
203 uint32_t taskFeatures[2]; /* Special feature for this task */
204#define tf64BitAddr 0x80000000 /* Task has 64-bit addressing */
205#define tf64BitData 0x40000000 /* Task has 64-bit data registers */
91447636
A
206#define task_has_64BitAddr(task) \
207 (((task)->taskFeatures[0] & tf64BitAddr) != 0)
208#define task_set_64BitAddr(task) \
209 ((task)->taskFeatures[0] |= tf64BitAddr)
210#define task_clear_64BitAddr(task) \
211 ((task)->taskFeatures[0] &= ~tf64BitAddr)
212
b0d623f7
A
213 mach_vm_address_t all_image_info_addr; /* dyld __all_image_info */
214 mach_vm_size_t all_image_info_size; /* section location and size */
2d21ac55
A
215#if CONFIG_MACF_MACH
216 ipc_labelh_t label;
217#endif
218
b0d623f7
A
219#if CONFIG_COUNTERS
220#define TASK_PMC_FLAG 0x1 /* Bit in "t_chud" signifying PMC interest */
221 uint32_t t_chud; /* CHUD flags, used for Shark */
222#endif
223
91447636 224};
1c79356b 225
b0d623f7
A
226#define task_lock(task) lck_mtx_lock(&(task)->lock)
227#define task_lock_try(task) lck_mtx_try_lock(&(task)->lock)
228#define task_unlock(task) lck_mtx_unlock(&(task)->lock)
1c79356b 229
2d21ac55
A
230#if CONFIG_MACF_MACH
231#define maclabel label->lh_label
232
233#define tasklabel_lock(task) lh_lock((task)->label)
234#define tasklabel_unlock(task) lh_unlock((task)->label)
235
236extern void tasklabel_lock2(task_t a, task_t b);
237extern void tasklabel_unlock2(task_t a, task_t b);
238#endif /* MAC_MACH */
239
b0d623f7
A
240#define itk_lock_init(task) lck_mtx_init(&(task)->itk_lock_data, &ipc_lck_grp, &ipc_lck_attr)
241#define itk_lock_destroy(task) lck_mtx_destroy(&(task)->itk_lock_data, &ipc_lck_grp)
242#define itk_lock(task) lck_mtx_lock(&(task)->itk_lock_data)
243#define itk_unlock(task) lck_mtx_unlock(&(task)->itk_lock_data)
1c79356b 244
91447636 245#define task_reference_internal(task) \
2d21ac55 246 (void)hw_atomic_add(&(task)->ref_count, 1)
9bccf70c 247
91447636
A
248#define task_deallocate_internal(task) \
249 hw_atomic_sub(&(task)->ref_count, 1)
55e303ae 250
91447636
A
251#define task_reference(task) \
252MACRO_BEGIN \
253 if ((task) != TASK_NULL) \
254 task_reference_internal(task); \
255MACRO_END
1c79356b 256
91447636
A
257extern kern_return_t kernel_task_create(
258 task_t task,
259 vm_offset_t map_base,
260 vm_size_t map_size,
261 task_t *child);
55e303ae 262
1c79356b 263/* Initialize task module */
2d21ac55 264extern void task_init(void) __attribute__((section("__TEXT, initcode")));
1c79356b 265
91447636
A
266#define current_task_fast() (current_thread()->task)
267#define current_task() current_task_fast()
1c79356b 268
b0d623f7
A
269extern lck_attr_t task_lck_attr;
270extern lck_grp_t task_lck_grp;
271
91447636 272#else /* MACH_KERNEL_PRIVATE */
1c79356b 273
91447636
A
274__BEGIN_DECLS
275
276extern task_t current_task(void);
277
278extern void task_reference(task_t task);
279
280__END_DECLS
1c79356b 281
9bccf70c 282#endif /* MACH_KERNEL_PRIVATE */
1c79356b 283
91447636 284__BEGIN_DECLS
1c79356b 285
91447636
A
286#ifdef XNU_KERNEL_PRIVATE
287
288/* Hold all threads in a task */
1c79356b 289extern kern_return_t task_hold(
91447636 290 task_t task);
1c79356b 291
91447636 292/* Release hold on all threads in a task */
1c79356b 293extern kern_return_t task_release(
91447636 294 task_t task);
1c79356b 295
91447636 296/* Halt all other threads in the current task */
b0d623f7
A
297extern kern_return_t task_start_halt(
298 task_t task);
299
300/* Wait for other threads to halt and free halting task resources */
301extern void task_complete_halt(
91447636
A
302 task_t task);
303
304extern kern_return_t task_terminate_internal(
305 task_t task);
306
307extern kern_return_t task_create_internal(
308 task_t parent_task,
309 boolean_t inherit_memory,
0c530ab8 310 boolean_t is_64bit,
91447636 311 task_t *child_task); /* OUT */
1c79356b 312
0b4e3aa0
A
313extern kern_return_t task_importance(
314 task_t task,
315 integer_t importance);
91447636 316
2d21ac55
A
317extern void task_vtimer_set(
318 task_t task,
319 integer_t which);
320
321extern void task_vtimer_clear(
322 task_t task,
323 integer_t which);
324
325extern void task_vtimer_update(
326 task_t task,
327 integer_t which,
328 uint32_t *microsecs);
329
330#define TASK_VTIMER_USER 0x01
331#define TASK_VTIMER_PROF 0x02
332#define TASK_VTIMER_RLIM 0x04
333
91447636
A
334extern void task_set_64bit(
335 task_t task,
336 boolean_t is64bit);
337
338extern void task_backing_store_privileged(
339 task_t task);
340
b0d623f7
A
341extern void task_set_dyld_info(
342 task_t task,
343 mach_vm_address_t addr,
344 mach_vm_size_t size);
345
91447636
A
346/* Get number of activations in a task */
347extern int get_task_numacts(
348 task_t task);
349
b0d623f7 350extern int get_task_numactivethreads(task_t task);
0b4e3aa0 351
1c79356b 352/* JMM - should just be temporary (implementation in bsd_kern still) */
1c79356b 353extern void set_bsdtask_info(task_t,void *);
91447636 354extern vm_map_t get_task_map_reference(task_t);
b0d623f7 355extern vm_map_t swap_task_map(task_t, thread_t, vm_map_t);
1c79356b 356extern pmap_t get_task_pmap(task_t);
b0d623f7 357extern uint64_t get_task_resident_size(task_t);
9bccf70c 358
91447636 359extern boolean_t is_kerneltask(task_t task);
9bccf70c 360
2d21ac55
A
361extern kern_return_t check_actforsig(task_t task, thread_t thread, int setast);
362
b0d623f7
A
363extern kern_return_t machine_task_get_state(
364 task_t task,
365 int flavor,
366 thread_state_t state,
367 mach_msg_type_number_t *state_count);
368
369extern kern_return_t machine_task_set_state(
370 task_t task,
371 int flavor,
372 thread_state_t state,
373 mach_msg_type_number_t state_count);
374
375
91447636 376#endif /* XNU_KERNEL_PRIVATE */
9bccf70c 377
91447636 378#ifdef KERNEL_PRIVATE
9bccf70c 379
91447636 380extern void *get_bsdtask_info(task_t);
2d21ac55 381extern void *get_bsdthreadtask_info(thread_t);
91447636 382extern vm_map_t get_task_map(task_t);
9bccf70c 383
91447636 384#endif /* KERNEL_PRIVATE */
9bccf70c 385
91447636
A
386extern task_t kernel_task;
387
388extern void task_deallocate(
389 task_t task);
9bccf70c 390
0c530ab8
A
391extern void task_name_deallocate(
392 task_name_t task_name);
91447636 393__END_DECLS
9bccf70c 394
1c79356b 395#endif /* _KERN_TASK_H_ */