Changeset 436 for trunk/kernel/syscalls/sys_kill.c
- Timestamp:
- Mar 7, 2018, 9:02:03 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_kill.c
r435 r436 37 37 uint32_t sig_id ) 38 38 { 39 uint32_t save_sr; // required to enable IRQs 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 39 xptr_t owner_xp; // extended pointer on target process in owner cluster 40 cxy_t owner_cxy; // target process owner cluster 41 process_t * owner_ptr; // local pointer on target process in owner cluster 43 42 xptr_t parent_xp; // extended pointer on parent process 44 43 cxy_t parent_cxy; // parent process cluster … … 49 48 thread_t * this = CURRENT_THREAD; 50 49 process_t * process = this->process; 50 trdid_t trdid = this->trdid; 51 51 52 52 #if CONFIG_DEBUG_SYS_KILL … … 59 59 #endif 60 60 61 // process cannot kill itself 62 if( pid == process->pid ) 61 // get pointers on process descriptor in owner cluster 62 owner_xp = cluster_get_owner_process_from_pid( pid ); 63 owner_cxy = GET_CXY( owner_xp ); 64 owner_ptr = GET_PTR( owner_xp ); 65 66 // check process found 67 if( owner_xp == XPTR_NULL) 63 68 { 64 69 65 70 #if CONFIG_DEBUG_SYSCALLS_ERROR 66 printk("\n[ERROR] in %s : process % d cannot kill itself\n", __FUNCTION__, pid );71 printk("\n[ERROR] in %s : process %x not found\n", __FUNCTION__, pid ); 67 72 #endif 68 73 this->errno = EINVAL; … … 70 75 } 71 76 72 // get cluster and pointers on owner target process descriptor 73 owner_xp = cluster_get_owner_process_from_pid( pid ); 74 owner_cxy = GET_CXY( owner_xp ); 75 owner_ptr = GET_PTR( owner_xp ); 76 77 // check process existence 78 if( owner_xp == XPTR_NULL ) 77 // process can kill itself only when calling thread is the main thread 78 if( (pid == process->pid) && ((owner_cxy != local_cxy) || (LTID_FROM_TRDID( trdid ))) ) 79 79 { 80 80 81 81 #if CONFIG_DEBUG_SYSCALLS_ERROR 82 printk("\n[ERROR] in %s : process %x not found\n", __FUNCTION__ , pid);82 printk("\n[ERROR] in %s : only main thread can kill itself\n", __FUNCTION__ ); 83 83 #endif 84 84 this->errno = EINVAL; 85 85 return -1; 86 86 } 87 87 88 88 // get parent process PID 89 89 parent_xp = hal_remote_lwd( XPTR( owner_cxy , &owner_ptr->parent_xp ) ); … … 92 92 ppid = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) ); 93 93 94 // processesINIT94 // check processe INIT 95 95 if( pid == 1 ) 96 96 { … … 103 103 } 104 104 105 // enable IRQs106 hal_enable_irq( &save_sr );107 108 105 // analyse signal type / supported values are : 0, SIGSTOP, SIGCONT, SIGKILL 109 106 switch( sig_id ) 110 107 { 111 case 0 : 108 case 0 : // does nothing 112 109 { 113 // does nothing114 110 retval = 0; 115 111 break; 116 112 } 117 case SIGSTOP: 113 case SIGSTOP: // block all target process threads 118 114 { 119 // remove TXT ownership from target process120 process_txt_ reset_ownership( owner_xp );115 // transfer TXT ownership 116 process_txt_transfer_ownership( owner_xp ); 121 117 122 // block all threads in all clusters 118 // block all threads in all clusters, but the main thread 123 119 process_sigaction( pid , BLOCK_ALL_THREADS ); 120 121 // get pointer on target process main thread 122 xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] ); 123 124 // block main thread 125 thread_block( main_xp , THREAD_BLOCKED_GLOBAL ); 124 126 125 127 // atomically update owner process termination state 126 128 hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) , 127 129 PROCESS_TERM_STOP ); 128 129 130 retval = 0; 130 131 break; 131 132 } 132 case SIGCONT: 133 case SIGCONT: // unblock all target process threads 133 134 { 134 135 // unblock all threads in all clusters 135 136 process_sigaction( pid , UNBLOCK_ALL_THREADS ); 136 137 137 // atomically update referenceprocess termination state138 // atomically update owner process termination state 138 139 hal_remote_atomic_and( XPTR( owner_cxy , &owner_ptr->term_state ) , 139 140 ~PROCESS_TERM_STOP ); … … 144 145 case SIGKILL: 145 146 { 146 // remove TXT ownership from owner process descriptor147 process_txt_ reset_ownership( owner_xp );147 // remove process from TXT list 148 process_txt_detach( owner_xp ); 148 149 149 // block all process threads in all clusters 150 process_sigaction( pid , BLOCK_ALL_THREADS ); 151 152 // mark all process threads in all clusters for delete 150 // mark for delete all process threads in all clusters, but the main 153 151 process_sigaction( pid , DELETE_ALL_THREADS ); 154 152 155 // atomically update owner process descriptor flags 153 // get pointer on target process main thread 154 xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] ); 155 156 // block main thread 157 thread_block( main_xp , THREAD_BLOCKED_GLOBAL ); 158 159 // atomically update owner process descriptor term_state to ask 160 // the parent process sys_wait() function to delete this main thread 156 161 hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) , 157 162 PROCESS_TERM_KILL ); 158 159 163 retval = 0; 160 164 break; … … 172 176 } 173 177 174 // restore IRQs175 hal_restore_irq( save_sr );176 177 178 hal_fence(); 178 179 … … 180 181 tm_end = hal_get_cycles(); 181 182 if( CONFIG_DEBUG_SYS_KILL < tm_end ) 182 printk("\n[DBG] %s : thread %x e nter/ process %x / sig %d / cost = %d / cycle %d\n",183 printk("\n[DBG] %s : thread %x exit / process %x / sig %d / cost = %d / cycle %d\n", 183 184 __FUNCTION__ , this, pid, sig_id, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 184 185 #endif
Note: See TracChangeset
for help on using the changeset viewer.