[1] | 1 | /* |
---|
| 2 | * sys_gettimeofday: get current time |
---|
| 3 | * |
---|
| 4 | * Copyright (c) 2015 UPMC Sorbonne Universites |
---|
| 5 | * |
---|
| 6 | * This file is part of ALMOS-kernel. |
---|
| 7 | * |
---|
| 8 | * ALMOS-kernel is free software; you can redistribute it and/or modify it |
---|
| 9 | * under the terms of the GNU General Public License as published by |
---|
| 10 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 11 | * |
---|
| 12 | * ALMOS-kernel is distributed in the hope that it will be useful, but |
---|
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 15 | * General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * 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, |
---|
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #include <cpu.h> |
---|
| 23 | #include <thread.h> |
---|
| 24 | #include <time.h> |
---|
| 25 | |
---|
| 26 | int sys_gettimeofday(struct timeval *tv, struct timezone *tz) |
---|
| 27 | { |
---|
| 28 | error_t err; |
---|
| 29 | uint_t tm_ms, tm_us; |
---|
| 30 | struct timeval time; |
---|
| 31 | |
---|
| 32 | if((tv == NULL) || NOT_IN_USPACE(tv) || NOT_IN_USPACE(tv+sizeof(*tv))) |
---|
| 33 | { |
---|
| 34 | err = EINVAL; |
---|
| 35 | goto fail_inval; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | if(tz) |
---|
| 39 | return ENOTSUPPORTED; |
---|
| 40 | |
---|
| 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; |
---|
| 44 | |
---|
| 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); |
---|
| 47 | |
---|
| 48 | err = cpu_copy_to_uspace(tv, &time, sizeof(time)); |
---|
| 49 | |
---|
| 50 | fail_inval: |
---|
| 51 | current_thread->info.errno = err; |
---|
| 52 | return err; |
---|
| 53 | } |
---|