2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
26 * @OSF_FREE_COPYRIGHT@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
31 * All Rights Reserved.
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.
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.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
57 * Author: Avadis Tevanian, Jr.
59 * This file contains the structure definitions for tasks.
63 * Copyright (c) 1993 The University of Utah and
64 * the Computer Systems Laboratory (CSL). All rights reserved.
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.
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.
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.
84 #include <kern/kern_types.h>
85 #include <mach/mach_types.h>
88 #ifdef __APPLE_API_PRIVATE
90 #ifdef MACH_KERNEL_PRIVATE
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>
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 */
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 */
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 */
135 /* Threads in this task */
136 queue_head_t threads
;
138 int res_thread_count
;
139 int active_thread_count
;
141 processor_set_t processor_set
; /* processor set for new threads */
143 boolean_t may_assign
; /* can assigned pset be changed? */
144 boolean_t assign_active
; /* waiting for may_assign */
145 #endif /* MACH_HOST */
147 /* User-visible scheduling information */
148 integer_t user_stop_count
; /* outstanding stops */
152 integer_t priority
; /* base priority for threads */
153 integer_t max_priority
; /* maximum priority for threads */
155 /* Task security and audit tokens */
156 security_token_t sec_token
;
157 audit_token_t audit_token
;
160 time_value_t total_user_time
; /* user time for dead threads */
161 time_value_t total_system_time
; /* system time for dead threads */
164 boolean_t task_profiled
; /* is task being profiled ? */
165 struct prof_data
*profil_buffer
;/* profile struct if so */
166 #endif /* MACH_PROF */
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 */
179 struct ipc_space
*itk_space
;
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 */
187 /* User space system call emulation support */
188 struct eml_dispatch
*eml_dispatch
;
191 struct ipc_port
*wired_ledger_port
;
192 struct ipc_port
*paged_ledger_port
;
193 unsigned long priv_flags
; /* privelege resource flags */
196 long child_node
; /* if != -1, node for new children */
197 #endif /* NORMA_TASK */
199 vm_offset_t fast_tas_base
;
200 vm_offset_t fast_tas_end
;
201 #endif /* FAST_TAS */
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 */
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 */
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)
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)
230 #define task_reference_locked(task) ((task)->ref_count++)
233 * priv_flags definitions
235 #define VM_BACKING_STORE_PRIV 0x1
238 * Internal only routines
241 extern void task_backing_store_privileged(
244 /* Initialize task module */
245 extern void task_init(void);
248 extern kern_return_t
task_create_internal(
250 boolean_t inherit_memory
,
251 task_t
*child_task
); /* OUT */
253 extern void consider_task_collect(void);
255 #define current_task_fast() (current_act_fast()->task)
256 #define current_task() current_task_fast()
258 #endif /* MACH_KERNEL_PRIVATE */
260 extern task_t kernel_task
;
262 /* Temporarily hold all threads in a task */
263 extern kern_return_t
task_hold(
266 /* Release temporary hold on all threads in a task */
267 extern kern_return_t
task_release(
270 /* Get a task prepared for major changes */
271 extern kern_return_t
task_halt(
274 #if defined(MACH_KERNEL_PRIVATE) || defined(BSD_BUILD)
275 extern kern_return_t
task_importance(
277 integer_t importance
);
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
);
287 extern boolean_t
task_reference_try(task_t task
);
289 #endif /* __APPLE_API_PRIVATE */
291 #if !defined(MACH_KERNEL_PRIVATE)
293 extern task_t
current_task(void);
295 #endif /* MACH_KERNEL_TASK */
297 /* Take reference on task (make sure it doesn't go away) */
298 extern void task_reference(task_t task
);
300 /* Remove reference to task */
301 extern void task_deallocate(task_t task
);
303 #endif /* _KERN_TASK_H_ */