Skip to content

[msan] Intercept mallinfo2 #73729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}