Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/thorpej-futex]: src/sys/compat/linux/common Re-factor the code that maps...
details: https://anonhg.NetBSD.org/src/rev/1244b314cd8e
branches: thorpej-futex
changeset: 982892:1244b314cd8e
user: thorpej <thorpej%NetBSD.org@localhost>
date: Thu Dec 17 02:52:40 2020 +0000
description:
Re-factor the code that maps the clockid_t in timer_create() and
the flags in timerfd_settime() into separate functions.
diffstat:
sys/compat/linux/common/linux_sched.h | 6 ++-
sys/compat/linux/common/linux_time.c | 70 +++++++++++++++++++++++++----------
2 files changed, 55 insertions(+), 21 deletions(-)
diffs (141 lines):
diff -r 26303d4e79e2 -r 1244b314cd8e sys/compat/linux/common/linux_sched.h
--- a/sys/compat/linux/common/linux_sched.h Wed Dec 16 03:08:01 2020 +0000
+++ b/sys/compat/linux/common/linux_sched.h Thu Dec 17 02:52:40 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_sched.h,v 1.8.64.1 2020/12/15 14:07:21 thorpej Exp $ */
+/* $NetBSD: linux_sched.h,v 1.8.64.2 2020/12/17 02:52:40 thorpej Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -104,4 +104,8 @@
void linux_to_native_itimerspec(struct itimerspec *,
const struct linux_itimerspec *);
+int linux_to_native_timer_create_clockid(clockid_t *, clockid_t);
+
+int linux_to_native_timerfd_settime_flags(int *, int);
+
#endif /* _LINUX_SCHED_H */
diff -r 26303d4e79e2 -r 1244b314cd8e sys/compat/linux/common/linux_time.c
--- a/sys/compat/linux/common/linux_time.c Wed Dec 16 03:08:01 2020 +0000
+++ b/sys/compat/linux/common/linux_time.c Thu Dec 17 02:52:40 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_time.c,v 1.39.16.1 2020/12/15 14:07:21 thorpej Exp $ */
+/* $NetBSD: linux_time.c,v 1.39.16.2 2020/12/17 02:52:40 thorpej Exp $ */
/*-
* Copyright (c) 2001, 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.39.16.1 2020/12/15 14:07:21 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.39.16.2 2020/12/17 02:52:40 thorpej Exp $");
#include <sys/param.h>
#include <sys/ucred.h>
@@ -319,18 +319,12 @@
}
int
-linux_sys_timer_create(struct lwp *l,
- const struct linux_sys_timer_create_args *uap, register_t *retval)
+linux_to_native_timer_create_clockid(clockid_t *nid, clockid_t lid)
{
- /* {
- syscallarg(clockid_t) clockid;
- syscallarg(struct linux_sigevent *) evp;
- syscallarg(timer_t *) timerid;
- } */
clockid_t id;
int error;
- error = linux_to_native_clockid(&id, SCARG(uap, clockid));
+ error = linux_to_native_clockid(&id, lid);
if (error == 0) {
/*
* We can't create a timer with every sort of clock ID
@@ -351,6 +345,26 @@
default:
return ENOTSUP;
}
+ *nid = id;
+ }
+
+ return error;
+}
+
+int
+linux_sys_timer_create(struct lwp *l,
+ const struct linux_sys_timer_create_args *uap, register_t *retval)
+{
+ /* {
+ syscallarg(clockid_t) clockid;
+ syscallarg(struct linux_sigevent *) evp;
+ syscallarg(timer_t *) timerid;
+ } */
+ clockid_t id;
+ int error;
+
+ error = linux_to_native_timer_create_clockid(&id, SCARG(uap, clockid));
+ if (error == 0) {
error = timer_create1(SCARG(uap, timerid), id,
(void *)SCARG(uap, evp), linux_sigevent_copyin, l);
}
@@ -483,6 +497,27 @@
}
int
+linux_to_native_timerfd_settime_flags(int *nflagsp, int lflags)
+{
+ int nflags = 0;
+
+ if (lflags & ~(LINUX_TFD_TIMER_ABSTIME |
+ LINUX_TFD_TIMER_CANCEL_ON_SET)) {
+ return EINVAL;
+ }
+ if (lflags & LINUX_TFD_TIMER_ABSTIME) {
+ nflags |= TFD_TIMER_ABSTIME;
+ }
+ if (lflags & LINUX_TFD_TIMER_CANCEL_ON_SET) {
+ nflags |= TFD_TIMER_CANCEL_ON_SET;
+ }
+
+ *nflagsp = nflags;
+
+ return 0;
+}
+
+int
linux_sys_timerfd_settime(struct lwp *l,
const struct linux_sys_timerfd_settime_args *uap, register_t *retval)
{
@@ -494,7 +529,7 @@
} */
struct itimerspec nits, oits, *oitsp = NULL;
struct linux_itimerspec lits;
- int nflags = 0;
+ int nflags;
int error;
error = copyin(SCARG(uap, new_value), &lits, sizeof(lits));
@@ -503,15 +538,10 @@
}
linux_to_native_itimerspec(&nits, &lits);
- if (SCARG(uap, flags) & ~(LINUX_TFD_TIMER_ABSTIME |
- LINUX_TFD_TIMER_CANCEL_ON_SET)) {
- return EINVAL;
- }
- if (SCARG(uap, flags) & LINUX_TFD_TIMER_ABSTIME) {
- nflags |= TFD_TIMER_ABSTIME;
- }
- if (SCARG(uap, flags) & LINUX_TFD_TIMER_CANCEL_ON_SET) {
- nflags |= TFD_TIMER_CANCEL_ON_SET;
+ error = linux_to_native_timerfd_settime_flags(&nflags,
+ SCARG(uap, flags));
+ if (error) {
+ return error;
}
if (SCARG(uap, old_value)) {
Home |
Main Index |
Thread Index |
Old Index