git: ce9f8d6ab00c - main - linux(4): Implement timerfd_gettime64 syscall.

From: Dmitry Chagin <dchagin_at_FreeBSD.org>
Date: Wed, 04 May 2022 10:08:20 UTC
The branch main has been updated by dchagin:

URL: https://cgit.FreeBSD.org/src/commit/?id=ce9f8d6ab00c491f84a021b23a28a1484ef817d8

commit ce9f8d6ab00c491f84a021b23a28a1484ef817d8
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2022-05-04 10:06:52 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2022-05-04 10:06:52 +0000

    linux(4): Implement timerfd_gettime64 syscall.
    
    MFC after:              2 weeks
---
 sys/amd64/linux32/linux32_dummy_machdep.c |  1 -
 sys/compat/linux/linux_event.c            | 44 +++++++++++++++++++++++++------
 sys/i386/linux/linux_dummy_machdep.c      |  1 -
 3 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/sys/amd64/linux32/linux32_dummy_machdep.c b/sys/amd64/linux32/linux32_dummy_machdep.c
index 6b264e2891f1..0cc1cd581c32 100644
--- a/sys/amd64/linux32/linux32_dummy_machdep.c
+++ b/sys/amd64/linux32/linux32_dummy_machdep.c
@@ -68,7 +68,6 @@ DUMMY(mq_getsetattr);
 DUMMY(arch_prctl);
 /* Linux 5.0: */
 DUMMY(clock_adjtime64);
-DUMMY(timerfd_gettime64);
 DUMMY(io_pgetevents_time64);
 DUMMY(recvmmsg_time64);
 DUMMY(mq_timedsend_time64);
diff --git a/sys/compat/linux/linux_event.c b/sys/compat/linux/linux_event.c
index 09c6391f88d2..5e62848303f1 100644
--- a/sys/compat/linux/linux_event.c
+++ b/sys/compat/linux/linux_event.c
@@ -901,16 +901,14 @@ linux_timerfd_curval(struct timerfd *tfd, struct itimerspec *ots)
 	}
 }
 
-int
-linux_timerfd_gettime(struct thread *td, struct linux_timerfd_gettime_args *args)
+static int
+linux_timerfd_gettime_common(struct thread *td, int fd, struct itimerspec *ots)
 {
-	struct l_itimerspec lots;
-	struct itimerspec ots;
 	struct timerfd *tfd;
 	struct file *fp;
 	int error;
 
-	error = fget(td, args->fd, &cap_read_rights, &fp);
+	error = fget(td, fd, &cap_read_rights, &fp);
 	if (error != 0)
 		return (error);
 	tfd = fp->f_data;
@@ -920,17 +918,47 @@ linux_timerfd_gettime(struct thread *td, struct linux_timerfd_gettime_args *args
 	}
 
 	mtx_lock(&tfd->tfd_lock);
-	linux_timerfd_curval(tfd, &ots);
+	linux_timerfd_curval(tfd, ots);
 	mtx_unlock(&tfd->tfd_lock);
 
+out:
+	fdrop(fp, td);
+	return (error);
+}
+
+int
+linux_timerfd_gettime(struct thread *td, struct linux_timerfd_gettime_args *args)
+{
+	struct l_itimerspec lots;
+	struct itimerspec ots;
+	int error;
+
+	error = linux_timerfd_gettime_common(td, args->fd, &ots);
+	if (error != 0)
+		return (error);
 	error = native_to_linux_itimerspec(&lots, &ots);
 	if (error == 0)
 		error = copyout(&lots, args->old_value, sizeof(lots));
+	return (error);
+}
 
-out:
-	fdrop(fp, td);
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+int
+linux_timerfd_gettime64(struct thread *td, struct linux_timerfd_gettime64_args *args)
+{
+	struct l_itimerspec64 lots;
+	struct itimerspec ots;
+	int error;
+
+	error = linux_timerfd_gettime_common(td, args->fd, &ots);
+	if (error != 0)
+		return (error);
+	error = native_to_linux_itimerspec64(&lots, &ots);
+	if (error == 0)
+		error = copyout(&lots, args->old_value, sizeof(lots));
 	return (error);
 }
+#endif
 
 static int
 linux_timerfd_settime_common(struct thread *td, int fd, int flags,
diff --git a/sys/i386/linux/linux_dummy_machdep.c b/sys/i386/linux/linux_dummy_machdep.c
index f5852e97ddae..4619fa226a72 100644
--- a/sys/i386/linux/linux_dummy_machdep.c
+++ b/sys/i386/linux/linux_dummy_machdep.c
@@ -70,7 +70,6 @@ DUMMY(vm86old);
 DUMMY(arch_prctl);
 /* Linux 5.0: */
 DUMMY(clock_adjtime64);
-DUMMY(timerfd_gettime64);
 DUMMY(io_pgetevents_time64);
 DUMMY(recvmmsg_time64);
 DUMMY(mq_timedsend_time64);