Module Name:    src
Committed By:   thorpej
Date:           Thu Dec 17 02:52:41 UTC 2020

Modified Files:
        src/sys/compat/linux/common [thorpej-futex]: linux_sched.h linux_time.c

Log Message:
Re-factor the code that maps the clockid_t in timer_create() and
the flags in timerfd_settime() into separate functions.


To generate a diff of this commit:
cvs rdiff -u -r1.8.64.1 -r1.8.64.2 src/sys/compat/linux/common/linux_sched.h
cvs rdiff -u -r1.39.16.1 -r1.39.16.2 src/sys/compat/linux/common/linux_time.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/compat/linux/common/linux_sched.h
diff -u src/sys/compat/linux/common/linux_sched.h:1.8.64.1 src/sys/compat/linux/common/linux_sched.h:1.8.64.2
--- src/sys/compat/linux/common/linux_sched.h:1.8.64.1	Tue Dec 15 14:07:21 2020
+++ src/sys/compat/linux/common/linux_sched.h	Thu Dec 17 02:52:40 2020
@@ -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	native_to_linux_itimerspec(struct l
 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 */

Index: src/sys/compat/linux/common/linux_time.c
diff -u src/sys/compat/linux/common/linux_time.c:1.39.16.1 src/sys/compat/linux/common/linux_time.c:1.39.16.2
--- src/sys/compat/linux/common/linux_time.c:1.39.16.1	Tue Dec 15 14:07:21 2020
+++ src/sys/compat/linux/common/linux_time.c	Thu Dec 17 02:52:40 2020
@@ -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 @@ linux_sys_clock_nanosleep(struct lwp *l,
 }
 
 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 @@ linux_sys_timer_create(struct lwp *l,
 		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 @@ linux_sys_timerfd_gettime(struct lwp *l,
 }
 
 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 @@ linux_sys_timerfd_settime(struct lwp *l,
 	} */
 	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_sys_timerfd_settime(struct lwp *l,
 	}
 	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)) {

Reply via email to