Ignore:
Timestamp:
Jan 29, 2018, 5:40:34 PM (6 years ago)
Author:
alain
Message:

Introduce sys_fg() , sys_display() , sys_wait() syscalls.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/sys_read.c

    r418 r421  
    9898
    9999    // enable IRQs
    100     // hal_enable_irq( &save_sr );
     100    hal_enable_irq( &save_sr );
    101101
    102102    // get extended pointer on remote file descriptor
     
    129129
    130130    // action depend on file type
    131     if( type == INODE_TYPE_FILE )      // transfer count bytes from file mapper
    132     {
     131    if( type == INODE_TYPE_FILE )      // check file readable & read from mapper
     132    {
     133        // check file readable
     134        uint32_t attr = hal_remote_lw( XPTR( file_cxy , &file_ptr->attr ) );
     135        if( (attr & FD_ATTR_READ_ENABLE) == 0 )
     136            {
     137            printk("\n[ERROR] in %s : file %d not readable in process %x\n",
     138            __FUNCTION__ , file_id , process->pid );
     139                    this->errno = EBADFD;
     140                    return -1;
     141            }
     142
     143        // move count bytes from mapper
    133144        nbytes = vfs_user_move( true,               // from mapper to buffer
    134145                                file_xp,
     
    136147                                count );
    137148    }
    138     else if( type == INODE_TYPE_DEV )  // transfer count bytes from device
    139     {
     149    else if( type == INODE_TYPE_DEV )  // check ownership & read from from device
     150    {
     151        // move count bytes from device
    140152        nbytes = devfs_user_move( true,             // from device to buffer
    141153                                  file_xp,
    142154                                  vaddr,
    143155                                  count );
     156
     157        // check ownership
     158        xptr_t    chdev_xp  = chdev_from_file( file_xp );
     159        cxy_t     chdev_cxy = GET_CXY( chdev_xp );
     160        chdev_t * chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
     161        xptr_t    owner_xp  = hal_remote_lwd( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) );
     162
     163        if( XPTR( local_cxy , process ) != owner_xp )
     164        {
     165            printk("\n[ERROR] in %s : process %x not in foreground for TXT%d\n",
     166            __FUNCTION__, process->pid, hal_remote_lw( XPTR(chdev_cxy,&chdev_ptr->channel) ) );
     167                    this->errno = EBADFD;
     168                    return -1;
     169        }
    144170    }
    145171    else
    146172    {
    147173        nbytes = 0;
    148         panic("file type %d non supported yet", type );
     174        assert( false , __FUNCTION__ , "file type %d non supported yet\n", type );
    149175    }
    150176
     
    158184
    159185    // restore IRQs
    160     // hal_restore_irq( save_sr );
     186    hal_restore_irq( save_sr );
    161187
    162188    hal_fence();
     
    171197#endif
    172198
    173 #if CONFIG_READ_DEBUG
     199#if (CONFIG_READ_DEBUG & 0x1)
    174200exit_sys_read = (uint32_t)tm_end;
    175201
Note: See TracChangeset for help on using the changeset viewer.