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/kern/process.c

    r407 r408  
    8282}
    8383
     84/////////////////////////////////////////////
     85void process_zero_init( process_t * process )
     86{
     87    // initialize PID, PPID anf PREF
     88    process->pid    = 0;
     89    process->ppid   = 0;
     90    process->ref_xp = XPTR( local_cxy , process );
     91
     92    // reset th_tbl[] array as empty
     93    uint32_t i;
     94    for( i = 0 ; i < CONFIG_THREAD_MAX_PER_CLUSTER ; i++ )
     95        {
     96        process->th_tbl[i] = NULL;
     97    }
     98    process->th_nr  = 0;
     99    spinlock_init( &process->th_lock );
     100
     101        hal_fence();
     102
     103process_dmsg("\n[DBG] %s : core[%x,%d] exit for process %x\n",
     104__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , process->pid );
     105
     106}  // end process_zero_init()
     107
    84108/////////////////////////////////////////////////
    85109void process_reference_init( process_t * process,
    86110                             pid_t       pid,
    87                              xptr_t      parent_xp )
    88 {
    89     cxy_t       parent_cxy;
    90     process_t * parent_ptr;
    91     pid_t       parent_pid;
    92 
     111                             pid_t       ppid,
     112                             xptr_t      model_xp )
     113{
     114    cxy_t       model_cxy;
     115    process_t * model_ptr;
    93116        error_t     error1;
    94117        error_t     error2;
     
    104127__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , pid );
    105128
    106     // get parent process cluster, local pointer, and pid
    107     // for all processes other than kernel process
    108     if( process == &process_zero )                   // kernel process
    109     {
    110         assert( (pid == 0) , __FUNCTION__ , "process_zero must have PID = 0\n");
    111 
    112         parent_cxy = 0;
    113         parent_ptr = NULL;
    114         parent_pid = 0;     
    115     }
    116     else                                             // user process
    117     {
    118         parent_cxy = GET_CXY( parent_xp );
    119         parent_ptr = (process_t *)GET_PTR( parent_xp );
    120         parent_pid = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) );
    121     }
     129    // get model process cluster and local pointer
     130    model_cxy = GET_CXY( model_xp );
     131    model_ptr = (process_t *)GET_PTR( model_xp );
    122132
    123133    // initialize PID, PPID, and REF
    124134        process->pid    = pid;
    125     process->ppid   = parent_pid;
     135    process->ppid   = ppid;
    126136    process->ref_xp = XPTR( local_cxy , process );
    127137
    128     // initialize vmm, fd array and others structures for user processes.
    129     // These structures are not used by the kernel process.
    130     if( pid )
    131     {
    132         // initialize vmm (not for kernel)
    133         vmm_init( process );
    134 
    135 process_dmsg("\n[DBG] %s : core[%x,%d] / vmm initialised for process %x\n",
     138    // initialize vmm
     139    vmm_init( process );
     140
     141process_dmsg("\n[DBG] %s : core[%x,%d] / vmm empty for process %x\n",
    136142__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , pid );
    137143
    138         // initialize fd_array (not for kernel)
    139         process_fd_init( process );
    140 
    141         // create stdin / stdout / stderr pseudo-files (not for kernel)
    142         if( parent_pid == 0 )                                              // process_init
    143         {
    144             error1 = vfs_open( process,
    145                                CONFIG_INIT_STDIN,
    146                                O_RDONLY,
    147                                0,                // FIXME chmod
    148                                &stdin_xp,
    149                                &stdin_id );
    150 
    151             error2 = vfs_open( process,
    152                                CONFIG_INIT_STDOUT,
    153                                O_WRONLY,
    154                                0,                // FIXME chmod
    155                                &stdout_xp,
    156                                &stdout_id );
    157 
    158             error3 = vfs_open( process,
    159                                CONFIG_INIT_STDERR,
    160                                O_WRONLY,
    161                                0,                // FIXME chmod
    162                                &stderr_xp,
    163                                &stderr_id );
    164         }
    165         else                                                               // user process
    166         {
    167             error1 = vfs_open( process,
    168                                CONFIG_USER_STDIN,
    169                                O_RDONLY,
    170                                0,                // FIXME chmod
    171                                &stdin_xp,
    172                                &stdin_id );
    173 
    174             error2 = vfs_open( process,
    175                                CONFIG_USER_STDOUT,
    176                                O_WRONLY,
    177                                0,                // FIXME chmod
    178                                &stdout_xp,
    179                                &stdout_id );
    180 
    181             error3 = vfs_open( process,
    182                                CONFIG_USER_STDERR,
    183                                O_WRONLY,
    184                                0,                // FIXME chmod
    185                                &stderr_xp,
    186                                &stderr_id );
    187         }
    188 
    189         assert( ((error1 == 0) && (error2 == 0) && (error3 == 0)) , __FUNCTION__ ,
    190         "cannot open stdin/stdout/stderr pseudo files\n");
    191 
    192         assert( ((stdin_id == 0) && (stdout_id == 1) && (stderr_id == 2)) , __FUNCTION__ ,
    193         "bad indexes : stdin %d / stdout %d / stderr %d \n", stdin_id , stdout_id , stderr_id );
     144    // initialize fd_array (not for kernel)
     145    process_fd_init( process );
     146
     147    // create stdin / stdout / stderr pseudo-files
     148    if( ppid == 0 )                                        // process_init
     149    {
     150        error1 = vfs_open( process,
     151                           CONFIG_INIT_STDIN,
     152                           O_RDONLY,
     153                           0,                // FIXME chmod
     154                           &stdin_xp,
     155                           &stdin_id );
     156
     157        error2 = vfs_open( process,
     158                           CONFIG_INIT_STDOUT,
     159                           O_WRONLY,
     160                           0,                // FIXME chmod
     161                           &stdout_xp,
     162                           &stdout_id );
     163
     164        error3 = vfs_open( process,
     165                           CONFIG_INIT_STDERR,
     166                           O_WRONLY,
     167                           0,                // FIXME chmod
     168                           &stderr_xp,
     169                           &stderr_id );
     170    }
     171    else                                                  // other user process
     172    {
     173        error1 = vfs_open( process,
     174                           CONFIG_USER_STDIN,
     175                           O_RDONLY,
     176                           0,                // FIXME chmod
     177                           &stdin_xp,
     178                           &stdin_id );
     179
     180        error2 = vfs_open( process,
     181                           CONFIG_USER_STDOUT,
     182                           O_WRONLY,
     183                           0,                // FIXME chmod
     184                           &stdout_xp,
     185                           &stdout_id );
     186
     187        error3 = vfs_open( process,
     188                           CONFIG_USER_STDERR,
     189                           O_WRONLY,
     190                           0,                // FIXME chmod
     191                           &stderr_xp,
     192                           &stderr_id );
     193    }
     194
     195    assert( ((error1 == 0) && (error2 == 0) && (error3 == 0)) , __FUNCTION__ ,
     196    "cannot open stdin/stdout/stderr pseudo files\n");
     197
     198    assert( ((stdin_id == 0) && (stdout_id == 1) && (stderr_id == 2)) , __FUNCTION__ ,
     199    "bad indexes : stdin %d / stdout %d / stderr %d \n", stdin_id , stdout_id , stderr_id );
     200
     201    // initialize specific files, cwd_lock, and fd_array
     202    process->vfs_root_xp = (xptr_t)hal_remote_lwd( XPTR( model_cxy,
     203                                                         &model_ptr->vfs_root_xp ) );
     204    process->vfs_cwd_xp  = (xptr_t)hal_remote_lwd( XPTR( model_cxy,
     205                                                         &model_ptr->vfs_cwd_xp ) );
     206    process->vfs_bin_xp  = (xptr_t)hal_remote_lwd( XPTR( model_cxy,
     207                                                         &model_ptr->vfs_bin_xp ) );
     208    vfs_file_count_up( process->vfs_root_xp );
     209    vfs_file_count_up( process->vfs_cwd_xp );
     210    vfs_file_count_up( process->vfs_bin_xp );
     211
     212    process_fd_remote_copy( XPTR( local_cxy , &process->fd_array ),
     213                            XPTR( model_cxy , &model_ptr->fd_array ) );
     214
     215    remote_rwlock_init( XPTR( local_cxy , &process->cwd_lock ) );
    194216
    195217process_dmsg("\n[DBG] %s : core[%x,%d] / fd array initialised for process %x\n",
    196218__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , pid );
    197219
    198 
    199         // reset reference process files structures and cwd_lock (not for kernel)
    200             process->vfs_root_xp     = XPTR_NULL;
    201             process->vfs_bin_xp      = XPTR_NULL;
    202             process->vfs_cwd_xp      = XPTR_NULL;
    203         remote_rwlock_init( XPTR( local_cxy , &process->cwd_lock ) );
    204 
    205         // reset children list root (not for kernel)
    206         xlist_root_init( XPTR( local_cxy , &process->children_root ) );
    207             process->children_nr     = 0;
    208 
    209         // reset semaphore / mutex / barrier / condvar list roots (nor for kernel)
    210         xlist_root_init( XPTR( local_cxy , &process->sem_root ) );
    211         xlist_root_init( XPTR( local_cxy , &process->mutex_root ) );
    212         xlist_root_init( XPTR( local_cxy , &process->barrier_root ) );
    213         xlist_root_init( XPTR( local_cxy , &process->condvar_root ) );
    214         remote_spinlock_init( XPTR( local_cxy , &process->sync_lock ) );
    215 
    216         // register new process in the parent children list (nor for kernel)
    217         xptr_t entry = XPTR( local_cxy  , &process->brothers_list );
    218         xptr_t root  = XPTR( parent_cxy , &parent_ptr->children_root );
    219         xlist_add_first( root , entry );
    220     }
    221 
    222     // reset th_tbl[] array as empty
     220    // reset children list root
     221    xlist_root_init( XPTR( local_cxy , &process->children_root ) );
     222    process->children_nr     = 0;
     223
     224    // reset semaphore / mutex / barrier / condvar list roots
     225    xlist_root_init( XPTR( local_cxy , &process->sem_root ) );
     226    xlist_root_init( XPTR( local_cxy , &process->mutex_root ) );
     227    xlist_root_init( XPTR( local_cxy , &process->barrier_root ) );
     228    xlist_root_init( XPTR( local_cxy , &process->condvar_root ) );
     229    remote_spinlock_init( XPTR( local_cxy , &process->sync_lock ) );
     230
     231    // register new process in the local cluster manager pref_tbl[]
     232    lpid_t lpid = LPID_FROM_PID( pid );
     233    LOCAL_CLUSTER->pmgr.pref_tbl[lpid] = XPTR( local_cxy , process );
     234
     235    // register new process descriptor in local cluster manager local_list
     236    cluster_process_local_link( process );
     237
     238    // register new process descriptor in local cluster manager copies_list
     239    cluster_process_copies_link( process );
     240
     241    // reset th_tbl[] array as empty in process descriptor
    223242    uint32_t i;
    224243    for( i = 0 ; i < CONFIG_THREAD_MAX_PER_CLUSTER ; i++ )
     
    228247    process->th_nr  = 0;
    229248    spinlock_init( &process->th_lock );
    230 
    231     // register new process descriptor in local cluster manager local_list
    232     cluster_process_local_link( process );
    233 
    234     // register new process descriptor in owner cluster manager copies_list
    235     cluster_process_copies_link( process );
    236 
    237     // initialize signal manager TODO [AG]
    238249
    239250        hal_fence();
     
    370381    uint32_t       count;     // thread counter
    371382
    372 printk("\n@@@ %s enter\n", __FUNCTION__ );
     383printk("\n[@@@] %s enter\n", __FUNCTION__ );
    373384
    374385    // get lock protecting th_tbl[]
     
    390401    }
    391402
    392 printk("\n@@@ %s : %d signal(s) sent\n", __FUNCTION__, count );
     403printk("\n[@@@] %s : %d signal(s) sent\n", __FUNCTION__, count );
    393404
    394405    // second loop on threads to wait acknowledge from scheduler,
     
    403414        {
    404415
    405 printk("\n@@@ %s start polling at cycle %d\n", __FUNCTION__ , hal_time_stamp() );
     416printk("\n[@@@] %s start polling at cycle %d\n", __FUNCTION__ , hal_time_stamp() );
    406417
    407418            // poll the THREAD_SIG_KILL bit until reset
    408419            while( thread->signals & THREAD_SIG_KILL ) asm volatile( "nop" );
    409420
    410 printk("\n@@@ %s exit polling\n", __FUNCTION__ );
     421printk("\n[@@@] %s exit polling\n", __FUNCTION__ );
    411422
    412423            // detach target thread from parent if attached
     
    424435    }
    425436
    426 printk("\n@@@ %s : %d ack(s) received\n", __FUNCTION__, count );
     437printk("\n[@@@] %s : %d ack(s) received\n", __FUNCTION__, count );
    427438
    428439    // release lock protecting th_tbl[]
     
    432443    process_destroy( process );
    433444
    434 printk("\n[@@@] %s : core[%x,%d] exit\n",
     445printk("\n[DBG] %s : core[%x,%d] exit\n",
    435446__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid );
    436447
     
    688699}  // process_remove_thread()
    689700
     701/////////////////////////////////////////////////////////
     702error_t process_make_fork( xptr_t      parent_process_xp,
     703                           xptr_t      parent_thread_xp,
     704                           pid_t     * child_pid,
     705                           thread_t ** child_thread )
     706{
     707    process_t * process;         // local pointer on child process descriptor
     708    thread_t  * thread;          // local pointer on child thread descriptor
     709    pid_t       new_pid;         // process identifier for child process
     710    pid_t       parent_pid;      // process identifier for parent process
     711    xptr_t      ref_xp;          // extended pointer on reference process
     712    error_t     error;
     713
     714    // get cluster and local pointer for parent process
     715    cxy_t       parent_process_cxy = GET_CXY( parent_process_xp );
     716    process_t * parent_process_ptr = (process_t *)GET_PTR( parent_process_xp );
     717
     718    // get parent process PID
     719    parent_pid = hal_remote_lw( XPTR( parent_process_cxy , &parent_process_ptr->pid ) );
     720   
     721    // check parent process is the reference
     722    ref_xp = hal_remote_lwd( XPTR( parent_process_cxy , &parent_process_ptr->ref_xp ) );
     723    assert( (parent_process_xp == ref_xp ) , __FUNCTION__ ,
     724    "parent process must be the reference process\n" );
     725
     726process_dmsg("\n[DBG] %s : core[%x,%d] enter at cycle %d\n",
     727__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid , hal_get_cycles() );
     728
     729    // allocate a process descriptor
     730    process = process_alloc();
     731    if( process == NULL )
     732    {
     733        printk("\n[ERROR] in %s : cannot get process in cluster %x\n",
     734        __FUNCTION__, local_cxy );
     735        return -1;
     736    }
     737
     738process_dmsg("\n[DBG] %s : core[%x,%d] child process descriptor allocated at cycle %d\n",
     739 __FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, hal_get_cycles() );
     740
     741    // allocate a child PID from local cluster
     742    error = cluster_pid_alloc( XPTR( local_cxy , process ) , &new_pid );
     743    if( (error != 0) || (new_pid == 0) )
     744    {
     745        printk("\n[ERROR] in %s : cannot get PID in cluster %x\n",
     746        __FUNCTION__, local_cxy );
     747        process_free( process );
     748        return -1;
     749    }
     750
     751process_dmsg("\n[DBG] %s : core[%x, %d] child process PID allocated = %x at cycle %d\n",
     752 __FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, new_pid , hal_get_cycles() );
     753
     754    // initializes child process descriptor from parent process descriptor
     755    process_reference_init( process,
     756                            new_pid,
     757                            parent_pid,
     758                            parent_process_xp );
     759
     760process_dmsg("\n[DBG] %s : core[%x, %d] child process initialised at cycle %d\n",
     761__FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, hal_get_cycles() );
     762
     763    // copy VMM from parent descriptor to child descriptor
     764    error = vmm_fork_copy( process,
     765                           parent_process_xp );
     766    if( error )
     767    {
     768        printk("\n[ERROR] in %s : cannot copy VMM in cluster %x\n",
     769        __FUNCTION__, local_cxy );
     770        process_free( process );
     771        cluster_pid_release( new_pid );
     772        return -1;
     773    }
     774
     775process_dmsg("\n[DBG] %s : core[%x, %d] child process VMM copied at cycle %d\n",
     776__FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, hal_get_cycles() );
     777
     778    // create child thread descriptor from parent thread descriptor
     779    error = thread_user_fork( parent_thread_xp,
     780                              process,
     781                              &thread );
     782    if( error )
     783    {
     784        printk("\n[ERROR] in %s : cannot create thread in cluster %x\n",
     785        __FUNCTION__, local_cxy );
     786        process_free( process );
     787        cluster_pid_release( new_pid );
     788        return -1;
     789    }
     790
     791process_dmsg("\n[DBG] %s : core[%x,%d] child thread created at cycle %d\n",
     792__FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, hal_get_cycles() );
     793
     794    // update parent process GPT to set Copy_On_Write for shared data vsegs
     795    // this includes all replicated GPT copies
     796    if( parent_process_cxy == local_cxy )   // reference is local
     797    {
     798        vmm_set_cow( parent_process_ptr );
     799    }
     800    else                                    // reference is remote
     801    {
     802        rpc_vmm_set_cow_client( parent_process_cxy,
     803                                parent_process_ptr );
     804    }
     805
     806process_dmsg("\n[DBG] %s : core[%x,%d] COW set in parent_process at cycle %d\n",
     807__FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, hal_get_cycles() );
     808
     809    // update children list in parent process
     810        xlist_add_last( XPTR( parent_process_cxy , &parent_process_ptr->children_root ),
     811                    XPTR( local_cxy , &process->brothers_list ) );
     812        hal_remote_atomic_add( XPTR( parent_process_cxy,
     813                                 &parent_process_ptr->children_nr), 1 );
     814
     815// vmm_display( process , true );
     816// vmm_display( parent_process_ptr , true );
     817// sched_display( 0 );
     818
     819    // return success
     820    *child_thread = thread;
     821    *child_pid    = new_pid;
     822
     823    return 0;
     824
     825}  // end process_make_fork()
     826
    690827/////////////////////////////////////////////////////
    691828error_t process_make_exec( exec_info_t  * exec_info )
    692829{
    693     char           * path;                            // pathname to .elf file
    694     bool_t           keep_pid;                        // new process keep parent PID if true
    695     process_t      * process;                         // local pointer on new process
    696     pid_t            pid;                             // new process pid
    697     xptr_t           parent_xp;                       // extended pointer on parent process
    698     cxy_t            parent_cxy;                      // parent process local cluster
    699     process_t      * parent_ptr;                      // local pointer on parent process
    700     uint32_t         parent_pid;                      // parent process identifier
    701     thread_t       * thread;                          // pointer on new thread
    702     pthread_attr_t   attr;                            // main thread attributes
    703     core_t         * core;                            // pointer on selected core
    704     lid_t            lid;                             // selected core local index
     830    char           * path;                    // pathname to .elf file
     831    process_t      * old;                     // local pointer on old process
     832    process_t      * new;                     // local pointer on new process
     833    pid_t            pid;                     // old process identifier
     834    thread_t       * thread;                  // pointer on new thread
     835    pthread_attr_t   attr;                    // main thread attributes
     836    lid_t            lid;                     // selected core local index
    705837        error_t          error;
    706838
    707         // get .elf pathname, parent_xp, and keep_pid flag from exec_info
    708         path      = exec_info->path;
    709     parent_xp = exec_info->parent_xp;
    710     keep_pid  = exec_info->keep_pid;
    711 
    712 process_dmsg("\n[DBG] %s : core[%x,%d] enters for path = %s\n",
    713 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, path );
    714 
    715     // get parent process cluster and local pointer
    716     parent_cxy = GET_CXY( parent_xp );
    717     parent_ptr = (process_t *)GET_PTR( parent_xp );
    718     parent_pid = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) );
    719 
    720     // allocates memory for process descriptor
    721         process = process_alloc();
    722         if( process == NULL ) return -1;
    723 
    724     // get PID
    725     if( keep_pid )    // keep parent PID
    726     {
    727         pid = parent_pid;
    728     }
    729     else              // get new PID from local cluster
    730     {
    731         error = cluster_pid_alloc( XPTR( local_cxy , process ) , &pid );
    732         if( error ) return -1;
    733     }
    734 
    735 process_dmsg("\n[DBG] %s : core[%x,%d] created process %x for path = %s\n",
     839        // get .elf pathname and PID from exec_info
     840        path = exec_info->path;
     841    pid  = exec_info->pid;
     842
     843    // check local cluster is old process owner
     844    assert( (CXY_FROM_PID( pid ) == local_cxy), __FUNCTION__,
     845    "local cluster %x is not owner for process %x\n", local_cxy, pid );
     846
     847exec_dmsg("\n[DBG] %s : core[%x,%d] enters for process %x / path = %s\n",
     848__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, pid , path );
     849
     850    // get old process local pointer
     851    old = (process_t *)cluster_get_local_process_from_pid( pid );
     852   
     853    assert( (old != NULL ) , __FUNCTION__ ,
     854    "process %x not found in cluster %x\n", pid , local_cxy );
     855
     856    // allocate memory for new process descriptor
     857    new = process_alloc();
     858
     859    // initialize new process descriptor
     860    process_reference_init( new,
     861                            old->pid,                   // same as old
     862                            old->ppid,                  // same as old
     863                            XPTR( local_cxy , old ) );
     864
     865exec_dmsg("\n[DBG] %s : core[%x,%d] created new process %x / path = %s\n",
    736866__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, pid, path );
    737867
    738     // initialize the process descriptor as the reference
    739     process_reference_init( process , pid , parent_xp );
    740 
    741 process_dmsg("\n[DBG] %s : core[%x,%d] initialized process %x / path = %s\n",
    742 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, pid, path );
    743 
    744     // initialize vfs_root and vfs_cwd from parent process
    745     xptr_t  vfs_root_xp = hal_remote_lwd( XPTR( parent_cxy , &parent_ptr->vfs_root_xp ) );
    746         vfs_file_count_up( vfs_root_xp );
    747         process->vfs_root_xp = vfs_root_xp;
    748 
    749     xptr_t  vfs_cwd_xp = hal_remote_lwd( XPTR( parent_cxy , &parent_ptr->vfs_cwd_xp ) );
    750         vfs_file_count_up( vfs_cwd_xp );
    751         process->vfs_cwd_xp = vfs_cwd_xp;
    752 
    753     // initialize embedded fd_array from parent process
    754     process_fd_remote_copy( XPTR( local_cxy  , &process->fd_array ),
    755                             XPTR( parent_cxy , &parent_ptr->fd_array) );
    756 
    757 process_dmsg("\n[DBG] %s :  core[%x,%d] copied fd_array for process %x\n",
    758 __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, pid );
    759 
    760     // register "code" and "data" vsegs as well as the process entry-point in VMM,
    761     // using information contained in the elf file.
    762         error = elf_load_process( path , process );
    763 
    764         if( error )
     868    // register "code" and "data" vsegs as well as entry-point
     869    // in new process VMM, using information contained in the elf file.
     870        if( elf_load_process( path , new ) )
    765871        {
    766872                printk("\n[ERROR] in %s : failed to access .elf file for process %x / path = %s\n",
    767                        __FUNCTION__, pid , path );
    768         process_destroy( process );
    769         return error;
     873                __FUNCTION__, pid , path );
     874        process_destroy( new );
     875        return -1;
    770876        }
    771877
    772 process_dmsg("\n[DBG] %s : core[%x,%d] registered code/data vsegs for process %x / path = %s\n",
     878exec_dmsg("\n[DBG] %s : core[%x,%d] registered code/data vsegs / process %x / path = %s\n",
    773879__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, pid, path );
    774880
    775     // select a core in cluster
     881    // select a core in local cluster to execute the main thread
    776882    lid  = cluster_select_local_core();
    777     core = &LOCAL_CLUSTER->core_tbl[lid];
    778883
    779884    // initialize pthread attributes for main thread
     
    784889    // create and initialize thread descriptor
    785890        error = thread_user_create( pid,
    786                                 (void *)process->vmm.entry_point,
     891                                (void *)new->vmm.entry_point,
    787892                                exec_info->args_pointers,
    788893                                &attr,
     
    792897                printk("\n[ERROR] in %s : cannot create thread for process %x / path = %s\n",
    793898                       __FUNCTION__, pid , path );
    794         process_destroy( process );
    795         return error;
     899        process_destroy( new );
     900        return -1;
    796901        }
    797902
    798 process_dmsg("\n[DBG] %s : core[%x,%d] created thread %x for process %x / path = %s\n",
    799 __FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, thread->trdid, pid, path  );
    800 
    801     // update children list in parent process
    802         xlist_add_last( XPTR( parent_cxy , &parent_ptr->children_root ),
    803                     XPTR( local_cxy  , &process->brothers_list ) );
    804         hal_remote_atomic_add( XPTR( parent_cxy , &parent_ptr->children_nr) , 1 );
     903exec_dmsg("\n[DBG] %s : core[%x,%d] created main thread %x for new process %x\n",
     904__FUNCTION__ , local_cxy, CURRENT_THREAD->core->lid, thread->trdid, pid );
     905
     906    // update children list (rooted in parent process)
     907        xlist_replace( XPTR( local_cxy , &old->brothers_list ) ,
     908                   XPTR( local_cxy , &new->brothers_list ) );
     909
     910    // FIXME request destruction of old process copies and threads in all clusters
    805911
    806912    // activate new thread
    807913        thread_unblock( XPTR( local_cxy , thread ) , THREAD_BLOCKED_GLOBAL );
    808914
    809 process_dmsg("\n[DBG] %s : core[%x,%d] exit for path = %s\n",
     915exec_dmsg("\n[DBG] %s : core[%x,%d] exit for path = %s\n",
    810916__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, path  );
    811917
     
    818924{
    819925    exec_info_t   exec_info;     // structure to be passed to process_make_exec()
    820     xptr_t        parent_xp;     // extended pointer on parent process.
     926    process_t   * process;       // local pointer on process_init descriptor
     927    pid_t         pid;           // process_init identifier
    821928    error_t       error;
    822929
     
    824931__FUNCTION__ , local_cxy );
    825932
    826     // parent process is local kernel process
    827     parent_xp = XPTR( local_cxy , &process_zero );
     933    // allocates memory for process descriptor from local cluster
     934        process = process_alloc();
     935        if( process == NULL )
     936    {
     937                printk("\n[PANIC] in %s : no memory for process descriptor in cluster %x\n",
     938                __FUNCTION__, local_cxy );
     939    }
     940
     941    // get new PID from local cluster
     942    error = cluster_pid_alloc( XPTR( local_cxy , process ) , &pid );
     943    if( error )
     944    {
     945                printk("\n[PANIC] in %s : cannot allocate PID in cluster %x\n",
     946                __FUNCTION__, local_cxy );
     947    }
     948
     949    // initialise the process desciptor (parent is local kernel process)
     950    process_reference_init( process,
     951                            pid,
     952                            process_zero.pid,
     953                            XPTR( local_cxy , &process_zero ) );
    828954
    829955    // initialize the exec_info structure
    830     exec_info.keep_pid     = false;
    831     exec_info.parent_xp    = parent_xp;
    832     strcpy( exec_info.path , CONFIG_PROCESS_INIT_PATH );
     956    exec_info.pid          = pid;
    833957    exec_info.args_nr      = 0;
    834958    exec_info.envs_nr      = 0;
    835 
    836     // initialize process_init and create thread_init
     959    strcpy( exec_info.path , CONFIG_PROCESS_INIT_PATH );
     960
     961    // update process descriptor and create thread descriptor
    837962        error = process_make_exec( &exec_info );
    838963
    839         if( error ) panic("cannot initialize process_init in cluster %x", local_cxy );
     964        if( error )
     965    {
     966                printk("\n[PANIC] in %s : cannot exec %s in cluster %x\n",
     967                __FUNCTION__, CONFIG_PROCESS_INIT_PATH , local_cxy );
     968    }
    840969
    841970process_dmsg("\n[DBG] %s : exit in cluster %x\n",
Note: See TracChangeset for help on using the changeset viewer.