Skip to content

Commit

Permalink
[msan] Intercept mallinfo2 (#73729)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalybuka committed Nov 29, 2023
1 parent 7fb89bf commit 6a63495
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion compiler-rt/lib/msan/msan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,24 @@ 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;
clear_mallinfo(&sret);
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
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_mallinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ struct __sanitizer_struct_mallinfo {
int v[10];
};

struct __sanitizer_struct_mallinfo2 {
uptr v[10];
};

#endif

} // namespace __sanitizer
Expand Down
3 changes: 3 additions & 0 deletions compiler-rt/test/msan/Linux/mallinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 6a63495

Please sign in to comment.