qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/7] Create os-time.c and add t2h_freebsd_timeval
@ 2023-04-22 16:19 Ajeets6
  2023-04-22 16:19 ` [PATCH 2/7] Create os-time.h and modify os-time.c Ajeets6
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Ajeets6 @ 2023-04-22 16:19 UTC (permalink / raw)
  To: itachis6234, qemu-devel; +Cc: imp, Stacey Son

From: Stacey Son <sson@FreeBSD.org>

os-time.c contains various functions to convert FreeBSD-specific time
structure between host and guest formats

Signed-off-by: Ajeets6 <itachis6234@gmail.com>
Signed-off-by: Stacey Son <sson@FreeBSD.org>
---
 bsd-user/freebsd/os-time.c | 41 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 bsd-user/freebsd/os-time.c

diff --git a/bsd-user/freebsd/os-time.c b/bsd-user/freebsd/os-time.c
new file mode 100644
index 0000000000..ec9f59ded7
--- /dev/null
+++ b/bsd-user/freebsd/os-time.c
@@ -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;
+}
\ No newline at end of file
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/7] Create os-time.h and modify os-time.c
  2023-04-22 16:19 [PATCH 1/7] Create os-time.c and add t2h_freebsd_timeval Ajeets6
@ 2023-04-22 16:19 ` Ajeets6
  2023-04-22 16:19 ` [PATCH 3/7] Add clock_nanosleep Ajeets6
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ajeets6 @ 2023-04-22 16:19 UTC (permalink / raw)
  To: itachis6234, qemu-devel; +Cc: imp, Stacey Son, Kyle Evans

From: Stacey Son <sson@FreeBSD.org>

+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
Co-Authored-By: Kyle Evans <kevans@freebsd.org>
Signed-off-by: Ajeets6 <itachis6234@gmail.com>
Signed-off-by: Kyle Evans <kevans@freebsd.org>
Signed-off-by: Stacey Son <sson@FreeBSD.org>
---
 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

diff --git a/bsd-user/freebsd/os-time.c b/bsd-user/freebsd/os-time.c
index ec9f59ded7..e71eed6519 100644
--- a/bsd-user/freebsd/os-time.c
+++ b/bsd-user/freebsd/os-time.c
@@ -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;
 }
\ No newline at end of file
diff --git a/bsd-user/freebsd/os-time.h b/bsd-user/freebsd/os-time.h
new file mode 100644
index 0000000000..18c9e1dd12
--- /dev/null
+++ b/bsd-user/freebsd/os-time.h
@@ -0,0 +1,44 @@
+/*
+ *  FreeBSD time related system call shims
+ *
+ *  Copyright (c) 2013-2015 Stacey 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 FREEBSD_OS_TIME_H
+#define FREEBSD_OS_TIME_H
+
+
+#include "qemu.h"
+
+
+
+
+/* nanosleep(2) */
+static inline abi_long do_freebsd_nanosleep(abi_long arg1, abi_long arg2)
+{
+    abi_long ret;
+    struct timespec req, rem;
+
+    ret = t2h_freebsd_timespec(&req, arg1);
+    if (!is_error(ret)) {
+        ret = get_errno(safe_nanosleep(&req, &rem));
+        if (ret == -TARGET_EINTR && arg2) {
+            h2t_freebsd_timespec(arg2, &rem);
+        }
+    }
+
+    return ret;
+}
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/7] Add clock_nanosleep
  2023-04-22 16:19 [PATCH 1/7] Create os-time.c and add t2h_freebsd_timeval Ajeets6
  2023-04-22 16:19 ` [PATCH 2/7] Create os-time.h and modify os-time.c Ajeets6
@ 2023-04-22 16:19 ` Ajeets6
  2023-04-22 16:19 ` [PATCH 4/7] Added clock_gettime(2) and clock_getres(2) Ajeets6
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ajeets6 @ 2023-04-22 16:19 UTC (permalink / raw)
  To: itachis6234, qemu-devel; +Cc: imp, Kyle Evans

From: Kyle Evans <kevans@freebsd.org>

+Add clock_nanosleep(2)
Provide sleep interval in nanoseconds and allows to choose which clock
to measure it against.
Signed-off-by: Ajeets6 <itachis6234@gmail.com>
Signed-off-by: Kyle Evans <kevans@freebsd.org>
---
 bsd-user/freebsd/os-time.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/bsd-user/freebsd/os-time.h b/bsd-user/freebsd/os-time.h
index 18c9e1dd12..29d2c8d02a 100644
--- a/bsd-user/freebsd/os-time.h
+++ b/bsd-user/freebsd/os-time.h
@@ -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;
+}
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/7] Added clock_gettime(2) and clock_getres(2)
  2023-04-22 16:19 [PATCH 1/7] Create os-time.c and add t2h_freebsd_timeval Ajeets6
  2023-04-22 16:19 ` [PATCH 2/7] Create os-time.h and modify os-time.c Ajeets6
  2023-04-22 16:19 ` [PATCH 3/7] Add clock_nanosleep Ajeets6
@ 2023-04-22 16:19 ` Ajeets6
  2023-04-22 16:19 ` [PATCH 5/7] Created qemu-os.h for function prototype Ajeets6
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Ajeets6 @ 2023-04-22 16:19 UTC (permalink / raw)
  To: itachis6234, qemu-devel; +Cc: imp, Stacey Son

From: Stacey Son <sson@FreeBSD.org>

+Added clock_gettime(2) which gets the time
+Added clock_getres(2) which finds the resoultion of the specidfied
clock

