Ignore:
Timestamp:
Jun 18, 2017, 10:06:41 PM (5 years ago)
Author:
alain
Message:

Introduce syscalls.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/sys_gettimeofday.c

    r1 r23  
    11/*
    2  * sys_gettimeofday: get current time
    3  *
    4  * Copyright (c) 2015 UPMC Sorbonne Universites
     2 * sys_gettimeofday.c - Get current time
    53 *
    6  * This file is part of ALMOS-kernel.
     4 * Author    Alain Greiner (2016,2017)
    75 *
    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
    911 * under the terms of the GNU General Public License as published by
    1012 * the Free Software Foundation; version 2.0 of the License.
    1113 *
    12  * ALMOS-kernel is distributed in the hope that it will be useful, but
     14 * ALMOS-MKH is distributed in the hope that it will be useful, but
    1315 * WITHOUT ANY WARRANTY; without even the implied warranty of
    1416 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     
    1618 *
    1719 * 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,
    1921 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    2022 */
    2123
    22 #include <cpu.h>
     24#include <hal_types.h>
     25#include <hal_uspace.h>
    2326#include <thread.h>
     27#include <printk.h>
     28#include <errno.h>
     29#include <process.h>
     30#include <vmm.h>
     31#include <core.h>
    2432#include <time.h>
    2533
    26 int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
     34///////////////////////////////////////////
     35int sys_gettimeofday( struct timeval  * tv,
     36                      struct timezone * tz )
    2737{
    28         error_t err;
    29         uint_t tm_ms, tm_us;
    30         struct timeval time;
     38        error_t        error;
     39    paddr_t        paddr;
    3140
    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;
    3743
    38         if(tz)
    39                 return ENOTSUPPORTED;
     44        struct timeval k_tv;
    4045
    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;
    4448
    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 );
    4760
    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    }
    4968
    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.