Skip to content

Commit c954414

Browse files
authored
[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.
1 parent 4e49358 commit c954414

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

compiler-rt/lib/msan/msan_interceptors.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,20 +244,23 @@ INTERCEPTOR(uptr, malloc_usable_size, void *ptr) {
244244
#endif
245245

246246
#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
247-
// This function actually returns a struct by value, but we can't unpoison a
248-
// temporary! The following is equivalent on all supported platforms but
249-
// aarch64 (which uses a different register for sret value). We have a test
250-
// to confirm that.
251-
INTERCEPTOR(void, mallinfo, __sanitizer_struct_mallinfo *sret) {
252-
#ifdef __aarch64__
253-
uptr r8;
254-
asm volatile("mov %0,x8" : "=r" (r8));
255-
sret = reinterpret_cast<__sanitizer_struct_mallinfo*>(r8);
256-
#endif
257-
REAL(memset)(sret, 0, sizeof(*sret));
247+
248+
template <class T>
249+
static NOINLINE void clear_mallinfo(T *sret) {
250+
ENSURE_MSAN_INITED();
251+
internal_memset(sret, 0, sizeof(*sret));
258252
__msan_unpoison(sret, sizeof(*sret));
259253
}
260-
#define MSAN_MAYBE_INTERCEPT_MALLINFO INTERCEPT_FUNCTION(mallinfo)
254+
255+
// Interceptor relies on NRVO and assumes that sret will be pre-allocated in
256+
// caller frame.
257+
INTERCEPTOR(__sanitizer_struct_mallinfo, mallinfo) {
258+
__sanitizer_struct_mallinfo sret;
259+
clear_mallinfo(&sret);
260+
return sret;
261+
}
262+
263+
# define MSAN_MAYBE_INTERCEPT_MALLINFO INTERCEPT_FUNCTION(mallinfo)
261264
#else
262265
#define MSAN_MAYBE_INTERCEPT_MALLINFO
263266
#endif

compiler-rt/test/msan/Linux/mallinfo.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
2-
// UNSUPPORTED: aarch64-target-arch
32

43
#include <assert.h>
54
#include <malloc.h>

0 commit comments

Comments
 (0)