]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/task.h
xnu-792.25.20.tar.gz
[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 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_FREE_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50 /*
51 */
52 /*
53 * File: task.h
54 * Author: Avadis Tevanian, Jr.
55 *
56 * This file contains the structure definitions for tasks.
57 *
58 */
59 /*
60 * Copyright (c) 1993 The University of Utah and
61 * the Computer Systems Laboratory (CSL). All rights reserved.
62 *
63 * Permission to use, copy, modify and distribute this software and its
64 * documentation is hereby granted, provided that both the copyright
65 * notice and this permission notice appear in all copies of the
66 * software, derivative works or modified versions, and any portions
67 * thereof, and that both notices appear in supporting documentation.
68 *
69 * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
70 * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
71 * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
72 *
73 * CSL requests users of this software to return to csl-dist@cs.utah.edu any
74 * improvements that they make and grant CSL redistribution rights.
75 *
76 */
77
78 #ifndef _KERN_TASK_H_
79 #define _KERN_TASK_H_
80
81 #include <kern/kern_types.h>
82 #include <mach/mach_types.h>
83 #include <sys/cdefs.h>
84
85 #ifdef MACH_KERNEL_PRIVATE
86
87 #include <mach/boolean.h>
88 #include <mach/port.h>
89 #include <mach/time_value.h>
90 #include <mach/message.h>
91 #include <mach/mach_param.h>
92 #include <mach/task_info.h>
93 #include <mach/exception_types.h>
94 #include <machine/task.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_nself; /* not a right, doesn't hold ref */
153 struct ipc_port *itk_sself; /* a send right */
154 struct exception_action exc_actions[EXC_TYPES_COUNT];
155 /* a send right each valid element */
156 struct ipc_port *itk_host; /* a send right */
157 struct ipc_port *itk_bootstrap; /* a send right */
158 struct ipc_port *itk_registered[TASK_PORT_REGISTER_MAX];
159 /* all send rights */
160
161 struct ipc_space *itk_space;
162
163 /* Synchronizer ownership information */
164 queue_head_t semaphore_list; /* list of owned semaphores */
165 queue_head_t lock_set_list; /* list of owned lock sets */
166 int semaphores_owned; /* number of semaphores owned */
167 int lock_sets_owned; /* number of lock sets owned */
168
169 /* Ledgers */
170 struct ipc_port *wired_ledger_port;
171 struct ipc_port *paged_ledger_port;
172 unsigned int priv_flags; /* privilege resource flags */
173 #define VM_BACKING_STORE_PRIV 0x1
174
175 MACHINE_TASK
176
177 integer_t faults; /* faults counter */
178 integer_t pageins; /* pageins counter */
179 integer_t cow_faults; /* copy on write fault counter */
180 integer_t messages_sent; /* messages sent counter */
181 integer_t messages_received; /* messages received counter */
182 integer_t syscalls_mach; /* mach system call counter */
183 integer_t syscalls_unix; /* unix system call counter */
184 integer_t csw; /* context switch counter */
185 #ifdef MACH_BSD
186 void *bsd_info;
187 #endif
188 struct shared_region_mapping *system_shared_region;
189 struct tws_hash *dynamic_working_set;
190 uint32_t taskFeatures[2]; /* Special feature for this task */
191 #define tf64BitAddr 0x80000000 /* Task has 64-bit addressing */
192 #define tf64BitData 0x40000000 /* Task has 64-bit data registers */
193 #define task_has_64BitAddr(task) \
194 (((task)->taskFeatures[0] & tf64BitAddr) != 0)
195 #define task_set_64BitAddr(task) \
196 ((task)->taskFeatures[0] |= tf64BitAddr)
197 #define task_clear_64BitAddr(task) \
198 ((task)->taskFeatures[0] &= ~tf64BitAddr)
199
200 };
201
202 #define task_lock(task) mutex_lock(&(task)->lock)
203 #define task_lock_try(task) mutex_try(&(task)->lock)
204 #define task_unlock(task) mutex_unlock(&(task)->lock)
205
206 #define itk_lock_init(task) mutex_init(&(task)->itk_lock_data, 0)
207 #define itk_lock(task) mutex_lock(&(task)->itk_lock_data)
208 #define itk_unlock(task) mutex_unlock(&(task)->itk_lock_data)
209
210 #define task_reference_internal(task) \
211 hw_atomic_add(&(task)->ref_count, 1)
212
213 #define task_deallocate_internal(task) \
214 hw_atomic_sub(&(task)->ref_count, 1)
215
216 #define task_reference(task) \
217 MACRO_BEGIN \
218 if ((task) != TASK_NULL) \
219 task_reference_internal(task); \
220 MACRO_END
221
222 extern kern_return_t kernel_task_create(
223 task_t task,
224 vm_offset_t map_base,
225 vm_size_t map_size,
226 task_t *child);
227
228 /* Initialize task module */
229 extern void task_init(void);
230
231 #define current_task_fast() (current_thread()->task)
232 #define current_task() current_task_fast()
233
234 #else /* MACH_KERNEL_PRIVATE */
235
236 __BEGIN_DECLS
237
238 extern task_t current_task(void);
239
240 extern void task_reference(task_t task);
241
242 __END_DECLS
243
244 #endif /* MACH_KERNEL_PRIVATE */
245
246 __BEGIN_DECLS
247
248 #ifdef XNU_KERNEL_PRIVATE
249
250 /* Hold all threads in a task */
251 extern kern_return_t task_hold(
252 task_t task);
253
254 /* Release hold on all threads in a task */
255 extern kern_return_t task_release(
256 task_t task);
257
258 /* Halt all other threads in the current task */
259 extern kern_return_t task_halt(
260 task_t task);
261
262 extern kern_return_t task_terminate_internal(
263 task_t task);
264
265 extern kern_return_t task_create_internal(
266 task_t parent_task,
267 boolean_t inherit_memory,
268 boolean_t is_64bit,
269 task_t *child_task); /* OUT */
270
271 extern kern_return_t task_importance(
272 task_t task,
273 integer_t importance);
274
275 extern void task_set_64bit(
276 task_t task,
277 boolean_t is64bit);
278
279 extern void task_backing_store_privileged(
280 task_t task);
281
282 extern void task_working_set_disable(
283 task_t task);
284
285
286 /* Get number of activations in a task */
287 extern int get_task_numacts(
288 task_t task);
289
290
291 /* JMM - should just be temporary (implementation in bsd_kern still) */
292 extern void set_bsdtask_info(task_t,void *);
293 extern vm_map_t get_task_map_reference(task_t);
294 extern vm_map_t swap_task_map(task_t, vm_map_t);
295 extern pmap_t get_task_pmap(task_t);
296
297 extern boolean_t is_kerneltask(task_t task);
298
299 #endif /* XNU_KERNEL_PRIVATE */
300
301 #ifdef KERNEL_PRIVATE
302
303 extern void *get_bsdtask_info(task_t);
304 extern vm_map_t get_task_map(task_t);
305
306 #endif /* KERNEL_PRIVATE */
307
308 extern task_t kernel_task;
309
310 extern void task_deallocate(
311 task_t task);
312
313 extern void task_name_deallocate(
314 task_name_t task_name);
315 __END_DECLS
316
317 #endif /* _KERN_TASK_H_ */