@@ -1,5 +1,7 @@
//===-- asan_allocator.cc -------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_allocator.h ----------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_flags.h -------------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_globals.cc ---------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_intercepted_functions.h ----------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_interceptors.cc ----------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -237,13 +239,17 @@ INTERCEPTOR(void*, memcpy, void *to, const void *from, uptr size) {
ASAN_WRITE_RANGE(from, size);
ASAN_READ_RANGE(to, size);
}
+#if MAC_INTERPOSE_FUNCTIONS
+ // Interposing of resolver functions is broken on Mac OS 10.7 and 10.8.
+ // See also http://code.google.com/p/address-sanitizer/issues/detail?id=116.
+ return internal_memcpy(to, from, size);
+#else
return REAL(memcpy)(to, from, size);
+#endif
}
INTERCEPTOR(void*, memmove, void *to, const void *from, uptr size) {
-#if MAC_INTERPOSE_FUNCTIONS
- if (!asan_inited) return REAL(memmove)(to, from, size);
-#endif
+ if (!asan_inited) return internal_memmove(to, from, size);
if (asan_init_is_running) {
return REAL(memmove)(to, from, size);
}
@@ -252,7 +258,13 @@ INTERCEPTOR(void*, memmove, void *to, const void *from, uptr size) {
ASAN_WRITE_RANGE(from, size);
ASAN_READ_RANGE(to, size);
}
+#if MAC_INTERPOSE_FUNCTIONS
+ // Interposing of resolver functions is broken on Mac OS 10.7 and 10.8.
+ // See also http://code.google.com/p/address-sanitizer/issues/detail?id=116.
+ return internal_memmove(to, from, size);
+#else
return REAL(memmove)(to, from, size);
+#endif
}
INTERCEPTOR(void*, memset, void *block, int c, uptr size) {
@@ -370,6 +382,14 @@ INTERCEPTOR(char*, strcpy, char *to, const char *from) { // NOLINT
#if ASAN_INTERCEPT_STRDUP
INTERCEPTOR(char*, strdup, const char *s) {
+#if MAC_INTERPOSE_FUNCTIONS
+ // FIXME: because internal_strdup() uses InternalAlloc(), which currently
+ // just calls malloc() on Mac, we can't use internal_strdup() with the
+ // dynamic runtime. We can remove the call to REAL(strdup) once InternalAlloc
+ // starts using mmap() instead.
+ // See also http://code.google.com/p/address-sanitizer/issues/detail?id=123.
+ if (!asan_inited) return REAL(strdup)(s);
+#endif
if (!asan_inited) return internal_strdup(s);
ENSURE_ASAN_INITED();
if (flags()->replace_str) {
@@ -1,5 +1,7 @@
//===-- asan_interceptors.h -------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_internal.h -----------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_linux.cc -----------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -66,20 +68,6 @@ void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
*pc = ucontext->uc_mcontext.gregs[REG_EIP];
*bp = ucontext->uc_mcontext.gregs[REG_EBP];
*sp = ucontext->uc_mcontext.gregs[REG_ESP];
-# elif defined(__sparc__)
- ucontext_t *ucontext = (ucontext_t*)context;
- uptr *stk_ptr;
-# if defined (__arch64__)
- *pc = ucontext->uc_mcontext.mc_gregs[MC_PC];
- *sp = ucontext->uc_mcontext.mc_gregs[MC_O6];
- stk_ptr = (uptr *) (*sp + 2047);
- *bp = stk_ptr[15];
-# else
- *pc = ucontext->uc_mcontext.gregs[REG_PC];
- *sp = ucontext->uc_mcontext.gregs[REG_O6];
- stk_ptr = (uptr *) *sp;
- *bp = stk_ptr[15];
-# endif
#else
# error "Unsupported arch"
#endif
@@ -1,5 +1,7 @@
//===-- asan_lock.h ---------------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_mac.cc -------------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -66,6 +68,7 @@ int GetMacosVersion() {
switch (version[1]) {
case '0': return MACOS_VERSION_SNOW_LEOPARD;
case '1': return MACOS_VERSION_LION;
+ case '2': return MACOS_VERSION_MOUNTAIN_LION;
default: return MACOS_VERSION_UNKNOWN;
}
}
@@ -128,7 +131,14 @@ bool AsanInterceptsSignal(int signum) {
}
void AsanPlatformThreadInit() {
- ReplaceCFAllocator();
+ // For the first program thread, we can't replace the allocator before
+ // __CFInitialize() has been called. If it hasn't, we'll call
+ // MaybeReplaceCFAllocator() later on this thread.
+ // For other threads __CFInitialize() has been called before their creation.
+ // See also asan_malloc_mac.cc.
+ if (((CFRuntimeBase*)kCFAllocatorSystemDefault)->_cfisa) {
+ MaybeReplaceCFAllocator();
+ }
}
AsanLock::AsanLock(LinkerInitialized) {
@@ -1,5 +1,7 @@
//===-- asan_mac.h ----------------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -38,7 +40,8 @@ enum {
MACOS_VERSION_UNKNOWN = 0,
MACOS_VERSION_LEOPARD,
MACOS_VERSION_SNOW_LEOPARD,
- MACOS_VERSION_LION
+ MACOS_VERSION_LION,
+ MACOS_VERSION_MOUNTAIN_LION
};
// Used by asan_malloc_mac.cc and asan_mac.cc
@@ -47,7 +50,7 @@ extern "C" void __CFInitialize();
namespace __asan {
int GetMacosVersion();
-void ReplaceCFAllocator();
+void MaybeReplaceCFAllocator();
} // namespace __asan
@@ -1,5 +1,7 @@
//===-- asan_malloc_linux.cc ----------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_malloc_mac.cc ------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -95,10 +97,6 @@ INTERCEPTOR(void, free, void *ptr) {
}
}
-namespace __asan {
- void ReplaceCFAllocator();
-}
-
// We can't always replace the default CFAllocator with cf_asan right in
// ReplaceSystemMalloc(), because it is sometimes called before
// __CFInitialize(), when the default allocator is invalid and replacing it may
@@ -116,7 +114,7 @@ INTERCEPTOR(void, __CFInitialize, void) {
CHECK(asan_inited);
#endif
REAL(__CFInitialize)();
- if (!cf_asan && asan_inited) ReplaceCFAllocator();
+ if (!cf_asan && asan_inited) MaybeReplaceCFAllocator();
}
namespace {
@@ -291,12 +289,10 @@ size_t mi_good_size(malloc_zone_t *zone, size_t size) {
boolean_t mi_check(malloc_zone_t *zone) {
UNIMPLEMENTED();
- return true;
}
void mi_print(malloc_zone_t *zone, boolean_t verbose) {
UNIMPLEMENTED();
- return;
}
void mi_log(malloc_zone_t *zone, void *address) {
@@ -331,7 +327,7 @@ boolean_t mi_zone_locked(malloc_zone_t *zone) {
extern int __CFRuntimeClassTableSize;
namespace __asan {
-void ReplaceCFAllocator() {
+void MaybeReplaceCFAllocator() {
static CFAllocatorContext asan_context = {
/*version*/ 0, /*info*/ &asan_zone,
/*retain*/ 0, /*release*/ 0,
@@ -342,7 +338,7 @@ void ReplaceCFAllocator() {
/*preferredSize*/ 0 };
if (!cf_asan)
cf_asan = CFAllocatorCreate(kCFAllocatorUseContext, &asan_context);
- if (CFAllocatorGetDefault() != cf_asan)
+ if (flags()->replace_cfallocator && CFAllocatorGetDefault() != cf_asan)
CFAllocatorSetDefault(cf_asan);
}
@@ -410,16 +406,14 @@ void ReplaceSystemMalloc() {
// Make sure the default allocator was replaced.
CHECK(malloc_default_zone() == &asan_zone);
- if (flags()->replace_cfallocator) {
- // If __CFInitialize() hasn't been called yet, cf_asan will be created and
- // installed as the default allocator after __CFInitialize() finishes (see
- // the interceptor for __CFInitialize() above). Otherwise install cf_asan
- // right now. On both Snow Leopard and Lion __CFInitialize() calls
- // __CFAllocatorInitialize(), which initializes the _base._cfisa field of
- // the default allocators we check here.
- if (((CFRuntimeBase*)kCFAllocatorSystemDefault)->_cfisa) {
- ReplaceCFAllocator();
- }
+ // If __CFInitialize() hasn't been called yet, cf_asan will be created and
+ // installed as the default allocator after __CFInitialize() finishes (see
+ // the interceptor for __CFInitialize() above). Otherwise install cf_asan
+ // right now. On both Snow Leopard and Lion __CFInitialize() calls
+ // __CFAllocatorInitialize(), which initializes the _base._cfisa field of
+ // the default allocators we check here.
+ if (((CFRuntimeBase*)kCFAllocatorSystemDefault)->_cfisa) {
+ MaybeReplaceCFAllocator();
}
}
} // namespace __asan
@@ -1,5 +1,7 @@
//===-- asan_malloc_win.cc ------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_mapping.h ------------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_interceptors.cc ----------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -15,7 +17,6 @@
#include "asan_stack.h"
#include <stddef.h>
-#include <new>
namespace __asan {
// This function is a no-op. We need it to make sure that object file
@@ -26,29 +27,40 @@ void ReplaceOperatorsNewAndDelete() { }
using namespace __asan; // NOLINT
+// On Android new() goes through malloc interceptors.
+#if !ASAN_ANDROID
+
+// Fake std::nothrow_t to avoid including <new>.
+namespace std {
+struct nothrow_t {};
+} // namespace std
+
#define OPERATOR_NEW_BODY \
GET_STACK_TRACE_HERE_FOR_MALLOC;\
return asan_memalign(0, size, &stack);
-#if ASAN_ANDROID
+INTERCEPTOR_ATTRIBUTE
void *operator new(size_t size) { OPERATOR_NEW_BODY; }
+INTERCEPTOR_ATTRIBUTE
void *operator new[](size_t size) { OPERATOR_NEW_BODY; }
-#else
-void *operator new(size_t size) throw(std::bad_alloc) { OPERATOR_NEW_BODY; }
-void *operator new[](size_t size) throw(std::bad_alloc) { OPERATOR_NEW_BODY; }
-void *operator new(size_t size, std::nothrow_t const&) throw()
-{ OPERATOR_NEW_BODY; }
-void *operator new[](size_t size, std::nothrow_t const&) throw()
-{ OPERATOR_NEW_BODY; }
-#endif
+INTERCEPTOR_ATTRIBUTE
+void *operator new(size_t size, std::nothrow_t const&) { OPERATOR_NEW_BODY; }
+INTERCEPTOR_ATTRIBUTE
+void *operator new[](size_t size, std::nothrow_t const&) { OPERATOR_NEW_BODY; }
#define OPERATOR_DELETE_BODY \
GET_STACK_TRACE_HERE_FOR_FREE(ptr);\
asan_free(ptr, &stack);
-void operator delete(void *ptr) throw() { OPERATOR_DELETE_BODY; }
-void operator delete[](void *ptr) throw() { OPERATOR_DELETE_BODY; }
-void operator delete(void *ptr, std::nothrow_t const&) throw()
+INTERCEPTOR_ATTRIBUTE
+void operator delete(void *ptr) { OPERATOR_DELETE_BODY; }
+INTERCEPTOR_ATTRIBUTE
+void operator delete[](void *ptr) { OPERATOR_DELETE_BODY; }
+INTERCEPTOR_ATTRIBUTE
+void operator delete(void *ptr, std::nothrow_t const&)
{ OPERATOR_DELETE_BODY; }
-void operator delete[](void *ptr, std::nothrow_t const&) throw()
+INTERCEPTOR_ATTRIBUTE
+void operator delete[](void *ptr, std::nothrow_t const&)
{ OPERATOR_DELETE_BODY; }
+
+#endif
@@ -1,5 +1,7 @@
//===-- asan_poisoning.cc -------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_linux.cc -----------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_report.cc ----------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -320,7 +322,7 @@ class ScopedInErrorReport {
void ReportSIGSEGV(uptr pc, uptr sp, uptr bp, uptr addr) {
ScopedInErrorReport in_report;
- Report("ERROR: AddressSanitizer crashed on unknown address %p"
+ Report("ERROR: AddressSanitizer: SEGV on unknown address %p"
" (pc %p sp %p bp %p T%d)\n",
(void*)addr, (void*)pc, (void*)sp, (void*)bp,
asanThreadRegistry().GetCurrentTidOrInvalid());
@@ -331,14 +333,14 @@ void ReportSIGSEGV(uptr pc, uptr sp, uptr bp, uptr addr) {
void ReportDoubleFree(uptr addr, StackTrace *stack) {
ScopedInErrorReport in_report;
- Report("ERROR: AddressSanitizer attempting double-free on %p:\n", addr);
+ Report("ERROR: AddressSanitizer: attempting double-free on %p:\n", addr);
PrintStack(stack);
DescribeHeapAddress(addr, 1);
}
void ReportFreeNotMalloced(uptr addr, StackTrace *stack) {
ScopedInErrorReport in_report;
- Report("ERROR: AddressSanitizer attempting free on address "
+ Report("ERROR: AddressSanitizer: attempting free on address "
"which was not malloc()-ed: %p\n", addr);
PrintStack(stack);
DescribeHeapAddress(addr, 1);
@@ -346,7 +348,7 @@ void ReportFreeNotMalloced(uptr addr, StackTrace *stack) {
void ReportMallocUsableSizeNotOwned(uptr addr, StackTrace *stack) {
ScopedInErrorReport in_report;
- Report("ERROR: AddressSanitizer attempting to call "
+ Report("ERROR: AddressSanitizer: attempting to call "
"malloc_usable_size() for pointer which is "
"not owned: %p\n", addr);
PrintStack(stack);
@@ -355,7 +357,7 @@ void ReportMallocUsableSizeNotOwned(uptr addr, StackTrace *stack) {
void ReportAsanGetAllocatedSizeNotOwned(uptr addr, StackTrace *stack) {
ScopedInErrorReport in_report;
- Report("ERROR: AddressSanitizer attempting to call "
+ Report("ERROR: AddressSanitizer: attempting to call "
"__asan_get_allocated_size() for pointer which is "
"not owned: %p\n", addr);
PrintStack(stack);
@@ -366,7 +368,7 @@ void ReportStringFunctionMemoryRangesOverlap(
const char *function, const char *offset1, uptr length1,
const char *offset2, uptr length2, StackTrace *stack) {
ScopedInErrorReport in_report;
- Report("ERROR: AddressSanitizer %s-param-overlap: "
+ Report("ERROR: AddressSanitizer: %s-param-overlap: "
"memory ranges [%p,%p) and [%p, %p) overlap\n", \
function, offset1, offset1 + length1, offset2, offset2 + length2);
PrintStack(stack);
@@ -459,7 +461,7 @@ void __asan_report_error(uptr pc, uptr bp, uptr sp,
}
}
- Report("ERROR: AddressSanitizer %s on address "
+ Report("ERROR: AddressSanitizer: %s on address "
"%p at pc 0x%zx bp 0x%zx sp 0x%zx\n",
bug_descr, (void*)addr, pc, bp, sp);
@@ -1,5 +1,7 @@
//===-- asan_report.h -------------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_rtl.cc -------------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_stack.cc -----------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_stack.h --------------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_stats.cc -----------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_stats.h --------------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_thread.cc ----------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_thread.h -------------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_thread_registry.cc -------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -111,7 +113,11 @@ AsanStats AsanThreadRegistry::GetAccumulatedStats() {
uptr AsanThreadRegistry::GetCurrentAllocatedBytes() {
ScopedLock lock(&mu_);
UpdateAccumulatedStatsUnlocked();
- return accumulated_stats_.malloced - accumulated_stats_.freed;
+ uptr malloced = accumulated_stats_.malloced;
+ uptr freed = accumulated_stats_.freed;
+ // Return sane value if malloced < freed due to racy
+ // way we update accumulated stats.
+ return (malloced > freed) ? malloced - freed : 1;
}
uptr AsanThreadRegistry::GetHeapSize() {
@@ -123,11 +129,14 @@ uptr AsanThreadRegistry::GetHeapSize() {
uptr AsanThreadRegistry::GetFreeBytes() {
ScopedLock lock(&mu_);
UpdateAccumulatedStatsUnlocked();
- return accumulated_stats_.mmaped
- - accumulated_stats_.malloced
- - accumulated_stats_.malloced_redzones
- + accumulated_stats_.really_freed
- + accumulated_stats_.really_freed_redzones;
+ uptr total_free = accumulated_stats_.mmaped
+ + accumulated_stats_.really_freed
+ + accumulated_stats_.really_freed_redzones;
+ uptr total_used = accumulated_stats_.malloced
+ + accumulated_stats_.malloced_redzones;
+ // Return sane value if total_free < total_used due to racy
+ // way we update accumulated stats.
+ return (total_free > total_used) ? total_free - total_used : 1;
}
// Return several stats counters with a single call to
@@ -1,5 +1,7 @@
//===-- asan_thread_registry.h ----------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- asan_win.cc -------------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- sanitizer/asan_interface.h ------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- sanitizer/common_interface_defs.h -----------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -61,6 +63,11 @@ extern "C" {
// Tell the tools to write their reports to "path.<pid>" instead of stderr.
void __sanitizer_set_report_path(const char *path)
SANITIZER_INTERFACE_ATTRIBUTE;
+
+ // Tell the tools to write their reports to given file descriptor instead of
+ // stderr.
+ void __sanitizer_set_report_fd(int fd)
+ SANITIZER_INTERFACE_ATTRIBUTE;
} // extern "C"
#endif // SANITIZER_COMMON_INTERFACE_DEFS_H
@@ -1,5 +1,7 @@
//===-- interception.h ------------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- interception_linux.cc -----------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- interception_linux.h ------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- interception_mac.cc -------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- interception_mac.h --------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- interception_linux.cc -----------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- interception_linux.h ------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- sanitizer_allocator.cc --------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- sanitizer_allocator64.h ---------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- sanitizer_atomic.h --------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- sanitizer_atomic_clang.h --------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- sanitizer_atomic_msvc.h ---------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- sanitizer_common.cc -----------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -14,7 +16,9 @@
namespace __sanitizer {
-static fd_t report_fd = 2; // By default, dump to stderr.
+// By default, dump to stderr. If report_fd is kInvalidFd, try to obtain file
+// descriptor by opening file in report_path.
+static fd_t report_fd = kStderrFd;
static char report_path[4096]; // Set via __sanitizer_set_report_path.
static void (*DieCallback)(void);
@@ -44,18 +48,27 @@ void NORETURN CheckFailed(const char *file, int line, const char *cond,
Die();
}
+static void MaybeOpenReportFile() {
+ if (report_fd != kInvalidFd)
+ return;
+ fd_t fd = internal_open(report_path, true);
+ if (fd == kInvalidFd) {
+ report_fd = kStderrFd;
+ Report("ERROR: Can't open file: %s\n", report_path);
+ Die();
+ }
+ report_fd = fd;
+}
+
+bool PrintsToTty() {
+ MaybeOpenReportFile();
+ return internal_isatty(report_fd);
+}
+
void RawWrite(const char *buffer) {
static const char *kRawWriteError = "RawWrite can't output requested buffer!";
uptr length = (uptr)internal_strlen(buffer);
- if (report_fd == kInvalidFd) {
- fd_t fd = internal_open(report_path, true);
- if (fd == kInvalidFd) {
- report_fd = 2;
- Report("ERROR: Can't open file: %s\n", report_path);
- Die();
- }
- report_fd = fd;
- }
+ MaybeOpenReportFile();
if (length != internal_write(report_fd, buffer, length)) {
internal_write(report_fd, kRawWriteError, internal_strlen(kRawWriteError));
Die();
@@ -136,16 +149,27 @@ void SortArray(uptr *array, uptr size) {
} // namespace __sanitizer
+using namespace __sanitizer; // NOLINT
+
+extern "C" {
void __sanitizer_set_report_path(const char *path) {
if (!path) return;
uptr len = internal_strlen(path);
- if (len > sizeof(__sanitizer::report_path) - 100) {
+ if (len > sizeof(report_path) - 100) {
Report("ERROR: Path is too long: %c%c%c%c%c%c%c%c...\n",
path[0], path[1], path[2], path[3],
path[4], path[5], path[6], path[7]);
Die();
}
- internal_snprintf(__sanitizer::report_path,
- sizeof(__sanitizer::report_path), "%s.%d", path, GetPid());
- __sanitizer::report_fd = kInvalidFd;
+ internal_snprintf(report_path, sizeof(report_path), "%s.%d", path, GetPid());
+ report_fd = kInvalidFd;
+}
+
+void __sanitizer_set_report_fd(int fd) {
+ if (report_fd != kStdoutFd &&
+ report_fd != kStderrFd &&
+ report_fd != kInvalidFd)
+ internal_close(report_fd);
+ report_fd = fd;
}
+} // extern "C"
@@ -1,5 +1,7 @@
//===-- sanitizer_common.h --------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -96,6 +98,7 @@ void SetLowLevelAllocateCallback(LowLevelAllocateCallback callback);
// IO
void RawWrite(const char *buffer);
+bool PrintsToTty();
void Printf(const char *format, ...);
void Report(const char *format, ...);
void SetPrintfAndReportCallback(void (*callback)(const char *));
@@ -114,6 +117,7 @@ void *MapFileToMemory(const char *file_name, uptr *buff_size);
// OS
void DisableCoreDumper();
void DumpProcessMap();
+bool FileExists(const char *filename);
const char *GetEnv(const char *name);
const char *GetPwd();
void ReExec();
@@ -1,5 +1,7 @@
//===-- sanitizer_flags.cc ------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- sanitizer_flags.h ---------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- sanitizer_internal_defs.h -------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -22,8 +24,7 @@ using namespace __sanitizer; // NOLINT
#define WEAK SANITIZER_WEAK_ATTRIBUTE
// Platform-specific defs.
-#if defined(_WIN32)
-typedef unsigned long DWORD; // NOLINT
+#if defined(_MSC_VER)
# define ALWAYS_INLINE __declspec(forceinline)
// FIXME(timurrrr): do we need this on Windows?
# define ALIAS(x)
@@ -33,7 +34,11 @@ typedef unsigned long DWORD; // NOLINT
# define NORETURN __declspec(noreturn)
# define THREADLOCAL __declspec(thread)
# define NOTHROW
-#else // _WIN32
+# define LIKELY(x) (x)
+# define UNLIKELY(x) (x)
+# define UNUSED
+# define USED
+#else // _MSC_VER
# define ALWAYS_INLINE __attribute__((always_inline))
# define ALIAS(x) __attribute__((alias(x)))
# define ALIGNED(x) __attribute__((aligned(x)))
@@ -41,22 +46,15 @@ typedef unsigned long DWORD; // NOLINT
# define NOINLINE __attribute__((noinline))
# define NORETURN __attribute__((noreturn))
# define THREADLOCAL __thread
-# ifdef __cplusplus
-# define NOTHROW throw()
-# else
-# define NOTHROW __attribute__((__nothrow__))
-#endif
-#endif // _WIN32
-
-// We have no equivalent of these on Windows.
-#ifndef _WIN32
+# define NOTHROW throw()
# define LIKELY(x) __builtin_expect(!!(x), 1)
# define UNLIKELY(x) __builtin_expect(!!(x), 0)
# define UNUSED __attribute__((unused))
# define USED __attribute__((used))
-#endif
+#endif // _MSC_VER
#if defined(_WIN32)
+typedef unsigned long DWORD; // NOLINT
typedef DWORD thread_return_t;
# define THREAD_CALLING_CONV __stdcall
#else // _WIN32
@@ -128,7 +126,12 @@ void NORETURN CheckFailed(const char *file, int line, const char *cond,
#define DCHECK_GE(a, b)
#endif
-#define UNIMPLEMENTED() CHECK("unimplemented" && 0)
+#define UNREACHABLE(msg) do { \
+ CHECK(0 && msg); \
+ Die(); \
+} while (0)
+
+#define UNIMPLEMENTED() UNREACHABLE("unimplemented")
#define COMPILER_CHECK(pred) IMPL_COMPILER_ASSERT(pred, __LINE__)
@@ -1,5 +1,7 @@
//===-- sanitizer_libc.cc -------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -42,6 +44,23 @@ void *internal_memcpy(void *dest, const void *src, uptr n) {
return dest;
}
+void *internal_memmove(void *dest, const void *src, uptr n) {
+ char *d = (char*)dest;
+ char *s = (char*)src;
+ sptr i, signed_n = (sptr)n;
+ CHECK_GE(signed_n, 0);
+ if (d < s) {
+ for (i = 0; i < signed_n; ++i)
+ d[i] = s[i];
+ } else {
+ if (d > s && signed_n > 0)
+ for (i = signed_n - 1; i >= 0 ; --i) {
+ d[i] = s[i];
+ }
+ }
+ return dest;
+}
+
void *internal_memset(void* s, int c, uptr n) {
// The next line prevents Clang from making a call to memset() instead of the
// loop below.
@@ -1,5 +1,7 @@
//===-- sanitizer_libc.h ----------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -27,6 +29,7 @@ s64 internal_atoll(const char *nptr);
void *internal_memchr(const void *s, int c, uptr n);
int internal_memcmp(const void* s1, const void* s2, uptr n);
void *internal_memcpy(void *dest, const void *src, uptr n);
+void *internal_memmove(void *dest, const void *src, uptr n);
// Should not be used in performance-critical places.
void *internal_memset(void *s, int c, uptr n);
char* internal_strchr(const char *s, int c);
@@ -52,7 +55,11 @@ int internal_munmap(void *addr, uptr length);
// I/O
typedef int fd_t;
const fd_t kInvalidFd = -1;
+const fd_t kStdinFd = 0;
+const fd_t kStdoutFd = 1;
+const fd_t kStderrFd = 2;
int internal_close(fd_t fd);
+int internal_isatty(fd_t fd);
fd_t internal_open(const char *filename, bool write);
uptr internal_read(fd_t fd, void *buf, uptr count);
uptr internal_write(fd_t fd, const void *buf, uptr count);
@@ -1,5 +1,7 @@
//===-- sanitizer_linux.cc ------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -34,7 +36,7 @@ namespace __sanitizer {
// --------------- sanitizer_libc.h
void *internal_mmap(void *addr, uptr length, int prot, int flags,
int fd, u64 offset) {
-#if __WORDSIZE == 64
+#if defined __x86_64__
return (void *)syscall(__NR_mmap, addr, length, prot, flags, fd, offset);
#else
return (void *)syscall(__NR_mmap2, addr, length, prot, flags, fd, offset);
@@ -67,7 +69,7 @@ uptr internal_write(fd_t fd, const void *buf, uptr count) {
}
uptr internal_filesize(fd_t fd) {
-#if __WORDSIZE == 64
+#if defined __x86_64__
struct stat st;
if (syscall(__NR_fstat, fd, &st))
return -1;
@@ -92,6 +94,20 @@ int internal_sched_yield() {
}
// ----------------- sanitizer_common.h
+bool FileExists(const char *filename) {
+#if defined __x86_64__
+ struct stat st;
+ if (syscall(__NR_stat, filename, &st))
+ return false;
+#else
+ struct stat64 st;
+ if (syscall(__NR_stat64, filename, &st))
+ return false;
+#endif
+ // Sanity check: filename is a regular file.
+ return S_ISREG(st.st_mode);
+}
+
uptr GetTid() {
return syscall(__NR_gettid);
}
@@ -1,5 +1,7 @@
//===-- sanitizer_list.h ----------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- sanitizer_mac.cc --------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -78,6 +80,14 @@ int internal_sched_yield() {
}
// ----------------- sanitizer_common.h
+bool FileExists(const char *filename) {
+ struct stat st;
+ if (stat(filename, &st))
+ return false;
+ // Sanity check: filename is a regular file.
+ return S_ISREG(st.st_mode);
+}
+
uptr GetTid() {
return reinterpret_cast<uptr>(pthread_self());
}
@@ -1,5 +1,7 @@
//===-- sanitizer_mutex.h ---------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- sanitizer_placement_new.h -------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- sanitizer_posix.cc ------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -72,10 +74,15 @@ void UnmapOrDie(void *addr, uptr size) {
}
void *MmapFixedNoReserve(uptr fixed_addr, uptr size) {
- return internal_mmap((void*)fixed_addr, size,
- PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
- -1, 0);
+ void *p = internal_mmap((void*)(fixed_addr & ~(kPageSize - 1)),
+ RoundUpTo(size, kPageSize),
+ PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANON | MAP_FIXED | MAP_NORESERVE,
+ -1, 0);
+ if (p == (void*)-1)
+ Report("ERROR: Failed to allocate 0x%zx (%zd) bytes at address %p (%d)\n",
+ size, size, fixed_addr, errno);
+ return p;
}
void *Mprotect(uptr fixed_addr, uptr size) {
@@ -182,6 +189,10 @@ int Atexit(void (*function)(void)) {
#endif
}
+int internal_isatty(fd_t fd) {
+ return isatty(fd);
+}
+
} // namespace __sanitizer
#endif // __linux__ || __APPLE_
@@ -1,5 +1,7 @@
//===-- sanitizer_printf.cc -----------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -53,13 +55,16 @@ static int AppendUnsigned(char **buff, const char *buff_end, u64 num,
return result;
}
-static int AppendSignedDecimal(char **buff, const char *buff_end, s64 num) {
+static int AppendSignedDecimal(char **buff, const char *buff_end, s64 num,
+ u8 minimal_num_length) {
int result = 0;
if (num < 0) {
result += AppendChar(buff, buff_end, '-');
num = -num;
+ if (minimal_num_length)
+ --minimal_num_length;
}
- result += AppendUnsigned(buff, buff_end, (u64)num, 10, 0);
+ result += AppendUnsigned(buff, buff_end, (u64)num, 10, minimal_num_length);
return result;
}
@@ -83,8 +88,8 @@ static int AppendPointer(char **buff, const char *buff_end, u64 ptr_value) {
int VSNPrintf(char *buff, int buff_length,
const char *format, va_list args) {
- static const char *kPrintfFormatsHelp = "Supported Printf formats: "
- "%%[z]{d,u,x}; %%p; %%s; %%c\n";
+ static const char *kPrintfFormatsHelp =
+ "Supported Printf formats: %%(0[0-9]*)?(z|ll)?{d,u,x}; %%p; %%s; %%c\n";
RAW_CHECK(format);
RAW_CHECK(buff_length > 0);
const char *buff_end = &buff[buff_length - 1];
@@ -96,42 +101,55 @@ int VSNPrintf(char *buff, int buff_length,
continue;
}
cur++;
+ bool have_width = (*cur == '0');
+ int width = 0;
+ if (have_width) {
+ while (*cur >= '0' && *cur <= '9') {
+ have_width = true;
+ width = width * 10 + *cur++ - '0';
+ }
+ }
bool have_z = (*cur == 'z');
cur += have_z;
+ bool have_ll = !have_z && (cur[0] == 'l' && cur[1] == 'l');
+ cur += have_ll * 2;
s64 dval;
u64 uval;
+ bool have_flags = have_width | have_z | have_ll;
switch (*cur) {
case 'd': {
- dval = have_z ? va_arg(args, sptr)
- : va_arg(args, int);
- result += AppendSignedDecimal(&buff, buff_end, dval);
+ dval = have_ll ? va_arg(args, s64)
+ : have_z ? va_arg(args, sptr)
+ : va_arg(args, int);
+ result += AppendSignedDecimal(&buff, buff_end, dval, width);
break;
}
case 'u':
case 'x': {
- uval = have_z ? va_arg(args, uptr)
- : va_arg(args, unsigned);
+ uval = have_ll ? va_arg(args, u64)
+ : have_z ? va_arg(args, uptr)
+ : va_arg(args, unsigned);
result += AppendUnsigned(&buff, buff_end, uval,
- (*cur == 'u') ? 10 : 16, 0);
+ (*cur == 'u') ? 10 : 16, width);
break;
}
case 'p': {
- RAW_CHECK_MSG(!have_z, kPrintfFormatsHelp);
+ RAW_CHECK_MSG(!have_flags, kPrintfFormatsHelp);
result += AppendPointer(&buff, buff_end, va_arg(args, uptr));
break;
}
case 's': {
- RAW_CHECK_MSG(!have_z, kPrintfFormatsHelp);
+ RAW_CHECK_MSG(!have_flags, kPrintfFormatsHelp);
result += AppendString(&buff, buff_end, va_arg(args, char*));
break;
}
case 'c': {
- RAW_CHECK_MSG(!have_z, kPrintfFormatsHelp);
+ RAW_CHECK_MSG(!have_flags, kPrintfFormatsHelp);
result += AppendChar(&buff, buff_end, va_arg(args, int));
break;
}
case '%' : {
- RAW_CHECK_MSG(!have_z, kPrintfFormatsHelp);
+ RAW_CHECK_MSG(!have_flags, kPrintfFormatsHelp);
result += AppendChar(&buff, buff_end, '%');
break;
}
@@ -151,7 +169,7 @@ void SetPrintfAndReportCallback(void (*callback)(const char *)) {
}
void Printf(const char *format, ...) {
- const int kLen = 1024 * 4;
+ const int kLen = 16 * 1024;
InternalScopedBuffer<char> buffer(kLen);
va_list args;
va_start(args, format);
@@ -177,7 +195,7 @@ int internal_snprintf(char *buffer, uptr length, const char *format, ...) {
// Like Printf, but prints the current PID before the output string.
void Report(const char *format, ...) {
- const int kLen = 1024 * 4;
+ const int kLen = 16 * 1024;
InternalScopedBuffer<char> buffer(kLen);
int needed_length = internal_snprintf(buffer.data(),
kLen, "==%d== ", GetPid());
@@ -1,5 +1,7 @@
//===-- sanitizer_procmaps.h ------------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -23,7 +25,6 @@ class MemoryMappingLayout {
bool GetObjectNameAndOffset(uptr addr, uptr *offset,
char filename[], uptr filename_size) {
UNIMPLEMENTED();
- return false;
}
};
@@ -1,5 +1,7 @@
//===-- sanitizer_stackdepot.cc -------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- sanitizer_stackdepot.h ----------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- sanitizer_stacktrace.cc -------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -75,7 +77,8 @@ void StackTrace::PrintStack(const uptr *addr, uptr size,
Printf(" %s\n", StripPathPrefix(buff.data(), strip_file_prefix));
frame_num++;
}
- } else if (symbolize) {
+ }
+ if (symbolize && addr_frames_num == 0) {
// Use our own (online) symbolizer, if necessary.
addr_frames_num = SymbolizeCode(pc, addr_frames.data(),
addr_frames.size());
@@ -1,5 +1,7 @@
//===-- sanitizer_stacktrace.h ----------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -1,5 +1,7 @@
//===-- sanitizer_symbolizer.cc -------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -291,7 +293,8 @@ class Symbolizer {
}
}
- static const uptr kMaxNumberOfModuleContexts = 4096;
+ // 16K loaded modules should be enough for everyone.
+ static const uptr kMaxNumberOfModuleContexts = 1 << 14;
LoadedModule *modules_; // Array of module descriptions is leaked.
uptr n_modules_;
@@ -1,5 +1,7 @@
//===-- sanitizer_symbolizer.h ----------------------------------*- C++ -*-===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -77,7 +79,7 @@ class LoadedModule {
};
char *full_name_;
uptr base_address_;
- static const uptr kMaxNumberOfAddressRanges = 8;
+ static const uptr kMaxNumberOfAddressRanges = 6;
AddressRange ranges_[kMaxNumberOfAddressRanges];
uptr n_ranges_;
};
@@ -1,5 +1,7 @@
//===-- sanitizer_symbolizer_linux.cc -------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -21,6 +23,7 @@
#include <poll.h>
#include <sys/socket.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include <unistd.h>
#if !defined(__ANDROID__) && !defined(ANDROID)
@@ -29,8 +32,15 @@
namespace __sanitizer {
+static const int kSymbolizerStartupTimeMillis = 10;
+
bool StartSymbolizerSubprocess(const char *path_to_symbolizer,
int *input_fd, int *output_fd) {
+ if (!FileExists(path_to_symbolizer)) {
+ Report("WARNING: invalid path to external symbolizer!\n");
+ return false;
+ }
+
int *infd = NULL;
int *outfd = NULL;
// The client program may close its stdin and/or stdout and/or stderr
@@ -97,13 +107,23 @@ bool StartSymbolizerSubprocess(const char *path_to_symbolizer,
internal_close(infd[1]);
*input_fd = infd[0];
*output_fd = outfd[1];
+
+ // Check that symbolizer subprocess started successfully.
+ int pid_status;
+ SleepForMillis(kSymbolizerStartupTimeMillis);
+ int exited_pid = waitpid(pid, &pid_status, WNOHANG);
+ if (exited_pid != 0) {
+ // Either waitpid failed, or child has already exited.
+ Report("WARNING: external symbolizer didn't start up correctly!\n");
+ return false;
+ }
+
return true;
}
#if defined(__ANDROID__) || defined(ANDROID)
uptr GetListOfModules(LoadedModule *modules, uptr max_modules) {
UNIMPLEMENTED();
- return 0;
}
#else // ANDROID
typedef ElfW(Phdr) Elf_Phdr;
@@ -1,5 +1,7 @@
//===-- sanitizer_symbolizer_mac.cc ---------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -18,12 +20,10 @@ namespace __sanitizer {
bool StartSymbolizerSubprocess(const char *path_to_symbolizer,
int *input_fd, int *output_fd) {
UNIMPLEMENTED();
- return false;
}
uptr GetListOfModules(LoadedModule *modules, uptr max_modules) {
UNIMPLEMENTED();
- return 0;
}
} // namespace __sanitizer
@@ -1,5 +1,7 @@
//===-- sanitizer_symbolizer_win.cc ---------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -20,12 +22,10 @@ namespace __sanitizer {
bool StartSymbolizerSubprocess(const char *path_to_symbolizer,
int *input_fd, int *output_fd) {
UNIMPLEMENTED();
- return false;
}
uptr GetListOfModules(LoadedModule *modules, uptr max_modules) {
UNIMPLEMENTED();
- return 0;
};
} // namespace __sanitizer
@@ -1,5 +1,7 @@
//===-- sanitizer_win.cc --------------------------------------------------===//
//
+// The LLVM Compiler Infrastructure
+//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
@@ -10,6 +12,9 @@
// sanitizer_libc.h.
//===----------------------------------------------------------------------===//
#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#define NOGDI
+#include <stdlib.h>
#include <windows.h>
#include "sanitizer_common.h"
@@ -18,6 +23,10 @@
namespace __sanitizer {
// --------------------- sanitizer_common.h
+bool FileExists(const char *filename) {
+ UNIMPLEMENTED();
+}
+
int GetPid() {
return GetProcessId(GetCurrentProcess());
}
@@ -39,7 +48,6 @@ void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,
*stack_bottom = (uptr)mbi.AllocationBase;
}
-
void *MmapOrDie(uptr size, const char *mem_type) {
void *rv = VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if (rv == 0) {
@@ -59,8 +67,12 @@ void UnmapOrDie(void *addr, uptr size) {
}
void *MmapFixedNoReserve(uptr fixed_addr, uptr size) {
- return VirtualAlloc((LPVOID)fixed_addr, size,
- MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
+ void *p = VirtualAlloc((LPVOID)fixed_addr, size,
+ MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
+ if (p == 0)
+ Report("ERROR: Failed to allocate 0x%zx (%zd) bytes at %p (%d)\n",
+ size, size, fixed_addr, GetLastError());
+ return p;
}
void *Mprotect(uptr fixed_addr, uptr size) {
@@ -75,7 +87,6 @@ bool MemoryRangeIsAvailable(uptr range_start, uptr range_end) {
void *MapFileToMemory(const char *file_name, uptr *buff_size) {
UNIMPLEMENTED();
- return 0;
}
const char *GetEnv(const char *name) {
@@ -96,7 +107,6 @@ const char *GetEnv(const char *name) {
const char *GetPwd() {
UNIMPLEMENTED();
- return 0;
}
void DumpProcessMap() {
@@ -113,7 +123,6 @@ void ReExec() {
bool StackSizeIsUnlimited() {
UNIMPLEMENTED();
- return false;
}
void SetStackSizeLimitInBytes(uptr limit) {
@@ -137,39 +146,40 @@ void Abort() {
_exit(-1); // abort is not NORETURN on Windows.
}
+#ifndef SANITIZER_GO
int Atexit(void (*function)(void)) {
return atexit(function);
}
+#endif
// ------------------ sanitizer_libc.h
void *internal_mmap(void *addr, uptr length, int prot, int flags,
int fd, u64 offset) {
UNIMPLEMENTED();
- return 0;
}
int internal_munmap(void *addr, uptr length) {
UNIMPLEMENTED();
- return 0;
}
int internal_close(fd_t fd) {
UNIMPLEMENTED();
- return 0;
+}
+
+int internal_isatty(fd_t fd) {
+ UNIMPLEMENTED();
}
fd_t internal_open(const char *filename, bool write) {
UNIMPLEMENTED();
- return 0;
}
uptr internal_read(fd_t fd, void *buf, uptr count) {
UNIMPLEMENTED();
- return 0;
}
uptr internal_write(fd_t fd, const void *buf, uptr count) {
- if (fd != 2)
+ if (fd != kStderrFd)
UNIMPLEMENTED();
HANDLE err = GetStdHandle(STD_ERROR_HANDLE);
if (err == 0)
@@ -182,21 +192,18 @@ uptr internal_write(fd_t fd, const void *buf, uptr count) {
uptr internal_filesize(fd_t fd) {
UNIMPLEMENTED();
- return 0;
}
int internal_dup2(int oldfd, int newfd) {
UNIMPLEMENTED();
- return 0;
}
uptr internal_readlink(const char *path, char *buf, uptr bufsize) {
UNIMPLEMENTED();
- return 0;
}
int internal_sched_yield() {
- UNIMPLEMENTED();
+ Sleep(0);
return 0;
}