]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/task.h
18eded87bb5e05e6edadba96e4e5ca72bd37aa51
[apple/xnu.git] / osfmk / kern / task.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * @OSF_FREE_COPYRIGHT@
25 */
26 /*
27 * Mach Operating System
28 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
29 * All Rights Reserved.
30 *
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
36 *
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 *
41 * Carnegie Mellon requests users of this software to return to
42 *
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
47 *
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
50 */
51 /*
52 */
53 /*
54 * File: task.h
55 * Author: Avadis Tevanian, Jr.
56 *
57 * This file contains the structure definitions for tasks.
58 *
59 */
60 /*
61 * Copyright (c) 1993 The University of Utah and
62 * the Computer Systems Laboratory (CSL). All rights reserved.
63 *
64 * Permission to use, copy, modify and distribute this software and its
65 * documentation is hereby granted, provided that both the copyright
66 * notice and this permission notice appear in all copies of the
67 * software, derivative works or modified versions, and any portions
68 * thereof, and that both notices appear in supporting documentation.
69 *
70 * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
71 * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
72 * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
73 *
74 * CSL requests users of this software to return to csl-dist@cs.utah.edu any
75 * improvements that they make and grant CSL redistribution rights.
76 *
77 */
78
79 #ifndef _KERN_TASK_H_
80 #define _KERN_TASK_H_
81
82 #include <kern/kern_types.h>
83 #include <mach/mach_types.h>
84 #include <sys/cdefs.h>
85
86 #ifdef MACH_KERNEL_PRIVATE
87
88 #include <mach/boolean.h>
89 #include <mach/port.h>
90 #include <mach/time_value.h>
91 #include <mach/message.h>
92 #include <mach/mach_param.h>
93 #include <mach/task_info.h>
94 #include <mach/exception_types.h>
95
96 #include <kern/cpu_data.h>
97 #include <kern/queue.h>
98 #include <kern/exception.h>
99 #include <kern/lock.h>
100 #include <kern/thread.h>
101
102 #include <mach_host.h>
103 #include <mach_prof.h>
104
105 struct task {
106 /* Synchronization/destruction information */
107 decl_mutex_data(,lock) /* Task's lock */
108 int ref_count; /* Number of references to me */
109 boolean_t active; /* Task has not been terminated */
110
111 /* Miscellaneous */
112 vm_map_t map; /* Address space description */
113 queue_chain_t pset_tasks; /* list of tasks assigned to pset */
114 void *user_data; /* Arbitrary data settable via IPC */
115 int suspend_count; /* Internal scheduling only */
116
117 /* Threads in this task */
118 queue_head_t threads;
119 int thread_count;
120 int active_thread_count;
121
122 processor_set_t processor_set; /* processor set for new threads */
123 #if MACH_HOST
124 boolean_t may_assign; /* can assigned pset be changed? */
125 boolean_t assign_active; /* waiting for may_assign */
126 #endif /* MACH_HOST */
127
128 /* User-visible scheduling information */
129 integer_t user_stop_count; /* outstanding stops */
130
131 task_role_t role;
132
133 integer_t priority; /* base priority for threads */
134 integer_t max_priority; /* maximum priority for threads */
135
136 /* Task security and audit tokens */
137 security_token_t sec_token;
138 audit_token_t audit_token;
139
140 /* Statistics */
141 uint64_t total_user_time; /* terminated threads only */
142 uint64_t total_system_time;
143
144 #if MACH_PROF
145 boolean_t task_profiled; /* is task being profiled ? */
146 struct prof_data *profil_buffer;/* profile struct if so */
147 #endif /* MACH_PROF */
148
149 /* IPC structures */
150 decl_mutex_data(,itk_lock_data)
151 struct ipc_port *itk_self; /* not a right, doesn't hold ref */
152 struct ipc_port *itk_sself; /* a send right */
153 struct exception_action exc_actions[EXC_TYPES_COUNT];
154 /* a send right each valid element */
155 struct ipc_port *itk_host; /* a send right */
156 struct ipc_port *itk_bootstrap; /* a send right */
157 struct ipc_port *itk_registered[TASK_PORT_REGISTER_MAX];
158 /* all send rights */
159
160 struct ipc_space *itk_space;
161
162 /* Synchronizer ownership information */
163 queue_head_t semaphore_list; /* list of owned semaphores */
164 queue_head_t lock_set_list; /* list of owned lock sets */
165 int semaphores_owned; /* number of semaphores owned */
166 int lock_sets_owned; /* number of lock sets owned */
167
168 /* Ledgers */
169 struct ipc_port *wired_ledger_port;
170 struct ipc_port *paged_ledger_port;
171 unsigned int priv_flags; /* privilege resource flags */
172 #define VM_BACKING_STORE_PRIV 0x1
173
174 integer_t faults; /* faults counter */
175 integer_t pageins; /* pageins counter */
176 integer_t cow_faults; /* copy on write fault counter */
177 integer_t messages_sent; /* messages sent counter */
178 integer_t messages_received; /* messages received counter */
179 integer_t syscalls_mach; /* mach system call counter */
180 integer_t syscalls_unix; /* unix system call counter */
181 integer_t csw; /* context switch counter */
182 #ifdef MACH_BSD
183 void *bsd_info;
184 #endif
185 struct shared_region_mapping *system_shared_region;
186 struct tws_hash *dynamic_working_set;
187 uint32_t taskFeatures[2]; /* Special feature for this task */
188 #define tf64BitAddr 0x80000000 /* Task has 64-bit addressing */
189 #define tf64BitData 0x40000000 /* Task has 64-bit data registers */
190 #define task_has_64BitAddr(task) \
191 (((task)->taskFeatures[0] & tf64BitAddr) != 0)
192 #define task_set_64BitAddr(task) \
193 ((task)->taskFeatures[0] |= tf64BitAddr)
194 #define task_clear_64BitAddr(task) \
195 ((task)->taskFeatures[0] &= ~tf64BitAddr)
196
197 };
198
199 #define task_lock(task) mutex_lock(&(task)->lock)
200 #define task_lock_try(task) mutex_try(&(task)->lock)
201 #define task_unlock(task) mutex_unlock(&(task)->lock)
202
203 #define itk_lock_init(task) mutex_init(&(task)->itk_lock_data, 0)
204 #define itk_lock(task) mutex_lock(&(task)->itk_lock_data)
205 #define itk_unlock(task) mutex_unlock(&(task)->itk_lock_data)
206
207 #define task_reference_internal(task) \
208 hw_atomic_add(&(task)->ref_count, 1)
209
210 #define task_deallocate_internal(task) \
211 hw_atomic_sub(&(task)->ref_count, 1)
212
213 #define task_reference(task) \
214 MACRO_BEGIN \
215 if ((task) != TASK_NULL) \
216 task_reference_internal(task); \
217 MACRO_END
218
219 extern kern_return_t kernel_task_create(
220 task_t task,
221 vm_offset_t map_base,
222 vm_size_t map_size,
223 task_t *child);
224
225 /* Initialize task module */
226 extern void task_init(void);
227
228 #define current_task_fast() (current_thread()->task)
229 #define current_task() current_task_fast()
230
231 #else /* MACH_KERNEL_PRIVATE */
232
233 __BEGIN_DECLS
234
235 extern task_t current_task(void);
236
237 extern void task_reference(task_t task);
238
239 __END_DECLS
240
241 #endif /* MACH_KERNEL_PRIVATE */
242
243 __BEGIN_DECLS
244
245 #ifdef XNU_KERNEL_PRIVATE
246
247 /* Hold all threads in a task */
248 extern kern_return_t task_hold(
249 task_t task);
250
251 /* Release hold on all threads in a task */
252 extern kern_return_t task_release(
253 task_t task);
254
255 /* Halt all other threads in the current task */
256 extern kern_return_t task_halt(
257 task_t task);
258
259 extern kern_return_t task_terminate_internal(
260 task_t task);
261
262 extern kern_return_t task_create_internal(
263 task_t parent_task,
264 boolean_t inherit_memory,
265 task_t *child_task); /* OUT */
266
267 extern kern_return_t task_importance(
268 task_t task,
269 integer_t importance);
270
271 extern void task_set_64bit(
272 task_t task,
273 boolean_t is64bit);
274
275 extern void task_backing_store_privileged(
276 task_t task);
277
278 extern void task_working_set_disable(
279 task_t task);
280
281 /* Get number of activations in a task */
282 extern int get_task_numacts(
283 task_t task);
284
285
286 /* JMM - should just be temporary (implementation in bsd_kern still) */
287 extern void set_bsdtask_info(task_t,void *);
288 extern vm_map_t get_task_map_reference(task_t);
289 extern vm_map_t swap_task_map(task_t, vm_map_t);
290 extern pmap_t get_task_pmap(task_t);
291
292 extern boolean_t is_kerneltask(task_t task);
293
294 #endif /* XNU_KERNEL_PRIVATE */
295
296 #ifdef KERNEL_PRIVATE
297
298 extern void *get_bsdtask_info(task_t);
299 extern vm_map_t get_task_map(task_t);
300
301 #endif /* KERNEL_PRIVATE */
302
303 extern task_t kernel_task;
304
305 extern void task_deallocate(
306 task_t task);
307
308 __END_DECLS
309
310 #endif /* _KERN_TASK_H_ */