Create os-time.c and add t2h_freebsd_timeval
PATCH 1/7 Create os-time.c and add t2h_freebsd_timeval
From: Stacey Son <[email protected]>
os-time.c contains various functions to convert FreeBSD-specific time structure between host and guest formats
--- bsd-user/freebsd/os-time.c | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 bsd-user/freebsd/os-time.c
bsd-user/freebsd/os-time.c new file +41 -0
@@ -0,0 +1,41 @@ +/* +* FreeBSD time related system call helpers +* +* Copyright (c) 2013-15 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +/* +* FreeBSD time conversion functions +*/ +#include <errno.h> +#include <time.h> +#include <sys/types.h> +#include "qemu.h" + + +abi_long t2h_freebsd_timeval (struct timeval *tv,abi_ulong target_tv_addr) +{ +struct target_freebsd_timeval *target_tv; + +if (!lock_user_struct (VERIFY_READ , target_tv, target_tv_addr,0 )) { +return -TARGET_EFAULT ; + } +__get_user (tv->tv_sec, &target_tv->tv_sec); +__get_user (tv->tv_usec, &target_tv->tv_usec); +unlock_user_struct (target_tv, target_tv_addr,1 ); + +return 0 ; +}
Signature · 1 line
2.34.1
PATCH 2/7 Create os-time.h and modify os-time.c
From: Stacey Son <[email protected]>
+add nanosleep(2) in os-time.h
+add t2h_freebsd_timeval and h2t_freebsd_timeval time conversion functions
-remove t2h_freebsd_timeval in os-time.c
--- bsd-user/freebsd/os-time.c | 29 ++++++++++++++++++------- bsd-user/freebsd/os-time.h | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 bsd-user/freebsd/os-time.h
bsd-user/freebsd/os-time.c +21 -8
@@ -20,22 +20,35 @@/* * FreeBSD time conversion functions */ -#include <errno.h> +#include "qemu/osdep.h" #include <time.h> -#include <sys/types.h> #include "qemu.h" -abi_long t2h_freebsd_timeval (struct timeval *tv,abi_ulong target_tv_addr) +abi_long t2h_freebsd_timespec (struct timespec *ts,abi_ulong target_ts_addr) { -struct target_freebsd_timeval *target_tv; +struct target_freebsd_timespec *target_ts; -if (!lock_user_struct (VERIFY_READ , target_tv, target_tv_addr,0 )) { +if (!lock_user_struct (VERIFY_READ , target_ts, target_ts_addr,0 )) {return -TARGET_EFAULT ; } -__get_user (tv->tv_sec, &target_tv->tv_sec); -__get_user (tv->tv_usec, &target_tv->tv_usec); -unlock_user_struct (target_tv, target_tv_addr,1 ); +__get_user (ts->tv_sec, &target_ts->tv_sec); +__get_user (ts->tv_nsec, &target_ts->tv_nsec); +unlock_user_struct (target_ts, target_ts_addr,1 ); + +return 0 ; +} + +abi_long h2t_freebsd_timespec (abi_ulong target_ts_addr,struct timespec *ts) +{ +struct target_freebsd_timespec *target_ts; + +if (!lock_user_struct (VERIFY_WRITE , target_ts, target_ts_addr,0 )) { +return -TARGET_EFAULT ; + } +__put_user (ts->tv_sec, &target_ts->tv_sec); +__put_user (ts->tv_nsec, &target_ts->tv_nsec); +unlock_user_struct (target_ts, target_ts_addr,1 );return 0 ; }
bsd-user/freebsd/os-time.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 3/7 Add clock_nanosleep
In reply to Ajeets6From: Kyle Evans <[email protected]>
+Add clock_nanosleep(2)
Provide sleep interval in nanoseconds and allows to choose which clock to measure it against.
--- bsd-user/freebsd/os-time.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
bsd-user/freebsd/os-time.h +21 -0
@@ -42,3 +42,24 @@ static inline abi_long do_freebsd_nanosleep(abi_long arg1, abi_long arg2)return ret; } +/* clock_nanosleep(2) */ +static inline abi_long do_freebsd_clock_nanosleep (abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4) +{ +struct timespec req, rem; +abi_long ret; +int clkid, flags; + + clkid = arg1; +/* XXX Translate? */ + flags = arg2; + ret =t2h_freebsd_timespec (&req, arg3); +if (!is_error (ret)) { + ret =get_errno (safe_clock_nanosleep (clkid, flags, &req, &rem)); +if (ret == -TARGET_EINTR && arg4) { +h2t_freebsd_timespec (arg4, &rem); + } + } + +return ret; +}
Signature · 1 line
2.34.1
PATCH 4/7 Added clock_gettime(2) and clock_getres(2)
In reply to Ajeets6From: Stacey Son <[email protected]>
+Added clock_gettime(2) which gets the time
+Added clock_getres(2) which finds the resoultion of the specidfied clock
--- bsd-user/freebsd/os-time.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
bsd-user/freebsd/os-time.h +32 -0
@@ -63,3 +63,35 @@ static inline abi_long do_freebsd_clock_nanosleep(abi_long arg1, abi_long arg2,return ret; } + +/* clock_gettime(2) */ +static inline abi_long do_freebsd_clock_gettime (abi_long arg1,abi_long arg2) +{ +abi_long ret; +struct timespec ts; + + ret =get_errno (clock_gettime (arg1, &ts)); +if (!is_error (ret)) { +if (h2t_freebsd_timespec (arg2, &ts)) { +return -TARGET_EFAULT ; + } + } + +return ret; +} + +/* clock_getres(2) */ +static inline abi_long do_freebsd_clock_getres (abi_long arg1,abi_long arg2) +{ +abi_long ret; +struct timespec ts; + + ret =get_errno (clock_getres (arg1, &ts)); +if (!is_error (ret)) { +if (h2t_freebsd_timespec (arg2, &ts)) { +return -TARGET_EFAULT ; + } + } + +return ret; +}
Signature · 1 line
2.34.1
PATCH 5/7 Created qemu-os.h for function prototype
In reply to Ajeets6From: Stacey Son <[email protected]>
+Added t2h_freebsd_timespec and h2t_freebsd_timespec function protype in qemu-is.h
+included qemu-os.h in os-time.c and os-time.h
--- bsd-user/freebsd/os-time.c | 2 ++ bsd-user/freebsd/os-time.h | 5 ++++- bsd-user/freebsd/qemu-os.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 bsd-user/freebsd/qemu-os.h
bsd-user/freebsd/os-time.c +2 -0
@@ -23,6 +23,8 @@#include "qemu/osdep.h" #include <time.h> #include "qemu.h" +#include "qemu-os.h" +abi_long t2h_freebsd_timespec (struct timespec *ts,abi_ulong target_ts_addr)
bsd-user/freebsd/os-time.h +4 -1
@@ -22,6 +22,7 @@#include "qemu.h" +#include "qemu-os.h"
@@ -94,4 +95,6 @@ static inline abi_long do_freebsd_clock_getres(abi_long arg1, abi_long arg2) }return ret; -} +} + +#endif /* FREEBSD_OS_TIME_H */
bsd-user/freebsd/qemu-os.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* FreeBSD conversion extern declarations +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef QEMU_OS_H +#define QEMU_OS_H + +#include <sys/timex.h> + +/* os-time.c */ +abi_long t2h_freebsd_timespec (struct timespec *ts,abi_ulong target_ts_addr); +abi_long h2t_freebsd_timespec (abi_ulong target_ts_addr,struct timespec *ts); + + +#endif /* QEMU_OS_H */
Signature · 1 line
2.34.1
PATCH 6/7 Added case staements for time functions
In reply to Ajeets6From: Warner Losh <[email protected]>
+Added cases for nanosleep(2),clock_nanosleep(2),clock_gettime(2) and clock_getres(2)
+Updated meson.build
--- bsd-user/freebsd/meson.build | 1 + bsd-user/freebsd/os-syscall.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+)
bsd-user/freebsd/meson.build +1 -0
@@ -1,4 +1,5 @@ bsd_user_ss.add(files( 'os-sys.c', 'os-syscall.c', + 'os-time.c', ))
bsd-user/freebsd/os-syscall.c +20 -0
@@ -46,6 +46,8 @@#include "bsd-file.h" #include "bsd-proc.h" +/* *BSD dependent syscall shims */ +#include "os-time.h" /* I/O */ safe_syscall3(int, open, const char *, path, int, flags, mode_t, mode);
@@ -507,6 +509,24 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,case TARGET_FREEBSD_NR_sysarch:/* sysarch(2) */ ret =do_freebsd_sysarch (cpu_env, arg1, arg2);break ; +/* +* time related system calls. +*/ +case TARGET_FREEBSD_NR_nanosleep:/* nanosleep(2) */ + ret =do_freebsd_nanosleep (arg1, arg2); +break ; + +case TARGET_FREEBSD_NR_clock_nanosleep:/* clock_nanosleep(2) */ + ret =do_freebsd_clock_nanosleep (arg1, arg2, arg3, arg4); +break ; + +case TARGET_FREEBSD_NR_clock_gettime:/* clock_gettime(2) */ + ret =do_freebsd_clock_gettime (arg1, arg2); +break ; + +case TARGET_FREEBSD_NR_clock_getres:/* clock_getres(2) */ + ret =do_freebsd_clock_getres (arg1, arg2); +break ;default :qemu_log_mask (LOG_UNIMP ,"Unsupported syscall: %d\n" , num);
Signature · 1 line
2.34.1
PATCH 7/7 Added safe_syscalls for time functions.
In reply to Ajeets6From: Warner Losh <[email protected]>
+Added safe_syscalls
--- bsd-user/freebsd/os-syscall.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
bsd-user/freebsd/os-syscall.c +10 -0
@@ -49,6 +49,16 @@/* *BSD dependent syscall shims */ #include "os-time.h" +/* used in os-time */ +safe_syscall2(int, nanosleep, const struct timespec *, rqtp, struct timespec *, + rmtp); +safe_syscall4 (int, clock_nanosleep, clockid_t, clock_id, int, flags, + const struct timespec *, rqtp, struct timespec *, rmtp); + +safe_syscall6(int, kevent, int, kq, const struct kevent *, changelist, + int, nchanges, struct kevent *, eventlist, int, nevents, + const struct timespec *, timeout); +/* I/O */ safe_syscall3(int, open, const char *, path, int, flags, mode_t, mode); safe_syscall4(int, openat, int, fd, const char *, path, int, flags, mode_t,
Signature · 1 line
2.34.1