Changeset 670 for trunk/kernel/syscalls/sys_socket.c
- Timestamp:
- Nov 19, 2020, 11:45:52 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_socket.c
r664 r670 53 53 else if( type == SOCK_ACCEPT ) return "ACCEPT"; 54 54 else if( type == SOCK_SEND ) return "SEND"; 55 else if( type == SOCK_SENDTO ) return "SENDTO";56 55 else if( type == SOCK_RECV ) return "RECV"; 57 else if( type == SOCK_RECVFROM ) return "RECVFROM";58 56 else return "undefined"; 59 57 } … … 66 64 reg_t arg3 ) 67 65 { 68 69 int32_t ret; 66 int ret; 70 67 vseg_t * vseg; 71 68 … … 77 74 uint32_t cmd = arg0; 78 75 79 #if (DEBUG_SYS_SOCKET || CONFIG_INSTRUMENTATION_SYSCALLS)76 #if DEBUG_SYS_SOCKET || DEBUG_SYSCALLS_ERROR || CONFIG_INSTRUMENTATION_SYSCALLS 80 77 uint64_t tm_start = hal_get_cycles(); 81 78 #endif 82 79 83 80 #if DEBUG_SYS_SOCKET 84 tm_start = hal_get_cycles(); 85 if( DEBUG_SYS_SOCKET < tm_start ) 81 if( DEBUG_SYS_SOCKET < (uint32_t)tm_start ) 86 82 printk("\n[%s] thread[%x,%x] enter / %s / a1 %x / a2 %x / a3 %x / cycle %d\n", 87 83 __FUNCTION__, process->pid, this->trdid, socket_cmd_type_str(cmd), … … 101 97 102 98 #if DEBUG_SYSCALLS_ERROR 103 printk("\n[ERROR] in %s for CREATE domain %d =! AF_INET\n", 104 __FUNCTION__ , domain ); 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 ); 105 102 #endif 106 103 this->errno = EINVAL; … … 113 110 114 111 #if DEBUG_SYSCALLS_ERROR 115 printk("\n[ERROR] in %s for CREATE : socket must be SOCK_STREAM(TCP) or SOCK_DGRAM(UDP)\n", 116 __FUNCTION__ ); 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 ); 117 115 #endif 118 116 this->errno = EINVAL; … … 124 122 ret = socket_build( domain , type ); 125 123 126 if( ret == -1 ) 127 { 128 129 #if DEBUG_SYSCALLS_ERROR 130 printk("\n[ERROR] in %s for CREATE : cannot create socket\n", 131 __FUNCTION__ ); 132 #endif 133 this->errno = EINVAL; 134 } 124 if( ret < 0 ) 125 { 126 127 #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 ); 131 #endif 132 this->errno = EINVAL; 133 ret = -1; 134 break; 135 } 136 135 137 break; 136 138 } … … 146 148 147 149 #if DEBUG_SYSCALLS_ERROR 148 printk("\n[ERROR] in %s for BIND : address %x unmapped\n", 149 __FUNCTION__ , (intptr_t)arg2 ); 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 153 #endif 151 154 this->errno = EINVAL; … … 164 167 k_sockaddr.sin_port ); 165 168 166 if( ret ) 167 { 168 169 #if DEBUG_SYSCALLS_ERROR 170 printk("\n[ERROR] in %s for BIND : cannot access socket[%x,%d]\n", 171 __FUNCTION__ , process->pid, fdid ); 172 #endif 173 this->errno = EINVAL; 174 } 169 if( ret < 0 ) 170 { 171 172 #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 ); 176 #endif 177 this->errno = EINVAL; 178 ret = -1; 179 break; 180 } 181 175 182 break; 176 183 } … … 184 191 ret = socket_listen( fdid , max_pending ); 185 192 186 if( ret ) 187 { 188 189 #if DEBUG_SYSCALLS_ERROR 190 printk("\n[ERROR] in %s for LISTEN : cannot access socket[%x,%d]\n", 191 __FUNCTION__ , process->pid, fdid ); 192 #endif 193 this->errno = EINVAL; 194 } 193 if( ret < 0 ) 194 { 195 196 #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 ); 200 #endif 201 this->errno = EINVAL; 202 ret = -1; 203 break; 204 } 205 195 206 break; 196 207 } … … 206 217 207 218 #if DEBUG_SYSCALLS_ERROR 208 printk("\n[ERROR] in %s for CONNECT : server address %x unmapped\n", 209 __FUNCTION__ , (intptr_t)arg2 ); 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 ); 210 222 #endif 211 223 this->errno = EINVAL; … … 223 235 k_sockaddr.sin_addr, 224 236 k_sockaddr.sin_port ); 225 226 if( ret ) 227 { 228 229 #if DEBUG_SYSCALLS_ERROR 230 printk("\n[ERROR] in %s for CONNECT : cannot access socket[%x,%d]\n", 231 __FUNCTION__ , process->pid, fdid ); 232 #endif 233 this->errno = EINVAL; 234 } 237 if( ret < 0 ) 238 { 239 240 #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 ); 244 #endif 245 this->errno = EINVAL; 246 ret = -1; 247 break; 248 } 249 235 250 break; 236 251 } … … 246 261 247 262 #if DEBUG_SYSCALLS_ERROR 248 printk("\n[ERROR] in %s for CONNECT : server address %x unmapped\n", 249 __FUNCTION__ , (intptr_t)arg2 ); 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 ); 250 266 #endif 251 267 this->errno = EINVAL; … … 259 275 &k_sockaddr.sin_port ); 260 276 261 if( ret < 0 ) 262 { 263 264 #if DEBUG_SYSCALLS_ERROR 265 printk("\n[ERROR] in %s for ACCEPT : cannot access socket[%x,%d]\n", 266 __FUNCTION__ , process->pid, fdid ); 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 ); 267 284 #endif 268 285 this->errno = EINVAL; … … 288 305 289 306 #if DEBUG_SYSCALLS_ERROR 290 printk("\n[ERROR] in %s for SEND : buffer %x unmapped\n", 291 __FUNCTION__ , (intptr_t)arg2 ); 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 ); 292 310 #endif 293 311 this->errno = EINVAL; … … 301 319 302 320 #if DEBUG_SYSCALLS_ERROR 303 printk("\n[ERROR] in %s for SEND : buffer length is 0\n", 304 __FUNCTION__ , (intptr_t)arg2 ); 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 ); 305 324 #endif 306 325 this->errno = EINVAL; … … 316 335 317 336 #if DEBUG_SYSCALLS_ERROR 318 printk("\n[ERROR] in %s for SEND : cannot access socket[%x,%d] \n", 319 __FUNCTION__ , process->pid, fdid ); 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 ); 320 340 #endif 321 341 this->errno = EINVAL; … … 335 355 336 356 #if DEBUG_SYSCALLS_ERROR 337 printk("\n[ERROR] in %s for SEND : buffer %x unmapped\n", 338 __FUNCTION__ , (intptr_t)arg2 ); 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 ); 339 360 #endif 340 361 this->errno = EINVAL; … … 348 369 349 370 #if DEBUG_SYSCALLS_ERROR 350 printk("\n[ERROR] in %s for SEND : buffer length is 0\n", 351 __FUNCTION__ , (intptr_t)arg2 ); 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 ); 352 374 #endif 353 375 this->errno = EINVAL; … … 363 385 364 386 #if DEBUG_SYSCALLS_ERROR 365 printk("\n[ERROR] in %s for RECV : cannot access socket[%x,%d] \n", 366 __FUNCTION__ , process->pid, fdid ); 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 ); 367 390 #endif 368 391 this->errno = EINVAL; … … 375 398 376 399 #if DEBUG_SYSCALLS_ERROR 377 printk("\n[ERROR] in %s : undefined socket operation %d\n", 378 __FUNCTION__ , cmd ); 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 ); 379 403 #endif 380 404 this->errno = EINVAL;
Note: See TracChangeset
for help on using the changeset viewer.