Changeset 664 for trunk


Ignore:
Timestamp:
Oct 10, 2020, 5:11:27 PM (4 years ago)
Author:
alain
Message:
  • Introduce the sys_socket.c file implementing all socket related syscalls.
  • Improve the non-standard sys_get_config() function.
Location:
trunk/kernel/syscalls
Files:
2 added
12 edited

Legend:

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

    r641 r664  
    5555    DISPLAY_BARRIER           = 10,
    5656    DISPLAY_FAT               = 11,
     57    DISPLAY_SOCKET            = 12,
    5758}
    5859display_type_t;
     
    8283thread_info_t;
    8384
     85/*******************************************************************************************
     86 * This structure defines the - user accessible - global hardware configuration.
     87 * It is used by the get_config() syscall.
     88 ******************************************************************************************/
     89
     90typedef struct hard_config_s
     91{
     92    unsigned int      x_size;                /*! number of clusters in a row              */
     93    unsigned int      y_size;                /*! number of clusters in a column           */
     94    unsigned int      ncores;                /*! max number of cores per cluster          */
     95   
     96    unsigned int      txt_channels;          /*! number of TXT channels                   */
     97    unsigned int      nic_channels;          /*! number of NIC channels                   */
     98    unsigned int      ioc_channels;          /*! number of IOC channels                   */
     99    unsigned int      fbf_channels;          /*! number of FBF channels                   */
     100}
     101hard_config_t;
     102
     103
    84104#endif /* _SHARED_ALMOS_H_ */
    85105
  • trunk/kernel/syscalls/sys_close.c

    r625 r664  
    22 * sys_close.c  close an open file
    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 <process.h>
    2929#include <thread.h>
     30#include <ksocket.h>
    3031#include <printk.h>
    3132
    3233#include <syscalls.h>
    3334
    34 //////////////////////////////////
    35 int sys_close ( uint32_t file_id )
     35///////////////////////////////
     36int sys_close ( uint32_t fdid )
    3637{
    3738    error_t            error;
     
    5152if( DEBUG_SYS_CLOSE < tm_start )
    5253printk("\n[%s] thread[%x,%x] enter / fdid %d / cycle %d\n",
    53 __FUNCTION__, process->pid, this->trdid, file_id, (uint32_t)tm_start );
     54__FUNCTION__, process->pid, this->trdid, fdid, (uint32_t)tm_start );
    5455#endif
    5556 
    56     // check file_id argument
    57         if( file_id >= CONFIG_PROCESS_FILE_MAX_NR )
     57    // check fdid argument
     58        if( fdid >= CONFIG_PROCESS_FILE_MAX_NR )
    5859        {
    5960
    6061#if DEBUG_SYSCALLS_ERROR
    6162printk("\n[ERROR] in %s : illegal file descriptor index = %d\n",
    62 __FUNCTION__ , file_id );
     63__FUNCTION__ , fdid );
    6364#endif
    6465                this->errno = EBADFD;
     
    6768
    6869    // get extended pointer on remote file descriptor
    69     file_xp = process_fd_get_xptr( process , file_id );
     70    file_xp = process_fd_get_xptr_from_local( process , fdid );
    7071
    7172    if( file_xp == XPTR_NULL )
     
    7475#if DEBUG_SYSCALLS_ERROR
    7576printk("\n[ERROR] in %s : undefined file descriptor %d\n",
    76 __FUNCTION__ , file_id );
     77__FUNCTION__ , fdid );
    7778#endif
    7879        this->errno = EBADFD;
     
    9091#if DEBUG_SYSCALLS_ERROR
    9192printk("\n[ERROR] in %s : file descriptor %d is a directory\n",
    92 __FUNCTION__ , file_id );
     93__FUNCTION__ , fdid );
    9394#endif
    9495                this->errno = EBADFD;
    9596                return -1;
    9697        }
    97 
    98     // call the relevant VFS function
    99         error = vfs_close( file_xp , file_id );
     98    else if( file_type == INODE_TYPE_SOCK )
     99    {
     100        // call the relevant socket function
     101        error = socket_close( file_xp , fdid );
     102    }
     103    else if( file_type == INODE_TYPE_FILE )
     104    {
     105        // call the relevant VFS function
     106            error = vfs_close( file_xp , fdid );
     107    }
     108    else
     109    {
     110           
     111#if DEBUG_SYSCALLS_ERROR
     112printk("\n[WARNING] in %s : type (%d) not supported  / fdid %d\n",
     113__FUNCTION__ , file_type , fdid );
     114#endif
     115        error = 0;       
     116    }
    100117
    101118        if( error )
     
    104121#if DEBUG_SYSCALLS_ERROR
    105122printk("\n[ERROR] in %s : cannot close file descriptor %d\n",
    106 __FUNCTION__ , file_id );
     123__FUNCTION__ , fdid );
    107124#endif
    108125                this->errno = error;
  • trunk/kernel/syscalls/sys_display.c

    r657 r664  
    3535#include <vfs.h>
    3636#include <mapper.h>
    37 
     37#include <ksocket.h>
    3838#include <syscalls.h>
    3939
     
    5757    else if( type == DISPLAY_BARRIER           ) return "BARRIER";
    5858    else if( type == DISPLAY_FAT               ) return "FAT";
     59    else if( type == DISPLAY_SOCKET            ) return "SOCKET";
    5960    else                                         return "undefined";
    6061}
     
    8182tm_start = hal_get_cycles();
    8283if( DEBUG_SYS_DISPLAY < tm_start )
    83 printk("\n[%s] thread[%x,%x] enter / type  %s / cycle = %d\n",
    84 __FUNCTION__, process->pid, this->trdid, display_type_str(type), (uint32_t)tm_start );
     84printk("\n[%s] thread[%x,%x] enter / type  %s / arg0 %x / arg1 %x / arg2 %x / cycle = %d\n",
     85__FUNCTION__, process->pid, this->trdid, display_type_str(type),
     86(uint32_t)arg0, (uint32_t)arg1, (uint32_t)arg2, (uint32_t)tm_start );
    8587#endif
    8688
     
    114116
    115117#if DEBUG_SYSCALLS_ERROR
    116 printk("\n[ERROR] in %s for STRING : string length %d too large\n",
     118printk("\n[ERROR] in %s STRING : string length %d too large\n",
    117119__FUNCTION__ , length );
    118120#endif
     
    143145
    144146#if DEBUG_SYSCALLS_ERROR
    145 printk("\n[ERROR] in %s for VMM : process %x in cluster %x not found\n",
     147printk("\n[ERROR] in %s VMM : process %x in cluster %x not found\n",
    146148__FUNCTION__ , pid , cxy );
    147149#endif
     
    156158
    157159#if DEBUG_SYSCALLS_ERROR
    158 printk("\n[ERROR] in %s for VMM : process %x in cluster %x not found\n",
     160printk("\n[ERROR] in %s VMM : process %x in cluster %x not found\n",
    159161__FUNCTION__ , pid , cxy );
    160162#endif
     
    179181
    180182#if DEBUG_SYSCALLS_ERROR
    181 printk("\n[ERROR] in %s for SCHED : illegal cxy argument %x\n",
     183printk("\n[ERROR] in %s SCHED : illegal cxy argument %x\n",
    182184__FUNCTION__ , cxy );
    183185#endif
     
    191193
    192194#if DEBUG_SYSCALLS_ERROR
    193 printk("\n[ERROR] in %s for SCHED : illegal lid argument %x\n",
     195printk("\n[ERROR] in %s SCHED : illegal lid argument %x\n",
    194196__FUNCTION__ , lid );
    195197#endif
     
    214216
    215217#if DEBUG_SYSCALLS_ERROR
    216 printk("\n[ERROR] in %s for CLUSTER_PROCESSES : illegal cxy argument %x\n",
     218printk("\n[ERROR] in %s CLUSTER_PROCESSES : illegal cxy argument %x\n",
    217219__FUNCTION__ , cxy );
    218220#endif
     
    249251
    250252#if DEBUG_SYSCALLS_ERROR
    251 printk("\n[ERROR] in %s for TXT_PROCESSES : illegal txt_id argument %d\n",
     253printk("\n[ERROR] in %s TXT_PROCESSES : illegal txt_id argument %d\n",
    252254__FUNCTION__ , txt_id );
    253255#endif
     
    280282
    281283#if DEBUG_SYSCALLS_ERROR
    282 printk("\n[ERROR] in %s for BUSYLOCKS : thread[%x,%x] not found\n",
     284printk("\n[ERROR] in %s BUSYLOCKS : thread[%x,%x] not found\n",
    283285__FUNCTION__ , pid, trdid );
    284286#endif
     
    313315
    314316#if DEBUG_SYSCALLS_ERROR
    315 printk("\n[ERROR] in %s for MAPPER : pathname too long\n",
     317printk("\n[ERROR] in %s MAPPER : pathname too long\n",
    316318 __FUNCTION__ );
    317319#endif
     
    325327
    326328#if DEBUG_SYSCALLS_ERROR
    327 printk("\n[ERROR] in %s for MAPPER : nbytes cannot be larger than 4096\n",
     329printk("\n[ERROR] in %s MAPPER : nbytes cannot be larger than 4096\n",
    328330 __FUNCTION__ );
    329331#endif
     
    386388
    387389#if DEBUG_SYSCALLS_ERROR
    388 printk("\n[ERROR] in %s for MAPPER : cannot get page %d\n",
     390printk("\n[ERROR] in %s MAPPER : cannot get page %d\n",
    389391__FUNCTION__ , page_id );
    390392#endif
     
    414416
    415417#if DEBUG_SYSCALLS_ERROR
    416 printk("\n[ERROR] in %s for BARRIER : process %x not found\n",
     418printk("\n[ERROR] in %s BARRIER : process %x not found\n",
    417419__FUNCTION__ , pid );
    418420#endif
     
    428430
    429431#if DEBUG_SYSCALLS_ERROR
    430 printk("\n[ERROR] in %s for BARRIER : no registered barrier in process %x\n",
     432printk("\n[ERROR] in %s BARRIER : no registered barrier in process %x\n",
    431433__FUNCTION__ , pid );
    432434#endif
     
    452454
    453455#if DEBUG_SYSCALLS_ERROR
    454 printk("\n[ERROR] in %s for FAT : nb_slots larger than 1024\n",
     456printk("\n[ERROR] in %s FAT : nb_slots larger than 1024\n",
    455457__FUNCTION__ );
    456458#endif
     
    467469
    468470#if DEBUG_SYSCALLS_ERROR
    469 printk("\n[ERROR] in %s for FAT : illegal cxy argument %x\n",
     471printk("\n[ERROR] in %s FAT : illegal cxy argument %x\n",
    470472__FUNCTION__ , cxy );
    471473#endif
     
    482484                fatfs_display_fat( min , slots );
    483485            }
     486
     487            break;
     488        }
     489        ////////////////////
     490        case DISPLAY_SOCKET:
     491        {
     492            pid_t   pid   = (pid_t)arg0;
     493            trdid_t fdid  = (trdid_t)arg1;
     494
     495            // get extended pointer on owner process descriptor
     496            xptr_t owner_xp = cluster_get_owner_process_from_pid( pid );
     497
     498            if( owner_xp == XPTR_NULL )
     499            {
     500
     501#if DEBUG_SYSCALLS_ERROR
     502printk("\n[ERROR] in %s SOCKET : pid %x not found\n", __FUNCTION__ , pid );
     503#endif
     504                this->errno = EINVAL;
     505                return -1;
     506            }
     507
     508            // get extended pointer on file descriptor
     509            xptr_t file_xp = process_fd_get_xptr_from_owner( owner_xp , fdid );
     510
     511            if( file_xp == XPTR_NULL )
     512            {
     513
     514#if DEBUG_SYSCALLS_ERROR
     515printk("\n[ERROR] in %s SOCKET : fdid %d not found\n", __FUNCTION__ , fdid );
     516#endif
     517                this->errno = EINVAL;
     518                return -1;
     519            }
     520
     521            // get local pointer and cluster for file
     522            vfs_file_t * file_ptr = GET_PTR( file_xp );
     523            cxy_t        file_cxy = GET_CXY( file_xp );
     524
     525            // get local pointer on socket descriptor
     526            socket_t * socket = hal_remote_lpt( XPTR( file_cxy , &file_ptr->socket ) );
     527
     528            // display socket descriptor on TXT0
     529            socket_display( XPTR( file_cxy , socket ), NULL );
    484530
    485531            break;
  • trunk/kernel/syscalls/sys_exit.c

    r651 r664  
    8989#endif
    9090
     91    // close all open files
     92    process_fd_clean_all( owner_xp );
     93
     94#if( DEBUG_SYS_EXIT & 1)
     95if( DEBUG_SYS_EXIT < tm_start )
     96printk("\n[%s] thread[%x,%x] closed all files for process %x\n",
     97__FUNCTION__, pid, this->trdid, pid );
     98#endif
     99
    91100    // mark for delete all process threads in all clusters,
    92101    // but the main thread and this calling thread
  • trunk/kernel/syscalls/sys_get_config.c

    r637 r664  
    22 * sys_get_config.c - get hardware platform parameters.
    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
     
    3434
    3535#include <syscalls.h>
     36#include <shared_syscalls.h>
    3637
    37 //////////////////////////////////////
    38 int sys_get_config( uint32_t * x_size,
    39                     uint32_t * y_size,
    40                     uint32_t * ncores )
     38//////////////////////////////////////////////
     39int sys_get_config( hard_config_t * u_config )
    4140{
    42         error_t    error;
    43     vseg_t   * vseg;
    44     uint32_t   k_x_size;
    45     uint32_t   k_y_size;
    46     uint32_t   k_ncores;
     41    vseg_t        * vseg;       
     42    hard_config_t   k_config;    // hard_config structure in kernel space
    4743
    4844    thread_t  * this    = CURRENT_THREAD;
     
    6056#endif
    6157
    62     // check x_size buffer in user space
    63     error = vmm_get_vseg( process , (intptr_t)x_size  , &vseg );
    64 
    65         if( error )
     58    // check u_config mapped in user space
     59    if( vmm_get_vseg( process , (intptr_t)u_config  , &vseg ) )
    6660        {
    6761
    6862#if DEBUG_SYSCALLS_ERROR
    69 printk("\n[ERROR] in %s : x_size buffer unmapped / thread %x / process %x\n",
    70 __FUNCTION__ , (intptr_t)x_size , this->trdid , process->pid );
     63printk("\n[ERROR] in %s : config pointer %x unmapped / thread %x / process %x\n",
     64__FUNCTION__ , (intptr_t)u_config , this->trdid , process->pid );
    7165#endif
    7266        this->errno = EINVAL;
     
    7468        }
    7569
    76     // check y_size buffer in user space
    77     error = vmm_get_vseg( process , (intptr_t)y_size  , &vseg );
     70    // copy config parameters from cluster descriptor to kernel structure
     71        k_config.x_size       = LOCAL_CLUSTER->x_size;
     72        k_config.y_size       = LOCAL_CLUSTER->y_size;
     73        k_config.ncores       = LOCAL_CLUSTER->cores_nr;
     74    k_config.txt_channels = LOCAL_CLUSTER->nb_txt_channels;
     75    k_config.nic_channels = LOCAL_CLUSTER->nb_nic_channels;
     76    k_config.ioc_channels = LOCAL_CLUSTER->nb_ioc_channels;
     77    k_config.fbf_channels = LOCAL_CLUSTER->nb_fbf_channels;
    7878
    79         if( error )
    80         {
    81 
    82 #if DEBUG_SYSCALLS_ERROR
    83 printk("\n[ERROR] in %s : y_size buffer unmapped / thread %x / process %x\n",
    84 __FUNCTION__ , (intptr_t)y_size , this->trdid , process->pid );
    85 #endif
    86         this->errno = EINVAL;
    87                 return -1;
    88         }
    89 
    90     // check ncores buffer in user space
    91     error = vmm_get_vseg( process , (intptr_t)ncores  , &vseg );
    92 
    93         if( error )
    94         {
    95 
    96 #if DEBUG_SYSCALLS_ERROR
    97 printk("\n[ERROR] in %s : ncores buffer unmapped / thread %x / process %x\n",
    98 __FUNCTION__ , (intptr_t)ncores , this->trdid , process->pid );
    99 #endif
    100         this->errno = EINVAL;
    101                 return -1;
    102         }
    103 
    104     // get parameters
    105         k_x_size  = LOCAL_CLUSTER->x_size;
    106         k_y_size  = LOCAL_CLUSTER->y_size;
    107         k_ncores  = LOCAL_CLUSTER->cores_nr;
    108 
    109     // copy to user space
    110         hal_copy_to_uspace( x_size, XPTR( local_cxy , &k_x_size ), sizeof(uint32_t) );
    111         hal_copy_to_uspace( y_size, XPTR( local_cxy , &k_y_size ), sizeof(uint32_t) );
    112         hal_copy_to_uspace( ncores, XPTR( local_cxy , &k_ncores ), sizeof(uint32_t) );
     79    // copy k_config structure to user space
     80        hal_copy_to_uspace( u_config , XPTR(local_cxy, &k_config ), sizeof(hard_config_t) );
    11381
    11482    hal_fence();
  • trunk/kernel/syscalls/sys_isatty.c

    r566 r664  
    7171
    7272    // get extended pointer on remote file descriptor
    73     file_xp = process_fd_get_xptr( process , file_id );
     73    file_xp = process_fd_get_xptr_from_local( process , file_id );
    7474
    7575    if( file_xp == XPTR_NULL )
  • trunk/kernel/syscalls/sys_kill.c

    r624 r664  
    195195            process_txt_detach( owner_xp );
    196196
     197            // close all open files
     198            process_fd_clean_all( owner_xp );
     199
    197200            // mark for delete all threads in all clusters, but the main
    198201            process_sigaction( pid , DELETE_ALL_THREADS );
  • trunk/kernel/syscalls/sys_lseek.c

    r651 r664  
    6767
    6868    // get extended pointer on remote file descriptor
    69     file_xp = process_fd_get_xptr( process , file_id );
     69    file_xp = process_fd_get_xptr_from_local( process , file_id );
    7070
    7171    if( file_xp == XPTR_NULL )
  • trunk/kernel/syscalls/sys_mmap.c

    r657 r664  
    2626#include <hal_vmm.h>
    2727#include <hal_irqmask.h>
    28 #include <shared_syscalls.h>
    2928#include <errno.h>
    3029#include <thread.h>
     
    3635
    3736#include <syscalls.h>
     37#include <shared_syscalls.h>
    3838
    3939//////////////////////////////////
     
    141141
    142142        // get extended pointer on file descriptor
    143         xptr_t file_xp = process_fd_get_xptr( process , fdid );
     143        xptr_t file_xp = process_fd_get_xptr_from_local( process , fdid );
    144144
    145145        if( file_xp == XPTR_NULL )
  • trunk/kernel/syscalls/sys_read.c

    r656 r664  
    114114
    115115    // get extended pointer on remote file descriptor
    116     file_xp = process_fd_get_xptr( process , file_id );
     116    file_xp = process_fd_get_xptr_from_local( process , file_id );
    117117
    118118    if( file_xp == XPTR_NULL )
  • trunk/kernel/syscalls/sys_write.c

    r656 r664  
    8282 
    8383#if (DEBUG_SYS_WRITE & 1)
     84if( DEBUG_SYS_WRITE < tm_start )
    8485enter_sys_write = (uint32_t)tm_start;
    8586#endif
     
    112113
    113114    // get extended pointer on remote file descriptor
    114     file_xp = process_fd_get_xptr( process , file_id );
     115    file_xp = process_fd_get_xptr_from_local( process , file_id );
    115116
    116117    if( file_xp == XPTR_NULL )
     
    215216
    216217#if (DEBUG_SYS_WRITE & 1)
     218if( DEBUG_SYS_WRITE < tm_start )
    217219exit_sys_write = (uint32_t)tm_end;
    218220
     221if( DEBUG_SYS_WRITE < tm_start )
    219222printk("\n***** timing to write a string *****\n"
    220223" - enter_sys_write          = %d / delta %d\n"
  • trunk/kernel/syscalls/syscalls.h

    r657 r664  
    348348 * but the directory must exist in the file system.
    349349 * It returns a DIR pointer <dirp> on the dirent array in user space.
     350 * The calling process fd_array is NOT modified.
    350351 ******************************************************************************************
    351352 * @ pathname   : [in]  pathname (can be relative or absolute).
     
    558559/******************************************************************************************
    559560 * [40] This function implement the non-standard get_config() syscall.
    560  * It returns in <x_size>, <y_size>, <ncores> the hardware platform parameters.
    561  ******************************************************************************************
    562  * @ x_size   : [out] number of clusters in a row.
    563  * @ y_size   : [out] number of clusters in a column.
    564  * @ ncores   : [out] number of cores per cluster.
    565  * @ return 0 if success / return -1 if illegal arguments
    566  *****************************************************************************************/
    567 int sys_get_config( uint32_t * x_size,
    568                     uint32_t * y_size,
    569                     uint32_t * ncores );
     561 * It returns the global hardware platform parameters in the <config> shared structure,
     562 * that is defined in the shared_almos.h file.
     563 ******************************************************************************************
     564 * @ config   : [out] pointer on the hard_config_t structure in user space.
     565 * @ return 0 if success / return -1 if illegal argument
     566 *****************************************************************************************/
     567int sys_get_config( struct hard_config_s * config );
    570568
    571569/******************************************************************************************
Note: See TracChangeset for help on using the changeset viewer.