diff mbox series

[Valgrind-developers] memcheck/tests: Fix timerfd syscall test

Message ID 20200309233639.1352764-1-raj.khem@gmail.com
State New
Headers show
Series [Valgrind-developers] memcheck/tests: Fix timerfd syscall test | expand

Commit Message

Khem Raj March 9, 2020, 11:36 p.m. UTC
modern libc provides these functions, moreover this also ensures that we
are 64bit time_t safe. Fallback to existing definitions if libc does not
have the implementation or syscall is not defined

Signed-off-by: Khem Raj <raj.khem@gmail.com>

---
 config.h                               |  9 +++++++++
 config.h.in                            |  9 +++++++++
 configure                              |  3 +++
 configure.ac                           |  3 +++
 memcheck/tests/linux/timerfd-syscall.c | 10 ++++++++--
 5 files changed, 32 insertions(+), 2 deletions(-)

-- 
2.25.1



_______________________________________________
Valgrind-developers mailing list
Valgrind-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-developers
diff mbox series

Patch

diff --git a/config.h b/config.h
index 18bb1c2..6f56dbe 100644
--- a/config.h
+++ b/config.h
@@ -311,6 +311,15 @@ 
 /* Define to 1 if <sys/user.h> defines struct user_regs_struct */
 /* #undef HAVE_SYS_USER_REGS */
 
+/* Define to 1 if you have the `timerfd_create' function. */
+#define HAVE_TIMERFD_CREATE 1
+
+/* Define to 1 if you have the `timerfd_gettime' function. */
+#define HAVE_TIMERFD_GETTIME 1
+
+/* Define to 1 if you have the `timerfd_settime' function. */
+#define HAVE_TIMERFD_SETTIME 1
+
 /* can use __thread to define thread-local variables */
 #define HAVE_TLS 1
 
diff --git a/config.h.in b/config.h.in
index 9747421..0f7cfca 100644
--- a/config.h.in
+++ b/config.h.in
@@ -310,6 +310,15 @@ 
 /* Define to 1 if <sys/user.h> defines struct user_regs_struct */
 #undef HAVE_SYS_USER_REGS
 
+/* Define to 1 if you have the `timerfd_create' function. */
+#undef HAVE_TIMERFD_CREATE
+
+/* Define to 1 if you have the `timerfd_gettime' function. */
+#undef HAVE_TIMERFD_GETTIME
+
+/* Define to 1 if you have the `timerfd_settime' function. */
+#undef HAVE_TIMERFD_SETTIME
+
 /* can use __thread to define thread-local variables */
 #undef HAVE_TLS
 
diff --git a/configure b/configure
index e6b79b6..9f5d9aa 100755
--- a/configure
+++ b/configure
@@ -14681,6 +14681,9 @@  for ac_func in      \
         strrchr      \
         strstr       \
         syscall      \
+        timerfd_create    \
+        timerfd_gettime   \
+        timerfd_settime   \
         utimensat    \
         process_vm_readv  \
         process_vm_writev \
diff --git a/configure.ac b/configure.ac
index 8ea157b..44f129c 100755
--- a/configure.ac
+++ b/configure.ac
@@ -4169,6 +4169,9 @@  AC_CHECK_FUNCS([     \
         strrchr      \
         strstr       \
         syscall      \
+        timerfd_create    \
+        timerfd_gettime   \
+        timerfd_settime   \
         utimensat    \
         process_vm_readv  \
         process_vm_writev \
diff --git a/memcheck/tests/linux/timerfd-syscall.c b/memcheck/tests/linux/timerfd-syscall.c
index 74f0682..a024715 100644
--- a/memcheck/tests/linux/timerfd-syscall.c
+++ b/memcheck/tests/linux/timerfd-syscall.c
@@ -54,7 +54,7 @@ 
  * timerfd_* system call numbers introduced in 2.6.23. These constants are
  * not yet in the glibc 2.7 headers, that is why they are defined here.
  */
-#ifndef __NR_timerfd_create
+#if !defined(__NR_timerfd_create) && !defined(HAVE_TIMERFD_CREATE)
 #if defined(__x86_64__)
 #define __NR_timerfd_create  283
 #elif defined(__i386__)
@@ -68,7 +68,7 @@ 
 #endif
 #endif
 
-#ifndef __NR_timerfd_settime
+#if !defined(__NR_timerfd_settime) && !defined(HAVE_TIMERFD_SETTIME)
 #if defined(__x86_64__)
 #define __NR_timerfd_settime 286
 #define __NR_timerfd_gettime 287
@@ -127,21 +127,27 @@  void set_timespec(struct timespec *tmr, unsigned long long ustime)
   tmr->tv_nsec = (long) (1000ULL * (ustime % 1000000ULL));
 }
 
+#if !defined(HAVE_TIMERFD_CREATE)
 int timerfd_create(int clockid, int flags)
 {
   return syscall(__NR_timerfd_create, clockid, flags);
 }
+#endif
 
+#if !defined(HAVE_TIMERFD_SETTIME)
 int timerfd_settime(int ufc, int flags, const struct itimerspec *utmr,
 		    struct itimerspec *otmr)
 {
   return syscall(__NR_timerfd_settime, ufc, flags, utmr, otmr);
 }
+#endif
 
+#if !defined(HAVE_TIMERFD_GETTIME)
 int timerfd_gettime(int ufc, struct itimerspec *otmr)
 {
   return syscall(__NR_timerfd_gettime, ufc, otmr);
 }
+#endif
 
 long waittmr(int tfd, int timeo)
 {