Changeset 584 for trunk/kernel/syscalls/sys_kill.c
- Timestamp:
- Nov 1, 2018, 12:13:45 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_kill.c
r566 r584 35 35 #include <syscalls.h> 36 36 37 38 #if DEBUG_SYS_KILL 39 //////////////////////////////////////////// 40 static char* sig_type_str( uint32_t sig_id ) 41 { 42 switch( sig_id ) 43 { 44 case SIGKILL: return "SIGKILL"; 45 case SIGSTOP: return "SIGSTOP"; 46 case SIGCONT: return "SIGCONT"; 47 default: return "undefined"; 48 } 49 } 50 #endif 51 52 37 53 /////////////////////////// 38 54 int sys_kill( pid_t pid, 39 55 uint32_t sig_id ) 40 56 { 41 reg_t save_sr; // required to enable IRQs42 57 xptr_t owner_xp; // extended pointer on process in owner cluster 43 58 cxy_t owner_cxy; // process owner cluster 44 59 process_t * owner_ptr; // local pointer on process in owner cluster 45 uint32_t retval; // return value for the switch46 60 xptr_t parent_xp; // extended pointer on parent process 47 61 cxy_t parent_cxy; // parent process cluster … … 53 67 process_t * process = this->process; 54 68 69 #if (DEBUG_SYS_KILL || CONFIG_INSTRUMENTATION_SYSCALLS) 70 uint64_t tm_start = hal_get_cycles(); 71 #endif 72 55 73 #if DEBUG_SYS_KILL 56 uint64_t tm_start;57 uint64_t tm_end;58 74 tm_start = hal_get_cycles(); 59 75 if( DEBUG_SYS_KILL < tm_start ) 60 printk("\n[DBG] %s : thread %x enter / process %x / sig %d / cycle %d\n", 61 __FUNCTION__ , this, pid, sig_id, (uint32_t)tm_start ); 76 printk("\n[DBG] %s : thread[%x,%x] enter / process %x / %s / cycle %d\n", 77 __FUNCTION__, this->process->pid, this->trdid, pid, 78 sig_type_str(sig_id), (uint32_t)tm_start ); 62 79 #endif 63 80 … … 69 86 #if (DEBUG_SYS_KILL & 1) 70 87 if( DEBUG_SYS_KILL < tm_start ) 71 printk("\n[DBG] %s : thread %xget owner process %x in cluster %x\n",72 __FUNCTION__ , this , owner_ptr, owner_cxy );88 printk("\n[DBG] %s : thread[%x,%x] get owner process %x in cluster %x\n", 89 __FUNCTION__ , this->process->pid, this->trdid, owner_ptr, owner_cxy ); 73 90 #endif 74 91 … … 81 98 #endif 82 99 this->errno = EINVAL; 83 return -1;84 }85 86 // process cannot kill itself87 if( (pid == process->pid) )88 {89 90 #if DEBUG_SYSCALLS_ERROR91 printk("\n[ERROR] in %s : process %x cannot kill itself\n", __FUNCTION__, pid );92 #endif93 this->errno = EINVAL;94 return -1;95 }96 97 // processe INIT cannot be killed98 if( pid == 1 )99 {100 101 #if DEBUG_SYSCALLS_ERROR102 printk("\n[ERROR] in %s : process_init cannot be killed\n", __FUNCTION__ );103 #endif104 this->errno = EINVAL;105 100 return -1; 106 101 } … … 113 108 #if (DEBUG_SYS_KILL & 1) 114 109 if( DEBUG_SYS_KILL < tm_start ) 115 printk("\n[DBG] %s : thread %xget parent process %x in cluster %x\n",116 __FUNCTION__ , this , parent_ptr, parent_cxy );110 printk("\n[DBG] %s : thread[%x,%x] get parent process %x in cluster %x\n", 111 __FUNCTION__ , this->process->pid, this->trdid, parent_ptr, parent_cxy ); 117 112 #endif 118 113 … … 126 121 case 0 : // does nothing 127 122 { 128 retval = 0;129 123 break; 130 124 } 131 125 case SIGSTOP: // block all target process threads 132 126 { 133 // transfer TXT ownership 134 process_txt_transfer_ownership( owner_xp ); 135 136 // block all threads in all clusters, but the main thread 127 // block all threads in all clusters 137 128 process_sigaction( pid , BLOCK_ALL_THREADS ); 138 139 // block the main thread140 xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] );141 thread_block( main_xp , THREAD_BLOCKED_GLOBAL );142 129 143 130 // atomically update owner process termination state … … 145 132 PROCESS_TERM_STOP ); 146 133 147 // unblock the parent process main thread 134 // unblock the parent process main thread 148 135 thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); 149 136 150 retval = 0;151 137 break; 152 138 } … … 159 145 hal_remote_atomic_and( XPTR( owner_cxy , &owner_ptr->term_state ) , 160 146 ~PROCESS_TERM_STOP ); 161 retval = 0; 162 break; 163 } 164 break; 147 148 // unblock the parent process main thread 149 thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); 150 151 break; 152 } 165 153 case SIGKILL: 166 154 { 155 // a process cannot kill itself 156 if( (pid == process->pid) ) 157 { 158 159 #if DEBUG_SYSCALLS_ERROR 160 printk("\n[ERROR] in %s : process %x cannot kill itself\n", __FUNCTION__, pid ); 161 #endif 162 this->errno = EINVAL; 163 return -1; 164 } 165 166 // processe INIT cannot be killed 167 if( pid == 1 ) 168 { 169 170 #if DEBUG_SYSCALLS_ERROR 171 printk("\n[ERROR] in %s : process_init cannot be killed\n", __FUNCTION__ ); 172 #endif 173 this->errno = EINVAL; 174 return -1; 175 } 176 167 177 // remove process from TXT list 168 178 process_txt_detach( owner_xp ); 169 179 170 180 // mark for delete all threads in all clusters, but the main 171 hal_enable_irq( &save_sr );172 181 process_sigaction( pid , DELETE_ALL_THREADS ); 173 hal_restore_irq( save_sr );174 182 175 183 // block main thread … … 185 193 thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); 186 194 187 retval = 0;188 195 break; 189 196 } … … 195 202 #endif 196 203 this->errno = EINVAL; 197 retval = -1; 198 break; 204 return -1; 199 205 } 200 206 } … … 202 208 hal_fence(); 203 209 210 #if (DEBUG_SYS_KILL || CONFIG_INSTRUMENTATION_SYSCALLS) 211 uint64_t tm_end = hal_get_cycles(); 212 #endif 213 204 214 #if DEBUG_SYS_KILL 205 tm_end = hal_get_cycles();206 215 if( DEBUG_SYS_KILL < tm_end ) 207 printk("\n[DBG] %s : thread %x exit / process %x / sig %d / cost = %d / cycle %d\n", 208 __FUNCTION__ , this, pid, sig_id, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 209 #endif 210 211 return retval; 216 printk("\n[DBG] %s : thread[%x,%x] exit / process %x / %s / cost = %d / cycle %d\n", 217 __FUNCTION__ , this->process->pid, this->trdid, pid, 218 sig_type_str(sig_id), (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 219 #endif 220 221 #if CONFIG_INSTRUMENTATION_SYSCALLS 222 hal_atomic_add( &syscalls_cumul_cost[SYS_KILL] , tm_end - tm_start ); 223 hal_atomic_add( &syscalls_occurences[SYS_KILL] , 1 ); 224 #endif 225 226 return 0; 212 227 213 228 } // end sys_kill()
Note: See TracChangeset
for help on using the changeset viewer.