summaryrefslogtreecommitdiff
path: root/sys/compat
diff options
context:
space:
mode:
authorPaul Irofti <pirofti@cvs.openbsd.org>2011-02-10 11:58:44 +0000
committerPaul Irofti <pirofti@cvs.openbsd.org>2011-02-10 11:58:44 +0000
commit4521f131ed044a211de3cd530b55258e4e3adbeb (patch)
treec1bf84a5bf0560baf693a3ebb73bda0a2b4378bd /sys/compat
parent7d30e6543f544806659717dc67f52247faa42579 (diff)
Add time related syscalls clock_gettime() and clock_getres().
Okay miod@.
Diffstat (limited to 'sys/compat')
-rw-r--r--sys/compat/linux/files.linux3
-rw-r--r--sys/compat/linux/linux_time.c122
-rw-r--r--sys/compat/linux/linux_types.h7
-rw-r--r--sys/compat/linux/syscalls.master8
4 files changed, 135 insertions, 5 deletions
diff --git a/sys/compat/linux/files.linux b/sys/compat/linux/files.linux
index 6141bf284f9..d6c32a7fdef 100644
--- a/sys/compat/linux/files.linux
+++ b/sys/compat/linux/files.linux
@@ -1,4 +1,4 @@
-# $OpenBSD: files.linux,v 1.14 2007/05/29 03:28:01 tedu Exp $
+# $OpenBSD: files.linux,v 1.15 2011/02/10 11:58:43 pirofti Exp $
# $NetBSD: files.linux,v 1.4 1996/03/08 04:55:59 mycroft Exp $
#
# Config.new file description for machine-independent Linux compat code.
@@ -26,4 +26,5 @@ file compat/linux/linux_socket.c compat_linux
file compat/linux/linux_syscalls.c compat_linux & syscall_debug
file compat/linux/linux_sysent.c compat_linux
file compat/linux/linux_termios.c compat_linux
+file compat/linux/linux_time.c compat_linux
file compat/linux/linux_dummy.c compat_linux
diff --git a/sys/compat/linux/linux_time.c b/sys/compat/linux/linux_time.c
new file mode 100644
index 00000000000..abb6aae0012
--- /dev/null
+++ b/sys/compat/linux/linux_time.c
@@ -0,0 +1,122 @@
+/* $OpenBSD: linux_time.c,v 1.1 2011/02/10 11:58:43 pirofti Exp $ */
+/*
+ * Copyright (c) 2010 Paul Irofti <pirofti@openbsd.org>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/ucred.h>
+#include <sys/mount.h>
+#include <sys/signal.h>
+#include <sys/stdint.h>
+#include <sys/time.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+
+#include <sys/syscallargs.h>
+
+#include <compat/linux/linux_types.h>
+#include <compat/linux/linux_fcntl.h>
+#include <compat/linux/linux_misc.h>
+#include <compat/linux/linux_mmap.h>
+#include <compat/linux/linux_sched.h>
+#include <compat/linux/linux_signal.h>
+#include <compat/linux/linux_syscallargs.h>
+#include <compat/linux/linux_util.h>
+#include <compat/linux/linux_dirent.h>
+#include <compat/linux/linux_emuldata.h>
+
+#define LINUX_CLOCK_REALTIME 0
+#define LINUX_CLOCK_MONOTONIC 1
+#define LINUX_CLOCK_PROCESS_CPUTIME_ID 2
+#define LINUX_CLOCK_THREAD_CPUTIME_ID 3
+#define LINUX_CLOCK_REALTIME_HR 4
+#define LINUX_CLOCK_MONOTONIC_HR 5
+
+static void native_to_linux_timespec(struct l_timespec *, struct timespec *);
+static int linux_to_native_clockid(clockid_t *, clockid_t);
+
+static void
+native_to_linux_timespec(struct l_timespec *ltp, struct timespec *ntp)
+{
+ ltp->tv_sec = ntp->tv_sec;
+ ltp->tv_nsec = ntp->tv_nsec;
+}
+
+static int
+linux_to_native_clockid(clockid_t *n, clockid_t l)
+{
+ switch (l) {
+ case LINUX_CLOCK_REALTIME:
+ *n = CLOCK_REALTIME;
+ break;
+ case LINUX_CLOCK_MONOTONIC:
+ *n = CLOCK_MONOTONIC;
+ break;
+ case LINUX_CLOCK_PROCESS_CPUTIME_ID:
+ case LINUX_CLOCK_THREAD_CPUTIME_ID:
+ case LINUX_CLOCK_REALTIME_HR:
+ case LINUX_CLOCK_MONOTONIC_HR:
+ default:
+ return (EINVAL);
+ break;
+ }
+
+ return (0);
+}
+
+int
+linux_sys_clock_getres(struct proc *p, void *v, register_t *retval)
+{
+ struct linux_sys_clock_getres_args *uap = v;
+ struct sys_clock_getres_args cgr;
+
+ int error;
+
+ if (SCARG(uap, tp) == NULL)
+ return 0;
+
+ error = linux_to_native_clockid(&SCARG(&cgr, clock_id),
+ SCARG(uap, which));
+ if (error != 0)
+ return error;
+
+ SCARG(&cgr, tp) = (struct timespec *)SCARG(uap, tp);
+ return sys_clock_getres(p, &cgr, retval);
+}
+
+int
+linux_sys_clock_gettime(struct proc *p, void *v, register_t *retval)
+{
+ struct linux_sys_clock_gettime_args *uap = v;
+
+ clockid_t clockid = 0;
+
+ struct timespec tp;
+ struct l_timespec ltp;
+
+ int error;
+
+ error = linux_to_native_clockid(&clockid, SCARG(uap, which));
+ if (error != 0)
+ return error;
+
+ error = clock_gettime(p, clockid, &tp);
+ if (error != 0)
+ return error;
+
+ native_to_linux_timespec(&ltp, &tp);
+
+ return (copyout(&ltp, SCARG(uap, tp), sizeof ltp));
+}
diff --git a/sys/compat/linux/linux_types.h b/sys/compat/linux/linux_types.h
index 4c65cd92a3a..bffad3c09d3 100644
--- a/sys/compat/linux/linux_types.h
+++ b/sys/compat/linux/linux_types.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_types.h,v 1.8 2005/05/19 18:27:28 mickey Exp $ */
+/* $OpenBSD: linux_types.h,v 1.9 2011/02/10 11:58:43 pirofti Exp $ */
/* $NetBSD: linux_types.h,v 1.5 1996/05/20 01:59:28 fvdl Exp $ */
/*
@@ -197,4 +197,9 @@ struct linux_stat64 {
unsigned long long lst_ino;
};
+struct l_timespec {
+ linux_time_t tv_sec;
+ long tv_nsec;
+};
+
#endif /* !_LINUX_TYPES_H */
diff --git a/sys/compat/linux/syscalls.master b/sys/compat/linux/syscalls.master
index 3538e7e5bc9..0e75f493436 100644
--- a/sys/compat/linux/syscalls.master
+++ b/sys/compat/linux/syscalls.master
@@ -1,4 +1,4 @@
- $OpenBSD: syscalls.master,v 1.51 2010/06/30 21:54:12 guenther Exp $
+ $OpenBSD: syscalls.master,v 1.52 2011/02/10 11:58:43 pirofti Exp $
; $NetBSD: syscalls.master,v 1.15 1995/12/18 14:35:10 fvdl Exp $
; @(#)syscalls.master 8.1 (Berkeley) 7/19/93
@@ -405,6 +405,8 @@
262 UNIMPL linux_sys_timer_getoverrun
263 UNIMPL linux_sys_timer_delete
264 UNIMPL linux_sys_clock_settime
-265 UNIMPL linux_sys_clock_gettime
-266 UNIMPL linux_sys_clock_getres
+265 STD { int linux_sys_clock_gettime(clockid_t which, \
+ struct l_timespec *tp); }
+266 STD { int linux_sys_clock_getres(clockid_t which, \
+ struct l_timespec *tp); }
267 UNIMPL linux_sys_clock_nanosleep