diff options
| author | Alexey Samsonov <samsonov@google.com> | 2012-08-09 12:15:40 +0000 |
|---|---|---|
| committer | Alexey Samsonov <samsonov@google.com> | 2012-08-09 12:15:40 +0000 |
| commit | f343eb7df43d4b56fe2bf2d759385ea56ec3f8ef (patch) | |
| tree | adce0c7d6aa3950ca5432ff2762d2f86fb67fb02 /compiler-rt | |
| parent | b53a670817761f0e7ab9e61b86ca311358489591 (diff) | |
| download | bcm5719-llvm-f343eb7df43d4b56fe2bf2d759385ea56ec3f8ef.tar.gz bcm5719-llvm-f343eb7df43d4b56fe2bf2d759385ea56ec3f8ef.zip | |
[ASan] Move mac-specific error reports to asan_report.cc as well
llvm-svn: 161576
Diffstat (limited to 'compiler-rt')
| -rw-r--r-- | compiler-rt/lib/asan/asan_malloc_mac.cc | 43 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/asan_report.cc | 46 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/asan_report.h | 8 |
3 files changed, 64 insertions, 33 deletions
diff --git a/compiler-rt/lib/asan/asan_malloc_mac.cc b/compiler-rt/lib/asan/asan_malloc_mac.cc index 1a6c84052a0..c38b4e937d7 100644 --- a/compiler-rt/lib/asan/asan_malloc_mac.cc +++ b/compiler-rt/lib/asan/asan_malloc_mac.cc @@ -24,6 +24,7 @@ #include "asan_interceptors.h" #include "asan_internal.h" #include "asan_mac.h" +#include "asan_report.h" #include "asan_stack.h" // Similar code is used in Google Perftools, @@ -152,20 +153,9 @@ void *mz_valloc(malloc_zone_t *zone, size_t size) { return asan_memalign(kPageSize, size, &stack); } -void print_zone_for_ptr(void *ptr) { - malloc_zone_t *orig_zone = malloc_zone_from_ptr(ptr); - if (orig_zone) { - if (orig_zone->zone_name) { - AsanPrintf("malloc_zone_from_ptr(%p) = %p, which is %s\n", - ptr, orig_zone, orig_zone->zone_name); - } else { - AsanPrintf("malloc_zone_from_ptr(%p) = %p, which doesn't have a name\n", - ptr, orig_zone); - } - } else { - AsanPrintf("malloc_zone_from_ptr(%p) = 0\n", ptr); - } -} +#define GET_ZONE_FOR_PTR(ptr) \ + malloc_zone_t *zone_ptr = malloc_zone_from_ptr(ptr); \ + const char *zone_name = (zone_ptr == 0) ? 0 : zone_ptr->zone_name void ALWAYS_INLINE free_common(void *context, void *ptr) { if (!ptr) return; @@ -174,12 +164,9 @@ void ALWAYS_INLINE free_common(void *context, void *ptr) { asan_free(ptr, &stack); } else { // Let us just leak this memory for now. - AsanPrintf("free_common(%p) -- attempting to free unallocated memory.\n" - "AddressSanitizer is ignoring this error on Mac OS now.\n", - ptr); - print_zone_for_ptr(ptr); GET_STACK_TRACE_HERE_FOR_FREE(ptr); - stack.PrintStack(); + GET_ZONE_FOR_PTR(ptr); + WarnMacFreeUnallocated((uptr)ptr, (uptr)zone_ptr, zone_name, &stack); return; } } @@ -205,14 +192,9 @@ void *mz_realloc(malloc_zone_t *zone, void *ptr, size_t size) { // We can't recover from reallocating an unknown address, because // this would require reading at most |size| bytes from // potentially unaccessible memory. - AsanPrintf("mz_realloc(%p) -- attempting to realloc unallocated memory.\n" - "This is an unrecoverable problem, exiting now.\n", - ptr); - print_zone_for_ptr(ptr); GET_STACK_TRACE_HERE_FOR_FREE(ptr); - stack.PrintStack(); - ShowStatsAndAbort(); - return 0; // unreachable + GET_ZONE_FOR_PTR(ptr); + ReportMacMzReallocUnknown((uptr)ptr, (uptr)zone_ptr, zone_name, &stack); } } } @@ -229,14 +211,9 @@ void *cf_realloc(void *ptr, CFIndex size, CFOptionFlags hint, void *info) { // We can't recover from reallocating an unknown address, because // this would require reading at most |size| bytes from // potentially unaccessible memory. - AsanPrintf("cf_realloc(%p) -- attempting to realloc unallocated memory.\n" - "This is an unrecoverable problem, exiting now.\n", - ptr); - print_zone_for_ptr(ptr); GET_STACK_TRACE_HERE_FOR_FREE(ptr); - stack.PrintStack(); - ShowStatsAndAbort(); - return 0; // unreachable + GET_ZONE_FOR_PTR(ptr); + ReportMacCfReallocUnknown((uptr)ptr, (uptr)zone_ptr, zone_name, &stack); } } } diff --git a/compiler-rt/lib/asan/asan_report.cc b/compiler-rt/lib/asan/asan_report.cc index 82b5b0dd3de..73ef6cbf8ad 100644 --- a/compiler-rt/lib/asan/asan_report.cc +++ b/compiler-rt/lib/asan/asan_report.cc @@ -211,6 +211,52 @@ void ReportStringFunctionMemoryRangesOverlap( ShowStatsAndAbort(); } +// ----------------------- Mac-specific reports ----------------- {{{1 + +static void PrintZoneForPointer(uptr ptr, uptr zone_ptr, + const char *zone_name) { + if (zone_ptr) { + if (zone_name) { + AsanPrintf("malloc_zone_from_ptr(%p) = %p, which is %s\n", + ptr, zone_ptr, zone_name); + } else { + AsanPrintf("malloc_zone_from_ptr(%p) = %p, which doesn't have a name\n", + ptr, zone_ptr); + } + } else { + AsanPrintf("malloc_zone_from_ptr(%p) = 0\n", ptr); + } +} + +void WarnMacFreeUnallocated( + uptr addr, uptr zone_ptr, const char *zone_name, AsanStackTrace *stack) { + AsanPrintf("free_common(%p) -- attempting to free unallocated memory.\n" + "AddressSanitizer is ignoring this error on Mac OS now.\n", + addr); + PrintZoneForPointer(addr, zone_ptr, zone_name); + stack->PrintStack(); +} + +void ReportMacMzReallocUnknown( + uptr addr, uptr zone_ptr, const char *zone_name, AsanStackTrace *stack) { + AsanPrintf("mz_realloc(%p) -- attempting to realloc unallocated memory.\n" + "This is an unrecoverable problem, exiting now.\n", + addr); + PrintZoneForPointer(addr, zone_ptr, zone_name); + stack->PrintStack(); + ShowStatsAndAbort(); +} + +void ReportMacCfReallocUnknown( + uptr addr, uptr zone_ptr, const char *zone_name, AsanStackTrace *stack) { + AsanPrintf("cf_realloc(%p) -- attempting to realloc unallocated memory.\n" + "This is an unrecoverable problem, exiting now.\n", + addr); + PrintZoneForPointer(addr, zone_ptr, zone_name); + stack->PrintStack(); + ShowStatsAndAbort(); +} + static void PrintBytes(const char *before, uptr *a) { u8 *bytes = (u8*)a; uptr byte_num = (__WORDSIZE) / 8; diff --git a/compiler-rt/lib/asan/asan_report.h b/compiler-rt/lib/asan/asan_report.h index 101797eadf7..4eb70e564a0 100644 --- a/compiler-rt/lib/asan/asan_report.h +++ b/compiler-rt/lib/asan/asan_report.h @@ -40,4 +40,12 @@ void NORETURN ReportStringFunctionMemoryRangesOverlap( const char *function, const char *offset1, uptr length1, const char *offset2, uptr length2, AsanStackTrace *stack); +// Mac-specific errors and warnings. +void WarnMacFreeUnallocated( + uptr addr, uptr zone_ptr, const char *zone_name, AsanStackTrace *stack); +void NORETURN ReportMacMzReallocUnknown( + uptr addr, uptr zone_ptr, const char *zone_name, AsanStackTrace *stack); +void NORETURN ReportMacCfReallocUnknown( + uptr addr, uptr zone_ptr, const char *zone_name, AsanStackTrace *stack); + } // namespace __asan |

