Ignore:
Timestamp:
Feb 14, 2018, 3:40:19 PM (4 years ago)
Author:
alain
Message:

blip

File:
1 edited

Legend:

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

    r421 r433  
    149149/////////////////////////////////////////////////////////////////////////////////////////
    150150// Implementation note:
    151 // This function build an exec_info_t structure containing all informations
     151// This function must be called by the main thread (thread 0 in owner cluster).
     152// IT build an exec_info_t structure containing all informations
    152153// required to initialize the new process descriptor and the associated thread.
    153 // It includes the process PID (unchanged), main() arguments, environment variables,
     154// It includes the process main() arguments, the environment variables,
    154155// and the pathname to the new process .elf file.
    155156// It calls the process_exec_get_strings() functions to copy the main() arguments and
     
    169170    error_t       error;
    170171
    171     // get parent process pid
     172    // get calling thread, process, & pid
    172173    thread_t    * this    = CURRENT_THREAD;
    173174    process_t   * process = this->process;
    174175    pid_t         pid     = process->pid;
    175176
    176 #if CONFIG_SYSCALL_DEBUG
     177    assert( (CXY_FROM_PID( pid ) == local_cxy) , __FUNCTION__ ,
     178    "must be called in the owner cluster\n");
     179
     180    assert( (LTID_FROM_TRDID( this->trdid ) == 0) , __FUNCTION__ ,
     181    "must be called by the main thread\n");
     182
     183    assert( (args == NULL) , __FUNCTION__ ,
     184    "args not supported yet\n" );
     185
     186    assert( (envs == NULL) , __FUNCTION__ ,
     187    "args not supported yet\n" );
     188
     189    // get owner cluster
     190
     191    // check pathname length
     192    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
     193    {
     194
     195#if CONFIG_DEBUG_SYSCALLS_ERROR
     196printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     197#endif
     198        this->errno = ENFILE;
     199        return -1;
     200    }
     201
     202    // copy pathname in exec_info structure (kernel space)
     203    hal_strcpy_from_uspace( exec_info.path , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
     204
     205#if CONFIG_DEBUG_SYS_EXEC
    177206uint64_t      tm_start;
    178207uint64_t      tm_end;
    179208tm_start = hal_get_cycles();
    180 printk("\n[DBG] %s : core[%x,%d] enter / process %x / cycle = %d\n",
    181 __FUNCTION__, local_cxy, this->core->lid, pid, (uint32_t)tm_start );
    182 #endif
    183 
    184     // get owner cluster
    185     cxy_t  owner_cxy = CXY_FROM_PID( pid );
    186 
    187     // check pathname length
    188     if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
    189     {
    190         printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
    191         this->errno = ENFILE;
    192         return -1;
    193     }
    194 
    195     // copy pathname in exec_info structure (kernel space)
    196     hal_strcpy_from_uspace( exec_info.path , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
    197 
    198     // check args argument
    199     assert( (args == NULL) , __FUNCTION__ ,
    200     "args not supported yet\n" );
    201 
    202     // check envs argument
    203     assert( (envs == NULL) , __FUNCTION__ ,
    204     "args not supported yet\n" );
     209if( CONFIG_DEBUG_SYS_EXEC < tm_start )
     210printk("\n[DBG] %s : thread %x enter / process %x / path %s / cycle = %d\n",
     211__FUNCTION__, this, pid, exec_info.path, (uint32_t)tm_start );
     212#endif
    205213
    206214    // check and store args in exec_info structure if required
     
    209217        if( process_exec_get_strings( &exec_info , true , args ) )
    210218        {
    211             printk("\n[ERROR] in %s : cannot access args\n", __FUNCTION__ );
     219
     220#if CONFIG_DEBUG_SYSCALLS_ERROR
     221printk("\n[ERROR] in %s : cannot access args\n", __FUNCTION__ );
     222#endif
    212223            this->errno = error;
    213224            return -1;
     
    220231        if( process_exec_get_strings( &exec_info , false , envs ) )
    221232        {
    222             printk("\n[ERROR] in %s : cannot access envs\n", __FUNCTION__ );
     233
     234#if CONFIG_DEBUG_SYCALLS_ERROR
     235printk("\n[ERROR] in %s : cannot access envs\n", __FUNCTION__ );
     236#endif
    223237            this->errno = error;
    224238            return -1;
     
    226240    }
    227241
    228     // register PID in exec_info
    229     exec_info.pid = pid;
    230 
    231     // call process_make_exec (local or remote)
    232     if( owner_cxy == local_cxy )
    233     {
    234         error = process_make_exec( &exec_info );
    235     }
    236     else
    237     {
    238         rpc_process_make_exec_client( owner_cxy,
    239                                       &exec_info,
    240                                       &error );
    241     }
     242    // call relevant kernel function
     243    error = process_make_exec( &exec_info );
    242244
    243245    if( error )
    244246    {
    245         printk("\n[ERROR] in %s : cannot create new process %x in cluster %x\n",
    246         __FUNCTION__, pid, owner_cxy );
     247
     248#if CONFIG_DEBUG_SYSCALLS_ERROR
     249printk("\n[ERROR] in %s : cannot create process %x in cluster %x\n",
     250__FUNCTION__, pid, CXY_FROM_PID( pid );
     251#endif
    247252        this->errno = error;
    248253        return -1;
    249254    }
    250255
    251 #if CONFIG_SYSCALL_DEBUG
     256#if CONFIG_DEBUG_SYS_EXEC
    252257tm_end = hal_get_cycles();
    253 printk("\n[DBG] %s : core[%x,%d] exit / process %x / path = %s / cost = %d / cycle %d\n",
    254 __FUNCTION__, local_cxy, this->core->lid, pid, exec_info.path,
    255 (uint32_t)(tm_end - tm_start) , (uint32_t)tm_end );
    256 #endif
    257 
    258     return 0;
     258if( CONFIG_DEBUG_SYS_EXEC < tm_end )
     259printk("\n[DBG] %s : thread %x exit / process %x / cost = %d / cycle %d\n",
     260__FUNCTION__, this, pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
     261#endif
     262
     263    // deschedule <=> old thread suicide because the BLOCKED_GLOBAL
     264    // and the FLAG_REQ_DELETE have been set by process_make_exec()
     265    sched_yield( "old process suicide in sys_exec()" );
     266
     267    assert( false , __FUNCTION__ , "This code should not be executed\n" );
     268
     269    return 0; 
    259270
    260271} // end sys_exec()
Note: See TracChangeset for help on using the changeset viewer.