Changeset 23 for trunk/kernel/syscalls/sys_gettimeofday.c
- Timestamp:
- Jun 18, 2017, 10:06:41 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_gettimeofday.c
r1 r23 1 1 /* 2 * sys_gettimeofday: get current time 3 * 4 * Copyright (c) 2015 UPMC Sorbonne Universites 2 * sys_gettimeofday.c - Get current time 5 3 * 6 * This file is part of ALMOS-kernel.4 * Author Alain Greiner (2016,2017) 7 5 * 8 * ALMOS-kernel is free software; you can redistribute it and/or modify it 6 * Copyright (c) UPMC Sorbonne Universites 7 * 8 * This file is part of ALMOS-MKH. 9 * 10 * ALMOS-MKH is free software; you can redistribute it and/or modify it 9 11 * under the terms of the GNU General Public License as published by 10 12 * the Free Software Foundation; version 2.0 of the License. 11 13 * 12 * 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 13 15 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU … … 16 18 * 17 19 * You should have received a copy of the GNU General Public License 18 * 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, 19 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 22 */ 21 23 22 #include <cpu.h> 24 #include <hal_types.h> 25 #include <hal_uspace.h> 23 26 #include <thread.h> 27 #include <printk.h> 28 #include <errno.h> 29 #include <process.h> 30 #include <vmm.h> 31 #include <core.h> 24 32 #include <time.h> 25 33 26 int sys_gettimeofday(struct timeval *tv, struct timezone *tz) 34 /////////////////////////////////////////// 35 int sys_gettimeofday( struct timeval * tv, 36 struct timezone * tz ) 27 37 { 28 error_t err; 29 uint_t tm_ms, tm_us; 30 struct timeval time; 38 error_t error; 39 paddr_t paddr; 31 40 32 if((tv == NULL) || NOT_IN_USPACE(tv) || NOT_IN_USPACE(tv+sizeof(*tv))) 33 { 34 err = EINVAL; 35 goto fail_inval; 36 } 41 uint32_t tm_s; 42 uint32_t tm_us; 37 43 38 if(tz) 39 return ENOTSUPPORTED; 44 struct timeval k_tv; 40 45 41 cpu_get_time(current_cpu, &tm_ms, &tm_us); 42 time.tv_sec = tm_ms/1000; 43 time.tv_usec = ((tm_ms%1000)*1000)+tm_us; 46 thread_t * this = CURRENT_THREAD; 47 process_t * process = this->process; 44 48 45 //printk(INFO, "%s: [%d] (%u ms) sec %u, usec %u\n", __FUNCTION__, 46 //current_cpu->gid, tm_ms, (uint32_t)time.tv_sec, (uint32_t)time.tv_usec); 49 // check tz (non supported / must be null) 50 if( tz ) 51 { 52 printk("\n[ERROR] in %s for thread %x in process %x : tz argument must be NULL\n", 53 __FUNCTION__ , this->trdid , process->pid ); 54 this->errno = EINVAL; 55 return -1; 56 } 57 58 // check tv 59 error = vmm_v2p_translate( false , tv , &paddr ); 47 60 48 err = cpu_copy_to_uspace(tv, &time, sizeof(time)); 61 if( error ) 62 { 63 printk("\n[ERROR] in %s for thread %x in process %x : tv argument unmapped\n", 64 __FUNCTION__ , this->trdid , process->pid ); 65 this->errno = EINVAL; 66 return -1; 67 } 49 68 50 fail_inval: 51 current_thread->info.errno = err; 52 return err; 53 } 69 // get time from calling core descriptor 70 core_get_time( this->core , &tm_s , &tm_us ); 71 k_tv.tv_sec = tm_s; 72 k_tv.tv_usec = tm_us; 73 74 // copy values to user space 75 hal_copy_to_uspace( tv , &k_tv , sizeof(struct timeval) ); 76 77 hal_wbflush(); 78 79 return 0; 80 81 } // end sys_timeofday()
Note: See TracChangeset
for help on using the changeset viewer.