Changeset 610 for trunk/kernel/syscalls/sys_getcwd.c
- Timestamp:
- Dec 27, 2018, 7:38:58 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_getcwd.c
r566 r610 1 1 /* 2 * sys_getcwd.c - get process current work directory2 * sys_getcwd.c - kernel function implementing the "getcwd" syscall. 3 3 * 4 4 * Author Alain Greiner (2016,2017,2018) … … 35 35 #include <syscalls.h> 36 36 37 /* TODO: user page(s) need to be locked [AG] */ 38 39 //////////////////////////////// 40 int sys_getcwd ( char * buf, 37 /////////////////////////////////// 38 int sys_getcwd ( char * buffer, 41 39 uint32_t nbytes ) 42 40 { 43 error_t error; 44 vseg_t * vseg; 45 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 46 41 error_t error; 42 vseg_t * vseg; 43 char * first; // first character valid in buffer 44 45 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 46 47 47 thread_t * this = CURRENT_THREAD; 48 48 process_t * process = this->process; 49 50 #if (DEBUG_SYS_GETCWD || CONFIG_INSTRUMENTATION_SYSCALLS) 51 uint64_t tm_start = hal_get_cycles(); 52 #endif 49 53 50 54 // check buffer size … … 53 57 54 58 #if DEBUG_SYSCALLS_ERROR 55 printk("\n[ERROR] in %s : buffer too small / thread %x / process %x\n",56 __FUNCTION__ , this->trdid , process->pid );59 printk("\n[ERROR] in %s : buffer too small for thread %x,%x]\n", 60 __FUNCTION__ , process->pid, this->trdid ); 57 61 #endif 58 62 this->errno = EINVAL; … … 61 65 62 66 // check buffer in user space 63 error = vmm_get_vseg( process, (intptr_t)buf , &vseg );67 error = vmm_get_vseg( process, (intptr_t)buffer , &vseg ); 64 68 65 69 if( error ) … … 67 71 68 72 #if DEBUG_SYSCALLS_ERROR 69 printk("\n[ERROR] in %s : user buffer unmapped %x / thread %x / process %x\n",70 __FUNCTION__ , (intptr_t)buf , this->trdid , process->pid );73 printk("\n[ERROR] in %s : user buffer unmapped %x for thread[%x,%x]\n", 74 __FUNCTION__ , (intptr_t)buffer , process->pid, this->trdid ); 71 75 #endif 72 76 this->errno = EINVAL; … … 74 78 } 75 79 76 // get reference process cluster and local pointer 80 #if DEBUG_SYS_GETCWD 81 if( DEBUG_SYS_GETCWD < tm_start ) 82 printk("\n[%s] thread[%x,%x] enter / cycle %d\n", 83 __FUNCTION__, process->pid, this->trdid, (uint32_t)tm_start ); 84 #endif 85 86 // get extended pointer on CWD inode from the reference process 77 87 xptr_t ref_xp = process->ref_xp; 88 process_t * ref_ptr = GET_PTR( ref_xp ); 78 89 cxy_t ref_cxy = GET_CXY( ref_xp ); 79 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 80 81 // get CWD lock in read mode 82 remote_rwlock_rd_acquire( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 90 xptr_t cwd_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) ); 83 91 84 92 // call relevant VFS function 85 error = vfs_get_path( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) , 86 kbuf , CONFIG_VFS_MAX_PATH_LENGTH ); 87 88 // release CWD lock in read mode 89 remote_rwlock_rd_release( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 93 error = vfs_get_path( cwd_xp, 94 kbuf, 95 &first, 96 CONFIG_VFS_MAX_PATH_LENGTH ); 90 97 91 98 // copy kernel buffer to user space 92 hal_ copy_to_uspace( buf , kbuf, CONFIG_VFS_MAX_PATH_LENGTH );99 hal_strcpy_to_uspace( buffer , first , CONFIG_VFS_MAX_PATH_LENGTH ); 93 100 94 101 hal_fence(); 102 103 #if (DEBUG_SYS_GETCWD || CONFIG_INSTRUMENTATION_SYSCALLS) 104 uint64_t tm_end = hal_get_cycles(); 105 #endif 106 107 #if DEBUG_SYS_GETCWD 108 if( DEBUG_SYS_GETCWD < tm_end ) 109 printk("\n[%s] thread[%x,%x] exit / cycle %d\n", 110 __FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end ); 111 #endif 112 113 #if CONFIG_INSTRUMENTATION_SYSCALLS 114 hal_atomic_add( &syscalls_cumul_cost[SYS_GETCWD] , tm_end - tm_start ); 115 hal_atomic_add( &syscalls_occurences[SYS_GETCWD] , 1 ); 116 #endif 95 117 96 118 return 0;
Note: See TracChangeset
for help on using the changeset viewer.