2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 * @OSF_FREE_COPYRIGHT@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
28 * All Rights Reserved.
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.
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.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
54 * Author: Avadis Tevanian, Jr.
56 * This file contains the structure definitions for tasks.
60 * Copyright (c) 1993 The University of Utah and
61 * the Computer Systems Laboratory (CSL). All rights reserved.
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.
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.
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.
81 #include <kern/kern_types.h>
82 #include <mach/mach_types.h>
83 #include <sys/cdefs.h>
85 #ifdef MACH_KERNEL_PRIVATE
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>
95 #include <kern/cpu_data.h>
96 #include <kern/queue.h>
97 #include <kern/exception.h>
98 #include <kern/lock.h>
99 #include <kern/thread.h>
101 #include <mach_host.h>
102 #include <mach_prof.h>
105 /* Synchronization/destruction information */
106 decl_mutex_data(,lock
) /* Task's lock */
107 int ref_count
; /* Number of references to me */
108 boolean_t active
; /* Task has not been terminated */
111 vm_map_t map
; /* Address space description */
112 queue_chain_t pset_tasks
; /* list of tasks assigned to pset */
113 void *user_data
; /* Arbitrary data settable via IPC */
114 int suspend_count
; /* Internal scheduling only */
116 /* Threads in this task */
117 queue_head_t threads
;
119 int active_thread_count
;
121 processor_set_t processor_set
; /* processor set for new threads */
123 boolean_t may_assign
; /* can assigned pset be changed? */
124 boolean_t assign_active
; /* waiting for may_assign */
125 #endif /* MACH_HOST */
127 /* User-visible scheduling information */
128 integer_t user_stop_count
; /* outstanding stops */
132 integer_t priority
; /* base priority for threads */
133 integer_t max_priority
; /* maximum priority for threads */
135 /* Task security and audit tokens */
136 security_token_t sec_token
;
137 audit_token_t audit_token
;
140 uint64_t total_user_time
; /* terminated threads only */
141 uint64_t total_system_time
;
144 boolean_t task_profiled
; /* is task being profiled ? */
145 struct prof_data
*profil_buffer
;/* profile struct if so */
146 #endif /* MACH_PROF */
149 decl_mutex_data(,itk_lock_data
)
150 struct ipc_port
*itk_self
; /* not a right, doesn't hold ref */
151 struct ipc_port
*itk_sself
; /* a send right */
152 struct exception_action exc_actions
[EXC_TYPES_COUNT
];
153 /* a send right each valid element */
154 struct ipc_port
*itk_host
; /* a send right */
155 struct ipc_port
*itk_bootstrap
; /* a send right */
156 struct ipc_port
*itk_registered
[TASK_PORT_REGISTER_MAX
];
157 /* all send rights */
159 struct ipc_space
*itk_space
;
161 /* Synchronizer ownership information */
162 queue_head_t semaphore_list
; /* list of owned semaphores */
163 queue_head_t lock_set_list
; /* list of owned lock sets */
164 int semaphores_owned
; /* number of semaphores owned */
165 int lock_sets_owned
; /* number of lock sets owned */
168 struct ipc_port
*wired_ledger_port
;
169 struct ipc_port
*paged_ledger_port
;
170 unsigned int priv_flags
; /* privilege resource flags */
171 #define VM_BACKING_STORE_PRIV 0x1
173 integer_t faults
; /* faults counter */
174 integer_t pageins
; /* pageins counter */
175 integer_t cow_faults
; /* copy on write fault counter */
176 integer_t messages_sent
; /* messages sent counter */
177 integer_t messages_received
; /* messages received counter */
178 integer_t syscalls_mach
; /* mach system call counter */
179 integer_t syscalls_unix
; /* unix system call counter */
180 integer_t csw
; /* context switch counter */
184 struct shared_region_mapping
*system_shared_region
;
185 struct tws_hash
*dynamic_working_set
;
186 uint32_t taskFeatures
[2]; /* Special feature for this task */
187 #define tf64BitAddr 0x80000000 /* Task has 64-bit addressing */
188 #define tf64BitData 0x40000000 /* Task has 64-bit data registers */
189 #define task_has_64BitAddr(task) \
190 (((task)->taskFeatures[0] & tf64BitAddr) != 0)
191 #define task_set_64BitAddr(task) \
192 ((task)->taskFeatures[0] |= tf64BitAddr)
193 #define task_clear_64BitAddr(task) \
194 ((task)->taskFeatures[0] &= ~tf64BitAddr)
198 #define task_lock(task) mutex_lock(&(task)->lock)
199 #define task_lock_try(task) mutex_try(&(task)->lock)
200 #define task_unlock(task) mutex_unlock(&(task)->lock)
202 #define itk_lock_init(task) mutex_init(&(task)->itk_lock_data, 0)
203 #define itk_lock(task) mutex_lock(&(task)->itk_lock_data)
204 #define itk_unlock(task) mutex_unlock(&(task)->itk_lock_data)
206 #define task_reference_internal(task) \
207 hw_atomic_add(&(task)->ref_count, 1)
209 #define task_deallocate_internal(task) \
210 hw_atomic_sub(&(task)->ref_count, 1)
212 #define task_reference(task) \
214 if ((task) != TASK_NULL) \
215 task_reference_internal(task); \
218 extern kern_return_t
kernel_task_create(
220 vm_offset_t map_base
,
224 /* Initialize task module */
225 extern void task_init(void);
227 #define current_task_fast() (current_thread()->task)
228 #define current_task() current_task_fast()
230 #else /* MACH_KERNEL_PRIVATE */
234 extern task_t
current_task(void);
236 extern void task_reference(task_t task
);
240 #endif /* MACH_KERNEL_PRIVATE */
244 #ifdef XNU_KERNEL_PRIVATE
246 /* Hold all threads in a task */
247 extern kern_return_t
task_hold(
250 /* Release hold on all threads in a task */
251 extern kern_return_t
task_release(
254 /* Halt all other threads in the current task */
255 extern kern_return_t
task_halt(
258 extern kern_return_t
task_terminate_internal(
261 extern kern_return_t
task_create_internal(
263 boolean_t inherit_memory
,
264 task_t
*child_task
); /* OUT */
266 extern kern_return_t
task_importance(
268 integer_t importance
);
270 extern void task_set_64bit(
274 extern void task_backing_store_privileged(
277 extern void task_working_set_disable(
280 /* Get number of activations in a task */
281 extern int get_task_numacts(
285 /* JMM - should just be temporary (implementation in bsd_kern still) */
286 extern void set_bsdtask_info(task_t
,void *);
287 extern vm_map_t
get_task_map_reference(task_t
);
288 extern vm_map_t
swap_task_map(task_t
, vm_map_t
);
289 extern pmap_t
get_task_pmap(task_t
);
291 extern boolean_t
is_kerneltask(task_t task
);
293 #endif /* XNU_KERNEL_PRIVATE */
295 #ifdef KERNEL_PRIVATE
297 extern void *get_bsdtask_info(task_t
);
298 extern vm_map_t
get_task_map(task_t
);
300 #endif /* KERNEL_PRIVATE */
302 extern task_t kernel_task
;
304 extern void task_deallocate(
309 #endif /* _KERN_TASK_H_ */