Skip to content

Commit d54fcb1

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

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

compiler-rt/lib/msan/msan_interceptors.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,34 @@ INTERCEPTOR(void, free, void *ptr) {
215215
MsanDeallocate(&stack, ptr);
216216
}
217217

218+
#if SANITIZER_INTERCEPT_FREE_SIZED
219+
INTERCEPTOR(void, free_sized, void *ptr, uptr size) {
220+
if (UNLIKELY(!ptr))
221+
return;
222+
if (DlsymAlloc::PointerIsMine(ptr))
223+
return DlsymAlloc::Free(ptr);
224+
GET_MALLOC_STACK_TRACE;
225+
MsanDeallocate(&stack, ptr);
226+
}
227+
#define MSAN_MAYBE_INTERCEPT_FREE_SIZED INTERCEPT_FUNCTION(free_sized)
228+
#else
229+
#define MSAN_MAYBE_INTERCEPT_FREE_SIZED
230+
#endif
231+
232+
#if SANITIZER_INTERCEPT_FREE_ALIGNED_SIZED
233+
INTERCEPTOR(void, free_aligned_sized, void *ptr, uptr alignment, uptr size) {
234+
if (UNLIKELY(!ptr))
235+
return;
236+
if (DlsymAlloc::PointerIsMine(ptr))
237+
return DlsymAlloc::Free(ptr);
238+
GET_MALLOC_STACK_TRACE;
239+
MsanDeallocate(&stack, ptr);
240+
}
241+
#define MSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED INTERCEPT_FUNCTION(free_aligned_sized)
242+
#else
243+
#define MSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED
244+
#endif
245+
218246
#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
219247
INTERCEPTOR(void, cfree, void *ptr) {
220248
if (UNLIKELY(!ptr))
@@ -1775,6 +1803,8 @@ void InitializeInterceptors() {
17751803
INTERCEPT_FUNCTION(realloc);
17761804
INTERCEPT_FUNCTION(reallocarray);
17771805
INTERCEPT_FUNCTION(free);
1806+
MSAN_MAYBE_INTERCEPT_FREE_SIZED;
1807+
MSAN_MAYBE_INTERCEPT_FREE_ALIGNED_SIZED;
17781808
MSAN_MAYBE_INTERCEPT_CFREE;
17791809
MSAN_MAYBE_INTERCEPT_MALLOC_USABLE_SIZE;
17801810
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)