@@ -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
new file mode 100644
@@ -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;
+}