Changeset 440 for trunk/kernel/syscalls
- Timestamp:
- May 3, 2018, 5:51:22 PM (7 years ago)
- Location:
- trunk/kernel/syscalls
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_barrier.c
r23 r440 2 2 * sys_barrier.c - Access a POSIX barrier. 3 3 * 4 * authors Alain Greiner (2016,2017 )4 * authors Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 37 37 { 38 38 error_t error; 39 paddr_t paddr;39 vseg_t * vseg; 40 40 41 thread_t * this = CURRENT_THREAD; 41 thread_t * this = CURRENT_THREAD; 42 process_t * process = this->process; 42 43 43 44 // check vaddr in user vspace 44 error = vmm_v2p_translate( false , vaddr , &paddr ); 45 error = vmm_get_vseg( process , (intptr_t)vaddr , &vseg ); 46 45 47 if( error ) 46 48 { 47 printk("\n[ERROR] in %s : illegal barrier virtual address = %x\n", 48 __FUNCTION__ , (intptr_t)vaddr ); 49 50 #if DEBUG_SYSCALLS_ERROR 51 printk("\n[ERROR] in %s : unmapped barrier %x / thread %x / process %x\n", 52 __FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid ); 53 vmm_display( process , false ); 54 #endif 49 55 this->errno = error; 50 56 return -1; … … 61 67 if( error ) 62 68 { 63 printk("\n[ERROR] in %s : cannot create barrier = %x\n", 64 __FUNCTION__ , (intptr_t)vaddr ); 69 70 #if DEBUG_SYSCALLS_ERROR 71 printk("\n[ERROR] in %s : cannot create barrier %x / thread %x / process %x\n", 72 __FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid ); 73 #endif 65 74 this->errno = error; 66 75 return -1; … … 75 84 if( barrier_xp == XPTR_NULL ) // user error 76 85 { 77 printk("\n[ERROR] in %s : barrier %x not registered\n", 78 __FUNCTION__ , (intptr_t)vaddr ); 86 87 #if DEBUG_SYSCALLS_ERROR 88 printk("\n[ERROR] in %s : barrier %x not registered / thread %x / process %x\n", 89 __FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid ); 90 #endif 79 91 this->errno = EINVAL; 80 92 return -1; … … 93 105 if( barrier_xp == XPTR_NULL ) // user error 94 106 { 95 printk("\n[ERROR] in %s : barrier %x not registered\n", 96 __FUNCTION__ , (intptr_t)vaddr ); 107 108 #if DEBUG_SYSCALLS_ERROR 109 printk("\n[ERROR] in %s : barrier %x not registered / thread %x / process %x\n", 110 __FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid ); 111 #endif 97 112 this->errno = EINVAL; 98 113 return -1; -
trunk/kernel/syscalls/sys_condvar.c
r23 r440 2 2 * sys_condvar.c - Access a POSIX condvar. 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 30 30 #include <syscalls.h> 31 31 #include <remote_condvar.h> 32 #include <remote_mutex.h> 32 33 33 34 //////////////////////////////////////// … … 36 37 void * mutex ) 37 38 { 38 error_t error;39 paddr_t paddr;39 error_t error; 40 vseg_t * vseg; 40 41 41 thread_t * this = CURRENT_THREAD; 42 thread_t * this = CURRENT_THREAD; 43 process_t * process = this->process; 42 44 43 45 // check condvar in user vspace 44 error = vmm_v2p_translate( false , condvar , &paddr ); 46 error = vmm_get_vseg( process , (intptr_t)condvar , &vseg ); 47 45 48 if( error ) 46 49 { 47 printk("\n[ERROR] in %s : illegal condvar virtual address = %x\n", 48 __FUNCTION__ , (intptr_t)condvar ); 50 51 #if DEBUG_SYSCALLS_ERROR 52 printk("\n[ERROR] in %s : unmapped condvar %x / thread %x / process %x\n", 53 __FUNCTION__ , (intptr_t)condvar , this->trdid , process->pid ); 54 vmm_display( process , false ); 55 #endif 49 56 this->errno = error; 50 57 return -1; … … 61 68 if( error ) 62 69 { 63 printk("\n[ERROR] in %s : cannot create condvar = %x\n", 64 __FUNCTION__ , (intptr_t)condvar ); 70 71 #if DEBUG_SYSCALLS_ERROR 72 printk("\n[ERROR] in %s : cannot create condvar %x / thread %x / process %x\n", 73 __FUNCTION__ , (intptr_t)condvar , this->trdid , process->pid ); 74 #endif 65 75 this->errno = error; 66 76 return -1; … … 72 82 { 73 83 // check mutex in user vspace 74 error = vmm_ v2p_translate( false , mutex , &paddr);84 error = vmm_get_vseg( process , (intptr_t)mutex , &vseg ); 75 85 76 86 if( error ) 77 87 { 78 printk("\n[ERROR] in %s : illegal condvar virtual address = %x\n", 79 __FUNCTION__ , (intptr_t)condvar ); 88 89 #if DEBUG_SYSCALLS_ERROR 90 printk("\n[ERROR] in %s : unmapped mutex %x / thread %x / process %x\n", 91 __FUNCTION__ , (intptr_t)mutex , this->trdid , process->pid ); 92 #endif 80 93 this->errno = error; 81 94 return -1; … … 86 99 if( condvar_xp == XPTR_NULL ) // user error 87 100 { 88 printk("\n[ERROR] in %s : condvar %x not registered\n", 89 __FUNCTION__ , (intptr_t)condvar ); 101 102 #if DEBUG_SYSCALLS_ERROR 103 printk("\n[ERROR] in %s : condvar %x not registered / thread %x / process %x\n", 104 __FUNCTION__ , (intptr_t)condvar , this->trdid , process->pid ); 105 #endif 90 106 this->errno = EINVAL; 91 107 return -1; 92 108 } 93 109 94 xptr_t mutex_xp = remote_condvar_from_ident( (intptr_t)condvar ); 110 xptr_t mutex_xp = remote_mutex_from_ident( (intptr_t)mutex ); 111 95 112 if( mutex_xp == XPTR_NULL ) // user error 96 113 { 97 printk("\n[ERROR] in %s : mutex %x not registered\n", 98 __FUNCTION__ , (intptr_t)condvar ); 114 115 #if DEBUG_SYSCALLS_ERROR 116 printk("\n[ERROR] in %s : mutex %x not registered / thread %x / process %x\n", 117 __FUNCTION__ , (intptr_t)mutex , this->trdid , process->pid ); 118 #endif 99 119 this->errno = EINVAL; 100 120 return -1; … … 112 132 if( condvar_xp == XPTR_NULL ) // user error 113 133 { 114 printk("\n[ERROR] in %s : condvar %x not registered\n", 115 __FUNCTION__ , (intptr_t)condvar ); 134 135 #if DEBUG_SYSCALLS_ERROR 136 printk("\n[ERROR] in %s : condvar %x not registered / thread %x / process %x\n", 137 __FUNCTION__ , (intptr_t)condvar , this->trdid , process->pid ); 138 #endif 116 139 this->errno = EINVAL; 117 140 return -1; … … 129 152 if( condvar_xp == XPTR_NULL ) // user error 130 153 { 131 printk("\n[ERROR] in %s : condvar %x not registered\n", 132 __FUNCTION__ , (intptr_t)condvar ); 154 155 #if DEBUG_SYSCALLS_ERROR 156 printk("\n[ERROR] in %s : condvar %x not registered / thread %x / process %x\n", 157 __FUNCTION__ , (intptr_t)condvar , this->trdid , process->pid ); 158 #endif 133 159 this->errno = EINVAL; 134 160 return -1; … … 146 172 if( condvar_xp == XPTR_NULL ) // user error 147 173 { 148 printk("\n[ERROR] in %s : condvar %x not registered\n", 149 __FUNCTION__ , (intptr_t)condvar ); 174 175 #if DEBUG_SYSCALLS_ERROR 176 printk("\n[ERROR] in %s : condvar %x not registered / thread %x / process %x\n", 177 __FUNCTION__ , (intptr_t)condvar , this->trdid , process->pid ); 178 #endif 150 179 this->errno = EINVAL; 151 180 return -1; -
trunk/kernel/syscalls/sys_display.c
r438 r440 2 2 * sys_display.c - display the current state of a kernel structure on TXT0 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 38 38 { 39 39 40 error_t error; 41 vseg_t * vseg; 42 43 thread_t * this = CURRENT_THREAD; 44 process_t * process = this->process; 45 40 46 #if DEBUG_SYS_DISPLAY 41 47 uint64_t tm_start; 42 48 uint64_t tm_end; 43 thread_t * this;44 this = CURRENT_THREAD;45 49 tm_start = hal_get_cycles(); 46 50 if( DEBUG_SYS_DISPLAY < tm_start ) … … 49 53 #endif 50 54 55 //////////////////////////// 51 56 if( type == DISPLAY_STRING ) 52 57 { 53 paddr_t paddr;54 58 char kbuf[256]; 55 59 uint32_t length; 56 60 57 61 char * string = (char *)arg0; 58 62 59 63 // check string in user space 60 if( vmm_v2p_translate( false , string , &paddr ) ) 61 { 62 printk("\n[ERROR] in %s : string buffer %x unmapped\n", 63 __FUNCTION__ , string ); 64 error = vmm_get_vseg( process , (intptr_t)arg0 , &vseg ); 65 66 if( error ) 67 { 68 69 #if DEBUG_SYSCALLS_ERROR 70 printk("\n[ERROR] in %s : string buffer %x unmapped / thread %x / process %x\n", 71 __FUNCTION__ , (intptr_t)arg0 , this->trdid , process->pid ); 72 #endif 73 this->errno = EINVAL; 64 74 return -1; 65 75 } … … 67 77 // ckeck string length 68 78 length = hal_strlen_from_uspace( string ); 79 69 80 if( length >= 256 ) 70 81 { 71 printk("\n[ERROR] in %s : string length %d too large\n", 72 __FUNCTION__ , length ); 73 return -1; 74 } 75 76 // copy string in kernel space 82 83 #if DEBUG_SYSCALLS_ERROR 84 printk("\n[ERROR] in %s : string length %d too large / thread %x / process %x\n", 85 __FUNCTION__ , length , this->trdid , process->pid ); 86 #endif 87 this->errno = EINVAL; 88 return -1; 89 } 90 91 // copy string to kernel space 77 92 hal_strcpy_from_uspace( kbuf , string , 256 ); 78 93 79 94 // print message on TXT0 kernel terminal 80 printk("\n[USER] %s / cycle %d\n", kbuf, (uint32_t)hal_get_cycles() ); 81 } 95 printk("\n%s / cycle %d\n", kbuf, (uint32_t)hal_get_cycles() ); 96 } 97 ////////////////////////////// 82 98 else if( type == DISPLAY_VMM ) 83 99 { … … 89 105 if( process_xp == XPTR_NULL ) 90 106 { 91 printk("\n[ERROR] in %s : undefined PID %x\n", 92 __FUNCTION__ , pid ); 107 108 #if DEBUG_SYSCALLS_ERROR 109 printk("\n[ERROR] in %s : undefined pid argument %d / thread %x / process %x\n", 110 __FUNCTION__ , pid , this->trdid , process->pid ); 111 #endif 112 this->errno = EINVAL; 93 113 return -1; 94 114 } … … 108 128 } 109 129 } 130 //////////////////////////////// 110 131 else if( type == DISPLAY_SCHED ) 111 132 { … … 113 134 lid_t lid = (lid_t)arg1; 114 135 115 // check c lusterargument136 // check cxy argument 116 137 if( cluster_is_undefined( cxy ) ) 117 138 { 118 printk("\n[ERROR] in %s : undefined cluster identifier %x\n", 119 __FUNCTION__ , cxy ); 120 return -1; 121 } 122 123 // check core argument 139 140 #if DEBUG_SYSCALLS_ERROR 141 printk("\n[ERROR] in %s : illegal cxy argument %x / thread %x / process %x\n", 142 __FUNCTION__ , cxy , this->trdid , process->pid ); 143 #endif 144 this->errno = EINVAL; 145 return -1; 146 } 147 148 // check lid argument 124 149 if( lid >= LOCAL_CLUSTER->cores_nr ) 125 150 { 126 printk("\n[ERROR] in %s : undefined local index %d\n", 127 __FUNCTION__ , lid ); 151 152 #if DEBUG_SYSCALLS_ERROR 153 printk("\n[ERROR] in %s : illegal lid argument %x / thread %x / process %x\n", 154 __FUNCTION__ , lid , this->trdid , process->pid ); 155 #endif 156 this->errno = EINVAL; 128 157 return -1; 129 158 } … … 138 167 } 139 168 } 169 //////////////////////////////////////////// 140 170 else if( type == DISPLAY_CLUSTER_PROCESSES ) 141 171 { 142 172 cxy_t cxy = (cxy_t)arg0; 143 173 144 // check c lusterargument174 // check cxy argument 145 175 if( cluster_is_undefined( cxy ) ) 146 176 { 147 printk("\n[ERROR] in %s : undefined cluster identifier %x\n", 148 __FUNCTION__ , cxy ); 177 178 #if DEBUG_SYSCALLS_ERROR 179 printk("\n[ERROR] in %s : illegal cxy argument %x / thread %x / process %x\n", 180 __FUNCTION__ , cxy , this->trdid , process->pid ); 181 #endif 182 this->errno = EINVAL; 149 183 return -1; 150 184 } … … 152 186 cluster_processes_display( cxy ); 153 187 } 188 //////////////////////////////////////// 154 189 else if( type == DISPLAY_TXT_PROCESSES ) 155 190 { … … 159 194 if( txt_id >= LOCAL_CLUSTER->nb_txt_channels ) 160 195 { 161 printk("\n[ERROR] in %s : undefined TXT channel %x\n", 162 __FUNCTION__ , txt_id ); 196 197 #if DEBUG_SYSCALLS_ERROR 198 printk("\n[ERROR] in %s : illegal txt_id argument %d / thread %x / process %x\n", 199 __FUNCTION__ , txt_id , this->trdid , process->pid ); 200 #endif 201 this->errno = EINVAL; 163 202 return -1; 164 203 } … … 166 205 process_txt_display( txt_id ); 167 206 } 207 ////////////////////////////// 168 208 else if( type == DISPLAY_VFS ) 169 209 { 170 // call kernel function171 process_t * process = CURRENT_THREAD->process;172 210 vfs_display( process->vfs_root_xp ); 173 211 } 212 //////////////////////////////// 174 213 else if( type == DISPLAY_CHDEV ) 175 214 { 176 215 chdev_dir_display(); 177 216 } 217 //// 178 218 else 179 219 { 180 printk("\n[ERROR] in %s : undefined display type %x\n", 181 __FUNCTION__ , type ); 220 221 #if DEBUG_SYSCALLS_ERROR 222 printk("\n[ERROR] in %s : undefined display type %x / thread %x / process %x\n", 223 __FUNCTION__ , type , this->trdid , process->pid ); 224 #endif 225 this->errno = EINVAL; 182 226 return -1; 183 227 } -
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 -
trunk/kernel/syscalls/sys_fork.c
r438 r440 77 77 ref_process_xp = parent_process_ptr->ref_xp; 78 78 ref_process_cxy = GET_CXY( ref_process_xp ); 79 ref_process_ptr = (process_t *)GET_PTR( ref_process_xp );79 ref_process_ptr = GET_PTR( ref_process_xp ); 80 80 81 81 // check parent process children number from reference … … 104 104 } 105 105 106 #if( DEBUG_SYS_FORK & 1) 107 108 // dqdt_display(); 109 110 if( local_cxy == 0 ) 111 { 112 sched_display( 0 ); 113 rpc_sched_display_client( 1 , 0 ); 114 } 115 else 116 { 117 sched_display( 0 ); 118 rpc_sched_display_client( 0 , 0 ); 119 } 120 106 #if (DEBUG_SYS_FORK & 1 ) 121 107 if( DEBUG_SYS_FORK < tm_start ) 122 108 printk("\n[DBG] %s : parent_thread %x selected cluster %x\n", -
trunk/kernel/syscalls/sys_get_config.c
r438 r440 2 2 * sys_get_config.c - get hardware platform parameters. 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 37 37 uint32_t * ncores ) 38 38 { 39 paddr_t paddr; 40 uint32_t k_x_size; 41 uint32_t k_y_size; 42 uint32_t k_ncores; 43 44 error_t error = 0; 39 error_t error; 40 vseg_t * vseg; 41 uint32_t k_x_size; 42 uint32_t k_y_size; 43 uint32_t k_ncores; 45 44 46 45 thread_t * this = CURRENT_THREAD; … … 56 55 #endif 57 56 58 // check buffer in user space 59 error |= vmm_v2p_translate( false , x_size , &paddr ); 60 error |= vmm_v2p_translate( false , y_size , &paddr ); 61 error |= vmm_v2p_translate( false , ncores , &paddr ); 57 // check x_size buffer in user space 58 error = vmm_get_vseg( process , (intptr_t)x_size , &vseg ); 62 59 63 60 if( error ) … … 65 62 66 63 #if DEBUG_SYSCALLS_ERROR 67 printk("\n[ERROR] in %s : user buffer unmapped for thread %x in process %x\n", 68 __FUNCTION__ , this->trdid , process->pid ); 64 printk("\n[ERROR] in %s : x_size buffer unmapped / thread %x / process %x\n", 65 __FUNCTION__ , (intptr_t)x_size , this->trdid , process->pid ); 66 vmm_display( process , false ); 69 67 #endif 70 this->errno = EFAULT; 68 this->errno = EINVAL; 69 return -1; 70 } 71 72 // check y_size buffer in user space 73 error = vmm_get_vseg( process , (intptr_t)y_size , &vseg ); 74 75 if( error ) 76 { 77 78 #if DEBUG_SYSCALLS_ERROR 79 printk("\n[ERROR] in %s : y_size buffer unmapped / thread %x / process %x\n", 80 __FUNCTION__ , (intptr_t)y_size , this->trdid , process->pid ); 81 vmm_display( process , false ); 82 #endif 83 this->errno = EINVAL; 84 return -1; 85 } 86 87 // check ncores buffer in user space 88 error = vmm_get_vseg( process , (intptr_t)ncores , &vseg ); 89 90 if( error ) 91 { 92 93 #if DEBUG_SYSCALLS_ERROR 94 printk("\n[ERROR] in %s : ncores buffer unmapped / thread %x / process %x\n", 95 __FUNCTION__ , (intptr_t)ncores , this->trdid , process->pid ); 96 vmm_display( process , false ); 97 #endif 98 this->errno = EINVAL; 71 99 return -1; 72 100 } -
trunk/kernel/syscalls/sys_get_core.c
r410 r440 37 37 uint32_t * lid ) 38 38 { 39 paddr_t paddr; 39 error_t error; 40 vseg_t * vseg; 40 41 uint32_t k_cxy; 41 42 uint32_t k_lid; 42 43 error_t error = 0;44 43 45 44 thread_t * this = CURRENT_THREAD; 46 45 process_t * process = this->process; 47 46 48 // check buffers in user space 49 error |= vmm_v2p_translate( false , cxy , &paddr ); 50 error |= vmm_v2p_translate( false , lid , &paddr ); 47 // check cxy buffer in user space 48 error = vmm_get_vseg( process , (intptr_t)cxy , &vseg ); 51 49 52 50 if( error ) 53 51 { 54 printk("\n[ERROR] in %s : user buffer unmapped for thread %x in process %x\n", 55 __FUNCTION__ , this->trdid , process->pid ); 52 53 #if DEBUG_SYSCALLS_ERROR 54 printk("\n[ERROR] in %s : cxy buffer unmapped %x / thread %x / process %x\n", 55 __FUNCTION__ , (intptr_t)cxy , this->trdid , process->pid ); 56 vmm_display( process , false ); 57 #endif 58 this->errno = EFAULT; 59 return -1; 60 } 61 62 // check lid buffer in user space 63 error = vmm_get_vseg( process , (intptr_t)lid , &vseg ); 64 65 if( error ) 66 { 67 68 #if DEBUG_SYSCALLS_ERROR 69 printk("\n[ERROR] in %s : lid buffer unmapped %x / thread %x / process %x\n", 70 __FUNCTION__ , (intptr_t)lid , this->trdid , process->pid ); 71 vmm_display( process , false ); 72 #endif 56 73 this->errno = EFAULT; 57 74 return -1; -
trunk/kernel/syscalls/sys_get_cycle.c
r408 r440 2 2 * sys_get_cycle.c - get calling core cycles count. 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 35 35 int sys_get_cycle ( uint64_t * cycle ) 36 36 { 37 error_t error;38 paddr_t paddr;39 uint64_t k_cycle;37 error_t error; 38 vseg_t * vseg; 39 uint64_t k_cycle; 40 40 41 41 thread_t * this = CURRENT_THREAD; … … 43 43 44 44 // check buffer in user space 45 error = vmm_ v2p_translate( false , cycle , &paddr);45 error = vmm_get_vseg( process , (intptr_t)cycle , &vseg ); 46 46 47 47 if( error ) 48 48 { 49 printk("\n[ERROR] in %s : user buffer unmapped for thread %x in process %x\n", 50 __FUNCTION__ , this->trdid , process->pid ); 49 50 #if DEBUG_SYSCALLS_ERROR 51 printk("\n[ERROR] in %s : user buffer unmapped %x / thread %x / process %x\n", 52 __FUNCTION__ , (intptr_t)cycle , this->trdid , process->pid ); 53 vmm_display( process , false ); 54 #endif 51 55 this->errno = EFAULT; 52 56 return -1; -
trunk/kernel/syscalls/sys_getcwd.c
r124 r440 2 2 * sys_getcwd.c - get process current work directory 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 40 40 { 41 41 error_t error; 42 paddr_t paddr;42 vseg_t * vseg; 43 43 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 44 44 … … 49 49 if( nbytes < CONFIG_VFS_MAX_PATH_LENGTH ) 50 50 { 51 printk("\n[ERROR] in %s : buffer too small\n", __FUNCTION__ ); 52 this->errno = ERANGE; 51 52 #if DEBUG_SYSCALLS_ERROR 53 printk("\n[ERROR] in %s : buffer too small / thread %x / process %x\n", 54 __FUNCTION__ , this->trdid , process->pid ); 55 #endif 56 this->errno = EINVAL; 53 57 return -1; 54 58 } 55 59 56 60 // check buffer in user space 57 error = vmm_ v2p_translate( false , buf , &paddr);61 error = vmm_get_vseg( process, (intptr_t)buf , &vseg ); 58 62 59 63 if( error ) 60 64 { 61 printk("\n[ERROR] in %s : user buffer unmapped\n", __FUNCTION__ ); 62 this->errno = EFAULT; 65 66 #if DEBUG_SYSCALLS_ERROR 67 printk("\n[ERROR] in %s : user buffer unmapped %x / thread %x / process %x\n", 68 __FUNCTION__ , (intptr_t)buf , this->trdid , process->pid ); 69 #endif 70 this->errno = EINVAL; 63 71 return -1; 64 72 } -
trunk/kernel/syscalls/sys_kill.c
r438 r440 2 2 * sys_kill.c - Kernel function implementing the "kill" 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 … … 38 38 { 39 39 xptr_t owner_xp; // extended pointer on target process in owner cluster 40 cxy_t owner_cxy; // target process owner cluster40 cxy_t owner_cxy; // target process in owner cluster 41 41 process_t * owner_ptr; // local pointer on target process in owner cluster 42 xptr_t parent_xp; // extended pointer on parent process43 cxy_t parent_cxy; // parent process cluster44 process_t * parent_ptr; // local pointer on parent process45 pid_t ppid; // parent process PID46 42 uint32_t retval; // return value for the switch 47 43 48 44 thread_t * this = CURRENT_THREAD; 49 45 process_t * process = this->process; 50 trdid_t trdid = this->trdid;51 46 52 47 #if DEBUG_SYS_KILL … … 75 70 } 76 71 77 // process can kill itself only when calling thread is the main thread78 if( (pid == process->pid) && ((owner_cxy != local_cxy) || (LTID_FROM_TRDID( trdid ))))72 // process cannot kill itself 73 if( (pid == process->pid) ) 79 74 { 80 75 81 76 #if DEBUG_SYSCALLS_ERROR 82 printk("\n[ERROR] in %s : only main thread can kill itself\n", __FUNCTION__);77 printk("\n[ERROR] in %s : process %x cannot kill itself\n", __FUNCTION__, pid ); 83 78 #endif 84 79 this->errno = EINVAL; … … 86 81 } 87 82 88 // get parent process PID 89 parent_xp = hal_remote_lwd( XPTR( owner_cxy , &owner_ptr->parent_xp ) ); 90 parent_cxy = GET_CXY( parent_xp ); 91 parent_ptr = GET_PTR( parent_xp ); 92 ppid = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) ); 93 94 // check processe INIT 83 // processe INIT cannot be killed 95 84 if( pid == 1 ) 96 85 { -
trunk/kernel/syscalls/sys_mmap.c
r438 r440 3 3 * 4 4 * Authors Ghassan Almaless (2008,2009,2010,2011,2012) 5 * Alain Greiner (2016,2017 )5 * Alain Greiner (2016,2017,2018) 6 6 * 7 7 * Copyright (c) UPMC Sorbonne Universites … … 44 44 xptr_t mapper_xp; 45 45 error_t error; 46 paddr_t paddr; // unused, but required for user space checking47 46 reg_t save_sr; // required to enable IRQs 48 47 … … 60 59 61 60 // check arguments in user space 62 error = vmm_ v2p_translate( false , attr , &paddr);61 error = vmm_get_vseg( process , (intptr_t)attr , &vseg ); 63 62 64 63 if ( error ) … … 66 65 67 66 #if DEBUG_SYSCALLS_ERROR 68 printk("\n[ERROR] in %s : arguments not in used space = %x\n", __FUNCTION__ , (intptr_t)attr ); 67 printk("\n[ERROR] in %s : user buffer unmapped %x / thread %x / process %x\n", 68 __FUNCTION__ , (intptr_t)attr , this->trdid , process->pid ); 69 vmm_display( process , false ); 69 70 #endif 70 71 this->errno = EINVAL; … … 92 93 93 94 #if DEBUG_SYSCALLS_ERROR 94 printk("\n[ERROR] in %s : MAP_FIXED not supported\n", __FUNCTION__ ); 95 printk("\n[ERROR] in %s : MAP_FIXED not supported / thread %x / process %x\n", 96 __FUNCTION__ , this->trdid , process->pid ); 95 97 #endif 96 98 this->errno = EINVAL; … … 102 104 103 105 #if DEBUG_SYSCALLS_ERROR 104 printk("\n[ERROR] in %s : MAP_SHARED xor MAP_PRIVATE\n", __FUNCTION__ ); 106 printk("\n[ERROR] in %s : MAP_SHARED == MAP_PRIVATE / thread %x / process %x\n", 107 __FUNCTION__ , this->trdid , process->pid ); 105 108 #endif 106 109 this->errno = EINVAL; … … 124 127 125 128 #if DEBUG_SYSCALLS_ERROR 126 printk("\n[ERROR] in %s: bad file descriptor = %d\n", __FUNCTION__ , fdid ); 129 printk("\n[ERROR] in %s: bad file descriptor %d / thread %x / process %x\n", 130 __FUNCTION__ , fdid , this->trdid , process->pid ); 127 131 #endif 128 132 this->errno = EBADFD; … … 137 141 138 142 #if DEBUG_SYSCALLS_ERROR 139 printk("\n[ERROR] in %s: file %d not found\n", __FUNCTION__ , fdid ); 143 printk("\n[ERROR] in %s: file %d not found / thread %x / process %x\n", 144 __FUNCTION__ , fdid , this->trdid , process->pid ); 140 145 #endif 141 146 this->errno = EBADFD; … … 160 165 161 166 #if DEBUG_SYSCALLS_ERROR 162 printk("\n[ERROR] in %s: offset (%d) + len (%d) >= file's size (%d)\n",163 __FUNCTION__, k_attr.offset, k_attr.length, size );167 printk("\n[ERROR] in %s: offset(%d) + len(%d) >= file's size(%d) / thread %x / process %x\n", 168 __FUNCTION__, k_attr.offset, k_attr.length, size, this->trdid, process->pid ); 164 169 #endif 165 170 this->errno = ERANGE; … … 173 178 174 179 #if DEBUG_SYSCALLS_ERROR 175 printk("\n[ERROR] in %s: prot = %x / file_attr = %x )\n",176 __FUNCTION__ , k_attr.prot , file_attr );180 printk("\n[ERROR] in %s: prot = %x / file_attr = %x / thread %x , process %x\n", 181 __FUNCTION__ , k_attr.prot , file_attr , this->trdid , process->pid ); 177 182 #endif 178 183 this->errno = EACCES; … … 206 211 207 212 #if DEBUG_SYSCALLS_ERROR 208 printk("\n[ERROR] in %s : illegal cxy for MAP_REMOTE\n", __FUNCTION__ ); 213 printk("\n[ERROR] in %s : illegal cxy for MAP_REMOTE / thread %x / process %x\n", 214 __FUNCTION__, this->trdid , process->pid ); 209 215 #endif 210 216 this->errno = EINVAL; … … 255 261 256 262 #if DEBUG_SYSCALLS_ERROR 257 printk("\n[ERROR] in %s : cannot create vseg\n", __FUNCTION__ ); 263 printk("\n[ERROR] in %s : cannot create vseg / thread %x / process %x\n", 264 __FUNCTION__, this->trdid , process->pid ); 258 265 #endif 259 266 this->errno = ENOMEM; -
trunk/kernel/syscalls/sys_mutex.c
r23 r440 2 2 * sys_mutex.c - Access a POSIX mutex. 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 37 37 uint32_t attr ) 38 38 { 39 error_t error;40 paddr_t paddr;39 error_t error; 40 vseg_t * vseg; 41 41 42 thread_t * this = CURRENT_THREAD; 42 thread_t * this = CURRENT_THREAD; 43 process_t * process = this->process; 43 44 44 45 // check vaddr in user vspace 45 error = vmm_v2p_translate( false , vaddr , &paddr ); 46 error = vmm_get_vseg( process , (intptr_t)vaddr , &vseg ); 47 46 48 if( error ) 47 49 { 48 printk("\n[ERROR] in %s : illegal virtual address = %x\n", 49 __FUNCTION__ , (intptr_t)vaddr ); 50 51 #if DEBUG_SYSCALLS_ERROR 52 printk("\n[ERROR] in %s : mutex unmapped %x / thread %x / process %x\n", 53 __FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid ); 54 vmm_display( process , false ); 55 #endif 50 56 this->errno = error; 51 57 return -1; … … 60 66 if( attr != 0 ) 61 67 { 62 printk("\n[ERROR] in %s : mutex attributes non supported yet\n", 63 __FUNCTION__ ); 68 69 #if DEBUG_SYSCALLS_ERROR 70 printk("\n[ERROR] in %s : mutex attribute non supported / thread %x / process %x\n", 71 __FUNCTION__ , this->trdid , process->pid ); 72 #endif 64 73 this->errno = error; 65 74 return -1; … … 70 79 if( error ) 71 80 { 72 printk("\n[ERROR] in %s : cannot create mutex\n", 73 __FUNCTION__ ); 81 82 #if DEBUG_SYSCALLS_ERROR 83 printk("\n[ERROR] in %s : cannot create mutex / thread %x / process %x\n", 84 __FUNCTION__ , this->trdid , process->pid ); 85 #endif 74 86 this->errno = error; 75 87 return -1; … … 84 96 if( mutex_xp == XPTR_NULL ) // user error 85 97 { 86 printk("\n[ERROR] in %s : mutex %x not registered\n", 87 __FUNCTION__ , (intptr_t)vaddr ); 98 99 #if DEBUG_SYSCALLS_ERROR 100 printk("\n[ERROR] in %s : mutex %x not registered / thread %x / process %x\n", 101 __FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid ); 102 #endif 88 103 this->errno = EINVAL; 89 104 return -1; … … 102 117 if( mutex_xp == XPTR_NULL ) // user error 103 118 { 104 printk("\n[ERROR] in %s : mutex %x not registered\n", 105 __FUNCTION__ , (intptr_t)vaddr ); 119 120 #if DEBUG_SYSCALLS_ERROR 121 printk("\n[ERROR] in %s : mutex %x not registered / thread %x / process %x\n", 122 __FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid ); 123 #endif 106 124 this->errno = EINVAL; 107 125 return -1; … … 120 138 if( mutex_xp == XPTR_NULL ) // user error 121 139 { 122 printk("\n[ERROR] in %s : mutex %x not registered\n", 123 __FUNCTION__ , (intptr_t)vaddr ); 140 141 #if DEBUG_SYSCALLS_ERROR 142 printk("\n[ERROR] in %s : mutex %x not registered / thread %x / process %x\n", 143 __FUNCTION__ , (intptr_t)vaddr , this->trdid , process->pid ); 144 #endif 124 145 this->errno = EINVAL; 125 146 return -1; -
trunk/kernel/syscalls/sys_read.c
r438 r440 2 2 * sys_read.c - read bytes from a file 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 58 58 { 59 59 error_t error; 60 paddr_t paddr;// required for user space checking60 vseg_t * vseg; // required for user space checking 61 61 xptr_t file_xp; // remote file extended pointer 62 62 uint32_t nbytes; // number of bytes actually read … … 91 91 92 92 // check user buffer in user space 93 error = vmm_ v2p_translate( false , vaddr , &paddr);93 error = vmm_get_vseg( process , (intptr_t)vaddr , &vseg ); 94 94 95 95 if ( error ) … … 97 97 98 98 #if DEBUG_SYSCALLS_ERROR 99 printk("\n[ERROR] in %s : user buffer unmapped = %x\n", 100 __FUNCTION__ , (intptr_t)vaddr ); 99 printk("\n[ERROR] in %s : user buffer unmapped %x / thread %x / process %x\n", 100 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid ); 101 vmm_display( process , false ); 101 102 #endif 102 103 this->errno = EINVAL; -
trunk/kernel/syscalls/sys_sem.c
r23 r440 2 2 * sys_sem.c - Acces a POSIX unamed semaphore. 3 3 * 4 * Authors Alain Greiner (2016,2017 )4 * Authors Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 36 36 uint32_t * value ) // pointer on in/out argument 37 37 { 38 uint32_t 39 paddr_t paddr;40 error_t 38 uint32_t data; 39 vseg_t * vseg; 40 error_t error; 41 41 42 thread_t * this = CURRENT_THREAD; 42 thread_t * this = CURRENT_THREAD; 43 process_t * process = this->process; 43 44 44 45 // check vaddr in user vspace 45 error = vmm_ v2p_translate( false , vaddr , &paddr);46 error = vmm_get_vseg( process , (intptr_t)vaddr , &vseg ); 46 47 if( error ) 47 48 { 48 printk("\n[ERROR] in %s : illegal semaphore virtual address = %x\n", 49 __FUNCTION__ , (intptr_t)vaddr ); 50 this->errno = error; 49 50 #if DEBUG_SYSCALLS_ERROR 51 printk("\n[ERROR] in %s : unmapped semaphore %x / thread %x / process %x\n", 52 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid ); 53 vmm_display( process , false ); 54 #endif 55 this->errno = EINVAL; 51 56 return -1; 52 57 } 53 58 54 59 // check value in user vspace 55 error = vmm_ v2p_translate( false , value , &paddr);60 error = vmm_get_vseg( process , (intptr_t)value , &vseg ); 56 61 if( error ) 57 62 { 58 printk("\n[ERROR] in %s : illegal argument virtual address = %x\n", 59 __FUNCTION__ , (intptr_t)value ); 60 this->errno = error; 61 return -1; 63 64 #if DEBUG_SYSCALLS_ERROR 65 printk("\n[ERROR] in %s : unmapped value %x / thread %x / process %x\n", 66 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid ); 67 vmm_display( process , false ); 68 #endif 69 this->errno = EINVAL; 70 return -1; 62 71 } 63 72 64 73 // execute requested operation 65 74 switch( operation ) … … 91 100 if( sem_xp == XPTR_NULL ) // user error 92 101 { 93 printk("\n[ERROR] in %s : semaphore %x not registered\n", 94 __FUNCTION__ , (intptr_t)value ); 102 103 #if DEBUG_SYSCALLS_ERROR 104 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x / process %x\n", 105 __FUNCTION__ , (intptr_t)value, this->trdid, process->pid ); 106 #endif 95 107 this->errno = EINVAL; 96 108 return -1; … … 114 126 if( sem_xp == XPTR_NULL ) // user error 115 127 { 116 printk("\n[ERROR] in %s : semaphore %x not registered\n", 117 __FUNCTION__ , (intptr_t)value ); 128 129 #if DEBUG_SYSCALLS_ERROR 130 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x / process %x\n", 131 __FUNCTION__ , (intptr_t)value, this->trdid, process->pid ); 132 #endif 118 133 this->errno = EINVAL; 119 134 return -1; … … 134 149 if( sem_xp == XPTR_NULL ) // user error 135 150 { 136 printk("\n[ERROR] in %s : semaphore %x not registered\n", 137 __FUNCTION__ , (intptr_t)value ); 151 152 #if DEBUG_SYSCALLS_ERROR 153 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x / process %x\n", 154 __FUNCTION__ , (intptr_t)value, this->trdid, process->pid ); 155 #endif 138 156 this->errno = EINVAL; 139 157 return -1; … … 154 172 if( sem_xp == XPTR_NULL ) // user error 155 173 { 156 printk("\n[ERROR] in %s : semaphore %x not registered\n", 157 __FUNCTION__ , (intptr_t)value ); 174 175 #if DEBUG_SYSCALLS_ERROR 176 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x / process %x\n", 177 __FUNCTION__ , (intptr_t)value, this->trdid, process->pid ); 178 #endif 158 179 this->errno = EINVAL; 159 180 return -1; -
trunk/kernel/syscalls/sys_stat.c
r407 r440 2 2 * sys_stat.c - Return statistics on a file or directory. 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 37 37 { 38 38 error_t error; 39 paddr_t paddr;39 vseg_t * vseg; // for user space checking 40 40 struct stat k_stat; // kernel space 41 41 xptr_t file_xp; … … 46 46 47 47 // check stat structure in user space 48 error = vmm_ v2p_translate( false , u_stat , &paddr);48 error = vmm_get_vseg( process , (intptr_t)u_stat , &vseg ); 49 49 50 50 if( error ) 51 51 { 52 printk("\n[ERROR] in %s : stat structure unmapped for thread %x in process %x\n", 53 __FUNCTION__ , this->trdid , process->pid ); 52 53 #if DEBUG_SYCALL_ERROR 54 printk("\n[ERROR] in %s : stat structure unmapped %x / thread %x / process %x\n", 55 __FUNCTION__ , (intptr_t)u_stat , this->trdid , process->pid ); 56 vmm_display( process , false ); 57 #endif 54 58 this->errno = EINVAL; 55 59 return -1; -
trunk/kernel/syscalls/sys_thread_cancel.c
r438 r440 23 23 24 24 #include <hal_types.h> 25 #include <hal_irqmask.h> 25 26 #include <hal_remote.h> 26 27 #include <hal_special.h> … … 32 33 int sys_thread_cancel( trdid_t trdid ) 33 34 { 35 reg_t save_sr; // required to enable IRQs 34 36 xptr_t target_xp; // target thread extended pointer 37 cxy_t target_cxy; // target thread cluster identifier 38 ltid_t target_ltid; // target thread local index 39 cxy_t owner_cxy; // process owner cluster identifier 40 xptr_t owner_xp; // extended pointer on owner process 35 41 36 42 // get killer thread pointers 37 43 thread_t * this = CURRENT_THREAD; 38 44 process_t * process = this->process; 45 pid_t pid = process->pid; 39 46 40 47 // get extended pointer on target thread 41 target_xp = thread_get_xptr( p rocess->pid , trdid );48 target_xp = thread_get_xptr( pid , trdid ); 42 49 43 50 // check target_xp … … 61 68 #endif 62 69 63 // cal the relevant kernel function 64 thread_kill( target_xp, 65 0, // is_exit 66 0 ); // is forced 70 // get process owner cluster identifier 71 owner_cxy = CXY_FROM_PID( pid ); 72 73 // get target thread ltid and cluster 74 target_cxy = CXY_FROM_TRDID( trdid ); 75 target_ltid = LTID_FROM_TRDID( trdid ); 76 77 // If target thread is the main thread, the process must be deleted, 78 // This require synchronisation with parent process 79 if( (target_cxy == owner_cxy) && (target_ltid == 0) ) 80 { 81 // get extended pointer on owner cluster 82 owner_xp = cluster_get_owner_process_from_pid( pid ); 83 84 // mark for delete all threads but the main 85 hal_enable_irq( &save_sr ); 86 process_sigaction( pid , DELETE_ALL_THREADS ); 87 hal_restore_irq( save_sr ); 88 89 // remove process from TXT list 90 process_txt_detach( owner_xp ); 91 92 // block the main thread 93 thread_block( XPTR( local_cxy ,this ) , THREAD_BLOCKED_GLOBAL ); 94 95 // atomically update owner process descriptor term_state to ask 96 // the parent process sys_wait() function to delete the main thread 97 hal_remote_atomic_or( XPTR( local_cxy , &process->term_state ) , 98 PROCESS_TERM_EXIT ); 99 } 100 else 101 { 102 // block target thread and mark it for delete 103 thread_delete( target_xp , pid , false ); 104 } 67 105 68 106 #if DEBUG_SYS_THREAD_CANCEL -
trunk/kernel/syscalls/sys_thread_create.c
r438 r440 53 53 trdid_t trdid; // created thread identifier 54 54 process_t * process; // pointer on local process descriptor 55 paddr_t paddr; // unused, required by vmm_v2p_translate()55 vseg_t * vseg; // required for user space checking 56 56 cxy_t target_cxy; // target cluster identifier 57 57 error_t error; … … 67 67 tm_start = hal_get_cycles(); 68 68 if( DEBUG_SYS_THREAD_CREATE < tm_start ) 69 printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n" 70 __FUNCTION__ , parent , process->pid, (uint32_t)tm_start ); 71 #endif 72 73 // check user_attr in user space & copy to kernel space 69 printk("\n[DBG] %s : thread %x (cxy %x) enter / process %x / cycle %d\n", 70 __FUNCTION__, parent, local_cxy, process->pid, (uint32_t)tm_start ); 71 #endif 72 73 // check trdid buffer in user space 74 error = vmm_get_vseg( process , (intptr_t)trdid_ptr , &vseg ); 75 76 if ( error ) 77 { 78 79 #if DEBUG_SYSCALLS_ERROR 80 printk("\n[ERROR] in %s : trdid buffer unmapped %x / thread %x / process %x\n", 81 __FUNCTION__ , (intptr_t)trdid_ptr, parent->trdid, process->pid ); 82 vmm_display( process , false ); 83 #endif 84 parent->errno = EINVAL; 85 return -1; 86 } 87 88 // check user_attr buffer in user space & copy to kernel space 74 89 if( user_attr != NULL ) 75 90 { 76 error = vmm_ v2p_translate( false , user_attr , &paddr);91 error = vmm_get_vseg( process , (intptr_t)user_attr , &vseg ); 77 92 78 93 if( error ) … … 80 95 81 96 #if DEBUG_SYSCALLS_ERROR 82 printk("\n[ERROR] in %s : user_attr unmapped\n", __FUNCTION__ ); 97 printk("\n[ERROR] in %s : user_attr buffer unmapped %x / thread %x / process %x\n", 98 __FUNCTION__ , (intptr_t)user_attr , parent->trdid , process->pid ); 99 vmm_display( process , false ); 83 100 #endif 84 101 parent->errno = EINVAL; … … 90 107 91 108 // check start_func in user space 92 error = vmm_v2p_translate( false , start_func , &paddr ); 93 94 if( error ) 95 { 96 97 #if DEBUG_SYSCALLS_ERROR 98 printk("\n[ERROR] in %s : start_func unmapped\n", __FUNCTION__ ); 99 #endif 100 parent->errno = EINVAL; 101 return -1; 102 } 103 104 // check start_arg in user space 105 if( start_arg != NULL ) error = vmm_v2p_translate( false , start_arg , &paddr ); 106 107 if( error ) 108 { 109 110 #if DEBUG_SYSCALLS_ERROR 111 printk("\n[ERROR] in %s : start_arg unmapped\n", __FUNCTION__ ); 112 #endif 113 parent->errno = EINVAL; 114 return -1; 115 } 116 117 // check / define attributes an target_cxy 109 error = vmm_get_vseg( process , (intptr_t)start_func , &vseg ); 110 111 if( error ) 112 { 113 114 #if DEBUG_SYSCALLS_ERROR 115 printk("\n[ERROR] in %s : start_func unmapped %x / thread %x / process %x\n", 116 __FUNCTION__ , (intptr_t)start_func , parent->trdid , process->pid ); 117 vmm_display( process , false ); 118 #endif 119 parent->errno = EINVAL; 120 return -1; 121 } 122 123 // check start_arg buffer in user space 124 if( start_arg != NULL ) 125 { 126 error = vmm_get_vseg( process , (intptr_t)start_arg , &vseg ); 127 128 if( error ) 129 { 130 131 #if DEBUG_SYSCALLS_ERROR 132 printk("\n[ERROR] in %s : start_arg buffer unmapped %x / thread %x / process %x\n", 133 __FUNCTION__ , (intptr_t)start_arg , parent->trdid , process->pid ); 134 vmm_display( process , false ); 135 #endif 136 parent->errno = EINVAL; 137 return -1; 138 } 139 } 140 141 // define attributes and target_cxy 118 142 if( user_attr != NULL ) // user defined attributes 119 143 { … … 125 149 126 150 #if DEBUG_SYSCALLS_ERROR 127 printk("\n[ERROR] in %s : illegal target cluster = %x\n", __FUNCTION__ , kern_attr.cxy ); 151 printk("\n[ERROR] in %s : illegal target cluster = %x / thread %x / process %x\n", 152 __FUNCTION__ , kern_attr.cxy, parent->trdid, process->pid ); 128 153 #endif 129 154 parent->errno = EINVAL; … … 175 200 176 201 #if DEBUG_SYSCALLS_ERROR 177 printk("\n[ERROR] in %s : cannot create thread\n", __FUNCTION__ ); 178 #endif 179 return ENOMEM; 202 printk("\n[ERROR] in %s : cannot create new thread / thread %x / process %x\n", 203 __FUNCTION__ , parent->trdid, process->pid ); 204 #endif 205 parent->errno = ENOMEM; 206 return -1; 180 207 } 181 208 … … 184 211 hal_copy_to_uspace( trdid_ptr , &trdid , sizeof(pthread_t) ); 185 212 186 // register child in parent if required187 if( user_attr != NULL )188 {189 if( (kern_attr.attributes & PT_ATTR_DETACH) == 0 )190 thread_child_parent_link( parent_xp , child_xp );191 }192 193 213 // activate new thread 194 214 thread_unblock( child_xp , THREAD_BLOCKED_GLOBAL ); … … 199 219 tm_end = hal_get_cycles(); 200 220 if( DEBUG_SYS_THREAD_CREATE < tm_end ) 201 printk("\n[DBG] %s : thread %x created thread %x for process %x in cluster %x / cycle %d\n"202 __FUNCTION__, parent, child_ptr, process->pid, target_cxy, (uint32_t)tm_end );221 printk("\n[DBG] %s : thread %x (cxy %x) created thread %x (cxy %x) / process %x / cycle %d\n", 222 __FUNCTION__, parent, local_cxy, child_ptr, target_cxy, process->pid, (uint32_t)tm_end ); 203 223 #endif 204 224 -
trunk/kernel/syscalls/sys_thread_exit.c
r438 r440 2 2 * sys_thread_exit.c - terminates the execution of calling thread 3 3 * 4 * Authors Alain Greiner (2016,2017 )4 * Authors Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 23 23 24 24 #include <hal_types.h> 25 #include <hal_irqmask.h> 25 26 #include <thread.h> 27 #include <process.h> 26 28 #include <core.h> 27 29 #include <vmm.h> … … 32 34 int sys_thread_exit( void * exit_value ) 33 35 { 34 thread_t * this = CURRENT_THREAD; 35 process_t * process = this->process; 36 reg_t save_sr; // required to enable IRQs 37 xptr_t owner_xp; // extended pointer on owner process 38 39 thread_t * this = CURRENT_THREAD; 40 trdid_t trdid = this->trdid; 41 process_t * process = this->process; 42 pid_t pid = process->pid; 43 cxy_t owner_cxy = CXY_FROM_PID( pid ); 36 44 37 45 // check exit_value argument … … 40 48 41 49 #if DEBUG_SYSCALLS_ERROR 42 printk("\n[ERROR] in %s : exit_value argument must be NULL forthread %x in process %x\n",43 __FUNCTION__ , exit_value, this->trdid , process->pid );50 printk("\n[ERROR] in %s : exit_value argument must be NULL / thread %x in process %x\n", 51 __FUNCTION__ , this , pid ); 44 52 #endif 45 53 this->errno = EINVAL; … … 53 61 if( DEBUG_SYS_THREAD_EXIT < tm_start ) 54 62 printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n", 55 __FUNCTION__ , this, p rocess->pid , (uint32_t)tm_start );63 __FUNCTION__ , this, pid , (uint32_t)tm_start ); 56 64 #endif 57 65 58 // cal the relevant kernel function 59 thread_kill( XPTR( local_cxy , this ), 60 1, // is_exit 61 0 ); // is forced 66 // If calling thread is the main thread, the process must be deleted. 67 // This require to delete all process threads and synchronise with parent process 68 if( (local_cxy == owner_cxy) && (LTID_FROM_TRDID(trdid) == 0) ) 69 { 70 // get extended pointer on owner cluster 71 owner_xp = cluster_get_owner_process_from_pid( pid ); 72 73 // mark for delete all threads but the main 74 hal_enable_irq( &save_sr ); 75 process_sigaction( pid , DELETE_ALL_THREADS ); 76 hal_restore_irq( save_sr ); 77 78 // remove process from TXT list 79 process_txt_detach( owner_xp ); 80 81 // block the main thread 82 thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_GLOBAL ); 83 84 // atomically update owner process descriptor term_state to ask 85 // the parent process sys_wait() function to delete the main thread 86 hal_remote_atomic_or( XPTR( local_cxy , &process->term_state ) , 87 PROCESS_TERM_EXIT ); 88 } 89 else 90 { 91 // block calling thread and mark it for delete, 92 thread_delete( XPTR( local_cxy , this ) , pid , false ); 93 } 62 94 63 95 #if DEBUG_SYS_THREAD_EXIT … … 65 97 if( DEBUG_SYS_THREAD_EXIT < tm_end ) 66 98 printk("\n[DBG] %s : thread %x exit / process %x / cost %d / cycle %d\n", 67 __FUNCTION__, this, this->process->pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );99 __FUNCTION__, this, pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 68 100 #endif 69 101 70 // deschedule <=> suicide, because blocked by thread_ kill()102 // deschedule <=> suicide, because blocked by thread_delete() 71 103 sched_yield( "suicide after thread_exit" ); 72 104 -
trunk/kernel/syscalls/sys_timeofday.c
r407 r440 2 2 * sys_timeofday.c - Get current time 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 37 37 { 38 38 error_t error; 39 paddr_t paddr;39 vseg_t * vseg; 40 40 41 41 uint32_t tm_s; … … 50 50 if( tz ) 51 51 { 52 printk("\n[ERROR] in %s for thread %x in process %x : tz argument must be NULL\n", 53 __FUNCTION__ , this->trdid , process->pid ); 52 53 #if DEBUG_SYSCALLS_ERROR 54 printk("\n[ERROR] in %s for thread %x in process %x : tz argument must be NULL\n", 55 __FUNCTION__ , this->trdid , process->pid ); 56 #endif 54 57 this->errno = EINVAL; 55 58 return -1; … … 57 60 58 61 // check tv 59 error = vmm_ v2p_translate( false , tv , &paddr);62 error = vmm_get_vseg( process , (intptr_t)tv , &vseg ); 60 63 61 64 if( error ) 62 65 { 63 printk("\n[ERROR] in %s for thread %x in process %x : tv argument unmapped\n", 64 __FUNCTION__ , this->trdid , process->pid ); 66 67 #if DEBUG_SYSCALLS_ERROR 68 printk("\n[ERROR] in %s : user buffer tz unmapped / thread %x / process %x\n", 69 __FUNCTION__ , (intptr_t)tz , this->trdid , process->pid ); 70 vmm_display( process , false ); 71 #endif 65 72 this->errno = EINVAL; 66 73 return -1; -
trunk/kernel/syscalls/sys_wait.c
r438 r440 2 2 * sys_wait.c - wait termination or blocking of a child process. 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 35 35 { 36 36 error_t error; 37 paddr_t paddr;37 vseg_t * vseg; 38 38 xptr_t iter_xp; 39 39 xptr_t child_xp; … … 59 59 60 60 // check status in user space 61 error = vmm_ v2p_translate( false , status , &paddr);61 error = vmm_get_vseg( process, (intptr_t)status , &vseg ); 62 62 63 63 if( error ) … … 65 65 66 66 #if DEBUG_SYSCALLS_ERROR 67 printk("\n[ERROR] in %s : status buffer unmapped for thread %x in process %x\n", 68 __FUNCTION__ , this->trdid , process->pid ); 67 printk("\n[ERROR] in %s : status buffer %x unmapped for thread %x in process %x\n", 68 __FUNCTION__ , (intptr_t)status, this->trdid , process->pid ); 69 vmm_display( process , false ); 69 70 #endif 70 71 this->errno = EINVAL; -
trunk/kernel/syscalls/sys_write.c
r438 r440 2 2 * sys_write.c - write bytes to a file 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 35 35 /* TODO: concurrent user page(s) unmap need to be handled [AG] */ 36 36 37 extern uint32_t enter_sys_write; 38 extern uint32_t enter_devfs_write; 39 extern uint32_t enter_txt_write; 40 extern uint32_t enter_chdev_cmd_write; 41 extern uint32_t enter_chdev_server_write; 42 extern uint32_t enter_tty_cmd_write; 43 extern uint32_t enter_tty_isr_write; 44 extern uint32_t exit_tty_isr_write; 45 extern uint32_t exit_tty_cmd_write; 46 extern uint32_t exit_chdev_server_write; 47 extern uint32_t exit_chdev_cmd_write; 48 extern uint32_t exit_txt_write; 49 extern uint32_t exit_devfs_write; 50 extern uint32_t exit_sys_write; 51 37 52 ////////////////////////////////// 38 53 int sys_write( uint32_t file_id, … … 41 56 { 42 57 error_t error; 43 paddr_t paddr;// required for user space checking58 vseg_t * vseg; // required for user space checking 44 59 xptr_t file_xp; // remote file extended pointer 45 60 uint32_t nbytes; // number of bytes actually written 46 61 reg_t save_sr; // required to enable IRQs during syscall 47 62 48 #if (DEBUG_SYS_WRITE _DEBUG& 1)49 enter_sys_ read= (uint32_t)tm_start;63 #if (DEBUG_SYS_WRITE & 1) 64 enter_sys_write = (uint32_t)tm_start; 50 65 #endif 51 66 … … 74 89 75 90 // check user buffer in user space 76 error = vmm_ v2p_translate( false , vaddr , &paddr);91 error = vmm_get_vseg( process , (intptr_t)vaddr , &vseg ); 77 92 78 93 if ( error ) … … 80 95 81 96 #if DEBUG_SYSCALLS_ERROR 82 printk("\n[ERROR] in %s : user buffer unmapped = %x\n", __FUNCTION__ , (intptr_t)vaddr ); 97 printk("\n[ERROR] in %s : user buffer unmapped %x / thread %x / process %x\n", 98 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid ); 99 vmm_display( process , false ); 83 100 #endif 84 101 this->errno = EINVAL; -
trunk/kernel/syscalls/syscalls.h
r437 r440 169 169 /****************************************************************************************** 170 170 * [10] This function implement the exit system call terminating a POSIX process. 171 * It can be called by any thread running in any cluster. 172 * It uses both remote accesses to access the owner process descriptor, ans the 173 * RPC_PROCESS_SIGACTION to delete remote process and thread descriptors 171 174 * In the present implementation, this function implements actually the _exit(): 172 * - it does not flush open ou rput steams.175 * - it does not flush open output streams. 173 176 * - it does not close open streams. 174 177 ****************************************************************************************** … … 619 622 int sys_fg( pid_t pid ); 620 623 624 int sys_place( uint32_t cxy, 625 uint32_t lid ); 621 626 622 627 #endif // _SYSCALLS_H_
Note: See TracChangeset
for help on using the changeset viewer.