diff options
author | Vitaly Buka <vitalybuka@google.com> | 2023-11-28 21:09:13 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-28 21:09:13 -0800 |
commit | c954414c0a0b55ad747d5d526100314ecc352c32 (patch) | |
tree | 15c246a628ff7210393bac5a52a12c40ad9db25e | |
parent | 4e49358cdcad9aed232ed1e95eab9ded5e6fd7b1 (diff) | |
download | llvm-c954414c0a0b55ad747d5d526100314ecc352c32.zip llvm-c954414c0a0b55ad747d5d526100314ecc352c32.tar.gz llvm-c954414c0a0b55ad747d5d526100314ecc352c32.tar.bz2 |
[msan][aarch64] Fix mallinfo interceptor (#73728)
Not sure how the previous implementation supposed to work, but the test
was disabled.
This implementation works for x86_64 and aarch64.
-rw-r--r-- | compiler-rt/lib/msan/msan_interceptors.cpp | 27 | ||||
-rw-r--r-- | 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 bac7564..dfecf6f 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 b2021c5..3c36929 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> |