diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp index dfecf6f7c470a..b883c5b2a24de 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 4e58c02df8351..1c07e68e55a7d 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 3c3692969852f..f061218c615a3 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; }