2 * Copyright (c) 2000 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>
85 #ifdef __APPLE_API_PRIVATE
87 #ifdef MACH_KERNEL_PRIVATE
89 #include <mach/boolean.h>
90 #include <mach/port.h>
91 #include <mach/time_value.h>
92 #include <mach/message.h>
93 #include <mach/mach_param.h>
94 #include <mach/task_info.h>
95 #include <mach/exception_types.h>
96 #include <mach_prof.h>
97 #include <machine/task.h>
98 #include <kern/queue.h>
99 #include <kern/exception.h>
100 #include <kern/lock.h>
101 #include <kern/syscall_emulation.h>
102 #include <norma_task.h>
103 #include <mach_host.h>
104 #include <fast_tas.h>
105 #include <task_swapper.h>
106 #include <kern/thread_act.h>
108 typedef struct task
{
109 /* Synchronization/destruction information */
110 decl_mutex_data(,lock
) /* Task's lock */
111 int ref_count
; /* Number of references to me */
112 boolean_t active
; /* Task has not been terminated */
115 vm_map_t map
; /* Address space description */
116 queue_chain_t pset_tasks
; /* list of tasks assigned to pset */
117 void *user_data
; /* Arbitrary data settable via IPC */
118 int suspend_count
; /* Internal scheduling only */
121 /* Task swapper data */
122 unsigned short swap_state
; /* swap state (e.g. IN/OUT) */
123 unsigned short swap_flags
; /* swap flags (e.g. MAKE_UNSWAPP) */
124 unsigned int swap_stamp
; /* when last swapped */
125 unsigned long swap_rss
; /* size (pages) when last swapped */
126 int swap_ast_waiting
; /* number of threads that have not */
127 /* reached a clean point and halted */
128 int swap_nswap
; /* number of times this task swapped */
129 queue_chain_t swapped_tasks
; /* list of non-resident tasks */
130 #endif /* TASK_SWAPPER */
132 /* Threads in this task */
133 queue_head_t threads
;
135 int res_thread_count
;
136 int active_thread_count
;
138 processor_set_t processor_set
; /* processor set for new threads */
140 boolean_t may_assign
; /* can assigned pset be changed? */
141 boolean_t assign_active
; /* waiting for may_assign */
142 #endif /* MACH_HOST */
144 /* User-visible scheduling information */
145 integer_t user_stop_count
; /* outstanding stops */
149 integer_t priority
; /* base priority for threads */
150 integer_t max_priority
; /* maximum priority for threads */
152 /* Task security and audit tokens */
153 security_token_t sec_token
;
154 audit_token_t audit_token
;
157 time_value_t total_user_time
; /* user time for dead threads */
158 time_value_t total_system_time
; /* system time for dead threads */
161 boolean_t task_profiled
; /* is task being profiled ? */
162 struct prof_data
*profil_buffer
;/* profile struct if so */
163 #endif /* MACH_PROF */
166 decl_mutex_data(,itk_lock_data
)
167 struct ipc_port
*itk_self
; /* not a right, doesn't hold ref */
168 struct ipc_port
*itk_sself
; /* a send right */
169 struct exception_action exc_actions
[EXC_TYPES_COUNT
];
170 /* a send right each valid element */
171 struct ipc_port
*itk_host
; /* a send right */
172 struct ipc_port
*itk_bootstrap
; /* a send right */
173 struct ipc_port
*itk_registered
[TASK_PORT_REGISTER_MAX
];
174 /* all send rights */
176 struct ipc_space
*itk_space
;
178 /* Synchronizer ownership information */
179 queue_head_t semaphore_list
; /* list of owned semaphores */
180 queue_head_t lock_set_list
; /* list of owned lock sets */
181 int semaphores_owned
; /* number of semaphores owned */
182 int lock_sets_owned
; /* number of lock sets owned */
184 /* User space system call emulation support */
185 struct eml_dispatch
*eml_dispatch
;
188 struct ipc_port
*wired_ledger_port
;
189 struct ipc_port
*paged_ledger_port
;
190 unsigned long priv_flags
; /* privelege resource flags */
193 long child_node
; /* if != -1, node for new children */
194 #endif /* NORMA_TASK */
196 vm_offset_t fast_tas_base
;
197 vm_offset_t fast_tas_end
;
198 #endif /* FAST_TAS */
200 integer_t faults
; /* faults counter */
201 integer_t pageins
; /* pageins counter */
202 integer_t cow_faults
; /* copy on write fault counter */
203 integer_t messages_sent
; /* messages sent counter */
204 integer_t messages_received
; /* messages received counter */
205 integer_t syscalls_mach
; /* mach system call counter */
206 integer_t syscalls_unix
; /* unix system call counter */
207 integer_t csw
; /* context switch counter */
211 vm_offset_t system_shared_region
;
212 vm_offset_t dynamic_working_set
;
213 uint32_t taskFeatures
[2]; /* Special feature for this task */
214 #define tf64BitAddr 0x80000000 /* Task has 64-bit addressing */
215 #define tf64BitData 0x40000000 /* Task has 64-bit data registers */
218 #define task_lock(task) mutex_lock(&(task)->lock)
219 #define task_lock_try(task) mutex_try(&(task)->lock)
220 #define task_unlock(task) mutex_unlock(&(task)->lock)
222 #define itk_lock_init(task) mutex_init(&(task)->itk_lock_data, \
223 ETAP_THREAD_TASK_ITK)
224 #define itk_lock(task) mutex_lock(&(task)->itk_lock_data)
225 #define itk_unlock(task) mutex_unlock(&(task)->itk_lock_data)
227 #define task_reference_locked(task) ((task)->ref_count++)
230 * priv_flags definitions
232 #define VM_BACKING_STORE_PRIV 0x1
235 * Internal only routines
238 extern void task_backing_store_privileged(
241 /* Initialize task module */
242 extern void task_init(void);
245 extern kern_return_t
task_create_internal(
247 boolean_t inherit_memory
,
248 task_t
*child_task
); /* OUT */
250 extern void consider_task_collect(void);
252 #define current_task_fast() (current_act_fast()->task)
253 #define current_task() current_task_fast()
255 #endif /* MACH_KERNEL_PRIVATE */
257 extern task_t kernel_task
;
259 /* Temporarily hold all threads in a task */
260 extern kern_return_t
task_hold(
263 /* Release temporary hold on all threads in a task */
264 extern kern_return_t
task_release(
267 /* Get a task prepared for major changes */
268 extern kern_return_t
task_halt(
271 #if defined(MACH_KERNEL_PRIVATE) || defined(BSD_BUILD)
272 extern kern_return_t
task_importance(
274 integer_t importance
);
277 /* JMM - should just be temporary (implementation in bsd_kern still) */
278 extern void *get_bsdtask_info(task_t
);
279 extern void set_bsdtask_info(task_t
,void *);
280 extern vm_map_t
get_task_map(task_t
);
281 extern vm_map_t
swap_task_map(task_t
, vm_map_t
);
282 extern pmap_t
get_task_pmap(task_t
);
284 extern boolean_t
task_reference_try(task_t task
);
286 #endif /* __APPLE_API_PRIVATE */
288 #if !defined(MACH_KERNEL_PRIVATE)
290 extern task_t
current_task(void);
292 #endif /* MACH_KERNEL_TASK */
294 /* Take reference on task (make sure it doesn't go away) */
295 extern void task_reference(task_t task
);
297 /* Remove reference to task */
298 extern void task_deallocate(task_t task
);
300 #endif /* _KERN_TASK_H_ */