Ignore:
Timestamp:
Nov 10, 2018, 2:33:26 PM (6 years ago)
Author:
alain
Message:

Fix various bugs in sys_stat() and sys_mmap() functions.
Improve debug in other functions.

File:
1 edited

Legend:

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

    r566 r594  
    3939{
    4040    error_t       error;
    41     vseg_t      * vseg;         // for user space checking
    42     struct stat   k_stat;       // kernel space
    43     xptr_t        file_xp;
     41    vseg_t      * vseg;                   // for user space checking
     42    struct stat   k_stat;                 // in kernel space
     43    xptr_t        inode_xp;               // extended pointer on target inode
     44
    4445    char          kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    4546       
    4647        thread_t  * this    = CURRENT_THREAD;
    4748        process_t * process = this->process;
     49
     50#if (DEBUG_SYS_STAT || CONFIG_INSTRUMENTATION_SYSCALLS)
     51uint64_t     tm_start = hal_get_cycles();
     52#endif
    4853
    4954    // check stat structure in user space
     
    5459
    5560#if DEBUG_SYSCALLS_ERROR
    56 printk("\n[ERROR] in %s : stat structure unmapped %x / thread %x / process %x\n",
    57 __FUNCTION__ , (intptr_t)u_stat , this->trdid , process->pid );
     61printk("\n[ERROR] in %s / thread[%x,%x] : stat structure unmapped\n",
     62__FUNCTION__ , process->pid , this->trdid );
    5863vmm_display( process , false );
    5964#endif
     
    6570    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
    6671    {
    67         printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     72
     73#if DEBUG_SYSCALLS_ERROR
     74printk("\n[ERROR] in %s / thread[%x,%x] : pathname too long\n",
     75 __FUNCTION__ , process->pid , this->trdid );
     76#endif
    6877        this->errno = ENFILE;
    6978        return -1;
     
    7281    // copy pathname in kernel space
    7382    hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
     83
     84#if DEBUG_SYS_STAT
     85if( DEBUG_SYS_STAT < tm_start )
     86printk("\n[%s] thread[%x,%x] enter for file <%s> / cycle %d\n",
     87__FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_start );
     88#endif
    7489
    7590    // get cluster and local pointer on reference process
     
    86101    // get extended pointer on remote file descriptor
    87102    error = vfs_lookup( cwd_xp,
    88                         pathname,
     103                        kbuf,
    89104                        0,
    90                         &file_xp );
     105                        &inode_xp );
    91106
    92107    // release the cwd lock
     
    95110    if( error )
    96111    {
    97         printk("\n[ERROR] in %s : cannot found file <%s> for thread %x in process %x\n",
    98                __FUNCTION__ , pathname , this->trdid , process->pid );
    99         this->errno = error;
     112
     113#if DEBUG_SYSCALLS_ERROR
     114printk("\n[ERROR] in %s / thread[%x,%x] : cannot found file <%s>\n",
     115__FUNCTION__ , process->pid , this->trdid , pathname );
     116#endif
     117        this->errno = ENFILE;
    100118        return -1;
    101119    }
    102120
     121#if (DEBUG_SYS_STAT & 1)
     122if( DEBUG_SYS_STAT < tm_start )
     123printk("\n[%s] thread[%x,%x] got inode %x in cluster %x for <%s>\n",
     124__FUNCTION__, process->pid, this->trdid, GET_PTR(inode_xp), GET_CXY(inode_xp), kbuf );
     125#endif
     126
    103127    // call VFS function to get stat info
    104     error = vfs_stat( file_xp,
     128    error = vfs_stat( inode_xp,
    105129                      &k_stat );
    106130    if( error )
    107131        {
    108         printk("\n[ERROR] in %s : cannot get stats for file %s\n",
    109                __FUNCTION__ , pathname );
    110                 this->errno = error;
     132
     133#if DEBUG_SYSCALLS_ERROR
     134printk("\n[ERROR] in %s / thread[%x,%x] : cannot get stats for inode <%s>\n",
     135__FUNCTION__ , process->pid , this->trdid , pathname );
     136#endif
     137                this->errno = ENFILE;
    111138                return -1;
    112139        }
    113140   
     141#if (DEBUG_SYS_STAT & 1)
     142if( DEBUG_SYS_STAT < tm_start )
     143printk("\n[%s] thread[%x,%x] set kstat : inum %d / size %d / mode %d\n",
     144__FUNCTION__, process->pid, this->trdid, k_stat.st_ino, k_stat.st_size, k_stat.st_mode );
     145#endif
     146
    114147    // copy k_stat to u_stat
    115148    hal_copy_to_uspace( u_stat , &k_stat , sizeof(struct stat) );
     
    117150    hal_fence();
    118151
     152#if (DEBUG_SYS_STAT || CONFIG_INSTRUMENTATION_SYSCALLS)
     153uint64_t     tm_end = hal_get_cycles();
     154#endif
     155
     156#if DEBUG_SYS_STAT
     157if( DEBUG_SYS_STAT < tm_end )
     158printk("\n[%s] thread[%x,%x] exit for file <%s> / cycle %d\n",
     159__FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_end );
     160#endif
     161 
     162#if CONFIG_INSTRUMENTATION_SYSCALLS
     163hal_atomic_add( &syscalls_cumul_cost[SYS_STAT] , tm_end - tm_start );
     164hal_atomic_add( &syscalls_occurences[SYS_STAT] , 1 );
     165#endif
     166
    119167        return 0;
    120168
Note: See TracChangeset for help on using the changeset viewer.