Ignore:
Timestamp:
Nov 7, 2017, 3:08:12 PM (6 years ago)
Author:
alain
Message:

First implementation of fork/exec.

File:
1 edited

Legend:

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

    r315 r407  
    3232#include <process.h>
    3333
    34 /* TODO: user page(s) need to be locked [AG] */
     34/* TODO: concurrent user page(s) unmap need to be handled [AG] */
    3535
    3636//////////////////////////////////
    3737int sys_write( uint32_t   file_id,
    38                void     * buf,
     38               void     * vaddr,
    3939               uint32_t   count )
    4040{
    4141    error_t      error;
    42     paddr_t      paddr;                // required for user space checking
     42    paddr_t      paddr;                // unused, but required for user space checking
    4343        xptr_t       file_xp;              // remote file extended pointer
     44    uint32_t     nbytes;               // number of bytes actually written
     45
     46        uint32_t     tm_start;
     47        uint32_t     tm_end;
     48
     49        tm_start = hal_get_cycles();
    4450
    4551        thread_t   * this = CURRENT_THREAD;
     
    5561
    5662    // check user buffer in user space
    57     error = vmm_v2p_translate( false , buf , &paddr );
     63    error = vmm_v2p_translate( false , vaddr , &paddr );
    5864
    5965    if ( error )
    6066    {
    6167        printk("\n[ERROR] in %s : user buffer unmapped = %x\n",
    62                __FUNCTION__ , (intptr_t)buf );
     68        __FUNCTION__ , (intptr_t)vaddr );
    6369                this->errno = EINVAL;
    6470                return -1;
     
    7076    if( file_xp == XPTR_NULL )
    7177    {
    72         printk("\n[ERROR] in %s : undefined file descriptor index = %d\n",
    73                __FUNCTION__ , file_id );
     78        printk("\n[ERROR] in %s : undefined file descriptor index = %d in process %x\n",
     79        __FUNCTION__ , file_id , process->pid );
    7480                this->errno = EBADFD;
    7581                return -1;
     
    8490    if( (attr & FD_ATTR_WRITE_ENABLE) == 0 )
    8591        {
    86         printk("\n[ERROR] in %s : file %d not writable\n",
    87                __FUNCTION__ , file_id );
     92        printk("\n[ERROR] in %s : file %d not writable in process %x\n",
     93        __FUNCTION__ , file_id , process->pid );
    8894                this->errno = EBADFD;
    8995                return -1;
    9096        }
    9197   
    92     // transfer count bytes directly from user buffer to mapper
    93     error = vfs_user_move( false,               // from buffer
    94                            file_xp,
    95                            buf ,
    96                            count );
     98    // get file type
     99    vfs_inode_type_t type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type ) );
    97100
    98     if( error )
     101    // action depend on file type
     102    if( type == INODE_TYPE_FILE )      // transfer count bytes to file mapper
    99103    {
    100         printk("\n[ERROR] in %s cannot read data from file %d\n",
    101                __FUNCTION__ , file_id );
     104        nbytes = vfs_user_move( false,               // from buffer to mapper
     105                                file_xp,
     106                                vaddr,
     107                                count );
     108    }
     109    else if( type == INODE_TYPE_DEV )  // transfer count bytes to device
     110    {
     111        nbytes = devfs_user_move( false,             // from buffer to device
     112                                 file_xp,
     113                                 vaddr,
     114                                 count );
     115    }
     116    else
     117    {
     118        nbytes = 0;
     119        panic("file type %d non supported", type );
     120    }
     121
     122    if( nbytes != count )
     123    {
     124        printk("\n[ERROR] in %s cannot write data to file %d in process %x\n",
     125        __FUNCTION__ , file_id , process->pid );
    102126        this->errno = error;
    103127        return -1;
     
    106130    hal_fence();
    107131
    108         return 0;
     132    tm_end = hal_get_cycles();
     133
     134syscall_dmsg("\n[DBG] %s : core[%x,%d] / thread %x / nbytes = %d / cycle %d\n"
     135" first byte = %c / file_id = %d / cost = %d\n",
     136__FUNCTION__ , local_cxy , this->core->lid , this->trdid , nbytes , tm_start ,
     137*((char *)(intptr_t)paddr) , file_id , tm_end - tm_start );
     138 
     139        return nbytes;
    109140
    110141}  // end sys_write()
Note: See TracChangeset for help on using the changeset viewer.