Changeset 611 for trunk/kernel/syscalls
- Timestamp:
- Jan 9, 2019, 3:02:51 PM (6 years ago)
- Location:
- trunk/kernel/syscalls
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/shared_include/shared_almos.h
r580 r611 52 52 DISPLAY_DQDT = 7, 53 53 DISPLAY_BUSYLOCKS = 8, 54 DISPLAY_MAPPER = 9, 54 55 } 55 56 display_type_t; -
trunk/kernel/syscalls/shared_include/shared_dirent.h
r445 r611 26 26 27 27 /******************************************************************************************* 28 * Th ese two structure defines the informations returned to user by the opendir()29 * function, used by the readdir() function, and released by the closedir() function.30 * - "DIR" describes the complete directory.31 * - "dirent" describes one directory entry.28 * This enum defines the possible types for a dirent inode in a dirent structure. 29 * 30 * WARNING : these types must be kept consistent with inode types in <vfs.h> file. 31 * and with types in <shared_stat.h> file. 32 32 ******************************************************************************************/ 33 33 34 #define DIRENT_NAME_MAX_LENGTH 56 35 #define DIRENT_MAX_NUMBER 63 34 typedef enum 35 { 36 DT_REG = 0, /*! regular file */ 37 DT_DIR = 1, /*! directory */ 38 DT_FIFO = 2, /*! named pipe (FIFO) */ 39 DT_PIPE = 3, /*! anonymous pipe */ 40 DT_SOCK = 4, /*! socket */ 41 DT_CHR = 5, /*! character device */ 42 DT_BLK = 6, /*! block device */ 43 DT_LNK = 7, /*! symbolic link */ 44 DT_UNKNOWN = 8, /*! undetermined type */ 45 } 46 dirent_type_t; 47 48 /******************************************************************************************* 49 * This defines the actual ALMOS-MKH implementation of the DIR user type. 50 ******************************************************************************************/ 51 52 typedef unsigned int DIR; 53 54 /******************************************************************************************* 55 * This structure defines the informations returned to user by the readdir() syscall. 56 * 57 * WARNING: sizeof(dirent) must be 64 bytes. 58 ******************************************************************************************/ 36 59 37 60 struct dirent 38 61 { 39 unsigned int inum; /*! inode identifier */ 40 unsigned int type; /*! inode type */ 41 char name[DIRENT_NAME_MAX_LENGTH]; /*! directory entry name */ 62 int d_ino; /*! inode identifier */ 63 int d_type; /*! inode type */ 64 char d_name[48]; /*! dentry name */ 65 char padding[64 - 48 - (2*sizeof(int))]; 42 66 }; 43 67 44 typedef struct user_directory45 {46 struct dirent entry[DIRENT_MAX_NUMBER];47 unsigned int current;48 }49 DIR;50 51 68 #endif -
trunk/kernel/syscalls/shared_include/shared_stat.h
r594 r611 30 30 *****************************************************************************************/ 31 31 32 typedefstruct stat32 struct stat 33 33 { 34 34 unsigned int st_dev; /*! ID of device containing file */ … … 42 42 unsigned int st_blksize; /*! blocksize for file system I/O */ 43 43 unsigned int st_blocks; /*! number of allocated blocks */ 44 } 45 stat_t; 44 }; 46 45 47 46 /****************************************************************************************** … … 52 51 * 53 52 * WARNING : these macros must be kept consistent with inode types in <vfs.h> file. 53 * and with types in <dirent.h> file. 54 54 *****************************************************************************************/ 55 55 … … 60 60 #define S_ISSOCK(x) ((((x)>>16) & 0xF) == 4) /*! it is a socket */ 61 61 #define S_ISCHR(x) ((((x)>>16) & 0xF) == 5) /*! it is a character device */ 62 #define S_ISLNK(x) ((((x)>>16) & 0xF) == 6) /*! it is a symbolic link */ 62 #define S_ISBLK(x) ((((x)>>16) & 0xF) == 6) /*! it is a block device */ 63 #define S_ISLNK(x) ((((x)>>16) & 0xF) == 7) /*! it is a symbolic link */ 63 64 64 65 #endif /* _STAT_H_ */ -
trunk/kernel/syscalls/sys_closedir.c
r473 r611 1 1 /* 2 * sys_closedir.c - Close an open directory.2 * sys_closedir.c - Close an open VFS directory. 3 3 * 4 * Author Alain Greiner (2016, 2017)4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 22 22 */ 23 23 24 #include <kernel_config.h> 24 25 #include <hal_kernel_types.h> 25 26 #include <vfs.h> … … 27 28 #include <thread.h> 28 29 #include <process.h> 30 #include <remote_dir.h> 29 31 #include <errno.h> 30 32 #include <syscalls.h> … … 34 36 int sys_closedir ( DIR * dirp ) 35 37 { 36 printk("\n[ERROR] in %s : not implemented yet\n", __FUNCTION__, dirp ); 37 return -1; 38 xptr_t dir_xp; // extended pointer on remote_dir_t structure 39 40 thread_t * this = CURRENT_THREAD; // client thread 41 process_t * process = this->process; // client process 42 43 #if (DEBUG_SYS_CLOSEDIR || CONFIG_INSTRUMENTATION_SYSCALLS) 44 uint64_t tm_start = hal_get_cycles(); 45 #endif 46 47 #if DEBUG_SYS_CLOSEDIR 48 if( DEBUG_SYS_CLOSEDIR < tm_start ) 49 printk("\n[%s] thread[%x,%x] enter for DIR <%x> / cycle %d\n", 50 __FUNCTION__, process->pid, this->trdid, dirp, (uint32_t)tm_start ); 51 #endif 52 53 // get extended pointer on kernel remote_dir_t structure from dirp 54 dir_xp = remote_dir_from_ident( (intptr_t)dirp ); 55 56 if( dir_xp == XPTR_NULL ) 57 { 58 59 #if DEBUG_SYSCALLS_ERROR 60 printk("\n[ERROR] in %s / thread[%x,%x] : DIR pointer %x not registered\n", 61 __FUNCTION__ , process->pid , this->trdid, dirp ); 62 #endif 63 this->errno = EINVAL; 64 return -1; 65 } 66 67 // delete kernel remote_dir_t structure 68 remote_dir_destroy( dir_xp ); 69 70 hal_fence(); 71 72 #if (DEBUG_SYS_CLOSEDIR || CONFIG_INSTRUMENTATION_SYSCALLS) 73 uint64_t tm_end = hal_get_cycles(); 74 #endif 75 76 #if DEBUG_SYS_CLOSEDIR 77 if( DEBUG_SYS_CLOSEDIR < tm_end ) 78 printk("\n[%s] thread[%x,%x] exit for DIR <%x> / cycle %d\n", 79 __FUNCTION__, process->pid, this->trdid, dirp, (uint32_t)tm_end ); 80 #endif 81 82 #if CONFIG_INSTRUMENTATION_SYSCALLS 83 hal_atomic_add( &syscalls_cumul_cost[SYS_CLOSEDIR] , tm_end - tm_start ); 84 hal_atomic_add( &syscalls_occurences[SYS_CLOSEDIR] , 1 ); 85 #endif 86 87 return 0; 88 38 89 } // end sys_closedir() -
trunk/kernel/syscalls/sys_display.c
r594 r611 31 31 #include <string.h> 32 32 #include <shared_syscalls.h> 33 #include <vfs.h> 34 #include <mapper.h> 33 35 34 36 #include <syscalls.h> … … 56 58 int sys_display( reg_t type, 57 59 reg_t arg0, 58 reg_t arg1 ) 60 reg_t arg1, 61 reg_t arg2 ) 59 62 { 60 63 … … 278 281 thread_display_busylocks( thread_xp ); 279 282 } 283 ///////////////////////////////// 284 else if( type == DISPLAY_MAPPER ) 285 { 286 xptr_t root_inode_xp; 287 xptr_t inode_xp; 288 cxy_t inode_cxy; 289 vfs_inode_t * inode_ptr; 290 xptr_t mapper_xp; 291 mapper_t * mapper_ptr; 292 293 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 294 295 char * path = (char *)arg0; 296 uint32_t page_id = (uint32_t)arg1; 297 uint32_t nbytes = (uint32_t)arg2; 298 299 // check pathname length 300 if( hal_strlen_from_uspace( path ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 301 { 302 303 #if DEBUG_SYSCALLS_ERROR 304 printk("\n[ERROR] in %s for MAPPER : pathname too long\n", 305 __FUNCTION__ ); 306 #endif 307 this->errno = ENFILE; 308 return -1; 309 } 310 311 // copy pathname in kernel space 312 hal_strcpy_from_uspace( kbuf , path , CONFIG_VFS_MAX_PATH_LENGTH ); 313 314 // compute root inode for pathname 315 if( kbuf[0] == '/' ) // absolute path 316 { 317 // use extended pointer on VFS root inode 318 root_inode_xp = process->vfs_root_xp; 319 } 320 else // relative path 321 { 322 // get cluster and local pointer on reference process 323 xptr_t ref_xp = process->ref_xp; 324 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 325 cxy_t ref_cxy = GET_CXY( ref_xp ); 326 327 // use extended pointer on CWD inode 328 root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) ); 329 } 330 331 // get extended pointer on target inode 332 error = vfs_lookup( root_inode_xp, 333 kbuf, 334 0, 335 &inode_xp, 336 NULL ); 337 if( error ) 338 { 339 340 #if DEBUG_SYSCALLS_ERROR 341 printk("\n[ERROR] in %s for MAPPER : cannot found inode <%s>\n", 342 __FUNCTION__ , kbuf ); 343 #endif 344 this->errno = ENFILE; 345 return -1; 346 } 347 348 // get target inode cluster and local pointer 349 inode_cxy = GET_CXY( inode_xp ); 350 inode_ptr = GET_PTR( inode_xp ); 351 352 // get extended pointer on target mapper 353 mapper_ptr = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) ); 354 mapper_xp = XPTR( inode_cxy , mapper_ptr ); 355 356 // display mapper 357 error = mapper_display_page( mapper_xp , page_id , nbytes , kbuf ); 358 359 if( error ) 360 { 361 362 #if DEBUG_SYSCALLS_ERROR 363 printk("\n[ERROR] in %s for MAPPER : cannot display page %d\n", 364 __FUNCTION__ , page_id ); 365 #endif 366 this->errno = ENFILE; 367 return -1; 368 } 369 } 280 370 //// 281 371 else -
trunk/kernel/syscalls/sys_mmap.c
r594 r611 119 119 // test mmap type : can be FILE / ANON / REMOTE 120 120 121 if( (map_anon == false) && (map_remote == false) ) // FILE 121 /////////////////////////////////////////////////////////// MAP_FILE 122 if( (map_anon == false) && (map_remote == false) ) 122 123 { 123 124 … … 217 218 vseg_cxy = file_cxy; 218 219 } 219 else if ( map_anon ) // MAP_ANON 220 ///////////////////////////////////////////////////////// MAP_ANON 221 else if ( map_anon ) 220 222 { 221 223 mapper_xp = XPTR_NULL; … … 230 232 231 233 } 232 else // MAP_REMOTE 234 /////////////////////////////////////////////////////// MAP_REMOTE 235 else 233 236 { 234 237 mapper_xp = XPTR_NULL; -
trunk/kernel/syscalls/sys_opendir.c
r610 r611 1 1 /* 2 * sys_opendir.c - open adirectory.2 * sys_opendir.c - Open a VFS directory. 3 3 * 4 4 * Author Alain Greiner (2016,2017,2018) … … 22 22 */ 23 23 24 #include <kernel_config.h> 24 25 #include <hal_kernel_types.h> 25 26 #include <hal_uspace.h> 26 27 #include <thread.h> 27 28 #include <process.h> 29 #include <remote_dir.h> 28 30 #include <printk.h> 29 31 #include <errno.h> 32 #include <vseg.h> 30 33 #include <vfs.h> 31 34 #include <syscalls.h> … … 36 39 DIR ** dirp ) 37 40 { 38 error_t error; 39 vseg_t * vseg; // for user space checking 40 xptr_t root_inode_xp; // extended pointer on path root inode 41 41 error_t error; 42 xptr_t root_inode_xp; // extended pointer on path root inode 43 xptr_t inode_xp; // extended pointer on directory inode 44 vfs_inode_t * inode_ptr; // local pointer on directory inode 45 cxy_t inode_cxy; // directory inode cluster 46 uint32_t inode_type; // to check directory inode type 47 xptr_t dir_xp; // extended pointer on remote_dir_t 48 remote_dir_t * dir_ptr; // local pointer on remote_dir_t 49 cxy_t dir_cxy; // remote_dir_t cluster identifier 50 vseg_t * vseg; // for user space checking 51 intptr_t ident; // dirent array pointer in user space 42 52 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 43 53 44 thread_t * this = CURRENT_THREAD;45 process_t * process = this->process;54 thread_t * this = CURRENT_THREAD; // client thread 55 process_t * process = this->process; // client process 46 56 47 57 #if (DEBUG_SYS_OPENDIR || CONFIG_INSTRUMENTATION_SYSCALLS) … … 85 95 #endif 86 96 87 // compute root inode for path 97 // compute root inode for pathname 88 98 if( kbuf[0] == '/' ) // absolute path 89 99 { … … 102 112 } 103 113 104 /* 105 // call the relevant VFS function ??? 106 error = vfs_opendir( root_inode_xp, 107 kbuf ); 114 // get extended pointer on directory inode 115 error = vfs_lookup( root_inode_xp, 116 kbuf, 117 0, 118 &inode_xp, 119 NULL ); 108 120 if( error ) 109 121 { 110 122 111 123 #if DEBUG_SYSCALLS_ERROR 112 printk("\n[ERROR] in %s / thread[%x,%x] : cannot opendirectory <%s>\n",113 __FUNCTION__ , process->pid , this->trdid , pathname);124 printk("\n[ERROR] in %s / thread[%x,%x] : cannot found directory <%s>\n", 125 __FUNCTION__ , process->pid , this->trdid , kbuf ); 114 126 #endif 115 127 this->errno = ENFILE; … … 117 129 } 118 130 119 // copy to user space ??? 120 */ 131 // check inode type 132 inode_ptr = GET_PTR( inode_xp ); 133 inode_cxy = GET_CXY( inode_xp ); 134 inode_type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type ) ); 135 136 if( inode_type != INODE_TYPE_DIR ) 137 { 138 139 #if DEBUG_SYSCALLS_ERROR 140 printk("\n[ERROR] in %s / thread[%x,%x] : cannot found directory <%s>\n", 141 __FUNCTION__ , process->pid , this->trdid , kbuf ); 142 #endif 143 this->errno = ENFILE; 144 return -1; 145 } 146 147 // allocate, initialize, and register a new remote_dir_t structure 148 // in the calling process reference cluster 149 dir_xp = remote_dir_create( inode_xp ); 150 dir_ptr = GET_PTR( dir_xp ); 151 dir_cxy = GET_CXY( dir_xp ); 152 153 if( dir_xp == XPTR_NULL ) 154 { 155 156 #if DEBUG_SYSCALLS_ERROR 157 printk("\n[ERROR] in %s / thread[%x,%x] : cannot create remote_dir for <%s>\n", 158 __FUNCTION__ , process->pid , this->trdid , kbuf ); 159 #endif 160 this->errno = ENFILE; 161 return -1; 162 } 163 164 // get ident from remote_dir structure 165 ident = (intptr_t)hal_remote_lpt( XPTR( dir_cxy , &dir_ptr->ident ) ); 166 167 // set ident value in user buffer 168 hal_copy_to_uspace( dirp , &ident , sizeof(intptr_t) ); 121 169 122 170 hal_fence(); -
trunk/kernel/syscalls/sys_readdir.c
r473 r611 1 1 /* 2 * sys_readdir.c - Read one entry from an open directory.2 * sys_readdir.c - Copy one entry from an open VFS directory to an user buffer. 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 30 30 #include <vfs.h> 31 31 #include <process.h> 32 #include <remote_dir.h> 32 33 #include <syscalls.h> 33 34 #include <shared_syscalls.h> … … 35 36 /////////////////////////////////////// 36 37 int sys_readdir( DIR * dirp, 37 struct dirent ** dentp)38 struct dirent ** buffer ) 38 39 { 39 printk("\n[ERROR] in %s : not implemented yet\n", __FUNCTION__, dirp, dentp ); 40 return -1; 40 error_t error; 41 vseg_t * vseg; // for user space checking of buffer 42 xptr_t dir_xp; // extended pointer on remote_dir_t structure 43 remote_dir_t * dir_ptr; // local pointer on remote_dir_t structure 44 cxy_t dir_cxy; // remote_dir_t stucture cluster identifier 45 struct dirent * direntp; // dirent pointer in user space 46 uint32_t entries; // total number of dirent entries 47 uint32_t current; // current dirent index 48 49 thread_t * this = CURRENT_THREAD; // client thread 50 process_t * process = this->process; // client process 51 52 #if (DEBUG_SYS_READDIR || CONFIG_INSTRUMENTATION_SYSCALLS) 53 uint64_t tm_start = hal_get_cycles(); 54 #endif 55 56 #if DEBUG_SYS_READDIR 57 if( DEBUG_SYS_READDIR < tm_start ) 58 printk("\n[%s] thread[%x,%x] enter / dirp %x / cycle %d\n", 59 __FUNCTION__, process->pid, this->trdid, dirp, (uint32_t)tm_start ); 60 #endif 61 62 // check buffer in user space 63 error = vmm_get_vseg( process , (intptr_t)buffer, &vseg ); 64 65 if( error ) 66 { 67 68 #if DEBUG_SYSCALLS_ERROR 69 printk("\n[ERROR] in %s / thread[%x,%x] : user buffer %x unmapped\n", 70 __FUNCTION__ , process->pid , this->trdid, buffer ); 71 vmm_display( process , false ); 72 #endif 73 this->errno = EINVAL; 74 return -1; 75 } 76 77 // get pointers on remote_dir_t structure from dirp 78 dir_xp = remote_dir_from_ident( (intptr_t)dirp ); 79 dir_ptr = GET_PTR( dir_xp ); 80 dir_cxy = GET_CXY( dir_xp ); 81 82 if( dir_xp == XPTR_NULL ) 83 { 84 85 #if DEBUG_SYSCALLS_ERROR 86 printk("\n[ERROR] in %s / thread[%x,%x] : dirp %x not registered\n", 87 __FUNCTION__ , process->pid , this->trdid, dirp ); 88 #endif 89 this->errno = EBADF; 90 return -1; 91 } 92 93 // get "current" and "entries_nr" values from remote_dir_t structure 94 current = hal_remote_l32( XPTR( dir_cxy , &dir_ptr->current ) ); 95 entries = hal_remote_l32( XPTR( dir_cxy , &dir_ptr->entries ) ); 96 97 // check "current" index 98 if( current >= entries ) 99 { 100 this->errno = 0; 101 return -1; 102 } 103 104 // compute dirent pointer in user space 105 direntp = (struct dirent *)dirp + current; 106 107 #if (DEBUG_SYS_READDIR & 1) 108 if( DEBUG_SYS_READDIR < tm_start ) 109 printk("\n[%s] entries = %d / current = %d / direntp = %x\n", 110 __FUNCTION__, entries, current, direntp ); 111 #endif 112 113 // copy dirent pointer to user buffer 114 hal_copy_to_uspace( buffer, &direntp , sizeof(void *) ); 115 116 // update current index in "remote_dir_t" structure 117 hal_remote_atomic_add( XPTR( dir_cxy , &dir_ptr->current ) , 1 ); 118 119 hal_fence(); 120 121 #if (DEBUG_SYS_READDIR || CONFIG_INSTRUMENTATION_SYSCALLS) 122 uint64_t tm_end = hal_get_cycles(); 123 #endif 124 125 #if DEBUG_SYS_READDIR 126 if( DEBUG_SYS_READDIR < tm_end ) 127 printk("\n[%s] thread[%x,%x] exit / cycle %d\n", 128 __FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end ); 129 #endif 130 131 #if CONFIG_INSTRUMENTATION_SYSCALLS 132 hal_atomic_add( &syscalls_cumul_cost[SYS_READDIR] , tm_end - tm_start ); 133 hal_atomic_add( &syscalls_occurences[SYS_READDIR] , 1 ); 134 #endif 135 136 return 0; 137 41 138 } // end sys_readdir() -
trunk/kernel/syscalls/syscalls.h
r610 r611 328 328 /****************************************************************************************** 329 329 * [23] This function open a directory, that must exist in the file system, returning 330 * a DIR pointer on the dire ctory in user space.331 ****************************************************************************************** 332 * @ pathname : pathname (can be relative or absolute).330 * a DIR pointer on the dirent array in user space. 331 ****************************************************************************************** 332 * @ pathname : [in] pathname (can be relative or absolute). 333 333 * @ dirp : [out] buffer for pointer on user directory (DIR). 334 334 * @ return 0 if success / returns -1 if failure. … … 341 341 * next directory entry in the directory identified by the <dirp> argument. 342 342 ****************************************************************************************** 343 * @ dirp : user pointer identifying the searcheddirectory.344 * @ dentp : [out] buffer for pointer on user direntory entry (dirent).343 * @ dirp : [in] user pointer on dirent array identifying the open directory. 344 * @ buffer : [out] pointer on user buffer for a pointer on dirent in user space. 345 345 * @ return O if success / returns -1 if failure. 346 346 *****************************************************************************************/ 347 347 int sys_readdir( DIR * dirp, 348 struct dirent ** dentp);348 struct dirent ** buffer ); 349 349 350 350 /****************************************************************************************** … … 352 352 * all structures associated with the <dirp> pointer. 353 353 ****************************************************************************************** 354 * @ dirp : user pointer identifying thedirectory.354 * @ dirp : [in] user pointer on dirent array identifying the open directory. 355 355 * @ return 0 if success / returns -1 if failure. 356 356 *****************************************************************************************/ … … 575 575 * [43] This debug function displays on the kernel terminal TXT0 an user defined string, 576 576 * or the current state of a kernel structure, identified by the <type> argument. 577 * The <arg0> and <arg1> arguments depends on the structure type:577 * The <arg0>, <arg1>, and <arg2> arguments depends on the structure type: 578 578 * - DISPLAY_STRING : an user defined string 579 579 * - DISPLAY_VMM : VSL and GPT for a process identified by <pid>. … … 583 583 * - DISPLAY_VFS : all files registered in the VFS cache. 584 584 * - DISPLAY_CHDEV : all registered channel devices. 585 * - DISPLAY_DQDT : all DQDT nodes. 585 * - DISPLAY_DQDT : all DQDT nodes curren values. 586 * - DISPLAY_BUSYLOCKS : all busylocks taken by one thread. 587 * - DISPLAY_MAPPER : one page of a given mapper. 586 588 ****************************************************************************************** 587 589 * type : [in] type of display 588 590 * arg0 : [in] type dependant argument. 589 591 * arg1 : [in] type dependant argument. 592 * arg2 : [in] type dependant argument. 590 593 * @ return 0 if success / return -1 if illegal arguments 591 594 *****************************************************************************************/ 592 595 int sys_display( reg_t type, 593 596 reg_t arg0, 594 reg_t arg1 ); 597 reg_t arg1, 598 reg_t arg2 ); 595 599 596 600 /******************************************************************************************
Note: See TracChangeset
for help on using the changeset viewer.