Ignore:
Timestamp:
Apr 10, 2019, 10:09:39 AM (2 years ago)
Author:
alain
Message:

Fix a bug in the vmm_remove_vseg() function: the physical pages
associated to an user DATA vseg were released to the kernel when
the target process descriptor was in the reference cluster.
This physical pages release should be done only when the page
forks counter value is zero.
All other modifications are cosmetic.

File:
1 edited

Legend:

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

    r624 r625  
    9191}
    9292
    93 /////////////////////////////////////////////////
    94 void process_reference_init( process_t * process,
    95                              pid_t       pid,
    96                              xptr_t      parent_xp )
    97 {
     93////////////////////////////////////////////////////
     94error_t process_reference_init( process_t * process,
     95                                pid_t       pid,
     96                                xptr_t      parent_xp )
     97{
     98    error_t     error;
    9899    xptr_t      process_xp;
    99100    cxy_t       parent_cxy;
     
    105106    uint32_t    stdout_id;
    106107    uint32_t    stderr_id;
    107     error_t     error;
    108108    uint32_t    txt_id;
    109109    char        rx_path[40];
     
    111111    xptr_t      file_xp;
    112112    xptr_t      chdev_xp;
    113     chdev_t chdev_ptr;
     113    chdev_t   * chdev_ptr;
    114114    cxy_t       chdev_cxy;
    115115    pid_t       parent_pid;
     116    vmm_t     * vmm;
    116117
    117118    // build extended pointer on this reference process
    118119    process_xp = XPTR( local_cxy , process );
     120
     121    // get pointer on process vmm
     122    vmm = &process->vmm;
    119123
    120124    // get parent process cluster and local pointer
     
    129133uint32_t cycle = (uint32_t)hal_get_cycles();
    130134if( DEBUG_PROCESS_REFERENCE_INIT < cycle )
    131 printk("\n[%s] thread[%x,%x] enter to initalialize process %x / cycle %d\n",
    132 __FUNCTION__, parent_pid, this->trdid, pid, cycle );
     135printk("\n[%s] thread[%x,%x] enter to initialize process %x / cycle %d\n",
     136__FUNCTION__, this->process->pid, this->trdid, pid, cycle );
    133137#endif
    134138
     
    144148    process->cwd_xp      = hal_remote_l64( XPTR( parent_cxy, &parent_ptr->cwd_xp ) );
    145149
    146     // initialize vmm as empty
    147     error = vmm_init( process );
    148 
    149 assert( (error == 0) , "cannot initialize VMM\n" );
     150    // initialize VSL as empty
     151    vmm->vsegs_nr = 0;
     152        xlist_root_init( XPTR( local_cxy , &vmm->vsegs_root ) );
     153
     154    // create an empty GPT as required by the architecture
     155    error = hal_gpt_create( &vmm->gpt );
     156    if( error )
     157    {
     158        printk("\n[ERROR] in %s : cannot create empty GPT\n", __FUNCTION__ );
     159        return -1;
     160    }
     161
     162#if (DEBUG_PROCESS_REFERENCE_INIT & 1)
     163if( DEBUG_PROCESS_REFERENCE_INIT < cycle )
     164printk("\n[%s] thread[%x,%x] created empty GPT for process %x\n",
     165__FUNCTION__, parent_pid, this->trdid, pid );
     166#endif
     167
     168    // initialize GPT and VSL locks
     169    remote_rwlock_init( XPTR( local_cxy , &vmm->gpt_lock ) , LOCK_VMM_GPT );
     170        remote_rwlock_init( XPTR( local_cxy , &vmm->vsl_lock ) , LOCK_VMM_VSL );
     171
     172    // register kernel vsegs in VMM as required by the architecture
     173    error = hal_vmm_kernel_update( process );
     174    if( error )
     175    {
     176        printk("\n[ERROR] in %s : cannot register kernel vsegs in VMM\n", __FUNCTION__ );
     177        return -1;
     178    }
     179
     180#if (DEBUG_PROCESS_REFERENCE_INIT & 1)
     181if( DEBUG_PROCESS_REFERENCE_INIT < cycle )
     182printk("\n[%s] thread[%x,%x] registered kernel vsegs for process %x\n",
     183__FUNCTION__, parent_pid, this->trdid, pid );
     184#endif
     185
     186    // create "args" and "envs" vsegs
     187    // create "stacks" and "mmap" vsegs allocators
     188    // initialize locks protecting GPT and VSL
     189    error = vmm_user_init( process );
     190    if( error )
     191    {
     192        printk("\n[ERROR] in %s : cannot register user vsegs in VMM\n", __FUNCTION__ );
     193        return -1;
     194    }
    150195 
    151196#if (DEBUG_PROCESS_REFERENCE_INIT & 1)
    152197cycle = (uint32_t)hal_get_cycles();
    153198if( DEBUG_PROCESS_REFERENCE_INIT < cycle )
    154 printk("\n[%s] thread[%x,%x] / vmm empty for process %x / cycle %d\n",
    155 __FUNCTION__, parent_pid, this->trdid, pid, cycle );
     199printk("\n[%s] thread[%x,%x] initialized vmm for process %x\n",
     200__FUNCTION__, parent_pid, this->trdid, pid );
    156201#endif
    157202
     
    187232                           &stdin_xp,
    188233                           &stdin_id );
    189 
    190 assert( (error == 0) , "cannot open stdin pseudo file" );
     234        if( error )
     235        {
     236            printk("\n[ERROR] in %s : cannot open stdout pseudo-file\n", __FUNCTION__ );
     237            return -1;
     238        }
     239
    191240assert( (stdin_id == 0) , "stdin index must be 0" );
    192241
     
    206255                           &stdout_xp,
    207256                           &stdout_id );
    208 
    209         assert( (error == 0) , "cannot open stdout pseudo file" );
    210         assert( (stdout_id == 1) , "stdout index must be 1" );
     257        if( error )
     258        {
     259            printk("\n[ERROR] in %s : cannot open stdout pseudo-file\n", __FUNCTION__ );
     260            return -1;
     261        }
     262
     263assert( (stdout_id == 1) , "stdout index must be 1" );
    211264
    212265#if (DEBUG_PROCESS_REFERENCE_INIT & 1)
     
    225278                           &stderr_xp,
    226279                           &stderr_id );
    227 
    228         assert( (error == 0) , "cannot open stderr pseudo file" );
    229         assert( (stderr_id == 2) , "stderr index must be 2" );
     280        if( error )
     281        {
     282            printk("\n[ERROR] in %s : cannot open stderr pseudo-file\n", __FUNCTION__ );
     283            return -1;
     284        }
     285
     286assert( (stderr_id == 2) , "stderr index must be 2" );
    230287
    231288#if (DEBUG_PROCESS_REFERENCE_INIT & 1)
     
    240297    {
    241298        // get extended pointer on stdin pseudo file in parent process
    242         file_xp = (xptr_t)hal_remote_l64( XPTR( parent_cxy , &parent_ptr->fd_array.array[0] ) );
     299        file_xp = (xptr_t)hal_remote_l64( XPTR( parent_cxy,
     300                                                &parent_ptr->fd_array.array[0] ) );
    243301
    244302        // get extended pointer on parent process TXT chdev
     
    261319
    262320    // initialize lock protecting CWD changes
    263     remote_busylock_init( XPTR( local_cxy , &process->cwd_lock ), LOCK_PROCESS_CWD );
     321    remote_busylock_init( XPTR( local_cxy ,
     322                                &process->cwd_lock ), LOCK_PROCESS_CWD );
    264323
    265324#if (DEBUG_PROCESS_REFERENCE_INIT & 1)
     
    273332    xlist_root_init( XPTR( local_cxy , &process->children_root ) );
    274333    process->children_nr     = 0;
    275     remote_queuelock_init( XPTR( local_cxy , &process->children_lock ), LOCK_PROCESS_CHILDREN );
     334    remote_queuelock_init( XPTR( local_cxy,
     335                                 &process->children_lock ), LOCK_PROCESS_CHILDREN );
    276336
    277337    // reset semaphore / mutex / barrier / condvar list roots and lock
     
    280340    xlist_root_init( XPTR( local_cxy , &process->barrier_root ) );
    281341    xlist_root_init( XPTR( local_cxy , &process->condvar_root ) );
    282     remote_queuelock_init( XPTR( local_cxy , &process->sync_lock ), LOCK_PROCESS_USERSYNC );
     342    remote_queuelock_init( XPTR( local_cxy ,
     343                                 &process->sync_lock ), LOCK_PROCESS_USERSYNC );
    283344
    284345    // reset open directories root and lock
    285346    xlist_root_init( XPTR( local_cxy , &process->dir_root ) );
    286     remote_queuelock_init( XPTR( local_cxy , &process->dir_lock ), LOCK_PROCESS_DIR );
     347    remote_queuelock_init( XPTR( local_cxy ,
     348                                 &process->dir_lock ), LOCK_PROCESS_DIR );
    287349
    288350    // register new process in the local cluster manager pref_tbl[]
     
    315377#endif
    316378
     379    return 0;
     380
    317381}  // process_reference_init()
    318382
     
    321385                           xptr_t      reference_process_xp )
    322386{
    323     error_t error;
     387    error_t   error;
     388    vmm_t   * vmm;
    324389
    325390    // get reference process cluster and local pointer
    326391    cxy_t       ref_cxy = GET_CXY( reference_process_xp );
    327392    process_t * ref_ptr = GET_PTR( reference_process_xp );
     393
     394    // get pointer on process vmm
     395    vmm = &local_process->vmm;
    328396
    329397    // initialize PID, REF_XP, PARENT_XP, and STATE
     
    343411
    344412// check user process
    345 assert( (local_process->pid != 0), "PID cannot be 0" );
    346 
    347     // reset local process vmm
    348     error = vmm_init( local_process );
    349     assert( (error == 0) , "cannot initialize VMM\n");
    350 
    351     // reset process file descriptors array
     413assert( (local_process->pid != 0), "LPID cannot be 0" );
     414
     415    // initialize VSL as empty
     416    vmm->vsegs_nr = 0;
     417        xlist_root_init( XPTR( local_cxy , &vmm->vsegs_root ) );
     418
     419    // create an empty GPT as required by the architecture
     420    error = hal_gpt_create( &vmm->gpt );
     421    if( error )
     422    {
     423        printk("\n[ERROR] in %s : cannot create empty GPT\n", __FUNCTION__ );
     424        return -1;
     425    }
     426
     427    // initialize GPT and VSL locks
     428    remote_rwlock_init( XPTR( local_cxy , &vmm->gpt_lock ) , LOCK_VMM_GPT );
     429        remote_rwlock_init( XPTR( local_cxy , &vmm->vsl_lock ) , LOCK_VMM_VSL );
     430
     431    // register kernel vsegs in VMM as required by the architecture
     432    error = hal_vmm_kernel_update( local_process );
     433    if( error )
     434    {
     435        printk("\n[ERROR] in %s : cannot register kernel vsegs in VMM\n", __FUNCTION__ );
     436        return -1;
     437    }
     438
     439    // create "args" and "envs" vsegs
     440    // create "stacks" and "mmap" vsegs allocators
     441    // initialize locks protecting GPT and VSL
     442    error = vmm_user_init( local_process );
     443    if( error )
     444    {
     445        printk("\n[ERROR] in %s : cannot register user vsegs in VMM\n", __FUNCTION__ );
     446        return -1;
     447    }
     448 
     449#if (DEBUG_PROCESS_COPY_INIT & 1)
     450cycle = (uint32_t)hal_get_cycles();
     451if( DEBUG_PROCESS_COPY_INIT < cycle )
     452printk("\n[%s] thread[%x,%x] initialized vmm for process %x / cycle %d\n",
     453__FUNCTION__, parent_pid, this->trdid, pid, cycle );
     454#endif
     455
     456    // set process file descriptors array
    352457        process_fd_init( local_process );
    353458
    354     // reset vfs_root_xp / vfs_bin_xp / cwd_xp fields
     459    // set vfs_root_xp / vfs_bin_xp / cwd_xp fields
    355460    local_process->vfs_root_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_root_xp ) );
    356461    local_process->vfs_bin_xp  = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_bin_xp ) );
     
    380485    local_process->th_nr  = 0;
    381486    rwlock_init( &local_process->th_lock , LOCK_PROCESS_THTBL );
    382 
    383487
    384488    // register new process descriptor in local cluster manager local_list
     
    451555#endif
    452556
    453     // remove process from children_list
    454     // and release PID if owner cluster
     557    // when target process cluster is the owner cluster
     558    // - remove process from TXT list and transfer ownership
     559    // - remove process from children_list
     560    // - release PID
    455561    if( CXY_FROM_PID( pid ) == local_cxy )
    456562    {
     563        process_txt_detach( XPTR( local_cxy , process ) );
     564
     565#if (DEBUG_PROCESS_DESTROY & 1)
     566if( DEBUG_PROCESS_DESTROY < cycle )
     567printk("\n[%s] thread[%x,%x] removed process %x from TXT list\n",
     568__FUNCTION__, this->process->pid, this->trdid, pid );
     569#endif
     570
    457571        // get pointers on parent process
    458572        parent_xp  = process->parent_xp;
     
    472586#if (DEBUG_PROCESS_DESTROY & 1)
    473587if( DEBUG_PROCESS_DESTROY < cycle )
    474 printk("\n[%s] thread[%x,%x] removed process %x in cluster %x from children list\n",
    475 __FUNCTION__, this->process->pid, this->trdid, pid, local_cxy );
     588printk("\n[%s] thread[%x,%x] removed process %x from parent process children list\n",
     589__FUNCTION__, this->process->pid, this->trdid, pid );
    476590#endif
    477591
     
    777891uint32_t cycle = (uint32_t)hal_get_cycles();
    778892if( DEBUG_PROCESS_SIGACTION < cycle )
    779 printk("\n[%s] thread[%x,%x] enter in cluster %x for process %x / cycle %d\n",
    780 __FUNCTION__, this->process->pid, this->trdid, local_cxy, process->pid, cycle );
     893printk("\n[%s] thread[%x,%x] enter for process %x n cluster %x / cycle %d\n",
     894__FUNCTION__, this->process->pid, this->trdid, process->pid, local_cxy, cycle );
    781895#endif
    782896
     
    11891303}  // end process_register_thread()
    11901304
    1191 /////////////////////////////////////////////////
    1192 bool_t process_remove_thread( thread_t * thread )
     1305///////////////////////////////////////////////////
     1306uint32_t process_remove_thread( thread_t * thread )
    11931307{
    11941308    uint32_t count;  // number of threads in local process descriptor
     1309
     1310// check thread
     1311assert( (thread != NULL) , "thread argument is NULL" );
    11951312
    11961313    process_t * process = thread->process;
     
    12051322    count = process->th_nr;
    12061323
    1207 // check thread
    1208 assert( (thread != NULL) , "thread argument is NULL" );
    1209 
    12101324// check th_nr value
    12111325assert( (count > 0) , "process th_nr cannot be 0" );
     
    12181332    rwlock_wr_release( &process->th_lock );
    12191333
    1220     return (count == 1);
     1334    return count;
    12211335
    12221336}  // end process_remove_thread()
     
    12831397cycle = (uint32_t)hal_get_cycles();
    12841398if( DEBUG_PROCESS_MAKE_FORK < cycle )
    1285 printk("\n[%s] thread[%x,%x] allocated process %x / cycle %d\n",
     1399printk("\n[%s] thread[%x,%x] allocated child_process %x / cycle %d\n",
    12861400__FUNCTION__, pid, trdid, new_pid, cycle );
    12871401#endif
    12881402
    12891403    // initializes child process descriptor from parent process descriptor
    1290     process_reference_init( process,
    1291                             new_pid,
    1292                             parent_process_xp );
     1404    error = process_reference_init( process,
     1405                                    new_pid,
     1406                                    parent_process_xp );
     1407    if( error )
     1408    {
     1409        printk("\n[ERROR] in %s : cannot initialize child process in cluster %x\n",
     1410        __FUNCTION__, local_cxy );
     1411        process_free( process );
     1412        return -1;
     1413    }
    12931414
    12941415#if( DEBUG_PROCESS_MAKE_FORK & 1 )
     
    12981419__FUNCTION__, pid, trdid, new_pid, cycle );
    12991420#endif
    1300 
    13011421
    13021422    // copy VMM from parent descriptor to child descriptor
     
    13611481#endif
    13621482
    1363     // set Copy_On_Write flag in parent process GPT
    1364     // this includes all replicated GPT copies
     1483    // set COW flag in DATA, ANON, REMOTE vsegs for parent process VMM
     1484    // this includes all parnet process copies in all clusters
    13651485    if( parent_process_cxy == local_cxy )   // reference is local
    13661486    {
     
    13731493    }
    13741494
    1375     // set Copy_On_Write flag in child process GPT
     1495    // set COW flag in DATA, ANON, REMOTE vsegs for child process VMM
    13761496    vmm_set_cow( process );
    13771497 
     
    14231543    char          ** args_pointers;           // array of pointers on main thread arguments
    14241544
    1425     // get thread, process, pid and ref_xp
     1545    // get calling thread, process, pid and ref_xp
    14261546    thread  = CURRENT_THREAD;
    14271547    process = thread->process;
     
    14701590cycle = (uint32_t)hal_get_cycles();
    14711591if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1472 printk("\n[%s] thread[%x,%x] deleted all threads / cycle %d\n",
     1592printk("\n[%s] thread[%x,%x] deleted existing threads / cycle %d\n",
    14731593__FUNCTION__, pid, thread->trdid, cycle );
    14741594#endif
    14751595
    1476     // reset local process VMM
    1477     vmm_destroy( process );
     1596    // reset calling process VMM
     1597    vmm_user_reset( process );
    14781598
    14791599#if( DEBUG_PROCESS_MAKE_EXEC & 1 )
    14801600cycle = (uint32_t)hal_get_cycles();
    14811601if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1482 printk("\n[%s] thread[%x,%x] reset VMM / cycle %d\n",
     1602printk("\n[%s] thread[%x,%x] completed VMM reset / cycle %d\n",
    14831603__FUNCTION__, pid, thread->trdid, cycle );
    14841604#endif
    14851605
    1486     // re-initialize the VMM (kentry/args/envs vsegs registration)
    1487     error = vmm_init( process );
     1606    // re-initialize the VMM (args/envs vsegs registration)
     1607    error = vmm_user_init( process );
    14881608    if( error )
    14891609    {
     
    14971617cycle = (uint32_t)hal_get_cycles();
    14981618if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1499 printk("\n[%s] thread[%x,%x] / kentry/args/envs vsegs registered / cycle %d\n",
     1619printk("\n[%s] thread[%x,%x] registered args/envs vsegs / cycle %d\n",
    15001620__FUNCTION__, pid, thread->trdid, cycle );
    15011621#endif
     
    15151635cycle = (uint32_t)hal_get_cycles();
    15161636if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1517 printk("\n[%s] thread[%x,%x] / code/data vsegs registered / cycle %d\n",
     1637printk("\n[%s] thread[%x,%x] registered code/data vsegs / cycle %d\n",
    15181638__FUNCTION__, pid, thread->trdid, cycle );
    15191639#endif
     
    15771697    vmm->vsegs_nr = 0;
    15781698        xlist_root_init( XPTR( local_cxy , &vmm->vsegs_root ) );
    1579         remote_rwlock_init( XPTR( local_cxy , &vmm->vsegs_lock ) , LOCK_VMM_VSL );
    15801699
    15811700    // initialise GPT as empty
    15821701    error = hal_gpt_create( &vmm->gpt );
    1583 
    15841702    if( error )
    15851703    {
     
    15881706    }
    15891707
    1590     // initialize GPT lock
     1708    // initialize VSL and GPT locks
     1709        remote_rwlock_init( XPTR( local_cxy , &vmm->vsl_lock ) , LOCK_VMM_VSL );
    15911710    remote_rwlock_init( XPTR( local_cxy , &vmm->gpt_lock ) , LOCK_VMM_GPT );
    15921711   
    15931712    // create kernel vsegs in GPT and VSL, as required by the hardware architecture
    15941713    error = hal_vmm_kernel_init( info );
    1595 
    15961714    if( error )
    15971715    {
     
    16521770    // allocates memory for process descriptor from local cluster
    16531771        process = process_alloc();
    1654        
    1655 // check memory allocator
    1656 assert( (process != NULL),
    1657 "no memory for process descriptor in cluster %x", local_cxy  );
     1772    if( process == NULL )
     1773    {
     1774        printk("\n[PANIC] in %s : cannot allocate process\n", __FUNCTION__ );
     1775        hal_core_sleep();
     1776    }
    16581777
    16591778    // set the CWD and VFS_ROOT fields in process descriptor
     
    16631782    // get PID from local cluster
    16641783    error = cluster_pid_alloc( process , &pid );
    1665 
    1666 // check PID allocator
    1667 assert( (error == 0),
    1668 "cannot allocate PID in cluster %x", local_cxy );
    1669 
    1670 // check PID value
    1671 assert( (pid == 1) ,
    1672 "process INIT must be first process in cluster 0" );
     1784    if( error )
     1785    {
     1786        printk("\n[PANIC] in %s : cannot allocate PID\n", __FUNCTION__ );
     1787        hal_core_sleep();
     1788    }
     1789    if( pid != 1 )
     1790    {
     1791        printk("\n[PANIC] in %s : process PID must be 0x1\n", __FUNCTION__ );
     1792        hal_core_sleep();
     1793    }
    16731794
    16741795    // initialize process descriptor / parent is local process_zero
    1675     process_reference_init( process,
    1676                             pid,
    1677                             XPTR( local_cxy , &process_zero ) ); 
     1796    error = process_reference_init( process,
     1797                                    pid,
     1798                                    XPTR( local_cxy , &process_zero ) ); 
     1799    if( error )
     1800    {
     1801        printk("\n[PANIC] in %s : cannot initialize process\n", __FUNCTION__ );
     1802        hal_core_sleep();
     1803    }
    16781804
    16791805#if(DEBUG_PROCESS_INIT_CREATE & 1)
     
    16931819                            &file_xp,
    16941820                            &file_id );
    1695 
    1696 assert( (error == 0),
    1697 "failed to open file <%s>", CONFIG_PROCESS_INIT_PATH );
     1821    if( error )
     1822    {
     1823        printk("\n[PANIC] in %s : cannot open file <%s>\n",
     1824         __FUNCTION__, CONFIG_PROCESS_INIT_PATH  );
     1825        hal_core_sleep();
     1826    }
    16981827
    16991828#if(DEBUG_PROCESS_INIT_CREATE & 1)
     
    17031832#endif
    17041833
    1705    // register "code" and "data" vsegs as well as entry-point
     1834    // register "code" and "data" vsegs as well as entry-point
    17061835    // in process VMM, using information contained in the elf file.
    17071836        error = elf_load_process( file_xp , process );
    17081837
    1709 assert( (error == 0),
    1710 "cannot access .elf file <%s>", CONFIG_PROCESS_INIT_PATH );
     1838    if( error )
     1839    {
     1840        printk("\n[PANIC] in %s : cannot access file <%s>\n",
     1841         __FUNCTION__, CONFIG_PROCESS_INIT_PATH  );
     1842        hal_core_sleep();
     1843    }
     1844
    17111845
    17121846#if(DEBUG_PROCESS_INIT_CREATE & 1)
     
    17141848printk("\n[%s] thread[%x,%x] registered code/data vsegs in VMM\n",
    17151849__FUNCTION__, this->process->pid, this->trdid );
     1850#endif
     1851
     1852#if (DEBUG_PROCESS_INIT_CREATE & 1)
     1853hal_vmm_display( process , true );
    17161854#endif
    17171855
     
    17511889                                &thread );
    17521890
    1753 assert( (error == 0),
    1754 "cannot create main thread for <%s>", CONFIG_PROCESS_INIT_PATH );
    1755 
    1756 assert( (thread->trdid == 0),
    1757 "main thread must have index 0 for <%s>", CONFIG_PROCESS_INIT_PATH );
     1891    if( error )
     1892    {
     1893        printk("\n[PANIC] in %s : cannot create main thread\n", __FUNCTION__  );
     1894        hal_core_sleep();
     1895    }
     1896    if( thread->trdid != 0 )
     1897    {
     1898        printk("\n[PANIC] in %s : bad main thread trdid\n", __FUNCTION__  );
     1899        hal_core_sleep();
     1900    }
    17581901
    17591902#if(DEBUG_PROCESS_INIT_CREATE & 1)
     
    19892132    process_txt_transfer_ownership( process_xp );
    19902133
    1991     // get extended pointer on process stdin file
     2134    // get extended pointer on process stdin pseudo file
    19922135    file_xp = (xptr_t)hal_remote_l64( XPTR( process_cxy , &process_ptr->fd_array.array[0] ) );
    19932136
     
    20142157uint32_t txt_id = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->channel ) );
    20152158if( DEBUG_PROCESS_TXT < cycle )
    2016 printk("\n[%s] thread[%x,%x] detached process %x from TXT %d / cycle %d\n",
     2159printk("\n[%s] thread[%x,%x] detached process %x from TXT%d / cycle %d\n",
    20172160__FUNCTION__, this->process->pid, this->trdid, process_pid, txt_id, cycle );
    20182161#endif
     
    20562199uint32_t txt_id = hal_remote_l32( XPTR( txt_cxy , &txt_ptr->channel ) );
    20572200if( DEBUG_PROCESS_TXT < cycle )
    2058 printk("\n[%s] thread[%x,%x] give TXT %d to process %x / cycle %d\n",
     2201printk("\n[%s] thread[%x,%x] give TXT%d ownership to process %x / cycle %d\n",
    20592202__FUNCTION__, this->process->pid, this->trdid, txt_id, process_pid, cycle );
    20602203#endif
     
    20782221    xptr_t      iter_xp;         // iterator for xlist
    20792222    xptr_t      current_xp;      // extended pointer on current process
    2080     process_t * current_ptr;     // local pointer on current process
    2081     cxy_t       current_cxy;     // cluster for current process
     2223    bool_t      found;
    20822224
    20832225#if DEBUG_PROCESS_TXT
     
    20862228#endif
    20872229
    2088     // get pointers on process in owner cluster
     2230    // get pointers on target process
    20892231    process_cxy = GET_CXY( process_xp );
    20902232    process_ptr = GET_PTR( process_xp );
    20912233    process_pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) );
    20922234
    2093     // check owner cluster
    2094     assert( (process_cxy == CXY_FROM_PID( process_pid )) ,
    2095     "process descriptor not in owner cluster" );
     2235// check owner cluster
     2236assert( (process_cxy == CXY_FROM_PID( process_pid )) ,
     2237"process descriptor not in owner cluster" );
    20962238
    20972239    // get extended pointer on stdin pseudo file
     
    21032245    txt_ptr = GET_PTR( txt_xp );
    21042246
    2105     // get extended pointer on TXT_RX owner and TXT channel
     2247    // get relevant infos from chdev descriptor
    21062248    owner_xp = hal_remote_l64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) );
    2107     txt_id   = hal_remote_l32 ( XPTR( txt_cxy , &txt_ptr->channel ) );
    2108 
    2109     // transfer ownership only if process is the TXT owner
     2249    txt_id   = hal_remote_l32( XPTR( txt_cxy , &txt_ptr->channel ) );
     2250
     2251    // transfer ownership only if target process is the TXT owner
    21102252    if( (owner_xp == process_xp) && (txt_id > 0) ) 
    21112253    {
     
    21142256        lock_xp = XPTR( txt_cxy , &txt_ptr->ext.txt.lock );
    21152257
    2116         // get lock
    2117         remote_busylock_acquire( lock_xp );
    2118 
    2119         if( process_get_ppid( process_xp ) != 1 )           // process is not KSH
     2258        if( process_get_ppid( process_xp ) != 1 )       // target process is not KSH
    21202259        {
     2260            // get lock
     2261            remote_busylock_acquire( lock_xp );
     2262
    21212263            // scan attached process list to find KSH process
    2122             XLIST_FOREACH( root_xp , iter_xp )
     2264            found = false;
     2265            for( iter_xp = hal_remote_l64( root_xp ) ;
     2266                 (iter_xp != root_xp) && (found == false) ;
     2267                 iter_xp = hal_remote_l64( iter_xp ) )
     2268            {
     2269                current_xp = XLIST_ELEMENT( iter_xp , process_t , txt_list );
     2270
     2271                if( process_get_ppid( current_xp ) == 1 )  // current is KSH
     2272                {
     2273                    // set owner field in TXT chdev
     2274                    hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp );
     2275
     2276#if DEBUG_PROCESS_TXT
     2277cycle = (uint32_t)hal_get_cycles();
     2278if( DEBUG_PROCESS_TXT < cycle )
     2279printk("\n[%s] thread[%x,%x] transfered TXT%d ownership to KSH / cycle %d\n",
     2280__FUNCTION__, this->process->pid, this->trdid, txt_id, cycle );
     2281#endif
     2282                    found = true;
     2283                }
     2284            }
     2285
     2286            // release lock
     2287            remote_busylock_release( lock_xp );
     2288
     2289// It must exist a KSH process for each user TXT channel
     2290assert( (found == true), "KSH process not found for TXT%d", txt_id );
     2291
     2292        }
     2293        else                                           // target process is KSH
     2294        {
     2295            // get lock
     2296            remote_busylock_acquire( lock_xp );
     2297
     2298            // scan attached process list to find another process
     2299            found = false;
     2300            for( iter_xp = hal_remote_l64( root_xp ) ;
     2301                 (iter_xp != root_xp) && (found == false) ;
     2302                 iter_xp = hal_remote_l64( iter_xp ) )
    21232303            {
    21242304                current_xp  = XLIST_ELEMENT( iter_xp , process_t , txt_list );
    2125                 current_cxy = GET_CXY( current_xp );
    2126                 current_ptr = GET_PTR( current_xp );
    2127 
    2128                 if( process_get_ppid( current_xp ) == 1 )  // current is KSH
     2305
     2306                if( current_xp != process_xp )            // current is not KSH
    21292307                {
    2130                     // release lock
    2131                     remote_busylock_release( lock_xp );
    2132 
    21332308                    // set owner field in TXT chdev
    21342309                    hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp );
    21352310
    21362311#if DEBUG_PROCESS_TXT
    2137 cycle = (uint32_t)hal_get_cycles();
    2138 uint32_t ksh_pid = hal_remote_l32( XPTR( current_cxy , &current_ptr->pid ) );
     2312cycle  = (uint32_t)hal_get_cycles();
     2313cxy_t       current_cxy = GET_CXY( current_xp );
     2314process_t * current_ptr = GET_PTR( current_xp );
     2315uint32_t    new_pid     = hal_remote_l32( XPTR( current_cxy , &current_ptr->pid ) );
    21392316if( DEBUG_PROCESS_TXT < cycle )
    2140 printk("\n[%s] thread[%x,%x] release TXT %d to KSH %x / cycle %d\n",
    2141 __FUNCTION__, this->process->pid, this->trdid, txt_id, ksh_pid, cycle );
    2142 process_txt_display( txt_id );
    2143 #endif
    2144                      return;
     2317printk("\n[%s] thread[%x,%x] transfered TXT%d ownership to process %x / cycle %d\n",
     2318__FUNCTION__,this->process->pid, this->trdid, txt_id, new_pid, cycle );
     2319#endif
     2320                    found = true;
    21452321                }
    21462322            }
    2147  
     2323
    21482324            // release lock
    21492325            remote_busylock_release( lock_xp );
    21502326
    2151             // PANIC if KSH not found
    2152             assert( false , "KSH process not found for TXT %d" );
    2153 
    2154             return;
     2327            // no more owner for TXT if no other process found
     2328            if( found == false )
     2329            {
     2330                // set owner field in TXT chdev
     2331                hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , XPTR_NULL );
     2332
     2333#if DEBUG_PROCESS_TXT
     2334cycle = (uint32_t)hal_get_cycles();
     2335if( DEBUG_PROCESS_TXT < cycle )
     2336printk("\n[%s] thread[%x,%x] released TXT%d (no attached process) / cycle %d\n",
     2337__FUNCTION__, this->process->pid, this->trdid, txt_id, cycle );
     2338#endif
     2339            }
    21552340        }
    2156         else                                               // process is KSH
    2157         {
    2158             // scan attached process list to find another process
    2159             XLIST_FOREACH( root_xp , iter_xp )
    2160             {
    2161                 current_xp  = XLIST_ELEMENT( iter_xp , process_t , txt_list );
    2162                 current_cxy = GET_CXY( current_xp );
    2163                 current_ptr = GET_PTR( current_xp );
    2164 
    2165                 if( current_xp != process_xp )            // current is not KSH
    2166                 {
    2167                     // release lock
    2168                     remote_busylock_release( lock_xp );
    2169 
    2170                     // set owner field in TXT chdev
    2171                     hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , current_xp );
     2341    }
     2342    else
     2343    {
    21722344
    21732345#if DEBUG_PROCESS_TXT
    2174 cycle  = (uint32_t)hal_get_cycles();
    2175 uint32_t new_pid = hal_remote_l32( XPTR( current_cxy , &current_ptr->pid ) );
     2346cycle = (uint32_t)hal_get_cycles();
    21762347if( DEBUG_PROCESS_TXT < cycle )
    2177 printk("\n[%s] thread[%x,%x] release TXT %d to process %x / cycle %d\n",
    2178 __FUNCTION__,this->process->pid, this->trdid, txt_id, new_pid, cycle );
    2179 process_txt_display( txt_id );
    2180 #endif
    2181                      return;
    2182                 }
    2183             }
    2184 
    2185             // release lock
    2186             remote_busylock_release( lock_xp );
    2187 
    2188             // no more owner for TXT if no other process found
    2189             hal_remote_s64( XPTR( txt_cxy , &txt_ptr->ext.txt.owner_xp ) , XPTR_NULL );
    2190 
    2191 #if DEBUG_PROCESS_TXT
    2192 cycle = (uint32_t)hal_get_cycles();
    2193 if( DEBUG_PROCESS_TXT < cycle )
    2194 printk("\n[%s] thread[%x,%x] release TXT %d to nobody / cycle %d\n",
    2195 __FUNCTION__, this->process->pid, this->trdid, txt_id, cycle );
    2196 process_txt_display( txt_id );
    2197 #endif
    2198             return;
    2199         }
    2200     }
    2201     else
    2202     {
    2203 
    2204 #if DEBUG_PROCESS_TXT
    2205 cycle = (uint32_t)hal_get_cycles();
    2206 if( DEBUG_PROCESS_TXT < cycle )
    2207 printk("\n[%s] thread %x in process %d does nothing (not TXT owner) / cycle %d\n",
    2208 __FUNCTION__, this->trdid, process_pid, cycle );
    2209 process_txt_display( txt_id );
    2210 #endif
    2211 
    2212     }
     2348printk("\n[%s] thread[%x,%x] does nothing for process %x (not TXT owner) / cycle %d\n",
     2349__FUNCTION__, this->process->pid, this->trdid, process_pid, cycle );
     2350#endif
     2351
     2352    }
     2353
    22132354}  // end process_txt_transfer_ownership()
    22142355
Note: See TracChangeset for help on using the changeset viewer.