Changeset 651 for trunk/kernel/syscalls/sys_thread_exit.c
- Timestamp:
- Nov 14, 2019, 11:50:09 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_thread_exit.c
r635 r651 33 33 #include <syscalls.h> 34 34 35 //////////////////////////////////////// 36 int sys_thread_exit( void * exit_ value)35 ///////////////////////////////////////// 36 int sys_thread_exit( void * exit_status ) 37 37 { 38 error_t error; 39 vseg_t * vseg; 40 38 41 thread_t * this = CURRENT_THREAD; 39 42 trdid_t trdid = this->trdid; 40 43 process_t * process = this->process; 41 44 pid_t pid = process->pid; 45 46 // check exit_value pointer in user space if required 47 if( exit_status != NULL ) 48 { 49 error = vmm_get_vseg( process , (intptr_t)exit_status , &vseg ); 42 50 43 // check exit_value argument 44 if( exit_value != NULL ) 45 { 51 if( error ) 52 { 46 53 47 54 #if DEBUG_SYSCALLS_ERROR 48 printk("\n[ERROR] in %s : thread[%x,%x] / exit_value argument %x must be NULL\n",49 __FUNCTION__ , pid, trdid , exit_value);55 printk("\n[ERROR] in %s : exit_status buffer %x unmapped / thread[%x,%x]\n", 56 __FUNCTION__, (intptr_t)exit_status, process->pid, this->trdid ); 50 57 #endif 51 this->errno = EINVAL; 52 return -1; 58 this->errno = EINVAL; 59 return -1; 60 } 61 } 62 63 // check busylocks 64 uint32_t count = this->busylocks; 65 if( count ) 66 { 67 68 #if DEBUG_SYSCALLS_ERROR 69 printk("\n[ERROR] in %s : busylocks count = %d / thread[%x,%x]\n", 70 __FUNCTION__ , count, process->pid, this->trdid ); 71 #endif 72 this->errno = EINVAL; 73 return -1; 53 74 } 54 75 55 76 // If calling thread is the main thread, the process must be deleted. 56 // => delete all process threads and synchronise with parent process. 57 // If calling thread is not the main thread, it must be deleted. 58 // => block the thread and mark it for delete. 59 if( (CXY_FROM_PID( pid ) == local_cxy) && (LTID_FROM_TRDID(trdid) == 0) ) 77 // => delete all process threads and synchronize with parent process. 78 // If calling thread is not the main thread, only this thread must be deleted. 79 // => register exit_status in thread descriptor, block the thread, 80 // mark it for delete, and synchronize with joining thread. 81 82 if( (CXY_FROM_PID( pid ) == local_cxy) && (LTID_FROM_TRDID(trdid) == 0) ) // main 60 83 { 61 84 … … 69 92 sys_exit( 0 ); 70 93 } 71 else 94 else // not the main 72 95 { 73 96 … … 78 101 __FUNCTION__ , pid , trdid , (uint32_t)tm_start ); 79 102 #endif 103 // register exit_status in thread descriptor 104 this->exit_status = exit_status; 105 80 106 // block calling thread and mark it for delete, 81 thread_delete( XPTR( local_cxy , this ) , pid , false );107 thread_delete( XPTR( local_cxy , this ) , false ); // not forced 82 108 83 109 // deschedule
Note: See TracChangeset
for help on using the changeset viewer.