source: trunk/kernel/syscalls/sys_timeofday.c @ 459

Last change on this file since 459 was 457, checked in by alain, 3 years ago

This version modifies the exec syscall and fixes a large number of small bugs.
The version number has been updated (0.1)

File size: 2.2 KB
Line 
1/*
2 * sys_timeofday.c - Get current time
3 *
4 * Author    Alain Greiner (2016,2017,2018)
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
24#include <hal_kernel_types.h>
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>
32#include <shared_syscalls.h>
33
34////////////////////////////////////////
35int sys_timeofday( struct timeval  * tv,
36                   struct timezone * tz )
37{
38        error_t        error;
39    vseg_t       * vseg;
40
41        uint32_t       tm_s;
42    uint32_t       tm_us;
43
44        struct timeval k_tv;
45
46        thread_t  *    this    = CURRENT_THREAD;
47        process_t *    process = this->process;
48
49    // check tz (non supported / must be null)
50    if( tz )
51    {
52
53#if DEBUG_SYSCALLS_ERROR
54printk("\n[ERROR] in %s for thread %x in process %x : tz argument must be NULL\n",
55__FUNCTION__ , this->trdid , process->pid );
56#endif
57        this->errno = EINVAL;
58        return -1;
59    }
60 
61    // check tv
62    error = vmm_get_vseg( process , (intptr_t)tv , &vseg );
63
64    if( error )
65    {
66
67#if DEBUG_SYSCALLS_ERROR
68printk("\n[ERROR] in %s : user buffer tz unmapped / thread %x / process %x\n",
69__FUNCTION__ , (intptr_t)tz , this->trdid , process->pid );
70vmm_display( process , false );
71#endif
72        this->errno = EINVAL;
73        return -1;
74    }
75
76    // get time from calling core descriptor
77    core_get_time( this->core , &tm_s , &tm_us );
78        k_tv.tv_sec  = tm_s;
79        k_tv.tv_usec = tm_us;
80
81    // copy values to user space
82        hal_copy_to_uspace( tv , &k_tv , sizeof(struct timeval) );
83
84    hal_fence();
85
86        return 0; 
87
88}  // end sys_timeofday()
Note: See TracBrowser for help on using the repository browser.