[flang] [libcxx] [clang] [llvm] [libc] [compiler-rt] [msan] Intercept mallinfo2 (PR #73729)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 28 22:23:27 PST 2023
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/73729
>From 0aee7158c8edf7929ba6b0d324edde21eba30093 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Tue, 28 Nov 2023 17:04:44 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
=?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
[skip ci]
---
compiler-rt/lib/msan/msan_interceptors.cpp | 27 ++++++++++++----------
compiler-rt/test/msan/Linux/mallinfo.cpp | 1 -
2 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp
index bac756424e28ca7..dfecf6f7c470a6c 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cpp
+++ b/compiler-rt/lib/msan/msan_interceptors.cpp
@@ -244,20 +244,23 @@ INTERCEPTOR(uptr, malloc_usable_size, void *ptr) {
#endif
#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
-// This function actually returns a struct by value, but we can't unpoison a
-// temporary! The following is equivalent on all supported platforms but
-// aarch64 (which uses a different register for sret value). We have a test
-// to confirm that.
-INTERCEPTOR(void, mallinfo, __sanitizer_struct_mallinfo *sret) {
-#ifdef __aarch64__
- uptr r8;
- asm volatile("mov %0,x8" : "=r" (r8));
- sret = reinterpret_cast<__sanitizer_struct_mallinfo*>(r8);
-#endif
- REAL(memset)(sret, 0, sizeof(*sret));
+
+template <class T>
+static NOINLINE void clear_mallinfo(T *sret) {
+ ENSURE_MSAN_INITED();
+ internal_memset(sret, 0, sizeof(*sret));
__msan_unpoison(sret, sizeof(*sret));
}
-#define MSAN_MAYBE_INTERCEPT_MALLINFO INTERCEPT_FUNCTION(mallinfo)
+
+// Interceptor relies on NRVO and assumes that sret will be pre-allocated in
+// caller frame.
+INTERCEPTOR(__sanitizer_struct_mallinfo, mallinfo) {
+ __sanitizer_struct_mallinfo sret;
+ clear_mallinfo(&sret);
+ return sret;
+}
+
+# define MSAN_MAYBE_INTERCEPT_MALLINFO INTERCEPT_FUNCTION(mallinfo)
#else
#define MSAN_MAYBE_INTERCEPT_MALLINFO
#endif
diff --git a/compiler-rt/test/msan/Linux/mallinfo.cpp b/compiler-rt/test/msan/Linux/mallinfo.cpp
index b2021c5df3cec84..3c3692969852f9b 100644
--- a/compiler-rt/test/msan/Linux/mallinfo.cpp
+++ b/compiler-rt/test/msan/Linux/mallinfo.cpp
@@ -1,5 +1,4 @@
// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
-// UNSUPPORTED: aarch64-target-arch
#include <assert.h>
#include <malloc.h>
>From ba2ec86a29f83e2553ffc34a45028cbb5c72d1d8 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Tue, 28 Nov 2023 17:06:04 -0800
Subject: [PATCH 2/2] dedup comment
Created using spr 1.3.4
---
compiler-rt/lib/msan/msan_interceptors.cpp | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp
index 680b7d397ff0622..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,8 +260,6 @@ 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);
More information about the llvm-commits
mailing list