1From 5d411fd147d652e9d7bb259f4048693c6e4742aa Mon Sep 17 00:00:00 2001 2From: Khem Raj <raj.khem@gmail.com> 3Date: Mon, 9 Mar 2020 16:30:19 -0700 4Subject: [PATCH] memcheck/tests: Fix timerfd syscall test 5 6modern libc provides these functions, moreover this also ensures that we 7are 64bit time_t safe. Fallback to existing definitions if libc does not 8have the implementation or syscall is not defined 9 10Upstream-Status: Submitted [https://sourceforge.net/p/valgrind/mailman/message/36943897/] 11Signed-off-by: Khem Raj <raj.khem@gmail.com> 12--- 13 config.h.in | 9 +++++++++ 14 configure.ac | 3 +++ 15 memcheck/tests/linux/timerfd-syscall.c | 10 ++++++++-- 16 5 files changed, 32 insertions(+), 2 deletions(-) 17 18--- a/config.h.in 19+++ b/config.h.in 20@@ -301,6 +301,9 @@ 21 /* Define to 1 if you have the <sys/sysnvl.h> header file. */ 22 #undef HAVE_SYS_SYSNVL_H 23 24+/* Define to 1 if you have the <sys/timerfd.h> header file. */ 25+#undef HAVE_SYS_TIMERFD_H 26+ 27 /* Define to 1 if you have the <sys/time.h> header file. */ 28 #undef HAVE_SYS_TIME_H 29 30--- a/configure.ac 31+++ b/configure.ac 32@@ -4098,6 +4098,7 @@ AC_CHECK_HEADERS([ \ 33 sys/syscall.h \ 34 sys/sysnvl.h \ 35 sys/time.h \ 36+ sys/timerfd.h \ 37 sys/types.h \ 38 ]) 39 40--- a/memcheck/tests/linux/timerfd-syscall.c 41+++ b/memcheck/tests/linux/timerfd-syscall.c 42@@ -45,6 +45,9 @@ 43 #if defined(HAVE_SYS_TIME_H) 44 #include <sys/time.h> 45 #endif 46+#if defined(HAVE_SYS_TIMERFD_H) 47+#include <sys/timerfd.h> 48+#endif 49 #if defined(HAVE_SYS_TYPES_H) 50 #include <sys/types.h> 51 #endif 52@@ -54,7 +57,8 @@ 53 * timerfd_* system call numbers introduced in 2.6.23. These constants are 54 * not yet in the glibc 2.7 headers, that is why they are defined here. 55 */ 56-#ifndef __NR_timerfd_create 57+#if !defined(HAVE_SYS_TIMERFD_H) 58+#if !defined(__NR_timerfd_create) 59 #if defined(__x86_64__) 60 #define __NR_timerfd_create 283 61 #elif defined(__i386__) 62@@ -67,8 +71,10 @@ 63 #error Cannot detect your architecture! 64 #endif 65 #endif 66+#endif 67 68-#ifndef __NR_timerfd_settime 69+#if !defined(HAVE_SYS_TIMERFD_H) 70+#if !defined(__NR_timerfd_settime) 71 #if defined(__x86_64__) 72 #define __NR_timerfd_settime 286 73 #define __NR_timerfd_gettime 287 74@@ -85,7 +91,7 @@ 75 #error Cannot detect your architecture! 76 #endif 77 #endif 78- 79+#endif 80 81 82 /* Definitions from include/linux/timerfd.h */ 83@@ -127,6 +133,7 @@ void set_timespec(struct timespec *tmr, 84 tmr->tv_nsec = (long) (1000ULL * (ustime % 1000000ULL)); 85 } 86 87+#if !defined(HAVE_SYS_TIMERFD_H) 88 int timerfd_create(int clockid, int flags) 89 { 90 return syscall(__NR_timerfd_create, clockid, flags); 91@@ -142,6 +149,7 @@ int timerfd_gettime(int ufc, struct itim 92 { 93 return syscall(__NR_timerfd_gettime, ufc, otmr); 94 } 95+#endif 96 97 long waittmr(int tfd, int timeo) 98 { 99