]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000-2005 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_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 | */ | |
83 | ||
84 | #ifndef _KERN_TASK_H_ | |
85 | #define _KERN_TASK_H_ | |
86 | ||
87 | #include <kern/kern_types.h> | |
88 | #include <mach/mach_types.h> | |
89 | #include <sys/cdefs.h> | |
90 | ||
91 | #ifdef MACH_KERNEL_PRIVATE | |
92 | ||
93 | #include <mach/boolean.h> | |
94 | #include <mach/port.h> | |
95 | #include <mach/time_value.h> | |
96 | #include <mach/message.h> | |
97 | #include <mach/mach_param.h> | |
98 | #include <mach/task_info.h> | |
99 | #include <mach/exception_types.h> | |
100 | #include <machine/task.h> | |
101 | ||
102 | #include <kern/cpu_data.h> | |
103 | #include <kern/queue.h> | |
104 | #include <kern/exception.h> | |
105 | #include <kern/lock.h> | |
106 | #include <kern/thread.h> | |
107 | ||
108 | #include <mach_host.h> | |
109 | #include <mach_prof.h> | |
110 | ||
111 | struct task { | |
112 | /* Synchronization/destruction information */ | |
113 | decl_mutex_data(,lock) /* Task's lock */ | |
114 | int ref_count; /* Number of references to me */ | |
115 | boolean_t active; /* Task has not been terminated */ | |
116 | ||
117 | /* Miscellaneous */ | |
118 | vm_map_t map; /* Address space description */ | |
119 | queue_chain_t pset_tasks; /* list of tasks assigned to pset */ | |
120 | void *user_data; /* Arbitrary data settable via IPC */ | |
121 | int suspend_count; /* Internal scheduling only */ | |
122 | ||
123 | /* Threads in this task */ | |
124 | queue_head_t threads; | |
125 | int thread_count; | |
126 | int active_thread_count; | |
127 | ||
128 | processor_set_t processor_set; /* processor set for new threads */ | |
129 | #if MACH_HOST | |
130 | boolean_t may_assign; /* can assigned pset be changed? */ | |
131 | boolean_t assign_active; /* waiting for may_assign */ | |
132 | #endif /* MACH_HOST */ | |
133 | ||
134 | /* User-visible scheduling information */ | |
135 | integer_t user_stop_count; /* outstanding stops */ | |
136 | ||
137 | task_role_t role; | |
138 | ||
139 | integer_t priority; /* base priority for threads */ | |
140 | integer_t max_priority; /* maximum priority for threads */ | |
141 | ||
142 | /* Task security and audit tokens */ | |
143 | security_token_t sec_token; | |
144 | audit_token_t audit_token; | |
145 | ||
146 | /* Statistics */ | |
147 | uint64_t total_user_time; /* terminated threads only */ | |
148 | uint64_t total_system_time; | |
149 | ||
150 | #if MACH_PROF | |
151 | boolean_t task_profiled; /* is task being profiled ? */ | |
152 | struct prof_data *profil_buffer;/* profile struct if so */ | |
153 | #endif /* MACH_PROF */ | |
154 | ||
155 | /* IPC structures */ | |
156 | decl_mutex_data(,itk_lock_data) | |
157 | struct ipc_port *itk_self; /* not a right, doesn't hold ref */ | |
158 | struct ipc_port *itk_nself; /* not a right, doesn't hold ref */ | |
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 */ | |
164 | struct ipc_port *itk_registered[TASK_PORT_REGISTER_MAX]; | |
165 | /* all send rights */ | |
166 | ||
167 | struct ipc_space *itk_space; | |
168 | ||
169 | /* Synchronizer ownership information */ | |
170 | queue_head_t semaphore_list; /* list of owned semaphores */ | |
171 | queue_head_t lock_set_list; /* list of owned lock sets */ | |
172 | int semaphores_owned; /* number of semaphores owned */ | |
173 | int lock_sets_owned; /* number of lock sets owned */ | |
174 | ||
175 | /* Ledgers */ | |
176 | struct ipc_port *wired_ledger_port; | |
177 | struct ipc_port *paged_ledger_port; | |
178 | unsigned int priv_flags; /* privilege resource flags */ | |
179 | #define VM_BACKING_STORE_PRIV 0x1 | |
180 | ||
181 | MACHINE_TASK | |
182 | ||
183 | integer_t faults; /* faults counter */ | |
184 | integer_t pageins; /* pageins counter */ | |
185 | integer_t cow_faults; /* copy on write fault counter */ | |
186 | integer_t messages_sent; /* messages sent counter */ | |
187 | integer_t messages_received; /* messages received counter */ | |
188 | integer_t syscalls_mach; /* mach system call counter */ | |
189 | integer_t syscalls_unix; /* unix system call counter */ | |
190 | integer_t csw; /* context switch counter */ | |
191 | #ifdef MACH_BSD | |
192 | void *bsd_info; | |
193 | #endif | |
194 | struct shared_region_mapping *system_shared_region; | |
195 | struct tws_hash *dynamic_working_set; | |
196 | uint32_t taskFeatures[2]; /* Special feature for this task */ | |
197 | #define tf64BitAddr 0x80000000 /* Task has 64-bit addressing */ | |
198 | #define tf64BitData 0x40000000 /* Task has 64-bit data registers */ | |
199 | #define task_has_64BitAddr(task) \ | |
200 | (((task)->taskFeatures[0] & tf64BitAddr) != 0) | |
201 | #define task_set_64BitAddr(task) \ | |
202 | ((task)->taskFeatures[0] |= tf64BitAddr) | |
203 | #define task_clear_64BitAddr(task) \ | |
204 | ((task)->taskFeatures[0] &= ~tf64BitAddr) | |
205 | ||
206 | }; | |
207 | ||
208 | #define task_lock(task) mutex_lock(&(task)->lock) | |
209 | #define task_lock_try(task) mutex_try(&(task)->lock) | |
210 | #define task_unlock(task) mutex_unlock(&(task)->lock) | |
211 | ||
212 | #define itk_lock_init(task) mutex_init(&(task)->itk_lock_data, 0) | |
213 | #define itk_lock(task) mutex_lock(&(task)->itk_lock_data) | |
214 | #define itk_unlock(task) mutex_unlock(&(task)->itk_lock_data) | |
215 | ||
216 | #define task_reference_internal(task) \ | |
217 | hw_atomic_add(&(task)->ref_count, 1) | |
218 | ||
219 | #define task_deallocate_internal(task) \ | |
220 | hw_atomic_sub(&(task)->ref_count, 1) | |
221 | ||
222 | #define task_reference(task) \ | |
223 | MACRO_BEGIN \ | |
224 | if ((task) != TASK_NULL) \ | |
225 | task_reference_internal(task); \ | |
226 | MACRO_END | |
227 | ||
228 | extern kern_return_t kernel_task_create( | |
229 | task_t task, | |
230 | vm_offset_t map_base, | |
231 | vm_size_t map_size, | |
232 | task_t *child); | |
233 | ||
234 | /* Initialize task module */ | |
235 | extern void task_init(void); | |
236 | ||
237 | #define current_task_fast() (current_thread()->task) | |
238 | #define current_task() current_task_fast() | |
239 | ||
240 | #else /* MACH_KERNEL_PRIVATE */ | |
241 | ||
242 | __BEGIN_DECLS | |
243 | ||
244 | extern task_t current_task(void); | |
245 | ||
246 | extern void task_reference(task_t task); | |
247 | ||
248 | __END_DECLS | |
249 | ||
250 | #endif /* MACH_KERNEL_PRIVATE */ | |
251 | ||
252 | __BEGIN_DECLS | |
253 | ||
254 | #ifdef XNU_KERNEL_PRIVATE | |
255 | ||
256 | /* Hold all threads in a task */ | |
257 | extern kern_return_t task_hold( | |
258 | task_t task); | |
259 | ||
260 | /* Release hold on all threads in a task */ | |
261 | extern kern_return_t task_release( | |
262 | task_t task); | |
263 | ||
264 | /* Halt all other threads in the current task */ | |
265 | extern kern_return_t task_halt( | |
266 | task_t task); | |
267 | ||
268 | extern kern_return_t task_terminate_internal( | |
269 | task_t task); | |
270 | ||
271 | extern kern_return_t task_create_internal( | |
272 | task_t parent_task, | |
273 | boolean_t inherit_memory, | |
274 | boolean_t is_64bit, | |
275 | task_t *child_task); /* OUT */ | |
276 | ||
277 | extern kern_return_t task_importance( | |
278 | task_t task, | |
279 | integer_t importance); | |
280 | ||
281 | extern void task_set_64bit( | |
282 | task_t task, | |
283 | boolean_t is64bit); | |
284 | ||
285 | extern void task_backing_store_privileged( | |
286 | task_t task); | |
287 | ||
288 | extern void task_working_set_disable( | |
289 | task_t task); | |
290 | ||
291 | ||
292 | /* Get number of activations in a task */ | |
293 | extern int get_task_numacts( | |
294 | task_t task); | |
295 | ||
296 | ||
297 | /* JMM - should just be temporary (implementation in bsd_kern still) */ | |
298 | extern void set_bsdtask_info(task_t,void *); | |
299 | extern vm_map_t get_task_map_reference(task_t); | |
300 | extern vm_map_t swap_task_map(task_t, vm_map_t); | |
301 | extern pmap_t get_task_pmap(task_t); | |
302 | ||
303 | extern boolean_t is_kerneltask(task_t task); | |
304 | ||
305 | #endif /* XNU_KERNEL_PRIVATE */ | |
306 | ||
307 | #ifdef KERNEL_PRIVATE | |
308 | ||
309 | extern void *get_bsdtask_info(task_t); | |
310 | extern vm_map_t get_task_map(task_t); | |
311 | ||
312 | #endif /* KERNEL_PRIVATE */ | |
313 | ||
314 | extern task_t kernel_task; | |
315 | ||
316 | extern void task_deallocate( | |
317 | task_t task); | |
318 | ||
319 | extern void task_name_deallocate( | |
320 | task_name_t task_name); | |
321 | __END_DECLS | |
322 | ||
323 | #endif /* _KERN_TASK_H_ */ |