1 /* 2 * Copyright 1991-1998 by Open Software Foundation, Inc. 3 * All Rights Reserved 4 * 5 * Permission to use, copy, modify, and distribute this software and 6 * its documentation for any purpose and without fee is hereby granted, 7 * provided that the above copyright notice appears in all copies and 8 * that both the copyright notice and this permission notice appear in 9 * supporting documentation. 10 * 11 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE 12 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 13 * FOR A PARTICULAR PURPOSE. 14 * 15 * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR 16 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 17 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, 18 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 19 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 20 */ 21 /* 22 * MkLinux 23 */ 24 /* CMU_HIST */ 25 /* 26 * Revision 2.6.4.3 92/09/15 17:23:01 jeffreyh 27 * Cleanup for profiling, dont include profil.h 28 * [92/07/24 bernadat] 29 * 30 * Revision 2.6.4.2 92/05/27 00:46:27 jeffreyh 31 * Added mcmsg_task field to task in MCMSG ifdefs 32 * [regnier@ssd.intel.com] 33 * 34 * Revision 2.6.4.1 92/02/18 19:11:41 jeffreyh 35 * New fields for profiling 36 * (Bernard Tabib & Andrei Danes @ gr.osf.org) 37 * [91/09/16 bernadat] 38 * 39 * Revision 2.5.2.1 91/09/26 04:48:34 bernadat 40 * New fields for profiling 41 * (Bernard Tabib & Andrei Danes @ gr.osf.org) 42 * [91/09/16 bernadat] 43 * 44 * Revision 2.6 91/11/15 14:11:16 rpd 45 * NORMA_TASK: added child_node field, which determines where child tasks 46 * are created for the given task. A value of -1 means local node. 47 * [91/09/23 09:19:35 jsb] 48 * 49 * Revision 2.5 91/05/14 16:48:20 mrt 50 * Correcting copyright 51 * 52 * Revision 2.4 91/02/05 17:30:06 mrt 53 * Changed to new Mach copyright 54 * [91/02/01 16:19:18 mrt] 55 * 56 * Revision 2.3 90/06/02 14:56:48 rpd 57 * Removed kernel_vm_space, keep_wired. They are no longer needed. 58 * [90/04/29 rpd] 59 * Converted to new IPC. 60 * [90/03/26 22:23:06 rpd] 61 * 62 * Revision 2.2 89/09/08 11:26:47 dbg 63 * Add 'keep_wired' privilege field, to allow out-of-line data 64 * passed to task to remain wired. Needed for default pager. 65 * Remove kernel_vm_space (not used). 66 * [89/07/17 dbg] 67 * 68 * 19-Oct-88 David Golub (dbg) at Carnegie-Mellon University 69 * Removed all non-MACH data structures. 70 * 71 * Revision 2.6 88/09/25 22:16:41 rpd 72 * Changed port_cache fields/definitions to obj_cache. 73 * [88/09/24 18:13:13 rpd] 74 * 75 * Revision 2.5 88/08/24 02:46:30 mwyoung 76 * Adjusted include file references. 77 * [88/08/17 02:24:13 mwyoung] 78 * 79 * Revision 2.4 88/07/20 21:07:49 rpd 80 * Added ipc_task_lock/ipc_task_unlock definitions. 81 * Changes for port sets. 82 * Add ipc_next_name field, used for assigning local port names. 83 * 84 * Revision 2.3 88/07/17 18:56:33 mwyoung 85 * . 86 * 87 * Revision 2.2.2.1 88/06/28 20:02:03 mwyoung 88 * Cleaned up. Replaced task_t->kernel_only with 89 * task_t->kernel_ipc_space, task_t->kernel_vm_space, and 90 * task_t->ipc_privilege, to prevent overloading errors. 91 * 92 * Remove current_task() declaration. 93 * Eliminate paging_task. 94 * 95 * Revision 2.2.1.2 88/06/26 00:45:49 rpd 96 * Changes for port sets. 97 * 98 * Revision 2.2.1.1 88/06/23 23:32:38 rpd 99 * Add ipc_next_name field, used for assigning local port names. 100 * 101 * 21-Jun-88 Michael Young (mwyoung) at Carnegie-Mellon University 102 * Cleaned up. Replaced task_t->kernel_only with 103 * task_t->kernel_ipc_space, task_t->kernel_vm_space, and 104 * task_t->ipc_privilege, to prevent overloading errors. 105 * 106 * 19-Apr-88 Michael Young (mwyoung) at Carnegie-Mellon University 107 * Remove current_task() declaration. 108 * Eliminate paging_task. 109 * 110 * 18-Jan-88 David Golub (dbg) at Carnegie-Mellon University 111 * Removed task_data (now is per_thread). Added 112 * task_bootstrap_port. Added new routine declarations. 113 * Removed wake_active (unused). Added fields to accumulate 114 * user and system time for terminated threads. 115 * 116 * 19-Feb-88 Douglas Orr (dorr) at Carnegie-Mellon University 117 * Change emulation bit mask into vector of routine addrs 118 * 119 * 27-Jan-87 Douglas Orr (dorr) at Carnegie-Mellon University 120 * Add support for user space syscall emulation (bit mask 121 * of enabled user space syscalls and user space emulation 122 * routine). 123 * 124 * 3-Dec-87 Michael Young (mwyoung) at Carnegie-Mellon University 125 * Change port cache account for per-task port names. 126 * Should move IPC stuff to a separate file :-). 127 * Add reply port for use by kernel-internal tasks. 128 * 129 * 2-Dec-87 David Black (dlb) at Carnegie-Mellon University 130 * Added active field. 131 * 132 * 18-Nov-87 Avadis Tevanian (avie) at Carnegie-Mellon University 133 * Eliminate conditionals, flush history. 134 */ 135 /* CMU_ENDHIST */ 136 /* 137 * Mach Operating System 138 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University 139 * All Rights Reserved. 140 * 141 * Permission to use, copy, modify and distribute this software and its 142 * documentation is hereby granted, provided that both the copyright 143 * notice and this permission notice appear in all copies of the 144 * software, derivative works or modified versions, and any portions 145 * thereof, and that both notices appear in supporting documentation. 146 * 147 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 148 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 149 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 150 * 151 * Carnegie Mellon requests users of this software to return to 152 * 153 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 154 * School of Computer Science 155 * Carnegie Mellon University 156 * Pittsburgh PA 15213-3890 157 * 158 * any improvements or extensions that they make and grant Carnegie Mellon 159 * the rights to redistribute these changes. 160 */ 161 /* 162 */ 163 /* 164 * File: task.h 165 * Author: Avadis Tevanian, Jr. 166 * 167 * This file contains the structure definitions for tasks. 168 * 169 */ 170 /* 171 * Copyright (c) 1993 The University of Utah and 172 * the Computer Systems Laboratory (CSL). All rights reserved. 173 * 174 * Permission to use, copy, modify and distribute this software and its 175 * documentation is hereby granted, provided that both the copyright 176 * notice and this permission notice appear in all copies of the 177 * software, derivative works or modified versions, and any portions 178 * thereof, and that both notices appear in supporting documentation. 179 * 180 * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS 181 * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF 182 * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 183 * 184 * CSL requests users of this software to return to csl-dist@cs.utah.edu any 185 * improvements that they make and grant CSL redistribution rights. 186 * 187 */ 188 189 #ifndef _KERN_TASK_H_ 190 #define _KERN_TASK_H_ 191 #if 0 192 #include <mach_host.h> 193 #include <fast_tas.h> 194 #include <task_swapper.h> 195 #endif 196 #include <sys/cdefs.h> 197 #include <sys/types.h> 198 #include <sys/param.h> 199 #include <sys/lock.h> 200 #include <sys/mutex.h> 201 202 #include <sys/mach/port.h> 203 #include <sys/mach/time_value.h> 204 #include <sys/mach/message.h> 205 206 #if 0 207 #include <sys/mach/mach_param.h> 208 #endif 209 #include <sys/mach/task_info.h> 210 #include <sys/mach/exception.h> 211 212 #include <compat/mach/kern_types.h> 213 214 #if 0 215 #include <mach_prof.h> 216 #include <kern/lock.h> 217 #include <kern/syscall_emulation.h> 218 #include <vm/vm_map.h> 219 #endif 220 #include <sys/mach/queue.h> 221 222 #define MACH_HOST 1 223 #define MACH_PROF 0 224 #define NORMA_TASK 0 225 #define FAST_TAS 0 226 #define TASK_SWAPPER 0 227 228 #include <sys/mach/mach_types.h> 229 #include <sys/mach/mach_param.h> 230 231 232 extern ipc_port_t convert_task_to_port(task_t); 233 extern ipc_port_t convert_task_name_to_port(task_name_t); 234 extern ipc_port_t convert_task_suspension_token_to_port(task_suspension_token_t task); 235 236 /* Convert from a port (in this case, an SO right to a task's resume port) to a task. */ 237 extern task_suspension_token_t convert_port_to_task_suspension_token(ipc_port_t port); 238 239 240 typedef struct mach_task { 241 /* Synchronization/destruction information */ 242 decl_mutex_data(,lock) /* Task's lock */ 243 int ref_count; /* Number of references to me */ 244 boolean_t active; /* Task has not been terminated */ 245 boolean_t kernel_loaded; /* Created with kernel_task_create() */ 246 247 struct ipc_space *itk_space; 248 uint64_t itk_uniqueid; 249 uint64_t itk_puniqueid; 250 decl_mutex_data(,itk_lock_data) 251 252 /* IPC structures */ 253 struct exception_action exc_actions[EXC_TYPES_COUNT]; 254 /* a send right each valid element */ 255 struct ipc_port *itk_self; /* not a right, doesn't hold ref */ 256 struct ipc_port *itk_nself; /* not a right, doesn't hold ref */ 257 struct ipc_port *itk_sself; /* a send right */ 258 struct ipc_port *itk_host; /* a send right */ 259 struct ipc_port *itk_bootstrap; /* a send right */ 260 struct ipc_port *itk_seatbelt; /* a send right */ 261 struct ipc_port *itk_gssd; /* yet another send right */ 262 struct ipc_port *itk_debug_control; /* send right for debugmode communications */ 263 struct ipc_port *itk_task_access; /* and another send right */ 264 struct ipc_port *itk_resume; /* a receive right to resume this task */ 265 struct ipc_port *itk_registered[TASK_PORT_REGISTER_MAX]; 266 /* all send rights */ 267 268 /* Ledgers */ 269 struct proc *itk_p; 270 271 /* Active activations in this task */ 272 int thr_act_count; 273 int res_act_count; 274 struct mtx act_list_lock; /* XXX act_list lock */ 275 int priority; /* for new threads */ 276 int max_priority; /* maximum priority */ 277 int sched_data; /* for use by policy */ 278 int policy; /* scheduling policy */ 279 processor_set_t processor_set; /* processor set for new threads */ 280 281 /* Task security token */ 282 security_token_t sec_token; 283 audit_token_t audit_token; 284 /* Synchronizer ownership information */ 285 queue_head_t semaphore_list; /* list of owned semaphores */ 286 int semaphores_owned; /* number of semaphores owned */ 287 288 int messages_received; 289 290 #ifdef notyet /* Active activations in this task */ 291 queue_head_t thr_acts; /* list of thread_activations */ 292 int thr_act_count; 293 queue_head_t thr_acts; /* list of thread_activations */ 294 int res_act_count; 295 mutex_t act_list_lock; /* XXX act_list lock */ 296 297 298 /* Miscellaneous */ 299 vm_map_t map; /* Address space description */ 300 queue_chain_t pset_tasks; /* list of tasks assigned to pset */ 301 void *user_data; /* Arbitrary data settable via IPC */ 302 int suspend_count; /* Internal scheduling only */ 303 304 /* User-visible scheduling information */ 305 int user_stop_count; /* outstanding stops */ 306 307 /* Statistics */ 308 time_value_t total_user_time; 309 /* total user time for dead threads */ 310 time_value_t total_system_time; 311 /* total system time for dead threads */ 312 313 /* RPC subsystem information */ 314 queue_head_t subsystem_list; /* list of subsystems */ 315 int subsystem_count;/* number of subsystems */ 316 317 queue_head_t lock_set_list; /* list of owned lock sets */ 318 int lock_sets_owned; /* number of lock sets owned */ 319 320 /* User space system call emulation support */ 321 struct eml_dispatch *eml_dispatch; 322 323 MACHINE_TASK 324 #endif 325 } Task; 326 327 #define TASK_NULL ((task_t) 0) 328 329 typedef mach_port_t *task_array_t; 330 typedef mach_port_t *task_port_array_t; 331 332 #define task_lock(task) mtx_lock(&(task)->lock) 333 #define task_lock_try(task) mtx_trylock(&(task)->lock) 334 #define task_unlock(task) mtx_unlock(&(task)->lock) 335 336 #define itk_lock_init(task) mach_mutex_init(&(task)->itk_lock_data, \ 337 "ETAP_THREAD_TASK_ITK") 338 #define itk_lock(task) mtx_lock(&(task)->itk_lock_data) 339 #define itk_unlock(task) mtx_unlock(&(task)->itk_lock_data) 340 341 /* 342 * Internal only routines 343 */ 344 345 /* Initialize task module */ 346 extern void task_init(void); 347 348 /* task create */ 349 extern kern_return_t task_create_local( 350 task_t parent_task, 351 boolean_t inherit_memory, 352 boolean_t kernel_loaded, 353 task_t *child_task); /* OUT */ 354 355 /* Take reference on task (make sure it doesn't go away) */ 356 extern void task_reference( 357 task_t task); 358 359 /* Remove reference to task */ 360 extern void task_deallocate( 361 task_t task); 362 363 /* Set tasks max priority (does not affect threads within task) */ 364 extern kern_return_t task_max_priority( 365 task_t task, 366 processor_set_t pset, 367 int max_priority); 368 369 #if MACH_HOST 370 /* Freeze and unfreeze task from being reassigned processor sets */ 371 extern void task_freeze( 372 task_t task); 373 374 extern void task_unfreeze( 375 task_t task); 376 #endif /* MACH_HOST */ 377 378 extern void consider_task_collect(void); 379 380 extern task_t kernel_task; 381 382 #endif /* _KERN_TASK_H_ */ 383