Ignore:
Timestamp:
Dec 5, 2017, 4:20:07 PM (4 years ago)
Author:
alain
Message:

Fix several bugs in the fork() syscall.

File:
1 edited

Legend:

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

    r407 r408  
    137137/*********************************************************************************************
    138138 * 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.
     139 * to create a new reference process descriptor, and the associated main thread,
     140 * in the parent process owner cluster.
    140141 ********************************************************************************************/
    141142
    142143typedef struct exec_info_s
    143144{
    144     xptr_t             parent_xp;      /*! extended pointer on parent process descriptor    */
    145     bool_t             keep_pid;       /*! keep parent PID if true / new PID if false       */
     145    pid_t              pid;            /*! process identifier (both parent and child)       */
    146146
    147147    char               path[CONFIG_VFS_MAX_PATH_LENGTH];   /*!  .elf file path              */
     
    187187
    188188/*********************************************************************************************
    189  * This function initializes a new process descriptor, in the reference cluster.
    190  * The PID value must have been defined previously by the owner cluster manager.
    191  * The reference cluster can be different from the owner cluster.
    192  * It set the pid / ppid / ref_xp fields.
    193  * It registers this process descriptor in three lists:
    194  * - the children_list in the parent reference process descriptor.
    195  * - the local_list, rooted in the reference cluster manager.
    196  * - the copies_list, rooted in the owner cluster manager.
    197  * It resets the embedded structures such as the VMM or the file descriptor array.
    198  *********************************************************************************************
    199  * @ process      : [in] pointer on process descriptor to initialize.
    200  * @ pid          : [in] process identifier defined by owner cluster.
    201  * @ parent_xp    : [in] extended pointer on parent process.
     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 * Both the PID and PPID fields are set to zero, and the ref_xp is the local process_zero.
     192 * The th_tbl[] is initialized as empty.
     193 *********************************************************************************************
     194 * @ process      : [in] pointer on local process descriptor to initialize.
     195 ********************************************************************************************/
     196void process_zero_init( process_t * process );
     197
     198/*********************************************************************************************
     199 * This function initializes a local, reference user process descriptor from another process
     200 * descriptor, defined by the <model_xp> argument. The <process> descriptor, the <pid>, and
     201 * 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
     204 *    called once, by the process_init_create() function in cluster[xmax-1][ymax-1].
     205 * 2) if the caller is the process_make_fork() function, the model is generally a remote
     206 *    process, that is also the parent process.
     207 * 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 *
     210 * The following fields are initialised (for all process but process_zero).
     211 * - It set the pid / ppid / ref_xp fields.
     212 * - It initializes an empty VMM (no vsegs registered in VSL and GPT).
     213 * - It initializes the FDT, defining the three pseudo files STDIN / STDOUT / STDERR.
     214 * - It set the root_xp, bin_xp, cwd_xp fields.
     215 * - It reset the children list as empty, but does NOT register it in parent children list.
     216 * - It reset the TH_TBL list of threads as empty.
     217 * - It reset the semaphore / mutex / barrier / condvar lists as empty.
     218 * - It registers the process in the local_list, rooted in the local cluster manager.
     219 * - It registers the process in the copies_list, rooted in the owner cluster manager.
     220 * - It registers the process extended pointer in the local pref_tbl[] array.
     221 *********************************************************************************************
     222 * @ process      : [in] pointer on local process descriptor to initialize.
     223 * @ pid          : [in] process identifier.
     224 * @ ppid         : [in] parent process identifier.
     225 * @ model_xp     : [in] extended pointer on model process descriptor (local or remote).
    202226 ********************************************************************************************/
    203227void process_reference_init( process_t * process,
    204228                             pid_t       pid,
    205                              xptr_t      parent_xp );
     229                             pid_t       ppid,
     230                             xptr_t      model_xp );
    206231
    207232/*********************************************************************************************
     
    249274
    250275/*********************************************************************************************
    251  * This function allocates memory and initializes a new user process descriptor,
    252  * and the associated main thread, from information found in the <exec_info> structure
    253  * (defined in the process.h file), that must be built by the caller.
    254  * - If the <keep_pid> field is true, the new process inherits its PID from the parent PID.
    255  * - If the <keep_pid> field is false, a new PID is allocated from the local cluster manager.
    256  * The new process inherits from the parent process (i) the open file descriptors, (ii) the
    257  * vfs_root and the vfs_cwd inodes.
    258  * It accesses the .elf file to get the size of the code and data segments, and initializes
    259  * the vsegs list in the VMM.
    260  * It is executed in the local cluster, that becomes both "owner" and "reference".
    261  * - It can be called by the process_init_create() function to build the "init" process.
    262  * - It can be called directly by the sys_exec() function in case of local exec.
    263  * - It can be called through the rpc_process_exec_server() function in case of remote exec.
     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.
     278 * The "new" process keep the "old" process PID and PPID, all open files, and env variables,
     279 * 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.
     282 * It completes the "new" process descriptor, from information found in the <exec_info>
     283 * structure (defined in the process.h file), that must be built by the caller.
     284 * 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.
     286 * It is executed in the local cluster, that becomes both the "owner" and the "reference"
     287 * cluster for the "new" process.
    264288 *********************************************************************************************
    265289 * @ exec_info   : [in]  pointer on the exec_info structure.
     
    268292error_t process_make_exec( exec_info_t * exec_info );
    269293
     294/*********************************************************************************************
     295 * This function implement the fork() system call, and is called by the sys_fork() function.
     296 * It allocates memory and initializes a new "child" process descriptor, and the
     297 * associated "child" thread descriptor in the local cluster. This function can involve
     298 * up to three different clusters :
     299 * - 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.
     302 * The new "child" process descriptor is initialised from informations found in the "parent"
     303 * reference process descriptor, containing the complete process description.
     304 * The new "child" thread descriptor is initialised from informations found in the "parent"
     305 * thread descriptor.
     306 *********************************************************************************************
     307 * @ parent_process_xp  : extended pointer on the reference parent process.
     308 * @ parent_thread_xp   : extended pointer on the parent thread requesting the fork.
     309 * @ child_pid          : [out] child process identifier.
     310 * @ child_thread_ptr   : [out] local pointer on child thread in target cluster.
     311 * @ return 0 if success / return non-zero if error.
     312 ********************************************************************************************/
     313error_t process_make_fork(  xptr_t             parent_process_xp,
     314                            xptr_t             parent_thread_xp,
     315                            pid_t            * child_pid,
     316                            struct thread_s ** child_thread_ptr );
    270317
    271318/********************   File Management Operations   ****************************************/
Note: See TracChangeset for help on using the changeset viewer.