Skip to content

Commit 6a63495

Browse files
authored
[msan] Intercept mallinfo2 (#73729)
1 parent 7fb89bf commit 6a63495

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

compiler-rt/lib/msan/msan_interceptors.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,24 @@ static NOINLINE void clear_mallinfo(T *sret) {
252252
__msan_unpoison(sret, sizeof(*sret));
253253
}
254254

255-
// Interceptor relies on NRVO and assumes that sret will be pre-allocated in
255+
// Interceptors use NRVO and assume that sret will be pre-allocated in
256256
// caller frame.
257257
INTERCEPTOR(__sanitizer_struct_mallinfo, mallinfo) {
258258
__sanitizer_struct_mallinfo sret;
259259
clear_mallinfo(&sret);
260260
return sret;
261261
}
262262

263+
INTERCEPTOR(__sanitizer_struct_mallinfo2, mallinfo2) {
264+
__sanitizer_struct_mallinfo2 sret;
265+
clear_mallinfo(&sret);
266+
return sret;
267+
}
263268
# define MSAN_MAYBE_INTERCEPT_MALLINFO INTERCEPT_FUNCTION(mallinfo)
269+
# define MSAN_MAYBE_INTERCEPT_MALLINFO2 INTERCEPT_FUNCTION(mallinfo2)
264270
#else
265271
#define MSAN_MAYBE_INTERCEPT_MALLINFO
272+
# define MSAN_MAYBE_INTERCEPT_MALLINFO2
266273
#endif
267274

268275
#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
@@ -1787,6 +1794,7 @@ void InitializeInterceptors() {
17871794
MSAN_MAYBE_INTERCEPT_CFREE;
17881795
MSAN_MAYBE_INTERCEPT_MALLOC_USABLE_SIZE;
17891796
MSAN_MAYBE_INTERCEPT_MALLINFO;
1797+
MSAN_MAYBE_INTERCEPT_MALLINFO2;
17901798
MSAN_MAYBE_INTERCEPT_MALLOPT;
17911799
MSAN_MAYBE_INTERCEPT_MALLOC_STATS;
17921800
INTERCEPT_FUNCTION(fread);

compiler-rt/lib/sanitizer_common/sanitizer_mallinfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ struct __sanitizer_struct_mallinfo {
3131
int v[10];
3232
};
3333

34+
struct __sanitizer_struct_mallinfo2 {
35+
uptr v[10];
36+
};
37+
3438
#endif
3539

3640
} // namespace __sanitizer

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
int main(void) {
99
struct mallinfo mi = mallinfo();
1010
assert(__msan_test_shadow(&mi, sizeof(mi)) == -1);
11+
12+
struct mallinfo2 mi2 = mallinfo2();
13+
assert(__msan_test_shadow(&mi2, sizeof(mi2)) == -1);
1114
return 0;
1215
}

0 commit comments

Comments
 (0)