Signed-off-by: Ajeets6 <itachis6234@gmail.com>
Signed-off-by: Stacey Son <sson@FreeBSD.org>
---
 bsd-user/freebsd/os-time.h | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/bsd-user/freebsd/os-time.h b/bsd-user/freebsd/os-time.h
index 29d2c8d02a..f76744e808 100644
--- a/bsd-user/freebsd/os-time.h
+++ b/bsd-user/freebsd/os-time.h
@@ -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;
+}
\ No newline at end of file
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/7] Created qemu-os.h for function prototype
  2023-04-22 16:19 [PATCH 1/7] Create os-time.c and add t2h_freebsd_timeval Ajeets6
                   ` (2 preceding siblings ...)
  2023-04-22 16:19 ` [PATCH 4/7] Added clock_gettime(2) and clock_getres(2) Ajeets6
@ 2023-04-22 16:19 ` Ajeets6
  2023-04-22 16:19 ` [PATCH 6/7] Added case staements for time functions Ajeets6
  2023-04-22 16:19 ` [PATCH 7/7] Added safe_syscalls " Ajeets6
  5 siblings, 0 replies; 7+ messages in thread
From: Ajeets6 @ 2023-04-22 16:19 UTC (permalink / raw)
  To: itachis6234, qemu-devel; +Cc: imp, Stacey Son

From: Stacey Son <sson@FreeBSD.org>

+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

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Ajeets6 <itachis6234@gmail.com>
---
 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

diff --git a/bsd-user/freebsd/os-time.c b/bsd-user/freebsd/os-time.c
index e71eed6519..5c88e1f13d 100644
--- a/bsd-user/freebsd/os-time.c
+++ b/bsd-user/freebsd/os-time.c
@@ -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)
diff --git a/bsd-user/freebsd/os-time.h b/bsd-user/freebsd/os-time.h
index f76744e808..bd995c8a7b 100644
--- a/bsd-user/freebsd/os-time.h
+++ b/bsd-user/freebsd/os-time.h
@@ -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;
-}
\ No newline at end of file
+}
+
+#endif /* FREEBSD_OS_TIME_H */
diff --git a/bsd-user/freebsd/qemu-os.h b/bsd-user/freebsd/qemu-os.h
new file mode 100644
index 0000000000..0c502ff0e5
--- /dev/null
+++ b/bsd-user/freebsd/qemu-os.h
@@ -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 */
\ No newline at end of file
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 6/7] Added case staements for time functions
  2023-04-22 16:19 [PATCH 1/7] Create os-time.c and add t2h_freebsd_timeval Ajeets6
                   ` (3 preceding siblings ...)
  2023-04-22 16:19 ` [PATCH 5/7] Created qemu-os.h for function prototype Ajeets6
@ 2023-04-22 16:19 ` Ajeets6
  2023-04-22 16:19 ` [PATCH 7/7] Added safe_syscalls " Ajeets6
  5 siblings, 0 replies; 7+ messages in thread
From: Ajeets6 @ 2023-04-22 16:19 UTC (permalink / raw)
  To: itachis6234, qemu-devel; +Cc: imp

From: Warner Losh <imp@bsdimp.com>

+Added cases for nanosleep(2),clock_nanosleep(2),clock_gettime(2) and
clock_getres(2)
+Updated meson.build

Signed-off-by: Warner Losh <imp@bsdimp.com>
Signed-off-by: Ajeets6 <itachis6234@gmail.com>
---
 bsd-user/freebsd/meson.build  |  1 +
 bsd-user/freebsd/os-syscall.c | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/bsd-user/freebsd/meson.build b/bsd-user/freebsd/meson.build
index f87c788e84..2eb0ed4d96 100644
--- a/bsd-user/freebsd/meson.build
+++ b/bsd-user/freebsd/meson.build
@@ -1,4 +1,5 @@
 bsd_user_ss.add(files(
   'os-sys.c',
   'os-syscall.c',
+  'os-time.c',
 ))
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index c8f998ecec..8fd6eb05cb 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -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);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 7/7] Added safe_syscalls for time functions.
  2023-04-22 16:19 [PATCH 1/7] Create os-time.c and add t2h_freebsd_timeval Ajeets6
                   ` (4 preceding siblings ...)
  2023-04-22 16:19 ` [PATCH 6/7] Added case staements for time functions Ajeets6
@ 2023-04-22 16:19 ` Ajeets6
  5 siblings, 0 replies; 7+ messages in thread
From: Ajeets6 @ 2023-04-22 16:19 UTC (permalink / raw)
  To: itachis6234, qemu-devel; +Cc: imp

From: Warner Losh <imp@bsdimp.com>

+Added safe_syscalls

Signed-off-by: Warner Losh <imp@bsdimp.com>
Signed-off-by: Ajeets6 <itachis6234@gmail.com>
---
 bsd-user/freebsd/os-syscall.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 8fd6eb05cb..3d56aff0fd 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -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,
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-04-22 17:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-22 16:19 [PATCH 1/7] Create os-time.c and add t2h_freebsd_timeval Ajeets6
2023-04-22 16:19 ` [PATCH 2/7] Create os-time.h and modify os-time.c Ajeets6
2023-04-22 16:19 ` [PATCH 3/7] Add clock_nanosleep Ajeets6
2023-04-22 16:19 ` [PATCH 4/7] Added clock_gettime(2) and clock_getres(2) Ajeets6
2023-04-22 16:19 ` [PATCH 5/7] Created qemu-os.h for function prototype Ajeets6
2023-04-22 16:19 ` [PATCH 6/7] Added case staements for time functions Ajeets6
2023-04-22 16:19 ` [PATCH 7/7] Added safe_syscalls " Ajeets6

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).