]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
cf7d32b8 | 2 | * Copyright (c) 2000-2008 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 | 117 | struct task { |
1c79356b A |
118 | /* Synchronization/destruction information */ |
119 | decl_mutex_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 */ |
1c79356b A |
122 | |
123 | /* Miscellaneous */ | |
124 | vm_map_t map; /* Address space description */ | |
2d21ac55 | 125 | queue_chain_t tasks; /* global list of tasks */ |
1c79356b A |
126 | void *user_data; /* Arbitrary data settable via IPC */ |
127 | int suspend_count; /* Internal scheduling only */ | |
128 | ||
55e303ae | 129 | /* Threads in this task */ |
2d21ac55 A |
130 | queue_head_t threads; |
131 | int thread_count; | |
132 | uint32_t active_thread_count; | |
cf7d32b8 | 133 | processor_set_t pset_hint; |
2d21ac55 | 134 | struct affinity_space *affinity_space; |
1c79356b A |
135 | |
136 | /* User-visible scheduling information */ | |
137 | integer_t user_stop_count; /* outstanding stops */ | |
138 | ||
0b4e3aa0 | 139 | task_role_t role; |
1c79356b | 140 | |
0b4e3aa0 A |
141 | integer_t priority; /* base priority for threads */ |
142 | integer_t max_priority; /* maximum priority for threads */ | |
1c79356b | 143 | |
55e303ae | 144 | /* Task security and audit tokens */ |
1c79356b | 145 | security_token_t sec_token; |
55e303ae | 146 | audit_token_t audit_token; |
1c79356b A |
147 | |
148 | /* Statistics */ | |
91447636 A |
149 | uint64_t total_user_time; /* terminated threads only */ |
150 | uint64_t total_system_time; | |
1c79356b | 151 | |
2d21ac55 A |
152 | /* Virtual timers */ |
153 | uint32_t vtimers; | |
1c79356b A |
154 | |
155 | /* IPC structures */ | |
156 | decl_mutex_data(,itk_lock_data) | |
157 | struct ipc_port *itk_self; /* not a right, doesn't hold ref */ | |
0c530ab8 | 158 | struct ipc_port *itk_nself; /* not a right, doesn't hold ref */ |
1c79356b A |
159 | struct ipc_port *itk_sself; /* a send right */ |
160 | struct exception_action exc_actions[EXC_TYPES_COUNT]; | |
161 | /* a send right each valid element */ | |
162 | struct ipc_port *itk_host; /* a send right */ | |
163 | struct ipc_port *itk_bootstrap; /* a send right */ | |
2d21ac55 A |
164 | struct ipc_port *itk_seatbelt; /* a send right */ |
165 | struct ipc_port *itk_gssd; /* yet another send right */ | |
166 | struct ipc_port *itk_task_access; /* and another send right */ | |
167 | struct ipc_port *itk_automountd;/* a send right */ | |
1c79356b A |
168 | struct ipc_port *itk_registered[TASK_PORT_REGISTER_MAX]; |
169 | /* all send rights */ | |
170 | ||
171 | struct ipc_space *itk_space; | |
172 | ||
1c79356b A |
173 | /* Synchronizer ownership information */ |
174 | queue_head_t semaphore_list; /* list of owned semaphores */ | |
175 | queue_head_t lock_set_list; /* list of owned lock sets */ | |
176 | int semaphores_owned; /* number of semaphores owned */ | |
177 | int lock_sets_owned; /* number of lock sets owned */ | |
178 | ||
91447636 | 179 | /* Ledgers */ |
1c79356b A |
180 | struct ipc_port *wired_ledger_port; |
181 | struct ipc_port *paged_ledger_port; | |
91447636 A |
182 | unsigned int priv_flags; /* privilege resource flags */ |
183 | #define VM_BACKING_STORE_PRIV 0x1 | |
0c530ab8 A |
184 | |
185 | MACHINE_TASK | |
1c79356b | 186 | |
1c79356b A |
187 | integer_t faults; /* faults counter */ |
188 | integer_t pageins; /* pageins counter */ | |
189 | integer_t cow_faults; /* copy on write fault counter */ | |
190 | integer_t messages_sent; /* messages sent counter */ | |
191 | integer_t messages_received; /* messages received counter */ | |
192 | integer_t syscalls_mach; /* mach system call counter */ | |
193 | integer_t syscalls_unix; /* unix system call counter */ | |
2d21ac55 A |
194 | uint32_t c_switch; /* total context switches */ |
195 | uint32_t p_switch; /* total processor switches */ | |
196 | uint32_t ps_switch; /* total pset switches */ | |
1c79356b A |
197 | #ifdef MACH_BSD |
198 | void *bsd_info; | |
199 | #endif | |
2d21ac55 | 200 | struct vm_shared_region *shared_region; |
55e303ae A |
201 | uint32_t taskFeatures[2]; /* Special feature for this task */ |
202 | #define tf64BitAddr 0x80000000 /* Task has 64-bit addressing */ | |
203 | #define tf64BitData 0x40000000 /* Task has 64-bit data registers */ | |
91447636 A |
204 | #define task_has_64BitAddr(task) \ |
205 | (((task)->taskFeatures[0] & tf64BitAddr) != 0) | |
206 | #define task_set_64BitAddr(task) \ | |
207 | ((task)->taskFeatures[0] |= tf64BitAddr) | |
208 | #define task_clear_64BitAddr(task) \ | |
209 | ((task)->taskFeatures[0] &= ~tf64BitAddr) | |
210 | ||
2d21ac55 A |
211 | #if CONFIG_MACF_MACH |
212 | ipc_labelh_t label; | |
213 | #endif | |
214 | ||
91447636 | 215 | }; |
1c79356b | 216 | |
1c79356b A |
217 | #define task_lock(task) mutex_lock(&(task)->lock) |
218 | #define task_lock_try(task) mutex_try(&(task)->lock) | |
219 | #define task_unlock(task) mutex_unlock(&(task)->lock) | |
220 | ||
2d21ac55 A |
221 | #if CONFIG_MACF_MACH |
222 | #define maclabel label->lh_label | |
223 | ||
224 | #define tasklabel_lock(task) lh_lock((task)->label) | |
225 | #define tasklabel_unlock(task) lh_unlock((task)->label) | |
226 | ||
227 | extern void tasklabel_lock2(task_t a, task_t b); | |
228 | extern void tasklabel_unlock2(task_t a, task_t b); | |
229 | #endif /* MAC_MACH */ | |
230 | ||
91447636 | 231 | #define itk_lock_init(task) mutex_init(&(task)->itk_lock_data, 0) |
1c79356b A |
232 | #define itk_lock(task) mutex_lock(&(task)->itk_lock_data) |
233 | #define itk_unlock(task) mutex_unlock(&(task)->itk_lock_data) | |
234 | ||
91447636 | 235 | #define task_reference_internal(task) \ |
2d21ac55 | 236 | (void)hw_atomic_add(&(task)->ref_count, 1) |
9bccf70c | 237 | |
91447636 A |
238 | #define task_deallocate_internal(task) \ |
239 | hw_atomic_sub(&(task)->ref_count, 1) | |
55e303ae | 240 | |
91447636 A |
241 | #define task_reference(task) \ |
242 | MACRO_BEGIN \ | |
243 | if ((task) != TASK_NULL) \ | |
244 | task_reference_internal(task); \ | |
245 | MACRO_END | |
1c79356b | 246 | |
91447636 A |
247 | extern kern_return_t kernel_task_create( |
248 | task_t task, | |
249 | vm_offset_t map_base, | |
250 | vm_size_t map_size, | |
251 | task_t *child); | |
55e303ae | 252 | |
1c79356b | 253 | /* Initialize task module */ |
2d21ac55 | 254 | extern void task_init(void) __attribute__((section("__TEXT, initcode"))); |
1c79356b | 255 | |
91447636 A |
256 | #define current_task_fast() (current_thread()->task) |
257 | #define current_task() current_task_fast() | |
1c79356b | 258 | |
91447636 | 259 | #else /* MACH_KERNEL_PRIVATE */ |
1c79356b | 260 | |
91447636 A |
261 | __BEGIN_DECLS |
262 | ||
263 | extern task_t current_task(void); | |
264 | ||
265 | extern void task_reference(task_t task); | |
266 | ||
267 | __END_DECLS | |
1c79356b | 268 | |
9bccf70c | 269 | #endif /* MACH_KERNEL_PRIVATE */ |
1c79356b | 270 | |
91447636 | 271 | __BEGIN_DECLS |
1c79356b | 272 | |
91447636 A |
273 | #ifdef XNU_KERNEL_PRIVATE |
274 | ||
275 | /* Hold all threads in a task */ | |
1c79356b | 276 | extern kern_return_t task_hold( |
91447636 | 277 | task_t task); |
1c79356b | 278 | |
91447636 | 279 | /* Release hold on all threads in a task */ |
1c79356b | 280 | extern kern_return_t task_release( |
91447636 | 281 | task_t task); |
1c79356b | 282 | |
91447636 | 283 | /* Halt all other threads in the current task */ |
1c79356b | 284 | extern kern_return_t task_halt( |
91447636 A |
285 | task_t task); |
286 | ||
287 | extern kern_return_t task_terminate_internal( | |
288 | task_t task); | |
289 | ||
290 | extern kern_return_t task_create_internal( | |
291 | task_t parent_task, | |
292 | boolean_t inherit_memory, | |
0c530ab8 | 293 | boolean_t is_64bit, |
91447636 | 294 | task_t *child_task); /* OUT */ |
1c79356b | 295 | |
0b4e3aa0 A |
296 | extern kern_return_t task_importance( |
297 | task_t task, | |
298 | integer_t importance); | |
91447636 | 299 | |
2d21ac55 A |
300 | extern void task_vtimer_set( |
301 | task_t task, | |
302 | integer_t which); | |
303 | ||
304 | extern void task_vtimer_clear( | |
305 | task_t task, | |
306 | integer_t which); | |
307 | ||
308 | extern void task_vtimer_update( | |
309 | task_t task, | |
310 | integer_t which, | |
311 | uint32_t *microsecs); | |
312 | ||
313 | #define TASK_VTIMER_USER 0x01 | |
314 | #define TASK_VTIMER_PROF 0x02 | |
315 | #define TASK_VTIMER_RLIM 0x04 | |
316 | ||
91447636 A |
317 | extern void task_set_64bit( |
318 | task_t task, | |
319 | boolean_t is64bit); | |
320 | ||
321 | extern void task_backing_store_privileged( | |
322 | task_t task); | |
323 | ||
593a1d5f A |
324 | extern int get_task_numactivethreads( |
325 | task_t task); | |
91447636 A |
326 | /* Get number of activations in a task */ |
327 | extern int get_task_numacts( | |
328 | task_t task); | |
329 | ||
0b4e3aa0 | 330 | |
1c79356b | 331 | /* JMM - should just be temporary (implementation in bsd_kern still) */ |
1c79356b | 332 | extern void set_bsdtask_info(task_t,void *); |
91447636 | 333 | extern vm_map_t get_task_map_reference(task_t); |
1c79356b A |
334 | extern vm_map_t swap_task_map(task_t, vm_map_t); |
335 | extern pmap_t get_task_pmap(task_t); | |
9bccf70c | 336 | |
91447636 | 337 | extern boolean_t is_kerneltask(task_t task); |
9bccf70c | 338 | |
2d21ac55 A |
339 | extern kern_return_t check_actforsig(task_t task, thread_t thread, int setast); |
340 | ||
91447636 | 341 | #endif /* XNU_KERNEL_PRIVATE */ |
9bccf70c | 342 | |
91447636 | 343 | #ifdef KERNEL_PRIVATE |
9bccf70c | 344 | |
91447636 | 345 | extern void *get_bsdtask_info(task_t); |
2d21ac55 | 346 | extern void *get_bsdthreadtask_info(thread_t); |
91447636 | 347 | extern vm_map_t get_task_map(task_t); |
9bccf70c | 348 | |
91447636 | 349 | #endif /* KERNEL_PRIVATE */ |
9bccf70c | 350 | |
91447636 A |
351 | extern task_t kernel_task; |
352 | ||
353 | extern void task_deallocate( | |
354 | task_t task); | |
9bccf70c | 355 | |
0c530ab8 A |
356 | extern void task_name_deallocate( |
357 | task_name_t task_name); | |
91447636 | 358 | __END_DECLS |
9bccf70c | 359 | |
1c79356b | 360 | #endif /* _KERN_TASK_H_ */ |