Ignore:
Timestamp:
Nov 19, 2020, 11:45:52 PM (3 years ago)
Author:
alain
Message:

1) Introduce up to 4 command lines arguments in the KSH "load" command.
These arguments are transfered to the user process through the
argc/argv mechanism, using the user space "args" vseg.

2) Introduce the named and anonymous "pipes", for inter-process communication
through the pipe() and mkfifo() syscalls.

3) Introduce the "chat" application to validate the two above mechanisms.

4) Improve printk() and assert() fonctions in printk.c.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/sys_socket.c

    r664 r670  
    5353    else if( type == SOCK_ACCEPT      ) return "ACCEPT";
    5454    else if( type == SOCK_SEND        ) return "SEND";
    55     else if( type == SOCK_SENDTO      ) return "SENDTO";
    5655    else if( type == SOCK_RECV        ) return "RECV";
    57     else if( type == SOCK_RECVFROM    ) return "RECVFROM";
    5856    else                                return "undefined";
    5957}
     
    6664                reg_t  arg3 )
    6765{
    68 
    69     int32_t         ret;
     66    int             ret;
    7067    vseg_t        * vseg;
    7168
     
    7774    uint32_t        cmd = arg0;
    7875
    79 #if (DEBUG_SYS_SOCKET || CONFIG_INSTRUMENTATION_SYSCALLS)
     76#if DEBUG_SYS_SOCKET || DEBUG_SYSCALLS_ERROR || CONFIG_INSTRUMENTATION_SYSCALLS
    8077uint64_t     tm_start = hal_get_cycles();
    8178#endif
    8279
    8380#if DEBUG_SYS_SOCKET
    84 tm_start = hal_get_cycles();
    85 if( DEBUG_SYS_SOCKET < tm_start )
     81if( DEBUG_SYS_SOCKET < (uint32_t)tm_start )
    8682printk("\n[%s] thread[%x,%x] enter / %s / a1 %x / a2 %x / a3 %x / cycle %d\n",
    8783__FUNCTION__, process->pid, this->trdid, socket_cmd_type_str(cmd),
     
    10197
    10298#if DEBUG_SYSCALLS_ERROR
    103 printk("\n[ERROR] in %s for CREATE domain %d =! AF_INET\n",
    104 __FUNCTION__ , domain );
     99if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     100printk("\n[ERROR] in %s : thread[%x,%x] / CREATE / domain %d =! AF_INET\n",
     101__FUNCTION__ , process->pid , this->trdid , domain );
    105102#endif
    106103                this->errno = EINVAL;
     
    113110
    114111#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__ );
     112if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     113printk("\n[ERROR] in %s : thread[%x,%x] / CREATE / illegal socket type\n",
     114__FUNCTION__ , process->pid , this->trdid );
    117115#endif
    118116                this->errno = EINVAL;
     
    124122            ret = socket_build( domain , type );
    125123
    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
     128if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     129printk("\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
    135137            break;
    136138        }
     
    146148
    147149#if DEBUG_SYSCALLS_ERROR
    148 printk("\n[ERROR] in %s for BIND : address %x unmapped\n",
    149 __FUNCTION__ , (intptr_t)arg2 );
     150if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     151printk("\n[ERROR] in %s : thread[%x,%x] / BIND / socket address %x unmapped\n",
     152__FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 );
    150153#endif
    151154                this->errno = EINVAL;
     
    164167                               k_sockaddr.sin_port );
    165168
    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
     173if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     174printk("\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
    175182            break;
    176183        }
     
    184191                ret = socket_listen( fdid , max_pending );
    185192
    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
     197if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     198printk("\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
    195206            break;
    196207        }
     
    206217
    207218#if DEBUG_SYSCALLS_ERROR
    208 printk("\n[ERROR] in %s for CONNECT : server address %x unmapped\n",
    209 __FUNCTION__ , (intptr_t)arg2 );
     219if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     220printk("\n[ERROR] in %s : thread[%x,%x] / CONNECT / server address %x unmapped\n",
     221__FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 );
    210222#endif
    211223                this->errno = EINVAL;
     
    223235                                  k_sockaddr.sin_addr,
    224236                                  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
     241if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     242printk("\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
    235250            break;
    236251        }
     
    246261
    247262#if DEBUG_SYSCALLS_ERROR
    248 printk("\n[ERROR] in %s for CONNECT : server address %x unmapped\n",
    249 __FUNCTION__ , (intptr_t)arg2 );
     263if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     264printk("\n[ERROR] in %s : thread[%x,%x] / CONNECT / server address %x unmapped\n",
     265__FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 );
    250266#endif
    251267                this->errno = EINVAL;
     
    259275                                 &k_sockaddr.sin_port );
    260276
    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
     281if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     282printk("\n[ERROR] in %s : thread[%x,%x] / ACCEPT / cannot access socket[%x,%d]\n",
     283__FUNCTION__ , process->pid , this->trdid , process->pid, fdid );
    267284#endif
    268285                this->errno = EINVAL;
     
    288305
    289306#if DEBUG_SYSCALLS_ERROR
    290 printk("\n[ERROR] in %s for SEND : buffer %x unmapped\n",
    291 __FUNCTION__ , (intptr_t)arg2 );
     307if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     308printk("\n[ERROR] in %s : thread[%x,%x] / SEND / buffer %x unmapped\n",
     309__FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 );
    292310#endif
    293311                this->errno = EINVAL;
     
    301319
    302320#if DEBUG_SYSCALLS_ERROR
    303 printk("\n[ERROR] in %s for SEND : buffer length is 0\n",
    304 __FUNCTION__ , (intptr_t)arg2 );
     321if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     322printk("\n[ERROR] in %s : thread[%x,%x] / SEND / buffer length is 0\n",
     323__FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 );
    305324#endif
    306325                this->errno = EINVAL;
     
    316335
    317336#if DEBUG_SYSCALLS_ERROR
    318 printk("\n[ERROR] in %s for SEND : cannot access socket[%x,%d] \n",
    319 __FUNCTION__ , process->pid, fdid );
     337if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     338printk("\n[ERROR] in %s : thread[%x,%x] / SEND / cannot access socket[%x,%d] \n",
     339__FUNCTION__ , process->pid , this->trdid , process->pid, fdid );
    320340#endif
    321341                this->errno = EINVAL;
     
    335355
    336356#if DEBUG_SYSCALLS_ERROR
    337 printk("\n[ERROR] in %s for SEND : buffer %x unmapped\n",
    338 __FUNCTION__ , (intptr_t)arg2 );
     357if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     358printk("\n[ERROR] in %s : thread[%x,%x] / RECV / buffer %x unmapped\n",
     359__FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 );
    339360#endif
    340361                this->errno = EINVAL;
     
    348369
    349370#if DEBUG_SYSCALLS_ERROR
    350 printk("\n[ERROR] in %s for SEND : buffer length is 0\n",
    351 __FUNCTION__ , (intptr_t)arg2 );
     371if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     372printk("\n[ERROR] in %s : thread[%x,%x] / RECV / buffer length is 0\n",
     373__FUNCTION__ , process->pid , this->trdid , (intptr_t)arg2 );
    352374#endif
    353375                this->errno = EINVAL;
     
    363385
    364386#if DEBUG_SYSCALLS_ERROR
    365 printk("\n[ERROR] in %s for RECV : cannot access socket[%x,%d] \n",
    366 __FUNCTION__ , process->pid, fdid );
     387if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     388printk("\n[ERROR] in %s : thread[%x,%x] / RECV / cannot access socket[%x,%d] \n",
     389__FUNCTION__ , process->pid , this->trdid , process->pid, fdid );
    367390#endif
    368391                this->errno = EINVAL;
     
    375398
    376399#if DEBUG_SYSCALLS_ERROR
    377 printk("\n[ERROR] in %s : undefined socket operation %d\n",
    378         __FUNCTION__ , cmd );
     400if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     401printk("\n[ERROR] in %s : thread[%x,%x] / undefined socket operation %d\n",
     402__FUNCTION__ , process->pid , this->trdid , cmd );
    379403#endif
    380404            this->errno = EINVAL;
Note: See TracChangeset for help on using the changeset viewer.