Ignore:
Timestamp:
Dec 20, 2017, 4:51:09 PM (6 years ago)
Author:
alain
Message:

Fix bugs in exec

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/process.h

    r408 r409  
    5454
    5555/*********************************************************************************************
     56 * This enum defines the actions that can be executed by the process_signal() function.
     57 ********************************************************************************************/
     58
     59enum process_sigactions
     60{
     61    BLOCK_ALL_THREADS,
     62    UNBLOCK_ALL_THREADS,
     63    DELETE_ALL_THREADS,
     64};
     65
     66/*********************************************************************************************
    5667 * This structure defines an array of extended pointers on the open file descriptors
    5768 * for a given process. We use an extended pointer because the open file descriptor
     
    7687 * - The PID 16 LSB bits contain the LPID (Local Process Index)
    7788 * - The PID 16 MSB bits contain the owner cluster CXY.
    78  * In each cluster, the process manager allocates LPID values for the process that are
    79  * allocated to this cluster.
    80  * The process descriptor for a PID process is replicated in all clusters containing
    81  * at least one thread of the PID process, with the following rules :
    82  *
     89 * In each cluster, the process manager allocates  the LPID values for the process that
     90 * are owned by this cluster.
     91 * The process descriptor is replicated in all clusters containing at least one thread
     92 * of the PID process, with the following rules :
    8393 * 1) The <pid>, <ppid>, <ref_xp>, <vfs_root_xp>, <vfs_bin_xp>  fields are defined
    8494 *    in all process descriptor copies.
    8595 * 2) The <vfs_cwd_xp> and associated <cwd_lock>, that can be dynamically modified,
    8696 *    are only defined in the reference process descriptor.
    87  * 2) The <vmm>, containing the list of registered vsegs, and the page table, are only
    88  *    complete in the reference process cluster, other copies are read-only caches.
     97 * 2) The <vmm>, containing the VSL (list of registered vsegs), and the GPT (generic
     98 *    page table), are only complete in the reference process cluster, other copies
     99 *    are actually use as read-only caches.
    89100 * 3) the <fd_array>, containing extended pointers on the open file descriptors, is only
    90101 *    complete in the reference process cluster, other copies are read-only caches.
     
    95106 * 6) The <brothers_list>, <local_list>, <copies_list>, <th_tbl>, <th_nr>, <th_lock> fields
    96107 *    are defined in all process descriptors copies.
    97  * 7) The <sig_mgr> field is only defined in the reference cluster. TODO
    98108 ********************************************************************************************/
    99109
     
    130140
    131141    remote_spinlock_t sync_lock;        /*! lock protecting sem,mutex,barrier,condvar lists */
    132 
    133         sig_mgr_t         sig_mgr;          /*! embedded signal manager TODO [AG]               */
    134142}
    135143process_t;
     
    137145/*********************************************************************************************
    138146 * This structure defines the information required by the process_make_exec() function
    139  * to create a new reference process descriptor, and the associated main thread,
    140  * in the parent process owner cluster.
     147 * to create a new reference process descriptor, and the associated main thread.
    141148 ********************************************************************************************/
    142149
     
    176183/*********************************************************************************************
    177184 * This function allocates memory and initializes the "process_init" descriptor and the
    178  * associated "thread_init" descriptor in the local cluster. It is called once at the end
    179  * of the kernel initialisation procedure, by the local kernel process.
     185 * associated "thread_init" descriptor. It is called once at the end of the kernel
     186 * initialisation procedure, by the kernel process in cluster_IO.
    180187 * The "process_init" is the first user process, and all other user processes will be forked
    181188 * from this process. The code executed by "process_init" is stored in a .elf file, whose
    182  * pathname is defined by the CONFIG_PROCESS_INIT_PATH argument.
    183  * Practically, it builds the exec_info structure, and calls the process_make_exec()
    184  * function, that make the real job.
     189 * pathname is defined by the CONFIG_PROCESS_INIT_PATH configuration variable.
     190 * The process_init streams are defined  by the CONFIG_INIT_[STDIN/STDOUT/STDERR] variables.
     191 * Its local process identifier is 1, and parent process is the local kernel process_zero.
    185192 ********************************************************************************************/
    186193void process_init_create();
     
    200207 * descriptor, defined by the <model_xp> argument. The <process> descriptor, the <pid>, and
    201208 * the <ppid> arguments must be previously defined by the caller.
    202  * It can be called by three functions, depending on the process type:
    203  * 1) if "process" is the user "process_init", the parent is the kernel process. It is
     209 * It can be called by two functions, depending on the process type:
     210 * 1) if "process" is the "process_init", the parent is the kernel process. It is
    204211 *    called once, by the process_init_create() function in cluster[xmax-1][ymax-1].
    205212 * 2) if the caller is the process_make_fork() function, the model is generally a remote
    206213 *    process, that is also the parent process.
     214
    207215 * 3) if the caller is the process_make_exec() function, the model is always a local process,
    208  *    but the parent is the parent of the model process.
    209  *
     216 *    and the parent is the parent of the model process. DEPRECATED [AG]
     217
    210218 * The following fields are initialised (for all process but process_zero).
    211219 * - It set the pid / ppid / ref_xp fields.
    212  * - It initializes an empty VMM (no vsegs registered in VSL and GPT).
     220 * - It initializes the VMM (register the kentry, args, envs vsegs in VSL)
    213221 * - It initializes the FDT, defining the three pseudo files STDIN / STDOUT / STDERR.
    214222 * - It set the root_xp, bin_xp, cwd_xp fields.
     
    251259
    252260/*********************************************************************************************
    253  * This function kills a user process in a given cluster.
    254  * It can be directly called in the reference cluster, or it can be called through the
    255  * PROCESS_KILL RPC.
    256  * - In a first loop, it set the THREAD_SIG_KILL signal to all threads of process.
    257  * - In a second loop, it wait, for each thread the reset of the THREAD_SIG_KILL signal
    258  *   by the scheduler, and completes the thread descriptor destruction.
     261 * This function returns a printable string defining the action for process_signa().
     262 *********************************************************************************************
     263 * @ action_type   : BLOCK_ALL_THREADS / UNBLOCK_ALL_THREADS / DELETE_ALL_THREADS
     264 * @ return a string pointer.
     265 ********************************************************************************************/
     266char * process_action_str( uint32_t action_type );
     267
     268/*********************************************************************************************
     269 * This function allows any thread running in any cluster to block, unblock  or delete
     270 * all threads of a given process identified by the <process> argument, dependig on the
     271 * <acion_type> argument.
     272 * It can be called by the sys_kill() or sys_exit() functions to handle the "kill" & "exit"
     273 * system calls, or by the process_make_exec() function to handle the "exec" system call.
     274 * It must be executed in the owner cluster for the target process (using the relevant RPC
     275 * (RPC_PROCESS_SIGNAL or RPC_PROCESS_EXEC) if the client thread in not running in the
     276 * owner cluster.
     277 * It uses the multicast, non blocking, RPC_PROCESS_KILL to send the signal to all process
     278 * copies in parallel, block & deschedule when all signals have been sent, and finally
     279 * returns only when all responses have been received and the operation is completed.
    259280 *********************************************************************************************
    260281 * @ process     : pointer on the process descriptor.
    261  ********************************************************************************************/
    262 void process_kill( process_t * process );
     282 * @ action_type   : BLOCK_ALL_THREADS / UNBLOCK_ALL_THREADS / DELETE_ALL_THREADS
     283 ********************************************************************************************/
     284void process_sigaction( process_t * process,
     285                        uint32_t    action_type );
     286
     287/*********************************************************************************************
     288 * This function blocks all threads of a given user process in a given cluster.
     289 * It is always called by a local RPC thread, through the multicast RPC_PROCESS_KILL.
     290 * It loop on all local threads of the process, requesting the relevant schedulers to
     291 * block and deschedule these threads, using IPI if required. The threads are not detached
     292 * from the scheduler, and not detached from the local process.
     293 * It acknowledges the client thread in the owner cluster only when all process threads
     294 * are descheduled and blocked on the BLOCKED_GLOBAL condition, using the <rsp_xp> argument.
     295 *********************************************************************************************
     296 * @ process     : pointer on the target process descriptor.
     297 * @ rsp_xp      : extended pointer on the response counter.
     298 * # client_xp   : extended pointer on client thread descriptor.
     299 ********************************************************************************************/
     300void process_block( process_t * process,
     301                    xptr_t      rsp_xp,
     302                    xptr_t      client_xp );
     303
     304/*********************************************************************************************
     305 * This function unblocks all threads of a given user process in a given cluster.
     306 * It is always called by a local RPC thread, through the multicast RPC_PROCESS_KILL.
     307 * It loops on local threads of the process, to reset the BLOCKED_GLOBAL bit in all threads.
     308 * It acknowledges directly the client thread in the owner cluster when this is done,
     309 * using the <rsp_xp> argument.
     310 *********************************************************************************************
     311 * @ process     : pointer on the process descriptor.
     312 * @ rsp_xp      : extended pointer on the response counter.
     313 * # client_xp   : extended pointer on client thread descriptor.
     314 ********************************************************************************************/
     315void process_unblock( process_t * process,
     316                      xptr_t      rsp_xp,
     317                      xptr_t      client_xp );
     318
     319/*********************************************************************************************
     320 * This function delete all threads descriptors, of given user process in a given cluster.
     321 * It is always called by a local RPC thread, through the multicast RPC_PROCESS_KILL.
     322 * It detach all process threads from the scheduler, detach the threads from the local
     323 * process, and release the local memory allocated to threads descriptors (including the
     324 * associated structures such as CPU and FPU context). Finally, it release the memory
     325 * allocated to the local process descriptor itself, but only when the local cluster
     326 * is NOT the process owner, but only a copy.  It acknowledges directly the client thread
     327 * in the owner cluster, using ithe <rsp_xp> argument.
     328 *********************************************************************************************
     329 * @ process     : pointer on the process descriptor.
     330 * @ rsp_xp      : extended pointer on the response counter.
     331 * # client_xp   : extended pointer on client thread descriptor.
     332 ********************************************************************************************/
     333void process_delete( process_t * process,
     334                     xptr_t      rsp_xp,
     335                     xptr_t      client_xp );
    263336
    264337/*********************************************************************************************
     
    274347
    275348/*********************************************************************************************
    276  * This function implements the exec() system call, and is called by the sys_exec() function.
    277  * It is also called by the process_init_create() function to build the "init" process.
     349 * This function implements the "exec" system call, and is called by the sys_exec() function.
    278350 * The "new" process keep the "old" process PID and PPID, all open files, and env variables,
    279351 * the vfs_root and vfs_cwd, but build a brand new memory image (new VMM from the new .elf).
    280  * It actually creates a "new" reference process descriptor, saves all relevant information
    281  * from the "old" reference process descriptor to the "new" process descriptor.
     352 * It actually creates a "new" reference process descriptor, and copies all relevant
     353 * information from the "old" process descriptor to the "new" process descriptor.
    282354 * It completes the "new" process descriptor, from information found in the <exec_info>
    283355 * structure (defined in the process.h file), that must be built by the caller.
    284356 * It creates and initializes the associated main thread. It finally destroys all copies
    285  * of the "old" process in all clusters, and all the old associated threads.
     357 * of the "old" process in all clusters, and destroys all old associated threads.
    286358 * It is executed in the local cluster, that becomes both the "owner" and the "reference"
    287359 * cluster for the "new" process.
     
    293365
    294366/*********************************************************************************************
    295  * This function implement the fork() system call, and is called by the sys_fork() function.
     367 * This function implements the "fork" system call, and is called by the sys_fork() function.
    296368 * It allocates memory and initializes a new "child" process descriptor, and the
    297369 * associated "child" thread descriptor in the local cluster. This function can involve
    298370 * up to three different clusters :
    299371 * - the local (child) cluster can be any cluster defined by the sys_fork function.
    300  * - the parent cluster must be the reference clusterfor the parent process.
    301  * - the client cluster containing the thread requestingthe fork can be any cluster.
     372 * - the parent cluster must be the reference cluster for the parent process.
     373 * - the client cluster containing the thread requesting the fork can be any cluster.
    302374 * The new "child" process descriptor is initialised from informations found in the "parent"
    303375 * reference process descriptor, containing the complete process description.
     
    315387                            pid_t            * child_pid,
    316388                            struct thread_s ** child_thread_ptr );
     389
     390/*********************************************************************************************
     391 * This function implement the "exit" system call, and is called by the sys_exit() function.
     392 * It must be executed by a thread running in the calling process owner cluster.
     393 * It uses twice the multicast RPC_PROCESS_SIGNAL to first block all process threads
     394 * in all clusters, and then delete all thread  and process descriptors.
     395 *********************************************************************************************
     396 * @ process  : pointer on process descriptor in owner cluster.
     397 * @ status   : exit return value.
     398 ********************************************************************************************/
     399void process_make_exit( process_t * process,
     400                        uint32_t    status );
     401
     402/*********************************************************************************************
     403 * This function implement the "kill" system call, and is called by the sys_kill() function.
     404 * It must be executed by a thread running in the target process owner cluster.
     405 * Only the SIGKILL, SIGSTOP, and SIGCONT signals are supported.
     406 * User defined handlers are not supported.
     407 * It uses once or twice the multicast RPC_PROCESS_SIGNAL to block, unblock or delete
     408 * all process threads in all clusters, and then delete process descriptors.
     409 *********************************************************************************************
     410 * @ process  : pointer on process descriptor in owner cluster.
     411 * @ sig_id   : signal type.
     412 ********************************************************************************************/
     413void process_make_kill( process_t * process,
     414                        uint32_t    sig_id );
     415
    317416
    318417/********************   File Management Operations   ****************************************/
     
    376475
    377476/*********************************************************************************************
    378  * This function copies all non-zero entries from a remote <src_xp> fd_array,
    379  * embedded in a process descriptor, to another remote <dst_xp> fd_array, embedded
    380  * in another process descriptor. The calling thread can be running in any cluster.
     477 * This function copies all non-zero entries (other than the three first stdin/stdout/stderr)
     478 * from a remote <src_xp> fd_array, embedded in a process descriptor, to another remote
     479 * <dst_xp> fd_array, embedded in another process descriptor.
     480 * The calling thread can be running in any cluster.
    381481 * It takes the remote lock protecting the <src_xp> fd_array during the copy.
    382482 * For each involved file descriptor, the refcount is incremented.
Note: See TracChangeset for help on using the changeset viewer.