Changeset 651 for trunk/kernel/syscalls/sys_lseek.c
- Timestamp:
- Nov 14, 2019, 11:50:09 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_lseek.c
r457 r651 1 1 /* 2 * kern/sys_lseek.c - set the read/write offset of an opened file2 * kern/sys_lseek.c - Kernel function implementing the lseek system call. 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,2019) 5 s 6 * Copyright (c) UPMC Sorbonne Universites 6 7 * 7 * This file is part of ALMOS- kernel.8 * This file is part of ALMOS-MKH. 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 */ … … 31 32 #include <process.h> 32 33 33 //////////////////////////////// 34 int sys_lseek ( uint32_t file_id,35 uint32_t offset,36 uint32_t whence )34 ///////////////////////////////// 35 int sys_lseek ( uint32_t file_id, 36 uint32_t offset, 37 uint32_t whence ) 37 38 { 38 39 error_t error; … … 43 44 process_t * process = this->process; 44 45 46 #if (DEBUG_SYS_LSEEK || CONFIG_INSTRUMENTATION_SYSCALLS) 47 uint64_t tm_start = hal_get_cycles(); 48 #endif 49 50 #if DEBUG_SYS_LSEEK 51 if( DEBUG_SYS_LSEEK < tm_start ) 52 printk("\n[%s] thread[%x,%x] enter / file_id %d / offset %d / cycle %d\n", 53 __FUNCTION__, process->pid, this->trdid, file_id, offset, (uint32_t)tm_start ); 54 #endif 55 45 56 // check file_id argument 46 57 if( file_id >= CONFIG_PROCESS_FILE_MAX_NR ) 47 58 { 48 printk("\n[ERROR] in %s : illegal file descriptor index = %d\n", 49 __FUNCTION__ , file_id ); 59 60 #if DEBUG_SYSCALLS_ERROR 61 printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index %d\n", 62 __FUNCTION__ , process->pid, this->trdid, file_id ); 63 #endif 50 64 this->errno = EBADFD; 51 65 return -1; … … 57 71 if( file_xp == XPTR_NULL ) 58 72 { 59 printk("\n[ERROR] in %s : undefined file descriptor index = %d\n", 60 __FUNCTION__ , file_id ); 73 74 #if DEBUG_SYSCALLS_ERROR 75 printk("\n[ERROR] in %s : thread[%x,%x] undefined fd_id %d\n", 76 __FUNCTION__, process->pid, this->trdid, file_id ); 77 #endif 61 78 this->errno = EBADFD; 62 79 return -1; 63 80 } 64 81 65 /* FIXME: file may be closed in parallel 66 * of seek/read/write/mmap ..etc 67 * so file may be NULL or invalid */ 82 // FIXME: file may be closed in parallel of seek/read/write/mmap ..etc 68 83 69 84 // call relevant VFS function … … 72 87 if( error ) 73 88 { 74 printk("\n[ERROR] in %s : cannot seek file = %d\n", 75 __FUNCTION__ , file_id ); 89 90 #if DEBUG_SYSCALLS_ERROR 91 printk("\n[ERROR] in %s : thread[%x,%x] cannot seek file_id %d\n", 92 __FUNCTION__, process->pid, this->trdid, file_id ); 93 #endif 76 94 this->errno = error; 77 95 return -1; 78 96 } 97 98 #if (DEBUG_SYS_LSEEK || CONFIG_INSTRUMENTATION_SYSCALLS) 99 uint64_t tm_end = hal_get_cycles(); 100 #endif 101 102 #if DEBUG_SYS_LSEEK 103 if( DEBUG_SYS_LSEEK < tm_end ) 104 printk("\n[%s] thread[%x,%x] exit / cycle %d\n", 105 __FUNCTION__ , process->pid, this->trdid, (uint32_t)tm_end ); 106 #endif 107 108 #if CONFIG_INSTRUMENTATION_SYSCALLS 109 hal_atomic_add( &syscalls_cumul_cost[SYS_LSEEK] , tm_end - tm_start ); 110 hal_atomic_add( &syscalls_occurences[SYS_LSEEK] , 1 ); 111 #endif 79 112 80 113 return new_offset;
Note: See TracChangeset
for help on using the changeset viewer.