diff mbox series

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

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

Commit Message

Khem Raj March 10, 2020, 1 a.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>

---
v2: Check for sys/timerfd.h header instead of funcitons

 configure.ac                           |  1 +
 memcheck/tests/linux/timerfd-syscall.c | 14 +++++++++++---
 2 files changed, 12 insertions(+), 3 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/configure.ac b/configure.ac
index 3336329e9..4c607fb8b 100755
--- a/configure.ac
+++ b/configure.ac
@@ -4206,6 +4206,7 @@  AC_CHECK_HEADERS([       \
         sys/syscall.h    \
         sys/sysnvl.h     \
         sys/time.h       \
+        sys/timerfd.h    \
         sys/types.h      \
         ])
 
diff --git a/memcheck/tests/linux/timerfd-syscall.c b/memcheck/tests/linux/timerfd-syscall.c
index 4af622cc4..9bb697475 100644
--- a/memcheck/tests/linux/timerfd-syscall.c
+++ b/memcheck/tests/linux/timerfd-syscall.c
@@ -44,6 +44,9 @@ 
 #if defined(HAVE_SYS_TIME_H)
 #include <sys/time.h>
 #endif
+#if defined(HAVE_SYS_TIMERFD_H)
+#include <sys/timerfd.h>
+#endif
 #if defined(HAVE_SYS_TYPES_H)
 #include <sys/types.h>
 #endif
@@ -53,7 +56,8 @@ 
  * 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(HAVE_SYS_TIMERFD_H)
+#if !defined(__NR_timerfd_create)
 #if defined(__x86_64__)
 #define __NR_timerfd_create  283
 #elif defined(__i386__)
@@ -66,8 +70,10 @@ 
 #error Cannot detect your architecture!
 #endif
 #endif
+#endif
 
-#ifndef __NR_timerfd_settime
+#if !defined(HAVE_SYS_TIMERFD_H)
+#if !defined(__NR_timerfd_settime)
 #if defined(__x86_64__)
 #define __NR_timerfd_settime 286
 #define __NR_timerfd_gettime 287
@@ -84,7 +90,7 @@ 
 #error Cannot detect your architecture!
 #endif
 #endif
-
+#endif
 
 
 /* Definitions from include/linux/timerfd.h */
@@ -126,6 +132,7 @@  void set_timespec(struct timespec *tmr, unsigned long long ustime)
   tmr->tv_nsec = (long) (1000ULL * (ustime % 1000000ULL));
 }
 
+#if !defined(HAVE_SYS_TIMERFD_H)
 int timerfd_create(int clockid, int flags)
 {
   return syscall(__NR_timerfd_create, clockid, flags);
@@ -141,6 +148,7 @@  int timerfd_gettime(int ufc, struct itimerspec *otmr)
 {
   return syscall(__NR_timerfd_gettime, ufc, otmr);
 }
+#endif
 
 long waittmr(int tfd, int timeo)
 {