]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/task.h
xnu-517.3.15.tar.gz
[apple/xnu.git] / osfmk / kern / task.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * @OSF_FREE_COPYRIGHT@
27 */
28 /*
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
31 * All Rights Reserved.
32 *
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
38 *
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
42 *
43 * Carnegie Mellon requests users of this software to return to
44 *
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
49 *
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
52 */
53 /*
54 */
55 /*
56 * File: task.h
57 * Author: Avadis Tevanian, Jr.
58 *
59 * This file contains the structure definitions for tasks.
60 *
61 */
62 /*
63 * Copyright (c) 1993 The University of Utah and
64 * the Computer Systems Laboratory (CSL). All rights reserved.
65 *
66 * Permission to use, copy, modify and distribute this software and its
67 * documentation is hereby granted, provided that both the copyright
68 * notice and this permission notice appear in all copies of the
69 * software, derivative works or modified versions, and any portions
70 * thereof, and that both notices appear in supporting documentation.
71 *
72 * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
73 * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
74 * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
75 *
76 * CSL requests users of this software to return to csl-dist@cs.utah.edu any
77 * improvements that they make and grant CSL redistribution rights.
78 *
79 */
80
81 #ifndef _KERN_TASK_H_
82 #define _KERN_TASK_H_
83
84 #include <kern/kern_types.h>
85 #include <mach/mach_types.h>
86 #include <vm/pmap.h>
87
88 #ifdef __APPLE_API_PRIVATE
89
90 #ifdef MACH_KERNEL_PRIVATE
91
92 #include <mach/boolean.h>
93 #include <mach/port.h>
94 #include <mach/time_value.h>
95 #include <mach/message.h>
96 #include <mach/mach_param.h>
97 #include <mach/task_info.h>
98 #include <mach/exception_types.h>
99 #include <mach_prof.h>
100 #include <machine/task.h>
101 #include <kern/queue.h>
102 #include <kern/exception.h>
103 #include <kern/lock.h>
104 #include <kern/syscall_emulation.h>
105 #include <norma_task.h>
106 #include <mach_host.h>
107 #include <fast_tas.h>
108 #include <task_swapper.h>
109 #include <kern/thread_act.h>
110
111 typedef 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 #if TASK_SWAPPER
124 /* Task swapper data */
125 unsigned short swap_state; /* swap state (e.g. IN/OUT) */
126 unsigned short swap_flags; /* swap flags (e.g. MAKE_UNSWAPP) */
127 unsigned int swap_stamp; /* when last swapped */
128 unsigned long swap_rss; /* size (pages) when last swapped */
129 int swap_ast_waiting; /* number of threads that have not */
130 /* reached a clean point and halted */
131 int swap_nswap; /* number of times this task swapped */
132 queue_chain_t swapped_tasks; /* list of non-resident tasks */
133 #endif /* TASK_SWAPPER */
134
135 /* Threads in this task */
136 queue_head_t threads;
137 int thread_count;
138 int res_thread_count;
139 int active_thread_count;
140
141 processor_set_t processor_set; /* processor set for new threads */
142 #if MACH_HOST
143 boolean_t may_assign; /* can assigned pset be changed? */
144 boolean_t assign_active; /* waiting for may_assign */
145 #endif /* MACH_HOST */
146
147 /* User-visible scheduling information */
148 integer_t user_stop_count; /* outstanding stops */
149
150 task_role_t role;
151
152 integer_t priority; /* base priority for threads */
153 integer_t max_priority; /* maximum priority for threads */
154
155 /* Task security and audit tokens */
156 security_token_t sec_token;
157 audit_token_t audit_token;
158
159 /* Statistics */
160 time_value_t total_user_time; /* user time for dead threads */
161 time_value_t total_system_time; /* system time for dead threads */
162
163 #if MACH_PROF
164 boolean_t task_profiled; /* is task being profiled ? */
165 struct prof_data *profil_buffer;/* profile struct if so */
166 #endif /* MACH_PROF */
167
168 /* IPC structures */
169 decl_mutex_data(,itk_lock_data)
170 struct ipc_port *itk_self; /* not a right, doesn't hold ref */
171 struct ipc_port *itk_sself; /* a send right */
172 struct exception_action exc_actions[EXC_TYPES_COUNT];
173 /* a send right each valid element */
174 struct ipc_port *itk_host; /* a send right */
175 struct ipc_port *itk_bootstrap; /* a send right */
176 struct ipc_port *itk_registered[TASK_PORT_REGISTER_MAX];
177 /* all send rights */
178
179 struct ipc_space *itk_space;
180
181 /* Synchronizer ownership information */
182 queue_head_t semaphore_list; /* list of owned semaphores */
183 queue_head_t lock_set_list; /* list of owned lock sets */
184 int semaphores_owned; /* number of semaphores owned */
185 int lock_sets_owned; /* number of lock sets owned */
186
187 /* User space system call emulation support */
188 struct eml_dispatch *eml_dispatch;
189
190 /* Ledgers */
191 struct ipc_port *wired_ledger_port;
192 struct ipc_port *paged_ledger_port;
193 unsigned long priv_flags; /* privelege resource flags */
194
195 #if NORMA_TASK
196 long child_node; /* if != -1, node for new children */
197 #endif /* NORMA_TASK */
198 #if FAST_TAS
199 vm_offset_t fast_tas_base;
200 vm_offset_t fast_tas_end;
201 #endif /* FAST_TAS */
202 MACHINE_TASK
203 integer_t faults; /* faults counter */
204 integer_t pageins; /* pageins counter */
205 integer_t cow_faults; /* copy on write fault counter */
206 integer_t messages_sent; /* messages sent counter */
207 integer_t messages_received; /* messages received counter */
208 integer_t syscalls_mach; /* mach system call counter */
209 integer_t syscalls_unix; /* unix system call counter */
210 integer_t csw; /* context switch counter */
211 #ifdef MACH_BSD
212 void *bsd_info;
213 #endif
214 vm_offset_t system_shared_region;
215 vm_offset_t dynamic_working_set;
216 uint32_t taskFeatures[2]; /* Special feature for this task */
217 #define tf64BitAddr 0x80000000 /* Task has 64-bit addressing */
218 #define tf64BitData 0x40000000 /* Task has 64-bit data registers */
219 } Task;
220
221 #define task_lock(task) mutex_lock(&(task)->lock)
222 #define task_lock_try(task) mutex_try(&(task)->lock)
223 #define task_unlock(task) mutex_unlock(&(task)->lock)
224
225 #define itk_lock_init(task) mutex_init(&(task)->itk_lock_data, \
226 ETAP_THREAD_TASK_ITK)
227 #define itk_lock(task) mutex_lock(&(task)->itk_lock_data)
228 #define itk_unlock(task) mutex_unlock(&(task)->itk_lock_data)
229
230 #define task_reference_locked(task) ((task)->ref_count++)
231
232 /*
233 * priv_flags definitions
234 */
235 #define VM_BACKING_STORE_PRIV 0x1
236
237 /*
238 * Internal only routines
239 */
240
241 extern void task_backing_store_privileged(
242 task_t task);
243
244 /* Initialize task module */
245 extern void task_init(void);
246
247 /* task create */
248 extern kern_return_t task_create_internal(
249 task_t parent_task,
250 boolean_t inherit_memory,
251 task_t *child_task); /* OUT */
252
253 extern void consider_task_collect(void);
254
255 #define current_task_fast() (current_act_fast()->task)
256 #define current_task() current_task_fast()
257
258 #endif /* MACH_KERNEL_PRIVATE */
259
260 extern task_t kernel_task;
261
262 /* Temporarily hold all threads in a task */
263 extern kern_return_t task_hold(
264 task_t task);
265
266 /* Release temporary hold on all threads in a task */
267 extern kern_return_t task_release(
268 task_t task);
269
270 /* Get a task prepared for major changes */
271 extern kern_return_t task_halt(
272 task_t task);
273
274 #if defined(MACH_KERNEL_PRIVATE) || defined(BSD_BUILD)
275 extern kern_return_t task_importance(
276 task_t task,
277 integer_t importance);
278 #endif
279
280 /* JMM - should just be temporary (implementation in bsd_kern still) */
281 extern void *get_bsdtask_info(task_t);
282 extern void set_bsdtask_info(task_t,void *);
283 extern vm_map_t get_task_map(task_t);
284 extern vm_map_t swap_task_map(task_t, vm_map_t);
285 extern pmap_t get_task_pmap(task_t);
286
287 extern boolean_t task_reference_try(task_t task);
288
289 #endif /* __APPLE_API_PRIVATE */
290
291 #if !defined(MACH_KERNEL_PRIVATE)
292
293 extern task_t current_task(void);
294
295 #endif /* MACH_KERNEL_TASK */
296
297 /* Take reference on task (make sure it doesn't go away) */
298 extern void task_reference(task_t task);
299
300 /* Remove reference to task */
301 extern void task_deallocate(task_t task);
302
303 #endif /* _KERN_TASK_H_ */