Skip to content

Commit 961ac58

Browse files
committed
msan: Support free_sized and free_aligned_sized from C23
Signed-off-by: Justin King <[email protected]>
1 parent 874a02f commit 961ac58

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

compiler-rt/lib/msan/msan_interceptors.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "sanitizer_common/sanitizer_glibc_version.h"
3535
#include "sanitizer_common/sanitizer_libc.h"
3636
#include "sanitizer_common/sanitizer_linux.h"
37+
#include "sanitizer_common/sanitizer_platform_interceptors.h"
3738
#include "sanitizer_common/sanitizer_platform_limits_netbsd.h"
3839
#include "sanitizer_common/sanitizer_platform_limits_posix.h"
3940
#include "sanitizer_common/sanitizer_stackdepot.h"
@@ -215,6 +216,35 @@ INTERCEPTOR(void, free, void *ptr) {
215216
MsanDeallocate(&stack, ptr);
216217
}
217218

219+
#if SANITIZER_INTERCEPT_FREE_SIZED
220+
INTERCEPTOR(void, free_sized, void *ptr, uptr size) {
221+
if (UNLIKELY(!ptr))
222+
return;
223+
if (DlsymAlloc::PointerIsMine(ptr))
224+
return DlsymAlloc::Free(ptr);
225+
GET_MALLOC_STACK_TRACE;
226+
MsanDeallocate(&stack, ptr);
227+
}
228+
# define MSAN_MAYBE_INTERCEPT_FREE_SIZED INTERCEPT_FUNCTION(free_sized)
229+
#else
230+
# define MSAN_MAYBE_INTERCEPT_FREE_SIZED
231+
#endif
232+
233+
#if SANITIZER_INTERCEPT_FREE_ALIGNED_SIZED
234+
INTERCEPTOR(void, free_aligned_sized, void *ptr, uptr alignment, uptr size) {
235+
if (UNLIKELY(!ptr))
236+
return;
237+
if (DlsymAlloc::PointerIsMine(ptr))
238+
return DlsymAlloc::Free(ptr);
239+
GET_MALLOC_STACK_TRACE;
240+
MsanDeallocate(&stack, ptr);
241+
}
242+
# define MSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED \
243+
INTERCEPT_FUNCTION(free_aligned_sized)
244+
#else
245+
# define MSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED
246+
#endif
247+
218248
#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
219249
INTERCEPTOR(void, cfree, void *ptr) {
220250
if (UNLIKELY(!ptr))
@@ -1775,6 +1805,8 @@ void InitializeInterceptors() {
17751805
INTERCEPT_FUNCTION(realloc);
17761806
INTERCEPT_FUNCTION(reallocarray);
17771807
INTERCEPT_FUNCTION(free);
1808+
MSAN_MAYBE_INTERCEPT_FREE_SIZED;
1809+
MSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED;
17781810
MSAN_MAYBE_INTERCEPT_CFREE;
17791811
MSAN_MAYBE_INTERCEPT_MALLOC_USABLE_SIZE;
17801812
MSAN_MAYBE_INTERCEPT_MALLINFO;

compiler-rt/test/sanitizer_common/TestCases/Linux/free_aligned_sized.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang -std=c23 -O0 %s -o %t && %run %t
2-
// UNSUPPORTED: asan, hwasan, rtsan, tsan, msan, ubsan
2+
// UNSUPPORTED: asan, hwasan, rtsan, tsan, ubsan
33

44
#include <stddef.h>
55
#include <stdlib.h>

compiler-rt/test/sanitizer_common/TestCases/Linux/free_sized.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang -std=c23 -O0 %s -o %t && %run %t
2-
// UNSUPPORTED: asan, hwasan, rtsan, tsan, msan, ubsan
2+
// UNSUPPORTED: asan, hwasan, rtsan, tsan, ubsan
33

44
#include <stddef.h>
55
#include <stdlib.h>

0 commit comments

Comments
 (0)