Annotation of XNU/osfmk/kern/task.h, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 2000 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  [email protected]
                     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 [email protected] 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 <vm/pmap.h>
                     84: 
                     85: #ifdef MACH_KERNEL_PRIVATE
                     86: #include <mach/boolean.h>
                     87: #include <mach/port.h>
                     88: #include <mach/time_value.h>
                     89: #include <mach/message.h>
                     90: #include <mach/mach_param.h>
                     91: #include <mach/task_info.h>
                     92: #include <mach/exception_types.h>
                     93: #include <mach_prof.h>
                     94: #include <machine/task.h>
                     95: #include <kern/queue.h>
                     96: #include <kern/lock.h>
                     97: #include <kern/syscall_emulation.h>
                     98: #include <norma_task.h>
                     99: #include <mach_host.h>
                    100: #include <fast_tas.h>
                    101: #include <task_swapper.h>
                    102: #include <kern/thread_act.h>
                    103: 
                    104: typedef struct task {
                    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 */
                    109:        boolean_t       kernel_loaded;  /* Created with kernel_task_create() */
                    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: #if    TASK_SWAPPER
                    118:        /* Task swapper data */
                    119:        unsigned short  swap_state;     /* swap state (e.g. IN/OUT) */
                    120:        unsigned short  swap_flags;     /* swap flags (e.g. MAKE_UNSWAPP) */
                    121:        unsigned int    swap_stamp;     /* when last swapped */
                    122:        unsigned long   swap_rss;       /* size (pages) when last swapped */
                    123:        int             swap_ast_waiting; /* number of threads that have not */
                    124:                                          /* reached a clean point and halted */
                    125:        int             swap_nswap;     /* number of times this task swapped */
                    126:        queue_chain_t   swapped_tasks;  /* list of non-resident tasks */
                    127: #endif /* TASK_SWAPPER */
                    128: 
                    129:        /* Active activations in this task */
                    130:        int             thr_act_count;
                    131:        queue_head_t    thr_acts;       /* list of thread_activations */
                    132:        int             res_act_count;
                    133:        mutex_t         act_list_lock;  /* XXX act_list lock */
                    134: 
                    135:        processor_set_t processor_set;  /* processor set for new threads */
                    136: #if    MACH_HOST
                    137:        boolean_t       may_assign;     /* can assigned pset be changed? */
                    138:        boolean_t       assign_active;  /* waiting for may_assign */
                    139: #endif /* MACH_HOST */
                    140: 
                    141:        /* User-visible scheduling information */
                    142:        int             user_stop_count;        /* outstanding stops */
                    143:                /*** ??? should `user_stop_count' be moved, too? ***/
                    144:        int             policy;                 /* scheduling policy */
                    145:        sp_attributes_t sp_attributes;          /* ptr to sched parameters */
                    146: 
                    147:         /* Task security token */
                    148:         security_token_t sec_token;
                    149:         
                    150:        /* Statistics */
                    151:        time_value_t    total_user_time;
                    152:                                /* total user time for dead threads */
                    153:        time_value_t    total_system_time;
                    154:                                /* total system time for dead threads */
                    155: 
                    156: #if    MACH_PROF
                    157:        boolean_t       task_profiled;  /* is task being profiled ? */
                    158:        struct prof_data *profil_buffer;/* profile struct if so */
                    159: #endif /* MACH_PROF */
                    160: 
                    161:        /* IPC structures */
                    162:        decl_mutex_data(,itk_lock_data)
                    163:        struct ipc_port *itk_self;      /* not a right, doesn't hold ref */
                    164:        struct ipc_port *itk_sself;     /* a send right */
                    165:        struct exception_action exc_actions[EXC_TYPES_COUNT];
                    166:                                        /* a send right each valid element  */
                    167:        struct ipc_port *itk_bootstrap; /* a send right */
                    168:        struct ipc_port *itk_registered[TASK_PORT_REGISTER_MAX];
                    169:                                        /* all send rights */
                    170: 
                    171:        struct ipc_space *itk_space;
                    172: 
                    173:        /* RPC subsystem information */
                    174:        queue_head_t    subsystem_list; /* list of subsystems */
                    175:        int             subsystem_count;/* number of subsystems */
                    176: 
                    177:        /* Synchronizer ownership information */
                    178:        queue_head_t    semaphore_list;         /* list of owned semaphores   */
                    179:        queue_head_t    lock_set_list;          /* list of owned lock sets    */
                    180:        int             semaphores_owned;       /* number of semaphores owned */
                    181:        int             lock_sets_owned;        /* number of lock sets owned  */
                    182: 
                    183:        /* User space system call emulation support */
                    184:        struct  eml_dispatch    *eml_dispatch;
                    185: 
                    186:         /* Ledgers */
                    187:        struct ipc_port *wired_ledger_port;
                    188:        struct ipc_port *paged_ledger_port;
                    189:         
                    190: #if    NORMA_TASK
                    191:        long            child_node;     /* if != -1, node for new children */
                    192: #endif /* NORMA_TASK */
                    193: #if    FAST_TAS
                    194:        vm_offset_t     fast_tas_base;
                    195:        vm_offset_t     fast_tas_end;
                    196: #endif /* FAST_TAS */
                    197:        MACHINE_TASK
                    198:        integer_t faults;              /* faults counter */
                    199:         integer_t pageins;             /* pageins counter */
                    200:         integer_t cow_faults;          /* copy on write fault counter */
                    201:         integer_t messages_sent;       /* messages sent counter */
                    202:         integer_t messages_received;   /* messages received counter */
                    203:         integer_t syscalls_mach;       /* mach system call counter */
                    204:         integer_t syscalls_unix;       /* unix system call counter */
                    205:         integer_t csw;                 /* context switch counter */
                    206: #ifdef  MACH_BSD 
                    207:        void *bsd_info;
                    208: #endif  
                    209: } Task;
                    210: 
                    211: 
                    212: #define task_lock(task)                mutex_lock(&(task)->lock)
                    213: #define task_lock_try(task)    mutex_try(&(task)->lock)
                    214: #define task_unlock(task)      mutex_unlock(&(task)->lock)
                    215: 
                    216: #define        itk_lock_init(task)     mutex_init(&(task)->itk_lock_data, \
                    217:                                           ETAP_THREAD_TASK_ITK)
                    218: #define        itk_lock(task)          mutex_lock(&(task)->itk_lock_data)
                    219: #define        itk_unlock(task)        mutex_unlock(&(task)->itk_lock_data)
                    220: 
                    221: /*
                    222:  *     Internal only routines
                    223:  */
                    224: 
                    225: /* Initialize task module */
                    226: extern void            task_init(void);
                    227: 
                    228: /* task create */
                    229: extern kern_return_t   task_create_local(
                    230:                                task_t          parent_task,
                    231:                                boolean_t       inherit_memory,
                    232:                                boolean_t       kernel_loaded,
                    233:                                task_t          *child_task);   /* OUT */
                    234: 
                    235: /* Set tasks max priority (does not affect threads within task) */
                    236: extern kern_return_t   task_max_priority(
                    237:                                task_t          task,
                    238:                                processor_set_t pset,
                    239:                                int             max_priority);
                    240: 
                    241: #if    MACH_HOST
                    242: /* Freeze and unfreeze task from being reassigned processor sets */
                    243: extern void            task_freeze(
                    244:                                task_t          task);
                    245: 
                    246: extern void            task_unfreeze(
                    247:                                task_t          task);
                    248: #endif /* MACH_HOST */
                    249: 
                    250: extern void            consider_task_collect(void);
                    251: 
                    252: #define        current_task_fast()     (current_act_fast()->task)
                    253: #define current_task()         current_task_fast()
                    254: 
                    255: #else /* !MACH_KERNEL_PRIVATE */
                    256: 
                    257: extern task_t current_task(void);
                    258: 
                    259: #endif /* !MACH_KERNEL_PRIVATE */
                    260: 
                    261: extern task_t          kernel_task;
                    262: extern boolean_t       is_kerneltask(task_t);
                    263: 
                    264: /* Stop all other threads in a task */
                    265: extern kern_return_t   task_halt(
                    266:                                task_t  task);
                    267: 
                    268: /* Take reference on task (make sure it doesn't go away) */
                    269: extern void            task_reference(task_t   task);
                    270: 
                    271: /* Remove reference to task */
                    272: extern void            task_deallocate(task_t  task);
                    273: 
                    274: /* JMM - should just be temporary (implementation in bsd_kern still) */
                    275: extern void    *get_bsdtask_info(task_t);
                    276: extern void    set_bsdtask_info(task_t,void *);
                    277: extern vm_map_t get_task_map(task_t);
                    278: extern void    set_task_map(task_t, vm_map_t);
                    279: extern pmap_t  get_task_pmap(task_t);
                    280: #endif /* _KERN_TASK_H_ */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.