[compiler-rt] [compiler-rt] madvise interception (PR #76562)

David CARLIER via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 29 03:51:32 PST 2023


https://github.com/devnexen updated https://github.com/llvm/llvm-project/pull/76562

>From 9a247d9a89e83c85c59a7ac4b0e5b050b3b521cd Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Fri, 29 Dec 2023 11:32:34 +0000
Subject: [PATCH] [compiler-rt] madvise interception

---
 .../sanitizer_common_interceptors.inc           | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index ba46707516971f..5ef7b98d36f6a3 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -7498,10 +7498,19 @@ INTERCEPTOR(int, mprotect, void *addr, SIZE_T sz, int prot) {
   MprotectMallocZones(addr, prot);
   return REAL(mprotect)(addr, sz, prot);
 }
-#define INIT_MMAP                                                              \
-  COMMON_INTERCEPT_FUNCTION(mmap);                                             \
-  COMMON_INTERCEPT_FUNCTION(munmap);                                           \
-  COMMON_INTERCEPT_FUNCTION(mprotect);
+
+INTERCEPTOR(int, madvise, uptr addr, SIZE_T sz, int advice) {
+  void *ctx;
+  if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED)
+    return (int)internal_madvise(addr, sz, advice);
+  COMMON_INTERCEPTOR_ENTER(ctx, madvise, addr, sz, advice);
+  return REAL(madvise)(addr, sz, advice);
+}
+#  define INIT_MMAP                      \
+    COMMON_INTERCEPT_FUNCTION(mmap);     \
+    COMMON_INTERCEPT_FUNCTION(munmap);   \
+    COMMON_INTERCEPT_FUNCTION(mprotect); \
+    COMMON_INTERCEPT_FUNCTION(madvise);
 #else
 #define INIT_MMAP
 #endif



More information about the llvm-commits mailing list