[sanitizer] support c11 aligned_alloc, Linux only for now

llvm-svn: 212322
This commit is contained in:
Kostya Serebryany 2014-07-04 07:30:34 +00:00
parent 302309f39f
commit 7c163a44aa
8 changed files with 35 additions and 1 deletions

View File

@ -106,6 +106,11 @@ INTERCEPTOR(void*, memalign, uptr boundary, uptr size) {
return asan_memalign(boundary, size, &stack, FROM_MALLOC);
}
INTERCEPTOR(void*, aligned_alloc, uptr boundary, uptr size) {
GET_STACK_TRACE_MALLOC;
return asan_memalign(boundary, size, &stack, FROM_MALLOC);
}
INTERCEPTOR(void*, __libc_memalign, uptr boundary, uptr size) {
GET_STACK_TRACE_MALLOC;
void *res = asan_memalign(boundary, size, &stack, FROM_MALLOC);

View File

@ -105,6 +105,12 @@ INTERCEPTOR(void*, memalign, uptr alignment, uptr size) {
return Allocate(stack, size, alignment, kAlwaysClearMemory);
}
INTERCEPTOR(void*, aligned_alloc, uptr alignment, uptr size) {
ENSURE_LSAN_INITED;
GET_STACK_TRACE;
return Allocate(stack, size, alignment, kAlwaysClearMemory);
}
INTERCEPTOR(int, posix_memalign, void **memptr, uptr alignment, uptr size) {
ENSURE_LSAN_INITED;
GET_STACK_TRACE;

View File

@ -162,6 +162,13 @@ INTERCEPTOR(void *, memalign, SIZE_T boundary, SIZE_T size) {
return ptr;
}
INTERCEPTOR(void *, aligned_alloc, SIZE_T boundary, SIZE_T size) {
GET_MALLOC_STACK_TRACE;
CHECK_EQ(boundary & (boundary - 1), 0);
void *ptr = MsanReallocate(&stack, 0, size, boundary, false);
return ptr;
}
INTERCEPTOR(void *, __libc_memalign, SIZE_T boundary, SIZE_T size) {
GET_MALLOC_STACK_TRACE;
CHECK_EQ(boundary & (boundary - 1), 0);

View File

@ -738,6 +738,11 @@ TSAN_INTERCEPTOR(void*, memalign, uptr align, uptr sz) {
return user_alloc(thr, pc, sz, align);
}
TSAN_INTERCEPTOR(void*, aligned_alloc, uptr align, uptr sz) {
SCOPED_INTERCEPTOR_RAW(memalign, align, sz);
return user_alloc(thr, pc, sz, align);
}
TSAN_INTERCEPTOR(void*, valloc, uptr sz) {
SCOPED_INTERCEPTOR_RAW(valloc, sz);
return user_alloc(thr, pc, sz, GetPageSizeCached());

View File

@ -10,6 +10,7 @@ endif()
if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT ANDROID)
list(APPEND SUPPORTED_TOOLS tsan)
list(APPEND SUPPORTED_TOOLS msan)
list(APPEND SUPPORTED_TOOLS lsan)
endif()
# Create a separate config for each tool we support.

View File

@ -0,0 +1,8 @@
// RUN: %clang -std=c11 -O0 %s -o %t && %run %t
#include <stdlib.h>
extern void *aligned_alloc (size_t alignment, size_t size);
int main() {
volatile void *p = aligned_alloc(128, 1024);
free((void*)p);
return 0;
}

View File

@ -3,7 +3,7 @@
//
// Not yet implemented for TSan.
// https://code.google.com/p/address-sanitizer/issues/detail?id=243
// XFAIL: tsan
// XFAIL: tsan,lsan
#include <sanitizer/common_interface_defs.h>

View File

@ -11,6 +11,8 @@ elif config.tool_name == "tsan":
tool_cflags = ["-fsanitize=thread"]
elif config.tool_name == "msan":
tool_cflags = ["-fsanitize=memory"]
elif config.tool_name == "lsan":
tool_cflags = ["-fsanitize=leak"]
else:
lit_config.fatal("Unknown tool for sanitizer_common tests: %r" % config.tool_name)