[compiler-rt] [compiler-rt] using more precise type for the Linux's timerfd api int… (PR #77197)

David CARLIER via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 6 05:20:13 PST 2024


https://github.com/devnexen created https://github.com/llvm/llvm-project/pull/77197

…erception.

>From 6598044906c6c47691dc378b5412ed6d6b99dc14 Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Sat, 6 Jan 2024 13:19:15 +0000
Subject: [PATCH] [compiler-rt] using more precise type for the Linux's timerfd
 api interception.

---
 .../sanitizer_common_interceptors.inc                |  6 +++---
 .../sanitizer_platform_limits_linux.cpp              |  3 +++
 .../sanitizer_platform_limits_posix.h                | 12 ++++++++++++
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 77fa1b4965a7a4..a40a771bc301bd 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -6376,8 +6376,8 @@ INTERCEPTOR(char *, getpass, const char *prompt) {
 #endif
 
 #if SANITIZER_INTERCEPT_TIMERFD
-INTERCEPTOR(int, timerfd_settime, int fd, int flags, void *new_value,
-            void *old_value) {
+INTERCEPTOR(int, timerfd_settime, int fd, int flags, __sanitizer_itimerspec *new_value,
+            __sanitizer_itimerspec *old_value) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, timerfd_settime, fd, flags, new_value,
                            old_value);
@@ -6388,7 +6388,7 @@ INTERCEPTOR(int, timerfd_settime, int fd, int flags, void *new_value,
   return res;
 }
 
-INTERCEPTOR(int, timerfd_gettime, int fd, void *curr_value) {
+INTERCEPTOR(int, timerfd_gettime, int fd, __sanitizer_itimerspec *curr_value) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, timerfd_gettime, fd, curr_value);
   int res = REAL(timerfd_gettime)(fd, curr_value);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_linux.cpp
index bf0f355847cb13..189bbfe7283d3d 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_linux.cpp
@@ -53,6 +53,7 @@
 #  if !SANITIZER_ANDROID
 #    include <sys/statfs.h>
 #    include <linux/perf_event.h>
+#    include <linux/time.h>
 #  endif
 
 using namespace __sanitizer;
@@ -81,6 +82,8 @@ COMPILER_CHECK(sizeof(struct __sanitizer_perf_event_attr) <=
                sizeof(struct perf_event_attr));
 CHECK_SIZE_AND_OFFSET(perf_event_attr, type);
 CHECK_SIZE_AND_OFFSET(perf_event_attr, size);
+COMPILER_CHECK(sizeof(struct __sanitizer_itimerspec) ==
+               sizeof(struct itimerspec));
 #endif
 
 COMPILER_CHECK(iocb_cmd_pread == IOCB_CMD_PREAD);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index 34bfef1f7ef456..d0679b8ede5174 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -406,6 +406,18 @@ struct __sanitizer_timeb {
   short dstflag;
 };
 
+#if SANITIZER_LINUX && !SANITIZER_ANDROID
+struct __sanitizer_timespec {
+  __sanitizer_time_t tv_sec;
+  long tv_nsec;
+};
+
+struct __sanitizer_itimerspec {
+  struct __sanitizer_timespec it_interval;
+  struct __sanitizer_timespec it_value;
+};
+#endif
+
 struct __sanitizer_ether_addr {
   u8 octet[6];
 };



More information about the llvm-commits mailing list