]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/task.h
xnu-344.49.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 boolean_t kernel_loaded; /* Created with kernel_task_create() */
117
118 /* Miscellaneous */
119 vm_map_t map; /* Address space description */
120 queue_chain_t pset_tasks; /* list of tasks assigned to pset */
121 void *user_data; /* Arbitrary data settable via IPC */
122 int suspend_count; /* Internal scheduling only */
123
124 #if TASK_SWAPPER
125 /* Task swapper data */
126 unsigned short swap_state; /* swap state (e.g. IN/OUT) */
127 unsigned short swap_flags; /* swap flags (e.g. MAKE_UNSWAPP) */
128 unsigned int swap_stamp; /* when last swapped */
129 unsigned long swap_rss; /* size (pages) when last swapped */
130 int swap_ast_waiting; /* number of threads that have not */
131 /* reached a clean point and halted */
132 int swap_nswap; /* number of times this task swapped */
133 queue_chain_t swapped_tasks; /* list of non-resident tasks */
134 #endif /* TASK_SWAPPER */
135
136 /* Activations in this task */
137 queue_head_t thr_acts; /* list of thread_activations */
138 int thr_act_count;
139 int res_act_count;
140 int active_act_count; /* have not terminate_self yet */
141
142 processor_set_t processor_set; /* processor set for new threads */
143 #if MACH_HOST
144 boolean_t may_assign; /* can assigned pset be changed? */
145 boolean_t assign_active; /* waiting for may_assign */
146 #endif /* MACH_HOST */
147
148 /* User-visible scheduling information */
149 integer_t user_stop_count; /* outstanding stops */
150
151 task_role_t role;
152
153 integer_t priority; /* base priority for threads */
154 integer_t max_priority; /* maximum priority for threads */
155
156 /* Task security token */
157 security_token_t sec_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
194 #if NORMA_TASK
195 long child_node; /* if != -1, node for new children */
196 #endif /* NORMA_TASK */
197 #if FAST_TAS
198 vm_offset_t fast_tas_base;
199 vm_offset_t fast_tas_end;
200 #endif /* FAST_TAS */
201 MACHINE_TASK
202 integer_t faults; /* faults counter */
203 integer_t pageins; /* pageins counter */
204 integer_t cow_faults; /* copy on write fault counter */
205 integer_t messages_sent; /* messages sent counter */
206 integer_t messages_received; /* messages received counter */
207 integer_t syscalls_mach; /* mach system call counter */
208 integer_t syscalls_unix; /* unix system call counter */
209 integer_t csw; /* context switch counter */
210 #ifdef MACH_BSD
211 void *bsd_info;
212 #endif
213 vm_offset_t system_shared_region;
214 vm_offset_t dynamic_working_set;
215 } Task;
216
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
221 #define itk_lock_init(task) mutex_init(&(task)->itk_lock_data, \
222 ETAP_THREAD_TASK_ITK)
223 #define itk_lock(task) mutex_lock(&(task)->itk_lock_data)
224 #define itk_unlock(task) mutex_unlock(&(task)->itk_lock_data)
225
226 #define task_reference_locked(task) ((task)->ref_count++)
227
228 /*
229 * Internal only routines
230 */
231
232 /* Initialize task module */
233 extern void task_init(void);
234
235 /* task create */
236 extern kern_return_t task_create_local(
237 task_t parent_task,
238 boolean_t inherit_memory,
239 boolean_t kernel_loaded,
240 task_t *child_task); /* OUT */
241
242 extern void consider_task_collect(void);
243
244 #define current_task_fast() (current_act_fast()->task)
245 #define current_task() current_task_fast()
246
247 #endif /* MACH_KERNEL_PRIVATE */
248
249 extern task_t kernel_task;
250
251 /* Temporarily hold all threads in a task */
252 extern kern_return_t task_hold(
253 task_t task);
254
255 /* Release temporary hold on all threads in a task */
256 extern kern_return_t task_release(
257 task_t task);
258
259 /* Get a task prepared for major changes */
260 extern kern_return_t task_halt(
261 task_t task);
262
263 #if defined(MACH_KERNEL_PRIVATE) || defined(BSD_BUILD)
264 extern kern_return_t task_importance(
265 task_t task,
266 integer_t importance);
267 #endif
268
269 /* JMM - should just be temporary (implementation in bsd_kern still) */
270 extern void *get_bsdtask_info(task_t);
271 extern void set_bsdtask_info(task_t,void *);
272 extern vm_map_t get_task_map(task_t);
273 extern vm_map_t swap_task_map(task_t, vm_map_t);
274 extern pmap_t get_task_pmap(task_t);
275
276 extern boolean_t task_reference_try(task_t task);
277
278 #endif /* __APPLE_API_PRIVATE */
279
280 #if !defined(MACH_KERNEL_PRIVATE)
281
282 extern task_t current_task(void);
283
284 #endif /* MACH_KERNEL_TASK */
285
286 /* Take reference on task (make sure it doesn't go away) */
287 extern void task_reference(task_t task);
288
289 /* Remove reference to task */
290 extern void task_deallocate(task_t task);
291
292 #endif /* _KERN_TASK_H_ */