Ignore:
Timestamp:
Dec 20, 2017, 4:51:09 PM (6 years ago)
Author:
alain
Message:

Fix bugs in exec

File:
1 edited

Legend:

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

    r124 r409  
    11/*
    2  * sys_kill.c: Send a signal to a given process.
     2 * sys_kill.c - Send a signal to a given process.
    33 *
    44 * Author    Alain Greiner (2016,2017)
     
    2424#include <kernel_config.h>
    2525#include <hal_types.h>
     26#include <hal_irqmask.h>
    2627#include <errno.h>
    2728#include <thread.h>
     
    3637              uint32_t sig_id )
    3738{
     39    uint32_t    save_sr;       // required to enable IRQs
     40
     41#if CONFIG_SYSCALL_DEBUG
     42uint64_t    tm_start;
     43uint64_t    tm_end;
     44tm_start = hal_get_cycles();
     45#endif
     46
    3847    thread_t  * this    = CURRENT_THREAD;
    3948    process_t * process = this->process;
    40 
    41     // check signal index
    42         if( (sig_id == 0) || (sig_id >= SIG_NR) )
    43         {
    44         printk("\n[ERROR] in %s : illegal signal = %d for thread %x in process %x\n",
    45                __FUNCTION__ , sig_id , this->trdid , process->pid );
    46                 this->errno = EINVAL;
    47         return -1;
    48         }
    49 
    50     // get local pointer on local cluster manager
    51     cluster_t * cluster = LOCAL_CLUSTER;
    5249
    5350    // get owner process cluster and lpid
     
    5552    lpid_t  lpid       = LPID_FROM_PID( pid );
    5653
    57     // check PID
     54    // check pid
    5855    if( (lpid >= CONFIG_MAX_PROCESS_PER_CLUSTER) || cluster_is_undefined( owner_cxy ) )
    5956    {
    6057        printk("\n[ERROR] in %s : illegal target PID = %d for thread %x in process %x\n",
    61                __FUNCTION__ , pid , this->trdid , process->pid );
     58        __FUNCTION__ , pid , this->trdid , pid );
    6259                this->errno = EINVAL;
    6360        return -1;
    6461    }
    6562
    66     // get extended pointers on copies root and lock
    67     xptr_t root_xp = XPTR( owner_cxy , &cluster->pmgr.copies_root[lpid] );
    68     xptr_t lock_xp = XPTR( owner_cxy , &cluster->pmgr.copies_lock[lpid] );
    69 
    70     // take the lock protecting the copies
    71     remote_spinlock_lock( lock_xp );
    72 
    73     // TODO the loop below sequencialize the RPCs
    74     // they could be pipelined using a non-blocking RPC ...
    75  
    76     // loop on the process decriptor copies
    77     xptr_t  iter_xp;
    78     XLIST_FOREACH( root_xp , iter_xp )
     63    // check sig_id
     64    if( (sig_id != SIGSTOP) && (sig_id != SIGCONT) && (sig_id != SIGKILL) )
    7965    {
    80         xptr_t      process_xp  = XLIST_ELEMENT( iter_xp , process_t , copies_list );
    81         cxy_t       process_cxy = GET_CXY( process_xp );
    82         process_t * process_ptr = (process_t *)GET_PTR( process_xp );
    83 
    84         if( process_cxy == local_cxy )   // process copy is local
    85         {
    86             signal_rise( process_ptr , sig_id );
    87         }
    88         else                           // process copy is remote
    89         {
    90             rpc_signal_rise_client( process_cxy , process_ptr , sig_id );
    91         }
     66        printk("\n[ERROR] in %s : illegal signal type for thread %x in process %x\n",
     67        __FUNCTION__ , sig_id , this->trdid , pid );
     68                this->errno = EINVAL;
     69        return -1;
    9270    }
    9371
    94     // release the lock
    95     remote_spinlock_unlock( lock_xp );
     72    // enable IRQs
     73    hal_enable_irq( &save_sr );
     74
     75    // execute process_make_kill() function in owner cluster
     76    if( local_cxy == owner_cxy )                                // owner is local
     77    {
     78        process_make_kill( process , sig_id );
     79    }
     80    else                                                        // owner is remote
     81    {
     82        rpc_process_make_kill_client( owner_cxy , process , sig_id );
     83    }
     84
     85    // restore IRQs
     86    hal_restore_irq( save_sr );
    9687
    9788    hal_fence();
    9889
     90#if CONFIG_SYSCALL_DEBUG
     91tm_end = hal_get_cycles();
     92syscall_dmsg("\n[DBG] %s exit : core[%x,%d] / thread %x in process %x / cycle %d\n"
     93"process %x killed / cost = %d\n",
     94__FUNCTION__ , local_cxy , this->core->lid , this->trdid , this->process->pid ,
     95tm_start , pid , (uint32_t)(tm_end - tm_start) );
     96#endif
     97 
    9998        return 0;
    10099
Note: See TracChangeset for help on using the changeset viewer.