Changeset 457 for trunk/kernel/syscalls
- Timestamp:
- Aug 2, 2018, 11:47:13 AM (6 years ago)
- Location:
- trunk/kernel/syscalls
- Files:
-
- 50 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/shared_include/shared_pthread.h
r445 r457 29 29 ******************************************************************************************/ 30 30 31 typedef unsigned int sem_t;32 31 typedef unsigned int pthread_cond_t; 33 32 typedef unsigned int pthread_condattr_t; … … 56 55 PT_ATTR_CORE_DEFINED = 0x0004, /*! user defined core index in cluster */ 57 56 }; 58 59 /*******************************************************************************************60 * This enum defines the operation mnemonics for operations on POSIX unnamed semaphores.61 ******************************************************************************************/62 63 typedef enum64 {65 SEM_INIT,66 SEM_DESTROY,67 SEM_GETVALUE,68 SEM_WAIT,69 SEM_POST,70 }71 sem_operation_t;72 57 73 58 /******************************************************************************************* -
trunk/kernel/syscalls/shared_include/syscalls_numbers.h
r444 r457 62 62 SYS_TRACE = 47, 63 63 SYS_FG = 48, 64 SYS_ UNDEFINED_49 = 49, ///64 SYS_IS_FG = 49, 65 65 66 66 SYSCALLS_NR = 50, -
trunk/kernel/syscalls/sys_alarm.c
r23 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <thread.h> 26 26 #include <printk.h> -
trunk/kernel/syscalls/sys_barrier.c
r440 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_special.h> 26 26 #include <errno.h> -
trunk/kernel/syscalls/sys_chdir.c
r407 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_uspace.h> 26 26 #include <chdev.h> -
trunk/kernel/syscalls/sys_chmod.c
r407 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_uspace.h> 26 26 #include <vfs.h> -
trunk/kernel/syscalls/sys_close.c
r124 r457 23 23 24 24 #include <kernel_config.h> 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <hal_special.h> 27 27 #include <vfs.h> -
trunk/kernel/syscalls/sys_closedir.c
r407 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <vfs.h> 26 26 #include <printk.h> -
trunk/kernel/syscalls/sys_condvar.c
r440 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_special.h> 26 26 #include <errno.h> -
trunk/kernel/syscalls/sys_creat.c
r407 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <vfs.h> 26 26 #include <syscalls.h> -
trunk/kernel/syscalls/sys_display.c
r450 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_uspace.h> 26 26 #include <errno.h> -
trunk/kernel/syscalls/sys_exec.c
r441 r457 23 23 24 24 #include <kernel_config.h> 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <hal_uspace.h> 27 27 #include <errno.h> … … 152 152 // It build an exec_info_t structure containing all informations 153 153 // required to initialize the new process descriptor and the associated thread. 154 // It includes the process main() arguments, the environment variables,154 // It includes the new process main() arguments, the environment variables, 155 155 // and the pathname to the new process .elf file. 156 156 // It calls the process_exec_get_strings() functions to copy the main() arguments and 157 157 // the environment variables from user buffers to the exec_info_t structure, allocate 158 158 // and call the process_make_exec() function. 159 // As it must destroy all parent process copies, and all parent threads in all clusters, 160 // the process_make_exec() function must be executed in the parent owner cluster, 161 // and this sys_exec() function uses a RPC to access the owner cluster if required. 159 // As it must destroy all process copies, and all othert threads in all clusters, 160 // the process_make_exec() function must be executed in the owner cluster. 162 161 // 163 162 // TODO : the args & envs arguments are not supported yet : both must be NULL [AG] … … 187 186 "args not supported yet\n" ); 188 187 189 // get owner cluster190 191 188 // check pathname length 192 189 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) … … 205 202 #if DEBUG_SYS_EXEC 206 203 uint64_t tm_start; 207 uint64_t tm_end;208 204 tm_start = hal_get_cycles(); 209 205 if( DEBUG_SYS_EXEC < tm_start ) 210 206 printk("\n[DBG] %s : thread %x in process %x enter for path <%s> / cycle = %d\n", 211 __FUNCTION__, this , pid, exec_info.path, (uint32_t)tm_start );207 __FUNCTION__, this->trdid, pid, exec_info.path, (uint32_t)tm_start ); 212 208 #endif 213 209 … … 220 216 #if DEBUG_SYSCALLS_ERROR 221 217 printk("\n[ERROR] in %s : thread %x in process %x cannot access args\n", 222 __FUNCTION__ , this , pid );218 __FUNCTION__ , this->trdid, pid ); 223 219 #endif 224 220 this->errno = EINVAL; … … 235 231 #if DEBUG_SYCALLS_ERROR 236 232 printk("\n[ERROR] in %s : thread %x in process %x cannot access envs\n", 237 __FUNCTION__ , this , pid );233 __FUNCTION__ , this->trdid, pid ); 238 234 #endif 239 235 this->errno = EINVAL; … … 250 246 #if DEBUG_SYSCALLS_ERROR 251 247 printk("\n[ERROR] in %s : thread %x in process %x cannot create process for <%s>\n", 252 __FUNCTION__, this , pid, exec_info.path );248 __FUNCTION__, this->trdid, pid, exec_info.path ); 253 249 #endif 254 250 this->errno = error; … … 256 252 } 257 253 258 #if DEBUG_SYS_EXEC 259 tm_end = hal_get_cycles(); 260 if( DEBUG_SYS_EXEC < tm_end ) 261 printk("\n[DBG] %s : thread %x in process %x exit / cost = %d / cycle %d\n", 262 __FUNCTION__, this, pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 263 #endif 264 265 // In case of success, this calling thread deschedules, causing suicide, 266 // because a new process descriptor and its associated main thread 267 // have been created by the process_make_exec() function, and the 268 // BLOCKED_GLOBAL & FLAG_REQ_DELETE bits have been set for the calling thread. 269 sched_yield( "old process suicide in sys_exec()" ); 254 assert( false , __FUNCTION__, "we should not execute this code" ); 270 255 271 256 return 0; -
trunk/kernel/syscalls/sys_exit.c
r446 r457 23 23 24 24 #include <kernel_config.h> 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <hal_irqmask.h> 27 27 #include <errno.h> … … 59 59 tm_start = hal_get_cycles(); 60 60 if( DEBUG_SYS_EXIT < tm_start ) 61 printk("\n[DBG] %s : thread %x enter / process %x/ status %x / cycle %d\n",62 __FUNCTION__ , this,pid , status , (uint32_t)tm_start );61 printk("\n[DBG] %s : thread %x in process %x enter / status %x / cycle %d\n", 62 __FUNCTION__, this->trdid, process->pid , status , (uint32_t)tm_start ); 63 63 #endif 64 64 … … 70 70 #if (DEBUG_SYS_EXIT & 1) 71 71 if( DEBUG_SYS_EXIT < tm_start ) 72 printk("\n[DBG] %s : thread %x get owner process %x in cluster %x\n",73 __FUNCTION__ , this, owner_ptr, owner_cxy );72 printk("\n[DBG] %s : thread %x in process %x get owner process %x in cluster %x\n", 73 __FUNCTION__, this->trdid, process->pid, owner_ptr, owner_cxy ); 74 74 #endif 75 75 76 // get pointer on the process main thread76 // get local pointer on the process main thread 77 77 main_ptr = hal_remote_lpt( XPTR( owner_cxy , &owner_ptr->th_tbl[0] ) ); 78 78 … … 84 84 #if (DEBUG_SYS_EXIT & 1) 85 85 if( DEBUG_SYS_EXIT < tm_start ) 86 printk("\n[DBG] %s : thread %x get parent process %x in cluster %x\n",87 __FUNCTION__ , this, parent_ptr, parent_cxy );86 printk("\n[DBG] %s : thread %x in process %x get parent process %x in cluster %x\n", 87 __FUNCTION__, this->trdid, process->pid, parent_ptr, parent_cxy ); 88 88 #endif 89 89 … … 99 99 100 100 #if( DEBUG_SYS_EXIT & 1) 101 if( tm_start > DEBUG_SYS_EXIT)102 printk("\n[DBG] %s : thread %x removed process %x from TXT list\n",103 __FUNCTION__ , this,pid );101 if( DEBUG_SYS_EXIT < tm_start ) 102 printk("\n[DBG] %s : thread %x in process %x detached process from TXT\n", 103 __FUNCTION__, this->trdid, process->pid ); 104 104 #endif 105 105 … … 107 107 // but the main thread and this calling thread 108 108 hal_enable_irq( &save_sr ); 109 process_sigaction( p id , DELETE_ALL_THREADS );109 process_sigaction( process->pid , DELETE_ALL_THREADS ); 110 110 hal_restore_irq( save_sr ); 111 111 112 112 #if( DEBUG_SYS_EXIT & 1) 113 if( tm_start > DEBUG_SYS_EXIT)114 printk("\n[DBG] %s : thread %x deleted threads for process %x\n",115 __FUNCTION__ , this,pid );113 if( DEBUG_SYS_EXIT < tm_start ) 114 printk("\n[DBG] %s : thread %x in process %x deleted all threads but itself\n", 115 __FUNCTION__, this->trdid, process->pid ); 116 116 #endif 117 117 … … 122 122 #if( DEBUG_SYS_EXIT & 1) 123 123 if( tm_start > DEBUG_SYS_EXIT ) 124 printk("\n[DBG] %s : calling thread %x marked iself for delete in process %x\n",125 __FUNCTION__ , this,pid );124 printk("\n[DBG] %s : thread %x in process %x marked iself for delete\n", 125 __FUNCTION__, this->trdid, process->pid ); 126 126 #endif 127 127 thread_delete( XPTR( local_cxy , this ) , pid , true ); … … 133 133 #if( DEBUG_SYS_EXIT & 1) 134 134 if( tm_start > DEBUG_SYS_EXIT ) 135 printk("\n[DBG] %s : thread %x blocked main thread for process %x\n",136 __FUNCTION__, this ,pid );135 printk("\n[DBG] %s : thread %x in process %x blocked main thread\n", 136 __FUNCTION__, this->trdid, process->pid ); 137 137 #endif 138 138 … … 144 144 #if( DEBUG_SYS_EXIT & 1) 145 145 if( tm_start > DEBUG_SYS_EXIT ) 146 printk("\n[DBG] %s : thread %x set exit status in process %x / term_state %x\n",147 __FUNCTION__ , this,pid, term_state );146 printk("\n[DBG] %s : thread %x in process %x set exit status %x in owner process\n", 147 __FUNCTION__, this->trdid, process->pid, term_state ); 148 148 #endif 149 149 150 // take the children lock andunblock the parent process main thread150 // unblock the parent process main thread 151 151 remote_spinlock_lock( children_lock_xp ); 152 152 thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); … … 155 155 #if( DEBUG_SYS_EXIT & 1) 156 156 if( tm_start > DEBUG_SYS_EXIT ) 157 printk("\n[DBG] %s : thread %x in cluster %x unblock parent main thread %x in cluster %x\n", 158 __FUNCTION__ , this, local_cxy, parent_main_ptr, parent_cxy ); 157 printk("\n[DBG] %s : thread %x in process %x unblock parent main thread in process %x\n", 158 __FUNCTION__ , this->trdid, process->pid, 159 hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid) ) ); 159 160 #endif 160 161 … … 164 165 tm_end = hal_get_cycles(); 165 166 if( DEBUG_SYS_EXIT < tm_end ) 166 printk("\n[DBG] %s : thread %x exit / process %x / status %x / cost = %d / cycle %d\n", 167 __FUNCTION__, this, pid, status, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 167 printk("\n[DBG] %s : thread %x in process %x exit / status %x / cost = %d / cycle %d\n", 168 __FUNCTION__, this->trdid, process->pid, status, 169 (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 168 170 #endif 169 171 -
trunk/kernel/syscalls/sys_fg.c
r446 r457 23 23 24 24 #include <kernel_config.h> 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <hal_irqmask.h> 27 27 #include <errno.h> -
trunk/kernel/syscalls/sys_fork.c
r440 r457 23 23 24 24 #include <kernel_config.h> 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <hal_context.h> 27 27 #include <hal_switch.h> … … 70 70 tm_start = hal_get_cycles(); 71 71 if( DEBUG_SYS_FORK < tm_start ) 72 printk("\n[DBG] %s : parent_thread %x enter / parent_pid %x/ cycle = %d\n",73 __FUNCTION__, parent_thread_ptr , parent_pid, (uint32_t)tm_start );72 printk("\n[DBG] %s : thread %x in process %x enter / cycle = %d\n", 73 __FUNCTION__, parent_thread_ptr->trdid, parent_pid, (uint32_t)tm_start ); 74 74 #endif 75 75 … … 106 106 #if (DEBUG_SYS_FORK & 1 ) 107 107 if( DEBUG_SYS_FORK < tm_start ) 108 printk("\n[DBG] %s : parent_thread%x selected cluster %x\n",109 __FUNCTION__, parent_thread_ptr , child_cxy );108 printk("\n[DBG] %s : thread %x in process %x selected cluster %x\n", 109 __FUNCTION__, parent_thread_ptr->trdid, parent_pid, child_cxy ); 110 110 #endif 111 111 … … 165 165 tm_end = hal_get_cycles(); 166 166 if( DEBUG_SYS_FORK < tm_end ) 167 printk("\n[DBG] %s : p arent_thread %x on cluster%x exit / cost = %d / cycle %d\n",168 __FUNCTION__, parent_ thread_ptr, parent_cxy, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );167 printk("\n[DBG] %s : process %x exit / cost = %d / cycle %d\n", 168 __FUNCTION__, parent_pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 169 169 #endif 170 171 170 return child_pid; 172 171 } … … 177 176 tm_end = hal_get_cycles(); 178 177 if( DEBUG_SYS_FORK < tm_end ) 179 printk("\n[DBG] %s : child_thread %x on cluster%x exit / cost = %d / cycle %d\n",180 __FUNCTION__, child_ thread_ptr, child_cxy, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );178 printk("\n[DBG] %s : process %x exit / cost = %d / cycle %d\n", 179 __FUNCTION__, child_pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 181 180 #endif 182 183 181 return 0; 184 182 } -
trunk/kernel/syscalls/sys_get_config.c
r440 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_uspace.h> 26 26 #include <hal_special.h> -
trunk/kernel/syscalls/sys_get_core.c
r440 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_uspace.h> 26 26 #include <hal_special.h> -
trunk/kernel/syscalls/sys_get_cycle.c
r440 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_uspace.h> 26 26 #include <hal_special.h> -
trunk/kernel/syscalls/sys_getcwd.c
r440 r457 23 23 24 24 #include <kernel_config.h> 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <hal_uspace.h> 27 27 #include <hal_special.h> -
trunk/kernel/syscalls/sys_isatty.c
r438 r457 23 23 24 24 #include <kernel_config.h> 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <hal_uspace.h> 27 27 #include <hal_irqmask.h> -
trunk/kernel/syscalls/sys_kill.c
r448 r457 23 23 24 24 #include <kernel_config.h> 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <hal_irqmask.h> 27 27 #include <errno.h> -
trunk/kernel/syscalls/sys_lseek.c
r23 r457 22 22 23 23 #include <kernel_config.h> 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_uspace.h> 26 26 #include <errno.h> -
trunk/kernel/syscalls/sys_mkdir.c
r407 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_uspace.h> 26 26 #include <vfs.h> -
trunk/kernel/syscalls/sys_mkfifo.c
r407 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_uspace.h> 26 26 #include <printk.h> -
trunk/kernel/syscalls/sys_mmap.c
r440 r457 23 23 */ 24 24 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <hal_uspace.h> 27 27 #include <hal_irqmask.h> -
trunk/kernel/syscalls/sys_munmap.c
r438 r457 23 23 */ 24 24 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <hal_uspace.h> 27 27 #include <shared_syscalls.h> -
trunk/kernel/syscalls/sys_mutex.c
r440 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_special.h> 26 26 #include <errno.h> -
trunk/kernel/syscalls/sys_open.c
r407 r457 23 23 24 24 #include <kernel_config.h> 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <hal_uspace.h> 27 27 #include <errno.h> -
trunk/kernel/syscalls/sys_opendir.c
r407 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <thread.h> 26 26 #include <process.h> -
trunk/kernel/syscalls/sys_pipe.c
r407 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <vfs.h> 26 26 #include <process.h> -
trunk/kernel/syscalls/sys_read.c
r450 r457 23 23 24 24 #include <kernel_config.h> 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <hal_uspace.h> 27 27 #include <hal_irqmask.h> -
trunk/kernel/syscalls/sys_readdir.c
r407 r457 23 23 24 24 #include <kernel_config.h> 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <hal_uspace.h> 27 27 #include <errno.h> -
trunk/kernel/syscalls/sys_rmdir.c
r407 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_uspace.h> 26 26 #include <printk.h> -
trunk/kernel/syscalls/sys_sem.c
r440 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_uspace.h> 26 #include <shared_semaphore.h> 26 27 #include <errno.h> 27 28 #include <thread.h> … … 31 32 #include <syscalls.h> 32 33 34 #if DEBUG_SYS_SEM 35 ////////////////////////////////////////////////// 36 static char * sys_sem_op_str( uint32_t operation ) 37 { 38 if ( operation == SEM_INIT ) return "INIT"; 39 else if( operation == SEM_WAIT ) return "WAIT"; 40 else if( operation == SEM_POST ) return "POST"; 41 else if( operation == SEM_GETVALUE ) return "GETVALUE"; 42 else if( operation == SEM_DESTROY ) return "DESTROY"; 43 else return "undefined"; 44 } 45 #endif 46 33 47 ////////////////////////////////// 34 int sys_sem( void * vaddr, // semaphore virtual address 35 uint32_t operation, // requested operation type 36 uint32_t * value ) // pointer on in/out argument 48 int sys_sem( void * vaddr, // semaphore virtual address 49 uint32_t operation, // requested operation type 50 uint32_t init_value, // initial value 51 uint32_t * current_value ) // pointer on current value buffer 37 52 { 38 uint32_t data;39 53 vseg_t * vseg; 40 54 error_t error; 55 uint32_t current; // semaphore current value 56 xptr_t sem_xp; // extended pointer on semaphore 41 57 42 58 thread_t * this = CURRENT_THREAD; 43 59 process_t * process = this->process; 60 61 #if DEBUG_SYS_SEM 62 uint64_t tm_start; 63 uint64_t tm_end; 64 tm_start = hal_get_cycles(); 65 if( DEBUG_SYS_SEM < tm_start ) 66 printk("\n[DBG] %s : thread %x in process %x enter for %s / cycle %d\n", 67 __FUNCTION__, this->trdid, process->pid, sys_sem_op_str( operation ), (uint32_t)tm_start ); 68 #endif 44 69 45 70 // check vaddr in user vspace … … 49 74 50 75 #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; 56 return -1; 57 } 58 59 // check value in user vspace 60 error = vmm_get_vseg( process , (intptr_t)value , &vseg ); 61 if( error ) 62 { 63 64 #if DEBUG_SYSCALLS_ERROR 65 printk("\n[ERROR] in %s : unmapped value %x / thread %x / process %x\n", 76 printk("\n[ERROR] in %s : unmapped semaphore pointer %x / thread %x in process %x\n", 66 77 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid ); 67 78 vmm_display( process , false ); … … 77 88 case SEM_INIT: 78 89 { 79 // get argument 80 hal_copy_from_uspace( &data , value , sizeof(uint32_t) ); 81 82 // call init function 83 error = remote_sem_create( (intptr_t)vaddr , data ); 90 // call relevant kernel function to initialize semaphore 91 error = remote_sem_create( (intptr_t)vaddr , 92 init_value, 93 XPTR( local_cxy , &sem_xp ) ); 84 94 85 95 if ( error ) 86 96 { 87 printk("\n[ERROR] in %s : cannot create semaphore = %x\n", 88 __FUNCTION__ , (intptr_t)value ); 89 this->errno = error; 90 return -1; 91 } 97 98 #if DEBUG_SYSCALLS_ERROR 99 printk("\n[ERROR] in %s : cannot create semaphore / thread %x in process %x\n", 100 __FUNCTION__, this->trdid, process->pid ); 101 #endif 102 this->errno = ENOMEM; 103 return -1; 104 } 105 92 106 break; 93 107 } … … 95 109 case SEM_GETVALUE: 96 110 { 97 // get extended pointer on remote semaphore 98 xptr_t sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr ); 99 100 if( sem_xp == XPTR_NULL ) // user error 101 { 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 107 this->errno = EINVAL; 108 return -1; 109 } 110 else // success 111 { 112 // get semaphore current value 113 remote_sem_get_value( sem_xp , &data ); 111 // check current_value buffer in user vspace 112 error = vmm_get_vseg( process , (intptr_t)current_value , &vseg ); 113 if( error ) 114 { 115 116 #if DEBUG_SYSCALLS_ERROR 117 printk("\n[ERROR] in %s : unmapped buffer for current value %x / thread %x in process %x\n", 118 __FUNCTION__ , (intptr_t)current_value, this->trdid, process->pid ); 119 vmm_display( process , false ); 120 #endif 121 this->errno = EINVAL; 122 return -1; 123 } 124 125 // get extended pointer on remote semaphore 126 sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr ); 127 128 // check semaphore registered 129 if( sem_xp == XPTR_NULL ) 130 { 131 132 #if DEBUG_SYSCALLS_ERROR 133 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x in process %x\n", 134 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid ); 135 #endif 136 this->errno = EINVAL; 137 return -1; 138 } 139 140 // call relevant kernel function to get semaphore current value 141 remote_sem_get_value( sem_xp , ¤t ); 114 142 115 116 hal_copy_to_uspace( value , &data, sizeof(uint32_t) );117 } 143 // return value to user 144 hal_copy_to_uspace( current_value , ¤t , sizeof(uint32_t) ); 145 118 146 break; 119 147 } … … 122 150 { 123 151 // get extended pointer on remote semaphore 124 xptr_tsem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );125 126 if( sem_xp == XPTR_NULL ) // user error127 {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 133 this->errno = EINVAL; 134 return -1;135 }136 else // success137 { 138 //wait semaphore available139 140 }152 sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr ); 153 154 // check semaphore registered 155 if( sem_xp == XPTR_NULL ) 156 { 157 158 #if DEBUG_SYSCALLS_ERROR 159 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x in process %x\n", 160 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid ); 161 #endif 162 this->errno = EINVAL; 163 return -1; 164 } 165 166 // call relevant kernel function to wait semaphore available 167 remote_sem_wait( sem_xp ); 168 141 169 break; 142 170 } … … 145 173 { 146 174 // get extended pointer on remote semaphore 147 xptr_tsem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );148 149 if( sem_xp == XPTR_NULL ) // user error150 {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 156 this->errno = EINVAL; 157 return -1;158 }159 else // success160 { 161 //release semaphore162 163 } 175 sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr ); 176 177 // check semaphore registered 178 if( sem_xp == XPTR_NULL ) 179 { 180 181 #if DEBUG_SYSCALLS_ERROR 182 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x in process %x\n", 183 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid ); 184 #endif 185 this->errno = EINVAL; 186 return -1; 187 } 188 189 // call relevant kernel function to release semaphore 190 remote_sem_post( sem_xp ); 191 164 192 break; 165 193 } … … 168 196 { 169 197 // get extended pointer on remote semaphore 170 xptr_tsem_xp = remote_sem_from_vaddr( (intptr_t)vaddr );171 172 if( sem_xp == XPTR_NULL ) // user error173 {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 179 this->errno = EINVAL; 180 return -1;181 }182 else // success183 { 184 185 186 } 198 sem_xp = remote_sem_from_vaddr( (intptr_t)vaddr ); 199 200 // check semaphore registered 201 if( sem_xp == XPTR_NULL ) 202 { 203 204 #if DEBUG_SYSCALLS_ERROR 205 printk("\n[ERROR] in %s : semaphore %x not registered / thread %x in process %x\n", 206 __FUNCTION__ , (intptr_t)vaddr, this->trdid, process->pid ); 207 #endif 208 this->errno = EINVAL; 209 return -1; 210 } 211 212 // destroy semaphore 213 remote_sem_destroy( sem_xp ); 214 187 215 break; 188 216 } … … 190 218 default: // undefined operation 191 219 { 192 printk("\n[PANIC] in %s : illegal operation type\n", __FUNCTION__ ); 193 hal_core_sleep(); 220 221 #if DEBUG_SYSCALLS_ERROR 222 printk("\n[ERROR] in %s : undefined operation type %d / thread %x in process %x\n", 223 __FUNCTION__ , operation, this->trdid, process->pid ); 224 #endif 225 this->errno = EINVAL; 226 return -1; 194 227 } 195 228 } 196 229 230 hal_fence(); 231 232 #if DEBUG_SYS_SEM 233 tm_end = hal_get_cycles(); 234 if( DEBUG_SYS_SEM < tm_end ) 235 { 236 cxy_t sem_cxy = GET_CXY( sem_xp ); 237 remote_sem_t * sem_ptr = GET_PTR( sem_xp ); 238 uint32_t value = hal_remote_lw( XPTR( sem_cxy , &sem_ptr->count ) ); 239 printk("\n[DBG] %s : thread %x in process %x exit for %s / value %d / cost = %d / cycle %d\n", 240 __FUNCTION__, this->trdid, process->pid, sys_sem_op_str( operation ), value, 241 (uint32_t)(tm_end - tm_start), (uint32_t)tm_end ); 242 } 243 #endif 244 197 245 return 0; 198 246 -
trunk/kernel/syscalls/sys_signal.c
r435 r457 23 23 */ 24 24 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <errno.h> 27 27 #include <thread.h> -
trunk/kernel/syscalls/sys_stat.c
r440 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_uspace.h> 26 26 #include <hal_special.h> -
trunk/kernel/syscalls/sys_thread_cancel.c
r443 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_irqmask.h> 26 26 #include <hal_remote.h> -
trunk/kernel/syscalls/sys_thread_create.c
r440 r457 23 23 24 24 #include <kernel_config.h> 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <hal_uspace.h> 27 27 #include <printk.h> -
trunk/kernel/syscalls/sys_thread_detach.c
r23 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_remote.h> 26 26 #include <hal_special.h> -
trunk/kernel/syscalls/sys_thread_exit.c
r440 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_irqmask.h> 26 26 #include <thread.h> -
trunk/kernel/syscalls/sys_thread_join.c
r438 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_remote.h> 26 26 #include <hal_special.h> -
trunk/kernel/syscalls/sys_thread_wakeup.c
r438 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <thread.h> 26 26 #include <printk.h> -
trunk/kernel/syscalls/sys_thread_yield.c
r445 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_special.h> 26 26 #include <scheduler.h> -
trunk/kernel/syscalls/sys_timeofday.c
r440 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_uspace.h> 26 26 #include <thread.h> -
trunk/kernel/syscalls/sys_trace.c
r443 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_special.h> 26 26 #include <printk.h> -
trunk/kernel/syscalls/sys_unlink.c
r407 r457 21 21 */ 22 22 23 #include <hal_ types.h>23 #include <hal_kernel_types.h> 24 24 #include <hal_uspace.h> 25 25 #include <vfs.h> -
trunk/kernel/syscalls/sys_utls.c
r23 r457 23 23 */ 24 24 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <errno.h> 27 27 #include <thread.h> -
trunk/kernel/syscalls/sys_wait.c
r446 r457 22 22 */ 23 23 24 #include <hal_ types.h>24 #include <hal_kernel_types.h> 25 25 #include <hal_uspace.h> 26 26 #include <hal_irqmask.h> -
trunk/kernel/syscalls/sys_write.c
r443 r457 23 23 24 24 #include <kernel_config.h> 25 #include <hal_ types.h>25 #include <hal_kernel_types.h> 26 26 #include <hal_uspace.h> 27 27 #include <hal_irqmask.h> -
trunk/kernel/syscalls/syscalls.h
r445 r457 2 2 * syscalls.h - Kernel side services for syscall handling. 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 25 25 #define _SYSCALLS_H_ 26 26 27 #include <hal_ types.h>27 #include <hal_kernel_types.h> 28 28 #include <shared_syscalls.h> 29 29 … … 116 116 * and the code implementing the operations is in the remore_sem.c file. 117 117 ****************************************************************************************** 118 * @ vaddr : semaphore virtual address in user space == identifier. 119 * @ operation : SEM_INIT / SEM_DESTROY / SEM_GETVALUE / SEM_POST / SEM_WAIT. 120 * @ value : pointer on in/out argument in user space. 118 * @ vaddr : semaphore virtual address in user space == identifier. 119 * @ operation : SEM_INIT / SEM_DESTROY / SEM_GETVALUE / SEM_POST / SEM_WAIT. 120 * @ init_value : initial semaphore value. 121 * @ current_value : pointer on buffer for current semaphore value. 121 122 * @ return 0 if success / return -1 if failure. 122 123 *****************************************************************************************/ 123 124 int sys_sem( void * vaddr, 124 125 uint32_t operation, 125 uint32_t * value ); 126 uint32_t init_value, 127 uint32_t * current_value ); 126 128 127 129 /****************************************************************************************** … … 584 586 585 587 /****************************************************************************************** 588 * [44] TBD 589 ****************************************************************************************** 590 * @ cxy : cluster identifier. 591 * @ lid : core local index. 592 * @ return 0 if success / return -1 if failure. 593 *****************************************************************************************/ 594 int sys_place( uint32_t cxy, 595 uint32_t lid ); 596 597 /****************************************************************************************** 586 598 * [45] This function block the calling thread on the THREAD_BLOCKED_GLOBAL condition, 587 599 * and deschedule. … … 624 636 625 637 /****************************************************************************************** 626 * [49] TBD 627 ****************************************************************************************** 628 * @ cxy : cluster identifier. 629 * @ lid : core local index. 630 * @ return 0 if success / return -1 if failure. 631 *****************************************************************************************/ 632 int sys_place( uint32_t cxy, 633 uint32_t lid ); 638 * [49] This function returns a non-zero value in the <is_fg> buffer when the process 639 * identified by the <pid> argument is the current TXT owner. 640 ****************************************************************************************** 641 * @ pid : process identifier. 642 * @ is_fg : pointer on buffer. 643 * @ return 0 if success / return -1 if failure. 644 *****************************************************************************************/ 645 int sys_is_fg( pid_t pid, 646 uint32_t * is_fg ); 634 647 635 648 #endif // _SYSCALLS_H_
Note: See TracChangeset
for help on using the changeset viewer.