From: Ajeets6 <itachis6234@gmail.com>
To: itachis6234@gmail.com, qemu-devel@nongnu.org
Cc: imp@bsdimp.com, Stacey Son <sson@FreeBSD.org>,
Kyle Evans <kevans@freebsd.org>
Subject: [PATCH 2/7] Create os-time.h and modify os-time.c
Date: Sat, 22 Apr 2023 21:49:29 +0530 [thread overview]
Message-ID: <20230422161934.2311-2-itachis6234@gmail.com> (raw)
In-Reply-To: <20230422161934.2311-1-itachis6234@gmail.com>
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
next prev parent reply other threads:[~2023-04-22 17:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-22 16:19 [PATCH 1/7] Create os-time.c and add t2h_freebsd_timeval Ajeets6
2023-04-22 16:19 ` Ajeets6 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230422161934.2311-2-itachis6234@gmail.com \
--to=itachis6234@gmail.com \
--cc=imp@bsdimp.com \
--cc=kevans@freebsd.org \
--cc=qemu-devel@nongnu.org \
--cc=sson@FreeBSD.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).