Ignore:
Timestamp:
Feb 20, 2018, 5:32:17 PM (6 years ago)
Author:
alain
Message:

Fix a bad bug in scheduler...

File:
1 edited

Legend:

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

    r433 r435  
    4848
    4949    thread_t  * this    = CURRENT_THREAD;
     50    process_t * process = this->process;
    5051
    5152#if CONFIG_DEBUG_SYS_KILL
     
    5859#endif
    5960
    60     // get cluster and pointers on owner process
     61    // process cannot kill itself
     62    if( pid == process->pid )
     63    {
     64
     65#if CONFIG_DEBUG_SYSCALLS_ERROR
     66printk("\n[ERROR] in %s : process %d cannot kill itself\n", __FUNCTION__ , pid );
     67#endif
     68        this->errno = EINVAL;
     69        return -1;
     70    }
     71
     72    // get cluster and pointers on owner target process descriptor
    6173    owner_xp  = cluster_get_owner_process_from_pid( pid );
    6274    owner_cxy = GET_CXY( owner_xp );
     
    6779    {
    6880
    69 syscall_dmsg("\n[ERROR] in %s : process %x not found\n", __FUNCTION__ , pid );
    70 
     81#if CONFIG_DEBUG_SYSCALLS_ERROR
     82printk("\n[ERROR] in %s : process %x not found\n", __FUNCTION__ , pid );
     83#endif
    7184        this->errno = EINVAL;
    7285        return -1;
     
    7992    ppid       = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) );
    8093
    81     // processes INIT and processes KSH cannot be stoped or killed
    82     if( ppid < 2 )
     94    // processes INIT
     95    if( pid == 1 )
    8396    {
    8497
    85 syscall_dmsg("\n[ERROR] in %s : process %x cannot be killed\n", __FUNCTION__ , pid );
    86 
     98#if CONFIG_DEBUG_SYSCALLS_ERROR
     99printk("\n[ERROR] in %s : process_init cannot be killed\n", __FUNCTION__ );
     100#endif
    87101                this->errno = EINVAL;
    88102        return -1;
     
    92106    hal_enable_irq( &save_sr );
    93107
    94     // analyse signal type
    95     // supported values are : 0, SIGSTOP, SIGCONT, SIGKILL
     108    // analyse signal type / supported values are : 0, SIGSTOP, SIGCONT, SIGKILL
    96109    switch( sig_id )
    97110    {
     
    108121
    109122            // block all threads in all clusters
    110             process_sigaction( owner_ptr , BLOCK_ALL_THREADS );
     123            process_sigaction( pid , BLOCK_ALL_THREADS );
    111124
    112             // atomically update reference process termination state
     125            // atomically update owner process termination state
    113126            hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) ,
    114                                   PROCESS_FLAG_BLOCK );
     127                                  PROCESS_TERM_STOP );
    115128 
    116129            retval = 0;
     
    120133        {
    121134            // unblock all threads in all clusters
    122             process_sigaction( owner_ptr , UNBLOCK_ALL_THREADS );
     135            process_sigaction( pid , UNBLOCK_ALL_THREADS );
    123136
    124137            // atomically update reference process termination state
    125138            hal_remote_atomic_and( XPTR( owner_cxy , &owner_ptr->term_state ) ,
    126                                    ~PROCESS_FLAG_BLOCK );
     139                                   ~PROCESS_TERM_STOP );
    127140            retval = 0;
    128141            break;
     
    131144        case SIGKILL:
    132145        {
    133             // the process_make_kill() function must be executed
    134             // by an RPC thread in process owner cluster
    135             // It deletes all target process threads in all clusters,
    136             // and updates the process termination state
    137             rpc_process_make_kill_client( owner_cxy , owner_ptr , false , 0 );
     146            // remove TXT ownership from owner process descriptor
     147            process_txt_reset_ownership( owner_xp );
     148
     149            // block all process threads in all clusters
     150            process_sigaction( pid , BLOCK_ALL_THREADS );
     151
     152            // mark all process threads in all clusters for delete
     153            process_sigaction( pid , DELETE_ALL_THREADS );
     154
     155            // atomically update owner process descriptor flags
     156            hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) ,
     157                                  PROCESS_TERM_KILL );
    138158
    139159            retval = 0;
     
    143163        {
    144164
    145 syscall_dmsg("\n[ERROR] in %s : illegal signal type %d for process %x\n",
    146 __FUNCTION__ , sig_id , pid );
    147 
     165#if CONFIG_DEBUG_SYSCALLS_ERROR
     166printk("\n[ERROR] in %s : illegal signal %d / process %x\n", __FUNCTION__, sig_id, pid );
     167#endif
    148168            this->errno = EINVAL;
    149169            retval = -1;
Note: See TracChangeset for help on using the changeset viewer.