Changeset 433 for trunk/kernel/syscalls/sys_kill.c
- Timestamp:
- Feb 14, 2018, 3:40:19 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_kill.c
r421 r433 38 38 { 39 39 uint32_t save_sr; // required to enable IRQs 40 xptr_t process_xp;// extended pointer on target reference process41 cxy_t process_cxy;// target process cluster42 process_t * process_ptr;// local pointer on target process40 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 43 43 xptr_t parent_xp; // extended pointer on parent process 44 44 cxy_t parent_cxy; // parent process cluster 45 45 process_t * parent_ptr; // local pointer on parent process 46 46 pid_t ppid; // parent process PID 47 uint32_t retval; // return value for the switch 47 48 48 49 thread_t * this = CURRENT_THREAD; 49 50 50 #if CONFIG_ SYSCALL_DEBUG51 #if CONFIG_DEBUG_SYS_KILL 51 52 uint64_t tm_start; 52 53 uint64_t tm_end; 53 54 tm_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 ); 55 if( CONFIG_DEBUG_SYS_KILL < tm_start ) 56 printk("\n[DBG] %s : thread %x enter / process %x / sig %d / cycle %d\n", 57 __FUNCTION__ , this, pid, sig_id, (uint32_t)tm_start ); 56 58 #endif 57 59 58 // get cluster and pointers on referenceprocess59 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 ); 62 64 63 65 // check process existence 64 if( process_xp == XPTR_NULL )66 if( owner_xp == XPTR_NULL ) 65 67 { 66 syscall_dmsg("\n[ERROR] in %s : process %x not found\n", 67 __FUNCTION__ , pid ); 68 69 syscall_dmsg("\n[ERROR] in %s : process %x not found\n", __FUNCTION__ , pid ); 70 68 71 this->errno = EINVAL; 69 72 return -1; … … 71 74 72 75 // 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 ) ); 74 77 parent_cxy = GET_CXY( parent_xp ); 75 78 parent_ptr = GET_PTR( parent_xp ); … … 79 82 if( ppid < 2 ) 80 83 { 81 syscall_dmsg("\n[ERROR] in %s : process %x cannot be killed\n",82 __FUNCTION__ , pid );83 this->errno = EINVAL;84 return -1;85 }86 84 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 ); 85 syscall_dmsg("\n[ERROR] in %s : process %x cannot be killed\n", __FUNCTION__ , pid ); 86 95 87 this->errno = EINVAL; 96 88 return -1; … … 100 92 hal_enable_irq( &save_sr ); 101 93 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 ) 104 97 { 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 145 syscall_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 } 106 152 } 107 else // owner cluster is remote 108 { 109 rpc_process_make_kill_client( process_cxy , pid , sig_id ); 110 } 111 153 112 154 // restore IRQs 113 155 hal_restore_irq( save_sr ); … … 115 157 hal_fence(); 116 158 117 #if CONFIG_ SYSCALL_DEBUG159 #if CONFIG_DEBUG_SYS_KILL 118 160 tm_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) ); 161 if( CONFIG_DEBUG_SYS_KILL < tm_end ) 162 printk("\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 ); 121 164 #endif 122 123 return 0;165 166 return retval; 124 167 125 168 } // end sys_kill()
Note: See TracChangeset
for help on using the changeset viewer.