Index: lib/scudo/CMakeLists.txt =================================================================== --- lib/scudo/CMakeLists.txt +++ lib/scudo/CMakeLists.txt @@ -11,9 +11,9 @@ 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 Index: lib/scudo/scudo_interceptors.cpp =================================================================== --- lib/scudo/scudo_interceptors.cpp +++ lib/scudo/scudo_interceptors.cpp @@ -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; -} Index: lib/scudo/scudo_malloc.cpp =================================================================== --- lib/scudo/scudo_malloc.cpp +++ lib/scudo/scudo_malloc.cpp @@ -0,0 +1,83 @@ +//===-- scudo_malloc.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" +#include "sanitizer_common/sanitizer_platform_interceptors.h" + +using namespace __scudo; + +extern "C" { +INTERCEPTOR_ATTRIBUTE void free(void *ptr) { + scudoFree(ptr, FromMalloc); +} + +INTERCEPTOR_ATTRIBUTE void *malloc(SIZE_T size) { + return scudoMalloc(size, FromMalloc); +} + +INTERCEPTOR_ATTRIBUTE void *realloc(void *ptr, SIZE_T size) { + return scudoRealloc(ptr, size); +} + +INTERCEPTOR_ATTRIBUTE void *calloc(SIZE_T nmemb, SIZE_T size) { + return scudoCalloc(nmemb, size); +} + +INTERCEPTOR_ATTRIBUTE void *valloc(SIZE_T size) { + return scudoValloc(size); +} + +INTERCEPTOR_ATTRIBUTE +int posix_memalign(void **memptr, SIZE_T alignment, SIZE_T size) { + return scudoPosixMemalign(memptr, alignment, 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_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 + +#if SANITIZER_INTERCEPT_ALIGNED_ALLOC +INTERCEPTOR_ATTRIBUTE void *aligned_alloc(SIZE_T alignment, SIZE_T size) { + return scudoAlignedAlloc(alignment, size); +} +#endif + +#if SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE +INTERCEPTOR_ATTRIBUTE SIZE_T malloc_usable_size(void *ptr) { + return scudoMallocUsableSize(ptr); +} +#endif + +#if SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO +INTERCEPTOR_ATTRIBUTE int mallopt(int cmd, int value) { + return -1; +} +#endif +} // extern "C"