[compiler-rt] 6a63495 - [msan] Intercept mallinfo2 (#73729)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 29 11:00:22 PST 2023


Author: Vitaly Buka
Date: 2023-11-29T11:00:17-08:00
New Revision: 6a634953e1a2ec1e434e1ed274e6b37ff7aa643d

URL: https://github.com/llvm/llvm-project/commit/6a634953e1a2ec1e434e1ed274e6b37ff7aa643d
DIFF: https://github.com/llvm/llvm-project/commit/6a634953e1a2ec1e434e1ed274e6b37ff7aa643d.diff

LOG: [msan] Intercept mallinfo2 (#73729)

Added: 
    

Modified: 
    compiler-rt/lib/msan/msan_interceptors.cpp
    compiler-rt/lib/sanitizer_common/sanitizer_mallinfo.h
    compiler-rt/test/msan/Linux/mallinfo.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp
index dfecf6f7c470a6c..b883c5b2a24deb6 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -252,7 +252,7 @@ static NOINLINE void clear_mallinfo(T *sret) {
   __msan_unpoison(sret, sizeof(*sret));
 }
 
-// Interceptor relies on NRVO and assumes that sret will be pre-allocated in
+// Interceptors use NRVO and assume that sret will be pre-allocated in
 // caller frame.
 INTERCEPTOR(__sanitizer_struct_mallinfo, mallinfo) {
   __sanitizer_struct_mallinfo sret;
@@ -260,9 +260,16 @@ INTERCEPTOR(__sanitizer_struct_mallinfo, mallinfo) {
   return sret;
 }
 
+INTERCEPTOR(__sanitizer_struct_mallinfo2, mallinfo2) {
+  __sanitizer_struct_mallinfo2 sret;
+  clear_mallinfo(&sret);
+  return sret;
+}
 #  define MSAN_MAYBE_INTERCEPT_MALLINFO INTERCEPT_FUNCTION(mallinfo)
+#  define MSAN_MAYBE_INTERCEPT_MALLINFO2 INTERCEPT_FUNCTION(mallinfo2)
 #else
 #define MSAN_MAYBE_INTERCEPT_MALLINFO
+#  define MSAN_MAYBE_INTERCEPT_MALLINFO2
 #endif
 
 #if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
@@ -1787,6 +1794,7 @@ void InitializeInterceptors() {
   MSAN_MAYBE_INTERCEPT_CFREE;
   MSAN_MAYBE_INTERCEPT_MALLOC_USABLE_SIZE;
   MSAN_MAYBE_INTERCEPT_MALLINFO;
+  MSAN_MAYBE_INTERCEPT_MALLINFO2;
   MSAN_MAYBE_INTERCEPT_MALLOPT;
   MSAN_MAYBE_INTERCEPT_MALLOC_STATS;
   INTERCEPT_FUNCTION(fread);

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_mallinfo.h b/compiler-rt/lib/sanitizer_common/sanitizer_mallinfo.h
index 4e58c02df835190..1c07e68e55a7d3b 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mallinfo.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mallinfo.h
@@ -31,6 +31,10 @@ struct __sanitizer_struct_mallinfo {
   int v[10];
 };
 
+struct __sanitizer_struct_mallinfo2 {
+  uptr v[10];
+};
+
 #endif
 
 }  // namespace __sanitizer

diff  --git a/compiler-rt/test/msan/Linux/mallinfo.cpp b/compiler-rt/test/msan/Linux/mallinfo.cpp
index 3c3692969852f9b..f061218c615a3a9 100644
--- a/compiler-rt/test/msan/Linux/mallinfo.cpp
+++ b/compiler-rt/test/msan/Linux/mallinfo.cpp
@@ -8,5 +8,8 @@
 int main(void) {
   struct mallinfo mi = mallinfo();
   assert(__msan_test_shadow(&mi, sizeof(mi)) == -1);
+
+  struct mallinfo2 mi2 = mallinfo2();
+  assert(__msan_test_shadow(&mi2, sizeof(mi2)) == -1);
   return 0;
 }


        


More information about the llvm-commits mailing list