Changeset 440 for trunk/kernel/syscalls/sys_exit.c
- Timestamp:
- May 3, 2018, 5:51:22 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_exit.c
r438 r440 2 2 * sys_exit.c - Kernel function implementing the "exit" system call. 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 41 41 process_t * process = this->process; 42 42 pid_t pid = process->pid; 43 trdid_t trdid = this->trdid;44 43 45 44 #if DEBUG_SYS_EXIT … … 52 51 #endif 53 52 54 // get owner cluster 55 cxy_t owner_cxy = CXY_FROM_PID( pid ); 53 // get owner process descriptor pointers an cluster 54 xptr_t owner_xp = cluster_get_owner_process_from_pid( pid ); 55 cxy_t owner_cxy = GET_CXY( owner_xp ); 56 process_t * owner_ptr = GET_PTR( owner_xp ); 56 57 57 // exit must be called by the main thread 58 if( (owner_cxy != local_cxy) || (LTID_FROM_TRDID( trdid ) != 0) ) 59 { 60 61 #if DEBUG_SYSCALLS_ERROR 62 printk("\n[ERROR] in %s : calling thread %x is not thread 0 in owner cluster %x\n", 63 __FUNCTION__, trdid, owner_cxy ); 64 #endif 65 this->errno = EINVAL; 66 return -1; 67 } 58 // get pointers on the process main thread 59 thread_t * main = hal_remote_lpt( XPTR( owner_cxy , &owner_ptr->th_tbl[0] ) ); 68 60 69 61 // enable IRQs 70 62 hal_enable_irq( &save_sr ); 71 63 72 // register exit_status in owner process descriptor 73 process->term_state = status; 64 // mark for delete all process threads in all clusters 65 // (but the main thread and this calling thread) 66 process_sigaction( pid , DELETE_ALL_THREADS ); 67 68 // disable IRQs 69 hal_restore_irq( save_sr ); 74 70 75 71 #if( DEBUG_SYS_EXIT & 1) 76 printk("\n[DBG] %s : set exit status in process term_state\n", __FUNCTION__); 72 if( tm_start > DEBUG_SYS_EXIT ) 73 printk("\n[DBG] %s : thread %x deleted threads / process %x\n", 74 __FUNCTION__ , this, pid ); 77 75 #endif 78 76 79 // remove process from TXT list 80 process_txt_detach( XPTR( local_cxy , process ) ); 77 // mark for delete this calling thread when it is not the main 78 if( (owner_cxy != local_cxy) || (main != this) ) 79 { 81 80 82 81 #if( DEBUG_SYS_EXIT & 1) 83 printk("\n[DBG] %s : removed from TXT list\n", __FUNCTION__); 82 if( tm_start > DEBUG_SYS_EXIT ) 83 printk("\n[DBG] %s : calling thread %x deleted itself / process %x\n", 84 __FUNCTION__ , this, pid ); 85 #endif 86 thread_delete( XPTR( local_cxy , this ) , pid , true ); 87 } 88 89 // remove process from TXT list 90 process_txt_detach( owner_xp ); 91 92 #if( DEBUG_SYS_EXIT & 1) 93 if( tm_start > DEBUG_SYS_EXIT ) 94 printk("\n[DBG] %s : thread %x removed process %x from TXT list\n", 95 __FUNCTION__ , this, pid ); 84 96 #endif 85 97 86 // mark for delete all process threads in all clusters (but the main)87 process_sigaction( pid , DELETE_ALL_THREADS);98 // block the main thread 99 thread_block( XPTR( owner_cxy , main ) , THREAD_BLOCKED_GLOBAL ); 88 100 89 101 #if( DEBUG_SYS_EXIT & 1) 90 printk("\n[DBG] %s : deleted all other threads than main\n", __FUNCTION__); 91 #endif 92 93 // restore IRQs 94 hal_restore_irq( save_sr ); 95 96 // block the main thread itself 97 thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_GLOBAL ); 98 99 #if( DEBUG_SYS_EXIT & 1) 100 printk("\n[DBG] %s : blocked the main thread\n", __FUNCTION__); 102 if( tm_start > DEBUG_SYS_EXIT ) 103 printk("\n[DBG] %s : thread %x blocked main thread for process %x\n", 104 __FUNCTION__, this , pid ); 101 105 #endif 102 106 103 107 // atomically update owner process descriptor term_state to ask 104 // the parent process sys_wait() function to delete th ismain thread105 hal_remote_atomic_or( XPTR( local_cxy , &process->term_state ) ,106 PROCESS_TERM_EXIT );108 // the parent process sys_wait() function to delete the main thread 109 hal_remote_atomic_or( XPTR( owner_cxy , &process->term_state ) , 110 PROCESS_TERM_EXIT | (status & 0xFF) ); 107 111 108 112 #if( DEBUG_SYS_EXIT & 1) 109 printk("\n[DBG] %s : set EXIT flag in process term_state\n", __FUNCTION__); 113 if( tm_start > DEBUG_SYS_EXIT ) 114 printk("\n[DBG] %s : thread %x set exit status in process %x term_state\n", 115 __FUNCTION__ , this, pid ); 110 116 #endif 111 117 … … 119 125 #endif 120 126 121 // mainthread deschedule127 // this thread deschedule 122 128 sched_yield( "process exit" ); 123 129
Note: See TracChangeset
for help on using the changeset viewer.