Ignore:
Timestamp:
Nov 19, 2020, 11:45:52 PM (4 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_read.c

    r664 r670  
    22 * sys_read.c - Kernel function implementing the "read" system call.
    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
     
    3333#include <thread.h>
    3434#include <printk.h>
     35#include <pipe.h>
    3536#include <process.h>
    3637
     
    7374    xptr_t        process_owner_xp = process->owner_xp;
    7475 
    75 #if (DEBUG_SYS_READ || CONFIG_INSTRUMENTATION_SYSCALLS)
     76#if DEBUG_SYS_READ || DEBUG_SYSCALLS_ERROR || CONFIG_INSTRUMENTATION_SYSCALLS
    7677uint64_t     tm_start = hal_get_cycles();
    7778#endif
     
    9293
    9394#if DEBUG_SYSCALLS_ERROR
    94 printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index %d\n",
     95if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     96printk("\n[ERROR] in %s : thread[%x,%x] / illegal file descriptor index %d\n",
    9597__FUNCTION__ , process->pid, this->trdid, file_id );
    9698#endif
     
    106108
    107109#if DEBUG_SYSCALLS_ERROR
    108 printk("\n[ERROR] in %s : thread[%x,%x] user buffer unmapped %x\n",
     110if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     111printk("\n[ERROR] in %s : thread[%x,%x] / user buffer unmapped %x\n",
    109112__FUNCTION__ , process->pid, this->trdid, (intptr_t)vaddr );
    110113#endif
     
    120123
    121124#if DEBUG_SYSCALLS_ERROR
    122 printk("\n[ERROR] in %s : thread[%x,%x] undefined fd_id %d\n",
     125if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     126printk("\n[ERROR] in %s : thread[%x,%x] / undefined fd_id %d\n",
    123127__FUNCTION__, process->pid, this->trdid, file_id );
    124128#endif
     
    140144    hal_enable_irq( &save_sr );
    141145
     146    // check file readable
     147    if( (file_attr & FD_ATTR_READ_ENABLE) == 0 )
     148    {
     149
     150#if DEBUG_SYSCALLS_ERROR
     151if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     152printk("\n[ERROR] in %s : thread[%x,%x] / file %d not readable\n",
     153__FUNCTION__, process->pid, this->trdid, file_id );
     154#endif
     155        hal_restore_irq( save_sr );
     156        this->errno = EBADFD;
     157        return -1;
     158    }
     159
    142160    // action depend on file type:
    143 
    144     if( file_type == INODE_TYPE_FILE )      // read from file mapper
    145     {
    146         // check file readable
    147         if( (file_attr & FD_ATTR_READ_ENABLE) == 0 )
    148             {
    149 
    150 #if DEBUG_SYSCALLS_ERROR
    151 printk("\n[ERROR] in %s : thread[%x,%x] file %d not readable\n",
    152 __FUNCTION__, process->pid, this->trdid, file_id );
    153 #endif
    154             hal_restore_irq( save_sr );
    155                     this->errno = EBADFD;
    156                     return -1;
    157             }
    158 
     161    if( file_type == FILE_TYPE_REG )                           // read from mapper
     162    {
    159163        // try to move count bytes from mapper
    160         nbytes = vfs_user_move( true,               // from mapper to buffer
     164        nbytes = vfs_user_move( true,   //  from mapper
    161165                                file_xp,
    162166                                vaddr,
    163167                                count );
    164168    }
    165     else if( file_type == INODE_TYPE_DEV )  // read from TXT device
     169    else if( file_type == FILE_TYPE_DEV )                      // read from TXT device
    166170    {
    167171        // get cluster and pointers on TXT_RX chdev
     
    176180        {
    177181            // extended pointer on TXT owner process
    178             txt_owner_xp  = hal_remote_l64( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) );
    179 
     182            txt_owner_xp  = hal_remote_l64( XPTR( chdev_cxy ,
     183                                                  &chdev_ptr->ext.txt.owner_xp ) );
    180184            // wait for TXT_RX ownership
    181185            if ( process_owner_xp != txt_owner_xp )
     
    197201
    198202        // try to move count bytes from TXT device
    199         nbytes = devfs_user_move( true,             // from device to buffer
     203        nbytes = devfs_user_move( true,    // from device
    200204                                  file_xp,
    201205                                  vaddr,
    202206                                  count );
    203207    }
    204     else    // not FILE and not DEV
    205     {
    206 
    207 #if DEBUG_SYSCALLS_ERROR
    208 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n",
     208    else if( (file_type == FILE_TYPE_PIPE) ||
     209             (file_type == FILE_TYPE_FIFO) )                  // read from pipe
     210    {
     211        // try to move count bytes from pipe
     212        nbytes = pipe_user_move( true,    // from pipe
     213                                 file_xp,
     214                                 vaddr,
     215                                 count );
     216    }   
     217    else                                                      // unsupported type
     218    {
     219
     220#if DEBUG_SYSCALLS_ERROR
     221if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     222printk("\n[ERROR] in %s : thread[%x,%x] / unsupported inode type %d\n",
    209223__FUNCTION__, vfs_inode_type_str( file_type ) );
    210224#endif
     
    219233
    220234#if DEBUG_SYSCALLS_ERROR
     235if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
    221236printk("\n[ERROR] in %s : thread[%x,‰x] cannot read data from file %d\n",
    222237__FUNCTION__, process->pid, this->trdid, file_id );
Note: See TracChangeset for help on using the changeset viewer.