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

    r637 r670  
    22 * sys_mkfifo.c - creates a named FIFO file.
    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
     
    3131////////////////////////////////////
    3232int sys_mkfifo ( char    * pathname,
    33                  uint32_t  mode __attribute__((unused)) )
     33                 uint32_t  mode )
    3434{
    35     char           kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
     35    vseg_t      * vseg;
     36    error_t       error;
     37    xptr_t        root_inode_xp;           
     38    char          kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    3639
    37     thread_t  * this    = CURRENT_THREAD;
    38     process_t * process = this->process;
     40    thread_t    * this    = CURRENT_THREAD;
     41    process_t   * process = this->process;
    3942
    40 #if (DEBUG_SYS_MKFIFO || CONFIG_INSTRUMENTATION_SYSCALLS)
     43#if DEBUG_SYS_MKFIFO || DEBUG_SYSCALLS_ERROR || CONFIG_INSTRUMENTATION_SYSCALLS
    4144uint64_t     tm_start = hal_get_cycles();
    4245#endif
     
    4548if( DEBUG_SYS_MKFIFO < tm_end )
    4649printk("\n[%s] thread[%x,%x] enter for <%s> / cycle %d\n",
    47 __FUNCTION__, process->pid, this->trdid, pathname, (uint32_t)tm_end );
     50__FUNCTION__, process->pid, this->trdid, pathname, (uint32_t)tm_start );
    4851#endif
    4952 
    50     // check fd_array not full
    51     if( process_fd_array_full() )
    52     {
     53    // check pathname in user space
     54    if( vmm_get_vseg( process, (intptr_t)pathname , &vseg ) )
     55        {
    5356
    5457#if DEBUG_SYSCALLS_ERROR
    55 printk("\n[ERROR] in %s : file descriptor array full for process %x\n",
    56 __FUNCTION__ , process->pid );
     58if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     59printk("\n[ERROR] in %s : user buffer unmapped %x for thread[%x,%x]\n",
     60__FUNCTION__ , (intptr_t)pathname , process->pid, this->trdid );
    5761#endif
    58         this->errno = ENFILE;
     62                this->errno = EINVAL;
    5963        return -1;
    60     }
     64        }
    6165
    6266    // check pathname length
     
    6569
    6670#if DEBUG_SYSCALLS_ERROR
    67 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     71if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     72printk("\n[ERROR] in %s : pathname too long for thread[%x,%x]\n",
     73__FUNCTION__ , process->pid , this->trdid );
    6874#endif
    6975        this->errno = ENFILE;
     
    7682                            CONFIG_VFS_MAX_PATH_LENGTH );
    7783
    78     printk("\n[ERROR] in %s : not implemented yet\n", __FUNCTION__ );
    79     return -1;
     84#if DEBUG_SYS_MKFIFO
     85if( DEBUG_SYS_MKFIFO < tm_end )
     86printk("\n[%s] thread[%x,%x] enter for <%s> / cycle %d\n",
     87__FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_start );
     88#endif
     89 
     90    // get cluster and local pointer on reference process
     91    xptr_t      ref_xp  = process->ref_xp;
     92    process_t * ref_ptr = GET_PTR( ref_xp );
     93    cxy_t       ref_cxy = GET_CXY( ref_xp );
     94
     95    // get extended pointer on root inode in path
     96    if( kbuf[0] == '/' )                            // absolute path
     97    {
     98        // use extended pointer on VFS root inode
     99        root_inode_xp = process->vfs_root_xp;
     100    }
     101    else                                            // relative path
     102    {
     103        // use extended pointer on CWD inode
     104        root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) );
     105    }
     106
     107    // call the relevant VFS function
     108    error = vfs_mkfifo( root_inode_xp,
     109                        kbuf,
     110                        mode );
     111    if( error )
     112    {
     113
     114#if DEBUG_SYSCALLS_ERROR
     115if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
     116printk("\n[ERROR] in %s : thread[%x,%x] cannot create node in VFS for <%s> path\n",
     117__FUNCTION__ , process->pid , this->trdid , kbuf );
     118#endif
     119        this->errno = ENFILE;
     120        return -1;
     121    }
    80122
    81123#if (DEBUG_SYS_MKFIFO || CONFIG_INSTRUMENTATION_SYSCALLS)
     
    94136#endif
    95137
     138    return 0;
     139
    96140} // end sys_mkfifo()
Note: See TracChangeset for help on using the changeset viewer.