Changeset 604 for trunk/kernel/syscalls
- Timestamp:
- Dec 3, 2018, 12:18:40 PM (6 years ago)
- Location:
- trunk/kernel/syscalls
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/shared_include/shared_pthread.h
r581 r604 98 98 /******************************************************************************************* 99 99 * These typedef and enum define the shared informations related to POSIX barriers. 100 * The following struct is NOT used in the current implementation or the POSIX barrier 101 * that is based on a - non scalable - single shared variable. 102 * It can be used by another implementation, based on a distributed quadtree implemented 103 * in user space, and relying on a busy waiting policy. 100 104 ******************************************************************************************/ 101 105 -
trunk/kernel/syscalls/sys_open.c
r599 r604 117 117 118 118 #if DEBUG_SYS_OPEN 119 if( DEBUG_SYS_OPEN < tm_ start)119 if( DEBUG_SYS_OPEN < tm_end ) 120 120 printk("\n[%s] thread[%x,%x] exit for <%s> / cycle %d\n", 121 121 __FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_end ); -
trunk/kernel/syscalls/sys_read.c
r594 r604 56 56 uint32_t count ) 57 57 { 58 error_t error; 59 vseg_t * vseg; // required for user space checking 60 xptr_t file_xp; // remote file extended pointer 61 uint32_t nbytes; // number of bytes actually read 62 reg_t save_sr; // required to enable IRQs during syscall 63 64 thread_t * this = CURRENT_THREAD; 65 process_t * process = this->process; 66 xptr_t process_owner_xp = process->owner_xp; 58 error_t error; 59 vseg_t * vseg; // required for user space checking 60 xptr_t file_xp; // remote file extended pointer 61 vfs_file_t * file_ptr; // remote file local pointer 62 cxy_t file_cxy; // remote file cluster identifier 63 uint32_t file_type; // file type 64 uint32_t file_offset; // current file offset 65 uint32_t file_attr; // file_attribute 66 vfs_inode_t * inode_ptr; // local pointer on associated inode 67 uint32_t nbytes; // number of bytes actually read 68 reg_t save_sr; // required to enable IRQs during syscall 69 70 thread_t * this = CURRENT_THREAD; 71 process_t * process = this->process; 72 xptr_t process_owner_xp = process->owner_xp; 67 73 68 74 #if (DEBUG_SYS_READ || CONFIG_INSTRUMENTATION_SYSCALLS) … … 85 91 86 92 #if DEBUG_SYSCALLS_ERROR 87 printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index =%d\n",93 printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index %d\n", 88 94 __FUNCTION__ , process->pid, this->trdid, file_id ); 89 95 #endif … … 107 113 } 108 114 115 // get extended pointer on remote file descriptor 116 file_xp = process_fd_get_xptr( process , file_id ); 117 118 if( file_xp == XPTR_NULL ) 119 { 120 121 #if DEBUG_SYSCALLS_ERROR 122 printk("\n[ERROR] in %s : thread[%x,%x] undefined fd_id %d\n", 123 __FUNCTION__, process->pid, this->trdid, file_id ); 124 #endif 125 this->errno = EBADFD; 126 return -1; 127 } 128 129 // get file descriptor cluster and local pointer 130 file_ptr = GET_PTR( file_xp ); 131 file_cxy = GET_CXY( file_xp ); 132 133 // get file type, offset, attributes and associated inode 134 file_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) ); 135 file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) ); 136 inode_ptr = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) ); 137 file_attr = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) ); 138 109 139 // enable IRQs 110 140 hal_enable_irq( &save_sr ); 111 141 112 // get extended pointer on remote file descriptor113 file_xp = process_fd_get_xptr( process , file_id );114 115 if( file_xp == XPTR_NULL )116 {117 118 #if DEBUG_SYSCALLS_ERROR119 printk("\n[ERROR] in %s : thread[%x,%x] undefined fd_id %d\n",120 __FUNCTION__, process->pid, this->trdid, file_id );121 #endif122 this->errno = EBADFD;123 return -1;124 }125 126 // get file descriptor cluster and local pointer127 vfs_file_t * file_ptr = GET_PTR( file_xp );128 cxy_t file_cxy = GET_CXY( file_xp );129 130 // get file type131 vfs_inode_type_t type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) );132 133 142 // action depend on file type 134 if( type == INODE_TYPE_FILE ) // check file readable & read frommapper143 if( file_type == INODE_TYPE_FILE ) // read from file mapper 135 144 { 136 145 // check file readable 137 uint32_t attr = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) ); 138 139 if( (attr & FD_ATTR_READ_ENABLE) == 0 ) 146 if( (file_attr & FD_ATTR_READ_ENABLE) == 0 ) 140 147 { 141 148 … … 144 151 __FUNCTION__, process->pid, this->trdid, file_id ); 145 152 #endif 153 hal_restore_irq( save_sr ); 146 154 this->errno = EBADFD; 147 155 return -1; … … 153 161 vaddr, 154 162 count ); 155 } 156 else if( type == INODE_TYPE_DEV ) // check ownership & read from device 163 if( nbytes != count ) 164 { 165 166 #if DEBUG_SYSCALLS_ERROR 167 printk("\n[ERROR] in %s : thread[%x,‰x] cannot read %d bytes from file %d\n", 168 __FUNCTION__, process->pid, this->trdid, count, file_id ); 169 #endif 170 this->errno = EIO; 171 hal_restore_irq( save_sr ); 172 return -1; 173 } 174 } 175 else if( file_type == INODE_TYPE_DEV ) // read from TXT device 157 176 { 158 177 // get cluster and pointers on TXT_RX chdev … … 192 211 vaddr, 193 212 count ); 194 195 } 196 else // not FILE and not DEV 197 { 198 199 #if DEBUG_SYSCALLS_ERROR 200 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n", 201 __FUNCTION__, vfs_inode_type_str( type ) ); 202 #endif 203 this->errno = EBADFD; 204 return -1; 205 } 206 207 if( nbytes != count ) 208 { 213 if( nbytes != count ) 214 { 209 215 210 216 #if DEBUG_SYSCALLS_ERROR … … 212 218 __FUNCTION__, process->pid, this->trdid, file_id ); 213 219 #endif 214 this->errno = EIO; 215 return -1; 220 this->errno = EIO; 221 hal_restore_irq( save_sr ); 222 return -1; 223 } 224 } 225 else // not FILE and not DEV 226 { 227 228 #if DEBUG_SYSCALLS_ERROR 229 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n", 230 __FUNCTION__, vfs_inode_type_str( file_type ) ); 231 #endif 232 this->errno = EBADFD; 233 hal_restore_irq( save_sr ); 234 return -1; 216 235 } 217 236 -
trunk/kernel/syscalls/sys_rmdir.c
r566 r604 36 36 int sys_rmdir( char * pathname ) 37 37 { 38 error_t error;38 // error_t error; 39 39 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 40 40 … … 45 45 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 46 46 { 47 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 47 48 #if DEBUG_SYSCALLS_ERROR 49 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 50 #endif 48 51 this->errno = ENFILE; 49 52 return -1; … … 59 62 60 63 // get extended pointer on cwd inode 61 xptr_t cwd_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) );64 // xptr_t cwd_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) ); 62 65 63 66 // get the cwd lock in write mode from reference process … … 65 68 66 69 // call the relevant VFS function 67 error = vfs_rmdir( cwd_xp, 68 kbuf ); 70 printk("\n[ERROR] in %s : non implemented yet\n", __FUNCTION__ ); 69 71 70 72 // release the cwd lock 71 73 remote_rwlock_wr_release( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 72 74 73 if( error )74 {75 printk("\n[ERROR] in %s : cannot remove directory %s\n",76 __FUNCTION__ , kbuf );77 this->errno = error;78 return -1;79 }80 81 75 return 0; 82 76 -
trunk/kernel/syscalls/sys_stat.c
r594 r604 156 156 #if DEBUG_SYS_STAT 157 157 if( DEBUG_SYS_STAT < tm_end ) 158 printk("\n[%s] thread[%x,%x] exit for file <%s> / cycle %d\n", 159 __FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_end ); 158 printk("\n[%s] thread[%x,%x] exit for file <%s> / size %d / mode %d / cycle %d\n", 159 __FUNCTION__, process->pid, this->trdid, kbuf, 160 k_stat.st_size, k_stat.st_mode, (uint32_t)tm_end ); 160 161 #endif 161 162 -
trunk/kernel/syscalls/sys_unlink.c
r566 r604 1 1 /* 2 * sys_unlink.c - file unlink 2 * sys_unlink.c - file unlink a file 3 3 * 4 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless 5 * Copyright (c) 2011,2012 UPMC Sorbonne Universites 4 * Author Alain Greiner (2016,2017,2018) 5 * 6 * Copyright (c) UPMC Sorbonne Universites 6 7 * 7 8 * This file is part of ALMOS-kernel. 8 9 * 9 * ALMOS- kernelis free software; you can redistribute it and/or modify it10 * ALMOS-MKH is free software; you can redistribute it and/or modify it 10 11 * under the terms of the GNU General Public License as published by 11 12 * the Free Software Foundation; version 2.0 of the License. 12 13 * 13 * ALMOS- kernelis distributed in the hope that it will be useful, but14 * ALMOS-MKH is distributed in the hope that it will be useful, but 14 15 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU … … 17 18 * 18 19 * You should have received a copy of the GNU General Public License 19 * along with ALMOS- kernel; if not, write to the Free Software Foundation,20 * along with ALMOS-MKH; if not, write to the Free Software Foundation, 20 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 22 */ 22 23 24 #include <kernel_config.h> 23 25 #include <hal_kernel_types.h> 24 26 #include <hal_uspace.h> 27 #include <errno.h> 25 28 #include <vfs.h> 26 29 #include <process.h> … … 39 42 process_t * process = this->process; 40 43 44 #if (DEBUG_SYS_UNLINK || CONFIG_INSTRUMENTATION_SYSCALLS) 45 uint64_t tm_start = hal_get_cycles(); 46 #endif 47 41 48 // check pathname length 42 49 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 43 50 { 44 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 51 52 #if DEBUG_SYSCALLS_ERROR 53 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 54 #endif 45 55 this->errno = ENFILE; 46 56 return -1; … … 50 60 hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 51 61 62 #if DEBUG_SYS_UNLINK 63 if( DEBUG_SYS_UNLINK < tm_start ) 64 printk("\n[%s] thread[%x,%x] enter for <%s> / cycle %d\n", 65 __FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_start ); 66 #endif 67 52 68 // get cluster and local pointer on reference process 53 69 xptr_t ref_xp = process->ref_xp; … … 69 85 if( error ) 70 86 { 71 printk("\n[ERROR] in %s : cannot unlink file/dir %s\n", 72 __FUNCTION__ , pathname ); 87 88 #if DEBUG_SYSCALLS_ERROR 89 printk("\n[ERROR] in %s : cannot unlink file/dir %s\n", __FUNCTION__, kbuf ); 90 #endif 73 91 this->errno = ENFILE; 74 92 return -1; 75 93 } 76 94 95 #if (DEBUG_SYS_UNLINK || CONFIG_INSTRUMENTATION_SYSCALLS) 96 uint64_t tm_end = hal_get_cycles(); 97 #endif 98 99 #if DEBUG_SYS_UNLINK 100 if( DEBUG_SYS_UNLINK < tm_end ) 101 printk("\n[%s] thread[%x,%x] exit for <%s> / cycle %d\n", 102 __FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_end ); 103 #endif 104 105 #if CONFIG_INSTRUMENTATION_SYSCALLS 106 hal_atomic_add( &syscalls_cumul_cost[SYS_UNLINK] , tm_end - tm_start ); 107 hal_atomic_add( &syscalls_occurences[SYS_UNLINK] , 1 ); 108 #endif 109 77 110 return 0; 78 111 -
trunk/kernel/syscalls/sys_write.c
r594 r604 55 55 uint32_t count ) 56 56 { 57 error_t error; 58 vseg_t * vseg; // required for user space checking 59 xptr_t file_xp; // remote file extended pointer 60 uint32_t nbytes; // number of bytes actually written 61 reg_t save_sr; // required to enable IRQs during syscall 62 63 thread_t * this = CURRENT_THREAD; 64 process_t * process = this->process; 57 error_t error; 58 vseg_t * vseg; // required for user space checking 59 xptr_t file_xp; // remote file extended pointer 60 vfs_file_t * file_ptr; // remote file local pointer 61 cxy_t file_cxy; // remote file cluster identifier 62 uint32_t file_type; // file type 63 uint32_t file_offset; // current file offset 64 uint32_t file_attr; // file_attribute 65 vfs_inode_t * inode_ptr; // local pointer on associated inode 66 uint32_t nbytes; // number of bytes actually written 67 reg_t save_sr; // required to enable IRQs during syscall 68 69 thread_t * this = CURRENT_THREAD; 70 process_t * process = this->process; 65 71 66 72 #if (DEBUG_SYS_WRITE || CONFIG_INSTRUMENTATION_SYSCALLS) … … 113 119 114 120 #if DEBUG_SYSCALLS_ERROR 115 printk("\n[ERROR] in %s : thread[%x,%x] undefined file descriptor index= %d\n",121 printk("\n[ERROR] in %s : thread[%x,%x] undefined file descriptor = %d\n", 116 122 __FUNCTION__, process->pid, this->trdid, file_id ); 117 123 #endif … … 121 127 122 128 // get file descriptor cluster and local pointer 123 vfs_file_t * file_ptr = (vfs_file_t *)GET_PTR( file_xp ); 124 cxy_t file_cxy = GET_CXY( file_xp ); 125 126 127 // get file type 128 vfs_inode_type_t type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) ); 129 file_ptr = GET_PTR( file_xp ); 130 file_cxy = GET_CXY( file_xp ); 131 132 // get file type, offset, aatributes, and associated inode 133 file_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) ); 134 file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) ); 135 inode_ptr = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) ); 136 file_attr = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) ); 129 137 130 138 // enable IRQs … … 132 140 133 141 // action depend on file type 134 if( type == INODE_TYPE_FILE ) // check file writable & write tomapper142 if( file_type == INODE_TYPE_FILE ) // write to file mapper 135 143 { 136 144 // check file writable 137 uint32_t attr = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) ); 138 if( (attr & FD_ATTR_WRITE_ENABLE) == 0 ) 145 if( (file_attr & FD_ATTR_WRITE_ENABLE) == 0 ) 139 146 { 140 147 … … 143 150 __FUNCTION__ , process->pid, this->trdid, file_id ); 144 151 #endif 152 hal_restore_irq( save_sr ); 145 153 this->errno = EBADFD; 146 154 return -1; … … 152 160 vaddr, 153 161 count ); 154 } 155 else if( type == INODE_TYPE_DEV ) // write to TXT device 162 if ( nbytes != count ) 163 { 164 165 #if DEBUG_SYSCALLS_ERROR 166 printk("\n[ERROR] in %s : thread[%x,%x] cannot write %d bytes into file %d\n", 167 __FUNCTION__ , process->pid, this->trdid, count, file_id ); 168 #endif 169 hal_restore_irq( save_sr ); 170 this->errno = EIO; 171 return -1; 172 173 } 174 175 // update size field in inode if required 176 xptr_t size_xp = XPTR( file_cxy , &inode_ptr->size ); 177 uint32_t inode_size = hal_remote_l32( size_xp ); 178 if ( (file_offset + count) > inode_size ) 179 { 180 hal_remote_s32( size_xp , file_offset + count ); 181 } 182 } 183 else if( file_type == INODE_TYPE_DEV ) // write to TXT device 156 184 { 157 185 // move count bytes to device 158 186 nbytes = devfs_user_move( false, // from buffer to device 159 file_xp, 160 vaddr, 161 count ); 162 } 163 else // not FILE and not DEV 164 { 165 166 #if DEBUG_SYSCALLS_ERROR 167 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n", 168 __FUNCTION__, vfs_inode_type_str( type ) ); 169 #endif 170 this->errno = EBADFD; 171 return -1; 172 } 173 174 if( nbytes != count ) 175 { 187 file_xp, 188 vaddr, 189 count ); 190 if( nbytes != count ) 191 { 176 192 177 193 #if DEBUG_SYSCALLS_ERROR … … 179 195 __FUNCTION__ , process->pid, this->trdid, file_id ); 180 196 #endif 181 this->errno = EIO; 182 return -1; 197 hal_restore_irq( save_sr ); 198 this->errno = EIO; 199 return -1; 200 } 201 } 202 else // not FILE and not DEV 203 { 204 205 #if DEBUG_SYSCALLS_ERROR 206 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n", 207 __FUNCTION__, vfs_inode_type_str( file_type ) ); 208 #endif 209 hal_restore_irq( save_sr ); 210 this->errno = EBADFD; 211 return -1; 183 212 } 184 213
Note: See TracChangeset
for help on using the changeset viewer.