Changeset 421 for trunk/kernel/syscalls
- Timestamp:
- Jan 29, 2018, 5:40:34 PM (7 years ago)
- Location:
- trunk/kernel/syscalls
- Files:
-
- 3 added
- 2 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/shared_syscalls.h
r416 r421 74 74 SYS_EXEC = 37, 75 75 SYS_STAT = 38, 76 SYS_ TRACE= 39,76 SYS_WAIT = 39, 77 77 78 78 SYS_GET_CONFIG = 40, 79 79 SYS_GET_CORE = 41, 80 80 SYS_GET_CYCLE = 42, 81 SYS_GET_SCHED = 43, 82 SYS_PANIC = 44, 83 SYS_SLEEP = 45, 84 SYS_WAKEUP = 46, 85 86 SYSCALLS_NR = 47, 81 SYS_DISPLAY = 43, 82 SYS_UNDEFINED_44 = 44, /// 83 SYS_THREAD_SLEEP = 45, 84 SYS_THREAD_WAKEUP = 46, 85 SYS_TRACE = 47, 86 SYS_FG = 48, 87 SYS_UNDEFINED_49 = 49, /// 88 89 SYSCALLS_NR = 50, 87 90 }; 88 91 … … 312 315 trace_operation_t; 313 316 317 /******************************************************************************************* 318 * This enum defines the type of structure for the "display" syscall. 319 ******************************************************************************************/ 320 321 typedef enum 322 { 323 DISPLAY_STRING = 0, 324 DISPLAY_VMM = 1, 325 DISPLAY_SCHED = 2, 326 DISPLAY_PROCESS = 3, 327 DISPLAY_VFS = 4, 328 DISPLAY_CHDEV = 5, 329 } 330 display_type_t; 331 314 332 /****************************************************************************************** 315 333 * This structure define the informations associated to a file descriptor, … … 368 386 struct timezone 369 387 { 370 int tz_minuteswest; /* 8of Greenwich */388 int tz_minuteswest; /*! of Greenwich */ 371 389 int tz_dsttime; /*! type of dst correction to apply */ 372 390 }; -
trunk/kernel/syscalls/sys_exec.c
r416 r421 170 170 171 171 // get parent process pid 172 thread_t * this = CURRENT_THREAD;173 process_t * process = this->process;174 pid_t pid = process->pid;172 thread_t * this = CURRENT_THREAD; 173 process_t * process = this->process; 174 pid_t pid = process->pid; 175 175 176 176 #if CONFIG_SYSCALL_DEBUG … … 178 178 uint64_t tm_end; 179 179 tm_start = hal_get_cycles(); 180 printk("\n[DBG] %s : core[%x,%d] enter / process %x / path = %s /cycle = %d\n",181 __FUNCTION__, local_cxy, this->core->lid, pid, exec_info.path,(uint32_t)tm_start );180 printk("\n[DBG] %s : core[%x,%d] enter / process %x / cycle = %d\n", 181 __FUNCTION__, local_cxy, this->core->lid, pid, (uint32_t)tm_start ); 182 182 #endif 183 183 … … 251 251 #if CONFIG_SYSCALL_DEBUG 252 252 tm_end = hal_get_cycles(); 253 printk("\n[DBG] %s : core[%x,%d] exit / process %x / path = %s / cost = %d\n", 254 __FUNCTION__, local_cxy, this->core->lid, pid, exec_info.path, (uint32_t)(tm_end - tm_start) ); 253 printk("\n[DBG] %s : core[%x,%d] exit / process %x / path = %s / cost = %d / cycle %d\n", 254 __FUNCTION__, local_cxy, this->core->lid, pid, exec_info.path, 255 (uint32_t)(tm_end - tm_start) , (uint32_t)tm_end ); 255 256 #endif 256 257 -
trunk/kernel/syscalls/sys_get_config.c
r410 r421 35 35 int sys_get_config( uint32_t * x_size, 36 36 uint32_t * y_size, 37 uint32_t * y_width, 37 38 uint32_t * ncores ) 38 39 { … … 40 41 uint32_t k_x_size; 41 42 uint32_t k_y_size; 43 uint32_t k_y_width; 42 44 uint32_t k_ncores; 43 45 … … 48 50 49 51 // check buffer in user space 50 error |= vmm_v2p_translate( false , x_size , &paddr ); 51 error |= vmm_v2p_translate( false , y_size , &paddr ); 52 error |= vmm_v2p_translate( false , ncores , &paddr ); 52 error |= vmm_v2p_translate( false , x_size , &paddr ); 53 error |= vmm_v2p_translate( false , y_size , &paddr ); 54 error |= vmm_v2p_translate( false , y_width , &paddr ); 55 error |= vmm_v2p_translate( false , ncores , &paddr ); 53 56 54 57 if( error ) … … 61 64 62 65 // get parameters 63 k_x_size = LOCAL_CLUSTER->x_size; 64 k_y_size = LOCAL_CLUSTER->y_size; 65 k_ncores = LOCAL_CLUSTER->cores_nr; 66 k_x_size = LOCAL_CLUSTER->x_size; 67 k_y_size = LOCAL_CLUSTER->y_size; 68 k_y_width = LOCAL_CLUSTER->y_width; 69 k_ncores = LOCAL_CLUSTER->cores_nr; 66 70 67 71 // copy to user space 68 hal_copy_to_uspace( x_size , &k_x_size , sizeof(uint32_t) ); 69 hal_copy_to_uspace( y_size , &k_y_size , sizeof(uint32_t) ); 70 hal_copy_to_uspace( ncores , &k_ncores , sizeof(uint32_t) ); 72 hal_copy_to_uspace( x_size , &k_x_size , sizeof(uint32_t) ); 73 hal_copy_to_uspace( y_size , &k_y_size , sizeof(uint32_t) ); 74 hal_copy_to_uspace( y_width , &k_y_width , sizeof(uint32_t) ); 75 hal_copy_to_uspace( ncores , &k_ncores , sizeof(uint32_t) ); 71 76 72 77 return 0; -
trunk/kernel/syscalls/sys_kill.c
r416 r421 38 38 { 39 39 uint32_t save_sr; // required to enable IRQs 40 xptr_t process_xp; // extended pointer on target reference process 41 cxy_t process_cxy; // target process cluster 42 process_t * process_ptr; // local pointer on target process 43 xptr_t parent_xp; // extended pointer on parent process 44 cxy_t parent_cxy; // parent process cluster 45 process_t * parent_ptr; // local pointer on parent process 46 pid_t ppid; // parent process PID 40 47 41 48 thread_t * this = CURRENT_THREAD; … … 49 56 #endif 50 57 51 // get owner process cluster and lpid 52 cxy_t owner_cxy = CXY_FROM_PID( pid ); 53 lpid_t lpid = LPID_FROM_PID( pid ); 58 // get cluster and pointers on reference process 59 process_xp = cluster_get_reference_process_from_pid( pid ); 60 process_cxy = GET_CXY( process_xp ); 61 process_ptr = (process_t *)GET_PTR( process_xp ); 54 62 55 // check p id56 if( (lpid >= CONFIG_MAX_PROCESS_PER_CLUSTER) || cluster_is_undefined( owner_cxy ))63 // check process existence 64 if( process_xp == XPTR_NULL ) 57 65 { 58 printk("\n[ERROR] in %s : illegal target PID = %d for thread %x in process %x\n", 59 __FUNCTION__ , pid , this->trdid , pid ); 66 syscall_dmsg("\n[ERROR] in %s : process %x not found\n", 67 __FUNCTION__ , pid ); 68 this->errno = EINVAL; 69 return -1; 70 } 71 72 // get parent process PID 73 parent_xp = hal_remote_lwd( XPTR( process_cxy , &process_ptr->parent_xp ) ); 74 parent_cxy = GET_CXY( parent_xp ); 75 parent_ptr = GET_PTR( parent_xp ); 76 ppid = hal_remote_lw( XPTR( parent_cxy , &parent_ptr->pid ) ); 77 78 // processes INIT and processes KSH cannot be stoped or killed 79 if( ppid < 2 ) 80 { 81 syscall_dmsg("\n[ERROR] in %s : process %x cannot be killed\n", 82 __FUNCTION__ , pid ); 60 83 this->errno = EINVAL; 61 84 return -1; 62 85 } 63 86 87 // does nothing if sig_id == 0 88 if( sig_id == 0 ) return 0; 89 64 90 // check sig_id 65 91 if( (sig_id != SIGSTOP) && (sig_id != SIGCONT) && (sig_id != SIGKILL) ) 66 92 { 67 printk("\n[ERROR] in %s : illegal signal type for thread %x inprocess %x\n",68 __FUNCTION__ , sig_id , this->trdid ,pid );93 syscall_dmsg("\n[ERROR] in %s : illegal signal type for process %x\n", 94 __FUNCTION__ , sig_id , pid ); 69 95 this->errno = EINVAL; 70 96 return -1; … … 75 101 76 102 // execute process_make_kill() function in owner cluster 77 if( local_cxy == owner_cxy ) // owner is local103 if( local_cxy == process_cxy ) // owner cluster is local 78 104 { 79 105 process_make_kill( pid , sig_id ); 80 106 } 81 else // owner is remote107 else // owner cluster is remote 82 108 { 83 rpc_process_make_kill_client( owner_cxy , pid , sig_id );109 rpc_process_make_kill_client( process_cxy , pid , sig_id ); 84 110 } 85 111 -
trunk/kernel/syscalls/sys_read.c
r418 r421 98 98 99 99 // enable IRQs 100 //hal_enable_irq( &save_sr );100 hal_enable_irq( &save_sr ); 101 101 102 102 // get extended pointer on remote file descriptor … … 129 129 130 130 // action depend on file type 131 if( type == INODE_TYPE_FILE ) // transfer count bytes from file mapper 132 { 131 if( type == INODE_TYPE_FILE ) // check file readable & read from mapper 132 { 133 // check file readable 134 uint32_t attr = hal_remote_lw( XPTR( file_cxy , &file_ptr->attr ) ); 135 if( (attr & FD_ATTR_READ_ENABLE) == 0 ) 136 { 137 printk("\n[ERROR] in %s : file %d not readable in process %x\n", 138 __FUNCTION__ , file_id , process->pid ); 139 this->errno = EBADFD; 140 return -1; 141 } 142 143 // move count bytes from mapper 133 144 nbytes = vfs_user_move( true, // from mapper to buffer 134 145 file_xp, … … 136 147 count ); 137 148 } 138 else if( type == INODE_TYPE_DEV ) // transfer count bytes from device 139 { 149 else if( type == INODE_TYPE_DEV ) // check ownership & read from from device 150 { 151 // move count bytes from device 140 152 nbytes = devfs_user_move( true, // from device to buffer 141 153 file_xp, 142 154 vaddr, 143 155 count ); 156 157 // check ownership 158 xptr_t chdev_xp = chdev_from_file( file_xp ); 159 cxy_t chdev_cxy = GET_CXY( chdev_xp ); 160 chdev_t * chdev_ptr = (chdev_t *)GET_PTR( chdev_xp ); 161 xptr_t owner_xp = hal_remote_lwd( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) ); 162 163 if( XPTR( local_cxy , process ) != owner_xp ) 164 { 165 printk("\n[ERROR] in %s : process %x not in foreground for TXT%d\n", 166 __FUNCTION__, process->pid, hal_remote_lw( XPTR(chdev_cxy,&chdev_ptr->channel) ) ); 167 this->errno = EBADFD; 168 return -1; 169 } 144 170 } 145 171 else 146 172 { 147 173 nbytes = 0; 148 panic("file type %d non supported yet", type );174 assert( false , __FUNCTION__ , "file type %d non supported yet\n", type ); 149 175 } 150 176 … … 158 184 159 185 // restore IRQs 160 //hal_restore_irq( save_sr );186 hal_restore_irq( save_sr ); 161 187 162 188 hal_fence(); … … 171 197 #endif 172 198 173 #if CONFIG_READ_DEBUG199 #if (CONFIG_READ_DEBUG & 0x1) 174 200 exit_sys_read = (uint32_t)tm_end; 175 201 -
trunk/kernel/syscalls/sys_thread_join.c
r409 r421 100 100 if( target_ptr->signature != THREAD_SIGNATURE ) 101 101 { 102 panic("\n[PANIC] in %s : kernel stack overflow\n", __FUNCTION__);102 assert( false , __FUNCTION__ , "kernel stack overflow\n" ); 103 103 } 104 104 -
trunk/kernel/syscalls/sys_thread_yield.c
r408 r421 2 2 * sys_thread_yield.c - calls the scheduler to yield 3 3 * 4 * Authors Ghassan Almaless (2008,2009,2010,2011,2012) 5 * Alain Greiner (2016,2017) 4 * Authors Alain Greiner (2016,2017) 6 5 * 7 6 * Copyright (c) 2011,2012 UPMC Sorbonne Universites -
trunk/kernel/syscalls/sys_write.c
r418 r421 92 92 cxy_t file_cxy = GET_CXY( file_xp ); 93 93 94 // check file writable 95 uint32_t attr = hal_remote_lw( XPTR( file_cxy , &file_ptr->attr ) ); 96 if( (attr & FD_ATTR_WRITE_ENABLE) == 0 ) 97 { 98 printk("\n[ERROR] in %s : file %d not writable in process %x\n", 99 __FUNCTION__ , file_id , process->pid ); 100 this->errno = EBADFD; 101 return -1; 102 } 103 94 104 95 // get file type 105 96 vfs_inode_type_t type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type ) ); 106 97 107 98 // action depend on file type 108 if( type == INODE_TYPE_FILE ) // transfer count bytes to filemapper99 if( type == INODE_TYPE_FILE ) // check file writable & write to mapper 109 100 { 101 // check file writable 102 uint32_t attr = hal_remote_lw( XPTR( file_cxy , &file_ptr->attr ) ); 103 if( (attr & FD_ATTR_WRITE_ENABLE) == 0 ) 104 { 105 printk("\n[ERROR] in %s : file %d not writable in process %x\n", 106 __FUNCTION__ , file_id , process->pid ); 107 this->errno = EBADFD; 108 return -1; 109 } 110 111 // move count bytes to mapper 110 112 nbytes = vfs_user_move( false, // from buffer to mapper 111 113 file_xp, … … 113 115 count ); 114 116 } 115 else if( type == INODE_TYPE_DEV ) // transfer count bytesto device117 else if( type == INODE_TYPE_DEV ) // check ownership & write to device 116 118 { 119 // move count bytes to device 117 120 nbytes = devfs_user_move( false, // from buffer to device 118 121 file_xp, … … 123 126 { 124 127 nbytes = 0; 125 panic("file type %d non supported", type );128 assert( false , __FUNCTION__ , "file type %d non supported\n", type ); 126 129 } 127 130 … … 148 151 #endif 149 152 150 #if CONFIG_WRITE_DEBUG153 #if (CONFIG_WRITE_DEBUG & 0x1) 151 154 printk("\n@@@@@@@@@@@@ timing to write character %c\n" 152 155 " - enter_sys_write = %d\n" -
trunk/kernel/syscalls/syscalls.h
r409 r421 78 78 * [3] This blocking function suspend execution of the calling thread until completion 79 79 * of another target thread identified by the <trdid> argument. 80 * The target thread must be joinable (running in ATTACHED mode), and must be different 81 * from the calling thread. 80 82 * If the <exit_value> argument is not NULL, the value passed to pthread_exit() by the 81 83 * target thread is stored in the location referenced by exit_value. … … 426 428 * remote access to traverse the list of process copies stored in the owner cluster, 427 429 * and the RPC_SIGNAL_RISE to signal the remote threads. 430 * This function does nothing for (sig_id == 0). This can be used to check process pid. 431 * TODO : This first implementation supports only SIGKILL / SIGSTOP / SIGCONT values. 428 432 ****************************************************************************************** 429 433 * @ pid : target process identifier. … … 491 495 492 496 /****************************************************************************************** 493 * [39] This non-standard function is used to activate / desactivate the trace for a thread 497 * [39] This blocking function wait a change of a child process state. A change can be: 498 * - a termination of child following a child exit. 499 * - a termination of child following a SIGKILL signal. 500 * - a blocking of child following a SIGSTOP signal. 501 * It returns the PID of the involved child process, after storing in the memory slot 502 * pointed by the <status> argument relevant information on the child state change. 503 * The following macros can be used to extract information from status: 504 * - WIFEXITED(status) : is true if the child process terminated with an exit(). 505 * - WIFSIGNALED(status) : is true if the child process terminated by a signal. 506 * - WIFSTOPPED(status) : is true if the child process is stopped by a signal. 507 * - WEXITSTATUS(status) : returns the low-order 8 bits of the exit() argument. 508 * A status of 0 indicates a normal termination. 509 * If a parent process terminates without waiting for all child processes to terminate, 510 * the remaining child processes are attached to the init process. 511 ****************************************************************************************** 512 * @ status : pointer on the child PID status. 513 * @ return child PID if success / return -1 if failure. 514 *****************************************************************************************/ 515 int sys_wait( uint32_t * status ); 516 517 /****************************************************************************************** 518 * [40] This function returns the hardware platform parameters. 519 ****************************************************************************************** 520 * @ x_size : [out] number of clusters in a row. 521 * @ y_size : [out] number of clusters in a column. 522 * @ y_width : [out] number of bits in Y field for CXY. 523 * @ ncores : [out] number of cores per cluster. 524 * @ return 0 if success / return -1 if illegal arguments 525 *****************************************************************************************/ 526 int sys_get_config( uint32_t * x_size, 527 uint32_t * y_size, 528 uint32_t * y_width, 529 uint32_t * ncores ); 530 531 /****************************************************************************************** 532 * [41] This function returns the calling core cluster and local index. 533 ****************************************************************************************** 534 * @ cxy : [out] cluster identifier (fixed format) 535 * @ lid : [out] core local index in cluster. 536 * @ return 0 if success / return -1 if illegal arguments 537 *****************************************************************************************/ 538 int sys_get_core( uint32_t * cxy, 539 uint32_t * lid ); 540 541 /****************************************************************************************** 542 * [42] This function returns in a 64 bits user buffer the calling core cycles count. 543 * It uses both the hardware register and the core descriptor cycles count to take 544 * into account a possible harware register overflow in 32 bits architectures. 545 ****************************************************************************************** 546 * cycle : [out] address of buffer in user space. 547 * @ return 0 if success / return -1 if illegal arguments 548 *****************************************************************************************/ 549 int sys_get_cycle( uint64_t * cycle ); 550 551 /****************************************************************************************** 552 * [43] This debug function displays on the kernel terminal TXT0 an user defined string, 553 * or the current state of a kernel structure, identified by the <type> argument. 554 * The <arg0> and <arg1> arguments depends on the structure type. It can be: 555 * - VMM : VSL and GPT for a process identified by <pid>. 556 * - SCHED : all threads allocated to a scheduler identified by <cxy> & <lid>. 557 * - PROCESS : all processes registered in a cluster identified by <cxy>. 558 * - VFS : all files registered in the VFS cache. 559 * - CHDEV : all registered channel devices. 560 ****************************************************************************************** 561 * type : [in] STRING / VMM / SCHED / PROCESS / VSEG / VFS 562 * arg0 : [in] type dependant argument. 563 * arg1 : [in] type dependant argument. 564 * @ return 0 if success / return -1 if illegal arguments 565 *****************************************************************************************/ 566 int sys_display( reg_t type, 567 reg_t arg0, 568 reg_t arg1 ); 569 570 /****************************************************************************************** 571 * [45] This function block the calling thread on the THREAD_BLOCKED_GLOBAL condition, 572 * and deschedule. 573 ****************************************************************************************** 574 * @ return 0 if success / returns -1 if failure. 575 *****************************************************************************************/ 576 int sys_thread_sleep(); 577 578 /****************************************************************************************** 579 * [46] This function unblock the thread identified by its <trdid> from the 580 * THREAD_BLOCKED_GLOBAL condition. 581 ****************************************************************************************** 582 * @ trdid : target thread identifier. 583 * @ return 0 if success / return -1 if failure. 584 *****************************************************************************************/ 585 int sys_thread_wakeup(); 586 587 /****************************************************************************************** 588 * [47] This non-standard function is used to activate / desactivate the trace for a thread 494 589 * identified by the <trdid> and <pid> arguments. 495 590 * It can be called by any other thread in the same process. … … 505 600 506 601 /****************************************************************************************** 507 * [40] This function returns the hardware platform parameters. 508 ****************************************************************************************** 509 * @ x_size : [out] number of clusters in a row. 510 * @ y_size : [out] number of clusters in a column. 511 * @ ncores : [out] number of cores per cluster. 512 * @ return 0 if success / return -1 if illegal arguments 513 *****************************************************************************************/ 514 int sys_get_config( uint32_t * x_size, 515 uint32_t * y_size, 516 uint32_t * ncores ); 517 518 /****************************************************************************************** 519 * [41] This function returns the calling core cluster and local index. 520 ****************************************************************************************** 521 * @ cxy : [out] cluster identifier (fixed format) 522 * @ lid : [out] core local index in cluster. 523 * @ return 0 if success / return -1 if illegal arguments 524 *****************************************************************************************/ 525 int sys_get_core( uint32_t * cxy, 526 uint32_t * lid ); 527 528 /****************************************************************************************** 529 * [42] This function returns in a 64 bits user buffer the calling core cycles count. 530 * It uses both the hardware register and the core descriptor cycles count to take 531 * into account a possible harware register overflow in 32 bits architectures. 532 ****************************************************************************************** 533 * cycle : [out] address of buffer in user space. 534 * @ return 0 if success / return -1 if illegal arguments 535 *****************************************************************************************/ 536 int sys_get_cycle( uint64_t * cycle ); 537 538 /****************************************************************************************** 539 * [43] This debug function displays on the kernel terminal the current state of a 540 * scheduler identified by the <cxy> and <lid> arguments. 541 ****************************************************************************************** 542 * cxy : [in] target cluster identifier. 543 * lid : [in] target core local index. 544 * @ return 0 if success / return -1 if illegal arguments 545 *****************************************************************************************/ 546 int sys_get_sched( uint32_t cxy, 547 uint32_t lid ); 548 549 /****************************************************************************************** 550 * [44] This debug function requires the kernel to display on the kernel terminal a message 551 * containing the thread / process / core identifiers, and the cause of panic, 552 * as defined by the <string> argument. 553 ****************************************************************************************** 554 * string : [in] message to be displayed. 555 * @ return always 0. 556 *****************************************************************************************/ 557 int sys_panic( char * string ); 558 559 /****************************************************************************************** 560 * [45] This function block the calling thread on the THREAD_BLOCKED_GLOBAL condition, 561 * and deschedule. 562 ****************************************************************************************** 563 * @ return 0 if success / returns -1 if failure. 564 *****************************************************************************************/ 565 int sys_thread_sleep(); 566 567 /****************************************************************************************** 568 * [46] This function unblock the thread identified by its <trdid> from the 569 * THREAD_BLOCKED_GLOBAL condition. 570 ****************************************************************************************** 571 * @ trdid : target thread identifier. 572 * @ return 0 if success / return -1 if failure. 573 *****************************************************************************************/ 574 int sys_thread_wakeup(); 602 * [48] This function gives the process identified by the <pid> argument 603 * the exclusive ownership of its TXT_TX terminal (put it in foreground). 604 ****************************************************************************************** 605 * @ pid : process identifier. 606 * @ return 0 if success / return -1 if failure. 607 *****************************************************************************************/ 608 int sys_fg( pid_t pid ); 575 609 576 610
Note: See TracChangeset
for help on using the changeset viewer.