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_write.c

    r664 r670  
    22 * sys_write.c - Kernel function implementing the "write" 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
     
    7172        process_t   * process = this->process;
    7273
    73 #if (DEBUG_SYS_WRITE || CONFIG_INSTRUMENTATION_SYSCALLS)
     74#if DEBUG_SYS_WRITE || DEBUG_SYSCALLS_ERROR || CONFIG_INSTRUMENTATION_SYSCALLS
    7475uint64_t     tm_start = hal_get_cycles();
    7576#endif
     
    9192
    9293#if DEBUG_SYSCALLS_ERROR
    93 printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index %d\n",
     94if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     95printk("\n[ERROR] in %s : thread[%x,%x] / illegal file descriptor index %d\n",
    9496__FUNCTION__, process->pid, this->trdid, file_id );
    9597#endif
     
    105107
    106108#if DEBUG_SYSCALLS_ERROR
    107 printk("\n[ERROR] in %s : thread[%x,%x] user buffer unmapped %x\n",
     109if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     110printk("\n[ERROR] in %s : thread[%x,%x] / user buffer unmapped %x\n",
    108111__FUNCTION__ , process->pid, this->trdid, (intptr_t)vaddr );
    109112#endif
     
    119122
    120123#if DEBUG_SYSCALLS_ERROR
    121 printk("\n[ERROR] in %s : thread[%x,%x] undefined file descriptor = %d\n",
     124if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     125printk("\n[ERROR] in %s : thread[%x,%x] / undefined file descriptor = %d\n",
    122126__FUNCTION__, process->pid, this->trdid, file_id );
    123127#endif
     
    139143    hal_enable_irq( &save_sr );
    140144
    141     // action depend on file type:
    142 
    143     if( file_type == INODE_TYPE_FILE )  // write to a file mapper
    144     {
    145         // check file writable
    146         if( (file_attr & FD_ATTR_WRITE_ENABLE) == 0 )
    147             {
    148 
    149 #if DEBUG_SYSCALLS_ERROR
    150 printk("\n[ERROR] in %s : thread[%x,%x] file %d not writable\n",
     145    // check file writable
     146    if( (file_attr & FD_ATTR_WRITE_ENABLE) == 0 )
     147    {
     148
     149#if DEBUG_SYSCALLS_ERROR
     150if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     151printk("\n[ERROR] in %s : thread[%x,%x] / file %d not writable\n",
    151152__FUNCTION__ , process->pid, this->trdid, file_id );
    152153#endif
     
    154155                    this->errno = EBADFD;
    155156                    return -1;
    156             }
    157 
     157    }
     158
     159    // action depend on file type:
     160    if( file_type == FILE_TYPE_REG )                         // write to mapper
     161    {
    158162        // move count bytes to mapper
    159         nbytes = vfs_user_move( false,               // from buffer to mapper
     163        nbytes = vfs_user_move( false,    // to mapper
    160164                                file_xp,
    161165                                vaddr,
    162166                                count );
    163167    }
    164     else if( file_type == INODE_TYPE_DEV )  // write to TXT device
     168    else if( file_type == FILE_TYPE_DEV )                     // write to TXT device
    165169    {
    166170        // move count bytes to device
    167         nbytes = devfs_user_move( false,             // from buffer to device
     171        nbytes = devfs_user_move( false,  // to device
    168172                                  file_xp,
    169173                                  vaddr,
    170174                                  count );
    171175    }
    172     else  // not FILE and not DEV
    173     {
    174 
    175 #if DEBUG_SYSCALLS_ERROR
     176    else if( (file_type == FILE_TYPE_PIPE) ||
     177             (file_type == FILE_TYPE_FIFO) )                  // write to pipe
     178    {
     179        // move count bytes to pipe
     180        nbytes = pipe_user_move( false,   // to pipe
     181                                 file_xp,
     182                                 vaddr,
     183                                 count );
     184    }
     185    else                                                       // unsupported type
     186    {
     187
     188#if DEBUG_SYSCALLS_ERROR
     189if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
    176190printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n",
    177191__FUNCTION__, vfs_inode_type_str( file_type ) );
     
    187201
    188202#if DEBUG_SYSCALLS_ERROR
     203if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
    189204printk("\n[ERROR] in %s : thread[%x,‰x] cannot write data to file %d\n",
    190205__FUNCTION__ , process->pid, this->trdid, file_id );
Note: See TracChangeset for help on using the changeset viewer.