| [50] | 1 | /* | 
|---|
 | 2 |  * sys_timeofday.c - Get current time | 
|---|
 | 3 |  * | 
|---|
| [440] | 4 |  * Author    Alain Greiner (2016,2017,2018)  | 
|---|
| [50] | 5 |  * | 
|---|
 | 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 | 
|---|
 | 11 |  * under the terms of the GNU General Public License as published by | 
|---|
 | 12 |  * the Free Software Foundation; version 2.0 of the License. | 
|---|
 | 13 |  * | 
|---|
 | 14 |  * ALMOS-MKH is distributed in the hope that it will be useful, but | 
|---|
 | 15 |  * WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
 | 16 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|---|
 | 17 |  * General Public License for more details. | 
|---|
 | 18 |  * | 
|---|
 | 19 |  * You should have received a copy of the GNU General Public License | 
|---|
 | 20 |  * along with ALMOS-MKH; if not, write to the Free Software Foundation, | 
|---|
 | 21 |  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 
|---|
 | 22 |  */ | 
|---|
 | 23 |  | 
|---|
| [457] | 24 | #include <hal_kernel_types.h> | 
|---|
| [50] | 25 | #include <hal_uspace.h> | 
|---|
 | 26 | #include <thread.h> | 
|---|
 | 27 | #include <printk.h> | 
|---|
 | 28 | #include <errno.h> | 
|---|
 | 29 | #include <process.h> | 
|---|
 | 30 | #include <vmm.h> | 
|---|
 | 31 | #include <core.h> | 
|---|
| [407] | 32 | #include <shared_syscalls.h> | 
|---|
| [50] | 33 |  | 
|---|
| [506] | 34 | #include <syscalls.h> | 
|---|
 | 35 |  | 
|---|
| [50] | 36 | //////////////////////////////////////// | 
|---|
 | 37 | int sys_timeofday( struct timeval  * tv, | 
|---|
 | 38 |                    struct timezone * tz ) | 
|---|
 | 39 | { | 
|---|
 | 40 |         error_t        error; | 
|---|
| [440] | 41 |     vseg_t       * vseg; | 
|---|
| [50] | 42 |  | 
|---|
 | 43 |         uint32_t       tm_s; | 
|---|
 | 44 |     uint32_t       tm_us; | 
|---|
 | 45 |  | 
|---|
 | 46 |         struct timeval k_tv; | 
|---|
 | 47 |  | 
|---|
 | 48 |         thread_t  *    this    = CURRENT_THREAD; | 
|---|
 | 49 |         process_t *    process = this->process; | 
|---|
 | 50 |  | 
|---|
 | 51 |     // check tz (non supported / must be null) | 
|---|
 | 52 |     if( tz ) | 
|---|
 | 53 |     { | 
|---|
| [440] | 54 |  | 
|---|
 | 55 | #if DEBUG_SYSCALLS_ERROR | 
|---|
 | 56 | printk("\n[ERROR] in %s for thread %x in process %x : tz argument must be NULL\n", | 
|---|
 | 57 | __FUNCTION__ , this->trdid , process->pid ); | 
|---|
 | 58 | #endif | 
|---|
| [50] | 59 |         this->errno = EINVAL; | 
|---|
 | 60 |         return -1; | 
|---|
 | 61 |     } | 
|---|
 | 62 |   | 
|---|
 | 63 |     // check tv | 
|---|
| [440] | 64 |     error = vmm_get_vseg( process , (intptr_t)tv , &vseg ); | 
|---|
| [50] | 65 |  | 
|---|
 | 66 |     if( error ) | 
|---|
 | 67 |     { | 
|---|
| [440] | 68 |  | 
|---|
 | 69 | #if DEBUG_SYSCALLS_ERROR | 
|---|
 | 70 | printk("\n[ERROR] in %s : user buffer tz unmapped / thread %x / process %x\n", | 
|---|
 | 71 | __FUNCTION__ , (intptr_t)tz , this->trdid , process->pid ); | 
|---|
 | 72 | vmm_display( process , false ); | 
|---|
 | 73 | #endif | 
|---|
| [50] | 74 |         this->errno = EINVAL; | 
|---|
 | 75 |         return -1; | 
|---|
 | 76 |     } | 
|---|
 | 77 |  | 
|---|
 | 78 |     // get time from calling core descriptor | 
|---|
 | 79 |     core_get_time( this->core , &tm_s , &tm_us ); | 
|---|
 | 80 |         k_tv.tv_sec  = tm_s; | 
|---|
 | 81 |         k_tv.tv_usec = tm_us; | 
|---|
 | 82 |  | 
|---|
 | 83 |     // copy values to user space | 
|---|
 | 84 |         hal_copy_to_uspace( tv , &k_tv , sizeof(struct timeval) ); | 
|---|
 | 85 |  | 
|---|
| [124] | 86 |     hal_fence(); | 
|---|
| [50] | 87 |  | 
|---|
 | 88 |         return 0;  | 
|---|
 | 89 |  | 
|---|
 | 90 | }  // end sys_timeofday() | 
|---|