[compiler-rt] r323464 - [scudo] Overhaul malloc related interceptors
Kostya Kortchinsky via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 25 12:42:44 PST 2018
Author: cryptoad
Date: Thu Jan 25 12:42:44 2018
New Revision: 323464
URL: http://llvm.org/viewvc/llvm-project?rev=323464&view=rev
Log:
[scudo] Overhaul malloc related interceptors
Summary:
This is a follow-up to D42506.
There are a few of things that bothered me about `scudo_interceptors.cpp`:
- the filename is a misnomer: it intercepts some functions, but the rest (C++)
is actually in `scudo_new_delete.cpp`. I feel like `scudo_malloc.cpp` is more
appropriate (ASan uses the same naming scheme);
- we do not need "full" interceptors, since we are never accessing the
unsanitized version of the functions, we just need the
`extern "C" INTERCEPTOR_ATTRIBUTE` part of it to just call our functions;
- a couple of functions where duplicated while they could just be `ALIAS`'d;
- use the `SANITIZER_INTERCEPT_*` defines to hide the unneeded interceptors;
- use `SIZE_T` instead of `uptr`: while it's the same behind the curtain,
the former is meant for this use case.
In the end there is no functional change on the currently supported platforms
(Linux, Android).
Reviewers: alekseyshl
Reviewed By: alekseyshl
Subscribers: mgorny, hintonda, delcypher, #sanitizers, llvm-commits
Differential Revision: https://reviews.llvm.org/D42546
Added:
compiler-rt/trunk/lib/scudo/scudo_malloc.cpp
- copied, changed from r323463, compiler-rt/trunk/lib/scudo/scudo_interceptors.cpp
Removed:
compiler-rt/trunk/lib/scudo/scudo_interceptors.cpp
Modified:
compiler-rt/trunk/lib/scudo/CMakeLists.txt
Modified: compiler-rt/trunk/lib/scudo/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/CMakeLists.txt?rev=323464&r1=323463&r2=323464&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/scudo/CMakeLists.txt Thu Jan 25 12:42:44 2018
@@ -11,9 +11,9 @@ set(SCUDO_DYNAMIC_LINK_FLAGS ${SANITIZER
set(SCUDO_SOURCES
scudo_allocator.cpp
- scudo_flags.cpp
scudo_crc32.cpp
- scudo_interceptors.cpp
+ scudo_flags.cpp
+ scudo_malloc.cpp
scudo_termination.cpp
scudo_tsd_exclusive.cpp
scudo_tsd_shared.cpp
Removed: compiler-rt/trunk/lib/scudo/scudo_interceptors.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/scudo_interceptors.cpp?rev=323463&view=auto
==============================================================================
--- compiler-rt/trunk/lib/scudo/scudo_interceptors.cpp (original)
+++ compiler-rt/trunk/lib/scudo/scudo_interceptors.cpp (removed)
@@ -1,70 +0,0 @@
-//===-- scudo_interceptors.cpp ----------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-///
-/// Interceptors for malloc related functions.
-///
-//===----------------------------------------------------------------------===//
-
-#include "scudo_allocator.h"
-
-#include "interception/interception.h"
-
-using namespace __scudo;
-
-INTERCEPTOR(void, free, void *ptr) {
- scudoFree(ptr, FromMalloc);
-}
-
-INTERCEPTOR(void, cfree, void *ptr) {
- scudoFree(ptr, FromMalloc);
-}
-
-INTERCEPTOR(void*, malloc, uptr size) {
- return scudoMalloc(size, FromMalloc);
-}
-
-INTERCEPTOR(void*, realloc, void *ptr, uptr size) {
- return scudoRealloc(ptr, size);
-}
-
-INTERCEPTOR(void*, calloc, uptr nmemb, uptr size) {
- return scudoCalloc(nmemb, size);
-}
-
-INTERCEPTOR(void*, valloc, uptr size) {
- return scudoValloc(size);
-}
-
-INTERCEPTOR(void*, memalign, uptr alignment, uptr size) {
- return scudoMemalign(alignment, size);
-}
-
-INTERCEPTOR(void*, __libc_memalign, uptr alignment, uptr size) {
- return scudoMemalign(alignment, size);
-}
-
-INTERCEPTOR(void*, pvalloc, uptr size) {
- return scudoPvalloc(size);
-}
-
-INTERCEPTOR(void*, aligned_alloc, uptr alignment, uptr size) {
- return scudoAlignedAlloc(alignment, size);
-}
-
-INTERCEPTOR(int, posix_memalign, void **memptr, uptr alignment, uptr size) {
- return scudoPosixMemalign(memptr, alignment, size);
-}
-
-INTERCEPTOR(uptr, malloc_usable_size, void *ptr) {
- return scudoMallocUsableSize(ptr);
-}
-
-INTERCEPTOR(int, mallopt, int cmd, int value) {
- return -1;
-}
Copied: compiler-rt/trunk/lib/scudo/scudo_malloc.cpp (from r323463, compiler-rt/trunk/lib/scudo/scudo_interceptors.cpp)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/scudo_malloc.cpp?p2=compiler-rt/trunk/lib/scudo/scudo_malloc.cpp&p1=compiler-rt/trunk/lib/scudo/scudo_interceptors.cpp&r1=323463&r2=323464&rev=323464&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/scudo_interceptors.cpp (original)
+++ compiler-rt/trunk/lib/scudo/scudo_malloc.cpp Thu Jan 25 12:42:44 2018
@@ -1,4 +1,4 @@
-//===-- scudo_interceptors.cpp ----------------------------------*- C++ -*-===//
+//===-- scudo_malloc.cpp ----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -14,57 +14,70 @@
#include "scudo_allocator.h"
#include "interception/interception.h"
+#include "sanitizer_common/sanitizer_platform_interceptors.h"
using namespace __scudo;
-INTERCEPTOR(void, free, void *ptr) {
+extern "C" {
+INTERCEPTOR_ATTRIBUTE void free(void *ptr) {
scudoFree(ptr, FromMalloc);
}
-INTERCEPTOR(void, cfree, void *ptr) {
- scudoFree(ptr, FromMalloc);
-}
-
-INTERCEPTOR(void*, malloc, uptr size) {
+INTERCEPTOR_ATTRIBUTE void *malloc(SIZE_T size) {
return scudoMalloc(size, FromMalloc);
}
-INTERCEPTOR(void*, realloc, void *ptr, uptr size) {
+INTERCEPTOR_ATTRIBUTE void *realloc(void *ptr, SIZE_T size) {
return scudoRealloc(ptr, size);
}
-INTERCEPTOR(void*, calloc, uptr nmemb, uptr size) {
+INTERCEPTOR_ATTRIBUTE void *calloc(SIZE_T nmemb, SIZE_T size) {
return scudoCalloc(nmemb, size);
}
-INTERCEPTOR(void*, valloc, uptr size) {
+INTERCEPTOR_ATTRIBUTE void *valloc(SIZE_T size) {
return scudoValloc(size);
}
-INTERCEPTOR(void*, memalign, uptr alignment, uptr size) {
- return scudoMemalign(alignment, size);
+INTERCEPTOR_ATTRIBUTE
+int posix_memalign(void **memptr, SIZE_T alignment, SIZE_T size) {
+ return scudoPosixMemalign(memptr, alignment, size);
}
-INTERCEPTOR(void*, __libc_memalign, uptr alignment, uptr size) {
+#if SANITIZER_INTERCEPT_CFREE
+INTERCEPTOR_ATTRIBUTE void cfree(void *ptr) ALIAS("free");
+#endif
+
+#if SANITIZER_INTERCEPT_MEMALIGN
+INTERCEPTOR_ATTRIBUTE void *memalign(SIZE_T alignment, SIZE_T size) {
return scudoMemalign(alignment, size);
}
-INTERCEPTOR(void*, pvalloc, uptr size) {
+INTERCEPTOR_ATTRIBUTE
+void *__libc_memalign(SIZE_T alignment, SIZE_T size) ALIAS("memalign");
+#endif
+
+#if SANITIZER_INTERCEPT_PVALLOC
+INTERCEPTOR_ATTRIBUTE void *pvalloc(SIZE_T size) {
return scudoPvalloc(size);
}
+#endif
-INTERCEPTOR(void*, aligned_alloc, uptr alignment, uptr size) {
+#if SANITIZER_INTERCEPT_ALIGNED_ALLOC
+INTERCEPTOR_ATTRIBUTE void *aligned_alloc(SIZE_T alignment, SIZE_T size) {
return scudoAlignedAlloc(alignment, size);
}
+#endif
-INTERCEPTOR(int, posix_memalign, void **memptr, uptr alignment, uptr size) {
- return scudoPosixMemalign(memptr, alignment, size);
-}
-
-INTERCEPTOR(uptr, malloc_usable_size, void *ptr) {
+#if SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE
+INTERCEPTOR_ATTRIBUTE SIZE_T malloc_usable_size(void *ptr) {
return scudoMallocUsableSize(ptr);
}
+#endif
-INTERCEPTOR(int, mallopt, int cmd, int value) {
+#if SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO
+INTERCEPTOR_ATTRIBUTE int mallopt(int cmd, int value) {
return -1;
}
+#endif
+} // extern "C"
More information about the llvm-commits
mailing list