diff options
Diffstat (limited to 'lib/asan')
-rw-r--r-- | lib/asan/asan_activation.cpp (renamed from lib/asan/asan_activation.cc) | 2 | ||||
-rw-r--r-- | lib/asan/asan_allocator.cpp (renamed from lib/asan/asan_allocator.cc) | 4 | ||||
-rw-r--r-- | lib/asan/asan_allocator.h | 2 | ||||
-rw-r--r-- | lib/asan/asan_debugging.cpp (renamed from lib/asan/asan_debugging.cc) | 10 | ||||
-rw-r--r-- | lib/asan/asan_descriptions.cpp (renamed from lib/asan/asan_descriptions.cc) | 2 | ||||
-rw-r--r-- | lib/asan/asan_descriptions.h | 4 | ||||
-rw-r--r-- | lib/asan/asan_errors.cpp (renamed from lib/asan/asan_errors.cc) | 7 | ||||
-rw-r--r-- | lib/asan/asan_errors.h | 3 | ||||
-rw-r--r-- | lib/asan/asan_fake_stack.cpp (renamed from lib/asan/asan_fake_stack.cc) | 2 | ||||
-rw-r--r-- | lib/asan/asan_fake_stack.h | 2 | ||||
-rw-r--r-- | lib/asan/asan_flags.cpp (renamed from lib/asan/asan_flags.cc) | 2 | ||||
-rw-r--r-- | lib/asan/asan_flags.inc | 13 | ||||
-rw-r--r-- | lib/asan/asan_fuchsia.cpp (renamed from lib/asan/asan_fuchsia.cc) | 6 | ||||
-rw-r--r-- | lib/asan/asan_globals.cpp (renamed from lib/asan/asan_globals.cc) | 10 | ||||
-rw-r--r-- | lib/asan/asan_globals_win.cpp (renamed from lib/asan/asan_globals_win.cc) | 10 | ||||
-rw-r--r-- | lib/asan/asan_interceptors.cpp (renamed from lib/asan/asan_interceptors.cc) | 125 | ||||
-rw-r--r-- | lib/asan/asan_interceptors.h | 14 | ||||
-rw-r--r-- | lib/asan/asan_interceptors_memintrinsics.cpp (renamed from lib/asan/asan_interceptors_memintrinsics.cc) | 4 | ||||
-rw-r--r-- | lib/asan/asan_interceptors_memintrinsics.h | 2 | ||||
-rw-r--r-- | lib/asan/asan_internal.h | 12 | ||||
-rw-r--r-- | lib/asan/asan_linux.cpp (renamed from lib/asan/asan_linux.cc) | 2 | ||||
-rw-r--r-- | lib/asan/asan_mac.cpp (renamed from lib/asan/asan_mac.cc) | 4 | ||||
-rw-r--r-- | lib/asan/asan_malloc_linux.cpp (renamed from lib/asan/asan_malloc_linux.cc) | 4 | ||||
-rw-r--r-- | lib/asan/asan_malloc_mac.cpp (renamed from lib/asan/asan_malloc_mac.cc) | 2 | ||||
-rw-r--r-- | lib/asan/asan_malloc_win.cpp (renamed from lib/asan/asan_malloc_win.cc) | 13 | ||||
-rw-r--r-- | lib/asan/asan_memory_profile.cpp (renamed from lib/asan/asan_memory_profile.cc) | 2 | ||||
-rw-r--r-- | lib/asan/asan_new_delete.cpp (renamed from lib/asan/asan_new_delete.cc) | 4 | ||||
-rw-r--r-- | lib/asan/asan_poisoning.cpp (renamed from lib/asan/asan_poisoning.cc) | 4 | ||||
-rw-r--r-- | lib/asan/asan_posix.cpp (renamed from lib/asan/asan_posix.cc) | 6 | ||||
-rw-r--r-- | lib/asan/asan_preinit.cpp (renamed from lib/asan/asan_preinit.cc) | 2 | ||||
-rw-r--r-- | lib/asan/asan_premap_shadow.cpp (renamed from lib/asan/asan_premap_shadow.cc) | 2 | ||||
-rw-r--r-- | lib/asan/asan_report.cpp (renamed from lib/asan/asan_report.cc) | 12 | ||||
-rw-r--r-- | lib/asan/asan_rtems.cpp (renamed from lib/asan/asan_rtems.cc) | 6 | ||||
-rw-r--r-- | lib/asan/asan_rtl.cpp (renamed from lib/asan/asan_rtl.cc) | 8 | ||||
-rw-r--r-- | lib/asan/asan_scariness_score.h | 2 | ||||
-rw-r--r-- | lib/asan/asan_shadow_setup.cpp (renamed from lib/asan/asan_shadow_setup.cc) | 7 | ||||
-rw-r--r-- | lib/asan/asan_stack.cpp (renamed from lib/asan/asan_stack.cc) | 2 | ||||
-rw-r--r-- | lib/asan/asan_stack.h | 2 | ||||
-rw-r--r-- | lib/asan/asan_stats.cpp (renamed from lib/asan/asan_stats.cc) | 4 | ||||
-rw-r--r-- | lib/asan/asan_suppressions.cpp (renamed from lib/asan/asan_suppressions.cc) | 4 | ||||
-rw-r--r-- | lib/asan/asan_suppressions.h | 2 | ||||
-rw-r--r-- | lib/asan/asan_thread.cpp (renamed from lib/asan/asan_thread.cc) | 7 | ||||
-rw-r--r-- | lib/asan/asan_thread.h | 2 | ||||
-rw-r--r-- | lib/asan/asan_win.cpp (renamed from lib/asan/asan_win.cc) | 12 | ||||
-rw-r--r-- | lib/asan/asan_win_dll_thunk.cpp (renamed from lib/asan/asan_win_dll_thunk.cc) | 12 | ||||
-rw-r--r-- | lib/asan/asan_win_dynamic_runtime_thunk.cpp (renamed from lib/asan/asan_win_dynamic_runtime_thunk.cc) | 16 | ||||
-rw-r--r-- | lib/asan/asan_win_weak_interception.cpp (renamed from lib/asan/asan_win_weak_interception.cc) | 2 |
47 files changed, 223 insertions, 158 deletions
diff --git a/lib/asan/asan_activation.cc b/lib/asan/asan_activation.cpp index fc97cbb554d0..795df95a5414 100644 --- a/lib/asan/asan_activation.cc +++ b/lib/asan/asan_activation.cpp @@ -1,4 +1,4 @@ -//===-- asan_activation.cc --------------------------------------*- C++ -*-===// +//===-- asan_activation.cpp -------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lib/asan/asan_allocator.cc b/lib/asan/asan_allocator.cpp index 2ca6220d8fd1..c9e9f5a93d0d 100644 --- a/lib/asan/asan_allocator.cc +++ b/lib/asan/asan_allocator.cpp @@ -1,4 +1,4 @@ -//===-- asan_allocator.cc -------------------------------------------------===// +//===-- asan_allocator.cpp ------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -1075,7 +1075,7 @@ IgnoreObjectResult IgnoreObjectLocked(const void *p) { } // namespace __lsan // ---------------------- Interface ---------------- {{{1 -using namespace __asan; // NOLINT +using namespace __asan; // ASan allocator doesn't reserve extra bytes, so normally we would // just return "size". We don't want to expose our redzone sizes, etc here. diff --git a/lib/asan/asan_allocator.h b/lib/asan/asan_allocator.h index 6add47be2c9c..b37d8ef4e8d2 100644 --- a/lib/asan/asan_allocator.h +++ b/lib/asan/asan_allocator.h @@ -8,7 +8,7 @@ // // This file is a part of AddressSanitizer, an address sanity checker. // -// ASan-private header for asan_allocator.cc. +// ASan-private header for asan_allocator.cpp. //===----------------------------------------------------------------------===// #ifndef ASAN_ALLOCATOR_H diff --git a/lib/asan/asan_debugging.cc b/lib/asan/asan_debugging.cpp index 7052a371e676..c01360b52fc9 100644 --- a/lib/asan/asan_debugging.cc +++ b/lib/asan/asan_debugging.cpp @@ -1,4 +1,4 @@ -//===-- asan_debugging.cc -------------------------------------------------===// +//===-- asan_debugging.cpp ------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -25,7 +25,7 @@ using namespace __asan; static void FindInfoForStackVar(uptr addr, const char *frame_descr, uptr offset, char *name, uptr name_size, - uptr ®ion_address, uptr ®ion_size) { + uptr *region_address, uptr *region_size) { InternalMmapVector<StackVarDescr> vars; vars.reserve(16); if (!ParseFrameDescription(frame_descr, &vars)) { @@ -39,8 +39,8 @@ static void FindInfoForStackVar(uptr addr, const char *frame_descr, uptr offset, // the whole name and then terminate with '\0'. internal_strlcpy(name, vars[i].name_pos, Min(name_size, vars[i].name_len + 1)); - region_address = addr - (offset - vars[i].beg); - region_size = vars[i].size; + *region_address = addr - (offset - vars[i].beg); + *region_size = vars[i].size; return; } } @@ -108,7 +108,7 @@ const char *__asan_locate_address(uptr addr, char *name, uptr name_size, // region_{address,size} are already 0 } else { FindInfoForStackVar(addr, stack->frame_descr, stack->offset, name, - name_size, region_address, region_size); + name_size, ®ion_address, ®ion_size); } } else if (auto global = descr.AsGlobal()) { region_kind = "global"; diff --git a/lib/asan/asan_descriptions.cc b/lib/asan/asan_descriptions.cpp index 9b1217a86652..153c874a4e77 100644 --- a/lib/asan/asan_descriptions.cc +++ b/lib/asan/asan_descriptions.cpp @@ -1,4 +1,4 @@ -//===-- asan_descriptions.cc ------------------------------------*- C++ -*-===// +//===-- asan_descriptions.cpp -----------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lib/asan/asan_descriptions.h b/lib/asan/asan_descriptions.h index 0226d844afc9..ee0e2061559e 100644 --- a/lib/asan/asan_descriptions.h +++ b/lib/asan/asan_descriptions.h @@ -8,7 +8,7 @@ // // This file is a part of AddressSanitizer, an address sanity checker. // -// ASan-private header for asan_descriptions.cc. +// ASan-private header for asan_descriptions.cpp. // TODO(filcab): Most struct definitions should move to the interface headers. //===----------------------------------------------------------------------===// #ifndef ASAN_DESCRIPTIONS_H @@ -203,7 +203,7 @@ class AddressDescription { AddressDescription() = default; // shouldLockThreadRegistry allows us to skip locking if we're sure we already // have done it. - AddressDescription(uptr addr, bool shouldLockThreadRegistry = true) + explicit AddressDescription(uptr addr, bool shouldLockThreadRegistry = true) : AddressDescription(addr, 1, shouldLockThreadRegistry) {} AddressDescription(uptr addr, uptr access_size, bool shouldLockThreadRegistry = true); diff --git a/lib/asan/asan_errors.cc b/lib/asan/asan_errors.cpp index d598e37b940e..541c6e0353b5 100644 --- a/lib/asan/asan_errors.cc +++ b/lib/asan/asan_errors.cpp @@ -1,4 +1,4 @@ -//===-- asan_errors.cc ------------------------------------------*- C++ -*-===// +//===-- asan_errors.cpp -----------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -35,7 +35,8 @@ static void OnStackUnwind(const SignalContext &sig, // corresponding code in the sanitizer_common and we use this callback to // print it. static_cast<const ScarinessScoreBase *>(callback_context)->Print(); - stack->Unwind(sig.pc, sig.bp, sig.context, fast); + stack->Unwind(StackTrace::GetNextInstructionPc(sig.pc), sig.bp, sig.context, + fast); } void ErrorDeadlySignal::Print() { @@ -244,7 +245,7 @@ void ErrorInvalidPosixMemalignAlignment::Print() { "ERROR: AddressSanitizer: invalid alignment requested in posix_memalign: " "%zd, alignment must be a power of two and a multiple of sizeof(void*) " "== %zd (thread %s)\n", - alignment, sizeof(void*), AsanThreadIdAndName(tid).c_str()); // NOLINT + alignment, sizeof(void *), AsanThreadIdAndName(tid).c_str()); Printf("%s", d.Default()); stack->Print(); PrintHintAllocatorCannotReturnNull(); diff --git a/lib/asan/asan_errors.h b/lib/asan/asan_errors.h index b84f56c18535..a7fda2fd9f5d 100644 --- a/lib/asan/asan_errors.h +++ b/lib/asan/asan_errors.h @@ -48,7 +48,8 @@ struct ErrorDeadlySignal : ErrorBase { scariness.Scare(10, "stack-overflow"); } else if (!signal.is_memory_access) { scariness.Scare(10, "signal"); - } else if (signal.addr < GetPageSizeCached()) { + } else if (signal.is_true_faulting_addr && + signal.addr < GetPageSizeCached()) { scariness.Scare(10, "null-deref"); } else if (signal.addr == signal.pc) { scariness.Scare(60, "wild-jump"); diff --git a/lib/asan/asan_fake_stack.cc b/lib/asan/asan_fake_stack.cpp index f8e1ac4b7bfe..295e6debc96c 100644 --- a/lib/asan/asan_fake_stack.cc +++ b/lib/asan/asan_fake_stack.cpp @@ -1,4 +1,4 @@ -//===-- asan_fake_stack.cc ------------------------------------------------===// +//===-- asan_fake_stack.cpp -----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lib/asan/asan_fake_stack.h b/lib/asan/asan_fake_stack.h index 59ba85218f88..270a19816d6e 100644 --- a/lib/asan/asan_fake_stack.h +++ b/lib/asan/asan_fake_stack.h @@ -8,7 +8,7 @@ // // This file is a part of AddressSanitizer, an address sanity checker. // -// ASan-private header for asan_fake_stack.cc, implements FakeStack. +// ASan-private header for asan_fake_stack.cpp, implements FakeStack. //===----------------------------------------------------------------------===// #ifndef ASAN_FAKE_STACK_H diff --git a/lib/asan/asan_flags.cc b/lib/asan/asan_flags.cpp index 89e98936129d..c5c70eaed737 100644 --- a/lib/asan/asan_flags.cc +++ b/lib/asan/asan_flags.cpp @@ -1,4 +1,4 @@ -//===-- asan_flags.cc -------------------------------------------*- C++ -*-===// +//===-- asan_flags.cpp ------------------------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lib/asan/asan_flags.inc b/lib/asan/asan_flags.inc index d360e03ca55e..43c70dbca56b 100644 --- a/lib/asan/asan_flags.inc +++ b/lib/asan/asan_flags.inc @@ -139,10 +139,10 @@ ASAN_FLAG( "If >= 2, detect operations like <, <=, >, >= and - on invalid pointer " "pairs (e.g. when pointers belong to different objects); " "If == 1, detect invalid operations only when both pointers are non-null.") -ASAN_FLAG( - bool, detect_container_overflow, true, - "If true, honor the container overflow annotations. See " - "https://github.com/google/sanitizers/wiki/AddressSanitizerContainerOverflow") +ASAN_FLAG(bool, detect_container_overflow, true, + "If true, honor the container overflow annotations. See " + "https://github.com/google/sanitizers/wiki/" + "AddressSanitizerContainerOverflow") ASAN_FLAG(int, detect_odr_violation, 2, "If >=2, detect violation of One-Definition-Rule (ODR); " "If ==1, detect ODR-violation only if the two variables " @@ -158,5 +158,6 @@ ASAN_FLAG(bool, allocator_frees_and_returns_null_on_realloc_zero, true, ASAN_FLAG(bool, verify_asan_link_order, true, "Check position of ASan runtime in library list (needs to be disabled" " when other library has to be preloaded system-wide)") -ASAN_FLAG(bool, windows_hook_rtl_allocators, false, - "(Windows only) enable hooking of Rtl(Allocate|Free|Size|ReAllocate)Heap.") +ASAN_FLAG( + bool, windows_hook_rtl_allocators, false, + "(Windows only) enable hooking of Rtl(Allocate|Free|Size|ReAllocate)Heap.") diff --git a/lib/asan/asan_fuchsia.cc b/lib/asan/asan_fuchsia.cpp index aebc17f38b4b..f8b2d5f26979 100644 --- a/lib/asan/asan_fuchsia.cc +++ b/lib/asan/asan_fuchsia.cpp @@ -1,4 +1,4 @@ -//===-- asan_fuchsia.cc --------------------------------------------------===// +//===-- asan_fuchsia.cpp -------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -28,7 +28,7 @@ namespace __asan { // The system already set up the shadow memory for us. // __sanitizer::GetMaxUserVirtualAddress has already been called by -// AsanInitInternal->InitializeHighMemEnd (asan_rtl.cc). +// AsanInitInternal->InitializeHighMemEnd (asan_rtl.cpp). // Just do some additional sanity checks here. void InitializeShadowMemory() { if (Verbosity()) PrintAddressSpaceLayout(); @@ -172,7 +172,7 @@ static void ThreadCreateHook(void *hook, bool aborted) { // This is called in the newly-created thread before it runs anything else, // with the pointer returned by BeforeThreadCreateHook (above). -// cf. asan_interceptors.cc:asan_thread_start +// cf. asan_interceptors.cpp:asan_thread_start static void ThreadStartHook(void *hook, uptr os_id) { AsanThread *thread = static_cast<AsanThread *>(hook); SetCurrentThread(thread); diff --git a/lib/asan/asan_globals.cc b/lib/asan/asan_globals.cpp index a831fdf9cd93..9d7dbc6f264c 100644 --- a/lib/asan/asan_globals.cc +++ b/lib/asan/asan_globals.cpp @@ -1,4 +1,4 @@ -//===-- asan_globals.cc ---------------------------------------------------===// +//===-- asan_globals.cpp --------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -227,8 +227,7 @@ static void RegisterGlobal(const Global *g) { list_of_all_globals = l; if (g->has_dynamic_init) { if (!dynamic_init_globals) { - dynamic_init_globals = - new (allocator_for_globals) VectorOfGlobals; // NOLINT + dynamic_init_globals = new (allocator_for_globals) VectorOfGlobals; dynamic_init_globals->reserve(kDynamicInitGlobalsInitialCapacity); } DynInitGlobal dyn_global = { *g, false }; @@ -315,8 +314,7 @@ void PrintGlobalLocation(InternalScopedString *str, const __asan_global &g) { } // namespace __asan // ---------------------- Interface ---------------- {{{1 -using namespace __asan; // NOLINT - +using namespace __asan; // Apply __asan_register_globals to all globals found in the same loaded // executable or shared library as `flag'. The flag tracks whether globals have @@ -364,7 +362,7 @@ void __asan_register_globals(__asan_global *globals, uptr n) { BlockingMutexLock lock(&mu_for_globals); if (!global_registration_site_vector) { global_registration_site_vector = - new (allocator_for_globals) GlobalRegistrationSiteVector; // NOLINT + new (allocator_for_globals) GlobalRegistrationSiteVector; global_registration_site_vector->reserve(128); } GlobalRegistrationSite site = {stack_id, &globals[0], &globals[n - 1]}; diff --git a/lib/asan/asan_globals_win.cc b/lib/asan/asan_globals_win.cpp index bdce37f701e1..19af88ab12b4 100644 --- a/lib/asan/asan_globals_win.cc +++ b/lib/asan/asan_globals_win.cpp @@ -1,4 +1,4 @@ -//===-- asan_globals_win.cc -----------------------------------------------===// +//===-- asan_globals_win.cpp ----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -15,8 +15,8 @@ namespace __asan { -#pragma section(".ASAN$GA", read, write) // NOLINT -#pragma section(".ASAN$GZ", read, write) // NOLINT +#pragma section(".ASAN$GA", read, write) +#pragma section(".ASAN$GZ", read, write) extern "C" __declspec(allocate(".ASAN$GA")) ALIGNED(sizeof(__asan_global)) __asan_global __asan_globals_start = {}; extern "C" __declspec(allocate(".ASAN$GZ")) @@ -49,8 +49,8 @@ static void unregister_dso_globals() { } // Register globals -#pragma section(".CRT$XCU", long, read) // NOLINT -#pragma section(".CRT$XTX", long, read) // NOLINT +#pragma section(".CRT$XCU", long, read) +#pragma section(".CRT$XTX", long, read) extern "C" __declspec(allocate(".CRT$XCU")) void (*const __asan_dso_reg_hook)() = ®ister_dso_globals; extern "C" __declspec(allocate(".CRT$XTX")) diff --git a/lib/asan/asan_interceptors.cc b/lib/asan/asan_interceptors.cpp index 7eea7d2f942b..b19cf25c7cd0 100644 --- a/lib/asan/asan_interceptors.cc +++ b/lib/asan/asan_interceptors.cpp @@ -1,4 +1,4 @@ -//===-- asan_interceptors.cc ----------------------------------------------===// +//===-- asan_interceptors.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -24,7 +24,7 @@ #include "sanitizer_common/sanitizer_libc.h" // There is no general interception at all on Fuchsia and RTEMS. -// Only the functions in asan_interceptors_memintrinsics.cc are +// Only the functions in asan_interceptors_memintrinsics.cpp are // really defined to replace libc functions. #if !SANITIZER_FUCHSIA && !SANITIZER_RTEMS @@ -79,7 +79,7 @@ int OnExit() { } // namespace __asan // ---------------------- Wrappers ---------------- {{{1 -using namespace __asan; // NOLINT +using namespace __asan; DECLARE_REAL_AND_INTERCEPTOR(void *, malloc, uptr) DECLARE_REAL_AND_INTERCEPTOR(void, free, void *) @@ -164,6 +164,11 @@ DECLARE_REAL_AND_INTERCEPTOR(void, free, void *) ASAN_MEMSET_IMPL(ctx, block, c, size); \ } while (false) +#if CAN_SANITIZE_LEAKS +#define COMMON_INTERCEPTOR_STRERROR() \ + __lsan::ScopedInterceptorDisabler disabler +#endif + #include "sanitizer_common/sanitizer_common_interceptors.inc" #include "sanitizer_common/sanitizer_signal_interceptors.inc" @@ -373,26 +378,26 @@ DEFINE_REAL(char*, index, const char *string, int c) // For both strcat() and strncat() we need to check the validity of |to| // argument irrespective of the |from| length. -INTERCEPTOR(char*, strcat, char *to, const char *from) { // NOLINT - void *ctx; - ASAN_INTERCEPTOR_ENTER(ctx, strcat); // NOLINT - ENSURE_ASAN_INITED(); - if (flags()->replace_str) { - uptr from_length = REAL(strlen)(from); - ASAN_READ_RANGE(ctx, from, from_length + 1); - uptr to_length = REAL(strlen)(to); - ASAN_READ_STRING_OF_LEN(ctx, to, to_length, to_length); - ASAN_WRITE_RANGE(ctx, to + to_length, from_length + 1); - // If the copying actually happens, the |from| string should not overlap - // with the resulting string starting at |to|, which has a length of - // to_length + from_length + 1. - if (from_length > 0) { - CHECK_RANGES_OVERLAP("strcat", to, from_length + to_length + 1, - from, from_length + 1); + INTERCEPTOR(char *, strcat, char *to, const char *from) { + void *ctx; + ASAN_INTERCEPTOR_ENTER(ctx, strcat); + ENSURE_ASAN_INITED(); + if (flags()->replace_str) { + uptr from_length = REAL(strlen)(from); + ASAN_READ_RANGE(ctx, from, from_length + 1); + uptr to_length = REAL(strlen)(to); + ASAN_READ_STRING_OF_LEN(ctx, to, to_length, to_length); + ASAN_WRITE_RANGE(ctx, to + to_length, from_length + 1); + // If the copying actually happens, the |from| string should not overlap + // with the resulting string starting at |to|, which has a length of + // to_length + from_length + 1. + if (from_length > 0) { + CHECK_RANGES_OVERLAP("strcat", to, from_length + to_length + 1, from, + from_length + 1); + } } + return REAL(strcat)(to, from); } - return REAL(strcat)(to, from); // NOLINT -} INTERCEPTOR(char*, strncat, char *to, const char *from, uptr size) { void *ctx; @@ -413,16 +418,17 @@ INTERCEPTOR(char*, strncat, char *to, const char *from, uptr size) { return REAL(strncat)(to, from, size); } -INTERCEPTOR(char*, strcpy, char *to, const char *from) { // NOLINT +INTERCEPTOR(char *, strcpy, char *to, const char *from) { void *ctx; - ASAN_INTERCEPTOR_ENTER(ctx, strcpy); // NOLINT + ASAN_INTERCEPTOR_ENTER(ctx, strcpy); #if SANITIZER_MAC - if (UNLIKELY(!asan_inited)) return REAL(strcpy)(to, from); // NOLINT + if (UNLIKELY(!asan_inited)) + return REAL(strcpy)(to, from); #endif // strcpy is called from malloc_default_purgeable_zone() // in __asan::ReplaceSystemAlloc() on Mac. if (asan_init_is_running) { - return REAL(strcpy)(to, from); // NOLINT + return REAL(strcpy)(to, from); } ENSURE_ASAN_INITED(); if (flags()->replace_str) { @@ -431,7 +437,7 @@ INTERCEPTOR(char*, strcpy, char *to, const char *from) { // NOLINT ASAN_READ_RANGE(ctx, from, from_size); ASAN_WRITE_RANGE(ctx, to, from_size); } - return REAL(strcpy)(to, from); // NOLINT + return REAL(strcpy)(to, from); } INTERCEPTOR(char*, strdup, const char *s) { @@ -479,8 +485,7 @@ INTERCEPTOR(char*, strncpy, char *to, const char *from, uptr size) { return REAL(strncpy)(to, from, size); } -INTERCEPTOR(long, strtol, const char *nptr, // NOLINT - char **endptr, int base) { +INTERCEPTOR(long, strtol, const char *nptr, char **endptr, int base) { void *ctx; ASAN_INTERCEPTOR_ENTER(ctx, strtol); ENSURE_ASAN_INITED(); @@ -488,7 +493,7 @@ INTERCEPTOR(long, strtol, const char *nptr, // NOLINT return REAL(strtol)(nptr, endptr, base); } char *real_endptr; - long result = REAL(strtol)(nptr, &real_endptr, base); // NOLINT + long result = REAL(strtol)(nptr, &real_endptr, base); StrtolFixAndCheck(ctx, nptr, endptr, real_endptr, base); return result; } @@ -514,7 +519,7 @@ INTERCEPTOR(int, atoi, const char *nptr) { return result; } -INTERCEPTOR(long, atol, const char *nptr) { // NOLINT +INTERCEPTOR(long, atol, const char *nptr) { void *ctx; ASAN_INTERCEPTOR_ENTER(ctx, atol); #if SANITIZER_MAC @@ -525,15 +530,14 @@ INTERCEPTOR(long, atol, const char *nptr) { // NOLINT return REAL(atol)(nptr); } char *real_endptr; - long result = REAL(strtol)(nptr, &real_endptr, 10); // NOLINT + long result = REAL(strtol)(nptr, &real_endptr, 10); FixRealStrtolEndptr(nptr, &real_endptr); ASAN_READ_STRING(ctx, nptr, (real_endptr - nptr) + 1); return result; } #if ASAN_INTERCEPT_ATOLL_AND_STRTOLL -INTERCEPTOR(long long, strtoll, const char *nptr, // NOLINT - char **endptr, int base) { +INTERCEPTOR(long long, strtoll, const char *nptr, char **endptr, int base) { void *ctx; ASAN_INTERCEPTOR_ENTER(ctx, strtoll); ENSURE_ASAN_INITED(); @@ -541,12 +545,12 @@ INTERCEPTOR(long long, strtoll, const char *nptr, // NOLINT return REAL(strtoll)(nptr, endptr, base); } char *real_endptr; - long long result = REAL(strtoll)(nptr, &real_endptr, base); // NOLINT + long long result = REAL(strtoll)(nptr, &real_endptr, base); StrtolFixAndCheck(ctx, nptr, endptr, real_endptr, base); return result; } -INTERCEPTOR(long long, atoll, const char *nptr) { // NOLINT +INTERCEPTOR(long long, atoll, const char *nptr) { void *ctx; ASAN_INTERCEPTOR_ENTER(ctx, atoll); ENSURE_ASAN_INITED(); @@ -554,31 +558,66 @@ INTERCEPTOR(long long, atoll, const char *nptr) { // NOLINT return REAL(atoll)(nptr); } char *real_endptr; - long long result = REAL(strtoll)(nptr, &real_endptr, 10); // NOLINT + long long result = REAL(strtoll)(nptr, &real_endptr, 10); FixRealStrtolEndptr(nptr, &real_endptr); ASAN_READ_STRING(ctx, nptr, (real_endptr - nptr) + 1); return result; } #endif // ASAN_INTERCEPT_ATOLL_AND_STRTOLL -#if ASAN_INTERCEPT___CXA_ATEXIT +#if ASAN_INTERCEPT___CXA_ATEXIT || ASAN_INTERCEPT_ATEXIT static void AtCxaAtexit(void *unused) { (void)unused; StopInitOrderChecking(); } +#endif +#if ASAN_INTERCEPT___CXA_ATEXIT INTERCEPTOR(int, __cxa_atexit, void (*func)(void *), void *arg, void *dso_handle) { #if SANITIZER_MAC if (UNLIKELY(!asan_inited)) return REAL(__cxa_atexit)(func, arg, dso_handle); #endif ENSURE_ASAN_INITED(); +#if CAN_SANITIZE_LEAKS + __lsan::ScopedInterceptorDisabler disabler; +#endif int res = REAL(__cxa_atexit)(func, arg, dso_handle); REAL(__cxa_atexit)(AtCxaAtexit, nullptr, nullptr); return res; } #endif // ASAN_INTERCEPT___CXA_ATEXIT +#if ASAN_INTERCEPT_ATEXIT +INTERCEPTOR(int, atexit, void (*func)()) { + ENSURE_ASAN_INITED(); +#if CAN_SANITIZE_LEAKS + __lsan::ScopedInterceptorDisabler disabler; +#endif + // Avoid calling real atexit as it is unrechable on at least on Linux. + int res = REAL(__cxa_atexit)((void (*)(void *a))func, nullptr, nullptr); + REAL(__cxa_atexit)(AtCxaAtexit, nullptr, nullptr); + return res; +} +#endif + +#if ASAN_INTERCEPT_PTHREAD_ATFORK +extern "C" { +extern int _pthread_atfork(void (*prepare)(), void (*parent)(), + void (*child)()); +}; + +INTERCEPTOR(int, pthread_atfork, void (*prepare)(), void (*parent)(), + void (*child)()) { +#if CAN_SANITIZE_LEAKS + __lsan::ScopedInterceptorDisabler disabler; +#endif + // REAL(pthread_atfork) cannot be called due to symbol indirections at least + // on NetBSD + return _pthread_atfork(prepare, parent, child); +} +#endif + #if ASAN_INTERCEPT_VFORK DEFINE_REAL(int, vfork) DECLARE_EXTERN_INTERCEPTOR_AND_WRAPPER(int, vfork) @@ -594,8 +633,8 @@ void InitializeAsanInterceptors() { InitializeSignalInterceptors(); // Intercept str* functions. - ASAN_INTERCEPT_FUNC(strcat); // NOLINT - ASAN_INTERCEPT_FUNC(strcpy); // NOLINT + ASAN_INTERCEPT_FUNC(strcat); + ASAN_INTERCEPT_FUNC(strcpy); ASAN_INTERCEPT_FUNC(strncat); ASAN_INTERCEPT_FUNC(strncpy); ASAN_INTERCEPT_FUNC(strdup); @@ -661,6 +700,14 @@ void InitializeAsanInterceptors() { ASAN_INTERCEPT_FUNC(__cxa_atexit); #endif +#if ASAN_INTERCEPT_ATEXIT + ASAN_INTERCEPT_FUNC(atexit); +#endif + +#if ASAN_INTERCEPT_PTHREAD_ATFORK + ASAN_INTERCEPT_FUNC(pthread_atfork); +#endif + #if ASAN_INTERCEPT_VFORK ASAN_INTERCEPT_FUNC(vfork); #endif diff --git a/lib/asan/asan_interceptors.h b/lib/asan/asan_interceptors.h index 381b03984191..344a64bd83d3 100644 --- a/lib/asan/asan_interceptors.h +++ b/lib/asan/asan_interceptors.h @@ -8,7 +8,7 @@ // // This file is a part of AddressSanitizer, an address sanity checker. // -// ASan-private header for asan_interceptors.cc +// ASan-private header for asan_interceptors.cpp //===----------------------------------------------------------------------===// #ifndef ASAN_INTERCEPTORS_H #define ASAN_INTERCEPTORS_H @@ -99,6 +99,12 @@ void InitializePlatformInterceptors(); # define ASAN_INTERCEPT___CXA_ATEXIT 0 #endif +#if SANITIZER_NETBSD +# define ASAN_INTERCEPT_ATEXIT 1 +#else +# define ASAN_INTERCEPT_ATEXIT 0 +#endif + #if SANITIZER_LINUX && !SANITIZER_ANDROID # define ASAN_INTERCEPT___STRDUP 1 #else @@ -112,6 +118,12 @@ void InitializePlatformInterceptors(); # define ASAN_INTERCEPT_VFORK 0 #endif +#if SANITIZER_NETBSD +# define ASAN_INTERCEPT_PTHREAD_ATFORK 1 +#else +# define ASAN_INTERCEPT_PTHREAD_ATFORK 0 +#endif + DECLARE_REAL(int, memcmp, const void *a1, const void *a2, uptr size) DECLARE_REAL(char*, strchr, const char *str, int c) DECLARE_REAL(SIZE_T, strlen, const char *s) diff --git a/lib/asan/asan_interceptors_memintrinsics.cc b/lib/asan/asan_interceptors_memintrinsics.cpp index e17f9ba4aab5..ccdd5159042c 100644 --- a/lib/asan/asan_interceptors_memintrinsics.cc +++ b/lib/asan/asan_interceptors_memintrinsics.cpp @@ -1,4 +1,4 @@ -//===-- asan_interceptors_memintrinsics.cc --------------------------------===// +//===-- asan_interceptors_memintrinsics.cpp -------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -16,7 +16,7 @@ #include "asan_stack.h" #include "asan_suppressions.h" -using namespace __asan; // NOLINT +using namespace __asan; void *__asan_memcpy(void *to, const void *from, uptr size) { ASAN_MEMCPY_IMPL(nullptr, to, from, size); diff --git a/lib/asan/asan_interceptors_memintrinsics.h b/lib/asan/asan_interceptors_memintrinsics.h index 1fd65fe24953..632f0515a9eb 100644 --- a/lib/asan/asan_interceptors_memintrinsics.h +++ b/lib/asan/asan_interceptors_memintrinsics.h @@ -8,7 +8,7 @@ // // This file is a part of AddressSanitizer, an address sanity checker. // -// ASan-private header for asan_memintrin.cc +// ASan-private header for asan_interceptors_memintrinsics.cpp //===---------------------------------------------------------------------===// #ifndef ASAN_MEMINTRIN_H #define ASAN_MEMINTRIN_H diff --git a/lib/asan/asan_internal.h b/lib/asan/asan_internal.h index e4f771079293..72a4c3f22ff1 100644 --- a/lib/asan/asan_internal.h +++ b/lib/asan/asan_internal.h @@ -61,29 +61,29 @@ using __sanitizer::StackTrace; void AsanInitFromRtl(); -// asan_win.cc +// asan_win.cpp void InitializePlatformExceptionHandlers(); // Returns whether an address is a valid allocated system heap block. // 'addr' must point to the beginning of the block. bool IsSystemHeapAddress(uptr addr); -// asan_rtl.cc +// asan_rtl.cpp void PrintAddressSpaceLayout(); void NORETURN ShowStatsAndAbort(); -// asan_shadow_setup.cc +// asan_shadow_setup.cpp void InitializeShadowMemory(); -// asan_malloc_linux.cc / asan_malloc_mac.cc +// asan_malloc_linux.cpp / asan_malloc_mac.cpp void ReplaceSystemMalloc(); -// asan_linux.cc / asan_mac.cc / asan_rtems.cc / asan_win.cc +// asan_linux.cpp / asan_mac.cpp / asan_rtems.cpp / asan_win.cpp uptr FindDynamicShadowStart(); void *AsanDoesNotSupportStaticLinkage(); void AsanCheckDynamicRTPrereqs(); void AsanCheckIncompatibleRT(); -// asan_thread.cc +// asan_thread.cpp AsanThread *CreateMainThread(); // Support function for __asan_(un)register_image_globals. Searches for the diff --git a/lib/asan/asan_linux.cc b/lib/asan/asan_linux.cpp index f9182328916f..ce5e873dc518 100644 --- a/lib/asan/asan_linux.cc +++ b/lib/asan/asan_linux.cpp @@ -1,4 +1,4 @@ -//===-- asan_linux.cc -----------------------------------------------------===// +//===-- asan_linux.cpp ----------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lib/asan/asan_mac.cc b/lib/asan/asan_mac.cpp index e776acd2f539..a8d3f5d3473c 100644 --- a/lib/asan/asan_mac.cc +++ b/lib/asan/asan_mac.cpp @@ -1,4 +1,4 @@ -//===-- asan_mac.cc -------------------------------------------------------===// +//===-- asan_mac.cpp ------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -205,7 +205,7 @@ void asan_dispatch_call_block_and_release(void *block) { } // namespace __asan -using namespace __asan; // NOLINT +using namespace __asan; // Wrap |ctxt| and |func| into an asan_block_context_t. // The caller retains control of the allocated context. diff --git a/lib/asan/asan_malloc_linux.cc b/lib/asan/asan_malloc_linux.cpp index 86fcd3b12d58..faa8968a5d00 100644 --- a/lib/asan/asan_malloc_linux.cc +++ b/lib/asan/asan_malloc_linux.cpp @@ -1,4 +1,4 @@ -//===-- asan_malloc_linux.cc ----------------------------------------------===// +//===-- asan_malloc_linux.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -27,7 +27,7 @@ #include "asan_stack.h" // ---------------------- Replacement functions ---------------- {{{1 -using namespace __asan; // NOLINT +using namespace __asan; static uptr allocated_for_dlsym; static uptr last_dlsym_alloc_size_in_words; diff --git a/lib/asan/asan_malloc_mac.cc b/lib/asan/asan_malloc_mac.cpp index 06dc1c289267..e8484685daed 100644 --- a/lib/asan/asan_malloc_mac.cc +++ b/lib/asan/asan_malloc_mac.cpp @@ -1,4 +1,4 @@ -//===-- asan_malloc_mac.cc ------------------------------------------------===// +//===-- asan_malloc_mac.cpp -----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lib/asan/asan_malloc_win.cc b/lib/asan/asan_malloc_win.cpp index 5fad55d6e284..13c6f652119b 100644 --- a/lib/asan/asan_malloc_win.cc +++ b/lib/asan/asan_malloc_win.cpp @@ -1,4 +1,4 @@ -//===-- asan_malloc_win.cc ------------------------------------------------===// +//===-- asan_malloc_win.cpp -----------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -54,7 +54,7 @@ size_t WINAPI HeapSize(HANDLE hHeap, DWORD dwFlags, LPCVOID lpMem); BOOL WINAPI HeapValidate(HANDLE hHeap, DWORD dwFlags, LPCVOID lpMem); } -using namespace __asan; // NOLINT +using namespace __asan; // MT: Simply defining functions with the same signature in *.obj // files overrides the standard functions in the CRT. @@ -528,10 +528,11 @@ void ReplaceSystemMalloc() { (uptr)WRAP(RtlAllocateHeap), (uptr *)&REAL(RtlAllocateHeap)); } else { -#define INTERCEPT_UCRT_FUNCTION(func) \ - if (!INTERCEPT_FUNCTION_DLLIMPORT("ucrtbase.dll", \ - "api-ms-win-core-heap-l1-1-0.dll", func)) \ - VPrintf(2, "Failed to intercept ucrtbase.dll import %s\n", #func); +#define INTERCEPT_UCRT_FUNCTION(func) \ + if (!INTERCEPT_FUNCTION_DLLIMPORT( \ + "ucrtbase.dll", "api-ms-win-core-heap-l1-1-0.dll", func)) { \ + VPrintf(2, "Failed to intercept ucrtbase.dll import %s\n", #func); \ + } INTERCEPT_UCRT_FUNCTION(HeapAlloc); INTERCEPT_UCRT_FUNCTION(HeapFree); INTERCEPT_UCRT_FUNCTION(HeapReAlloc); diff --git a/lib/asan/asan_memory_profile.cc b/lib/asan/asan_memory_profile.cpp index 87d874d2f274..4fcd5600ed1a 100644 --- a/lib/asan/asan_memory_profile.cc +++ b/lib/asan/asan_memory_profile.cpp @@ -1,4 +1,4 @@ -//===-- asan_memory_profile.cc.cc -----------------------------------------===// +//===-- asan_memory_profile.cpp ----------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lib/asan/asan_new_delete.cc b/lib/asan/asan_new_delete.cpp index 5f51d12b1b5a..5dfcc00fd5d1 100644 --- a/lib/asan/asan_new_delete.cc +++ b/lib/asan/asan_new_delete.cpp @@ -1,4 +1,4 @@ -//===-- asan_interceptors.cc ----------------------------------------------===// +//===-- asan_interceptors.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -48,7 +48,7 @@ COMMENT_EXPORT("??_V@YAXPAX@Z") // operator delete[] #define CXX_OPERATOR_ATTRIBUTE INTERCEPTOR_ATTRIBUTE #endif -using namespace __asan; // NOLINT +using namespace __asan; // FreeBSD prior v9.2 have wrong definition of 'size_t'. // http://svnweb.freebsd.org/base?view=revision&revision=232261 diff --git a/lib/asan/asan_poisoning.cc b/lib/asan/asan_poisoning.cpp index 44b87c76e9cc..f3fbe684e2cb 100644 --- a/lib/asan/asan_poisoning.cc +++ b/lib/asan/asan_poisoning.cpp @@ -1,4 +1,4 @@ -//===-- asan_poisoning.cc -------------------------------------------------===// +//===-- asan_poisoning.cpp ------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -92,7 +92,7 @@ void AsanPoisonOrUnpoisonIntraObjectRedzone(uptr ptr, uptr size, bool poison) { } // namespace __asan // ---------------------- Interface ---------------- {{{1 -using namespace __asan; // NOLINT +using namespace __asan; // Current implementation of __asan_(un)poison_memory_region doesn't check // that user program (un)poisons the memory it owns. It poisons memory diff --git a/lib/asan/asan_posix.cc b/lib/asan/asan_posix.cpp index 5c5e0359ad6c..920d216624a3 100644 --- a/lib/asan/asan_posix.cc +++ b/lib/asan/asan_posix.cpp @@ -1,4 +1,4 @@ -//===-- asan_posix.cc -----------------------------------------------------===// +//===-- asan_posix.cpp ----------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -39,8 +39,8 @@ void AsanOnDeadlySignal(int signo, void *siginfo, void *context) { // ---------------------- TSD ---------------- {{{1 -#if SANITIZER_NETBSD || SANITIZER_FREEBSD -// Thread Static Data cannot be used in early init on NetBSD and FreeBSD. +#if SANITIZER_NETBSD && !ASAN_DYNAMIC +// Thread Static Data cannot be used in early static ASan init on NetBSD. // Reuse the Asan TSD API for compatibility with existing code // with an alternative implementation. diff --git a/lib/asan/asan_preinit.cc b/lib/asan/asan_preinit.cpp index 444998c44176..b07556ec96f8 100644 --- a/lib/asan/asan_preinit.cc +++ b/lib/asan/asan_preinit.cpp @@ -1,4 +1,4 @@ -//===-- asan_preinit.cc ---------------------------------------------------===// +//===-- asan_preinit.cpp --------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lib/asan/asan_premap_shadow.cc b/lib/asan/asan_premap_shadow.cpp index 6e547718c68e..7835e99748ff 100644 --- a/lib/asan/asan_premap_shadow.cc +++ b/lib/asan/asan_premap_shadow.cpp @@ -1,4 +1,4 @@ -//===-- asan_premap_shadow.cc ---------------------------------------------===// +//===-- asan_premap_shadow.cpp --------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lib/asan/asan_report.cc b/lib/asan/asan_report.cpp index 49067437d9d4..2e6ce436d030 100644 --- a/lib/asan/asan_report.cc +++ b/lib/asan/asan_report.cpp @@ -1,4 +1,4 @@ -//===-- asan_report.cc ----------------------------------------------------===// +//===-- asan_report.cpp ---------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -410,8 +410,12 @@ static bool IsInvalidPointerPair(uptr a1, uptr a2) { static INLINE void CheckForInvalidPointerPair(void *p1, void *p2) { switch (flags()->detect_invalid_pointer_pairs) { - case 0 : return; - case 1 : if (p1 == nullptr || p2 == nullptr) return; break; + case 0: + return; + case 1: + if (p1 == nullptr || p2 == nullptr) + return; + break; } uptr a1 = reinterpret_cast<uptr>(p1); @@ -472,7 +476,7 @@ void ReportGenericError(uptr pc, uptr bp, uptr sp, uptr addr, bool is_write, } // namespace __asan // --------------------------- Interface --------------------- {{{1 -using namespace __asan; // NOLINT +using namespace __asan; void __asan_report_error(uptr pc, uptr bp, uptr sp, uptr addr, int is_write, uptr access_size, u32 exp) { diff --git a/lib/asan/asan_rtems.cc b/lib/asan/asan_rtems.cpp index 4878f4d67c86..ecd568c5981b 100644 --- a/lib/asan/asan_rtems.cc +++ b/lib/asan/asan_rtems.cpp @@ -1,4 +1,4 @@ -//===-- asan_rtems.cc -----------------------------------------------------===// +//===-- asan_rtems.cpp ----------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -181,11 +181,11 @@ static void ThreadStartHook(void *hook, uptr os_id) { asanThreadRegistry().GetThreadLocked(thread->tid())->status; DCHECK(status == ThreadStatusCreated || status == ThreadStatusRunning); // Determine whether we are starting or restarting the thread. - if (status == ThreadStatusCreated) + if (status == ThreadStatusCreated) { // In lieu of AsanThread::ThreadStart. asanThreadRegistry().StartThread(thread->tid(), os_id, ThreadType::Regular, nullptr); - else { + } else { // In a thread restart, a thread may resume execution at an // arbitrary function entry point, with its stack and TLS state // reset. We unpoison the stack in that case. diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cpp index db8dcd0689a5..594d7752eea6 100644 --- a/lib/asan/asan_rtl.cc +++ b/lib/asan/asan_rtl.cpp @@ -1,4 +1,4 @@ -//===-- asan_rtl.cc -------------------------------------------------------===// +//===-- asan_rtl.cpp ------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -402,7 +402,6 @@ static void AsanInitInternal() { asan_init_is_running = true; CacheBinaryName(); - CheckASLR(); // Initialize flags. This must be done early, because most of the // initialization steps look at flags(). @@ -450,6 +449,7 @@ static void AsanInitInternal() { SetLowLevelAllocateCallback(OnLowLevelAllocate); InitializeAsanInterceptors(); + CheckASLR(); // Enable system log ("adb logcat") on Android. // Doing this before interceptors are initialized crashes in: @@ -542,7 +542,7 @@ void AsanInitFromRtl() { // (and thus normal initializers from .preinit_array or modules haven't run). class AsanInitializer { -public: // NOLINT + public: AsanInitializer() { AsanInitFromRtl(); } @@ -554,7 +554,7 @@ static AsanInitializer asan_initializer; } // namespace __asan // ---------------------- Interface ---------------- {{{1 -using namespace __asan; // NOLINT +using namespace __asan; void NOINLINE __asan_handle_no_return() { if (asan_init_is_running) diff --git a/lib/asan/asan_scariness_score.h b/lib/asan/asan_scariness_score.h index 9e7ba47d82dc..3932973c225e 100644 --- a/lib/asan/asan_scariness_score.h +++ b/lib/asan/asan_scariness_score.h @@ -43,7 +43,7 @@ struct ScarinessScoreBase { internal_strlcat(descr, "-", sizeof(descr)); internal_strlcat(descr, reason, sizeof(descr)); score += add_to_score; - }; + } int GetScore() const { return score; } const char *GetDescription() const { return descr; } void Print() const { diff --git a/lib/asan/asan_shadow_setup.cc b/lib/asan/asan_shadow_setup.cpp index 9cfa4e2bd65d..17324932a86f 100644 --- a/lib/asan/asan_shadow_setup.cc +++ b/lib/asan/asan_shadow_setup.cpp @@ -1,4 +1,4 @@ -//===-- asan_shadow_setup.cc ----------------------------------------------===// +//===-- asan_shadow_setup.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -13,7 +13,7 @@ #include "sanitizer_common/sanitizer_platform.h" -// asan_fuchsia.cc and asan_rtems.cc have their own +// asan_fuchsia.cpp and asan_rtems.cpp have their own // InitializeShadowMemory implementation. #if !SANITIZER_FUCHSIA && !SANITIZER_RTEMS @@ -30,14 +30,13 @@ void ReserveShadowMemoryRange(uptr beg, uptr end, const char *name) { CHECK_EQ(((end + 1) % GetMmapGranularity()), 0); uptr size = end - beg + 1; DecreaseTotalMmap(size); // Don't count the shadow against mmap_limit_mb. - if (!MmapFixedNoReserve(beg, size, name)) { + if (!MmapFixedSuperNoReserve(beg, size, name)) { Report( "ReserveShadowMemoryRange failed while trying to map 0x%zx bytes. " "Perhaps you're using ulimit -v\n", size); Abort(); } - if (common_flags()->no_huge_pages_for_shadow) NoHugePagesInRegion(beg, size); if (common_flags()->use_madv_dontdump) DontDumpShadowMemory(beg, size); } diff --git a/lib/asan/asan_stack.cc b/lib/asan/asan_stack.cpp index b244da4fa0ad..b7f4e6aeeab0 100644 --- a/lib/asan/asan_stack.cc +++ b/lib/asan/asan_stack.cpp @@ -1,4 +1,4 @@ -//===-- asan_stack.cc -----------------------------------------------------===// +//===-- asan_stack.cpp ----------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/lib/asan/asan_stack.h b/lib/asan/asan_stack.h index 3a4b3cefc5de..4089d3d7340e 100644 --- a/lib/asan/asan_stack.h +++ b/lib/asan/asan_stack.h @@ -8,7 +8,7 @@ // // This file is a part of AddressSanitizer, an address sanity checker. // -// ASan-private header for asan_stack.cc. +// ASan-private header for asan_stack.cpp. //===----------------------------------------------------------------------===// #ifndef ASAN_STACK_H diff --git a/lib/asan/asan_stats.cc b/lib/asan/asan_stats.cpp index 2f996ce63ccc..00ded8f5ef50 100644 --- a/lib/asan/asan_stats.cc +++ b/lib/asan/asan_stats.cpp @@ -1,4 +1,4 @@ -//===-- asan_stats.cc -----------------------------------------------------===// +//===-- asan_stats.cpp ----------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -133,7 +133,7 @@ static void PrintAccumulatedStats() { } // namespace __asan // ---------------------- Interface ---------------- {{{1 -using namespace __asan; // NOLINT +using namespace __asan; uptr __sanitizer_get_current_allocated_bytes() { AsanStats stats; diff --git a/lib/asan/asan_suppressions.cc b/lib/asan/asan_suppressions.cpp index 118853e61b79..8cb2c3e3b9b6 100644 --- a/lib/asan/asan_suppressions.cc +++ b/lib/asan/asan_suppressions.cpp @@ -1,4 +1,4 @@ -//===-- asan_suppressions.cc ----------------------------------------------===// +//===-- asan_suppressions.cpp ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -36,7 +36,7 @@ SANITIZER_INTERFACE_WEAK_DEF(const char *, __asan_default_suppressions, void) { void InitializeSuppressions() { CHECK_EQ(nullptr, suppression_ctx); - suppression_ctx = new (suppression_placeholder) // NOLINT + suppression_ctx = new (suppression_placeholder) SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes)); suppression_ctx->ParseFromFile(flags()->suppressions); if (&__asan_default_suppressions) diff --git a/lib/asan/asan_suppressions.h b/lib/asan/asan_suppressions.h index 9bf297602cfa..121d4ddf1875 100644 --- a/lib/asan/asan_suppressions.h +++ b/lib/asan/asan_suppressions.h @@ -8,7 +8,7 @@ // // This file is a part of AddressSanitizer, an address sanity checker. // -// ASan-private header for asan_suppressions.cc. +// ASan-private header for asan_suppressions.cpp. //===----------------------------------------------------------------------===// #ifndef ASAN_SUPPRESSIONS_H #define ASAN_SUPPRESSIONS_H diff --git a/lib/asan/asan_thread.cc b/lib/asan/asan_thread.cpp index e63561c2243f..6734d9a1668c 100644 --- a/lib/asan/asan_thread.cc +++ b/lib/asan/asan_thread.cpp @@ -1,4 +1,4 @@ -//===-- asan_thread.cc ----------------------------------------------------===// +//===-- asan_thread.cpp ---------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -367,8 +367,9 @@ uptr AsanThread::GetStackVariableShadowStart(uptr addr) { } else if (has_fake_stack()) { bottom = fake_stack()->AddrIsInFakeStack(addr); CHECK(bottom); - } else + } else { return 0; + } uptr aligned_addr = RoundDownTo(addr, SANITIZER_WORDSIZE / 8); // align addr. u8 *shadow_ptr = (u8*)MemToShadow(aligned_addr); @@ -505,7 +506,7 @@ void EnsureMainThreadIDIsCorrect() { } // namespace __lsan // ---------------------- Interface ---------------- {{{1 -using namespace __asan; // NOLINT +using namespace __asan; extern "C" { SANITIZER_INTERFACE_ATTRIBUTE diff --git a/lib/asan/asan_thread.h b/lib/asan/asan_thread.h index d725e88864eb..c503f507059d 100644 --- a/lib/asan/asan_thread.h +++ b/lib/asan/asan_thread.h @@ -8,7 +8,7 @@ // // This file is a part of AddressSanitizer, an address sanity checker. // -// ASan-private header for asan_thread.cc. +// ASan-private header for asan_thread.cpp. //===----------------------------------------------------------------------===// #ifndef ASAN_THREAD_H diff --git a/lib/asan/asan_win.cc b/lib/asan/asan_win.cpp index f7601f3301ea..417892aaedd8 100644 --- a/lib/asan/asan_win.cc +++ b/lib/asan/asan_win.cpp @@ -1,4 +1,4 @@ -//===-- asan_win.cc -------------------------------------------------------===// +//===-- asan_win.cpp ------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -29,7 +29,7 @@ #include "sanitizer_common/sanitizer_win.h" #include "sanitizer_common/sanitizer_win_defs.h" -using namespace __asan; // NOLINT +using namespace __asan; extern "C" { SANITIZER_INTERFACE_ATTRIBUTE @@ -106,7 +106,7 @@ INTERCEPTOR_WINAPI(void, RaiseException, void *a, void *b, void *c, void *d) { INTERCEPTOR_WINAPI(EXCEPTION_DISPOSITION, __C_specific_handler, _EXCEPTION_RECORD *a, void *b, _CONTEXT *c, - _DISPATCHER_CONTEXT *d) { // NOLINT + _DISPATCHER_CONTEXT *d) { CHECK(REAL(__C_specific_handler)); __asan_handle_no_return(); return REAL(__C_specific_handler)(a, b, c, d); @@ -362,7 +362,7 @@ bool HandleDlopenInit() { // beginning of C++ initialization. We set our priority to XCAB to run // immediately after the CRT runs. This way, our exception filter is called // first and we can delegate to their filter if appropriate. -#pragma section(".CRT$XCAB", long, read) // NOLINT +#pragma section(".CRT$XCAB", long, read) __declspec(allocate(".CRT$XCAB")) int (*__intercept_seh)() = __asan_set_seh_filter; @@ -375,7 +375,7 @@ static void NTAPI asan_thread_init(void *module, DWORD reason, void *reserved) { __asan_init(); } -#pragma section(".CRT$XLAB", long, read) // NOLINT +#pragma section(".CRT$XLAB", long, read) __declspec(allocate(".CRT$XLAB")) void(NTAPI *__asan_tls_init)( void *, unsigned long, void *) = asan_thread_init; #endif @@ -389,7 +389,7 @@ static void NTAPI asan_thread_exit(void *module, DWORD reason, void *reserved) { } } -#pragma section(".CRT$XLY", long, read) // NOLINT +#pragma section(".CRT$XLY", long, read) __declspec(allocate(".CRT$XLY")) void(NTAPI *__asan_tls_exit)( void *, unsigned long, void *) = asan_thread_exit; diff --git a/lib/asan/asan_win_dll_thunk.cc b/lib/asan/asan_win_dll_thunk.cpp index 47b3948c5aea..a5671cc9dffd 100644 --- a/lib/asan/asan_win_dll_thunk.cc +++ b/lib/asan/asan_win_dll_thunk.cpp @@ -1,4 +1,4 @@ -//===-- asan_win_dll_thunk.cc ---------------------------------------------===// +//===-- asan_win_dll_thunk.cpp --------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -54,7 +54,7 @@ INTERCEPT_WRAP_W_W(_expand_dbg) // TODO(timurrrr): Might want to add support for _aligned_* allocation // functions to detect a bit more bugs. Those functions seem to wrap malloc(). -// TODO(timurrrr): Do we need to add _Crt* stuff here? (see asan_malloc_win.cc). +// TODO(timurrrr): Do we need to add _Crt* stuff here? (see asan_malloc_win.cpp) INTERCEPT_LIBRARY_FUNCTION(atoi); INTERCEPT_LIBRARY_FUNCTION(atol); @@ -67,10 +67,10 @@ INTERCEPT_LIBRARY_FUNCTION(memcmp); INTERCEPT_LIBRARY_FUNCTION(memcpy); INTERCEPT_LIBRARY_FUNCTION(memmove); INTERCEPT_LIBRARY_FUNCTION(memset); -INTERCEPT_LIBRARY_FUNCTION(strcat); // NOLINT +INTERCEPT_LIBRARY_FUNCTION(strcat); INTERCEPT_LIBRARY_FUNCTION(strchr); INTERCEPT_LIBRARY_FUNCTION(strcmp); -INTERCEPT_LIBRARY_FUNCTION(strcpy); // NOLINT +INTERCEPT_LIBRARY_FUNCTION(strcpy); INTERCEPT_LIBRARY_FUNCTION(strcspn); INTERCEPT_LIBRARY_FUNCTION(strdup); INTERCEPT_LIBRARY_FUNCTION(strlen); @@ -135,7 +135,7 @@ static int asan_dll_thunk_init() { return 0; } -#pragma section(".CRT$XIB", long, read) // NOLINT +#pragma section(".CRT$XIB", long, read) __declspec(allocate(".CRT$XIB")) int (*__asan_preinit)() = asan_dll_thunk_init; static void WINAPI asan_thread_init(void *mod, unsigned long reason, @@ -143,7 +143,7 @@ static void WINAPI asan_thread_init(void *mod, unsigned long reason, if (reason == /*DLL_PROCESS_ATTACH=*/1) asan_dll_thunk_init(); } -#pragma section(".CRT$XLAB", long, read) // NOLINT +#pragma section(".CRT$XLAB", long, read) __declspec(allocate(".CRT$XLAB")) void (WINAPI *__asan_tls_init)(void *, unsigned long, void *) = asan_thread_init; diff --git a/lib/asan/asan_win_dynamic_runtime_thunk.cc b/lib/asan/asan_win_dynamic_runtime_thunk.cpp index cf4a59842c4f..f0b5ec9eef7f 100644 --- a/lib/asan/asan_win_dynamic_runtime_thunk.cc +++ b/lib/asan/asan_win_dynamic_runtime_thunk.cpp @@ -1,4 +1,4 @@ -//===-- asan_win_dynamic_runtime_thunk.cc ---------------------------------===// +//===-- asan_win_dynamic_runtime_thunk.cpp --------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -32,12 +32,12 @@ #include "asan_interface.inc" // First, declare CRT sections we'll be using in this file -#pragma section(".CRT$XIB", long, read) // NOLINT -#pragma section(".CRT$XID", long, read) // NOLINT -#pragma section(".CRT$XCAB", long, read) // NOLINT -#pragma section(".CRT$XTW", long, read) // NOLINT -#pragma section(".CRT$XTY", long, read) // NOLINT -#pragma section(".CRT$XLAB", long, read) // NOLINT +#pragma section(".CRT$XIB", long, read) +#pragma section(".CRT$XID", long, read) +#pragma section(".CRT$XCAB", long, read) +#pragma section(".CRT$XTW", long, read) +#pragma section(".CRT$XTY", long, read) +#pragma section(".CRT$XLAB", long, read) //////////////////////////////////////////////////////////////////////////////// // Define a copy of __asan_option_detect_stack_use_after_return that should be @@ -114,7 +114,7 @@ int (*__asan_schedule_unregister_globals)() = ScheduleUnregisterGlobals; //////////////////////////////////////////////////////////////////////////////// // ASan SEH handling. // We need to set the ASan-specific SEH handler at the end of CRT initialization -// of each module (see also asan_win.cc). +// of each module (see also asan_win.cpp). extern "C" { __declspec(dllimport) int __asan_set_seh_filter(); static int SetSEHFilter() { return __asan_set_seh_filter(); } diff --git a/lib/asan/asan_win_weak_interception.cc b/lib/asan/asan_win_weak_interception.cpp index 19965ca473b4..62534e12e2a6 100644 --- a/lib/asan/asan_win_weak_interception.cc +++ b/lib/asan/asan_win_weak_interception.cpp @@ -1,4 +1,4 @@ -//===-- asan_win_weak_interception.cc -------------------------------------===// +//===-- asan_win_weak_interception.cpp ------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. |