Changeset 683 for trunk/kernel/syscalls
- Timestamp:
- Jan 13, 2021, 12:36:17 AM (4 years ago)
- Location:
- trunk/kernel/syscalls
- Files:
-
- 1 deleted
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/shared_include/shared_almos.h
r670 r683 2 2 * shared_almos.h - Shared mnemonics used by the almos-mkh specific syscalls. 3 3 * 4 * Author Alain Greiner (2016,2017,2018 )4 * Author Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 62 62 63 63 /******************************************************************************************* 64 * This enum defines the operation mnemonics for the non standard get_xxx() syscalls. 65 ******************************************************************************************/ 66 67 typedef enum 68 { 69 GET_PROCESSES = 0, 70 GET_CONFIG = 1, 71 GET_CORE_ID = 2, 72 GET_NB_CORES = 3, 73 GET_BEST_CORE = 4, 74 GET_CYCLE = 5, 75 GET_THREAD_INFO = 6, 76 } 77 get_operation_type_t; 78 79 /******************************************************************************************* 64 80 * This structure defines the - user accessible - information stored in a thread. 65 81 ******************************************************************************************/ -
trunk/kernel/syscalls/shared_include/shared_dirent.h
r611 r683 1 1 /* 2 * shared_dirent.h - Shared structureused by the opendir() / readdir() / closedir() syscalls.2 * shared_dirent.h - structures used by the opendir() / readdir() / closedir() syscalls. 3 3 * 4 * Author Alain Greiner (2016,2017,2018 )4 * Author Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites -
trunk/kernel/syscalls/shared_include/shared_socket.h
r670 r683 69 69 SOCK_SEND = 5, 70 70 SOCK_RECV = 6, 71 SOCK_SENDTO = 7, 72 SOCK_RECVFROM = 8, 71 73 } 72 74 socket_operation_type_t; -
trunk/kernel/syscalls/shared_include/syscalls_numbers.h
r657 r683 2 2 * syscalls_numbers.c - Contains enum of the syscalls. 3 3 * 4 * Author Alain Greiner (2016,2017,2018,2019 )4 * Author Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 27 27 /****************************************************************************************** 28 28 * This enum defines the mnemonics for the syscall indexes. 29 * It must be kept consistent with the array defined in do_syscalls.c 29 * It must be kept consistent with the array defined in the <do_syscalls.c> file 30 * and with the SYS_OBJs defined in the kernel <Makefile> 30 31 *****************************************************************************************/ 31 32 typedef enum … … 75 76 SYS_WAIT = 39, 76 77 77 SYS_GET _CONFIG= 40,78 SYS_ GET_CORE_ID= 41,79 SYS_ GET_CYCLE = 42,80 SYS_ DISPLAY= 43,81 SYS_ PLACE_FORK = 44,82 SYS_T HREAD_SLEEP= 45,83 SYS_ THREAD_WAKEUP= 46,84 SYS_ TRACE= 47,85 SYS_F G= 48,86 SYS_ IS_FG= 49,78 SYS_GET = 40, 79 SYS_DISPLAY = 41, 80 SYS_PLACE_FORK = 42, 81 SYS_THREAD_SLEEP = 43, 82 SYS_THREAD_WAKEUP = 44, 83 SYS_TRACE = 45, 84 SYS_FG = 46, 85 SYS_IS_FG = 47, 86 SYS_FBF = 48, 87 SYS_UNDEFINED_49 = 49, 87 88 88 89 SYS_EXIT = 50, 89 90 SYS_SYNC = 51, 90 91 SYS_FSYNC = 52, 91 SYS_GET_BEST_CORE = 53, 92 SYS_GET_NB_CORES = 54, 93 SYS_GET_THREAD_INFO = 55, 94 SYS_FBF = 56, 95 SYS_SOCKET = 57, 92 SYS_SOCKET = 53, 96 93 97 SYSCALLS_NR = 5 8,94 SYSCALLS_NR = 54, 98 95 99 96 } syscalls_t; -
trunk/kernel/syscalls/sys_alarm.c
r506 r683 3 3 * 4 4 * Author Alain Greiner (2016,2017) 5 *5 * 6 6 * Copyright (c) UPMC Sorbonne Universites 7 7 * -
trunk/kernel/syscalls/sys_barrier.c
r670 r683 2 2 * sys_barrier.c - Access a POSIX barrier. 3 3 * 4 * authors Alain Greiner (2016,2017,2018,2019 )4 * authors Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 33 33 #include <remote_barrier.h> 34 34 35 ///////////////////////////////////////////////////////////////////////////////// 36 // This function returns a printable string for the barrier related command type. 37 ///////////////////////////////////////////////////////////////////////////////// 38 39 #if DEBUG_SYS_SOCKET || DEBUG_SYSCALLS_ERROR 40 static char* barrier_cmd_str( uint32_t type ) 41 { 42 if ( type == BARRIER_INIT ) return "INIT"; 43 else if( type == BARRIER_WAIT ) return "WAIT"; 44 else if( type == BARRIER_DESTROY ) return "DESTROY"; 45 else return "undefined"; 46 } 47 #endif 48 35 49 ////////////////////////////////// 36 50 int sys_barrier( intptr_t vaddr, … … 53 67 if( DEBUG_SYS_BARRIER < tm_start ) 54 68 printk("\n[%s] thread[%x,%x] enters for %s / count %d / cycle %d\n", 55 __FUNCTION__, process->pid, this->trdid, sys_barrier_op_str(operation), count,69 __FUNCTION__, process->pid, this->trdid, barrier_cmd_str(operation), count, 56 70 (uint32_t)tm_start ); 57 71 #endif 58 72 59 73 // check vaddr in user vspace 60 error = vmm_get_vseg( process , vaddr , &vseg ); 61 if( error ) 74 if( vmm_get_vseg( process , vaddr , &vseg ) ) 62 75 { 63 76 … … 65 78 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 66 79 printk("\n[ERROR] in %s for %s : unmapped barrier %x / thread[%x,%x]\n", 67 __FUNCTION__, sys_barrier_op_str(operation), vaddr, process->pid, this->trdid );68 #endif 69 this->errno = error;80 __FUNCTION__, barrier_cmd_str(operation), vaddr, process->pid, this->trdid ); 81 #endif 82 this->errno = EINVAL; 70 83 return -1; 71 84 } … … 79 92 if( attr != 0 ) // QDT barrier required 80 93 { 81 error = vmm_get_vseg( process , attr , &vseg ); 82 if( error ) 94 if( vmm_get_vseg( process , attr , &vseg ) ) 83 95 { 84 96 -
trunk/kernel/syscalls/sys_display.c
r670 r683 529 529 530 530 // display socket descriptor on TXT0 531 socket_display( XPTR( file_cxy , socket ), NULL );531 socket_display( XPTR( file_cxy , socket ), __FUNCTION__ , NULL ); 532 532 533 533 break; -
trunk/kernel/syscalls/sys_exec.c
r670 r683 38 38 #include <syscalls.h> 39 39 40 ////////////////////////////////////////////////i//////////////////////////////////////// 41 // This static function is called twice by the sys_exec() function : 42 // - to register the main() arguments (args) in the process <exec_info> structure. 43 // - to register the environment variables (envs) in the <exec_info> structure. 44 // In both cases the input is an array of NULL terminated string pointers in user space, 45 // identified by the <u_pointers> argument. The strings can be dispatched anywhere in 46 // the calling user process space. The max number of envs, and the max number of args 47 // are defined by the CONFIG_PROCESS_ARGS_NR and CONFIG_PROCESS_ENVS_MAX_NR parameters. 48 ////////////////////////////////////////////////i//////////////////////////////////////// 49 // Implementation Note: 50 // Both the array of pointers and the strings themselve are stored in kernel space in one 51 // single, dynamically allocated, kernel buffer containing an integer number of pages, 52 // defined by the CONFIG_VMM_ENVS_SIZE and CONFIG_VMM_STACK_SIZE parameters. 53 // These two kernel buffers contains : 54 // - in the first bytes a fixed size kernel array of kernel pointers on the strings. 55 // - in the following bytes the strings themselves. 56 // The exec_info_t structure is defined in the <process.h> file. 57 ////////////////////////////////////////////////i//////////////////////////////////////// 58 // @ is_args : [in] true if called for (args) / false if called for (envs). 59 // @ u_pointers : [in] array of pointers on the strings (in user space). 60 // @ exec_info : [inout] pointer on the exec_info structure. 61 // @ return 0 if success / non-zero if too many strings or no memory. 62 ////////////////////////////////////////////////i//////////////////////////////////////// 63 static error_t exec_get_strings( bool_t is_args, 64 char ** u_pointers, 65 exec_info_t * exec_info ) 66 { 67 uint32_t index; // slot index in pointers array 68 uint32_t length; // string length (in bytes) 69 uint32_t pointers_bytes; // number of bytes to store pointers 70 uint32_t max_index; // max size of pointers array 71 char ** k_pointers; // base of kernel array of pointers 72 char * k_buf_ptr; // pointer on first empty slot in strings buffer 73 uint32_t k_buf_space; // number of bytes available in string buffer 74 char * k_buf; // kernel buffer for both pointers & strings 75 76 #if DEBUG_SYS_EXEC 77 thread_t * this = CURRENT_THREAD; 78 uint32_t cycle = (uint32_t)hal_get_cycles(); 79 #endif 80 81 // Allocate one block of physical memory for both the pointers and the strings 82 83 if( is_args ) 84 { 85 k_buf = kmem_alloc( bits_log2(CONFIG_VMM_ARGS_SIZE << CONFIG_PPM_PAGE_ORDER), AF_ZERO ); 86 87 pointers_bytes = (CONFIG_PROCESS_ARGS_MAX_NR + 1) * sizeof(char *); 88 k_pointers = (char **)k_buf; 89 k_buf_ptr = k_buf + pointers_bytes; 90 k_buf_space = (CONFIG_VMM_ARGS_SIZE << CONFIG_PPM_PAGE_ORDER) - pointers_bytes; 91 max_index = CONFIG_PROCESS_ARGS_MAX_NR + 1; 92 93 #if DEBUG_SYS_EXEC 94 if( DEBUG_SYS_EXEC < cycle ) 95 printk("\n[%s] thread[%x,%x] for args / u_buf %x / k_buf %x\n", 96 __FUNCTION__, this->process->pid, this->trdid, u_pointers, k_buf ); 97 #endif 98 99 } 100 else // envs 101 { 102 k_buf = kmem_alloc( bits_log2(CONFIG_VMM_ENVS_SIZE << CONFIG_PPM_PAGE_ORDER), AF_ZERO ); 103 104 pointers_bytes = (CONFIG_PROCESS_ENVS_MAX_NR + 1) * sizeof(char *); 105 k_pointers = (char **)k_buf; 106 k_buf_ptr = k_buf + pointers_bytes; 107 k_buf_space = (CONFIG_VMM_ENVS_SIZE << CONFIG_PPM_PAGE_ORDER) - pointers_bytes; 108 max_index = CONFIG_PROCESS_ENVS_MAX_NR + 1; 109 110 #if DEBUG_SYS_EXEC 111 if( DEBUG_SYS_EXEC < cycle ) 112 printk("\n[%s] thread[%x,%x] for envs / u_buf %x / k_buf %x\n", 113 __FUNCTION__, this->process->pid, this->trdid, u_pointers, k_buf ); 114 #endif 115 116 } 117 118 // copy the user array of pointers to kernel buffer 119 hal_copy_from_uspace( XPTR( local_cxy , k_pointers ), 120 u_pointers, 121 pointers_bytes ); 122 123 // WARNING : the pointers copied in the k_pointers[] array are user pointers, 124 // after the loop below, the k_pointers[] array contains kernel pointers. 125 126 #if DEBUG_SYS_EXEC 127 if( DEBUG_SYS_EXEC < cycle ) 128 printk("\n[%s] thread[%x,%x] moved u_ptr array of pointers to k_ptr array\n", 129 __FUNCTION__, this->process->pid, this->trdid ); 130 #endif 131 132 // scan kernel array of pointers to copy strings to kernel buffer 133 for( index = 0 ; index < max_index ; index++ ) 134 { 135 // exit loop if (k_pointers[index] == NUll) 136 if( k_pointers[index] == NULL ) break; 137 138 // compute string length (without the NUL character) 139 length = hal_strlen_from_uspace( k_pointers[index] ); 140 141 // return error if overflow in kernel buffer 142 if( length > k_buf_space ) return -1; 143 144 // copy the string itself to kernel buffer 145 hal_copy_from_uspace( XPTR( local_cxy , k_buf_ptr ), 146 k_pointers[index], 147 length + 1 ); 148 149 #if DEBUG_SYS_EXEC 150 if( DEBUG_SYS_EXEC < cycle ) 151 printk("\n[%s] thread[%x,%x] copied string[%d] <%s> to kernel buffer / length %d\n", 152 __FUNCTION__, this->process->pid, this->trdid, index, k_buf_ptr, length ); 153 #endif 154 155 // replace the user pointer by a kernel pointer in the k_pointer[] array 156 k_pointers[index] = k_buf_ptr; 157 158 // increment loop variables 159 k_buf_ptr += (length + 1); 160 k_buf_space -= (length + 1); 161 162 #if DEBUG_SYS_EXEC 163 if( DEBUG_SYS_EXEC < cycle ) 164 { 165 if( k_pointers[0] != NULL ) 166 printk("\n[%s] thread[%x,%x] : &arg0 = %x / arg0 = <%s>\n", 167 __FUNCTION__, this->process->pid, this->trdid, k_pointers[0], k_pointers[0] ); 168 else 169 printk("\n[%s] thread[%x,%x] : unexpected NULL value for &arg0\n", 170 __FUNCTION__, this->process->pid, this->trdid ); 171 } 172 #endif 173 174 } // end loop on index 175 176 // update into exec_info structure 177 if( is_args ) 178 { 179 exec_info->args_pointers = k_pointers; 180 exec_info->args_nr = index; 181 } 182 else 183 { 184 exec_info->envs_pointers = k_pointers; 185 exec_info->envs_buf_free = k_buf_ptr; 186 exec_info->envs_nr = index; 187 } 188 189 #if DEBUG_SYS_EXEC 190 if( DEBUG_SYS_EXEC < cycle ) 191 printk("\n[%s] thread[%x,%x] copied %d strings to kernel buffer\n", 192 __FUNCTION__, this->process->pid, this->trdid, index ); 193 #endif 194 195 return 0; 196 197 } // end exec_get_strings() 198 199 40 200 /////////////////////////////// 41 int sys_exec( char * pathname, 42 char ** user_args, // pointer onprocess arguments in user space43 char ** user_envs ) // pointer onenv variables in user space201 int sys_exec( char * pathname, // .elf file pathname in user space 202 char ** user_args, // pointer on array of process arguments in user space 203 char ** user_envs ) // pointer on array of env variables in user space 44 204 { 45 205 error_t error; … … 96 256 97 257 #if DEBUG_SYSCALLS_ERROR 258 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 98 259 printk("\n[ERROR] in %s for thread[%x,%] : user_args pointer %x unmapped\n", 99 260 __FUNCTION__, pid, trdid, user_args ); … … 115 276 return -1; 116 277 } 117 118 #if DEBUG_SYS_EXEC119 if( DEBUG_SYS_EXEC < (uint32_t)tm_start )120 printk("\n[%s] thread[%x,%x] enter / path <%s> / args %x / envs %x / cycle %d\n",121 __FUNCTION__, pid, trdid, &process->exec_info.path[0], user_args, user_envs, cycle );122 #endif123 278 124 279 // 1. copy "pathname" in kernel exec_info structure … … 127 282 CONFIG_VFS_MAX_PATH_LENGTH ); 128 283 284 #if DEBUG_SYS_EXEC 285 if( DEBUG_SYS_EXEC < (uint32_t)tm_start ) 286 printk("\n[%s] thread[%x,%x] enter / path <%s> / args %x / envs %x / cycle %d\n", 287 __FUNCTION__, pid, trdid, &process->exec_info.path[0], 288 user_args, user_envs, (uint32_t)tm_start ); 289 #endif 290 129 291 // 2. copy "arguments" pointers & strings in process exec_info if required 130 292 if( user_args != NULL ) 131 293 { 132 if( process_exec_get_strings( true , user_args , &process->exec_info ) )294 if( exec_get_strings( true , user_args , &process->exec_info ) ) 133 295 { 134 296 135 297 #if DEBUG_SYSCALLS_ERROR 136 298 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 137 printk("\n[ERROR] in %s : thread[%x,%] get arguments for <%s>\n",299 printk("\n[ERROR] in %s : thread[%x,%] cannot get arguments for <%s>\n", 138 300 __FUNCTION__, pid, trdid, pathname ); 139 301 #endif … … 144 306 #if DEBUG_SYS_EXEC 145 307 if( DEBUG_SYS_EXEC < (uint32_t)tm_start ) 146 printk("\n[%s] thread[%x,%x] got arguments/ arg[0] = <%s>\n",308 printk("\n[%s] thread[%x,%x] set arguments in exec_info / arg[0] = <%s>\n", 147 309 __FUNCTION__, pid, trdid, process->exec_info.args_pointers[0] ); 148 310 #endif … … 153 315 if( user_envs != NULL ) 154 316 { 155 if( process_exec_get_strings( false , user_envs , &process->exec_info ) )317 if( exec_get_strings( false , user_envs , &process->exec_info ) ) 156 318 { 157 319 158 320 #if DEBUG_SYSCALLS_ERROR 159 321 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 160 printk("\n[ERROR] in %s : thread[%x,%] get env variables for <%s>\n",322 printk("\n[ERROR] in %s : thread[%x,%] cannot get env variables for <%s>\n", 161 323 __FUNCTION__, pid, trdid, pathname ); 162 324 #endif … … 167 329 #if DEBUG_SYS_EXEC 168 330 if( DEBUG_SYS_EXEC < (uint32_t)tm_start ) 169 printk("\n[%s] thread[%x,%x] got envs/ env[0] = <%s>\n",331 printk("\n[%s] thread[%x,%x] set envs in exec_info / env[0] = <%s>\n", 170 332 __FUNCTION__, pid, trdid, process->exec_info.envs_pointers[0] ); 171 333 #endif -
trunk/kernel/syscalls/sys_kill.c
r664 r683 2 2 * sys_kill.c - Kernel function implementing the "kill" system call. 3 3 * 4 * Author Alain Greiner (2016,2017,2018)4 * Author Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 67 67 process_t * process = this->process; 68 68 69 #if (DEBUG_SYS_KILL || CONFIG_INSTRUMENTATION_SYSCALLS)69 #if DEBUG_SYS_KILL || DEBUG_SYSCALLS_ERROR || CONFIG_INSTRUMENTATION_SYSCALLS 70 70 uint64_t tm_start = hal_get_cycles(); 71 71 #endif 72 72 73 73 #if DEBUG_SYS_KILL 74 tm_start = hal_get_cycles();75 74 if( DEBUG_SYS_KILL < tm_start ) 76 75 printk("\n[%s] thread[%x,%x] enter : %s to process %x / cycle %d\n", … … 95 94 96 95 #if DEBUG_SYSCALLS_ERROR 97 printk("\n[ERROR] in %s : process %x not found\n", __FUNCTION__, pid ); 96 if( DEBUG_SYSCALLS_ERROR < tm_start ) 97 printk("\n[ERROR] in %s : thread[%x,%x] / process %x not found\n", 98 __FUNCTION__, process->pid, this->trdid, pid ); 98 99 #endif 99 100 this->errno = EINVAL; … … 175 176 176 177 #if DEBUG_SYSCALLS_ERROR 177 printk("\n[ERROR] in %s : process %x cannot kill itself\n", __FUNCTION__, pid ); 178 if( DEBUG_SYSCALLS_ERROR < tm_start ) 179 printk("\n[ERROR] in %s : thread[%x,%x] / process %x cannot kill itself\n", 180 __FUNCTION__, process->pid, this->trdid, pid ); 178 181 #endif 179 182 this->errno = EINVAL; … … 186 189 187 190 #if DEBUG_SYSCALLS_ERROR 188 printk("\n[ERROR] in %s : process_init cannot be killed\n", __FUNCTION__ ); 191 if( DEBUG_SYSCALLS_ERROR < tm_start ) 192 printk("\n[ERROR] in %s : thread[%x,%x] / process_init cannot be killed\n", 193 __FUNCTION__, process->pid, this->trdid); 189 194 #endif 190 195 this->errno = EINVAL; … … 219 224 220 225 #if DEBUG_SYSCALLS_ERROR 221 printk("\n[ERROR] in %s : illegal signal %d / process %x\n", __FUNCTION__, sig_id, pid ); 226 if( DEBUG_SYSCALLS_ERROR < tm_start ) 227 printk("\n[ERROR] in %s : thread[%x,%x] / illegal signal %d\n", 228 __FUNCTION__, process->pid, this->trdid, sig_id ); 222 229 #endif 223 230 this->errno = EINVAL; … … 234 241 #if DEBUG_SYS_KILL 235 242 if( DEBUG_SYS_KILL < tm_end ) 236 printk("\n[%s] thread[%x,%x] exit / process %x / %s / c ost = %d / cycle %d\n",243 printk("\n[%s] thread[%x,%x] exit / process %x / %s / cycle %d\n", 237 244 __FUNCTION__ , this->process->pid, this->trdid, pid, 238 sig_type_str(sig_id), (uint32_t) (tm_end - tm_start), (uint32_t)tm_end );245 sig_type_str(sig_id), (uint32_t)tm_end ); 239 246 #endif 240 247 -
trunk/kernel/syscalls/sys_opendir.c
r670 r683 65 65 66 66 #if DEBUG_SYSCALLS_ERROR 67 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 68 printk("\n[ERROR] in %s : thread[%x,%x] / DIR buffer %x unmapped\n", 69 __FUNCTION__ , process->pid , this->trdid, dirp ); 67 printk("\n[ERROR] in %s : thread[%x,%x] / DIR buffer %x unmapped / cycle %d\n", 68 __FUNCTION__ , process->pid , this->trdid, dirp, (uint32_t)tm_start ); 70 69 #endif 71 70 this->errno = EINVAL; … … 80 79 81 80 #if DEBUG_SYSCALLS_ERROR 82 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 83 printk("\n[ERROR] in %s : thread[%x,%x] / pathname %x unmapped\n", 84 __FUNCTION__ , process->pid , this->trdid, pathname ); 81 printk("\n[ERROR] in %s : thread[%x,%x] / pathname %x unmapped / cycle %d\n", 82 __FUNCTION__ , process->pid , this->trdid, pathname, (uint32_t)tm_start ); 85 83 #endif 86 84 this->errno = EINVAL; … … 92 90 93 91 #if DEBUG_SYSCALLS_ERROR 94 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 95 printk("\n[ERROR] in %s / thread[%x,%x] : pathname too long\n", 96 __FUNCTION__ , process->pid , this->trdid ); 92 printk("\n[ERROR] in %s / thread[%x,%x] : pathname too long / cycle %d\n", 93 __FUNCTION__ , process->pid , this->trdid, (uint32_t)tm_start ); 97 94 #endif 98 95 this->errno = ENFILE; … … 138 135 139 136 #if DEBUG_SYSCALLS_ERROR 140 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 141 printk("\n[ERROR] in %s : thread[%x,%x] / cannot found directory <%s>\n", 142 __FUNCTION__ , process->pid , this->trdid , kbuf ); 137 printk("\n[ERROR] in %s : thread[%x,%x] / cannot found directory <%s> / cycle %d\n", 138 __FUNCTION__ , process->pid , this->trdid , kbuf , (uint32_t)tm_start ); 143 139 #endif 144 140 this->errno = ENFILE; … … 155 151 156 152 #if DEBUG_SYSCALLS_ERROR 157 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 158 printk("\n[ERROR] in %s : thread[%x,%x] / <%s> is not a directory\n", 159 __FUNCTION__ , process->pid , this->trdid , kbuf ); 153 printk("\n[ERROR] in %s : thread[%x,%x] / <%s> is not a directory / cycle %d\n", 154 __FUNCTION__ , process->pid , this->trdid , kbuf , (uint32_t)tm_start ); 160 155 #endif 161 156 this->errno = ENFILE; … … 163 158 } 164 159 165 // create a new user_dir_t structure in target directory inode cluster160 // create an user_dir_t structure in cluster containing directory inode 166 161 // map it in the reference user process VMM (in a new ANON vseg) 167 162 // an get the local pointer on the created user_dir_t structure … … 183 178 184 179 #if DEBUG_SYSCALLS_ERROR 185 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 186 printk("\n[ERROR] in %s : thread[%x,%x] / cannot create user_dir for <%s>\n", 187 __FUNCTION__ , process->pid , this->trdid , kbuf ); 180 printk("\n[ERROR] in %s : thread[%x,%x] / cannot create user_dir for <%s> / cycle %d\n", 181 __FUNCTION__ , process->pid , this->trdid , kbuf , (uint32_t)tm_start ); 188 182 #endif 189 183 this->errno = ENFILE; -
trunk/kernel/syscalls/sys_pipe.c
r670 r683 36 36 { 37 37 vseg_t * vseg; 38 kmem_req_t req;39 38 pipe_t * pipe; 40 39 vfs_file_t * file_0; … … 88 87 // 2. allocate memory for fd[0] file descriptor in local cluster 89 88 // we don't use the vfs_file_create function because there is no inode. 90 req.type = KMEM_KCM; 91 req.order = bits_log2( sizeof(vfs_file_t) ); 92 req.flags = AF_ZERO; 93 file_0 = kmem_alloc( &req ); 89 file_0 = kmem_alloc( bits_log2(sizeof(vfs_file_t)) , AF_ZERO ); 94 90 95 91 if( file_0 == NULL ) … … 120 116 121 117 // 4. allocate memory for fd[1] file descriptor in local cluster 122 req.type = KMEM_KCM; 123 req.order = bits_log2( sizeof(vfs_file_t) ); 124 req.flags = AF_ZERO; 125 file_1 = kmem_alloc( &req ); 118 // we don't use the vfs_file_create function because there is no inode. 119 file_1 = kmem_alloc( bits_log2(sizeof(vfs_file_t)) , AF_ZERO ); 126 120 127 121 if( file_1 == NULL ) … … 178 172 error_5: // release memory allocated for fd[1] file descriptor 179 173 180 req.ptr = file_1; 181 kmem_free( &req ); 174 kmem_free( file_1 , bits_log2(sizeof(vfs_file_t)) ); 182 175 183 176 error_4: // release fdid_0 from fd_array[] … … 187 180 error_3: // release memory allocated for fd[0] file descriptor 188 181 189 req.ptr = file_0; 190 kmem_free( &req ); 182 kmem_free( file_0 , bits_log2(sizeof(vfs_file_t)) ); 191 183 192 184 error_2: // release memory allocated for the pipe -
trunk/kernel/syscalls/sys_place_fork.c
r670 r683 55 55 56 56 #if DEBUG_SYSCALLS_ERROR 57 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) ;57 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 58 58 printk("\n[ERROR] in %s : thread[%x,‰x] / illegal cxy argument %x\n", 59 59 __FUNCTION__ , process->pid , this->trdid , cxy ); -
trunk/kernel/syscalls/sys_socket.c
r670 r683 45 45 46 46 #if DEBUG_SYS_SOCKET 47 static char* socket_ cmd_type_str( uint32_t type )47 static char* socket_user_cmd_str( uint32_t type ) 48 48 { 49 49 if ( type == SOCK_CREATE ) return "CREATE"; … … 54 54 else if( type == SOCK_SEND ) return "SEND"; 55 55 else if( type == SOCK_RECV ) return "RECV"; 56 else if( type == SOCK_SENDTO ) return "SENDTO"; 57 else if( type == SOCK_RECVFROM ) return "RECVFROM"; 56 58 else return "undefined"; 57 59 } … … 79 81 80 82 #if DEBUG_SYS_SOCKET 83 char kbuf[64]; 81 84 if( DEBUG_SYS_SOCKET < (uint32_t)tm_start ) 82 printk("\n[%s] thread[%x,%x] enter /%s / a1 %x / a2 %x / a3 %x / cycle %d\n",83 __FUNCTION__, process->pid, this->trdid, socket_ cmd_type_str(cmd),85 printk("\n[%s] thread[%x,%x] enter for %s / a1 %x / a2 %x / a3 %x / cycle %d\n", 86 __FUNCTION__, process->pid, this->trdid, socket_user_cmd_str(cmd), 84 87 arg1, arg2, arg3, (uint32_t)tm_start ); 85 88 #endif … … 97 100 98 101 #if DEBUG_SYSCALLS_ERROR 99 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 100 printk("\n[ERROR] in %s : thread[%x,%x] / CREATE / domain %d =! AF_INET\n", 101 __FUNCTION__ , process->pid , this->trdid , domain ); 102 printk("\n[ERROR] in %s : thread[%x,%x] / CREATE / domain %d =! AF_INET / cycle %d\n", 103 __FUNCTION__ , process->pid , this->trdid , domain , (uint32_t)tm_start ); 102 104 #endif 103 105 this->errno = EINVAL; … … 110 112 111 113 #if DEBUG_SYSCALLS_ERROR 112 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 113 printk("\n[ERROR] in %s : thread[%x,%x] / CREATE / illegal socket type\n", 114 __FUNCTION__ , process->pid , this->trdid ); 114 printk("\n[ERROR] in %s : thread[%x,%x] / CREATE / illegal socket type / cycle %d\n", 115 __FUNCTION__ , process->pid , this->trdid , (uint32_t)tm_start); 115 116 #endif 116 117 this->errno = EINVAL; … … 126 127 127 128 #if DEBUG_SYSCALLS_ERROR 128 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 129 printk("\n[ERROR] in %s : thread[%x,%x] / CREATE / cannot create socket\n", 130 __FUNCTION__ , process->pid , this->trdid ); 129 printk("\n[ERROR] in %s : thread[%x,%x] / CREATE / cannot create socket / cycle %d\n", 130 __FUNCTION__ , process->pid , this->trdid , (uint32_t)tm_start); 131 131 #endif 132 132 this->errno = EINVAL; … … 148 148 149 149 #if DEBUG_SYSCALLS_ERROR 150 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 151 printk("\n[ERROR] in %s : thread[%x,%x] / BIND / socket address %x unmapped\n", 152 __FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 ); 150 printk("\n[ERROR] in %s : thread[%x,%x] / BIND / socket address %x unmapped / cycle %d\n", 151 __FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 , (uint32_t)tm_start ); 153 152 #endif 154 153 this->errno = EINVAL; … … 171 170 172 171 #if DEBUG_SYSCALLS_ERROR 173 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 174 printk("\n[ERROR] in %s : thread[%x,%x] / BIND / cannot access socket[%x,%d]\n", 175 __FUNCTION__ , process->pid , this->trdid , process->pid, fdid ); 172 printk("\n[ERROR] in %s : thread[%x,%x] / BIND / cannot access socket[%x,%d] / cycle %d\n", 173 __FUNCTION__ , process->pid , this->trdid , process->pid, fdid , (uint32_t)tm_start ); 176 174 #endif 177 175 this->errno = EINVAL; … … 195 193 196 194 #if DEBUG_SYSCALLS_ERROR 197 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 198 printk("\n[ERROR] in %s : thread[%x,%x] / LISTEN / cannot access socket[%x,%d]\n", 199 __FUNCTION__ , process->pid , this->trdid , process->pid, fdid ); 195 printk("\n[ERROR] in %s : thread[%x,%x] / LISTEN / cannot access socket[%x,%d] / cycle %d\n", 196 __FUNCTION__ , process->pid , this->trdid , process->pid, fdid , (uint32_t)tm_start ); 200 197 #endif 201 198 this->errno = EINVAL; … … 217 214 218 215 #if DEBUG_SYSCALLS_ERROR 219 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 220 printk("\n[ERROR] in %s : thread[%x,%x] / CONNECT / server address %x unmapped\n", 221 __FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 ); 216 printk("\n[ERROR] in %s : thread[%x,%x] / CONNECT / server address %x unmapped / cycle %d\n", 217 __FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 , (uint32_t)tm_start ); 222 218 #endif 223 219 this->errno = EINVAL; … … 239 235 240 236 #if DEBUG_SYSCALLS_ERROR 241 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 242 printk("\n[ERROR] in %s : thread[%x,%x] / LISTEN / cannot access socket[%x,%d]\n", 243 __FUNCTION__ , process->pid , this->trdid , process->pid, fdid ); 237 printk("\n[ERROR] in %s : thread[%x,%x] / LISTEN / cannot access socket[%x,%d] / cycle %d\n", 238 __FUNCTION__ , process->pid , this->trdid , process->pid, fdid , (uint32_t)tm_start ); 244 239 #endif 245 240 this->errno = EINVAL; … … 261 256 262 257 #if DEBUG_SYSCALLS_ERROR 263 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 264 printk("\n[ERROR] in %s : thread[%x,%x] / CONNECT / server address %x unmapped\n", 265 __FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 ); 258 printk("\n[ERROR] in %s : thread[%x,%x] / CONNECT / server address %x unmapped / cycle %d\n", 259 __FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 , (uint32_t)tm_start ); 266 260 #endif 267 261 this->errno = EINVAL; … … 275 269 &k_sockaddr.sin_port ); 276 270 277 if( ret ) 278 { 279 280 #if DEBUG_SYSCALLS_ERROR 281 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 282 printk("\n[ERROR] in %s : thread[%x,%x] / ACCEPT / cannot access socket[%x,%d]\n", 283 __FUNCTION__ , process->pid , this->trdid , process->pid, fdid ); 271 if( ret < 0 ) 272 { 273 274 #if DEBUG_SYSCALLS_ERROR 275 printk("\n[ERROR] in %s : thread[%x,%x] / ACCEPT / cannot access socket[%x,%d] / cycle %d\n", 276 __FUNCTION__ , process->pid , this->trdid , process->pid, fdid , (uint32_t)tm_start ); 284 277 #endif 285 278 this->errno = EINVAL; … … 305 298 306 299 #if DEBUG_SYSCALLS_ERROR 307 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 308 printk("\n[ERROR] in %s : thread[%x,%x] / SEND / buffer %x unmapped\n", 309 __FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 ); 310 #endif 311 this->errno = EINVAL; 312 ret = -1; 313 break; 314 } 315 316 // check length 317 if( length == 0 ) 318 { 319 320 #if DEBUG_SYSCALLS_ERROR 321 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 322 printk("\n[ERROR] in %s : thread[%x,%x] / SEND / buffer length is 0\n", 323 __FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 ); 324 #endif 325 this->errno = EINVAL; 326 ret = -1; 327 break; 328 } 329 330 // cal relevant relevant socket function 331 ret = socket_send( fdid , u_buf , length ); 332 333 if( ret < 0 ) 334 { 335 336 #if DEBUG_SYSCALLS_ERROR 337 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 338 printk("\n[ERROR] in %s : thread[%x,%x] / SEND / cannot access socket[%x,%d] \n", 339 __FUNCTION__ , process->pid , this->trdid , process->pid, fdid ); 340 #endif 341 this->errno = EINVAL; 342 } 300 printk("\n[ERROR] in %s : thread[%x,%x] / SEND / u_buf %x unmapped / cycle %d\n", 301 __FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 , (uint32_t)tm_start ); 302 #endif 303 this->errno = EINVAL; 304 ret = -1; 305 break; 306 } 307 308 // check length argument 309 if( (length == 0) || (length > (1<<CONFIG_SOCK_TX_BUF_ORDER)) ) 310 { 311 312 #if DEBUG_SYSCALLS_ERROR 313 printk("\n[ERROR] in %s : thread[%x,%x] / SEND / bad buffer length %d / cycle %d\n", 314 __FUNCTION__ , process->pid , this->trdid , length , (uint32_t)tm_start ); 315 #endif 316 this->errno = EINVAL; 317 ret = -1; 318 break; 319 } 320 321 // cal relevant socket function 322 ret = socket_send( fdid, 323 u_buf, 324 length ); 325 if( ret < 0 ) 326 { 327 328 #if DEBUG_SYSCALLS_ERROR 329 printk("\n[ERROR] in %s : thread[%x,%x] / SEND / cannot access socket[%x,%d] / cycle %d\n", 330 __FUNCTION__ , process->pid , this->trdid , process->pid, fdid , (uint32_t)tm_start ); 331 #endif 332 this->errno = EINVAL; 333 } 334 335 #if DEBUG_SYS_SOCKET 336 if( DEBUG_SYS_SOCKET < (uint32_t)tm_start ) 337 { 338 hal_copy_from_uspace( XPTR( local_cxy , &kbuf ) , u_buf , ret ); 339 printk("\n[%s] thread[%x,%x] send %d bytes <%s>\n", 340 __FUNCTION__, process->pid, this->trdid , ret, kbuf ); 341 } 342 #endif 343 343 break; 344 344 } … … 355 355 356 356 #if DEBUG_SYSCALLS_ERROR 357 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 358 printk("\n[ERROR] in %s : thread[%x,%x] / RECV / buffer %x unmapped\n", 359 __FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 ); 360 #endif 361 this->errno = EINVAL; 362 ret = -1; 363 break; 364 } 365 366 // check length 367 if( length == 0 ) 368 { 369 370 #if DEBUG_SYSCALLS_ERROR 371 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 372 printk("\n[ERROR] in %s : thread[%x,%x] / RECV / buffer length is 0\n", 373 __FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 ); 357 printk("\n[ERROR] in %s : thread[%x,%x] / RECV / u_buf %x unmapped / cycle %d\n", 358 __FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 , (uint32_t)tm_start ); 359 #endif 360 this->errno = EINVAL; 361 ret = -1; 362 break; 363 } 364 365 // check length argument 366 if( (length == 0) || (length > (1<<CONFIG_SOCK_RX_BUF_ORDER)) ) 367 { 368 369 #if DEBUG_SYSCALLS_ERROR 370 printk("\n[ERROR] in %s : thread[%x,%x] / RECV / bad buffer length %d / cycle %d\n", 371 __FUNCTION__ , process->pid , this->trdid , length , (uint32_t)tm_start ); 374 372 #endif 375 373 this->errno = EINVAL; … … 379 377 380 378 // cal relevant kernel socket function 381 ret = socket_recv( fdid , u_buf , length ); 382 383 if( ret < 0 ) 384 { 385 386 #if DEBUG_SYSCALLS_ERROR 387 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 388 printk("\n[ERROR] in %s : thread[%x,%x] / RECV / cannot access socket[%x,%d] \n", 389 __FUNCTION__ , process->pid , this->trdid , process->pid, fdid ); 390 #endif 391 this->errno = EINVAL; 392 } 379 ret = socket_recv( fdid, 380 u_buf, 381 length ); 382 if( ret < 0 ) 383 { 384 385 #if DEBUG_SYSCALLS_ERROR 386 printk("\n[ERROR] in %s : thread[%x,%x] / RECV / cannot access socket[%x,%d] / cycle %d\n", 387 __FUNCTION__ , process->pid , this->trdid , process->pid, fdid , (uint32_t)tm_start ); 388 #endif 389 this->errno = EINVAL; 390 } 391 392 #if DEBUG_SYS_SOCKET 393 if( DEBUG_SYS_SOCKET < (uint32_t)tm_start ) 394 { 395 hal_copy_from_uspace( XPTR( local_cxy , &kbuf ) , u_buf , ret ); 396 printk("\n[%s] thread[%x,%x] received %d bytes <%s>\n", 397 __FUNCTION__, process->pid, this->trdid , ret, kbuf ); 398 } 399 #endif 400 break; 401 } 402 ///////////////// 403 case SOCK_SENDTO: 404 { 405 sockaddr_in_t k_remote_addr; 406 407 uint32_t fdid = (uint32_t)arg1 & 0x0000FFFF; 408 uint32_t length = (uint32_t)arg1 >> 16; 409 uint8_t * u_buf = (uint8_t *)(intptr_t)arg2; 410 sockaddr_t * u_remote_addr = (sockaddr_t *)(intptr_t)arg3; 411 412 // check u_buf mapped in user space 413 if( vmm_get_vseg( process , (intptr_t)arg2 , &vseg ) ) 414 { 415 416 #if DEBUG_SYSCALLS_ERROR 417 printk("\n[ERROR] in %s : thread[%x,%x] / SENDTO / u_buf %x unmapped / cycle %d\n", 418 __FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 , (uint32_t)tm_start ); 419 #endif 420 this->errno = EINVAL; 421 ret = -1; 422 break; 423 } 424 425 // check u_remote_addr mapped in user space 426 if( vmm_get_vseg( process , (intptr_t)arg3 , &vseg ) ) 427 { 428 429 #if DEBUG_SYSCALLS_ERROR 430 printk("\n[ERROR] in %s : thread[%x,%x] / SENDTO / u_remote_addr %x unmapped / cycle %d\n", 431 __FUNCTION__ , process->pid , this->trdid , (intptr_t)arg3 , (uint32_t)tm_start ); 432 #endif 433 this->errno = EINVAL; 434 ret = -1; 435 break; 436 } 437 438 // check length argument 439 if( (length == 0) || (length > (1<<CONFIG_SOCK_TX_BUF_ORDER)) ) 440 { 441 442 #if DEBUG_SYSCALLS_ERROR 443 printk("\n[ERROR] in %s : thread[%x,%x] / SENDTO / bad length %d / cycle %d\n", 444 __FUNCTION__ , process->pid , this->trdid , length , (uint32_t)tm_start ); 445 #endif 446 this->errno = EINVAL; 447 ret = -1; 448 break; 449 } 450 451 // make a kernel copy of the sockaddr_t structure 452 hal_copy_from_uspace( XPTR( local_cxy , &k_remote_addr ), 453 u_remote_addr, sizeof(sockaddr_t) ); 454 455 // cal relevant socket function 456 ret = socket_sendto( fdid, 457 u_buf, 458 length, 459 k_remote_addr.sin_addr, 460 k_remote_addr.sin_port ); 461 if( ret < 0 ) 462 { 463 464 #if DEBUG_SYSCALLS_ERROR 465 printk("\n[ERROR] in %s : thread[%x,%x] / SENDTO / cannot access socket[%x,%d] / cycle %d\n", 466 __FUNCTION__ , process->pid , this->trdid , process->pid, fdid , (uint32_t)tm_start ); 467 #endif 468 this->errno = EINVAL; 469 } 470 471 break; 472 } 473 /////////////////// 474 case SOCK_RECVFROM: 475 { 476 sockaddr_in_t k_remote_addr; 477 478 uint32_t fdid = (uint32_t)arg1 & 0x0000FFFF; 479 uint32_t length = (uint32_t)arg1 >> 16; 480 uint8_t * u_buf = (uint8_t *)(intptr_t)arg2; 481 sockaddr_t * u_remote_addr = (sockaddr_t *)(intptr_t)arg3; 482 483 // check buffer is mapped in user space 484 if( vmm_get_vseg( process , (intptr_t)arg2 , &vseg ) ) 485 { 486 487 #if DEBUG_SYSCALLS_ERROR 488 printk("\n[ERROR] in %s : thread[%x,%x] / RECVFROM / u_buf %x unmapped / cycle %d\n", 489 __FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 , (uint32_t)tm_start ); 490 #endif 491 this->errno = EINVAL; 492 ret = -1; 493 break; 494 } 495 496 // check u_remote_addr mapped in user space 497 if( vmm_get_vseg( process , (intptr_t)arg3 , &vseg ) ) 498 { 499 500 #if DEBUG_SYSCALLS_ERROR 501 printk("\n[ERROR] in %s : thread[%x,%x] / RECVFROM / u_remote_addr %x unmapped / cycle %d\n", 502 __FUNCTION__ , process->pid , this->trdid , (intptr_t)arg3 , (uint32_t)tm_start ); 503 #endif 504 this->errno = EINVAL; 505 ret = -1; 506 break; 507 } 508 509 // check length argument 510 if( (length == 0) || (length > (1<<CONFIG_SOCK_RX_BUF_ORDER)) ) 511 { 512 513 #if DEBUG_SYSCALLS_ERROR 514 printk("\n[ERROR] in %s : thread[%x,%x] / RECVFROM / bad length %d / cycle %d\n", 515 __FUNCTION__ , process->pid , this->trdid , length , (uint32_t)tm_start ); 516 #endif 517 this->errno = EINVAL; 518 ret = -1; 519 break; 520 } 521 522 // make a kernel copy of the sockaddr_t structure 523 hal_copy_from_uspace( XPTR( local_cxy , &k_remote_addr ), 524 u_remote_addr, sizeof(sockaddr_t) ); 525 526 // cal relevant socket function 527 ret = socket_recvfrom( fdid, 528 u_buf, 529 length, 530 k_remote_addr.sin_addr, 531 k_remote_addr.sin_port ); 532 if( ret < 0 ) 533 { 534 535 #if DEBUG_SYSCALLS_ERROR 536 printk("\n[ERROR] in %s : thread[%x,%x] / RECVFROM / cannot access socket[%x,%d] / cycle %d\n", 537 __FUNCTION__ , process->pid , this->trdid , process->pid, fdid , (uint32_t)tm_start ); 538 #endif 539 this->errno = EINVAL; 540 } 541 393 542 break; 394 543 } … … 398 547 399 548 #if DEBUG_SYSCALLS_ERROR 400 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 401 printk("\n[ERROR] in %s : thread[%x,%x] / undefined socket operation %d\n", 402 __FUNCTION__ , process->pid , this->trdid , cmd ); 549 printk("\n[ERROR] in %s : thread[%x,%x] / undefined socket operation %d / cycle %d\n", 550 __FUNCTION__ , process->pid , this->trdid , cmd , (uint32_t)tm_start ); 403 551 #endif 404 552 this->errno = EINVAL; … … 413 561 414 562 #if DEBUG_SYS_SOCKET 415 if( DEBUG_SYS_SOCKET < tm_end ) 416 printk("\n[%s] thread[%x,%x] exit / cycle %d\n", 417 __FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end ); 563 printk("\n[%s] thread[%x,%x] exit for %s / cycle %d\n", 564 __FUNCTION__, process->pid, this->trdid, socket_user_cmd_str(cmd), (uint32_t)tm_end ); 418 565 #endif 419 566 -
trunk/kernel/syscalls/sys_thread_exit.c
r670 r683 2 2 * sys_thread_exit.c - terminates the execution of calling thread 3 3 * 4 * Authors Alain Greiner (2016,2017,2018,2019 )4 * Authors Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 44 44 pid_t pid = process->pid; 45 45 46 #if DEBUG_SYS_THREAD_EXIT || DEBUG_SYSCALLS_ERROR 47 uint64_t tm_start = hal_get_cycles(); 48 #endif 49 46 50 // check exit_value pointer in user space if required 47 51 if( exit_status != NULL ) … … 53 57 54 58 #if DEBUG_SYSCALLS_ERROR 55 printk("\n[ERROR] in %s : exit_status buffer %x unmapped / thread[%x,%x]\n", 56 __FUNCTION__, (intptr_t)exit_status, process->pid, this->trdid ); 59 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 60 printk("\n[WARNING] in %s : exit_status buffer %x unmapped / thread[%x,%x]\n", 61 __FUNCTION__, (intptr_t)exit_status, pid, trdid ); 57 62 #endif 58 63 this->errno = EINVAL; … … 67 72 68 73 #if DEBUG_SYSCALLS_ERROR 69 printk("\n[ERROR] in %s : busylocks count = %d / thread[%x,%x]\n", 70 __FUNCTION__ , count, process->pid, this->trdid ); 74 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 75 printk("\n[WARNING] in %s : busylocks count = %d / thread[%x,%x]\n", 76 __FUNCTION__ , count, pid, trdid ); 71 77 #endif 72 78 this->errno = EINVAL; … … 84 90 85 91 #if DEBUG_SYS_THREAD_EXIT 86 uint64_t tm_start = hal_get_cycles(); 87 if( DEBUG_SYS_THREAD_EXIT < tm_start ) 92 if( DEBUG_SYS_THREAD_EXIT < (uint32_t)tm_start ) 88 93 printk("\n[%s] thread[%x,%x] is main => delete process / cycle %d\n", 89 94 __FUNCTION__ , pid , trdid , (uint32_t)tm_start ); … … 96 101 97 102 #if DEBUG_SYS_THREAD_EXIT 98 uint64_t tm_start = hal_get_cycles(); 99 if( DEBUG_SYS_THREAD_EXIT < tm_start ) 103 if( DEBUG_SYS_THREAD_EXIT < (uint32_t)tm_start ) 100 104 printk("\n[%s] thread[%x,%x] is not main => delete thread / cycle %d\n", 101 105 __FUNCTION__ , pid , trdid , (uint32_t)tm_start ); -
trunk/kernel/syscalls/sys_thread_sleep.c
r566 r683 1 1 /* 2 * sys_thread_sleep.c - put the calling thread in sleep state2 * sys_thread_sleep.c - block the calling thread on SLEEP, with or without alarm 3 3 * 4 * Author Alain Greiner (2016,2017)4 * Author Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 28 28 #include <syscalls.h> 29 29 30 ////////////////////// 31 int sys_thread_sleep( void ) 30 /////////////////////////////////////////////////////////////////////////////////////// 31 // This static function implements the alarm handler used to wake-up a thread 32 // when the amarm rings after after a sleep( seconds ) syscall. 33 /////////////////////////////////////////////////////////////////////////////////////// 34 // @ thread_xp : extended pointer on blocked thread. 35 /////////////////////////////////////////////////////////////////////////////////////// 36 static void __attribute__((noinline)) sleep_alarm_handler( xptr_t thread_xp ) 32 37 { 38 // stop the alarm 39 alarm_stop( thread_xp ); 33 40 34 thread_t * this = CURRENT_THREAD; 41 // unblock the thread 42 thread_unblock( thread_xp , THREAD_BLOCKED_SLEEP ); 43 44 } // end sleep_alarm_handler() 45 46 //////////////////////////////////////// 47 int sys_thread_sleep( uint32_t seconds ) 48 { 49 cycle_t ncycles; // number of cycles to sleep 50 51 thread_t * this = CURRENT_THREAD; 52 xptr_t thread_xp = XPTR( local_cxy , this ); 53 54 cycle_t tm_start = hal_get_cycles(); 35 55 36 56 #if DEBUG_SYS_THREAD_SLEEP 37 uint64_t tm_start; 38 uint64_t tm_end; 39 tm_start = hal_get_cycles(); 40 if( DEBUG_SYS_THREAD_SLEEP < tm_start ) 41 printk("\n[DBG] %s : thread %x n process %x blocked / cycle %d\n", 42 __FUNCTION__ , this->trdid, this->process->pid , (uint32_t)tm_start ); 57 if( DEBUG_SYS_THREAD_SLEEP < (uint32_t)tm_start ) 58 printk("\n[%s] thread[%x,%x] enter / cycle %d\n", 59 __FUNCTION__, this->process->pid, this->trdid, (uint32_t)tm_start ); 43 60 #endif 44 61 45 thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_GLOBAL ); 46 sched_yield("blocked on sleep"); 62 if( seconds == 0 ) // sleep without alarm 63 { 64 65 #if DEBUG_SYS_THREAD_SLEEP 66 if( DEBUG_SYS_THREAD_SLEEP < tm_start ) 67 printk("\n[%s] thread[%x,%x] blocks on <SLEEP> without alarm / cycle %d\n", 68 __FUNCTION__ , this->process->pid, this->trdid, (uint32_t)tm_start ); 69 #endif 70 // threads blocks and deschedules 71 thread_block( thread_xp , THREAD_BLOCKED_SLEEP ); 72 sched_yield("sleep without alarm"); 73 } 74 else // sleep with alarm 75 { 76 // translate seconds to ncycles 77 ncycles = seconds * LOCAL_CLUSTER->sys_clk; 78 79 // register & start the calling thread alarm 80 alarm_start( thread_xp, 81 tm_start + ncycles, 82 &sleep_alarm_handler, 83 thread_xp ); 84 85 #if DEBUG_SYS_THREAD_SLEEP 86 if( DEBUG_SYS_THREAD_SLEEP < tm_start ) 87 printk("\n[DBG] %s : thread[%x,%x] blocks on <SLEEP> for %d seconds / cycle %d\n", 88 __FUNCTION__ , this->process->pid, this->trdid, seconds, (uint32_t)tm_start ); 89 #endif 90 // thread blocks & deschedules 91 thread_block( thread_xp , THREAD_BLOCKED_SLEEP ); 92 sched_yield("sleep with alarm"); 93 } 47 94 48 95 #if DEBUG_SYS_THREAD_SLEEP 49 tm_end = hal_get_cycles();50 96 if( DEBUG_SYS_THREAD_SLEEP < tm_end ) 51 printk("\n[ DBG] %s : thread %x in process %xresume / cycle %d\n",52 __FUNCTION__ , this-> trdid, this->process->pid, (uint32_t)tm_end );97 printk("\n[%s] thread[%x,%x] resume / cycle %d\n", 98 __FUNCTION__ , this->process->pid, this->trdid, (uint32_t)tm_end ); 53 99 #endif 54 100 -
trunk/kernel/syscalls/sys_thread_wakeup.c
r637 r683 1 1 /* 2 * sys_thread_wakeup.c - wakeup indicated thread2 * sys_thread_wakeup.c - unblock indicated thread from the SLEEP condition 3 3 * 4 * Author Alain Greiner (2016,2017,2018,2019)4 * Author Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 27 27 #include <process.h> 28 28 #include <errno.h> 29 30 29 #include <syscalls.h> 31 30 … … 36 35 process_t * process = this->process; 37 36 38 #if (DEBUG_SYS_THREAD_WAKEUP || CONFIG_INSTRUMENTATION_SYSCALLS)39 uint64_ttm_start = hal_get_cycles();37 #if DEBUG_SYS_THREAD_WAKEUP || DEBUG_SYSCALLS_ERROR || CONFIG_INTRUMENTATION_SYSCALLS 38 cycle_t tm_start = hal_get_cycles(); 40 39 #endif 41 40 42 41 #if DEBUG_SYS_THREAD_WAKEUP 43 if( DEBUG_SYS_THREAD_WAKEUP < tm_start )44 printk("\n[%s] thread %x in processenter to activate thread %x / cycle %d\n",45 __FUNCTION__, this->trdid, process->pid, trdid, (uint32_t)tm_start );42 if( DEBUG_SYS_THREAD_WAKEUP < (uint32_t)tm_start ) 43 printk("\n[%s] thread[%x,%x] enter to activate thread %x / cycle %d\n", 44 __FUNCTION__, process->pid, this->trdid, trdid, (uint32_t)tm_start ); 46 45 #endif 47 46 … … 56 55 57 56 #if DEBUG_SYSCALLS_ERROR 58 printk("\n[ERROR] in %s : thread %x in process %x / illegal trdid argument %x\n", 59 __FUNCTION__, this->trdid, process->pid, trdid ); 57 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 58 printk("\n[ERROR] in %s : thread[%x,%x] / illegal trdid argument %x\n", 59 __FUNCTION__, process->pid, this->trdid, trdid ); 60 60 #endif 61 61 this->errno = EINVAL; … … 70 70 71 71 #if DEBUG_SYSCALLS_ERROR 72 printk("\n[ERROR] in %s : thread %x in process %x cannot find thread %x/n", 73 __FUNCTION__ , this->trdid, process->pid, trdid ); 72 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 73 printk("\n[ERROR] in %s : thread[%x,%x] / cannot find thread[%x,%x]\n", 74 __FUNCTION__, process->pid, this->trdid, process->pid, trdid ); 74 75 #endif 75 76 CURRENT_THREAD->errno = EINVAL; … … 77 78 } 78 79 80 // get target thread cluster and local pointer 81 thread_t * tgt_ptr = GET_PTR( thread_xp ); 82 cxy_t tgt_cxy = GET_CXY( thread_xp ); 83 84 // get state of the target thread alarm 85 bool_t linked = hal_remote_l32( XPTR( tgt_cxy , &tgt_ptr->alarm.linked ) ); 86 87 // delete the alarm if active 88 if( linked ) alarm_stop( thread_xp ); 89 79 90 // unblock target thread 80 thread_unblock( thread_xp , THREAD_BLOCKED_ GLOBAL);91 thread_unblock( thread_xp , THREAD_BLOCKED_SLEEP ); 81 92 82 93 #if (DEBUG_SYS_THREAD_WAKEUP || CONFIG_INSTRUMENTATION_SYSCALLS) … … 87 98 #if DEBUG_SYS_THREAD_WAKEUP 88 99 if( DEBUG_SYS_THREAD_WAKEUP < tm_end ) 89 printk("\n[%s] thread %x in process %x exit / thread %xactivated / cycle %d\n",90 __FUNCTION__ , this->trdid, process->pid, trdid, (uint32_t)tm_end );100 printk("\n[%s] thread[%x,%x] exit / thread[%x,%x] activated / cycle %d\n", 101 __FUNCTION__ , process->pid, this->trdid, process->pid, trdid, (uint32_t)tm_end ); 91 102 #endif 92 103 -
trunk/kernel/syscalls/sys_timeofday.c
r637 r683 2 2 * sys_timeofday.c - Get current time 3 3 * 4 * Author Alain Greiner (2016,2017,2018,2019)4 * Author Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 32 32 #include <core.h> 33 33 #include <shared_syscalls.h> 34 35 34 #include <syscalls.h> 36 35 … … 50 49 process_t * process = this->process; 51 50 52 #if (DEBUG_SYS_TIMEOFDAY || CONFIG_INSTRUMENTATION_SYSCALLS)51 #if DEBUG_SYS_TIMEOFDAY || DEBUG_SYSCALLS_ERROR || CONFIG_INSTRUMENTATION_SYSCALLS 53 52 uint64_t tm_start = hal_get_cycles(); 54 53 #endif 55 54 56 55 #if DEBUG_SYS_TIMEOFDAY 57 if( DEBUG_SYS_TIMEOFDAY < tm_start )56 if( DEBUG_SYS_TIMEOFDAY < (uint32_t)tm_start ) 58 57 printk("\n[%s] thread[%x,%x] enter / cycle %d\n", 59 58 __FUNCTION__, process->pid, this->trdid, (uint32_t)tm_start ); … … 65 64 66 65 #if DEBUG_SYSCALLS_ERROR 67 printk("\n[ERROR] in %s for thread %x in process %x : tz argument must be NULL\n", 66 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 67 printk("\n[ERROR] in %s : thread[%x,%x] / tz argument must be NULL\n", 68 68 __FUNCTION__ , this->trdid , process->pid ); 69 69 #endif … … 79 79 80 80 #if DEBUG_SYSCALLS_ERROR 81 printk("\n[ERROR] in %s : user buffer tz unmapped / thread %x / process %x\n", 82 __FUNCTION__ , (intptr_t)tz , this->trdid , process->pid ); 81 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 82 printk("\n[ERROR] in %s : thread[%x,%x] / user buffer tv unmapped\n", 83 __FUNCTION__ , this->trdid , process->pid , (intptr_t)tz ); 83 84 #endif 84 85 this->errno = EINVAL; -
trunk/kernel/syscalls/syscalls.h
r670 r683 38 38 39 39 /****************************************************************************************** 40 * This function forces the calling thread to sleep, for a fixed number of cycles.41 ****************************************************************************************** 42 * cycles : number of cycles.43 *****************************************************************************************/ 44 int sys_alarm( uint32_t cycles );40 * This function forces the calling thread to sleep, for a fixed number of seconds. 41 ****************************************************************************************** 42 * @ seconds : number of seconds. 43 *****************************************************************************************/ 44 int sys_alarm( uint32_t seconds ); 45 45 46 46 /****************************************************************************************** … … 229 229 230 230 /****************************************************************************************** 231 * This generic function implements all the non standard syscalls of type "get_xxx()", 232 * defined in the <almosmkh.h> and <almosmkh.c> files. 233 * The operation types mnemonics are defined in the <shared_almos.h> file. 234 * This function ckecks the syscall arguments, and call the relevant kernel function. 235 ****************************************************************************************** 236 * @ arg0 : operation type (mnemonics defined in shared_get.h) 237 * @ arg1 : depends on operation type 238 * @ arg2 : depends on operation type 239 * @ arg3 : depends on operation type 240 * @ return 0 if success / return -1 if illegal argument. 241 *****************************************************************************************/ 242 int sys_get( reg_t arg0, 243 reg_t arg1, 244 reg_t arg2, 245 reg_t arg3 ); 246 247 /****************************************************************************************** 231 248 * This function implements the non-standard "get_best_core" syscall. 232 249 * It selects, in a macro-cluster specified by the <base_cxy> and <level> arguments, … … 470 487 * as a remote_buffer_t, creates two (read and write) file descriptors, and links these 471 488 * two file descriptors to the pipe. 472 * TODO : the dynamic memory allocation in case of buffer full is not implemented. 489 * TODO : the dynamic memory allocation in case of buffer full is not implemented. 490 * FIXME : wich syscall release the kernel memory allocated by this syscall ? 473 491 ****************************************************************************************** 474 492 * @ fd : pointeur on a 2 slots array of fdid : fd[0] read / fd[1] write. … … 566 584 567 585 /****************************************************************************************** 568 * This generic function implements thesocket related syscalls.586 * This generic function implements all socket related syscalls. 569 587 * The operation types mnemonics are defined in the <shared_socket> file. 570 588 * The supported operations are defined in the <socket.h> & <socket.c> files. … … 686 704 687 705 /****************************************************************************************** 688 * This function block the calling thread on the THREAD_BLOCKED_GLOBAL condition, 689 * and deschedule. 690 ****************************************************************************************** 691 * @ return 0 if success / returns -1 if failure. 692 *****************************************************************************************/ 693 int sys_thread_sleep( void ); 706 * This function blocks the calling thread on the THREAD_BLOCKED_SLEEP condition, 707 * and deschedules. When the <seconds> argument is non-zero, this argument defines 708 * the sleeping time. When it is zero, the sleeping time is unbounded, and the thread 709 * must be unblocked by the sys_thread_wakeup() function 710 ****************************************************************************************** 711 * @ seconds : number of seconds of sleep / No alarm is activated when 0. 712 * @ return 0 if success / returns -1 if failure. 713 *****************************************************************************************/ 714 int sys_thread_sleep( uint32_t seconds ); 694 715 695 716 /****************************************************************************************** 696 717 * This function unblock the thread identified by its <trdid> from the 697 * THREAD_BLOCKED_ GLOBAL condition.718 * THREAD_BLOCKED_SLEEP condition, and cancel the registered alarm if required. 698 719 ****************************************************************************************** 699 720 * @ trdid : target thread identifier. … … 705 726 * This function calls the scheduler for the core running the calling thread. 706 727 ****************************************************************************************** 707 * @ x_size : [out] number of clusters in a row.708 * @ y_size : [out] number of clusters in a column.709 * @ ncores : [out] number of cores per cluster.710 728 * @ return always 0. 711 729 *****************************************************************************************/
Note: See TracChangeset
for help on using the changeset viewer.