[llvm-branch-commits] [compiler-rt] [msan] Intercept mallinfo2 (PR #73729)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Nov 28 17:05:22 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Vitaly Buka (vitalybuka)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/73729.diff


3 Files Affected:

- (modified) compiler-rt/lib/msan/msan_interceptors.cpp (+10) 
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_mallinfo.h (+4) 
- (modified) compiler-rt/test/msan/Linux/mallinfo.cpp (+3) 


``````````diff
diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp
index dfecf6f7c470a6c..680b7d397ff0622 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -260,9 +260,18 @@ INTERCEPTOR(__sanitizer_struct_mallinfo, mallinfo) {
   return sret;
 }
 
+// Interceptor relies on NRVO and assumes that sret will be pre-allocated in
+// caller frame.
+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 +1796,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;
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/73729


More information about the llvm-branch-commits mailing list