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

Fix several bugs in the fork() syscall.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/sys_exec.c

    r407 r408  
    150150// Implementation note:
    151151// This function build an exec_info_t structure containing all informations
    152 // required to create the new process descriptor and the associated thread.
     152// required to initialize the new process descriptor and the associated thread.
     153// It includes the process PID (unchanged), main() arguments, environment variables,
     154// and the pathname to the new process .elf file.
    153155// It calls the process_exec_get_strings() functions to copy the main() arguments and
    154156// the environment variables from user buffers to the exec_info_t structure, allocate
    155157// and call the process_make_exec() function.
    156 // Finally, it destroys the calling thread and process.
     158// As it must destroy all parent process copies, and all parent threads in all clusters,
     159// the process_make_exec() function must be executed in the parent owner cluster,
     160// and this sys_exec() function uses a RPC to access the owner cluster if required.
     161//
    157162// TODO : the args & envs arguments are not supported yet : both must be NULL
    158163/////////////////////////////////////////////////////////////////////////////////////////
     
    169174        tm_start = hal_get_cycles();
    170175
    171     // get pointers on parent process and thread
     176    // get parent process pid
    172177    thread_t   * this    = CURRENT_THREAD;
    173178    process_t  * process = this->process;
     
    177182__FUNCTION__, local_cxy, this->core->lid, pid, (uint32_t)hal_get_cycles() );
    178183
    179 sched_display( 0 );
     184    // get owner cluster
     185    cxy_t  owner_cxy = CXY_FROM_PID( pid );
    180186
    181187    // check pathname length
     
    189195    // copy pathname in exec_info structure (kernel space)
    190196    hal_strcpy_from_uspace( exec_info.path , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
     197
    191198    // check args argument
    192199    assert( (args == NULL) , __FUNCTION__ ,
     
    196203    assert( (envs == NULL) , __FUNCTION__ ,
    197204    "args not supported yet\n" );
    198 
    199     // compute client_cxy (local cluster) and server_cxy (target cluster)
    200     cxy_t     cxy_server = CXY_FROM_PID( pid );
    201     cxy_t     cxy_client = local_cxy;
    202 
    203     // register parent process in exec_info
    204     exec_info.parent_xp   = process->ref_xp;
    205 
    206     // new process keep the parent process PID
    207     exec_info.keep_pid   = true;
    208205
    209206    // check and store args in exec_info structure if required
     
    229226    }
    230227
     228    // register PID in exec_info
     229    exec_info.pid = pid;
     230
    231231    // call process_make_exec (local or remote)
    232     if( cxy_server == cxy_client )
     232    if( owner_cxy == local_cxy )
    233233    {
    234234        error = process_make_exec( &exec_info );
     
    236236    else
    237237    {
    238         rpc_process_exec_client( cxy_server , &exec_info , &error );
     238        rpc_process_make_exec_client( owner_cxy,
     239                                      &exec_info,
     240                                      &error );
    239241    }
    240242
     
    242244    {
    243245        printk("\n[ERROR] in %s : cannot create new process %x in cluster %x\n",
    244         __FUNCTION__, pid, cxy_server );
     246        __FUNCTION__, pid, owner_cxy );
    245247        this->errno = error;
    246248        return -1;
    247249    }
    248 
    249     // FIXME delete the local process descriptor
    250     // process_kill( process );
    251250
    252251    tm_end = hal_get_cycles();
Note: See TracChangeset for help on using the changeset viewer.