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