Changeset 409 for trunk/kernel/syscalls/sys_kill.c
- Timestamp:
- Dec 20, 2017, 4:51:09 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_kill.c
r124 r409 1 1 /* 2 * sys_kill.c :Send a signal to a given process.2 * sys_kill.c - Send a signal to a given process. 3 3 * 4 4 * Author Alain Greiner (2016,2017) … … 24 24 #include <kernel_config.h> 25 25 #include <hal_types.h> 26 #include <hal_irqmask.h> 26 27 #include <errno.h> 27 28 #include <thread.h> … … 36 37 uint32_t sig_id ) 37 38 { 39 uint32_t save_sr; // required to enable IRQs 40 41 #if CONFIG_SYSCALL_DEBUG 42 uint64_t tm_start; 43 uint64_t tm_end; 44 tm_start = hal_get_cycles(); 45 #endif 46 38 47 thread_t * this = CURRENT_THREAD; 39 48 process_t * process = this->process; 40 41 // check signal index42 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 manager51 cluster_t * cluster = LOCAL_CLUSTER;52 49 53 50 // get owner process cluster and lpid … … 55 52 lpid_t lpid = LPID_FROM_PID( pid ); 56 53 57 // check PID54 // check pid 58 55 if( (lpid >= CONFIG_MAX_PROCESS_PER_CLUSTER) || cluster_is_undefined( owner_cxy ) ) 59 56 { 60 57 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 ); 62 59 this->errno = EINVAL; 63 60 return -1; 64 61 } 65 62 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) ) 79 65 { 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; 92 70 } 93 71 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 ); 96 87 97 88 hal_fence(); 98 89 90 #if CONFIG_SYSCALL_DEBUG 91 tm_end = hal_get_cycles(); 92 syscall_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 , 95 tm_start , pid , (uint32_t)(tm_end - tm_start) ); 96 #endif 97 99 98 return 0; 100 99
Note: See TracChangeset
for help on using the changeset viewer.