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

blip

File:
1 edited

Legend:

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

    r421 r433  
    3838{
    3939    uint32_t    save_sr;       // required to enable IRQs
    40     xptr_t      process_xp;    // extended pointer on target reference process
    41     cxy_t       process_cxy;   // target process cluster
    42     process_t * process_ptr;   // local pointer on target process
     40    xptr_t      owner_xp;      // extended pointer on target reference process
     41    cxy_t       owner_cxy;     // target process cluster
     42    process_t * owner_ptr;     // local pointer on target process
    4343    xptr_t      parent_xp;     // extended pointer on parent process
    4444    cxy_t       parent_cxy;    // parent process cluster
    4545    process_t * parent_ptr;    // local pointer on parent process
    4646    pid_t       ppid;          // parent process PID
     47    uint32_t    retval;        // return value for the switch
    4748
    4849    thread_t  * this    = CURRENT_THREAD;
    4950
    50 #if CONFIG_SYSCALL_DEBUG
     51#if CONFIG_DEBUG_SYS_KILL
    5152uint64_t    tm_start;
    5253uint64_t    tm_end;
    5354tm_start = hal_get_cycles();
    54 printk("\n[DBG] %s : core[%x,%d] enter / process %x / sig %d / cycle %d\n",
    55 __FUNCTION__ , local_cxy , this->core->lid , pid, sig_id, (uint32_t)tm_start );
     55if( CONFIG_DEBUG_SYS_KILL < tm_start )
     56printk("\n[DBG] %s : thread %x enter / process %x / sig %d / cycle %d\n",
     57__FUNCTION__ , this, pid, sig_id, (uint32_t)tm_start );
    5658#endif
    5759
    58     // get cluster and pointers on reference process
    59     process_xp  = cluster_get_reference_process_from_pid( pid );
    60     process_cxy = GET_CXY( process_xp );
    61     process_ptr = (process_t *)GET_PTR( process_xp );
     60    // get cluster and pointers on owner process
     61    owner_xp  = cluster_get_owner_process_from_pid( pid );
     62    owner_cxy = GET_CXY( owner_xp );
     63    owner_ptr = GET_PTR( owner_xp );
    6264
    6365    // check process existence
    64     if( process_xp == XPTR_NULL )
     66    if( owner_xp == XPTR_NULL )
    6567    {
    66         syscall_dmsg("\n[ERROR] in %s : process %x not found\n",
    67         __FUNCTION__ , pid );
     68
     69syscall_dmsg("\n[ERROR] in %s : process %x not found\n", __FUNCTION__ , pid );
     70
    6871        this->errno = EINVAL;
    6972        return -1;
     
    7174   
    7275    // get parent process PID
    73     parent_xp  = hal_remote_lwd( XPTR( process_cxy , &process_ptr->parent_xp ) );
     76    parent_xp  = hal_remote_lwd( XPTR( owner_cxy , &owner_ptr->parent_xp ) );
    7477    parent_cxy = GET_CXY( parent_xp );
    7578    parent_ptr = GET_PTR( parent_xp );
     
    7982    if( ppid < 2 )
    8083    {
    81         syscall_dmsg("\n[ERROR] in %s : process %x cannot be killed\n",
    82         __FUNCTION__ , pid );
    83                 this->errno = EINVAL;
    84         return -1;
    85     }
    8684
    87     // does nothing if sig_id == 0
    88     if( sig_id == 0 )  return 0;
    89    
    90     // check sig_id
    91     if( (sig_id != SIGSTOP) && (sig_id != SIGCONT) && (sig_id != SIGKILL) )
    92     {
    93         syscall_dmsg("\n[ERROR] in %s : illegal signal type for process %x\n",
    94         __FUNCTION__ , sig_id , pid );
     85syscall_dmsg("\n[ERROR] in %s : process %x cannot be killed\n", __FUNCTION__ , pid );
     86
    9587                this->errno = EINVAL;
    9688        return -1;
     
    10092    hal_enable_irq( &save_sr );
    10193
    102     // execute process_make_kill() function in owner cluster
    103     if( local_cxy == process_cxy )                            // owner cluster is local
     94    // analyse signal type
     95    // supported values are : 0, SIGSTOP, SIGCONT, SIGKILL
     96    switch( sig_id )
    10497    {
    105         process_make_kill( pid , sig_id );
     98        case 0 :
     99        {
     100            // does nothing
     101            retval = 0;
     102            break;
     103        }
     104        case SIGSTOP:     
     105        {
     106            // remove TXT ownership from target process
     107            process_txt_reset_ownership( owner_xp );
     108
     109            // block all threads in all clusters
     110            process_sigaction( owner_ptr , BLOCK_ALL_THREADS );
     111
     112            // atomically update reference process termination state
     113            hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) ,
     114                                  PROCESS_FLAG_BLOCK );
     115 
     116            retval = 0;
     117            break;
     118        }
     119        case SIGCONT:
     120        {
     121            // unblock all threads in all clusters
     122            process_sigaction( owner_ptr , UNBLOCK_ALL_THREADS );
     123
     124            // atomically update reference process termination state
     125            hal_remote_atomic_and( XPTR( owner_cxy , &owner_ptr->term_state ) ,
     126                                   ~PROCESS_FLAG_BLOCK );
     127            retval = 0;
     128            break;
     129        }
     130        break;
     131        case SIGKILL:
     132        {
     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 );
     138
     139            retval = 0;
     140            break;
     141        }
     142        default:
     143        {
     144
     145syscall_dmsg("\n[ERROR] in %s : illegal signal type %d for process %x\n",
     146__FUNCTION__ , sig_id , pid );
     147
     148            this->errno = EINVAL;
     149            retval = -1;
     150            break;
     151        }
    106152    }
    107     else                                                      // owner cluster is remote
    108     {
    109         rpc_process_make_kill_client( process_cxy , pid , sig_id );
    110     }
    111 
     153   
    112154    // restore IRQs
    113155    hal_restore_irq( save_sr );
     
    115157    hal_fence();
    116158
    117 #if CONFIG_SYSCALL_DEBUG
     159#if CONFIG_DEBUG_SYS_KILL
    118160tm_end = hal_get_cycles();
    119 printk("\n[DBG] %s : core[%x,%d] exit / process %x / sig %d / cost = %d\n",
    120 __FUNCTION__ , local_cxy , this->core->lid , pid, sig_id, (uint32_t)(tm_end - tm_start) );
     161if( CONFIG_DEBUG_SYS_KILL < tm_end )
     162printk("\n[DBG] %s : thread %x enter / process %x / sig %d / cost = %d / cycle %d\n",
     163__FUNCTION__ , this, pid, sig_id, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
    121164#endif
    122  
    123         return 0;
     165
     166        return retval;
    124167
    125168}  // end sys_kill()
Note: See TracChangeset for help on using the changeset viewer.