[1] | 1 | /* |
---|
| 2 | * process.h - process related management functions |
---|
[173] | 3 | * |
---|
[1] | 4 | * Authors Ghassan Almaless (2008,2009,2010,2011,2012) |
---|
| 5 | * Mohamed Lamine Karaoui (2015) |
---|
[433] | 6 | * Alain Greiner (2016,2017,2018) |
---|
[1] | 7 | * |
---|
| 8 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 9 | * |
---|
| 10 | * This file is part of ALMOS-MKH. |
---|
| 11 | * |
---|
| 12 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 13 | * under the terms of the GNU General Public License as published by |
---|
| 14 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 15 | * |
---|
| 16 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 19 | * General Public License for more details. |
---|
| 20 | * |
---|
| 21 | * You should have received a copy of the GNU General Public License |
---|
| 22 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 23 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #ifndef _PROCESS_H_ |
---|
| 27 | #define _PROCESS_H_ |
---|
| 28 | |
---|
[14] | 29 | #include <kernel_config.h> |
---|
[1] | 30 | #include <errno.h> |
---|
| 31 | #include <hal_types.h> |
---|
| 32 | #include <list.h> |
---|
| 33 | #include <xlist.h> |
---|
| 34 | #include <bits.h> |
---|
| 35 | #include <spinlock.h> |
---|
| 36 | #include <hal_atomic.h> |
---|
| 37 | #include <vmm.h> |
---|
| 38 | #include <cluster.h> |
---|
| 39 | #include <vfs.h> |
---|
| 40 | |
---|
| 41 | /**** Forward declarations ****/ |
---|
| 42 | |
---|
| 43 | struct thread_s; |
---|
| 44 | |
---|
| 45 | /********************************************************************************************* |
---|
| 46 | * These macros are used to compose or decompose global process identifier (PID) |
---|
| 47 | * to or from cluster identifier / local process index (CXY , LPID) |
---|
| 48 | ********************************************************************************************/ |
---|
| 49 | |
---|
| 50 | #define LPID_FROM_PID( pid ) (lpid_t)(pid & 0x0000FFFF) |
---|
| 51 | #define CXY_FROM_PID( pid ) (cxy_t)(pid >> 16) |
---|
| 52 | #define PID( cxy , lpid ) (pid_t)((cxy << 16) | lpid ) |
---|
| 53 | |
---|
| 54 | /********************************************************************************************* |
---|
[428] | 55 | * This enum defines the actions that can be executed by the process_sigaction() function. |
---|
[409] | 56 | ********************************************************************************************/ |
---|
| 57 | |
---|
| 58 | enum process_sigactions |
---|
| 59 | { |
---|
[436] | 60 | BLOCK_ALL_THREADS = 0x11, |
---|
| 61 | UNBLOCK_ALL_THREADS = 0x22, |
---|
| 62 | DELETE_ALL_THREADS = 0x33, |
---|
[409] | 63 | }; |
---|
| 64 | |
---|
| 65 | /********************************************************************************************* |
---|
[1] | 66 | * This structure defines an array of extended pointers on the open file descriptors |
---|
| 67 | * for a given process. We use an extended pointer because the open file descriptor |
---|
| 68 | * is always stored in the same cluster as the inode associated to the file. |
---|
| 69 | * A free entry in this array contains the XPTR_NULL value. |
---|
| 70 | * The array size is defined by a the CONFIG_PROCESS_FILE_MAX_NR parameter. |
---|
[23] | 71 | * All modifications (open/close) in this structure must be done by the reference cluster, |
---|
| 72 | * and reported in process copies. |
---|
[1] | 73 | ********************************************************************************************/ |
---|
| 74 | |
---|
| 75 | typedef struct fd_array_s |
---|
| 76 | { |
---|
[101] | 77 | remote_spinlock_t lock; /*! lock protecting fd_array */ |
---|
| 78 | uint32_t current; /*! current number of open files */ |
---|
| 79 | xptr_t array[CONFIG_PROCESS_FILE_MAX_NR]; /*! xptr on open file descriptors */ |
---|
[1] | 80 | } |
---|
| 81 | fd_array_t; |
---|
| 82 | |
---|
| 83 | /********************************************************************************************* |
---|
| 84 | * This structure defines a process descriptor. |
---|
| 85 | * A process is identified by a unique PID (process identifier): |
---|
| 86 | * - The PID 16 LSB bits contain the LPID (Local Process Index) |
---|
| 87 | * - The PID 16 MSB bits contain the owner cluster CXY. |
---|
[409] | 88 | * In each cluster, the process manager allocates the LPID values for the process that |
---|
| 89 | * are owned by this cluster. |
---|
| 90 | * The process descriptor is replicated in all clusters containing at least one thread |
---|
| 91 | * of the PID process, with the following rules : |
---|
[23] | 92 | * 1) The <pid>, <ppid>, <ref_xp>, <vfs_root_xp>, <vfs_bin_xp> fields are defined |
---|
| 93 | * in all process descriptor copies. |
---|
| 94 | * 2) The <vfs_cwd_xp> and associated <cwd_lock>, that can be dynamically modified, |
---|
| 95 | * are only defined in the reference process descriptor. |
---|
[409] | 96 | * 2) The <vmm>, containing the VSL (list of registered vsegs), and the GPT (generic |
---|
| 97 | * page table), are only complete in the reference process cluster, other copies |
---|
| 98 | * are actually use as read-only caches. |
---|
[23] | 99 | * 3) the <fd_array>, containing extended pointers on the open file descriptors, is only |
---|
| 100 | * complete in the reference process cluster, other copies are read-only caches. |
---|
[173] | 101 | * 4) The <sem_root>, <mutex_root>, <barrier_root>, <condvar_root>, and the associated |
---|
[23] | 102 | * <sync_lock>, that are dynamically allocated, are only defined in the reference cluster. |
---|
[440] | 103 | * 5) The <children_root>, <children_nr>, <children_list>, and <txt_list> fields are only |
---|
[428] | 104 | * defined in the reference cluster, and are undefined in other clusters. |
---|
| 105 | * 6) The <local_list>, <copies_list>, <th_tbl>, <th_nr>, <th_lock> fields |
---|
[23] | 106 | * are defined in all process descriptors copies. |
---|
[433] | 107 | * 7) The termination <flags> and <exit_status> are only defined in the reference cluster. |
---|
[440] | 108 | * The term state format is defined in the shared_syscalls.h file. |
---|
[1] | 109 | ********************************************************************************************/ |
---|
| 110 | |
---|
| 111 | typedef struct process_s |
---|
| 112 | { |
---|
[23] | 113 | vmm_t vmm; /*! embedded virtual memory manager */ |
---|
[1] | 114 | |
---|
[23] | 115 | fd_array_t fd_array; /*! embedded open file descriptors array */ |
---|
[1] | 116 | |
---|
[173] | 117 | xptr_t vfs_root_xp; /*! extended pointer on current VFS root inode */ |
---|
[428] | 118 | xptr_t vfs_bin_xp; /*! extended pointer on .elf file descriptor */ |
---|
[23] | 119 | pid_t pid; /*! process identifier */ |
---|
| 120 | xptr_t ref_xp; /*! extended pointer on reference process */ |
---|
[428] | 121 | xptr_t parent_xp; /*! extended pointer on parent process */ |
---|
[1] | 122 | |
---|
[23] | 123 | xptr_t vfs_cwd_xp; /*! extended pointer on current working dir inode */ |
---|
| 124 | remote_rwlock_t cwd_lock; /*! lock protecting working directory changes */ |
---|
[173] | 125 | |
---|
[23] | 126 | xlist_entry_t children_root; /*! root of the children process xlist */ |
---|
[428] | 127 | remote_spinlock_t children_lock; /*! lock protecting children process xlist */ |
---|
[23] | 128 | uint32_t children_nr; /*! number of children processes */ |
---|
[1] | 129 | |
---|
[428] | 130 | xlist_entry_t children_list; /*! member of list of children of same parent */ |
---|
[23] | 131 | xlist_entry_t local_list; /*! member of list of process in same cluster */ |
---|
| 132 | xlist_entry_t copies_list; /*! member of list of copies of same process */ |
---|
[428] | 133 | xlist_entry_t txt_list; /*! member of list of processes sharing same TXT */ |
---|
[1] | 134 | |
---|
[23] | 135 | spinlock_t th_lock; /*! lock protecting th_tbl[] concurrent access */ |
---|
| 136 | uint32_t th_nr; /*! number of threads in this cluster */ |
---|
[428] | 137 | |
---|
[23] | 138 | struct thread_s * th_tbl[CONFIG_THREAD_MAX_PER_CLUSTER]; /*! pointers on local threads */ |
---|
[1] | 139 | |
---|
[23] | 140 | xlist_entry_t sem_root; /*! root of the process semaphore list */ |
---|
| 141 | xlist_entry_t mutex_root; /*! root of the process mutex list */ |
---|
| 142 | xlist_entry_t barrier_root; /*! root of the process barrier list */ |
---|
| 143 | xlist_entry_t condvar_root; /*! root of the process condvar list */ |
---|
[428] | 144 | remote_spinlock_t sync_lock; /*! lock protecting sem,mutex,barrier,condvar lists */ |
---|
[1] | 145 | |
---|
[433] | 146 | uint32_t term_state; /*! termination status (flags & exit status) */ |
---|
[428] | 147 | |
---|
| 148 | bool_t txt_owner; /*! current TXT owner */ |
---|
[1] | 149 | } |
---|
| 150 | process_t; |
---|
| 151 | |
---|
| 152 | /********************************************************************************************* |
---|
[101] | 153 | * This structure defines the information required by the process_make_exec() function |
---|
[409] | 154 | * to create a new reference process descriptor, and the associated main thread. |
---|
[1] | 155 | ********************************************************************************************/ |
---|
| 156 | |
---|
| 157 | typedef struct exec_info_s |
---|
| 158 | { |
---|
[23] | 159 | char path[CONFIG_VFS_MAX_PATH_LENGTH]; /*! .elf file path */ |
---|
[1] | 160 | |
---|
| 161 | char ** args_pointers; /*! physical base address of array of pointers */ |
---|
| 162 | char * args_buf_base; /*! physical base address of kernel args buffer */ |
---|
| 163 | uint32_t args_nr; /*! actual number of arguments */ |
---|
| 164 | |
---|
| 165 | char ** envs_pointers; /*! physical base address of array of pointers */ |
---|
| 166 | char * envs_buf_base; /*! physical base address of kernel args buffer */ |
---|
| 167 | char * envs_buf_free; /*! physical address of first free slot in envs_buf */ |
---|
| 168 | uint32_t envs_nr; /*! actual number of environment variables */ |
---|
| 169 | } |
---|
| 170 | exec_info_t; |
---|
| 171 | |
---|
| 172 | /*************** Process Descriptor Operations *****************************************/ |
---|
| 173 | |
---|
[173] | 174 | /********************************************************************************************* |
---|
| 175 | * This function allocates memory in local cluster for a process descriptor. |
---|
| 176 | ********************************************************************************************* |
---|
[1] | 177 | * @ returns pointer on process descriptor if success / return NULL if failure |
---|
| 178 | ********************************************************************************************/ |
---|
| 179 | process_t * process_alloc(); |
---|
| 180 | |
---|
[173] | 181 | /********************************************************************************************* |
---|
| 182 | * This function releases memory in local cluster for a process descriptor. |
---|
| 183 | ********************************************************************************************* |
---|
[1] | 184 | * @ process : pointer on process descriptor to release. |
---|
| 185 | ********************************************************************************************/ |
---|
| 186 | void process_free( process_t * process ); |
---|
| 187 | |
---|
[173] | 188 | /********************************************************************************************* |
---|
[428] | 189 | * This function initialize, in each cluster, the kernel "process_zero", that is the owner |
---|
| 190 | * of all kernel threads in a given cluster. It is called by the kernel_init() function. |
---|
| 191 | * The process_zero descriptor is allocated as a global variable in file kernel_init.c |
---|
| 192 | * Both the PID and PPID fields are set to zero, the ref_xp is the local process_zero, |
---|
| 193 | * and the parent process is set to XPTR_NULL. The th_tbl[] is initialized as empty. |
---|
| 194 | ********************************************************************************************* |
---|
| 195 | * @ process : [in] pointer on local process descriptor to initialize. |
---|
| 196 | ********************************************************************************************/ |
---|
| 197 | void process_zero_create( process_t * process ); |
---|
| 198 | |
---|
| 199 | /********************************************************************************************* |
---|
[173] | 200 | * This function allocates memory and initializes the "process_init" descriptor and the |
---|
[409] | 201 | * associated "thread_init" descriptor. It is called once at the end of the kernel |
---|
[428] | 202 | * initialisation procedure. Its local process identifier is 1, and parent process |
---|
| 203 | * is the kernel process in cluster 0. |
---|
[173] | 204 | * The "process_init" is the first user process, and all other user processes will be forked |
---|
[101] | 205 | * from this process. The code executed by "process_init" is stored in a .elf file, whose |
---|
[409] | 206 | * pathname is defined by the CONFIG_PROCESS_INIT_PATH configuration variable. |
---|
[428] | 207 | * The process_init does not use the [STDIN/STDOUT/STDERR] streams, but it is linked |
---|
| 208 | * to kernel TXT0, because these streams must be defined for all user processes. |
---|
[173] | 209 | ********************************************************************************************/ |
---|
[1] | 210 | void process_init_create(); |
---|
| 211 | |
---|
[173] | 212 | /********************************************************************************************* |
---|
[428] | 213 | * This function initializes a local, reference, user process descriptor from another process |
---|
| 214 | * descriptor, defined by the <model_xp> argument. The <process> and <pid> arguments must |
---|
| 215 | * be previously allocated by he caller. This function can be called by three functions: |
---|
| 216 | * 1) process_init_create() : process is the reference INIT process / pid = 1 / |
---|
| 217 | * the parent and model process descriptors are both the kernel process_zero. |
---|
| 218 | * 2) process_make_fork() : the model process descriptor is the (generally remote) |
---|
| 219 | * parent process. |
---|
| 220 | * 3) process_make exec() : the model process is the local old_process, the new_process |
---|
| 221 | * parent is the same as the old_process parent. |
---|
| 222 | * The following fields are initialised : |
---|
| 223 | * - It set the pid / ppid / ref_xp / parent_xp / state fields. |
---|
[409] | 224 | * - It initializes the VMM (register the kentry, args, envs vsegs in VSL) |
---|
[408] | 225 | * - It initializes the FDT, defining the three pseudo files STDIN / STDOUT / STDERR. |
---|
| 226 | * - It set the root_xp, bin_xp, cwd_xp fields. |
---|
| 227 | * - It reset the children list as empty, but does NOT register it in parent children list. |
---|
| 228 | * - It reset the TH_TBL list of threads as empty. |
---|
| 229 | * - It reset the semaphore / mutex / barrier / condvar lists as empty. |
---|
| 230 | * - It registers the process in the local_list, rooted in the local cluster manager. |
---|
| 231 | * - It registers the process in the copies_list, rooted in the owner cluster manager. |
---|
| 232 | * - It registers the process extended pointer in the local pref_tbl[] array. |
---|
| 233 | ********************************************************************************************* |
---|
| 234 | * @ process : [in] pointer on local process descriptor to initialize. |
---|
| 235 | * @ pid : [in] process identifier. |
---|
[428] | 236 | * @ parent_xp : [in] extended pointer on parent process descriptor. |
---|
| 237 | * @ model_xp : [in] extended pointer on model process descriptor. |
---|
[408] | 238 | ********************************************************************************************/ |
---|
[1] | 239 | void process_reference_init( process_t * process, |
---|
| 240 | pid_t pid, |
---|
[428] | 241 | xptr_t parent_xp, |
---|
[408] | 242 | xptr_t model_xp ); |
---|
[1] | 243 | |
---|
[173] | 244 | /********************************************************************************************* |
---|
| 245 | * This function initializes a copy process descriptor, in the local cluster, |
---|
| 246 | * from information defined in the reference remote process descriptor. |
---|
| 247 | ********************************************************************************************* |
---|
[1] | 248 | * @ process : [in] local pointer on process descriptor to initialize. |
---|
| 249 | * @ reference_process_xp : [in] extended pointer on reference process descriptor. |
---|
| 250 | * @ return 0 if success / return ENOMEM if failure |
---|
| 251 | ********************************************************************************************/ |
---|
| 252 | error_t process_copy_init( process_t * local_process, |
---|
| 253 | xptr_t reference_process_xp ); |
---|
| 254 | |
---|
[173] | 255 | /********************************************************************************************* |
---|
[1] | 256 | * This function releases all memory allocated for a process descriptor in the local cluster, |
---|
[23] | 257 | * including memory allocated for embedded substructures (fd_array, vmm, etc). |
---|
[1] | 258 | * The local th_tbl[] array must be empty. |
---|
[173] | 259 | ********************************************************************************************* |
---|
[1] | 260 | * @ process : pointer on the process descriptor. |
---|
| 261 | ********************************************************************************************/ |
---|
| 262 | void process_destroy( process_t * process ); |
---|
| 263 | |
---|
[173] | 264 | /********************************************************************************************* |
---|
[428] | 265 | * This debug function diplays on the kernel terminal TXT0 detailed informations on a |
---|
| 266 | * reference process identified by the <process_xp> argument. |
---|
| 267 | * It can be called by a thread running in any cluster. |
---|
| 268 | ********************************************************************************************* |
---|
| 269 | * @ process_xp : extended pointer on reference process. |
---|
| 270 | ********************************************************************************************/ |
---|
| 271 | void process_display( xptr_t process_xp ); |
---|
| 272 | |
---|
| 273 | /********************************************************************************************* |
---|
| 274 | * This function returns a printable string defining the sigaction type. |
---|
| 275 | ********************************************************************************************* |
---|
| 276 | * @ sigaction_type : BLOCK_ALL_THREADS / UNBLOCK_ALL_THREADS / DELETE_ALL_THREADS |
---|
| 277 | * @ return a string pointer. |
---|
| 278 | ********************************************************************************************/ |
---|
| 279 | char * process_action_str( uint32_t sigaction_type ); |
---|
| 280 | |
---|
| 281 | /********************************************************************************************* |
---|
[435] | 282 | * This function allows a client thread running in any cluster to block, unblock or delete |
---|
| 283 | * all threads of a process identified by the <pid> argument, depending on the |
---|
[436] | 284 | * <action_type> argument. |
---|
[440] | 285 | * WARNING : the DELETE and BLOCK actions are NOT executed on the target process main thread |
---|
| 286 | * (thread 0 in process owner cluster), and not executed on the calling thread itself. |
---|
[436] | 287 | * It uses the multicast, non blocking rpc_process_sigaction_client() function to send |
---|
[440] | 288 | * parallel requests to all remote clusters containing process copies. |
---|
[436] | 289 | * Then it blocks and deschedule to wait completion of these parallel requests. |
---|
| 290 | * |
---|
[416] | 291 | * It is used by the sys_kill() & sys_exit() functions to handle the "kill" & "exit" syscalls. |
---|
| 292 | * It is also used by the process_make_exec() function to handle the "exec" syscall. |
---|
[436] | 293 | * It is also called by the TXT device ISR to execute the ctrl C & ctrl Z commands. |
---|
| 294 | * |
---|
| 295 | * Implementation note: |
---|
| 296 | * This function allocates a - shared - RPC descriptor in client thread stack, |
---|
| 297 | * and initializes it. This RPC descriptor can be shared because all parallel, |
---|
| 298 | * non-blocking, RPC server threads use the same input arguments, including the |
---|
| 299 | * RPC responses counter field. |
---|
[409] | 300 | ********************************************************************************************* |
---|
[435] | 301 | * @ pid : target process identifier. |
---|
[416] | 302 | * @ action_type : BLOCK_ALL_THREADS / UNBLOCK_ALL_THREADS / DELETE_ALL_THREADS |
---|
[1] | 303 | ********************************************************************************************/ |
---|
[435] | 304 | void process_sigaction( pid_t pid, |
---|
[409] | 305 | uint32_t action_type ); |
---|
[1] | 306 | |
---|
[173] | 307 | /********************************************************************************************* |
---|
[440] | 308 | * This function blocks all threads for a given <process> in the local cluster. |
---|
| 309 | * It scan the list of local thread, and sets the THREAD_BLOCKED_GLOBAL bit for all |
---|
| 310 | * threads, BUT the main thread (thread 0 in owner cluster), and the client thread |
---|
| 311 | * identified by the <client_xp> argument. It request the relevant schedulers to acknowledge |
---|
| 312 | * the blocking, using IPI if required, and returns only when all blockable threads |
---|
| 313 | * in cluster are actually blocked. |
---|
[416] | 314 | * The threads are not detached from the scheduler, and not detached from the local process. |
---|
[409] | 315 | ********************************************************************************************* |
---|
| 316 | * @ process : pointer on the target process descriptor. |
---|
[440] | 317 | * @ client_xp : extended pointer on the client thread that should not be blocked. |
---|
[409] | 318 | ********************************************************************************************/ |
---|
[440] | 319 | void process_block_threads( process_t * process, |
---|
| 320 | xptr_t client_xp ); |
---|
[409] | 321 | |
---|
| 322 | /********************************************************************************************* |
---|
[440] | 323 | * This function marks for deletion all threads for a given <process> in the local cluster. |
---|
| 324 | * It scan the list of local thread, and sets the THREAD_FLAG_REQ_DELETE bit for all |
---|
| 325 | * threads, BUT the main thread (thread 0 in owner cluster), and the client thread |
---|
| 326 | * identified by the <client_xp> argument. |
---|
| 327 | * The actual deletion will be done by the scheduler at the next scheduling point. |
---|
[409] | 328 | ********************************************************************************************* |
---|
| 329 | * @ process : pointer on the process descriptor. |
---|
[440] | 330 | * @ client_xp : extended pointer on the client thread that should not be marked. |
---|
[409] | 331 | ********************************************************************************************/ |
---|
[440] | 332 | void process_delete_threads( process_t * process, |
---|
| 333 | xptr_t client_xp ); |
---|
[409] | 334 | |
---|
| 335 | /********************************************************************************************* |
---|
[440] | 336 | * This function unblocks all threads of a given user process in a given cluster. |
---|
[409] | 337 | ********************************************************************************************* |
---|
| 338 | * @ process : pointer on the process descriptor. |
---|
| 339 | ********************************************************************************************/ |
---|
[440] | 340 | void process_unblock_threads( process_t * process ); |
---|
[409] | 341 | |
---|
| 342 | /********************************************************************************************* |
---|
[1] | 343 | * This function returns a pointer on the local copy of a process identified by its PID. |
---|
[173] | 344 | * If this local copy does not exist yet, it is dynamically created, from the reference |
---|
[1] | 345 | * process descriptor, registered in the global copies_list, and registered in the local_list. |
---|
[23] | 346 | * This function is used by the thread_user_create() function. |
---|
[173] | 347 | ********************************************************************************************* |
---|
[1] | 348 | * @ pid : searched process identifier. |
---|
| 349 | * @ returns pointer on the local process descriptor if success / returns NULL if failure. |
---|
| 350 | ********************************************************************************************/ |
---|
| 351 | process_t * process_get_local_copy( pid_t pid ); |
---|
| 352 | |
---|
[173] | 353 | /********************************************************************************************* |
---|
[436] | 354 | * This function returns the parent process identifier for a remote process descriptor |
---|
| 355 | * identified by an extended pointer. |
---|
| 356 | ********************************************************************************************* |
---|
| 357 | * @ process_xp : extended pointer on remote process descriptor. |
---|
| 358 | * @ returns parent process dentifier. |
---|
| 359 | ********************************************************************************************/ |
---|
| 360 | pid_t process_get_ppid( xptr_t process_xp ); |
---|
| 361 | |
---|
| 362 | /********************************************************************************************* |
---|
[409] | 363 | * This function implements the "exec" system call, and is called by the sys_exec() function. |
---|
[408] | 364 | * The "new" process keep the "old" process PID and PPID, all open files, and env variables, |
---|
| 365 | * the vfs_root and vfs_cwd, but build a brand new memory image (new VMM from the new .elf). |
---|
[409] | 366 | * It actually creates a "new" reference process descriptor, and copies all relevant |
---|
| 367 | * information from the "old" process descriptor to the "new" process descriptor. |
---|
[408] | 368 | * It completes the "new" process descriptor, from information found in the <exec_info> |
---|
| 369 | * structure (defined in the process.h file), that must be built by the caller. |
---|
| 370 | * It creates and initializes the associated main thread. It finally destroys all copies |
---|
[409] | 371 | * of the "old" process in all clusters, and destroys all old associated threads. |
---|
[408] | 372 | * It is executed in the local cluster, that becomes both the "owner" and the "reference" |
---|
| 373 | * cluster for the "new" process. |
---|
[173] | 374 | ********************************************************************************************* |
---|
[1] | 375 | * @ exec_info : [in] pointer on the exec_info structure. |
---|
| 376 | * @ return 0 if success / return non-zero if error. |
---|
| 377 | ********************************************************************************************/ |
---|
| 378 | error_t process_make_exec( exec_info_t * exec_info ); |
---|
| 379 | |
---|
[408] | 380 | /********************************************************************************************* |
---|
[409] | 381 | * This function implements the "fork" system call, and is called by the sys_fork() function. |
---|
[408] | 382 | * It allocates memory and initializes a new "child" process descriptor, and the |
---|
| 383 | * associated "child" thread descriptor in the local cluster. This function can involve |
---|
| 384 | * up to three different clusters : |
---|
[433] | 385 | * - the child (local) cluster can be any cluster defined by the sys_fork function. |
---|
[409] | 386 | * - the parent cluster must be the reference cluster for the parent process. |
---|
| 387 | * - the client cluster containing the thread requesting the fork can be any cluster. |
---|
[408] | 388 | * The new "child" process descriptor is initialised from informations found in the "parent" |
---|
| 389 | * reference process descriptor, containing the complete process description. |
---|
| 390 | * The new "child" thread descriptor is initialised from informations found in the "parent" |
---|
| 391 | * thread descriptor. |
---|
| 392 | ********************************************************************************************* |
---|
| 393 | * @ parent_process_xp : extended pointer on the reference parent process. |
---|
| 394 | * @ parent_thread_xp : extended pointer on the parent thread requesting the fork. |
---|
| 395 | * @ child_pid : [out] child process identifier. |
---|
| 396 | * @ child_thread_ptr : [out] local pointer on child thread in target cluster. |
---|
| 397 | * @ return 0 if success / return non-zero if error. |
---|
| 398 | ********************************************************************************************/ |
---|
| 399 | error_t process_make_fork( xptr_t parent_process_xp, |
---|
| 400 | xptr_t parent_thread_xp, |
---|
| 401 | pid_t * child_pid, |
---|
| 402 | struct thread_s ** child_thread_ptr ); |
---|
[1] | 403 | |
---|
[173] | 404 | /******************** File Management Operations ****************************************/ |
---|
[1] | 405 | |
---|
| 406 | /********************************************************************************************* |
---|
[173] | 407 | * This function initializes all entries of the local fd_array as empty. |
---|
| 408 | ********************************************************************************************* |
---|
[1] | 409 | * @ process : pointer on the local process descriptor. |
---|
| 410 | ********************************************************************************************/ |
---|
| 411 | void process_fd_init( process_t * process ); |
---|
| 412 | |
---|
| 413 | /********************************************************************************************* |
---|
[23] | 414 | * This function uses as many remote accesses as required, to reset an entry in fd_array[], |
---|
[407] | 415 | * in all clusters containing a copy. The entry is identified by the <fdid> argument. |
---|
[173] | 416 | * This function must be executed by a thread running reference cluster, that contains |
---|
[23] | 417 | * the complete list of process descriptors copies. |
---|
[173] | 418 | ********************************************************************************************* |
---|
[1] | 419 | * @ process : pointer on the local process descriptor. |
---|
[407] | 420 | * @ fdid : file descriptor index in the fd_array. |
---|
[1] | 421 | ********************************************************************************************/ |
---|
[23] | 422 | void process_fd_remove( process_t * process, |
---|
[407] | 423 | uint32_t fdid ); |
---|
[1] | 424 | |
---|
| 425 | /********************************************************************************************* |
---|
[173] | 426 | * This function returns an extended pointer on a file descriptor identified by its index |
---|
[23] | 427 | * in fd_array. It can be called by any thread running in any cluster. |
---|
[173] | 428 | * It accesses first the local process descriptor. In case of local miss, it uses remote |
---|
| 429 | * access to access the reference process descriptor. |
---|
| 430 | * It updates the local fd_array when the file descriptor exists in reference cluster. |
---|
[23] | 431 | * The file descriptor refcount is not incremented. |
---|
[173] | 432 | ********************************************************************************************* |
---|
[1] | 433 | * @ process : pointer on the local process descriptor. |
---|
[407] | 434 | * @ fdid : file descriptor index in the fd_array. |
---|
[23] | 435 | * @ return extended pointer on file descriptor if success / return XPTR_NULL if not found. |
---|
[1] | 436 | ********************************************************************************************/ |
---|
[23] | 437 | xptr_t process_fd_get_xptr( process_t * process, |
---|
[407] | 438 | uint32_t fdid ); |
---|
[1] | 439 | |
---|
| 440 | /********************************************************************************************* |
---|
[173] | 441 | * This function checks the number of open files for a given process. |
---|
[23] | 442 | * It can be called by any thread in any cluster, because it uses portable remote access |
---|
| 443 | * primitives to access the reference process descriptor. |
---|
[173] | 444 | ********************************************************************************************* |
---|
[23] | 445 | * @ returns true if file descriptor array full. |
---|
[1] | 446 | ********************************************************************************************/ |
---|
[23] | 447 | bool_t process_fd_array_full(); |
---|
[1] | 448 | |
---|
| 449 | /********************************************************************************************* |
---|
[23] | 450 | * This function allocates a free slot in the fd_array of the reference process, |
---|
| 451 | * register the <file_xp> argument in the allocated slot, and return the slot index. |
---|
| 452 | * It can be called by any thread in any cluster, because it uses portable remote access |
---|
| 453 | * primitives to access the reference process descriptor. |
---|
[173] | 454 | ********************************************************************************************* |
---|
[23] | 455 | * @ file_xp : extended pointer on the file descriptor to be registered. |
---|
[407] | 456 | * @ fdid : [out] buffer for fd_array slot index. |
---|
[23] | 457 | * @ return 0 if success / return EMFILE if array full. |
---|
[1] | 458 | ********************************************************************************************/ |
---|
[407] | 459 | error_t process_fd_register( process_t * process, |
---|
| 460 | xptr_t file_xp, |
---|
| 461 | uint32_t * fdid ); |
---|
[1] | 462 | |
---|
| 463 | /********************************************************************************************* |
---|
[409] | 464 | * This function copies all non-zero entries (other than the three first stdin/stdout/stderr) |
---|
| 465 | * from a remote <src_xp> fd_array, embedded in a process descriptor, to another remote |
---|
| 466 | * <dst_xp> fd_array, embedded in another process descriptor. |
---|
| 467 | * The calling thread can be running in any cluster. |
---|
[1] | 468 | * It takes the remote lock protecting the <src_xp> fd_array during the copy. |
---|
[173] | 469 | * For each involved file descriptor, the refcount is incremented. |
---|
| 470 | ********************************************************************************************* |
---|
[1] | 471 | * @ dst_xp : extended pointer on the destination fd_array_t. |
---|
| 472 | * @ src_xp : extended pointer on the source fd_array_t. |
---|
| 473 | ********************************************************************************************/ |
---|
| 474 | void process_fd_remote_copy( xptr_t dst_xp, |
---|
| 475 | xptr_t src_xp ); |
---|
| 476 | |
---|
| 477 | |
---|
[23] | 478 | |
---|
[173] | 479 | /******************** Thread Related Operations *****************************************/ |
---|
[1] | 480 | |
---|
| 481 | /********************************************************************************************* |
---|
| 482 | * This function registers a new thread in the local process descriptor. |
---|
| 483 | * It checks that there is an available slot in the local th_tbl[] array, |
---|
| 484 | * allocates a new LTID, and registers the new thread in the th_tbl[]. |
---|
| 485 | * WARNING : the lock protecting the th_tbl[] must be taken by the caller. |
---|
[173] | 486 | ********************************************************************************************* |
---|
[1] | 487 | * @ process : pointer on the local process descriptor. |
---|
| 488 | * @ thread : pointer on new thread to be registered. |
---|
| 489 | * @ trdid : [out] address of buffer for allocated trdid. |
---|
| 490 | * @ returns 0 if success / returns non zero if no slot available. |
---|
| 491 | ********************************************************************************************/ |
---|
| 492 | error_t process_register_thread( process_t * process, |
---|
| 493 | struct thread_s * thread, |
---|
| 494 | trdid_t * trdid ); |
---|
| 495 | |
---|
| 496 | /********************************************************************************************* |
---|
| 497 | * This function removes a thread registration from the local process descriptor. |
---|
| 498 | * WARNING : the lock protecting the th_tbl[] must be taken by the caller. |
---|
[173] | 499 | ********************************************************************************************* |
---|
[1] | 500 | * @ thread : local pointer on thread to be removed. |
---|
| 501 | ********************************************************************************************/ |
---|
| 502 | void process_remove_thread( struct thread_s * thread ); |
---|
| 503 | |
---|
| 504 | |
---|
[428] | 505 | /*************** Terminals related operations ********************************************/ |
---|
[1] | 506 | |
---|
[428] | 507 | /********************************************************************************************* |
---|
| 508 | * This function scan the set of user TXT terminals to find a free terminal |
---|
| 509 | * (the list of attached processes is empty for a free TXT terminal). |
---|
| 510 | * It is called only by the process_reference_init() function when creating a KSH process. |
---|
| 511 | * It makes a kernel panic if no free TXT terminal is found. |
---|
[441] | 512 | * The allocated TXT terminal is only released if the KSH process is deleted, |
---|
| 513 | * which is a rare and abnormal event. |
---|
[428] | 514 | ********************************************************************************************* |
---|
| 515 | * @ return TXT terminal index if succes / kernel panic if no terminal found. |
---|
| 516 | ********************************************************************************************/ |
---|
| 517 | uint32_t process_txt_alloc(); |
---|
| 518 | |
---|
| 519 | /********************************************************************************************* |
---|
[436] | 520 | * This function attach a process descriptor in owner cluster, identified by the <process> |
---|
[428] | 521 | * argument to a TXT terminal, identified by its <txt_id> channel index argument. |
---|
| 522 | * It insert the process descriptor in the xlist rooted in the TXT_RX device. |
---|
| 523 | * It is called by the process_reference_init() function. |
---|
| 524 | ********************************************************************************************* |
---|
| 525 | * @ process : local pointer on process descriptor. |
---|
| 526 | * @ txt_id : TXT channel index. |
---|
| 527 | ********************************************************************************************/ |
---|
| 528 | void process_txt_attach( process_t * process, |
---|
| 529 | uint32_t txt_id ); |
---|
| 530 | |
---|
| 531 | /********************************************************************************************* |
---|
[436] | 532 | * This function detach a process, identified by the <process_xp> argument, |
---|
| 533 | * from the list of process attached to a given TXT terminal. |
---|
| 534 | * The target process descriptor must be in the owner cluster, but the calling thread can |
---|
| 535 | * be running in any cluster. |
---|
[428] | 536 | ********************************************************************************************* |
---|
[436] | 537 | * @ process_xp : extended pointer on process descriptor. |
---|
[428] | 538 | ********************************************************************************************/ |
---|
[436] | 539 | void process_txt_detach( xptr_t process_xp ); |
---|
[428] | 540 | |
---|
| 541 | /********************************************************************************************* |
---|
[436] | 542 | * This function gives to a process identified by the <owner_xp> argument, and attached |
---|
[428] | 543 | * to terminal TXT[i] the exclusive ownership of the TXT_RX[i] terminal. |
---|
[436] | 544 | * The process descriptor must be in the process owner cluster. |
---|
[428] | 545 | ********************************************************************************************* |
---|
[436] | 546 | * @ owner_xp : extended pointer on process descriptor in owner cluster. |
---|
[428] | 547 | ********************************************************************************************/ |
---|
[436] | 548 | void process_txt_set_ownership( xptr_t owner_xp ); |
---|
[428] | 549 | |
---|
| 550 | /********************************************************************************************* |
---|
[436] | 551 | * When the process dentified by the <owner_xp> argument has the exclusive ownership of |
---|
| 552 | * the TXT_RX terminal, this function transfer this ownership to another attached process. |
---|
| 553 | * The process descriptor must be in the process owner cluster. |
---|
| 554 | * This function does nothing if the <pid> process is not the owner. |
---|
| 555 | * - If the current owner is not the KSH process, the new owner is the KSH process. |
---|
| 556 | * - If the <pid> process is the the KSH process, the new owner is another attached process. |
---|
| 557 | * - If there is no other attached process, the TXT has no more defined owner. |
---|
[428] | 558 | ********************************************************************************************* |
---|
[436] | 559 | * @ owner_xp : extended pointer on process descriptor in owner cluster. |
---|
[428] | 560 | ********************************************************************************************/ |
---|
[436] | 561 | void process_txt_transfer_ownership( xptr_t owner_xp ); |
---|
[428] | 562 | |
---|
[435] | 563 | /********************************************************************************************* |
---|
[436] | 564 | * This function returns the TXT owner process (foreground process) |
---|
[435] | 565 | * for a given TXT terminal identified by its <channel> index. |
---|
| 566 | ********************************************************************************************* |
---|
| 567 | * @ channel : TXT terminal channel. |
---|
[436] | 568 | * @ return extentded pointer on TXT owner process in owner cluster. |
---|
[435] | 569 | ********************************************************************************************/ |
---|
[436] | 570 | xptr_t process_txt_get_owner( uint32_t channel ); |
---|
[435] | 571 | |
---|
| 572 | /********************************************************************************************* |
---|
| 573 | * This debug function diplays on the kernel terminal the list of processes attached |
---|
| 574 | * to a given terminal identified by the <txt_id> argument. |
---|
| 575 | ********************************************************************************************* |
---|
| 576 | * @ txt_id : TXT terminal channel. |
---|
| 577 | ********************************************************************************************/ |
---|
| 578 | void process_txt_display( uint32_t txt_id ); |
---|
| 579 | |
---|
| 580 | |
---|
[1] | 581 | #endif /* _PROCESS_H_ */ |
---|