[llvm-commits] [compiler-rt] r161569 - in /compiler-rt/trunk/lib/asan: CMakeLists.txt asan_allocator.cc asan_report.cc asan_report.h
Alexey Samsonov
samsonov at google.com
Thu Aug 9 01:15:46 PDT 2012
Author: samsonov
Date: Thu Aug 9 03:15:46 2012
New Revision: 161569
URL: http://llvm.org/viewvc/llvm-project?rev=161569&view=rev
Log:
[ASan] Move error reports away from ASan allocator. Add new source file to CMakeLists as well
Modified:
compiler-rt/trunk/lib/asan/CMakeLists.txt
compiler-rt/trunk/lib/asan/asan_allocator.cc
compiler-rt/trunk/lib/asan/asan_report.cc
compiler-rt/trunk/lib/asan/asan_report.h
Modified: compiler-rt/trunk/lib/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=161569&r1=161568&r2=161569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/CMakeLists.txt Thu Aug 9 03:15:46 2012
@@ -13,6 +13,7 @@
asan_poisoning.cc
asan_posix.cc
asan_printf.cc
+ asan_report.cc
asan_rtl.cc
asan_stack.cc
asan_stats.cc
Modified: compiler-rt/trunk/lib/asan/asan_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator.cc?rev=161569&r1=161568&r2=161569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator.cc Thu Aug 9 03:15:46 2012
@@ -32,6 +32,7 @@
#include "asan_lock.h"
#include "asan_mapping.h"
#include "asan_stats.h"
+#include "asan_report.h"
#include "asan_thread.h"
#include "asan_thread_registry.h"
#include "sanitizer_common/sanitizer_atomic.h"
@@ -585,7 +586,7 @@
malloc_info.SwallowThreadLocalMallocStorage(this, true);
}
-static void Describe(uptr addr, uptr access_size) {
+void DescribeHeapAddress(uptr addr, uptr access_size) {
AsanChunk *m = malloc_info.FindMallocedOrFreed(addr, access_size);
if (!m) return;
m->DescribeAddress(addr, access_size);
@@ -727,15 +728,9 @@
memory_order_acq_rel);
if (old_chunk_state == CHUNK_QUARANTINE) {
- AsanReport("ERROR: AddressSanitizer attempting double-free on %p:\n", ptr);
- stack->PrintStack();
- Describe((uptr)ptr, 1);
- ShowStatsAndAbort();
+ ReportDoubleFree((uptr)ptr, stack);
} else if (old_chunk_state != CHUNK_ALLOCATED) {
- AsanReport("ERROR: AddressSanitizer attempting free on address "
- "which was not malloc()-ed: %p\n", ptr);
- stack->PrintStack();
- ShowStatsAndAbort();
+ ReportFreeNotMalloced((uptr)ptr, stack);
}
CHECK(old_chunk_state == CHUNK_ALLOCATED);
// With REDZONE==16 m->next is in the user area, otherwise it should be 0.
@@ -884,12 +879,7 @@
if (ptr == 0) return 0;
uptr usable_size = malloc_info.AllocationSize((uptr)ptr);
if (flags()->check_malloc_usable_size && (usable_size == 0)) {
- AsanReport("ERROR: AddressSanitizer attempting to call "
- "malloc_usable_size() for pointer which is "
- "not owned: %p\n", ptr);
- stack->PrintStack();
- Describe((uptr)ptr, 1);
- ShowStatsAndAbort();
+ ReportMallocUsableSizeNotOwned((uptr)ptr, stack);
}
return usable_size;
}
@@ -898,10 +888,6 @@
return malloc_info.AllocationSize((uptr)ptr);
}
-void DescribeHeapAddress(uptr addr, uptr access_size) {
- Describe(addr, access_size);
-}
-
void asan_mz_force_lock() {
malloc_info.ForceLock();
}
@@ -1090,12 +1076,8 @@
uptr allocated_size = malloc_info.AllocationSize((uptr)p);
// Die if p is not malloced or if it is already freed.
if (allocated_size == 0) {
- AsanReport("ERROR: AddressSanitizer attempting to call "
- "__asan_get_allocated_size() for pointer which is "
- "not owned: %p\n", p);
- PRINT_CURRENT_STACK();
- Describe((uptr)p, 1);
- ShowStatsAndAbort();
+ GET_STACK_TRACE_HERE(kStackTraceMax);
+ ReportAsanGetAllocatedSizeNotOwned((uptr)p, &stack);
}
return allocated_size;
}
Modified: compiler-rt/trunk/lib/asan/asan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_report.cc?rev=161569&r1=161568&r2=161569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_report.cc Thu Aug 9 03:15:46 2012
@@ -11,6 +11,7 @@
//
// This file contains error reporting code.
//===----------------------------------------------------------------------===//
+#include "asan_allocator.h"
#include "asan_internal.h"
#include "asan_report.h"
#include "asan_stack.h"
@@ -29,4 +30,37 @@
ShowStatsAndAbort();
}
+void ReportDoubleFree(uptr addr, AsanStackTrace *stack) {
+ AsanReport("ERROR: AddressSanitizer attempting double-free on %p:\n", addr);
+ stack->PrintStack();
+ DescribeHeapAddress(addr, 1);
+ ShowStatsAndAbort();
+}
+
+void ReportFreeNotMalloced(uptr addr, AsanStackTrace *stack) {
+ AsanReport("ERROR: AddressSanitizer attempting free on address "
+ "which was not malloc()-ed: %p\n", addr);
+ stack->PrintStack();
+ ShowStatsAndAbort();
+}
+
+void ReportMallocUsableSizeNotOwned(uptr addr, AsanStackTrace *stack) {
+ AsanReport("ERROR: AddressSanitizer attempting to call "
+ "malloc_usable_size() for pointer which is "
+ "not owned: %p\n", addr);
+ stack->PrintStack();
+ DescribeHeapAddress(addr, 1);
+ ShowStatsAndAbort();
+}
+
+void ReportAsanGetAllocatedSizeNotOwned(uptr addr, AsanStackTrace *stack) {
+ AsanReport("ERROR: AddressSanitizer attempting to call "
+ "__asan_get_allocated_size() for pointer which is "
+ "not owned: %p\n", addr);
+ stack->PrintStack();
+ DescribeHeapAddress(addr, 1);
+ ShowStatsAndAbort();
+}
+
+
} // namespace __asan
Modified: compiler-rt/trunk/lib/asan/asan_report.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_report.h?rev=161569&r1=161568&r2=161569&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.h (original)
+++ compiler-rt/trunk/lib/asan/asan_report.h Thu Aug 9 03:15:46 2012
@@ -16,6 +16,13 @@
namespace __asan {
-void ReportSIGSEGV(uptr pc, uptr sp, uptr bp, uptr addr);
+void NORETURN ReportSIGSEGV(uptr pc, uptr sp, uptr bp, uptr addr);
+
+void NORETURN ReportDoubleFree(uptr addr, AsanStackTrace *stack);
+void NORETURN ReportFreeNotMalloced(uptr addr, AsanStackTrace *stack);
+void NORETURN ReportMallocUsableSizeNotOwned(uptr addr,
+ AsanStackTrace *stack);
+void NORETURN ReportAsanGetAllocatedSizeNotOwned(uptr addr,
+ AsanStackTrace *stack);
} // namespace __asan
More information about the llvm-commits
mailing list