Changeset 683 for trunk/kernel/syscalls


Ignore:
Timestamp:
Jan 13, 2021, 12:36:17 AM (4 years ago)
Author:
alain
Message:

All modifications required to support the <tcp_chat> application
including error recovery in case of packet loss.A

Location:
trunk/kernel/syscalls
Files:
1 deleted
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/shared_include/shared_almos.h

    r670 r683  
    22 * shared_almos.h - Shared mnemonics used by the almos-mkh specific syscalls.
    33 *
    4  * Author  Alain Greiner (2016,2017,2018)
     4 * Author  Alain Greiner (2016,2017,2018,2019,2020)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    6262
    6363/*******************************************************************************************
     64 * This enum defines the operation mnemonics for the non standard get_xxx() syscalls.
     65 ******************************************************************************************/
     66
     67typedef 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}
     77get_operation_type_t;
     78
     79/*******************************************************************************************
    6480 * This structure defines the - user accessible - information stored in a thread.
    6581 ******************************************************************************************/
  • trunk/kernel/syscalls/shared_include/shared_dirent.h

    r611 r683  
    11/*
    2  * shared_dirent.h - Shared structure used by the opendir() / readdir() / closedir() syscalls.
     2 * shared_dirent.h - structures used by the opendir() / readdir() / closedir() syscalls.
    33 *
    4  * Author  Alain Greiner (2016,2017,2018)
     4 * Author  Alain Greiner (2016,2017,2018,2019,2020)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
  • trunk/kernel/syscalls/shared_include/shared_socket.h

    r670 r683  
    6969    SOCK_SEND        = 5,
    7070    SOCK_RECV        = 6,
     71    SOCK_SENDTO      = 7,
     72    SOCK_RECVFROM    = 8,
    7173}
    7274socket_operation_type_t;
  • trunk/kernel/syscalls/shared_include/syscalls_numbers.h

    r657 r683  
    22 * syscalls_numbers.c - Contains enum of the syscalls.
    33 *
    4  * Author    Alain Greiner (2016,2017,2018,2019)
     4 * Author    Alain Greiner (2016,2017,2018,2019,2020)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2727/******************************************************************************************
    2828 * 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>
    3031 *****************************************************************************************/
    3132typedef enum
     
    7576    SYS_WAIT            = 39,
    7677
    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_THREAD_SLEEP    = 45,
    83     SYS_THREAD_WAKEUP   = 46,
    84     SYS_TRACE           = 47,
    85     SYS_FG              = 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,
    8788
    8889    SYS_EXIT            = 50,
    8990    SYS_SYNC            = 51,
    9091    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,
    9693
    97     SYSCALLS_NR         = 58,
     94    SYSCALLS_NR         = 54,
    9895
    9996} syscalls_t;
  • trunk/kernel/syscalls/sys_alarm.c

    r506 r683  
    33 *
    44 * Author    Alain Greiner (2016,2017)
    5 *
     5 *
    66 * Copyright (c) UPMC Sorbonne Universites
    77 *
  • trunk/kernel/syscalls/sys_barrier.c

    r670 r683  
    22 * sys_barrier.c - Access a POSIX barrier.
    33 *
    4  * authors       Alain Greiner (2016,2017,2018,2019)
     4 * authors       Alain Greiner (2016,2017,2018,2019,2020)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    3333#include <remote_barrier.h>
    3434
     35/////////////////////////////////////////////////////////////////////////////////
     36// This function returns a printable string for the barrier related command type.
     37/////////////////////////////////////////////////////////////////////////////////
     38
     39#if DEBUG_SYS_SOCKET || DEBUG_SYSCALLS_ERROR
     40static 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
    3549//////////////////////////////////
    3650int sys_barrier( intptr_t   vaddr,
     
    5367if( DEBUG_SYS_BARRIER < tm_start )
    5468printk("\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,
    5670(uint32_t)tm_start );
    5771#endif
    5872
    5973    // check vaddr in user vspace
    60         error = vmm_get_vseg( process , vaddr , &vseg );
    61         if( error )
     74        if( vmm_get_vseg( process , vaddr , &vseg ) )
    6275    {
    6376
     
    6578if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
    6679printk("\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;
    7083        return -1;
    7184    }
     
    7992            if( attr != 0 )   // QDT barrier required
    8093            {
    81                 error = vmm_get_vseg( process , attr , &vseg );
    82                 if( error )
     94                if( vmm_get_vseg( process , attr , &vseg ) )
    8395                {
    8496
  • trunk/kernel/syscalls/sys_display.c

    r670 r683  
    529529
    530530            // display socket descriptor on TXT0
    531             socket_display( XPTR( file_cxy , socket ), NULL );
     531            socket_display( XPTR( file_cxy , socket ), __FUNCTION__ , NULL );
    532532
    533533            break;
  • trunk/kernel/syscalls/sys_exec.c

    r670 r683  
    3838#include <syscalls.h>
    3939
     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////////////////////////////////////////
     63static 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
     77thread_t * this  = CURRENT_THREAD;
     78uint32_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
     94if( DEBUG_SYS_EXEC < cycle )
     95printk("\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
     111if( DEBUG_SYS_EXEC < cycle )
     112printk("\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
     127if( DEBUG_SYS_EXEC < cycle )
     128printk("\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
     150if( DEBUG_SYS_EXEC < cycle )
     151printk("\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
     163if( 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
     190if( DEBUG_SYS_EXEC < cycle )
     191printk("\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
    40200///////////////////////////////
    41 int sys_exec( char  * pathname,       // .elf file pathname in user space
    42               char ** user_args,      // pointer on process arguments in user space
    43               char ** user_envs )     // pointer on env variables in user space
     201int 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
    44204{
    45205    error_t       error;
     
    96256
    97257#if DEBUG_SYSCALLS_ERROR
     258if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
    98259printk("\n[ERROR] in %s for thread[%x,%] : user_args pointer %x unmapped\n",
    99260__FUNCTION__, pid, trdid, user_args );
     
    115276                return -1;
    116277        }
    117 
    118 #if DEBUG_SYS_EXEC
    119 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 #endif
    123278
    124279    // 1. copy "pathname" in kernel exec_info structure
     
    127282                            CONFIG_VFS_MAX_PATH_LENGTH );
    128283
     284#if DEBUG_SYS_EXEC
     285if( DEBUG_SYS_EXEC < (uint32_t)tm_start )
     286printk("\n[%s] thread[%x,%x] enter / path <%s> / args %x / envs %x / cycle %d\n",
     287__FUNCTION__, pid, trdid, &process->exec_info.path[0],
     288user_args, user_envs, (uint32_t)tm_start );
     289#endif
     290
    129291    // 2. copy "arguments" pointers & strings in process exec_info if required
    130292    if( user_args != NULL )
    131293    {
    132         if( process_exec_get_strings( true , user_args , &process->exec_info ) )
     294        if( exec_get_strings( true , user_args , &process->exec_info ) )
    133295        {
    134296
    135297#if DEBUG_SYSCALLS_ERROR
    136298if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
    137 printk("\n[ERROR] in %s : thread[%x,%] get arguments for <%s>\n",
     299printk("\n[ERROR] in %s : thread[%x,%] cannot get arguments for <%s>\n",
    138300__FUNCTION__, pid, trdid, pathname );
    139301#endif
     
    144306#if DEBUG_SYS_EXEC
    145307if( DEBUG_SYS_EXEC < (uint32_t)tm_start )
    146 printk("\n[%s] thread[%x,%x] got arguments / arg[0] = <%s>\n",
     308printk("\n[%s] thread[%x,%x] set arguments in exec_info / arg[0] = <%s>\n",
    147309__FUNCTION__, pid, trdid, process->exec_info.args_pointers[0] );
    148310#endif
     
    153315    if( user_envs != NULL )
    154316    {
    155         if( process_exec_get_strings( false , user_envs , &process->exec_info ) )
     317        if( exec_get_strings( false , user_envs , &process->exec_info ) )
    156318        {
    157319
    158320#if DEBUG_SYSCALLS_ERROR
    159321if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
    160 printk("\n[ERROR] in %s : thread[%x,%] get env variables for <%s>\n",
     322printk("\n[ERROR] in %s : thread[%x,%] cannot get env variables for <%s>\n",
    161323__FUNCTION__, pid, trdid, pathname );
    162324#endif
     
    167329#if DEBUG_SYS_EXEC
    168330if( DEBUG_SYS_EXEC < (uint32_t)tm_start )
    169 printk("\n[%s] thread[%x,%x] got envs / env[0] = <%s>\n",
     331printk("\n[%s] thread[%x,%x] set envs in exec_info / env[0] = <%s>\n",
    170332__FUNCTION__, pid, trdid, process->exec_info.envs_pointers[0] );
    171333#endif
  • trunk/kernel/syscalls/sys_kill.c

    r664 r683  
    22 * sys_kill.c - Kernel function implementing the "kill" system call.
    33 *
    4  * Author    Alain Greiner (2016,2017,2018)
     4 * Author    Alain Greiner     (2016,2017,2018,2019,2020)
    55 *
    66 * Copyright (c)  UPMC Sorbonne Universites
     
    6767    process_t * process = this->process;
    6868
    69 #if (DEBUG_SYS_KILL || CONFIG_INSTRUMENTATION_SYSCALLS)
     69#if DEBUG_SYS_KILL || DEBUG_SYSCALLS_ERROR || CONFIG_INSTRUMENTATION_SYSCALLS
    7070uint64_t     tm_start = hal_get_cycles();
    7171#endif
    7272
    7373#if DEBUG_SYS_KILL
    74 tm_start = hal_get_cycles();
    7574if( DEBUG_SYS_KILL < tm_start )
    7675printk("\n[%s] thread[%x,%x] enter : %s to process %x / cycle %d\n",
     
    9594
    9695#if DEBUG_SYSCALLS_ERROR
    97 printk("\n[ERROR] in %s : process %x not found\n", __FUNCTION__, pid );
     96if( DEBUG_SYSCALLS_ERROR < tm_start )
     97printk("\n[ERROR] in %s : thread[%x,%x] / process %x not found\n",
     98__FUNCTION__, process->pid, this->trdid, pid );
    9899#endif
    99100        this->errno = EINVAL;
     
    175176
    176177#if DEBUG_SYSCALLS_ERROR
    177 printk("\n[ERROR] in %s : process %x cannot kill itself\n", __FUNCTION__, pid );
     178if( DEBUG_SYSCALLS_ERROR < tm_start )
     179printk("\n[ERROR] in %s : thread[%x,%x] / process %x cannot kill itself\n",
     180__FUNCTION__, process->pid, this->trdid, pid );
    178181#endif
    179182                this->errno = EINVAL;
     
    186189
    187190#if DEBUG_SYSCALLS_ERROR
    188 printk("\n[ERROR] in %s : process_init cannot be killed\n", __FUNCTION__ );
     191if( DEBUG_SYSCALLS_ERROR < tm_start )
     192printk("\n[ERROR] in %s : thread[%x,%x] / process_init cannot be killed\n",
     193 __FUNCTION__, process->pid, this->trdid);
    189194#endif
    190195                        this->errno = EINVAL;
     
    219224
    220225#if DEBUG_SYSCALLS_ERROR
    221 printk("\n[ERROR] in %s : illegal signal %d / process %x\n", __FUNCTION__, sig_id, pid );
     226if( DEBUG_SYSCALLS_ERROR < tm_start )
     227printk("\n[ERROR] in %s : thread[%x,%x] / illegal signal %d\n",
     228__FUNCTION__, process->pid, this->trdid, sig_id );
    222229#endif
    223230            this->errno = EINVAL;
     
    234241#if DEBUG_SYS_KILL
    235242if( DEBUG_SYS_KILL < tm_end )
    236 printk("\n[%s] thread[%x,%x] exit / process %x / %s / cost = %d / cycle %d\n",
     243printk("\n[%s] thread[%x,%x] exit / process %x / %s / cycle %d\n",
    237244__FUNCTION__ , this->process->pid, this->trdid, pid,
    238 sig_type_str(sig_id), (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
     245sig_type_str(sig_id), (uint32_t)tm_end );
    239246#endif
    240247
  • trunk/kernel/syscalls/sys_opendir.c

    r670 r683  
    6565
    6666#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 );
     67printk("\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 );
    7069#endif
    7170                this->errno = EINVAL;
     
    8079
    8180#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 );
     81printk("\n[ERROR] in %s : thread[%x,%x] / pathname %x unmapped / cycle %d\n",
     82__FUNCTION__ , process->pid , this->trdid, pathname, (uint32_t)tm_start );
    8583#endif
    8684                this->errno = EINVAL;
     
    9290
    9391#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 );
     92printk("\n[ERROR] in %s / thread[%x,%x] : pathname too long / cycle %d\n",
     93 __FUNCTION__ , process->pid , this->trdid, (uint32_t)tm_start );
    9794#endif
    9895        this->errno = ENFILE;
     
    138135
    139136#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 );
     137printk("\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 );
    143139#endif
    144140                this->errno = ENFILE;
     
    155151
    156152#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 );
     153printk("\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 );
    160155#endif
    161156                this->errno = ENFILE;
     
    163158        }
    164159   
    165     // create a new user_dir_t structure in target directory inode cluster
     160    // create an user_dir_t structure in cluster containing directory inode
    166161    // map it in the reference user process VMM (in a new ANON vseg)
    167162    // an get the local pointer on the created user_dir_t structure
     
    183178
    184179#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 );
     180printk("\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 );
    188182#endif
    189183                this->errno = ENFILE;
  • trunk/kernel/syscalls/sys_pipe.c

    r670 r683  
    3636{
    3737    vseg_t       * vseg;
    38     kmem_req_t     req;
    3938    pipe_t       * pipe;
    4039    vfs_file_t   * file_0;
     
    8887    // 2. allocate memory for fd[0] file descriptor in local cluster
    8988    // 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 );
    9490
    9591    if( file_0 == NULL )
     
    120116
    121117    // 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 );
    126120
    127121    if( file_1 == NULL )
     
    178172error_5:    // release memory allocated for fd[1] file descriptor
    179173
    180     req.ptr = file_1;
    181     kmem_free( &req );
     174    kmem_free( file_1 , bits_log2(sizeof(vfs_file_t)) );
    182175
    183176error_4:    // release fdid_0 from fd_array[]
     
    187180error_3:    // release memory allocated for fd[0] file descriptor
    188181
    189     req.ptr = file_0;
    190     kmem_free( &req );
     182    kmem_free( file_0 , bits_log2(sizeof(vfs_file_t)) );
    191183
    192184error_2:    // release memory allocated for the pipe
  • trunk/kernel/syscalls/sys_place_fork.c

    r670 r683  
    5555       
    5656#if DEBUG_SYSCALLS_ERROR
    57 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start );
     57if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
    5858printk("\n[ERROR] in %s : thread[%x,‰x] / illegal cxy argument %x\n",
    5959__FUNCTION__ , process->pid , this->trdid , cxy );
  • trunk/kernel/syscalls/sys_socket.c

    r670 r683  
    4545
    4646#if DEBUG_SYS_SOCKET
    47 static char* socket_cmd_type_str( uint32_t type )
     47static char* socket_user_cmd_str( uint32_t type )
    4848{
    4949    if     ( type == SOCK_CREATE      ) return "CREATE";
     
    5454    else if( type == SOCK_SEND        ) return "SEND";
    5555    else if( type == SOCK_RECV        ) return "RECV";
     56    else if( type == SOCK_SENDTO      ) return "SENDTO";
     57    else if( type == SOCK_RECVFROM    ) return "RECVFROM";
    5658    else                                return "undefined";
    5759}
     
    7981
    8082#if DEBUG_SYS_SOCKET
     83char kbuf[64];
    8184if( 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),
     85printk("\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),
    8487arg1, arg2, arg3, (uint32_t)tm_start );
    8588#endif
     
    97100
    98101#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 );
     102printk("\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 );
    102104#endif
    103105                this->errno = EINVAL;
     
    110112
    111113#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 );
     114printk("\n[ERROR] in %s : thread[%x,%x] / CREATE / illegal socket type / cycle %d\n",
     115__FUNCTION__ , process->pid , this->trdid  , (uint32_t)tm_start);
    115116#endif
    116117                this->errno = EINVAL;
     
    126127
    127128#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 );
     129printk("\n[ERROR] in %s : thread[%x,%x] / CREATE / cannot create socket / cycle %d\n",
     130__FUNCTION__ , process->pid , this->trdid  , (uint32_t)tm_start);
    131131#endif
    132132                this->errno = EINVAL;
     
    148148
    149149#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 );
     150printk("\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 );
    153152#endif
    154153                this->errno = EINVAL;
     
    171170
    172171#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 );
     172printk("\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 );
    176174#endif
    177175                this->errno = EINVAL;
     
    195193
    196194#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 );
     195printk("\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 );
    200197#endif
    201198                this->errno = EINVAL;
     
    217214
    218215#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 );
     216printk("\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 );
    222218#endif
    223219                this->errno = EINVAL;
     
    239235
    240236#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 );
     237printk("\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 );
    244239#endif
    245240                this->errno = EINVAL;
     
    261256
    262257#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 );
     258printk("\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 );
    266260#endif
    267261                this->errno = EINVAL;
     
    275269                                 &k_sockaddr.sin_port );
    276270
    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
     275printk("\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 );
    284277#endif
    285278                this->errno = EINVAL;
     
    305298
    306299#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             }
     300printk("\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
     313printk("\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
     329printk("\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
     336if( 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
    343343            break;
    344344        }
     
    355355
    356356#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 );
     357printk("\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
     370printk("\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 );
    374372#endif
    375373                this->errno = EINVAL;
     
    379377
    380378            // 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
     386printk("\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
     393if( 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
     417printk("\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
     430printk("\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
     443printk("\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
     465printk("\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
     488printk("\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
     501printk("\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
     514printk("\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
     536printk("\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
    393542            break;
    394543        }
     
    398547
    399548#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 );
     549printk("\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 );
    403551#endif
    404552            this->errno = EINVAL;
     
    413561
    414562#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 );
     563printk("\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 );
    418565#endif
    419566
  • trunk/kernel/syscalls/sys_thread_exit.c

    r670 r683  
    22 * sys_thread_exit.c - terminates the execution of calling thread
    33 *
    4  * Authors   Alain Greiner (2016,2017,2018,2019)
     4 * Authors   Alain Greiner (2016,2017,2018,2019,2020)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    4444    pid_t       pid       = process->pid;
    4545   
     46#if DEBUG_SYS_THREAD_EXIT || DEBUG_SYSCALLS_ERROR
     47uint64_t     tm_start = hal_get_cycles();
     48#endif
     49
    4650    // check exit_value pointer in user space if required
    4751    if( exit_status != NULL )
     
    5357
    5458#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 );
     59if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     60printk("\n[WARNING] in %s : exit_status buffer %x unmapped / thread[%x,%x]\n",
     61__FUNCTION__, (intptr_t)exit_status, pid, trdid );
    5762#endif
    5863            this->errno = EINVAL;
     
    6772
    6873#if DEBUG_SYSCALLS_ERROR
    69 printk("\n[ERROR] in %s : busylocks count = %d  / thread[%x,%x]\n",
    70 __FUNCTION__ , count, process->pid, this->trdid );
     74if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     75printk("\n[WARNING] in %s : busylocks count = %d  / thread[%x,%x]\n",
     76__FUNCTION__ , count, pid, trdid );
    7177#endif
    7278            this->errno = EINVAL;
     
    8490
    8591#if DEBUG_SYS_THREAD_EXIT
    86 uint64_t     tm_start = hal_get_cycles();
    87 if( DEBUG_SYS_THREAD_EXIT < tm_start )
     92if( DEBUG_SYS_THREAD_EXIT < (uint32_t)tm_start )
    8893printk("\n[%s] thread[%x,%x] is main => delete process / cycle %d\n",
    8994__FUNCTION__ , pid , trdid , (uint32_t)tm_start );
     
    96101
    97102#if DEBUG_SYS_THREAD_EXIT
    98 uint64_t     tm_start = hal_get_cycles();
    99 if( DEBUG_SYS_THREAD_EXIT < tm_start )
     103if( DEBUG_SYS_THREAD_EXIT < (uint32_t)tm_start )
    100104printk("\n[%s] thread[%x,%x] is not main => delete thread / cycle %d\n",
    101105__FUNCTION__ , pid , trdid , (uint32_t)tm_start );
  • trunk/kernel/syscalls/sys_thread_sleep.c

    r566 r683  
    11/*
    2  * sys_thread_sleep.c - put the calling thread in sleep state
     2 * sys_thread_sleep.c - block the calling thread on SLEEP, with or without alarm
    33 *
    4  * Author    Alain Greiner (2016,2017)
     4 * Author    Alain Greiner    (2016,2017,2018,2019,2020)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2828#include <syscalls.h>
    2929
    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///////////////////////////////////////////////////////////////////////////////////////
     36static void __attribute__((noinline)) sleep_alarm_handler( xptr_t thread_xp )
    3237{
     38    // stop the alarm
     39    alarm_stop( thread_xp );
    3340
    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////////////////////////////////////////
     47int 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();
    3555
    3656#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 );
     57if( DEBUG_SYS_THREAD_SLEEP < (uint32_t)tm_start )
     58printk("\n[%s] thread[%x,%x] enter / cycle %d\n",
     59__FUNCTION__, this->process->pid, this->trdid, (uint32_t)tm_start );
    4360#endif
    4461
    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
     66if( DEBUG_SYS_THREAD_SLEEP < tm_start )
     67printk("\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
     86if( DEBUG_SYS_THREAD_SLEEP < tm_start )
     87printk("\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    }
    4794
    4895#if DEBUG_SYS_THREAD_SLEEP
    49 tm_end = hal_get_cycles();
    5096if( DEBUG_SYS_THREAD_SLEEP < tm_end )
    51 printk("\n[DBG] %s : thread %x in process %x resume / cycle %d\n",
    52 __FUNCTION__ , this->trdid, this->process->pid , (uint32_t)tm_end );
     97printk("\n[%s] thread[%x,%x] resume / cycle %d\n",
     98__FUNCTION__ , this->process->pid, this->trdid, (uint32_t)tm_end );
    5399#endif
    54100
  • trunk/kernel/syscalls/sys_thread_wakeup.c

    r637 r683  
    11/*
    2  * sys_thread_wakeup.c - wakeup indicated thread
     2 * sys_thread_wakeup.c - unblock indicated thread from the SLEEP condition
    33 *
    4  * Author    Alain Greiner (2016,2017,2018,2019)
     4 * Author    Alain Greiner     (2016,2017,2018,2019,2020)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2727#include <process.h>
    2828#include <errno.h>
    29 
    3029#include <syscalls.h>
    3130
     
    3635    process_t * process = this->process;
    3736
    38 #if (DEBUG_SYS_THREAD_WAKEUP || CONFIG_INSTRUMENTATION_SYSCALLS)
    39 uint64_t     tm_start = hal_get_cycles();
     37#if DEBUG_SYS_THREAD_WAKEUP || DEBUG_SYSCALLS_ERROR || CONFIG_INTRUMENTATION_SYSCALLS
     38cycle_t      tm_start = hal_get_cycles();
    4039#endif
    4140
    4241#if DEBUG_SYS_THREAD_WAKEUP
    43 if( DEBUG_SYS_THREAD_WAKEUP < tm_start )
    44 printk("\n[%s] thread %x in process enter to activate thread %x / cycle %d\n",
    45 __FUNCTION__, this->trdid, process->pid, trdid, (uint32_t)tm_start );
     42if( DEBUG_SYS_THREAD_WAKEUP < (uint32_t)tm_start )
     43printk("\n[%s] thread[%x,%x] enter to activate thread %x / cycle %d\n",
     44__FUNCTION__, process->pid, this->trdid, trdid, (uint32_t)tm_start );
    4645#endif
    4746
     
    5655
    5756#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 );
     57if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     58printk("\n[ERROR] in %s : thread[%x,%x] / illegal trdid argument %x\n",
     59__FUNCTION__, process->pid, this->trdid, trdid );
    6060#endif
    6161                this->errno = EINVAL;
     
    7070
    7171#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 );
     72if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     73printk("\n[ERROR] in %s : thread[%x,%x] / cannot find thread[%x,%x]\n",
     74__FUNCTION__, process->pid, this->trdid, process->pid, trdid );
    7475#endif
    7576        CURRENT_THREAD->errno = EINVAL;
     
    7778    }
    7879
     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
    7990    // unblock target thread
    80     thread_unblock( thread_xp , THREAD_BLOCKED_GLOBAL );
     91    thread_unblock( thread_xp , THREAD_BLOCKED_SLEEP );
    8192
    8293#if (DEBUG_SYS_THREAD_WAKEUP || CONFIG_INSTRUMENTATION_SYSCALLS)
     
    8798#if DEBUG_SYS_THREAD_WAKEUP
    8899if( DEBUG_SYS_THREAD_WAKEUP < tm_end )
    89 printk("\n[%s] thread %x in process %x exit / thread %x activated / cycle %d\n",
    90 __FUNCTION__ , this->trdid, process->pid, trdid, (uint32_t)tm_end );
     100printk("\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 );
    91102#endif
    92103
  • trunk/kernel/syscalls/sys_timeofday.c

    r637 r683  
    22 * sys_timeofday.c - Get current time
    33 *
    4  * Author    Alain Greiner (2016,2017,2018,2019)
     4 * Author    Alain Greiner      (2016,2017,2018,2019,2020)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    3232#include <core.h>
    3333#include <shared_syscalls.h>
    34 
    3534#include <syscalls.h>
    3635
     
    5049        process_t *    process = this->process;
    5150
    52 #if (DEBUG_SYS_TIMEOFDAY || CONFIG_INSTRUMENTATION_SYSCALLS)
     51#if DEBUG_SYS_TIMEOFDAY || DEBUG_SYSCALLS_ERROR || CONFIG_INSTRUMENTATION_SYSCALLS
    5352uint64_t     tm_start = hal_get_cycles();
    5453#endif
    5554
    5655#if DEBUG_SYS_TIMEOFDAY
    57 if( DEBUG_SYS_TIMEOFDAY < tm_start )
     56if( DEBUG_SYS_TIMEOFDAY < (uint32_t)tm_start )
    5857printk("\n[%s] thread[%x,%x] enter / cycle %d\n",
    5958__FUNCTION__, process->pid, this->trdid, (uint32_t)tm_start );
     
    6564
    6665#if DEBUG_SYSCALLS_ERROR
    67 printk("\n[ERROR] in %s for thread %x in process %x : tz argument must be NULL\n",
     66if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     67printk("\n[ERROR] in %s : thread[%x,%x] / tz argument must be NULL\n",
    6868__FUNCTION__ , this->trdid , process->pid );
    6969#endif
     
    7979
    8080#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 );
     81if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     82printk("\n[ERROR] in %s : thread[%x,%x] / user buffer tv unmapped\n",
     83__FUNCTION__ , this->trdid , process->pid , (intptr_t)tz );
    8384#endif
    8485        this->errno = EINVAL;
  • trunk/kernel/syscalls/syscalls.h

    r670 r683  
    3838
    3939/******************************************************************************************
    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 *****************************************************************************************/
     44int sys_alarm( uint32_t seconds );
    4545
    4646/******************************************************************************************
     
    229229
    230230/******************************************************************************************
     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 *****************************************************************************************/
     242int sys_get( reg_t   arg0,
     243             reg_t   arg1,
     244             reg_t   arg2,
     245             reg_t   arg3 );
     246
     247/******************************************************************************************
    231248 * This function implements the non-standard "get_best_core" syscall.
    232249 * It selects, in a macro-cluster specified by the <base_cxy> and <level> arguments,
     
    470487 * as a remote_buffer_t, creates two (read and write) file descriptors, and links these
    471488 * 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 ?
    473491 ******************************************************************************************
    474492 * @ fd   : pointeur on a 2 slots array of fdid : fd[0] read / fd[1] write.
     
    566584
    567585/******************************************************************************************
    568  * This generic function implements the socket related syscalls.
     586 * This generic function implements all socket related syscalls.
    569587 * The operation types mnemonics are defined in the <shared_socket> file.
    570588 * The supported operations are defined in the <socket.h> & <socket.c> files.
     
    686704
    687705/******************************************************************************************
    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 *****************************************************************************************/
     714int sys_thread_sleep( uint32_t seconds );
    694715
    695716/******************************************************************************************
    696717 * 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.
    698719 ******************************************************************************************
    699720 * @ trdid  : target thread identifier.
     
    705726 * This function calls the scheduler for the core running the calling thread.
    706727 ******************************************************************************************
    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.
    710728 * @ return always 0.
    711729 *****************************************************************************************/
Note: See TracChangeset for help on using the changeset viewer.