From: Martin Liska Date: Fri, 13 Nov 2020 16:03:23 +0000 (+0100) Subject: libsanitizer: merge from master. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=98f792ff538109c71d85ab2a61461cd090f3b9f3;p=gcc.git libsanitizer: merge from master. --- diff --git a/libsanitizer/MERGE b/libsanitizer/MERGE index d2a25927007..2df9b4637b1 100644 --- a/libsanitizer/MERGE +++ b/libsanitizer/MERGE @@ -1,4 +1,4 @@ -51ff04567b2f8d06b2062bd3ed72eab2e93e4466 +a28a466210199559d38251c11f30515cc83eadd6 The first line of this file holds the git revision number of the last merge done from the master library sources. diff --git a/libsanitizer/asan/asan_fuchsia.cpp b/libsanitizer/asan/asan_fuchsia.cpp index ec15abfa0fe..6c61344f87c 100644 --- a/libsanitizer/asan/asan_fuchsia.cpp +++ b/libsanitizer/asan/asan_fuchsia.cpp @@ -91,8 +91,7 @@ struct AsanThread::InitOptions { // Shared setup between thread creation and startup for the initial thread. static AsanThread *CreateAsanThread(StackTrace *stack, u32 parent_tid, uptr user_id, bool detached, - const char *name, uptr stack_bottom, - uptr stack_size) { + const char *name) { // In lieu of AsanThread::Create. AsanThread *thread = (AsanThread *)MmapOrDie(AsanThreadMmapSize(), __func__); @@ -101,12 +100,6 @@ static AsanThread *CreateAsanThread(StackTrace *stack, u32 parent_tid, asanThreadRegistry().CreateThread(user_id, detached, parent_tid, &args); asanThreadRegistry().SetThreadName(tid, name); - // On other systems, AsanThread::Init() is called from the new - // thread itself. But on Fuchsia we already know the stack address - // range beforehand, so we can do most of the setup right now. - const AsanThread::InitOptions options = {stack_bottom, stack_size}; - thread->Init(&options); - return thread; } @@ -135,9 +128,16 @@ AsanThread *CreateMainThread() { _zx_object_get_property(thrd_get_zx_handle(self), ZX_PROP_NAME, name, sizeof(name)) == ZX_OK ? name - : nullptr, - __sanitizer::MainThreadStackBase, __sanitizer::MainThreadStackSize); + : nullptr); + // We need to set the current thread before calling AsanThread::Init() below, + // since it reads the thread ID. SetCurrentThread(t); + DCHECK_EQ(t->tid(), 0); + + const AsanThread::InitOptions options = {__sanitizer::MainThreadStackBase, + __sanitizer::MainThreadStackSize}; + t->Init(&options); + return t; } @@ -153,8 +153,15 @@ static void *BeforeThreadCreateHook(uptr user_id, bool detached, GET_STACK_TRACE_THREAD; u32 parent_tid = GetCurrentTidOrInvalid(); - return CreateAsanThread(&stack, parent_tid, user_id, detached, name, - stack_bottom, stack_size); + AsanThread *thread = + CreateAsanThread(&stack, parent_tid, user_id, detached, name); + + // On other systems, AsanThread::Init() is called from the new + // thread itself. But on Fuchsia we already know the stack address + // range beforehand, so we can do most of the setup right now. + const AsanThread::InitOptions options = {stack_bottom, stack_size}; + thread->Init(&options); + return thread; } // This is called after creating a new thread (in the creating thread), diff --git a/libsanitizer/asan/asan_globals.cpp b/libsanitizer/asan/asan_globals.cpp index e045c31cd1c..9d7dbc6f264 100644 --- a/libsanitizer/asan/asan_globals.cpp +++ b/libsanitizer/asan/asan_globals.cpp @@ -154,6 +154,23 @@ static void CheckODRViolationViaIndicator(const Global *g) { } } +// Check ODR violation for given global G by checking if it's already poisoned. +// We use this method in case compiler doesn't use private aliases for global +// variables. +static void CheckODRViolationViaPoisoning(const Global *g) { + if (__asan_region_is_poisoned(g->beg, g->size_with_redzone)) { + // This check may not be enough: if the first global is much larger + // the entire redzone of the second global may be within the first global. + for (ListOfGlobals *l = list_of_all_globals; l; l = l->next) { + if (g->beg == l->g->beg && + (flags()->detect_odr_violation >= 2 || g->size != l->g->size) && + !IsODRViolationSuppressed(g->name)) + ReportODRViolation(g, FindRegistrationSite(g), + l->g, FindRegistrationSite(l->g)); + } + } +} + // Clang provides two different ways for global variables protection: // it can poison the global itself or its private alias. In former // case we may poison same symbol multiple times, that can help us to @@ -199,6 +216,8 @@ static void RegisterGlobal(const Global *g) { // where two globals with the same name are defined in different modules. if (UseODRIndicator(g)) CheckODRViolationViaIndicator(g); + else + CheckODRViolationViaPoisoning(g); } if (CanPoisonMemory()) PoisonRedZones(*g); diff --git a/libsanitizer/asan/asan_interceptors.h b/libsanitizer/asan/asan_interceptors.h index 43cb4e3bb4f..8e9525673d1 100644 --- a/libsanitizer/asan/asan_interceptors.h +++ b/libsanitizer/asan/asan_interceptors.h @@ -81,12 +81,7 @@ void InitializePlatformInterceptors(); #if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && !SANITIZER_SOLARIS && \ !SANITIZER_NETBSD # define ASAN_INTERCEPT___CXA_THROW 1 -# if ! defined(ASAN_HAS_CXA_RETHROW_PRIMARY_EXCEPTION) \ - || ASAN_HAS_CXA_RETHROW_PRIMARY_EXCEPTION -# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1 -# else -# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 0 -# endif +# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1 # if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__)) # define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 1 # else diff --git a/libsanitizer/asan/asan_mapping.h b/libsanitizer/asan/asan_mapping.h index a7136de60d2..f239c3ee2ff 100644 --- a/libsanitizer/asan/asan_mapping.h +++ b/libsanitizer/asan/asan_mapping.h @@ -178,7 +178,7 @@ static const u64 kAArch64_ShadowOffset64 = 1ULL << 36; static const u64 kRiscv64_ShadowOffset64 = 0x20000000; static const u64 kMIPS32_ShadowOffset32 = 0x0aaa0000; static const u64 kMIPS64_ShadowOffset64 = 1ULL << 37; -static const u64 kPPC64_ShadowOffset64 = 1ULL << 41; +static const u64 kPPC64_ShadowOffset64 = 1ULL << 44; static const u64 kSystemZ_ShadowOffset64 = 1ULL << 52; static const u64 kSPARC64_ShadowOffset64 = 1ULL << 43; // 0x80000000000 static const u64 kFreeBSD_ShadowOffset32 = 1ULL << 30; // 0x40000000 diff --git a/libsanitizer/asan/asan_report.cpp b/libsanitizer/asan/asan_report.cpp index 4b4db1db6dc..03f1ed2b018 100644 --- a/libsanitizer/asan/asan_report.cpp +++ b/libsanitizer/asan/asan_report.cpp @@ -151,7 +151,8 @@ class ScopedInErrorReport { if (common_flags()->print_cmdline) PrintCmdline(); - if (common_flags()->print_module_map == 2) PrintModuleMap(); + if (common_flags()->print_module_map == 2) + DumpProcessMap(); // Copy the message buffer so that we could start logging without holding a // lock that gets aquired during printing. diff --git a/libsanitizer/asan/asan_rtl.cpp b/libsanitizer/asan/asan_rtl.cpp index 115733cdaa4..7b5a929963c 100644 --- a/libsanitizer/asan/asan_rtl.cpp +++ b/libsanitizer/asan/asan_rtl.cpp @@ -45,7 +45,8 @@ static void AsanDie() { // Don't die twice - run a busy loop. while (1) { } } - if (common_flags()->print_module_map >= 1) PrintModuleMap(); + if (common_flags()->print_module_map >= 1) + DumpProcessMap(); if (flags()->sleep_before_dying) { Report("Sleeping for %d second(s)\n", flags()->sleep_before_dying); SleepForSeconds(flags()->sleep_before_dying); diff --git a/libsanitizer/asan/asan_thread.cpp b/libsanitizer/asan/asan_thread.cpp index 58cdc29d365..fb09af0ecca 100644 --- a/libsanitizer/asan/asan_thread.cpp +++ b/libsanitizer/asan/asan_thread.cpp @@ -188,7 +188,7 @@ uptr AsanThread::stack_size() { return bounds.top - bounds.bottom; } -// We want to create the FakeStack lazyly on the first use, but not eralier +// We want to create the FakeStack lazily on the first use, but not earlier // than the stack size is known and the procedure has to be async-signal safe. FakeStack *AsanThread::AsyncSignalSafeLazyInitFakeStack() { uptr stack_size = this->stack_size(); @@ -211,6 +211,7 @@ FakeStack *AsanThread::AsyncSignalSafeLazyInitFakeStack() { stack_size_log = Max(stack_size_log, static_cast(flags()->min_uar_stack_size_log)); fake_stack_ = FakeStack::Create(stack_size_log); + DCHECK_EQ(GetCurrentThread(), this); SetTLSFakeStack(fake_stack_); return fake_stack_; } @@ -218,6 +219,7 @@ FakeStack *AsanThread::AsyncSignalSafeLazyInitFakeStack() { } void AsanThread::Init(const InitOptions *options) { + DCHECK_NE(tid(), ThreadRegistry::kUnknownTid); next_stack_top_ = next_stack_bottom_ = 0; atomic_store(&stack_switching_, false, memory_order_release); CHECK_EQ(this->stack_size(), 0U); @@ -229,8 +231,17 @@ void AsanThread::Init(const InitOptions *options) { } ClearShadowForThreadStackAndTLS(); fake_stack_ = nullptr; - if (__asan_option_detect_stack_use_after_return) + if (__asan_option_detect_stack_use_after_return && + tid() == GetCurrentTidOrInvalid()) { + // AsyncSignalSafeLazyInitFakeStack makes use of threadlocals and must be + // called from the context of the thread it is initializing, not its parent. + // Most platforms call AsanThread::Init on the newly-spawned thread, but + // Fuchsia calls this function from the parent thread. To support that + // approach, we avoid calling AsyncSignalSafeLazyInitFakeStack here; it will + // be called by the new thread when it first attempts to access the fake + // stack. AsyncSignalSafeLazyInitFakeStack(); + } int local = 0; VReport(1, "T%d: stack [%p,%p) size 0x%zx; local=%p\n", tid(), (void *)stack_bottom_, (void *)stack_top_, stack_top_ - stack_bottom_, diff --git a/libsanitizer/asan/asan_thread.h b/libsanitizer/asan/asan_thread.h index c503f507059..ea58de4216a 100644 --- a/libsanitizer/asan/asan_thread.h +++ b/libsanitizer/asan/asan_thread.h @@ -35,7 +35,7 @@ class AsanThread; // These objects are created for every thread and are never deleted, // so we can find them by tid even if the thread is long dead. -class AsanThreadContext : public ThreadContextBase { +class AsanThreadContext final : public ThreadContextBase { public: explicit AsanThreadContext(int tid) : ThreadContextBase(tid), announced(false), diff --git a/libsanitizer/include/sanitizer/memprof_interface.h b/libsanitizer/include/sanitizer/memprof_interface.h new file mode 100644 index 00000000000..a7212605100 --- /dev/null +++ b/libsanitizer/include/sanitizer/memprof_interface.h @@ -0,0 +1,60 @@ +//===-- sanitizer/memprof_interface.h --------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file is a part of MemProfiler (MemProf). +// +// Public interface header. +//===----------------------------------------------------------------------===// +#ifndef SANITIZER_MEMPROF_INTERFACE_H +#define SANITIZER_MEMPROF_INTERFACE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif +/// Records access to a memory region ([addr, addr+size)). +/// +/// This memory must be previously allocated by your program. +/// +/// \param addr Start of memory region. +/// \param size Size of memory region. +void __memprof_record_access_range(void const volatile *addr, size_t size); + +/// Records access to a memory address addr. +/// +/// This memory must be previously allocated by your program. +/// +/// \param addr Accessed memory address +void __memprof_record_access(void const volatile *addr); + +/// User-provided callback on MemProf errors. +/// +/// You can provide a function that would be called immediately when MemProf +/// detects an error. This is useful in cases when MemProf detects an error but +/// your program crashes before the MemProf report is printed. +void __memprof_on_error(void); + +/// Prints accumulated statistics to stderr (useful for calling from the +/// debugger). +void __memprof_print_accumulated_stats(void); + +/// User-provided default option settings. +/// +/// You can provide your own implementation of this function to return a string +/// containing MemProf runtime options (for example, +/// verbosity=1:print_stats=1). +/// +/// \returns Default options string. +const char *__memprof_default_options(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // SANITIZER_MEMPROF_INTERFACE_H diff --git a/libsanitizer/interception/interception.h b/libsanitizer/interception/interception.h index d27a8ccf92a..cb0b5284ed2 100644 --- a/libsanitizer/interception/interception.h +++ b/libsanitizer/interception/interception.h @@ -17,7 +17,7 @@ #include "sanitizer_common/sanitizer_internal_defs.h" #if !SANITIZER_LINUX && !SANITIZER_FREEBSD && !SANITIZER_MAC && \ - !SANITIZER_NETBSD && !SANITIZER_OPENBSD && !SANITIZER_WINDOWS && \ + !SANITIZER_NETBSD && !SANITIZER_WINDOWS && \ !SANITIZER_FUCHSIA && !SANITIZER_RTEMS && !SANITIZER_SOLARIS # error "Interception doesn't work on this operating system." #endif @@ -281,7 +281,7 @@ typedef unsigned long uptr; #define INCLUDED_FROM_INTERCEPTION_LIB #if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \ - SANITIZER_OPENBSD || SANITIZER_SOLARIS + SANITIZER_SOLARIS # include "interception_linux.h" # define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func) diff --git a/libsanitizer/interception/interception_linux.cpp b/libsanitizer/interception/interception_linux.cpp index 950cd512653..6883608d44f 100644 --- a/libsanitizer/interception/interception_linux.cpp +++ b/libsanitizer/interception/interception_linux.cpp @@ -14,7 +14,7 @@ #include "interception.h" #if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \ - SANITIZER_OPENBSD || SANITIZER_SOLARIS + SANITIZER_SOLARIS #include // for dlsym() and dlvsym() @@ -64,7 +64,7 @@ bool InterceptFunction(const char *name, uptr *ptr_to_real, uptr func, } // Android and Solaris do not have dlvsym -#if !SANITIZER_ANDROID && !SANITIZER_SOLARIS && !SANITIZER_OPENBSD +#if !SANITIZER_ANDROID && !SANITIZER_SOLARIS static void *GetFuncAddr(const char *name, const char *ver) { return dlvsym(RTLD_NEXT, name, ver); } @@ -80,4 +80,4 @@ bool InterceptFunction(const char *name, const char *ver, uptr *ptr_to_real, } // namespace __interception #endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || - // SANITIZER_OPENBSD || SANITIZER_SOLARIS + // SANITIZER_SOLARIS diff --git a/libsanitizer/interception/interception_linux.h b/libsanitizer/interception/interception_linux.h index e578da0cf64..097375fd1c1 100644 --- a/libsanitizer/interception/interception_linux.h +++ b/libsanitizer/interception/interception_linux.h @@ -12,7 +12,7 @@ //===----------------------------------------------------------------------===// #if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \ - SANITIZER_OPENBSD || SANITIZER_SOLARIS + SANITIZER_SOLARIS #if !defined(INCLUDED_FROM_INTERCEPTION_LIB) # error "interception_linux.h should be included from interception library only" @@ -35,8 +35,8 @@ bool InterceptFunction(const char *name, const char *ver, uptr *ptr_to_real, (::__interception::uptr) & (func), \ (::__interception::uptr) & WRAP(func)) -// Android, Solaris and OpenBSD do not have dlvsym -#if !SANITIZER_ANDROID && !SANITIZER_SOLARIS && !SANITIZER_OPENBSD +// Android and Solaris do not have dlvsym +#if !SANITIZER_ANDROID && !SANITIZER_SOLARIS #define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \ ::__interception::InterceptFunction( \ #func, symver, \ @@ -50,4 +50,4 @@ bool InterceptFunction(const char *name, const char *ver, uptr *ptr_to_real, #endif // INTERCEPTION_LINUX_H #endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || - // SANITIZER_OPENBSD || SANITIZER_SOLARIS + // SANITIZER_SOLARIS diff --git a/libsanitizer/lsan/lsan.cpp b/libsanitizer/lsan/lsan.cpp index c8cc045783d..2c0a3bf0787 100644 --- a/libsanitizer/lsan/lsan.cpp +++ b/libsanitizer/lsan/lsan.cpp @@ -77,7 +77,7 @@ static void InitializeFlags() { parser.ParseString(lsan_default_options); parser.ParseStringFromEnv("LSAN_OPTIONS"); - SetVerbosity(common_flags()->verbosity); + InitializeCommonFlags(); if (Verbosity()) ReportUnrecognizedFlags(); diff --git a/libsanitizer/lsan/lsan_common.cpp b/libsanitizer/lsan/lsan_common.cpp index 107d63ac911..9e23aa9997a 100644 --- a/libsanitizer/lsan/lsan_common.cpp +++ b/libsanitizer/lsan/lsan_common.cpp @@ -71,17 +71,17 @@ static const char kSuppressionLeak[] = "leak"; static const char *kSuppressionTypes[] = { kSuppressionLeak }; static const char kStdSuppressions[] = #if SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT - // For more details refer to the SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT - // definition. - "leak:*pthread_exit*\n" + // For more details refer to the SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT + // definition. + "leak:*pthread_exit*\n" #endif // SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT #if SANITIZER_MAC - // For Darwin and os_log/os_trace: https://reviews.llvm.org/D35173 - "leak:*_os_trace*\n" + // For Darwin and os_log/os_trace: https://reviews.llvm.org/D35173 + "leak:*_os_trace*\n" #endif - // TLS leak in some glibc versions, described in - // https://sourceware.org/bugzilla/show_bug.cgi?id=12650. - "leak:*tls_get_addr*\n"; + // TLS leak in some glibc versions, described in + // https://sourceware.org/bugzilla/show_bug.cgi?id=12650. + "leak:*tls_get_addr*\n"; void InitializeSuppressions() { CHECK_EQ(nullptr, suppression_ctx); @@ -215,6 +215,12 @@ static void ProcessThreads(SuspendedThreadsList const &, Frontier *) {} #else +#if SANITIZER_ANDROID +// FIXME: Move this out into *libcdep.cpp +extern "C" SANITIZER_WEAK_ATTRIBUTE void __libc_iterate_dynamic_tls( + pid_t, void (*cb)(void *, void *, uptr, void *), void *); +#endif + // Scans thread data (stacks and TLS) for heap pointers. static void ProcessThreads(SuspendedThreadsList const &suspended_threads, Frontier *frontier) { @@ -294,6 +300,20 @@ static void ProcessThreads(SuspendedThreadsList const &suspended_threads, kReachable); } } +#if SANITIZER_ANDROID + auto *cb = +[](void *dtls_begin, void *dtls_end, uptr /*dso_idd*/, + void *arg) -> void { + ScanRangeForPointers(reinterpret_cast(dtls_begin), + reinterpret_cast(dtls_end), + reinterpret_cast(arg), "DTLS", + kReachable); + }; + + // FIXME: There might be a race-condition here (and in Bionic) if the + // thread is suspended in the middle of updating its DTLS. IOWs, we + // could scan already freed memory. (probably fine for now) + __libc_iterate_dynamic_tls(os_id, cb, frontier); +#else if (dtls && !DTLSInDestruction(dtls)) { for (uptr j = 0; j < dtls->dtv_size; ++j) { uptr dtls_beg = dtls->dtv[j].beg; @@ -309,6 +329,7 @@ static void ProcessThreads(SuspendedThreadsList const &suspended_threads, // this and continue. LOG_THREADS("Thread %d has DTLS under destruction.\n", os_id); } +#endif } } } @@ -576,7 +597,7 @@ static void CheckForLeaksCallback(const SuspendedThreadsList &suspended_threads, static bool CheckForLeaks() { if (&__lsan_is_turned_off && __lsan_is_turned_off()) - return false; + return false; EnsureMainThreadIDIsCorrect(); CheckForLeaksParam param; LockStuffAndStopTheWorld(CheckForLeaksCallback, ¶m); diff --git a/libsanitizer/lsan/lsan_common.h b/libsanitizer/lsan/lsan_common.h index 3434beede82..1fdce087b3a 100644 --- a/libsanitizer/lsan/lsan_common.h +++ b/libsanitizer/lsan/lsan_common.h @@ -29,16 +29,17 @@ // To enable LeakSanitizer on a new architecture, one needs to implement the // internal_clone function as well as (probably) adjust the TLS machinery for // the new architecture inside the sanitizer library. -#if (SANITIZER_LINUX && !SANITIZER_ANDROID || SANITIZER_MAC) && \ - (SANITIZER_WORDSIZE == 64) && \ - (defined(__x86_64__) || defined(__mips64) || defined(__aarch64__) || \ +// Exclude leak-detection on arm32 for Android because `__aeabi_read_tp` +// is missing. This caused a link error. +#if SANITIZER_ANDROID && (__ANDROID_API__ < 28 || defined(__arm__)) +#define CAN_SANITIZE_LEAKS 0 +#elif (SANITIZER_LINUX || SANITIZER_MAC) && (SANITIZER_WORDSIZE == 64) && \ + (defined(__x86_64__) || defined(__mips64) || defined(__aarch64__) || \ defined(__powerpc64__) || defined(__s390x__)) #define CAN_SANITIZE_LEAKS 1 -#elif defined(__i386__) && \ - (SANITIZER_LINUX && !SANITIZER_ANDROID || SANITIZER_MAC) +#elif defined(__i386__) && (SANITIZER_LINUX || SANITIZER_MAC) #define CAN_SANITIZE_LEAKS 1 -#elif defined(__arm__) && \ - SANITIZER_LINUX && !SANITIZER_ANDROID +#elif defined(__arm__) && SANITIZER_LINUX #define CAN_SANITIZE_LEAKS 1 #elif SANITIZER_NETBSD || SANITIZER_FUCHSIA #define CAN_SANITIZE_LEAKS 1 diff --git a/libsanitizer/lsan/lsan_common_fuchsia.cpp b/libsanitizer/lsan/lsan_common_fuchsia.cpp index caedbf15596..3c62c9433d3 100644 --- a/libsanitizer/lsan/lsan_common_fuchsia.cpp +++ b/libsanitizer/lsan/lsan_common_fuchsia.cpp @@ -19,6 +19,7 @@ #include "lsan_allocator.h" #include "sanitizer_common/sanitizer_flags.h" +#include "sanitizer_common/sanitizer_stoptheworld_fuchsia.h" #include "sanitizer_common/sanitizer_thread_registry.h" // Ensure that the Zircon system ABI is linked in. @@ -147,7 +148,7 @@ void LockStuffAndStopTheWorld(StopTheWorldCallback callback, ¶ms->argument->frontier); } - params->callback({}, params->argument); + params->callback(SuspendedThreadsListFuchsia(), params->argument); }, ¶ms); diff --git a/libsanitizer/lsan/lsan_common_linux.cpp b/libsanitizer/lsan/lsan_common_linux.cpp index c97ef31593d..3af586e220f 100644 --- a/libsanitizer/lsan/lsan_common_linux.cpp +++ b/libsanitizer/lsan/lsan_common_linux.cpp @@ -93,6 +93,11 @@ static int ProcessGlobalRegionsCallback(struct dl_phdr_info *info, size_t size, return 0; } +#if SANITIZER_ANDROID && __ANDROID_API__ < 21 +extern "C" __attribute__((weak)) int dl_iterate_phdr( + int (*)(struct dl_phdr_info *, size_t, void *), void *); +#endif + // Scans global variables for heap pointers. void ProcessGlobalRegions(Frontier *frontier) { if (!flags()->use_globals) return; diff --git a/libsanitizer/lsan/lsan_interceptors.cpp b/libsanitizer/lsan/lsan_interceptors.cpp index 39d075ddec0..bf8d316770e 100644 --- a/libsanitizer/lsan/lsan_interceptors.cpp +++ b/libsanitizer/lsan/lsan_interceptors.cpp @@ -115,7 +115,11 @@ INTERCEPTOR(void*, memalign, uptr alignment, uptr size) { return lsan_memalign(alignment, size, stack); } #define LSAN_MAYBE_INTERCEPT_MEMALIGN INTERCEPT_FUNCTION(memalign) +#else +#define LSAN_MAYBE_INTERCEPT_MEMALIGN +#endif // SANITIZER_INTERCEPT_MEMALIGN +#if SANITIZER_INTERCEPT___LIBC_MEMALIGN INTERCEPTOR(void *, __libc_memalign, uptr alignment, uptr size) { ENSURE_LSAN_INITED; GET_STACK_TRACE_MALLOC; @@ -125,9 +129,8 @@ INTERCEPTOR(void *, __libc_memalign, uptr alignment, uptr size) { } #define LSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN INTERCEPT_FUNCTION(__libc_memalign) #else -#define LSAN_MAYBE_INTERCEPT_MEMALIGN #define LSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN -#endif // SANITIZER_INTERCEPT_MEMALIGN +#endif // SANITIZER_INTERCEPT___LIBC_MEMALIGN #if SANITIZER_INTERCEPT_ALIGNED_ALLOC INTERCEPTOR(void*, aligned_alloc, uptr alignment, uptr size) { diff --git a/libsanitizer/lsan/lsan_posix.h b/libsanitizer/lsan/lsan_posix.h index 840e427c55e..b1265f233f3 100644 --- a/libsanitizer/lsan/lsan_posix.h +++ b/libsanitizer/lsan/lsan_posix.h @@ -27,7 +27,7 @@ struct DTLS; namespace __lsan { -class ThreadContext : public ThreadContextLsanBase { +class ThreadContext final : public ThreadContextLsanBase { public: explicit ThreadContext(int tid); void OnStarted(void *arg) override; diff --git a/libsanitizer/lsan/lsan_thread.h b/libsanitizer/lsan/lsan_thread.h index e876f9ff9cf..36643753d01 100644 --- a/libsanitizer/lsan/lsan_thread.h +++ b/libsanitizer/lsan/lsan_thread.h @@ -32,6 +32,7 @@ class ThreadContextLsanBase : public ThreadContextBase { void *onstarted_arg); protected: + ~ThreadContextLsanBase() {} uptr stack_begin_ = 0; uptr stack_end_ = 0; uptr cache_begin_ = 0; diff --git a/libsanitizer/sanitizer_common/sanitizer_allocator_report.cpp b/libsanitizer/sanitizer_common/sanitizer_allocator_report.cpp index d74e08010d5..1c6520819ef 100644 --- a/libsanitizer/sanitizer_common/sanitizer_allocator_report.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_allocator_report.cpp @@ -134,4 +134,12 @@ void NORETURN ReportOutOfMemory(uptr requested_size, const StackTrace *stack) { Die(); } +void NORETURN ReportRssLimitExceeded(const StackTrace *stack) { + { + ScopedAllocatorErrorReport report("rss-limit-exceeded", stack); + Report("ERROR: %s: allocator exceeded the RSS limit\n", SanitizerToolName); + } + Die(); +} + } // namespace __sanitizer diff --git a/libsanitizer/sanitizer_common/sanitizer_allocator_report.h b/libsanitizer/sanitizer_common/sanitizer_allocator_report.h index 0653c365c1c..6e4e6b13549 100644 --- a/libsanitizer/sanitizer_common/sanitizer_allocator_report.h +++ b/libsanitizer/sanitizer_common/sanitizer_allocator_report.h @@ -33,6 +33,7 @@ void NORETURN ReportInvalidPosixMemalignAlignment(uptr alignment, void NORETURN ReportAllocationSizeTooBig(uptr user_size, uptr max_size, const StackTrace *stack); void NORETURN ReportOutOfMemory(uptr requested_size, const StackTrace *stack); +void NORETURN ReportRssLimitExceeded(const StackTrace *stack); } // namespace __sanitizer diff --git a/libsanitizer/sanitizer_common/sanitizer_atomic_clang_other.h b/libsanitizer/sanitizer_common/sanitizer_atomic_clang_other.h index 7580ac2dc58..4a39889e534 100644 --- a/libsanitizer/sanitizer_common/sanitizer_atomic_clang_other.h +++ b/libsanitizer/sanitizer_common/sanitizer_atomic_clang_other.h @@ -50,11 +50,8 @@ inline typename T::Type atomic_load( __sync_synchronize(); } } else { - // 64-bit load on 32-bit platform. - // Gross, but simple and reliable. - // Assume that it is not in read-only memory. - v = __sync_fetch_and_add( - const_cast(&a->val_dont_use), 0); + __atomic_load(const_cast(&a->val_dont_use), &v, + __ATOMIC_SEQ_CST); } return v; } @@ -79,16 +76,7 @@ inline void atomic_store(volatile T *a, typename T::Type v, memory_order mo) { __sync_synchronize(); } } else { - // 64-bit store on 32-bit platform. - // Gross, but simple and reliable. - typename T::Type cmp = a->val_dont_use; - typename T::Type cur; - for (;;) { - cur = __sync_val_compare_and_swap(&a->val_dont_use, cmp, v); - if (cur == cmp || cur == v) - break; - cmp = cur; - } + __atomic_store(&a->val_dont_use, &v, __ATOMIC_SEQ_CST); } } diff --git a/libsanitizer/sanitizer_common/sanitizer_common.h b/libsanitizer/sanitizer_common/sanitizer_common.h index 040db6fc2a1..bce24d68045 100644 --- a/libsanitizer/sanitizer_common/sanitizer_common.h +++ b/libsanitizer/sanitizer_common/sanitizer_common.h @@ -254,7 +254,6 @@ void UpdateProcessName(); void CacheBinaryName(); void DisableCoreDumperIfNecessary(); void DumpProcessMap(); -void PrintModuleMap(); const char *GetEnv(const char *name); bool SetEnv(const char *name, const char *value); diff --git a/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc b/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc index 5b510781d40..729eead43c0 100644 --- a/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc +++ b/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc @@ -1864,7 +1864,7 @@ UNUSED static void unpoison_passwd(void *ctx, __sanitizer_passwd *pwd) { COMMON_INTERCEPTOR_WRITE_RANGE(ctx, pwd->pw_gecos, REAL(strlen)(pwd->pw_gecos) + 1); #endif -#if SANITIZER_MAC || SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_OPENBSD +#if SANITIZER_MAC || SANITIZER_FREEBSD || SANITIZER_NETBSD if (pwd->pw_class) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, pwd->pw_class, REAL(strlen)(pwd->pw_class) + 1); @@ -3750,7 +3750,7 @@ INTERCEPTOR(char *, strerror, int errnum) { // static storage. #if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE) || \ SANITIZER_MAC || SANITIZER_ANDROID || SANITIZER_NETBSD || \ - SANITIZER_FREEBSD || SANITIZER_OPENBSD + SANITIZER_FREEBSD // POSIX version. Spec is not clear on whether buf is NULL-terminated. // At least on OSX, buf contents are valid even when the call fails. INTERCEPTOR(int, strerror_r, int errnum, char *buf, SIZE_T buflen) { diff --git a/libsanitizer/sanitizer_common/sanitizer_common_nolibc.cpp b/libsanitizer/sanitizer_common/sanitizer_common_nolibc.cpp index 3b278e017eb..487a634a165 100644 --- a/libsanitizer/sanitizer_common/sanitizer_common_nolibc.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_common_nolibc.cpp @@ -10,9 +10,10 @@ // libc in no-libcdep sources. //===----------------------------------------------------------------------===// -#include "sanitizer_platform.h" #include "sanitizer_common.h" +#include "sanitizer_flags.h" #include "sanitizer_libc.h" +#include "sanitizer_platform.h" namespace __sanitizer { @@ -29,6 +30,7 @@ void SleepForSeconds(int seconds) { internal_sleep(seconds); } #if !SANITIZER_WINDOWS && !SANITIZER_MAC void ListOfModules::init() {} +void InitializePlatformCommonFlags(CommonFlags *cf) {} #endif } // namespace __sanitizer diff --git a/libsanitizer/sanitizer_common/sanitizer_deadlock_detector1.cpp b/libsanitizer/sanitizer_common/sanitizer_deadlock_detector1.cpp index d4a325bea4b..2c924f5d396 100644 --- a/libsanitizer/sanitizer_common/sanitizer_deadlock_detector1.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_deadlock_detector1.cpp @@ -32,7 +32,7 @@ struct DDLogicalThread { bool report_pending; }; -struct DD : public DDetector { +struct DD final : public DDetector { SpinMutex mtx; DeadlockDetector dd; DDFlags flags; diff --git a/libsanitizer/sanitizer_common/sanitizer_deadlock_detector2.cpp b/libsanitizer/sanitizer_common/sanitizer_deadlock_detector2.cpp index 4026739d4e5..e3f8e1b1276 100644 --- a/libsanitizer/sanitizer_common/sanitizer_deadlock_detector2.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_deadlock_detector2.cpp @@ -80,7 +80,7 @@ struct Mutex { Link link[kMaxLink]; }; -struct DD : public DDetector { +struct DD final : public DDetector { explicit DD(const DDFlags *flags); DDPhysicalThread* CreatePhysicalThread(); diff --git a/libsanitizer/sanitizer_common/sanitizer_deadlock_detector_interface.h b/libsanitizer/sanitizer_common/sanitizer_deadlock_detector_interface.h index a4722b080eb..7f461c98bad 100644 --- a/libsanitizer/sanitizer_common/sanitizer_deadlock_detector_interface.h +++ b/libsanitizer/sanitizer_common/sanitizer_deadlock_detector_interface.h @@ -66,6 +66,9 @@ struct DDCallback { virtual u32 Unwind() { return 0; } virtual int UniqueTid() { return 0; } + + protected: + ~DDCallback() {} }; struct DDetector { @@ -85,6 +88,9 @@ struct DDetector { virtual void MutexDestroy(DDCallback *cb, DDMutex *m) {} virtual DDReport *GetReport(DDCallback *cb) { return nullptr; } + + protected: + ~DDetector() {} }; } // namespace __sanitizer diff --git a/libsanitizer/sanitizer_common/sanitizer_errno.h b/libsanitizer/sanitizer_common/sanitizer_errno.h index 584e66e4a86..94f16b6e873 100644 --- a/libsanitizer/sanitizer_common/sanitizer_errno.h +++ b/libsanitizer/sanitizer_common/sanitizer_errno.h @@ -23,7 +23,7 @@ #if SANITIZER_FREEBSD || SANITIZER_MAC # define __errno_location __error -#elif SANITIZER_ANDROID || SANITIZER_NETBSD || SANITIZER_OPENBSD || \ +#elif SANITIZER_ANDROID || SANITIZER_NETBSD || \ SANITIZER_RTEMS # define __errno_location __errno #elif SANITIZER_SOLARIS diff --git a/libsanitizer/sanitizer_common/sanitizer_file.cpp b/libsanitizer/sanitizer_common/sanitizer_file.cpp index 79930d79425..7cce60906b7 100644 --- a/libsanitizer/sanitizer_common/sanitizer_file.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_file.cpp @@ -58,35 +58,38 @@ void ReportFile::ReopenIfNecessary() { } else { internal_snprintf(full_path, kMaxPathLength, "%s.%zu", path_prefix, pid); } - fd = OpenFile(full_path, WrOnly); + error_t err; + fd = OpenFile(full_path, WrOnly, &err); if (fd == kInvalidFd) { const char *ErrorMsgPrefix = "ERROR: Can't open file: "; WriteToFile(kStderrFd, ErrorMsgPrefix, internal_strlen(ErrorMsgPrefix)); WriteToFile(kStderrFd, full_path, internal_strlen(full_path)); + char errmsg[100]; + internal_snprintf(errmsg, sizeof(errmsg), " (reason: %d)", err); + WriteToFile(kStderrFd, errmsg, internal_strlen(errmsg)); Die(); } fd_pid = pid; } void ReportFile::SetReportPath(const char *path) { - if (!path) - return; - uptr len = internal_strlen(path); - if (len > sizeof(path_prefix) - 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(); + if (path) { + uptr len = internal_strlen(path); + if (len > sizeof(path_prefix) - 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(); + } } SpinMutexLock l(mu); if (fd != kStdoutFd && fd != kStderrFd && fd != kInvalidFd) CloseFile(fd); fd = kInvalidFd; - if (internal_strcmp(path, "stdout") == 0) { - fd = kStdoutFd; - } else if (internal_strcmp(path, "stderr") == 0) { + if (!path || internal_strcmp(path, "stderr") == 0) { fd = kStderrFd; + } else if (internal_strcmp(path, "stdout") == 0) { + fd = kStdoutFd; } else { internal_snprintf(path_prefix, kMaxPathLength, "%s", path); } diff --git a/libsanitizer/sanitizer_common/sanitizer_flag_parser.h b/libsanitizer/sanitizer_common/sanitizer_flag_parser.h index fac5dff3463..acc71ccd89e 100644 --- a/libsanitizer/sanitizer_common/sanitizer_flag_parser.h +++ b/libsanitizer/sanitizer_common/sanitizer_flag_parser.h @@ -42,7 +42,7 @@ class FlagHandlerBase { }; template -class FlagHandler : public FlagHandlerBase { +class FlagHandler final : public FlagHandlerBase { T *t_; public: diff --git a/libsanitizer/sanitizer_common/sanitizer_flags.cpp b/libsanitizer/sanitizer_common/sanitizer_flags.cpp index d3290493fd6..21048be7304 100644 --- a/libsanitizer/sanitizer_common/sanitizer_flags.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_flags.cpp @@ -13,9 +13,10 @@ #include "sanitizer_flags.h" #include "sanitizer_common.h" +#include "sanitizer_flag_parser.h" #include "sanitizer_libc.h" +#include "sanitizer_linux.h" #include "sanitizer_list.h" -#include "sanitizer_flag_parser.h" namespace __sanitizer { @@ -72,7 +73,7 @@ void SubstituteForFlagValue(const char *s, char *out, uptr out_size) { *out = '\0'; } -class FlagHandlerInclude : public FlagHandlerBase { +class FlagHandlerInclude final : public FlagHandlerBase { FlagParser *parser_; bool ignore_missing_; const char *original_path_; @@ -124,6 +125,8 @@ void InitializeCommonFlags(CommonFlags *cf) { // need to record coverage to generate coverage report. cf->coverage |= cf->html_cov_report; SetVerbosity(cf->verbosity); + + InitializePlatformCommonFlags(cf); } } // namespace __sanitizer diff --git a/libsanitizer/sanitizer_common/sanitizer_flags.h b/libsanitizer/sanitizer_common/sanitizer_flags.h index 8f5e987da3f..5b59e5801bf 100644 --- a/libsanitizer/sanitizer_common/sanitizer_flags.h +++ b/libsanitizer/sanitizer_common/sanitizer_flags.h @@ -62,6 +62,10 @@ void RegisterIncludeFlags(FlagParser *parser, CommonFlags *cf); // and perform initializations common to all sanitizers (e.g. setting // verbosity). void InitializeCommonFlags(CommonFlags *cf = &common_flags_dont_use); + +// Platform specific flags initialization. +void InitializePlatformCommonFlags(CommonFlags *cf); + } // namespace __sanitizer #endif // SANITIZER_FLAGS_H diff --git a/libsanitizer/sanitizer_common/sanitizer_flags.inc b/libsanitizer/sanitizer_common/sanitizer_flags.inc index d1412478fd2..cfb5822645f 100644 --- a/libsanitizer/sanitizer_common/sanitizer_flags.inc +++ b/libsanitizer/sanitizer_common/sanitizer_flags.inc @@ -52,9 +52,9 @@ COMMON_FLAG(bool, handle_ioctl, false, "Intercept and handle ioctl requests.") COMMON_FLAG(int, malloc_context_size, 1, "Max number of stack frames kept for each allocation/deallocation.") COMMON_FLAG( - const char *, log_path, "stderr", + const char *, log_path, nullptr, "Write logs to \"log_path.pid\". The special values are \"stdout\" and " - "\"stderr\". The default is \"stderr\".") + "\"stderr\". If unspecified, defaults to \"stderr\".") COMMON_FLAG( bool, log_exe_name, false, "Mention name of executable when reporting error and " @@ -82,8 +82,9 @@ COMMON_FLAG(bool, print_summary, true, "If false, disable printing error summaries in addition to error " "reports.") COMMON_FLAG(int, print_module_map, 0, - "OS X only (0 - don't print, 1 - print only once before process " - "exits, 2 - print after each report).") + "Print the process module map where supported (0 - don't print, " + "1 - print only once before process exits, 2 - print after each " + "report).") COMMON_FLAG(bool, check_printf, true, "Check printf arguments.") #define COMMON_FLAG_HANDLE_SIGNAL_HELP(signal) \ "Controls custom tool's " #signal " handler (0 - do not registers the " \ diff --git a/libsanitizer/sanitizer_common/sanitizer_fuchsia.cpp b/libsanitizer/sanitizer_common/sanitizer_fuchsia.cpp index 6d1ad794677..7200ffdac0f 100644 --- a/libsanitizer/sanitizer_common/sanitizer_fuchsia.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_fuchsia.cpp @@ -14,10 +14,6 @@ #include "sanitizer_fuchsia.h" #if SANITIZER_FUCHSIA -#include "sanitizer_common.h" -#include "sanitizer_libc.h" -#include "sanitizer_mutex.h" - #include #include #include @@ -25,6 +21,11 @@ #include #include #include +#include + +#include "sanitizer_common.h" +#include "sanitizer_libc.h" +#include "sanitizer_mutex.h" namespace __sanitizer { @@ -47,8 +48,10 @@ unsigned int internal_sleep(unsigned int seconds) { } u64 NanoTime() { + zx_handle_t utc_clock = _zx_utc_reference_get(); + CHECK_NE(utc_clock, ZX_HANDLE_INVALID); zx_time_t time; - zx_status_t status = _zx_clock_get(ZX_CLOCK_UTC, &time); + zx_status_t status = _zx_clock_read(utc_clock, &time); CHECK_EQ(status, ZX_OK); return time; } @@ -105,8 +108,6 @@ void SetAlternateSignalStack() {} void UnsetAlternateSignalStack() {} void InitTlsSize() {} -void PrintModuleMap() {} - bool SignalContext::IsStackOverflow() const { return false; } void SignalContext::DumpAllRegisters(void *context) { UNIMPLEMENTED(); } const char *SignalContext::Describe() const { UNIMPLEMENTED(); } @@ -504,6 +505,8 @@ u32 GetNumberOfCPUs() { uptr GetRSS() { UNIMPLEMENTED(); } +void InitializePlatformCommonFlags(CommonFlags *cf) {} + } // namespace __sanitizer using namespace __sanitizer; diff --git a/libsanitizer/sanitizer_common/sanitizer_internal_defs.h b/libsanitizer/sanitizer_common/sanitizer_internal_defs.h index a6c55148705..d8f0540037d 100644 --- a/libsanitizer/sanitizer_common/sanitizer_internal_defs.h +++ b/libsanitizer/sanitizer_common/sanitizer_internal_defs.h @@ -39,7 +39,7 @@ // TLS is handled differently on different platforms #if SANITIZER_LINUX || SANITIZER_NETBSD || \ - SANITIZER_FREEBSD || SANITIZER_OPENBSD + SANITIZER_FREEBSD # define SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE \ __attribute__((tls_model("initial-exec"))) thread_local #else @@ -104,8 +104,7 @@ // // FIXME: do we have anything like this on Mac? #ifndef SANITIZER_CAN_USE_PREINIT_ARRAY -#if ((SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_OPENBSD || \ - SANITIZER_FUCHSIA || SANITIZER_NETBSD) && !defined(PIC) +#if (SANITIZER_LINUX || SANITIZER_FUCHSIA || SANITIZER_NETBSD) && !defined(PIC) #define SANITIZER_CAN_USE_PREINIT_ARRAY 1 // Before Solaris 11.4, .preinit_array is fully supported only with GNU ld. // FIXME: Check for those conditions. @@ -170,7 +169,7 @@ typedef int pid_t; #endif #if SANITIZER_FREEBSD || SANITIZER_NETBSD || \ - SANITIZER_OPENBSD || SANITIZER_MAC || \ + SANITIZER_MAC || \ (SANITIZER_SOLARIS && (defined(_LP64) || _FILE_OFFSET_BITS == 64)) || \ (SANITIZER_LINUX && defined(__x86_64__)) typedef u64 OFF_T; @@ -182,7 +181,7 @@ typedef u64 OFF64_T; #if (SANITIZER_WORDSIZE == 64) || SANITIZER_MAC typedef uptr operator_new_size_type; #else -# if SANITIZER_OPENBSD || defined(__s390__) && !defined(__s390x__) +# if defined(__s390__) && !defined(__s390x__) // Special case: 31-bit s390 has unsigned long as size_t. typedef unsigned long operator_new_size_type; # else @@ -448,5 +447,8 @@ using namespace __sanitizer; namespace __hwasan { using namespace __sanitizer; } +namespace __memprof { +using namespace __sanitizer; +} #endif // SANITIZER_DEFS_H diff --git a/libsanitizer/sanitizer_common/sanitizer_libignore.cpp b/libsanitizer/sanitizer_common/sanitizer_libignore.cpp index eb9bb765013..9ea19bc21fa 100644 --- a/libsanitizer/sanitizer_common/sanitizer_libignore.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_libignore.cpp @@ -9,7 +9,7 @@ #include "sanitizer_platform.h" #if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC || \ - SANITIZER_NETBSD || SANITIZER_OPENBSD + SANITIZER_NETBSD #include "sanitizer_libignore.h" #include "sanitizer_flags.h" diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cpp b/libsanitizer/sanitizer_common/sanitizer_linux.cpp index c84946ca9bf..379f6d9e294 100644 --- a/libsanitizer/sanitizer_common/sanitizer_linux.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_linux.cpp @@ -14,7 +14,7 @@ #include "sanitizer_platform.h" #if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \ - SANITIZER_OPENBSD || SANITIZER_SOLARIS + SANITIZER_SOLARIS #include "sanitizer_common.h" #include "sanitizer_flags.h" @@ -38,6 +38,14 @@ #include #include #define stat kernel_stat +#if SANITIZER_GO +#undef st_atime +#undef st_mtime +#undef st_ctime +#define st_atime st_atim +#define st_mtime st_mtim +#define st_ctime st_ctim +#endif #include #undef stat #endif @@ -59,13 +67,7 @@ #include #include #include -#if !SANITIZER_OPENBSD #include -#endif -#if SANITIZER_OPENBSD -#include -#include -#endif #include #if SANITIZER_LINUX @@ -129,7 +131,7 @@ const int FUTEX_WAKE_PRIVATE = FUTEX_WAKE | FUTEX_PRIVATE_FLAG; #endif // Note : FreeBSD had implemented both -// Linux and OpenBSD apis, available from +// Linux apis, available from // future 12.x version most likely #if SANITIZER_LINUX && defined(__NR_getrandom) # if !defined(GRND_NONBLOCK) @@ -140,15 +142,11 @@ const int FUTEX_WAKE_PRIVATE = FUTEX_WAKE | FUTEX_PRIVATE_FLAG; # define SANITIZER_USE_GETRANDOM 0 #endif // SANITIZER_LINUX && defined(__NR_getrandom) -#if SANITIZER_OPENBSD -# define SANITIZER_USE_GETENTROPY 1 +#if SANITIZER_FREEBSD && __FreeBSD_version >= 1200000 +# define SANITIZER_USE_GETENTROPY 1 #else -# if SANITIZER_FREEBSD && __FreeBSD_version >= 1200000 -# define SANITIZER_USE_GETENTROPY 1 -# else -# define SANITIZER_USE_GETENTROPY 0 -# endif -#endif // SANITIZER_USE_GETENTROPY +# define SANITIZER_USE_GETENTROPY 0 +#endif namespace __sanitizer { @@ -166,7 +164,7 @@ namespace __sanitizer { // --------------- sanitizer_libc.h #if !SANITIZER_SOLARIS && !SANITIZER_NETBSD -#if !SANITIZER_S390 && !SANITIZER_OPENBSD +#if !SANITIZER_S390 uptr internal_mmap(void *addr, uptr length, int prot, int flags, int fd, u64 offset) { #if SANITIZER_FREEBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS @@ -179,9 +177,8 @@ uptr internal_mmap(void *addr, uptr length, int prot, int flags, int fd, offset / 4096); #endif } -#endif // !SANITIZER_S390 && !SANITIZER_OPENBSD +#endif // !SANITIZER_S390 -#if !SANITIZER_OPENBSD uptr internal_munmap(void *addr, uptr length) { return internal_syscall(SYSCALL(munmap), (uptr)addr, length); } @@ -193,7 +190,6 @@ int internal_mprotect(void *addr, uptr length, int prot) { int internal_madvise(uptr addr, uptr length, int advice) { return internal_syscall(SYSCALL(madvise), addr, length, advice); } -#endif uptr internal_close(fd_t fd) { return internal_syscall(SYSCALL(close), fd); @@ -260,9 +256,11 @@ static void stat64_to_stat(struct stat64 *in, struct stat *out) { // Undefine compatibility macros from // so that they would not clash with the kernel_stat // st_[a|m|c]time fields +#if !SANITIZER_GO #undef st_atime #undef st_mtime #undef st_ctime +#endif #if defined(SANITIZER_ANDROID) // Bionic sys/stat.h defines additional macros // for compatibility with the old NDKs and @@ -305,7 +303,7 @@ static void kernel_stat_to_stat(struct kernel_stat *in, struct stat *out) { #endif uptr internal_stat(const char *path, void *buf) { -#if SANITIZER_FREEBSD || SANITIZER_OPENBSD +#if SANITIZER_FREEBSD return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf, 0); #elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf, @@ -329,7 +327,7 @@ uptr internal_stat(const char *path, void *buf) { } uptr internal_lstat(const char *path, void *buf) { -#if SANITIZER_FREEBSD || SANITIZER_OPENBSD +#if SANITIZER_FREEBSD return internal_syscall(SYSCALL(fstatat), AT_FDCWD, (uptr)path, (uptr)buf, AT_SYMLINK_NOFOLLOW); #elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS @@ -354,9 +352,8 @@ uptr internal_lstat(const char *path, void *buf) { } uptr internal_fstat(fd_t fd, void *buf) { -#if SANITIZER_FREEBSD || SANITIZER_OPENBSD || \ - SANITIZER_LINUX_USES_64BIT_SYSCALLS -#if SANITIZER_MIPS64 && !SANITIZER_OPENBSD +#if SANITIZER_FREEBSD || SANITIZER_LINUX_USES_64BIT_SYSCALLS +#if SANITIZER_MIPS64 // For mips64, fstat syscall fills buffer in the format of kernel_stat struct kernel_stat kbuf; int res = internal_syscall(SYSCALL(fstat), fd, &kbuf); @@ -396,16 +393,13 @@ uptr internal_readlink(const char *path, char *buf, uptr bufsize) { #if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS return internal_syscall(SYSCALL(readlinkat), AT_FDCWD, (uptr)path, (uptr)buf, bufsize); -#elif SANITIZER_OPENBSD - return internal_syscall(SYSCALL(readlinkat), AT_FDCWD, (uptr)path, (uptr)buf, - bufsize); #else return internal_syscall(SYSCALL(readlink), (uptr)path, (uptr)buf, bufsize); #endif } uptr internal_unlink(const char *path) { -#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS || SANITIZER_OPENBSD +#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS return internal_syscall(SYSCALL(unlinkat), AT_FDCWD, (uptr)path, 0); #else return internal_syscall(SYSCALL(unlink), (uptr)path); @@ -416,7 +410,7 @@ uptr internal_rename(const char *oldpath, const char *newpath) { #if defined(__riscv) return internal_syscall(SYSCALL(renameat2), AT_FDCWD, (uptr)oldpath, AT_FDCWD, (uptr)newpath, 0); -#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS || SANITIZER_OPENBSD +#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS return internal_syscall(SYSCALL(renameat), AT_FDCWD, (uptr)oldpath, AT_FDCWD, (uptr)newpath); #else @@ -446,7 +440,7 @@ uptr internal_execve(const char *filename, char *const argv[], #if !SANITIZER_NETBSD void internal__exit(int exitcode) { -#if SANITIZER_FREEBSD || SANITIZER_OPENBSD || SANITIZER_SOLARIS +#if SANITIZER_FREEBSD || SANITIZER_SOLARIS internal_syscall(SYSCALL(exit), exitcode); #else internal_syscall(SYSCALL(exit_group), exitcode); @@ -476,8 +470,6 @@ tid_t GetTid() { long Tid; thr_self(&Tid); return Tid; -#elif SANITIZER_OPENBSD - return internal_syscall(SYSCALL(getthrid)); #elif SANITIZER_SOLARIS return thr_self(); #else @@ -490,9 +482,6 @@ int TgKill(pid_t pid, tid_t tid, int sig) { return internal_syscall(SYSCALL(tgkill), pid, tid, sig); #elif SANITIZER_FREEBSD return internal_syscall(SYSCALL(thr_kill2), pid, tid, sig); -#elif SANITIZER_OPENBSD - (void)pid; - return internal_syscall(SYSCALL(thrkill), tid, sig, nullptr); #elif SANITIZER_SOLARIS (void)pid; return thr_kill(tid, sig); @@ -502,7 +491,7 @@ int TgKill(pid_t pid, tid_t tid, int sig) { #if !SANITIZER_SOLARIS && !SANITIZER_NETBSD u64 NanoTime() { -#if SANITIZER_FREEBSD || SANITIZER_OPENBSD +#if SANITIZER_FREEBSD timeval tv; #else kernel_timeval tv; @@ -521,8 +510,7 @@ uptr internal_clock_gettime(__sanitizer_clockid_t clk_id, void *tp) { // 'environ' array (on some others) and does not use libc. This function // should be called first inside __asan_init. const char *GetEnv(const char *name) { -#if SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_OPENBSD || \ - SANITIZER_SOLARIS +#if SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_SOLARIS if (::environ != 0) { uptr NameLen = internal_strlen(name); for (char **Env = ::environ; *Env != 0; Env++) { @@ -560,15 +548,13 @@ const char *GetEnv(const char *name) { #endif } -#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD && !SANITIZER_OPENBSD && \ - !SANITIZER_GO +#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD && !SANITIZER_GO extern "C" { SANITIZER_WEAK_ATTRIBUTE extern void *__libc_stack_end; } #endif -#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD && \ - !SANITIZER_OPENBSD +#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD static void ReadNullSepFileToArray(const char *path, char ***arr, int arr_size) { char *buff; @@ -593,7 +579,6 @@ static void ReadNullSepFileToArray(const char *path, char ***arr, } #endif -#if !SANITIZER_OPENBSD static void GetArgsAndEnv(char ***argv, char ***envp) { #if SANITIZER_FREEBSD // On FreeBSD, retrieving the argument and environment arrays is done via the @@ -645,8 +630,6 @@ char **GetEnviron() { return envp; } -#endif // !SANITIZER_OPENBSD - #if !SANITIZER_SOLARIS enum MutexState { MtxUnlocked = 0, @@ -702,16 +685,6 @@ void BlockingMutex::CheckLocked() { // 32-bit syscall here. #if SANITIZER_NETBSD // Not used -#elif SANITIZER_OPENBSD -// struct dirent is different for Linux and us. At this moment, we use only -// d_fileno (Linux call this d_ino), d_reclen, and d_name. -struct linux_dirent { - u64 d_ino; // d_fileno - u16 d_reclen; - u16 d_namlen; // not used - u8 d_type; // not used - char d_name[NAME_MAX + 1]; -}; #else struct linux_dirent { #if SANITIZER_X32 || defined(__aarch64__) || SANITIZER_RISCV64 @@ -789,19 +762,13 @@ int internal_fork() { #endif } -#if SANITIZER_FREEBSD || SANITIZER_OPENBSD +#if SANITIZER_FREEBSD int internal_sysctl(const int *name, unsigned int namelen, void *oldp, uptr *oldlenp, const void *newp, uptr newlen) { -#if SANITIZER_OPENBSD - return sysctl(name, namelen, oldp, (size_t *)oldlenp, (void *)newp, - (size_t)newlen); -#else return internal_syscall(SYSCALL(__sysctl), name, namelen, oldp, (size_t *)oldlenp, newp, (size_t)newlen); -#endif } -#if SANITIZER_FREEBSD int internal_sysctlbyname(const char *sname, void *oldp, uptr *oldlenp, const void *newp, uptr newlen) { // Note: this function can be called during startup, so we need to avoid @@ -829,7 +796,6 @@ int internal_sysctlbyname(const char *sname, void *oldp, uptr *oldlenp, #endif } #endif -#endif #if SANITIZER_LINUX #define SA_RESTORER 0x04000000 @@ -882,7 +848,7 @@ int internal_sigaction_norestorer(int signum, const void *act, void *oldact) { uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set, __sanitizer_sigset_t *oldset) { -#if SANITIZER_FREEBSD || SANITIZER_OPENBSD +#if SANITIZER_FREEBSD return internal_syscall(SYSCALL(sigprocmask), how, set, oldset); #else __sanitizer_kernel_sigset_t *k_set = (__sanitizer_kernel_sigset_t *)set; @@ -1059,7 +1025,7 @@ static uptr GetKernelAreaSize() { #endif // SANITIZER_WORDSIZE == 32 uptr GetMaxVirtualAddress() { -#if (SANITIZER_NETBSD || SANITIZER_OPENBSD) && defined(__x86_64__) +#if SANITIZER_NETBSD && defined(__x86_64__) return 0x7f7ffffff000ULL; // (0x00007f8000000000 - PAGE_SIZE) #elif SANITIZER_WORDSIZE == 64 # if defined(__powerpc64__) || defined(__aarch64__) @@ -1122,7 +1088,6 @@ uptr GetPageSize() { } #endif // !SANITIZER_ANDROID -#if !SANITIZER_OPENBSD uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) { #if SANITIZER_SOLARIS const char *default_module_name = getexecname(); @@ -1159,7 +1124,6 @@ uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) { return module_name_len; #endif } -#endif // !SANITIZER_OPENBSD uptr ReadLongProcessName(/*out*/ char *buf, uptr buf_len) { #if SANITIZER_LINUX @@ -1192,10 +1156,10 @@ bool LibraryNameIs(const char *full_name, const char *base_name) { // Call cb for each region mapped by map. void ForEachMappedRegion(link_map *map, void (*cb)(const void *, uptr)) { CHECK_NE(map, nullptr); -#if !SANITIZER_FREEBSD && !SANITIZER_OPENBSD +#if !SANITIZER_FREEBSD typedef ElfW(Phdr) Elf_Phdr; typedef ElfW(Ehdr) Elf_Ehdr; -#endif // !SANITIZER_FREEBSD && !SANITIZER_OPENBSD +#endif // !SANITIZER_FREEBSD char *base = (char *)map->l_addr; Elf_Ehdr *ehdr = (Elf_Ehdr *)base; char *phdrs = base + ehdr->e_phoff; @@ -1845,11 +1809,7 @@ static bool Aarch64GetESR(ucontext_t *ucontext, u64 *esr) { } #endif -#if SANITIZER_OPENBSD -using Context = sigcontext; -#else using Context = ucontext_t; -#endif SignalContext::WriteFlag SignalContext::GetWriteFlag() const { Context *ucontext = (Context *)context; @@ -1859,8 +1819,6 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const { uptr err = ucontext->uc_mcontext.mc_err; #elif SANITIZER_NETBSD uptr err = ucontext->uc_mcontext.__gregs[_REG_ERR]; -#elif SANITIZER_OPENBSD - uptr err = ucontext->sc_err; #elif SANITIZER_SOLARIS && defined(__i386__) const int Err = 13; uptr err = ucontext->uc_mcontext.gregs[Err]; @@ -2086,11 +2044,6 @@ static void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) { *pc = ucontext->uc_mcontext.mc_rip; *bp = ucontext->uc_mcontext.mc_rbp; *sp = ucontext->uc_mcontext.mc_rsp; -#elif SANITIZER_OPENBSD - sigcontext *ucontext = (sigcontext *)context; - *pc = ucontext->sc_rip; - *bp = ucontext->sc_rbp; - *sp = ucontext->sc_rsp; # else ucontext_t *ucontext = (ucontext_t*)context; *pc = ucontext->uc_mcontext.gregs[REG_RIP]; @@ -2103,11 +2056,6 @@ static void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) { *pc = ucontext->uc_mcontext.mc_eip; *bp = ucontext->uc_mcontext.mc_ebp; *sp = ucontext->uc_mcontext.mc_esp; -#elif SANITIZER_OPENBSD - sigcontext *ucontext = (sigcontext *)context; - *pc = ucontext->sc_eip; - *bp = ucontext->sc_ebp; - *sp = ucontext->sc_esp; # else ucontext_t *ucontext = (ucontext_t*)context; # if SANITIZER_SOLARIS @@ -2280,8 +2228,6 @@ void CheckMPROTECT() { #endif } -void PrintModuleMap() { } - void CheckNoDeepBind(const char *filename, int flag) { #ifdef RTLD_DEEPBIND if (flag & RTLD_DEEPBIND) { diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.h b/libsanitizer/sanitizer_common/sanitizer_linux.h index a8625ca86e8..24902d1b6bc 100644 --- a/libsanitizer/sanitizer_common/sanitizer_linux.h +++ b/libsanitizer/sanitizer_common/sanitizer_linux.h @@ -14,12 +14,11 @@ #include "sanitizer_platform.h" #if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \ - SANITIZER_OPENBSD || SANITIZER_SOLARIS + SANITIZER_SOLARIS #include "sanitizer_common.h" #include "sanitizer_internal_defs.h" #include "sanitizer_platform_limits_freebsd.h" #include "sanitizer_platform_limits_netbsd.h" -#include "sanitizer_platform_limits_openbsd.h" #include "sanitizer_platform_limits_posix.h" #include "sanitizer_platform_limits_solaris.h" #include "sanitizer_posix.h" diff --git a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp index af077439478..47c84ce1b06 100644 --- a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp @@ -14,7 +14,7 @@ #include "sanitizer_platform.h" #if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \ - SANITIZER_OPENBSD || SANITIZER_SOLARIS + SANITIZER_SOLARIS #include "sanitizer_allocator_internal.h" #include "sanitizer_atomic.h" @@ -50,11 +50,6 @@ #define pthread_getattr_np pthread_attr_get_np #endif -#if SANITIZER_OPENBSD -#include -#include -#endif - #if SANITIZER_NETBSD #include #include @@ -142,11 +137,6 @@ void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top, CHECK_EQ(thr_stksegment(&ss), 0); stacksize = ss.ss_size; stackaddr = (char *)ss.ss_sp - stacksize; -#elif SANITIZER_OPENBSD - stack_t sattr; - CHECK_EQ(pthread_stackseg_np(pthread_self(), &sattr), 0); - stackaddr = sattr.ss_sp; - stacksize = sattr.ss_size; #else // !SANITIZER_SOLARIS pthread_attr_t attr; pthread_attr_init(&attr); @@ -194,7 +184,7 @@ __attribute__((unused)) static bool GetLibcVersion(int *major, int *minor, } #if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO && \ - !SANITIZER_NETBSD && !SANITIZER_OPENBSD && !SANITIZER_SOLARIS + !SANITIZER_NETBSD && !SANITIZER_SOLARIS static uptr g_tls_size; #ifdef __i386__ @@ -385,12 +375,9 @@ uptr ThreadSelf() { descr_addr = reinterpret_cast(__builtin_thread_pointer()) - ThreadDescriptorSize(); #elif SANITIZER_RISCV64 - uptr tcb_end; - asm volatile("mv %0, tp;\n" : "=r"(tcb_end)); // https://github.com/riscv/riscv-elf-psabi-doc/issues/53 - const uptr kTlsTcbOffset = 0x800; - descr_addr = - reinterpret_cast(tcb_end - kTlsTcbOffset - TlsPreTcbSize()); + uptr thread_pointer = reinterpret_cast(__builtin_thread_pointer()); + descr_addr = thread_pointer - TlsPreTcbSize(); #elif defined(__s390__) descr_addr = reinterpret_cast(__builtin_thread_pointer()); #elif defined(__powerpc64__) @@ -458,9 +445,27 @@ int GetSizeFromHdr(struct dl_phdr_info *info, size_t size, void *data) { } #endif // SANITIZER_NETBSD +#if SANITIZER_ANDROID +// Bionic provides this API since S. +extern "C" SANITIZER_WEAK_ATTRIBUTE void __libc_get_static_tls_bounds(void **, + void **); +#endif + #if !SANITIZER_GO static void GetTls(uptr *addr, uptr *size) { -#if SANITIZER_LINUX && !SANITIZER_ANDROID +#if SANITIZER_ANDROID + if (&__libc_get_static_tls_bounds) { + void *start_addr; + void *end_addr; + __libc_get_static_tls_bounds(&start_addr, &end_addr); + *addr = reinterpret_cast(start_addr); + *size = + reinterpret_cast(end_addr) - reinterpret_cast(start_addr); + } else { + *addr = 0; + *size = 0; + } +#elif SANITIZER_LINUX #if defined(__x86_64__) || defined(__i386__) || defined(__s390__) *addr = ThreadSelf(); *size = GetTlsSize(); @@ -501,12 +506,6 @@ static void GetTls(uptr *addr, uptr *size) { *addr = (uptr)tcb->tcb_dtv[1]; } } -#elif SANITIZER_OPENBSD - *addr = 0; - *size = 0; -#elif SANITIZER_ANDROID - *addr = 0; - *size = 0; #elif SANITIZER_SOLARIS // FIXME *addr = 0; @@ -520,7 +519,7 @@ static void GetTls(uptr *addr, uptr *size) { #if !SANITIZER_GO uptr GetTlsSize() { #if SANITIZER_FREEBSD || SANITIZER_ANDROID || SANITIZER_NETBSD || \ - SANITIZER_OPENBSD || SANITIZER_SOLARIS + SANITIZER_SOLARIS uptr addr, size; GetTls(&addr, &size); return size; @@ -557,13 +556,13 @@ void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size, #endif } -#if !SANITIZER_FREEBSD && !SANITIZER_OPENBSD +#if !SANITIZER_FREEBSD typedef ElfW(Phdr) Elf_Phdr; #elif SANITIZER_WORDSIZE == 32 && __FreeBSD_version <= 902001 // v9.2 #define Elf_Phdr XElf32_Phdr #define dl_phdr_info xdl_phdr_info #define dl_iterate_phdr(c, b) xdl_iterate_phdr((c), (b)) -#endif // !SANITIZER_FREEBSD && !SANITIZER_OPENBSD +#endif // !SANITIZER_FREEBSD struct DlIteratePhdrData { InternalMmapVectorNoCtor *modules; @@ -683,7 +682,7 @@ uptr GetRSS() { // sysconf(_SC_NPROCESSORS_{CONF,ONLN}) cannot be used on most platforms as // they allocate memory. u32 GetNumberOfCPUs() { -#if SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_OPENBSD +#if SANITIZER_FREEBSD || SANITIZER_NETBSD u32 ncpu; int req[2]; uptr len = sizeof(ncpu); @@ -730,13 +729,9 @@ u32 GetNumberOfCPUs() { #elif SANITIZER_SOLARIS return sysconf(_SC_NPROCESSORS_ONLN); #else -#if defined(CPU_COUNT) cpu_set_t CPUs; CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0); return CPU_COUNT(&CPUs); -#else - return 1; -#endif #endif } @@ -844,7 +839,6 @@ u64 MonotonicNanoTime() { } #endif // SANITIZER_LINUX && !SANITIZER_GO -#if !SANITIZER_OPENBSD void ReExec() { const char *pathname = "/proc/self/exe"; @@ -876,7 +870,6 @@ void ReExec() { Printf("execve failed, errno %d\n", rverrno); Die(); } -#endif // !SANITIZER_OPENBSD void UnmapFromTo(uptr from, uptr to) { if (to == from) @@ -913,6 +906,13 @@ uptr MapDynamicShadow(uptr shadow_size_bytes, uptr shadow_scale, return shadow_start; } +void InitializePlatformCommonFlags(CommonFlags *cf) { +#if SANITIZER_ANDROID + if (&__libc_get_static_tls_bounds == nullptr) + cf->detect_leaks = false; +#endif +} + } // namespace __sanitizer #endif diff --git a/libsanitizer/sanitizer_common/sanitizer_mac.cpp b/libsanitizer/sanitizer_common/sanitizer_mac.cpp index 36a8f79cbdb..62d422d043d 100644 --- a/libsanitizer/sanitizer_common/sanitizer_mac.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_mac.cpp @@ -37,7 +37,7 @@ extern char **environ; #endif -#if defined(__has_include) && __has_include() && defined(__BLOCKS__) +#if defined(__has_include) && __has_include() #define SANITIZER_OS_TRACE 1 #include #else @@ -1300,7 +1300,7 @@ void FormatUUID(char *out, uptr size, const u8 *uuid) { uuid[12], uuid[13], uuid[14], uuid[15]); } -void PrintModuleMap() { +void DumpProcessMap() { Printf("Process module map:\n"); MemoryMappingLayout memory_mapping(false); InternalMmapVector modules; @@ -1333,6 +1333,8 @@ u32 GetNumberOfCPUs() { return (u32)sysconf(_SC_NPROCESSORS_ONLN); } +void InitializePlatformCommonFlags(CommonFlags *cf) {} + } // namespace __sanitizer #endif // SANITIZER_MAC diff --git a/libsanitizer/sanitizer_common/sanitizer_mac.h b/libsanitizer/sanitizer_common/sanitizer_mac.h index a2c42b3bf4f..023071e4f11 100644 --- a/libsanitizer/sanitizer_common/sanitizer_mac.h +++ b/libsanitizer/sanitizer_common/sanitizer_mac.h @@ -14,26 +14,6 @@ #include "sanitizer_common.h" #include "sanitizer_platform.h" - -/* TARGET_OS_OSX is not present in SDKs before Darwin16 (macOS 10.12) use - TARGET_OS_MAC (we have no support for iOS in any form for these versions, - so there's no ambiguity). */ -#if !defined(TARGET_OS_OSX) && TARGET_OS_MAC -# define TARGET_OS_OSX 1 -#endif - -/* Other TARGET_OS_xxx are not present on earlier versions, define them to - 0 (we have no support for them; they are not valid targets anyway). */ -#ifndef TARGET_OS_IOS -#define TARGET_OS_IOS 0 -#endif -#ifndef TARGET_OS_TV -#define TARGET_OS_TV 0 -#endif -#ifndef TARGET_OS_WATCH -#define TARGET_OS_WATCH 0 -#endif - #if SANITIZER_MAC #include "sanitizer_posix.h" diff --git a/libsanitizer/sanitizer_common/sanitizer_openbsd.cpp b/libsanitizer/sanitizer_common/sanitizer_openbsd.cpp index 195901714b1..e69de29bb2d 100644 --- a/libsanitizer/sanitizer_common/sanitizer_openbsd.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_openbsd.cpp @@ -1,119 +0,0 @@ -//===-- sanitizer_openbsd.cpp ---------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file is shared between various sanitizers' runtime libraries and -// implements Solaris-specific functions. -//===----------------------------------------------------------------------===// - -#include "sanitizer_platform.h" -#if SANITIZER_OPENBSD - -#include - -#include "sanitizer_common.h" -#include "sanitizer_flags.h" -#include "sanitizer_internal_defs.h" -#include "sanitizer_libc.h" -#include "sanitizer_placement_new.h" -#include "sanitizer_platform_limits_posix.h" -#include "sanitizer_procmaps.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern char **environ; - -namespace __sanitizer { - -uptr internal_mmap(void *addr, size_t length, int prot, int flags, int fd, - u64 offset) { - return (uptr)mmap(addr, length, prot, flags, fd, offset); -} - -uptr internal_munmap(void *addr, uptr length) { return munmap(addr, length); } - -int internal_mprotect(void *addr, uptr length, int prot) { - return mprotect(addr, length, prot); -} - -int internal_madvise(uptr addr, uptr length, int advice) { - return madvise((void *)addr, length, advice); -} - -int internal_sysctlbyname(const char *sname, void *oldp, uptr *oldlenp, - const void *newp, uptr newlen) { - Printf("internal_sysctlbyname not implemented for OpenBSD"); - Die(); - return 0; -} - -uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) { - // On OpenBSD we cannot get the full path - struct kinfo_proc kp; - uptr kl; - const int Mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()}; - if (internal_sysctl(Mib, ARRAY_SIZE(Mib), &kp, &kl, NULL, 0) != -1) - return internal_snprintf(buf, - (KI_MAXCOMLEN < buf_len ? KI_MAXCOMLEN : buf_len), - "%s", kp.p_comm); - return (uptr)0; -} - -static void GetArgsAndEnv(char ***argv, char ***envp) { - uptr nargv; - uptr nenv; - int argvmib[4] = {CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV}; - int envmib[4] = {CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ENV}; - if (internal_sysctl(argvmib, 4, NULL, &nargv, NULL, 0) == -1) { - Printf("sysctl KERN_PROC_NARGV failed\n"); - Die(); - } - if (internal_sysctl(envmib, 4, NULL, &nenv, NULL, 0) == -1) { - Printf("sysctl KERN_PROC_NENV failed\n"); - Die(); - } - if (internal_sysctl(argvmib, 4, &argv, &nargv, NULL, 0) == -1) { - Printf("sysctl KERN_PROC_ARGV failed\n"); - Die(); - } - if (internal_sysctl(envmib, 4, &envp, &nenv, NULL, 0) == -1) { - Printf("sysctl KERN_PROC_ENV failed\n"); - Die(); - } -} - -char **GetArgv() { - char **argv, **envp; - GetArgsAndEnv(&argv, &envp); - return argv; -} - -char **GetEnviron() { - char **argv, **envp; - GetArgsAndEnv(&argv, &envp); - return envp; -} - -void ReExec() { - UNIMPLEMENTED(); -} - -} // namespace __sanitizer - -#endif // SANITIZER_OPENBSD diff --git a/libsanitizer/sanitizer_common/sanitizer_platform.h b/libsanitizer/sanitizer_common/sanitizer_platform.h index 5547c68bc51..b2372a025c0 100644 --- a/libsanitizer/sanitizer_common/sanitizer_platform.h +++ b/libsanitizer/sanitizer_common/sanitizer_platform.h @@ -13,7 +13,7 @@ #define SANITIZER_PLATFORM_H #if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \ - !defined(__OpenBSD__) && !defined(__APPLE__) && !defined(_WIN32) && \ + !defined(__APPLE__) && !defined(_WIN32) && \ !defined(__Fuchsia__) && !defined(__rtems__) && \ !(defined(__sun__) && defined(__svr4__)) # error "This operating system is not supported" @@ -37,12 +37,6 @@ # define SANITIZER_NETBSD 0 #endif -#if defined(__OpenBSD__) -# define SANITIZER_OPENBSD 1 -#else -# define SANITIZER_OPENBSD 0 -#endif - #if defined(__sun__) && defined(__svr4__) # define SANITIZER_SOLARIS 1 #else @@ -112,7 +106,7 @@ #define SANITIZER_POSIX \ (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC || \ - SANITIZER_NETBSD || SANITIZER_OPENBSD || SANITIZER_SOLARIS) + SANITIZER_NETBSD || SANITIZER_SOLARIS) #if __LP64__ || defined(_WIN64) # define SANITIZER_WORDSIZE 64 @@ -244,7 +238,11 @@ // FIXME: this value should be different on different platforms. Larger values // will still work but will consume more memory for TwoLevelByteMap. #if defined(__mips__) +#if SANITIZER_GO && defined(__mips64) +#define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47) +#else # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 40) +#endif #elif SANITIZER_RISCV64 #define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 38) #elif defined(__aarch64__) @@ -339,7 +337,7 @@ #endif #if SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_NETBSD || \ - SANITIZER_OPENBSD || SANITIZER_SOLARIS + SANITIZER_SOLARIS # define SANITIZER_MADVISE_DONTNEED MADV_FREE #else # define SANITIZER_MADVISE_DONTNEED MADV_DONTNEED diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_interceptors.h b/libsanitizer/sanitizer_common/sanitizer_platform_interceptors.h index 37f178a6f57..18bab346ce6 100644 --- a/libsanitizer/sanitizer_common/sanitizer_platform_interceptors.h +++ b/libsanitizer/sanitizer_common/sanitizer_platform_interceptors.h @@ -18,131 +18,124 @@ #include "sanitizer_platform.h" #if SANITIZER_POSIX -# define SI_POSIX 1 +#define SI_POSIX 1 #else -# define SI_POSIX 0 +#define SI_POSIX 0 #endif #if !SANITIZER_WINDOWS -# define SI_WINDOWS 0 +#define SI_WINDOWS 0 #else -# define SI_WINDOWS 1 +#define SI_WINDOWS 1 #endif #if SI_WINDOWS && SI_POSIX -# error "Windows is not POSIX!" +#error "Windows is not POSIX!" #endif #if SI_POSIX -# include "sanitizer_platform_limits_freebsd.h" -# include "sanitizer_platform_limits_netbsd.h" -# include "sanitizer_platform_limits_openbsd.h" -# include "sanitizer_platform_limits_posix.h" -# include "sanitizer_platform_limits_solaris.h" +#include "sanitizer_platform_limits_freebsd.h" +#include "sanitizer_platform_limits_netbsd.h" +#include "sanitizer_platform_limits_posix.h" +#include "sanitizer_platform_limits_solaris.h" #endif #if SANITIZER_LINUX && !SANITIZER_ANDROID -# define SI_LINUX_NOT_ANDROID 1 +#define SI_LINUX_NOT_ANDROID 1 #else -# define SI_LINUX_NOT_ANDROID 0 +#define SI_LINUX_NOT_ANDROID 0 #endif #if SANITIZER_ANDROID -# define SI_ANDROID 1 +#define SI_ANDROID 1 #else -# define SI_ANDROID 0 +#define SI_ANDROID 0 #endif #if SANITIZER_FREEBSD -# define SI_FREEBSD 1 +#define SI_FREEBSD 1 #else -# define SI_FREEBSD 0 +#define SI_FREEBSD 0 #endif #if SANITIZER_NETBSD -# define SI_NETBSD 1 +#define SI_NETBSD 1 #else -# define SI_NETBSD 0 -#endif - -#if SANITIZER_OPENBSD -#define SI_OPENBSD 1 -#else -#define SI_OPENBSD 0 +#define SI_NETBSD 0 #endif #if SANITIZER_LINUX -# define SI_LINUX 1 +#define SI_LINUX 1 #else -# define SI_LINUX 0 +#define SI_LINUX 0 #endif #if SANITIZER_MAC -# define SI_MAC 1 -# define SI_NOT_MAC 0 +#define SI_MAC 1 +#define SI_NOT_MAC 0 #else -# define SI_MAC 0 -# define SI_NOT_MAC 1 +#define SI_MAC 0 +#define SI_NOT_MAC 1 #endif #if SANITIZER_IOS -# define SI_IOS 1 +#define SI_IOS 1 #else -# define SI_IOS 0 +#define SI_IOS 0 #endif #if SANITIZER_IOSSIM -# define SI_IOSSIM 1 +#define SI_IOSSIM 1 #else -# define SI_IOSSIM 0 +#define SI_IOSSIM 0 #endif #if SANITIZER_WATCHOS -# define SI_WATCHOS 1 +#define SI_WATCHOS 1 #else -# define SI_WATCHOS 0 +#define SI_WATCHOS 0 #endif #if SANITIZER_TVOS -# define SI_TVOS 1 +#define SI_TVOS 1 #else -# define SI_TVOS 0 +#define SI_TVOS 0 #endif #if SANITIZER_FUCHSIA -# define SI_NOT_FUCHSIA 0 +#define SI_NOT_FUCHSIA 0 #else -# define SI_NOT_FUCHSIA 1 +#define SI_NOT_FUCHSIA 1 #endif #if SANITIZER_RTEMS -# define SI_NOT_RTEMS 0 +#define SI_NOT_RTEMS 0 #else -# define SI_NOT_RTEMS 1 +#define SI_NOT_RTEMS 1 #endif #if SANITIZER_SOLARIS -# define SI_SOLARIS 1 +#define SI_SOLARIS 1 #else -# define SI_SOLARIS 0 +#define SI_SOLARIS 0 #endif #if SANITIZER_SOLARIS32 -# define SI_SOLARIS32 1 +#define SI_SOLARIS32 1 #else -# define SI_SOLARIS32 0 +#define SI_SOLARIS32 0 #endif #if SANITIZER_POSIX && !SANITIZER_MAC -# define SI_POSIX_NOT_MAC 1 +#define SI_POSIX_NOT_MAC 1 #else -# define SI_POSIX_NOT_MAC 0 +#define SI_POSIX_NOT_MAC 0 #endif #if SANITIZER_LINUX && !SANITIZER_FREEBSD -# define SI_LINUX_NOT_FREEBSD 1 -# else -# define SI_LINUX_NOT_FREEBSD 0 +#define SI_LINUX_NOT_FREEBSD 1 +#else +#define SI_LINUX_NOT_FREEBSD 0 #endif #define SANITIZER_INTERCEPT_STRLEN SI_NOT_FUCHSIA @@ -164,21 +157,20 @@ #define SANITIZER_INTERCEPT_MEMCMP SI_NOT_FUCHSIA #define SANITIZER_INTERCEPT_BCMP \ SANITIZER_INTERCEPT_MEMCMP && \ - ((SI_POSIX && _GNU_SOURCE) || SI_NETBSD || SI_OPENBSD || SI_FREEBSD) + ((SI_POSIX && _GNU_SOURCE) || SI_NETBSD || SI_FREEBSD) #define SANITIZER_INTERCEPT_STRNDUP SI_POSIX #define SANITIZER_INTERCEPT___STRNDUP SI_LINUX_NOT_FREEBSD #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1070 -# define SI_MAC_DEPLOYMENT_BELOW_10_7 1 +#define SI_MAC_DEPLOYMENT_BELOW_10_7 1 #else -# define SI_MAC_DEPLOYMENT_BELOW_10_7 0 +#define SI_MAC_DEPLOYMENT_BELOW_10_7 0 #endif // memmem on Darwin doesn't exist on 10.6 // FIXME: enable memmem on Windows. #define SANITIZER_INTERCEPT_MEMMEM (SI_POSIX && !SI_MAC_DEPLOYMENT_BELOW_10_7) #define SANITIZER_INTERCEPT_MEMCHR SI_NOT_FUCHSIA -#define SANITIZER_INTERCEPT_MEMRCHR \ - (SI_FREEBSD || SI_LINUX || SI_NETBSD || SI_OPENBSD) +#define SANITIZER_INTERCEPT_MEMRCHR (SI_FREEBSD || SI_LINUX || SI_NETBSD) #define SANITIZER_INTERCEPT_READ SI_POSIX #define SANITIZER_INTERCEPT_PREAD SI_POSIX @@ -198,12 +190,12 @@ #define SANITIZER_INTERCEPT_WRITEV SI_POSIX #define SANITIZER_INTERCEPT_PREADV \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_LINUX_NOT_ANDROID) + (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID) #define SANITIZER_INTERCEPT_PWRITEV SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_PREADV64 SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_PWRITEV64 SI_LINUX_NOT_ANDROID -#define SANITIZER_INTERCEPT_PRCTL SI_LINUX +#define SANITIZER_INTERCEPT_PRCTL SI_LINUX #define SANITIZER_INTERCEPT_LOCALTIME_AND_FRIENDS SI_POSIX #define SANITIZER_INTERCEPT_STRPTIME SI_POSIX @@ -212,9 +204,9 @@ #define SANITIZER_INTERCEPT_ISOC99_SCANF SI_LINUX_NOT_ANDROID #ifndef SANITIZER_INTERCEPT_PRINTF -# define SANITIZER_INTERCEPT_PRINTF SI_POSIX -# define SANITIZER_INTERCEPT_PRINTF_L (SI_FREEBSD || SI_NETBSD) -# define SANITIZER_INTERCEPT_ISOC99_PRINTF SI_LINUX_NOT_ANDROID +#define SANITIZER_INTERCEPT_PRINTF SI_POSIX +#define SANITIZER_INTERCEPT_PRINTF_L (SI_FREEBSD || SI_NETBSD) +#define SANITIZER_INTERCEPT_ISOC99_PRINTF SI_LINUX_NOT_ANDROID #endif #define SANITIZER_INTERCEPT___PRINTF_CHK \ @@ -224,23 +216,21 @@ #define SANITIZER_INTERCEPT_FREXPF_FREXPL SI_POSIX #define SANITIZER_INTERCEPT_GETPWNAM_AND_FRIENDS SI_POSIX -#define SANITIZER_INTERCEPT_GETPWNAM_R_AND_FRIENDS \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_MAC || SI_LINUX_NOT_ANDROID || \ - SI_SOLARIS) -#define SANITIZER_INTERCEPT_GETPWENT \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_MAC || SI_LINUX_NOT_ANDROID || \ - SI_SOLARIS) -#define SANITIZER_INTERCEPT_FGETGRENT_R \ - (SI_FREEBSD || SI_OPENBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) +#define SANITIZER_INTERCEPT_GETPWNAM_R_AND_FRIENDS \ + (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS) +#define SANITIZER_INTERCEPT_GETPWENT \ + (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS) +#define SANITIZER_INTERCEPT_FGETGRENT_R \ + (SI_FREEBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_FGETPWENT SI_LINUX_NOT_ANDROID || SI_SOLARIS #define SANITIZER_INTERCEPT_GETPWENT_R \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) + (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_FGETPWENT_R \ - (SI_FREEBSD || SI_OPENBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) + (SI_FREEBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_SETPWENT \ (SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_CLOCK_GETTIME \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_LINUX || SI_SOLARIS) + (SI_FREEBSD || SI_NETBSD || SI_LINUX || SI_SOLARIS) #define SANITIZER_INTERCEPT_CLOCK_GETCPUCLOCKID SI_LINUX #define SANITIZER_INTERCEPT_GETITIMER SI_POSIX #define SANITIZER_INTERCEPT_TIME SI_POSIX @@ -248,7 +238,7 @@ #define SANITIZER_INTERCEPT_GLOB64 SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_WAIT SI_POSIX #define SANITIZER_INTERCEPT_INET SI_POSIX -#define SANITIZER_INTERCEPT_PTHREAD_GETSCHEDPARAM (SI_POSIX && !SI_OPENBSD) +#define SANITIZER_INTERCEPT_PTHREAD_GETSCHEDPARAM SI_POSIX #define SANITIZER_INTERCEPT_GETADDRINFO SI_POSIX #define SANITIZER_INTERCEPT_GETNAMEINFO SI_POSIX #define SANITIZER_INTERCEPT_GETSOCKNAME SI_POSIX @@ -264,8 +254,7 @@ (SI_FREEBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_GETSOCKOPT SI_POSIX #define SANITIZER_INTERCEPT_ACCEPT SI_POSIX -#define SANITIZER_INTERCEPT_ACCEPT4 \ - (SI_LINUX_NOT_ANDROID || SI_NETBSD || SI_OPENBSD) +#define SANITIZER_INTERCEPT_ACCEPT4 (SI_LINUX_NOT_ANDROID || SI_NETBSD) #define SANITIZER_INTERCEPT_PACCEPT SI_NETBSD #define SANITIZER_INTERCEPT_MODF SI_POSIX #define SANITIZER_INTERCEPT_RECVMSG SI_POSIX @@ -299,36 +288,32 @@ #define SANITIZER_INTERCEPT___STRXFRM_L SI_LINUX #define SANITIZER_INTERCEPT_WCSXFRM SI_POSIX #define SANITIZER_INTERCEPT___WCSXFRM_L SI_LINUX -#define SANITIZER_INTERCEPT_WCSNRTOMBS \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_MAC || SI_LINUX_NOT_ANDROID || \ - SI_SOLARIS) -#define SANITIZER_INTERCEPT_WCRTOMB \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_MAC || SI_LINUX_NOT_ANDROID || \ - SI_SOLARIS) -#define SANITIZER_INTERCEPT_WCTOMB \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_MAC || SI_LINUX_NOT_ANDROID || \ - SI_SOLARIS) +#define SANITIZER_INTERCEPT_WCSNRTOMBS \ + (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS) +#define SANITIZER_INTERCEPT_WCRTOMB \ + (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS) +#define SANITIZER_INTERCEPT_WCTOMB \ + (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_TCGETATTR SI_LINUX_NOT_ANDROID || SI_SOLARIS #define SANITIZER_INTERCEPT_REALPATH SI_POSIX #define SANITIZER_INTERCEPT_CANONICALIZE_FILE_NAME \ (SI_LINUX_NOT_ANDROID || SI_SOLARIS) -#define SANITIZER_INTERCEPT_CONFSTR \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_MAC || SI_LINUX_NOT_ANDROID || \ - SI_SOLARIS) +#define SANITIZER_INTERCEPT_CONFSTR \ + (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_SCHED_GETAFFINITY SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_SCHED_GETPARAM SI_LINUX_NOT_ANDROID || SI_SOLARIS #define SANITIZER_INTERCEPT_STRERROR SI_POSIX #define SANITIZER_INTERCEPT_STRERROR_R SI_POSIX #define SANITIZER_INTERCEPT_XPG_STRERROR_R SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_SCANDIR \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) + (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_SCANDIR64 SI_LINUX_NOT_ANDROID || SI_SOLARIS32 #define SANITIZER_INTERCEPT_GETGROUPS SI_POSIX #define SANITIZER_INTERCEPT_POLL SI_POSIX #define SANITIZER_INTERCEPT_PPOLL SI_LINUX_NOT_ANDROID || SI_SOLARIS -#define SANITIZER_INTERCEPT_WORDEXP \ +#define SANITIZER_INTERCEPT_WORDEXP \ (SI_FREEBSD || SI_NETBSD || (SI_MAC && !SI_IOS) || SI_LINUX_NOT_ANDROID || \ - SI_SOLARIS) + SI_SOLARIS) // NOLINT #define SANITIZER_INTERCEPT_SIGWAIT SI_POSIX #define SANITIZER_INTERCEPT_SIGWAITINFO SI_LINUX_NOT_ANDROID || SI_SOLARIS #define SANITIZER_INTERCEPT_SIGTIMEDWAIT SI_LINUX_NOT_ANDROID || SI_SOLARIS @@ -339,7 +324,7 @@ #define SANITIZER_INTERCEPT_SIGPROCMASK SI_POSIX #define SANITIZER_INTERCEPT_PTHREAD_SIGMASK SI_POSIX #define SANITIZER_INTERCEPT_BACKTRACE \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) + (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_GETMNTENT SI_LINUX #define SANITIZER_INTERCEPT_GETMNTENT_R SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_STATFS \ @@ -347,25 +332,25 @@ #define SANITIZER_INTERCEPT_STATFS64 \ (((SI_MAC && !TARGET_CPU_ARM64) && !SI_IOS) || SI_LINUX_NOT_ANDROID) #define SANITIZER_INTERCEPT_STATVFS \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_LINUX_NOT_ANDROID) + (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID) #define SANITIZER_INTERCEPT_STATVFS64 SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_INITGROUPS SI_POSIX -#define SANITIZER_INTERCEPT_ETHER_NTOA_ATON (SI_POSIX && !SI_OPENBSD) +#define SANITIZER_INTERCEPT_ETHER_NTOA_ATON SI_POSIX #define SANITIZER_INTERCEPT_ETHER_HOST \ (SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID) #define SANITIZER_INTERCEPT_ETHER_R (SI_FREEBSD || SI_LINUX_NOT_ANDROID) #define SANITIZER_INTERCEPT_SHMCTL \ (((SI_FREEBSD || SI_LINUX_NOT_ANDROID) && SANITIZER_WORDSIZE == 64) || \ - SI_NETBSD || SI_OPENBSD || SI_SOLARIS) // NOLINT + SI_NETBSD || SI_SOLARIS) // NOLINT #define SANITIZER_INTERCEPT_RANDOM_R SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_PTHREAD_ATTR_GET SI_POSIX #define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETINHERITSCHED \ (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_PTHREAD_ATTR_GETAFFINITY_NP SI_LINUX_NOT_ANDROID -#define SANITIZER_INTERCEPT_PTHREAD_ATTR_GET_SCHED (SI_POSIX && !SI_OPENBSD) +#define SANITIZER_INTERCEPT_PTHREAD_ATTR_GET_SCHED SI_POSIX #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPSHARED \ - (SI_POSIX && !SI_NETBSD && !SI_OPENBSD) -#define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETTYPE (SI_POSIX && !SI_OPENBSD) + (SI_POSIX && !SI_NETBSD) +#define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETTYPE SI_POSIX #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPROTOCOL \ (SI_MAC || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETPRIOCEILING \ @@ -374,14 +359,13 @@ (SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_PTHREAD_MUTEXATTR_GETROBUST_NP SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GETPSHARED \ - (SI_POSIX && !SI_NETBSD && !SI_OPENBSD) + (SI_POSIX && !SI_NETBSD) #define SANITIZER_INTERCEPT_PTHREAD_RWLOCKATTR_GETKIND_NP SI_LINUX_NOT_ANDROID -#define SANITIZER_INTERCEPT_PTHREAD_CONDATTR_GETPSHARED \ - (SI_POSIX && !SI_NETBSD && !SI_OPENBSD) +#define SANITIZER_INTERCEPT_PTHREAD_CONDATTR_GETPSHARED (SI_POSIX && !SI_NETBSD) #define SANITIZER_INTERCEPT_PTHREAD_CONDATTR_GETCLOCK \ (SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_PTHREAD_BARRIERATTR_GETPSHARED \ - (SI_LINUX_NOT_ANDROID && !SI_NETBSD && !SI_OPENBSD) + (SI_LINUX_NOT_ANDROID && !SI_NETBSD) #define SANITIZER_INTERCEPT_THR_EXIT SI_FREEBSD #define SANITIZER_INTERCEPT_TMPNAM SI_POSIX #define SANITIZER_INTERCEPT_TMPNAM_R SI_LINUX_NOT_ANDROID || SI_SOLARIS @@ -398,40 +382,37 @@ #define SANITIZER_INTERCEPT_LGAMMA_R (SI_FREEBSD || SI_LINUX || SI_SOLARIS) #define SANITIZER_INTERCEPT_LGAMMAL_R SI_LINUX_NOT_ANDROID || SI_SOLARIS #define SANITIZER_INTERCEPT_DRAND48_R SI_LINUX_NOT_ANDROID -#define SANITIZER_INTERCEPT_RAND_R \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_MAC || SI_LINUX_NOT_ANDROID || \ - SI_SOLARIS) +#define SANITIZER_INTERCEPT_RAND_R \ + (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_ICONV \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) + (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_TIMES SI_POSIX // FIXME: getline seems to be available on OSX 10.7 #define SANITIZER_INTERCEPT_GETLINE \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) + (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT__EXIT \ - (SI_LINUX || SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_MAC || SI_SOLARIS) + (SI_LINUX || SI_FREEBSD || SI_NETBSD || SI_MAC || SI_SOLARIS) #define SANITIZER_INTERCEPT_PTHREAD_MUTEX SI_POSIX #define SANITIZER_INTERCEPT___PTHREAD_MUTEX SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT___LIBC_MUTEX SI_NETBSD #define SANITIZER_INTERCEPT_PTHREAD_SETNAME_NP \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) + (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_PTHREAD_GETNAME_NP \ (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_TLS_GET_ADDR \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) + (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS) #define SANITIZER_INTERCEPT_LISTXATTR SI_LINUX #define SANITIZER_INTERCEPT_GETXATTR SI_LINUX #define SANITIZER_INTERCEPT_GETRESID SI_LINUX -#define SANITIZER_INTERCEPT_GETIFADDRS \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_LINUX_NOT_ANDROID || SI_MAC || \ - SI_SOLARIS) -#define SANITIZER_INTERCEPT_IF_INDEXTONAME \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_LINUX_NOT_ANDROID || SI_MAC || \ - SI_SOLARIS) +#define SANITIZER_INTERCEPT_GETIFADDRS \ + (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_MAC || SI_SOLARIS) +#define SANITIZER_INTERCEPT_IF_INDEXTONAME \ + (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_MAC || SI_SOLARIS) #define SANITIZER_INTERCEPT_CAPGET SI_LINUX_NOT_ANDROID #if SI_LINUX && defined(__arm__) #define SANITIZER_INTERCEPT_AEABI_MEM 1 @@ -440,29 +421,27 @@ #endif #define SANITIZER_INTERCEPT___BZERO SI_MAC || SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_BZERO SI_LINUX_NOT_ANDROID -#define SANITIZER_INTERCEPT_FTIME \ - (!SI_FREEBSD && !SI_NETBSD && !SI_OPENBSD && SI_POSIX) +#define SANITIZER_INTERCEPT_FTIME (!SI_FREEBSD && !SI_NETBSD && SI_POSIX) #define SANITIZER_INTERCEPT_XDR SI_LINUX_NOT_ANDROID || SI_SOLARIS #define SANITIZER_INTERCEPT_XDRREC SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_TSEARCH \ - (SI_LINUX_NOT_ANDROID || SI_MAC || SI_NETBSD || SI_OPENBSD || SI_SOLARIS) + (SI_LINUX_NOT_ANDROID || SI_MAC || SI_NETBSD || SI_SOLARIS) #define SANITIZER_INTERCEPT_LIBIO_INTERNALS SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_FOPEN SI_POSIX #define SANITIZER_INTERCEPT_FOPEN64 SI_LINUX_NOT_ANDROID || SI_SOLARIS32 #define SANITIZER_INTERCEPT_OPEN_MEMSTREAM \ - (SI_LINUX_NOT_ANDROID || SI_NETBSD || SI_OPENBSD || SI_SOLARIS) + (SI_LINUX_NOT_ANDROID || SI_NETBSD || SI_SOLARIS) #define SANITIZER_INTERCEPT_OBSTACK SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_FFLUSH SI_POSIX #define SANITIZER_INTERCEPT_FCLOSE SI_POSIX #ifndef SANITIZER_INTERCEPT_DLOPEN_DLCLOSE -#define SANITIZER_INTERCEPT_DLOPEN_DLCLOSE \ - (SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_LINUX_NOT_ANDROID || SI_MAC || \ - SI_SOLARIS) +#define SANITIZER_INTERCEPT_DLOPEN_DLCLOSE \ + (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID || SI_MAC || SI_SOLARIS) #endif #define SANITIZER_INTERCEPT_GETPASS \ - (SI_LINUX_NOT_ANDROID || SI_MAC || SI_NETBSD || SI_OPENBSD) + (SI_LINUX_NOT_ANDROID || SI_MAC || SI_NETBSD) #define SANITIZER_INTERCEPT_TIMERFD SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_MLOCKX SI_POSIX @@ -470,11 +449,10 @@ #define SANITIZER_INTERCEPT_SEM \ (SI_LINUX || SI_FREEBSD || SI_NETBSD || SI_SOLARIS) #define SANITIZER_INTERCEPT_PTHREAD_SETCANCEL SI_POSIX -#define SANITIZER_INTERCEPT_MINCORE \ - (SI_LINUX || SI_NETBSD || SI_OPENBSD || SI_SOLARIS) +#define SANITIZER_INTERCEPT_MINCORE (SI_LINUX || SI_NETBSD || SI_SOLARIS) #define SANITIZER_INTERCEPT_PROCESS_VM_READV SI_LINUX #define SANITIZER_INTERCEPT_CTERMID \ - (SI_LINUX || SI_MAC || SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_SOLARIS) + (SI_LINUX || SI_MAC || SI_FREEBSD || SI_NETBSD || SI_SOLARIS) #define SANITIZER_INTERCEPT_CTERMID_R (SI_MAC || SI_FREEBSD || SI_SOLARIS) #define SANITIZER_INTERCEPTOR_HOOKS \ @@ -484,7 +462,7 @@ #define SANITIZER_INTERCEPT_EVENTFD_READ_WRITE SI_LINUX #define SANITIZER_INTERCEPT_STAT \ - (SI_FREEBSD || SI_MAC || SI_ANDROID || SI_NETBSD || SI_OPENBSD || SI_SOLARIS) + (SI_FREEBSD || SI_MAC || SI_ANDROID || SI_NETBSD || SI_SOLARIS) #define SANITIZER_INTERCEPT_LSTAT (SI_NETBSD || SI_FREEBSD) #define SANITIZER_INTERCEPT___XSTAT (!SANITIZER_INTERCEPT_STAT && SI_POSIX) #define SANITIZER_INTERCEPT___XSTAT64 SI_LINUX_NOT_ANDROID @@ -497,41 +475,43 @@ (SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD || SI_NETBSD) #define SANITIZER_INTERCEPT_GETLOADAVG \ - (SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD || SI_NETBSD || SI_OPENBSD) + (SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD || SI_NETBSD) #define SANITIZER_INTERCEPT_MMAP SI_POSIX #define SANITIZER_INTERCEPT_MMAP64 SI_LINUX_NOT_ANDROID -#define SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO \ - (!SI_FREEBSD && !SI_MAC && !SI_NETBSD && !SI_OPENBSD && SI_NOT_FUCHSIA && \ - SI_NOT_RTEMS && !SI_SOLARIS) // NOLINT +#define SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO \ + (!SI_FREEBSD && !SI_MAC && !SI_NETBSD && SI_NOT_FUCHSIA && SI_NOT_RTEMS && \ + !SI_SOLARIS) // NOLINT #define SANITIZER_INTERCEPT_MEMALIGN \ - (!SI_FREEBSD && !SI_MAC && !SI_NETBSD && !SI_OPENBSD && SI_NOT_RTEMS) -#define SANITIZER_INTERCEPT_PVALLOC \ - (!SI_FREEBSD && !SI_MAC && !SI_NETBSD && !SI_OPENBSD && SI_NOT_FUCHSIA && \ - SI_NOT_RTEMS && !SI_SOLARIS) // NOLINT -#define SANITIZER_INTERCEPT_CFREE \ - (!SI_FREEBSD && !SI_MAC && !SI_NETBSD && !SI_OPENBSD && SI_NOT_FUCHSIA && \ - SI_NOT_RTEMS && !SI_SOLARIS) // NOLINT + (!SI_FREEBSD && !SI_MAC && !SI_NETBSD && SI_NOT_RTEMS) +#define SANITIZER_INTERCEPT___LIBC_MEMALIGN \ + (!SI_FREEBSD && !SI_MAC && !SI_NETBSD && !SI_OPENBSD && SI_NOT_RTEMS && \ + !SI_ANDROID) // NOLINT +#define SANITIZER_INTERCEPT_PVALLOC \ + (!SI_FREEBSD && !SI_MAC && !SI_NETBSD && SI_NOT_FUCHSIA && SI_NOT_RTEMS && \ + !SI_SOLARIS) // NOLINT +#define SANITIZER_INTERCEPT_CFREE \ + (!SI_FREEBSD && !SI_MAC && !SI_NETBSD && SI_NOT_FUCHSIA && SI_NOT_RTEMS && \ + !SI_SOLARIS && !SANITIZER_ANDROID) // NOLINT #define SANITIZER_INTERCEPT_REALLOCARRAY SI_POSIX #define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!SI_MAC && SI_NOT_RTEMS) -#define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE \ - (!SI_MAC && !SI_OPENBSD && !SI_NETBSD) +#define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!SI_MAC && !SI_NETBSD) #define SANITIZER_INTERCEPT_MCHECK_MPROBE SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_WCSCAT SI_POSIX #define SANITIZER_INTERCEPT_WCSDUP SI_POSIX #define SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION (!SI_WINDOWS && SI_NOT_FUCHSIA) #define SANITIZER_INTERCEPT_BSD_SIGNAL SI_ANDROID -#define SANITIZER_INTERCEPT_ACCT (SI_NETBSD || SI_OPENBSD || SI_FREEBSD) +#define SANITIZER_INTERCEPT_ACCT (SI_NETBSD || SI_FREEBSD) #define SANITIZER_INTERCEPT_USER_FROM_UID SI_NETBSD #define SANITIZER_INTERCEPT_UID_FROM_USER SI_NETBSD #define SANITIZER_INTERCEPT_GROUP_FROM_GID SI_NETBSD #define SANITIZER_INTERCEPT_GID_FROM_GROUP SI_NETBSD -#define SANITIZER_INTERCEPT_ACCESS (SI_NETBSD || SI_OPENBSD || SI_FREEBSD) -#define SANITIZER_INTERCEPT_FACCESSAT (SI_NETBSD || SI_OPENBSD || SI_FREEBSD) -#define SANITIZER_INTERCEPT_GETGROUPLIST (SI_NETBSD || SI_OPENBSD) -#define SANITIZER_INTERCEPT_STRLCPY \ - (SI_NETBSD || SI_FREEBSD || SI_OPENBSD || SI_MAC || SI_ANDROID) +#define SANITIZER_INTERCEPT_ACCESS (SI_NETBSD || SI_FREEBSD) +#define SANITIZER_INTERCEPT_FACCESSAT (SI_NETBSD || SI_FREEBSD) +#define SANITIZER_INTERCEPT_GETGROUPLIST SI_NETBSD +#define SANITIZER_INTERCEPT_STRLCPY \ + (SI_NETBSD || SI_FREEBSD || SI_MAC || SI_ANDROID) #define SANITIZER_INTERCEPT_NAME_TO_HANDLE_AT SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_OPEN_BY_HANDLE_AT SI_LINUX_NOT_ANDROID @@ -539,14 +519,14 @@ #define SANITIZER_INTERCEPT_READLINK SI_POSIX #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101000 -# define SI_MAC_DEPLOYMENT_BELOW_10_10 1 +#define SI_MAC_DEPLOYMENT_BELOW_10_10 1 #else -# define SI_MAC_DEPLOYMENT_BELOW_10_10 0 +#define SI_MAC_DEPLOYMENT_BELOW_10_10 0 #endif #define SANITIZER_INTERCEPT_READLINKAT \ (SI_POSIX && !SI_MAC_DEPLOYMENT_BELOW_10_10) -#define SANITIZER_INTERCEPT_DEVNAME (SI_NETBSD || SI_OPENBSD || SI_FREEBSD) +#define SANITIZER_INTERCEPT_DEVNAME (SI_NETBSD || SI_FREEBSD) #define SANITIZER_INTERCEPT_DEVNAME_R (SI_NETBSD || SI_FREEBSD) #define SANITIZER_INTERCEPT_FGETLN (SI_NETBSD || SI_FREEBSD) #define SANITIZER_INTERCEPT_STRMODE (SI_NETBSD || SI_FREEBSD) @@ -554,8 +534,8 @@ #define SANITIZER_INTERCEPT_PROTOENT (SI_NETBSD || SI_LINUX) #define SANITIZER_INTERCEPT_PROTOENT_R (SI_LINUX_NOT_ANDROID) #define SANITIZER_INTERCEPT_NETENT SI_NETBSD -#define SANITIZER_INTERCEPT_SETVBUF (SI_NETBSD || SI_FREEBSD || \ - SI_LINUX || SI_MAC) +#define SANITIZER_INTERCEPT_SETVBUF \ + (SI_NETBSD || SI_FREEBSD || SI_LINUX || SI_MAC) #define SANITIZER_INTERCEPT_GETMNTINFO (SI_NETBSD || SI_FREEBSD || SI_MAC) #define SANITIZER_INTERCEPT_MI_VECTOR_HASH SI_NETBSD #define SANITIZER_INTERCEPT_GETVFSSTAT SI_NETBSD diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp b/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp index f22f5039128..c51327e1269 100644 --- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp @@ -26,12 +26,9 @@ // With old kernels (and even new kernels on powerpc) asm/stat.h uses types that // are not defined anywhere in userspace headers. Fake them. This seems to work -// fine with newer headers, too. Beware that with , struct stat -// takes the form of struct stat64 on 32-bit platforms if _FILE_OFFSET_BITS=64. -// Also, for some platforms (e.g. mips) there are additional members in the -// struct stat:s. +// fine with newer headers, too. #include -#if defined(__x86_64__) +#if defined(__x86_64__) || defined(__mips__) #include #else #define ino_t __kernel_ino_t diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_openbsd.cpp b/libsanitizer/sanitizer_common/sanitizer_platform_limits_openbsd.cpp index 1420ecbfa56..e69de29bb2d 100644 --- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_openbsd.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_openbsd.cpp @@ -1,279 +0,0 @@ -//===-- sanitizer_platform_limits_openbsd.cpp -----------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file is a part of Sanitizer common code. -// -// Sizes and layouts of platform-specific NetBSD data structures. -//===----------------------------------------------------------------------===// - -#include "sanitizer_platform.h" - -#if SANITIZER_OPENBSD -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Include these after system headers to avoid name clashes and ambiguities. -#include "sanitizer_internal_defs.h" -#include "sanitizer_platform_limits_openbsd.h" - -namespace __sanitizer { -unsigned struct_utsname_sz = sizeof(struct utsname); -unsigned struct_stat_sz = sizeof(struct stat); -unsigned struct_rusage_sz = sizeof(struct rusage); -unsigned struct_tm_sz = sizeof(struct tm); -unsigned struct_passwd_sz = sizeof(struct passwd); -unsigned struct_group_sz = sizeof(struct group); -unsigned siginfo_t_sz = sizeof(siginfo_t); -unsigned struct_sigaction_sz = sizeof(struct sigaction); -unsigned struct_stack_t_sz = sizeof(stack_t); -unsigned struct_itimerval_sz = sizeof(struct itimerval); -unsigned pthread_t_sz = sizeof(pthread_t); -unsigned pthread_mutex_t_sz = sizeof(pthread_mutex_t); -unsigned pthread_cond_t_sz = sizeof(pthread_cond_t); -unsigned pid_t_sz = sizeof(pid_t); -unsigned timeval_sz = sizeof(timeval); -unsigned uid_t_sz = sizeof(uid_t); -unsigned gid_t_sz = sizeof(gid_t); -unsigned mbstate_t_sz = sizeof(mbstate_t); -unsigned sigset_t_sz = sizeof(sigset_t); -unsigned struct_timezone_sz = sizeof(struct timezone); -unsigned struct_tms_sz = sizeof(struct tms); -unsigned struct_sched_param_sz = sizeof(struct sched_param); -unsigned struct_sockaddr_sz = sizeof(struct sockaddr); -unsigned struct_rlimit_sz = sizeof(struct rlimit); -unsigned struct_timespec_sz = sizeof(struct timespec); -unsigned struct_utimbuf_sz = sizeof(struct utimbuf); -unsigned struct_itimerspec_sz = sizeof(struct itimerspec); -unsigned struct_msqid_ds_sz = sizeof(struct msqid_ds); -unsigned struct_statvfs_sz = sizeof(struct statvfs); - -const uptr sig_ign = (uptr)SIG_IGN; -const uptr sig_dfl = (uptr)SIG_DFL; -const uptr sig_err = (uptr)SIG_ERR; -const uptr sa_siginfo = (uptr)SA_SIGINFO; - -int shmctl_ipc_stat = (int)IPC_STAT; - -unsigned struct_utmp_sz = sizeof(struct utmp); - -int map_fixed = MAP_FIXED; - -int af_inet = (int)AF_INET; -int af_inet6 = (int)AF_INET6; - -uptr __sanitizer_in_addr_sz(int af) { - if (af == AF_INET) - return sizeof(struct in_addr); - else if (af == AF_INET6) - return sizeof(struct in6_addr); - else - return 0; -} - -unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); - -int glob_nomatch = GLOB_NOMATCH; -int glob_altdirfunc = GLOB_ALTDIRFUNC; - -unsigned path_max = PATH_MAX; - -const int si_SEGV_MAPERR = SEGV_MAPERR; -const int si_SEGV_ACCERR = SEGV_ACCERR; -} // namespace __sanitizer - -using namespace __sanitizer; - -COMPILER_CHECK(sizeof(__sanitizer_pthread_attr_t) >= sizeof(pthread_attr_t)); - -COMPILER_CHECK(sizeof(socklen_t) == sizeof(unsigned)); -CHECK_TYPE_SIZE(pthread_key_t); - -CHECK_TYPE_SIZE(dl_phdr_info); -CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_addr); -CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_name); -CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phdr); -CHECK_SIZE_AND_OFFSET(dl_phdr_info, dlpi_phnum); - -CHECK_TYPE_SIZE(glob_t); -CHECK_SIZE_AND_OFFSET(glob_t, gl_pathc); -CHECK_SIZE_AND_OFFSET(glob_t, gl_pathv); -CHECK_SIZE_AND_OFFSET(glob_t, gl_offs); -CHECK_SIZE_AND_OFFSET(glob_t, gl_flags); -CHECK_SIZE_AND_OFFSET(glob_t, gl_closedir); -CHECK_SIZE_AND_OFFSET(glob_t, gl_readdir); -CHECK_SIZE_AND_OFFSET(glob_t, gl_opendir); -CHECK_SIZE_AND_OFFSET(glob_t, gl_lstat); -CHECK_SIZE_AND_OFFSET(glob_t, gl_stat); - -CHECK_TYPE_SIZE(addrinfo); -CHECK_SIZE_AND_OFFSET(addrinfo, ai_flags); -CHECK_SIZE_AND_OFFSET(addrinfo, ai_family); -CHECK_SIZE_AND_OFFSET(addrinfo, ai_socktype); -CHECK_SIZE_AND_OFFSET(addrinfo, ai_protocol); -CHECK_SIZE_AND_OFFSET(addrinfo, ai_addrlen); -CHECK_SIZE_AND_OFFSET(addrinfo, ai_addr); -CHECK_SIZE_AND_OFFSET(addrinfo, ai_canonname); -CHECK_SIZE_AND_OFFSET(addrinfo, ai_next); - -CHECK_TYPE_SIZE(hostent); -CHECK_SIZE_AND_OFFSET(hostent, h_name); -CHECK_SIZE_AND_OFFSET(hostent, h_aliases); -CHECK_SIZE_AND_OFFSET(hostent, h_addrtype); -CHECK_SIZE_AND_OFFSET(hostent, h_length); -CHECK_SIZE_AND_OFFSET(hostent, h_addr_list); - -CHECK_TYPE_SIZE(iovec); -CHECK_SIZE_AND_OFFSET(iovec, iov_base); -CHECK_SIZE_AND_OFFSET(iovec, iov_len); - -CHECK_TYPE_SIZE(msghdr); -CHECK_SIZE_AND_OFFSET(msghdr, msg_name); -CHECK_SIZE_AND_OFFSET(msghdr, msg_namelen); -CHECK_SIZE_AND_OFFSET(msghdr, msg_iov); -CHECK_SIZE_AND_OFFSET(msghdr, msg_iovlen); -CHECK_SIZE_AND_OFFSET(msghdr, msg_control); -CHECK_SIZE_AND_OFFSET(msghdr, msg_controllen); -CHECK_SIZE_AND_OFFSET(msghdr, msg_flags); - -CHECK_TYPE_SIZE(cmsghdr); -CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_len); -CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_level); -CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_type); - -COMPILER_CHECK(sizeof(__sanitizer_dirent) <= sizeof(dirent)); -CHECK_SIZE_AND_OFFSET(dirent, d_fileno); -CHECK_SIZE_AND_OFFSET(dirent, d_off); -CHECK_SIZE_AND_OFFSET(dirent, d_reclen); - -CHECK_TYPE_SIZE(ifconf); -CHECK_SIZE_AND_OFFSET(ifconf, ifc_len); -CHECK_SIZE_AND_OFFSET(ifconf, ifc_ifcu); - -CHECK_TYPE_SIZE(pollfd); -CHECK_SIZE_AND_OFFSET(pollfd, fd); -CHECK_SIZE_AND_OFFSET(pollfd, events); -CHECK_SIZE_AND_OFFSET(pollfd, revents); - -CHECK_TYPE_SIZE(nfds_t); - -CHECK_TYPE_SIZE(sigset_t); - -COMPILER_CHECK(sizeof(__sanitizer_sigaction) == sizeof(struct sigaction)); -// Can't write checks for sa_handler and sa_sigaction due to them being -// preprocessor macros. -CHECK_STRUCT_SIZE_AND_OFFSET(sigaction, sa_mask); - -CHECK_TYPE_SIZE(tm); -CHECK_SIZE_AND_OFFSET(tm, tm_sec); -CHECK_SIZE_AND_OFFSET(tm, tm_min); -CHECK_SIZE_AND_OFFSET(tm, tm_hour); -CHECK_SIZE_AND_OFFSET(tm, tm_mday); -CHECK_SIZE_AND_OFFSET(tm, tm_mon); -CHECK_SIZE_AND_OFFSET(tm, tm_year); -CHECK_SIZE_AND_OFFSET(tm, tm_wday); -CHECK_SIZE_AND_OFFSET(tm, tm_yday); -CHECK_SIZE_AND_OFFSET(tm, tm_isdst); -CHECK_SIZE_AND_OFFSET(tm, tm_gmtoff); -CHECK_SIZE_AND_OFFSET(tm, tm_zone); - -CHECK_TYPE_SIZE(ipc_perm); -CHECK_SIZE_AND_OFFSET(ipc_perm, cuid); -CHECK_SIZE_AND_OFFSET(ipc_perm, cgid); -CHECK_SIZE_AND_OFFSET(ipc_perm, uid); -CHECK_SIZE_AND_OFFSET(ipc_perm, gid); -CHECK_SIZE_AND_OFFSET(ipc_perm, mode); -CHECK_SIZE_AND_OFFSET(ipc_perm, seq); -CHECK_SIZE_AND_OFFSET(ipc_perm, key); - -CHECK_TYPE_SIZE(shmid_ds); -CHECK_SIZE_AND_OFFSET(shmid_ds, shm_perm); -CHECK_SIZE_AND_OFFSET(shmid_ds, shm_segsz); -CHECK_SIZE_AND_OFFSET(shmid_ds, shm_atime); -CHECK_SIZE_AND_OFFSET(shmid_ds, __shm_atimensec); -CHECK_SIZE_AND_OFFSET(shmid_ds, shm_dtime); -CHECK_SIZE_AND_OFFSET(shmid_ds, __shm_dtimensec); -CHECK_SIZE_AND_OFFSET(shmid_ds, shm_ctime); -CHECK_SIZE_AND_OFFSET(shmid_ds, __shm_ctimensec); -CHECK_SIZE_AND_OFFSET(shmid_ds, shm_cpid); -CHECK_SIZE_AND_OFFSET(shmid_ds, shm_lpid); -CHECK_SIZE_AND_OFFSET(shmid_ds, shm_nattch); - -CHECK_TYPE_SIZE(clock_t); - -CHECK_TYPE_SIZE(ifaddrs); -CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_next); -CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_name); -CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_addr); -CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_netmask); -// Compare against the union, because we can't reach into the union in a -// compliant way. -#ifdef ifa_dstaddr -#undef ifa_dstaddr -#endif -CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_dstaddr); -CHECK_SIZE_AND_OFFSET(ifaddrs, ifa_data); - -CHECK_TYPE_SIZE(passwd); -CHECK_SIZE_AND_OFFSET(passwd, pw_name); -CHECK_SIZE_AND_OFFSET(passwd, pw_passwd); -CHECK_SIZE_AND_OFFSET(passwd, pw_uid); -CHECK_SIZE_AND_OFFSET(passwd, pw_gid); -CHECK_SIZE_AND_OFFSET(passwd, pw_dir); -CHECK_SIZE_AND_OFFSET(passwd, pw_shell); - -CHECK_SIZE_AND_OFFSET(passwd, pw_gecos); - -CHECK_TYPE_SIZE(group); -CHECK_SIZE_AND_OFFSET(group, gr_name); -CHECK_SIZE_AND_OFFSET(group, gr_passwd); -CHECK_SIZE_AND_OFFSET(group, gr_gid); -CHECK_SIZE_AND_OFFSET(group, gr_mem); - -#endif // SANITIZER_OPENBSD diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_openbsd.h b/libsanitizer/sanitizer_common/sanitizer_platform_limits_openbsd.h index 8a194872360..e69de29bb2d 100644 --- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_openbsd.h +++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_openbsd.h @@ -1,382 +0,0 @@ -//===-- sanitizer_platform_limits_openbsd.h -------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file is a part of Sanitizer common code. -// -// Sizes and layouts of platform-specific OpenBSD data structures. -//===----------------------------------------------------------------------===// - -#ifndef SANITIZER_PLATFORM_LIMITS_OPENBSD_H -#define SANITIZER_PLATFORM_LIMITS_OPENBSD_H - -#if SANITIZER_OPENBSD - -#include "sanitizer_internal_defs.h" -#include "sanitizer_platform.h" - -#define _GET_LINK_MAP_BY_DLOPEN_HANDLE(handle, shift) \ - ((link_map *)((handle) == nullptr ? nullptr : ((char *)(handle) + (shift)))) - -#if defined(__x86_64__) -#define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \ - _GET_LINK_MAP_BY_DLOPEN_HANDLE(handle, 312) -#elif defined(__i386__) -#define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \ - _GET_LINK_MAP_BY_DLOPEN_HANDLE(handle, 164) -#endif - -#define RLIMIT_AS RLIMIT_DATA - -namespace __sanitizer { -extern unsigned struct_utsname_sz; -extern unsigned struct_stat_sz; -extern unsigned struct_rusage_sz; -extern unsigned siginfo_t_sz; -extern unsigned struct_itimerval_sz; -extern unsigned pthread_t_sz; -extern unsigned pthread_mutex_t_sz; -extern unsigned pthread_cond_t_sz; -extern unsigned pid_t_sz; -extern unsigned timeval_sz; -extern unsigned uid_t_sz; -extern unsigned gid_t_sz; -extern unsigned mbstate_t_sz; -extern unsigned struct_timezone_sz; -extern unsigned struct_tms_sz; -extern unsigned struct_itimerspec_sz; -extern unsigned struct_sigevent_sz; -extern unsigned struct_stack_t_sz; -extern unsigned struct_statfs_sz; -extern unsigned struct_sockaddr_sz; - -extern unsigned struct_rlimit_sz; -extern unsigned struct_utimbuf_sz; -extern unsigned struct_timespec_sz; - -struct __sanitizer_iocb { - u64 aio_offset; - uptr aio_buf; - long aio_nbytes; - u32 aio_fildes; - u32 aio_lio_opcode; - long aio_reqprio; -#if SANITIZER_WORDSIZE == 64 - u8 aio_sigevent[32]; -#else - u8 aio_sigevent[20]; -#endif - u32 _state; - u32 _errno; - long _retval; -}; - -struct __sanitizer___sysctl_args { - int *name; - int nlen; - void *oldval; - uptr *oldlenp; - void *newval; - uptr newlen; -}; - -struct __sanitizer_sem_t { - uptr data[5]; -}; - -struct __sanitizer_ipc_perm { - u32 cuid; - u32 cgid; - u32 uid; - u32 gid; - u32 mode; - unsigned short seq; - long key; -}; - -struct __sanitizer_shmid_ds { - __sanitizer_ipc_perm shm_perm; - int shm_segsz; - u32 shm_lpid; - u32 shm_cpid; - short shm_nattch; - u64 shm_atime; - long __shm_atimensec; - u64 shm_dtime; - long __shm_dtimensec; - u64 shm_ctime; - long __shm_ctimensec; - void *_shm_internal; -}; - -extern unsigned struct_msqid_ds_sz; -extern unsigned struct_mq_attr_sz; -extern unsigned struct_timex_sz; -extern unsigned struct_statvfs_sz; - -struct __sanitizer_iovec { - void *iov_base; - uptr iov_len; -}; - -struct __sanitizer_ifaddrs { - struct __sanitizer_ifaddrs *ifa_next; - char *ifa_name; - unsigned int ifa_flags; - struct __sanitizer_sockaddr *ifa_addr; // (struct sockaddr *) - struct __sanitizer_sockaddr *ifa_netmask; // (struct sockaddr *) - struct __sanitizer_sockaddr *ifa_dstaddr; // (struct sockaddr *) - void *ifa_data; -}; - -typedef unsigned __sanitizer_pthread_key_t; - -typedef long long __sanitizer_time_t; -typedef int __sanitizer_suseconds_t; - -struct __sanitizer_timeval { - __sanitizer_time_t tv_sec; - __sanitizer_suseconds_t tv_usec; -}; - -struct __sanitizer_itimerval { - struct __sanitizer_timeval it_interval; - struct __sanitizer_timeval it_value; -}; - -struct __sanitizer_passwd { - char *pw_name; - char *pw_passwd; - int pw_uid; - int pw_gid; - __sanitizer_time_t pw_change; - char *pw_class; - char *pw_gecos; - char *pw_dir; - char *pw_shell; - __sanitizer_time_t pw_expire; -}; - -struct __sanitizer_group { - char *gr_name; - char *gr_passwd; - int gr_gid; - char **gr_mem; -}; - -struct __sanitizer_ether_addr { - u8 octet[6]; -}; - -struct __sanitizer_tm { - int tm_sec; - int tm_min; - int tm_hour; - int tm_mday; - int tm_mon; - int tm_year; - int tm_wday; - int tm_yday; - int tm_isdst; - long int tm_gmtoff; - const char *tm_zone; -}; - -struct __sanitizer_msghdr { - void *msg_name; - unsigned msg_namelen; - struct __sanitizer_iovec *msg_iov; - unsigned msg_iovlen; - void *msg_control; - unsigned msg_controllen; - int msg_flags; -}; -struct __sanitizer_cmsghdr { - unsigned cmsg_len; - int cmsg_level; - int cmsg_type; -}; - -struct __sanitizer_dirent { - u64 d_fileno; - u64 d_off; - u16 d_reclen; -}; - -typedef u64 __sanitizer_clock_t; -typedef u32 __sanitizer_clockid_t; - -typedef u32 __sanitizer___kernel_uid_t; -typedef u32 __sanitizer___kernel_gid_t; -typedef u64 __sanitizer___kernel_off_t; -typedef struct { - u32 fds_bits[8]; -} __sanitizer___kernel_fd_set; - -typedef struct { - unsigned int pta_magic; - int pta_flags; - void *pta_private; -} __sanitizer_pthread_attr_t; - -typedef unsigned int __sanitizer_sigset_t; - -struct __sanitizer_siginfo { - // The size is determined by looking at sizeof of real siginfo_t on linux. - u64 opaque[128 / sizeof(u64)]; -}; - -using __sanitizer_sighandler_ptr = void (*)(int sig); -using __sanitizer_sigactionhandler_ptr = void (*)(int sig, - __sanitizer_siginfo *siginfo, - void *uctx); - -struct __sanitizer_sigaction { - union { - __sanitizer_sighandler_ptr handler; - __sanitizer_sigactionhandler_ptr sigaction; - }; - __sanitizer_sigset_t sa_mask; - int sa_flags; -}; - -typedef __sanitizer_sigset_t __sanitizer_kernel_sigset_t; - -struct __sanitizer_kernel_sigaction_t { - union { - void (*handler)(int signo); - void (*sigaction)(int signo, void *info, void *ctx); - }; - unsigned long sa_flags; - void (*sa_restorer)(void); - __sanitizer_kernel_sigset_t sa_mask; -}; - -extern const uptr sig_ign; -extern const uptr sig_dfl; -extern const uptr sig_err; -extern const uptr sa_siginfo; - -extern int af_inet; -extern int af_inet6; -uptr __sanitizer_in_addr_sz(int af); - -struct __sanitizer_dl_phdr_info { -#if SANITIZER_WORDSIZE == 64 - u64 dlpi_addr; -#else - u32 dlpi_addr; -#endif - const char *dlpi_name; - const void *dlpi_phdr; -#if SANITIZER_WORDSIZE == 64 - u32 dlpi_phnum; -#else - u16 dlpi_phnum; -#endif -}; - -extern unsigned struct_ElfW_Phdr_sz; - -struct __sanitizer_addrinfo { - int ai_flags; - int ai_family; - int ai_socktype; - int ai_protocol; - unsigned ai_addrlen; - struct __sanitizer_sockaddr *ai_addr; - char *ai_canonname; - struct __sanitizer_addrinfo *ai_next; -}; - -struct __sanitizer_hostent { - char *h_name; - char **h_aliases; - int h_addrtype; - int h_length; - char **h_addr_list; -}; - -struct __sanitizer_pollfd { - int fd; - short events; - short revents; -}; - -typedef unsigned __sanitizer_nfds_t; - -struct __sanitizer_glob_t { - int gl_pathc; - int gl_matchc; - int gl_offs; - int gl_flags; - char **gl_pathv; - void **gl_statv; - int (*gl_errfunc)(const char *, int); - void (*gl_closedir)(void *dirp); - struct dirent *(*gl_readdir)(void *dirp); - void *(*gl_opendir)(const char *); - int (*gl_lstat)(const char *, void * /* struct stat* */); - int (*gl_stat)(const char *, void * /* struct stat* */); -}; - -extern int glob_nomatch; -extern int glob_altdirfunc; - -extern unsigned path_max; - -typedef char __sanitizer_FILE; -#define SANITIZER_HAS_STRUCT_FILE 0 - -extern int shmctl_ipc_stat; - -// This simplifies generic code -#define struct_shminfo_sz -1 -#define struct_shm_info_sz -1 -#define shmctl_shm_stat -1 -#define shmctl_ipc_info -1 -#define shmctl_shm_info -1 - -extern unsigned struct_utmp_sz; -extern unsigned struct_utmpx_sz; - -extern int map_fixed; - -// ioctl arguments -struct __sanitizer_ifconf { - int ifc_len; - union { - void *ifcu_req; - } ifc_ifcu; -}; - -extern const int si_SEGV_MAPERR; -extern const int si_SEGV_ACCERR; -} // namespace __sanitizer - -#define CHECK_TYPE_SIZE(TYPE) \ - COMPILER_CHECK(sizeof(__sanitizer_##TYPE) == sizeof(TYPE)) - -#define CHECK_SIZE_AND_OFFSET(CLASS, MEMBER) \ - COMPILER_CHECK(sizeof(((__sanitizer_##CLASS *)NULL)->MEMBER) == \ - sizeof(((CLASS *)NULL)->MEMBER)); \ - COMPILER_CHECK(offsetof(__sanitizer_##CLASS, MEMBER) == \ - offsetof(CLASS, MEMBER)) - -// For sigaction, which is a function and struct at the same time, -// and thus requires explicit "struct" in sizeof() expression. -#define CHECK_STRUCT_SIZE_AND_OFFSET(CLASS, MEMBER) \ - COMPILER_CHECK(sizeof(((struct __sanitizer_##CLASS *)NULL)->MEMBER) == \ - sizeof(((struct CLASS *)NULL)->MEMBER)); \ - COMPILER_CHECK(offsetof(struct __sanitizer_##CLASS, MEMBER) == \ - offsetof(struct CLASS, MEMBER)) - -#define SIGACTION_SYMNAME __sigaction14 - -#endif // SANITIZER_OPENBSD - -#endif diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h index 0812039b038..e69560ee39e 100644 --- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h +++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h @@ -83,7 +83,7 @@ const unsigned struct_kernel_stat64_sz = 104; #elif defined(__mips__) const unsigned struct_kernel_stat_sz = SANITIZER_ANDROID ? FIRST_32_SECOND_64(104, 128) - : FIRST_32_SECOND_64(144, 216); + : FIRST_32_SECOND_64(160, 216); const unsigned struct_kernel_stat64_sz = 104; #elif defined(__s390__) && !defined(__s390x__) const unsigned struct_kernel_stat_sz = 64; diff --git a/libsanitizer/sanitizer_common/sanitizer_posix.cpp b/libsanitizer/sanitizer_common/sanitizer_posix.cpp index b8b75c20d9f..2e080098283 100644 --- a/libsanitizer/sanitizer_common/sanitizer_posix.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_posix.cpp @@ -239,6 +239,7 @@ bool MemoryRangeIsAvailable(uptr range_start, uptr range_end) { return true; } +#if !SANITIZER_MAC void DumpProcessMap() { MemoryMappingLayout proc_maps(/*cache_enabled*/true); const sptr kBufSize = 4095; @@ -252,6 +253,7 @@ void DumpProcessMap() { Report("End of process memory map.\n"); UnmapOrDie(filename, kBufSize); } +#endif const char *GetPwd() { return GetEnv("PWD"); diff --git a/libsanitizer/sanitizer_common/sanitizer_posix.h b/libsanitizer/sanitizer_common/sanitizer_posix.h index 66bcaf4fd2e..e1a2b48e5cd 100644 --- a/libsanitizer/sanitizer_common/sanitizer_posix.h +++ b/libsanitizer/sanitizer_common/sanitizer_posix.h @@ -17,7 +17,6 @@ #include "sanitizer_internal_defs.h" #include "sanitizer_platform_limits_freebsd.h" #include "sanitizer_platform_limits_netbsd.h" -#include "sanitizer_platform_limits_openbsd.h" #include "sanitizer_platform_limits_posix.h" #include "sanitizer_platform_limits_solaris.h" diff --git a/libsanitizer/sanitizer_common/sanitizer_posix_libcdep.cpp b/libsanitizer/sanitizer_common/sanitizer_posix_libcdep.cpp index 37aaec362dd..d29438cf9db 100644 --- a/libsanitizer/sanitizer_common/sanitizer_posix_libcdep.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_posix_libcdep.cpp @@ -18,7 +18,6 @@ #include "sanitizer_common.h" #include "sanitizer_flags.h" #include "sanitizer_platform_limits_netbsd.h" -#include "sanitizer_platform_limits_openbsd.h" #include "sanitizer_platform_limits_posix.h" #include "sanitizer_platform_limits_solaris.h" #include "sanitizer_posix.h" diff --git a/libsanitizer/sanitizer_common/sanitizer_procmaps.h b/libsanitizer/sanitizer_common/sanitizer_procmaps.h index 665ed45fa93..a56640db43e 100644 --- a/libsanitizer/sanitizer_common/sanitizer_procmaps.h +++ b/libsanitizer/sanitizer_common/sanitizer_procmaps.h @@ -16,7 +16,7 @@ #include "sanitizer_platform.h" #if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \ - SANITIZER_OPENBSD || SANITIZER_MAC || SANITIZER_SOLARIS || \ + SANITIZER_MAC || SANITIZER_SOLARIS || \ SANITIZER_FUCHSIA #include "sanitizer_common.h" diff --git a/libsanitizer/sanitizer_common/sanitizer_procmaps_bsd.cpp b/libsanitizer/sanitizer_common/sanitizer_procmaps_bsd.cpp index 02ff7c0e91a..1f489b71ad9 100644 --- a/libsanitizer/sanitizer_common/sanitizer_procmaps_bsd.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_procmaps_bsd.cpp @@ -7,11 +7,11 @@ //===----------------------------------------------------------------------===// // // Information about the process mappings -// (FreeBSD, OpenBSD and NetBSD-specific parts). +// (FreeBSD and NetBSD-specific parts). //===----------------------------------------------------------------------===// #include "sanitizer_platform.h" -#if SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_OPENBSD +#if SANITIZER_FREEBSD || SANITIZER_NETBSD #include "sanitizer_common.h" #if SANITIZER_FREEBSD #include "sanitizer_freebsd.h" @@ -28,11 +28,6 @@ #endif #include -#if SANITIZER_OPENBSD -#define KVME_PROT_READ KVE_PROT_READ -#define KVME_PROT_WRITE KVE_PROT_WRITE -#define KVME_PROT_EXEC KVE_PROT_EXEC -#endif // Fix 'kinfo_vmentry' definition on FreeBSD prior v9.2 in 32-bit mode. #if SANITIZER_FREEBSD && (SANITIZER_WORDSIZE == 32) @@ -51,10 +46,6 @@ void ReadProcMaps(ProcSelfMapsBuff *proc_maps) { KERN_PROC, KERN_PROC_VMMAP, getpid() -#elif SANITIZER_OPENBSD - CTL_KERN, - KERN_PROC_VMMAP, - getpid() #elif SANITIZER_NETBSD CTL_VM, VM_PROC, @@ -71,28 +62,12 @@ void ReadProcMaps(ProcSelfMapsBuff *proc_maps) { CHECK_EQ(Err, 0); CHECK_GT(Size, 0); -#if !SANITIZER_OPENBSD size_t MmapedSize = Size * 4 / 3; void *VmMap = MmapOrDie(MmapedSize, "ReadProcMaps()"); Size = MmapedSize; Err = internal_sysctl(Mib, ARRAY_SIZE(Mib), VmMap, &Size, NULL, 0); CHECK_EQ(Err, 0); proc_maps->data = (char *)VmMap; -#else - size_t PageSize = GetPageSize(); - size_t MmapedSize = Size; - MmapedSize = ((MmapedSize - 1) / PageSize + 1) * PageSize; - char *Mem = (char *)MmapOrDie(MmapedSize, "ReadProcMaps()"); - Size = 2 * Size + 10 * sizeof(struct kinfo_vmentry); - if (Size > 0x10000) - Size = 0x10000; - Size = (Size / sizeof(struct kinfo_vmentry)) * sizeof(struct kinfo_vmentry); - Err = internal_sysctl(Mib, ARRAY_SIZE(Mib), Mem, &Size, NULL, 0); - CHECK_EQ(Err, 0); - MmapedSize = Size; - proc_maps->data = Mem; -#endif - proc_maps->mmaped_size = MmapedSize; proc_maps->len = Size; } @@ -117,13 +92,11 @@ bool MemoryMappingLayout::Next(MemoryMappedSegment *segment) { if ((VmEntry->kve_protection & KVME_PROT_EXEC) != 0) segment->protection |= kProtectionExecute; -#if !SANITIZER_OPENBSD if (segment->filename != NULL && segment->filename_size > 0) { internal_snprintf(segment->filename, Min(segment->filename_size, (uptr)PATH_MAX), "%s", VmEntry->kve_path); } -#endif #if SANITIZER_FREEBSD data_.current += VmEntry->kve_structsize; diff --git a/libsanitizer/sanitizer_common/sanitizer_procmaps_common.cpp b/libsanitizer/sanitizer_common/sanitizer_procmaps_common.cpp index e0cb47f8ca9..f2cfcffaf47 100644 --- a/libsanitizer/sanitizer_common/sanitizer_procmaps_common.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_procmaps_common.cpp @@ -12,7 +12,7 @@ #include "sanitizer_platform.h" #if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \ - SANITIZER_OPENBSD || SANITIZER_SOLARIS + SANITIZER_SOLARIS #include "sanitizer_common.h" #include "sanitizer_placement_new.h" diff --git a/libsanitizer/sanitizer_common/sanitizer_rtems.cpp b/libsanitizer/sanitizer_common/sanitizer_rtems.cpp index 29bcfcfa6f1..d58bd08fb1a 100644 --- a/libsanitizer/sanitizer_common/sanitizer_rtems.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_rtems.cpp @@ -108,8 +108,6 @@ void SetAlternateSignalStack() {} void UnsetAlternateSignalStack() {} void InitTlsSize() {} -void PrintModuleMap() {} - void SignalContext::DumpAllRegisters(void *context) {} const char *DescribeSignalOrException(int signo) { UNIMPLEMENTED(); } diff --git a/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp b/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp index b28fc1cf736..b0487d8987d 100644 --- a/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp @@ -84,8 +84,8 @@ static inline uhwptr *GetCanonicFrame(uptr bp, // Nope, this does not look right either. This means the frame after next does // not have a valid frame pointer, but we can still extract the caller PC. // Unfortunately, there is no way to decide between GCC and LLVM frame - // layouts. Assume GCC. - return bp_prev - 1; + // layouts. Assume LLVM. + return bp_prev; #else return (uhwptr*)bp; #endif @@ -108,21 +108,14 @@ void BufferedStackTrace::UnwindFast(uptr pc, uptr bp, uptr stack_top, IsAligned((uptr)frame, sizeof(*frame)) && size < max_depth) { #ifdef __powerpc__ - // PowerPC ABIs specify that the return address is saved on the - // *caller's* stack frame. Thus we must dereference the back chain - // to find the caller frame before extracting it. + // PowerPC ABIs specify that the return address is saved at offset + // 16 of the *caller's* stack frame. Thus we must dereference the + // back chain to find the caller frame before extracting it. uhwptr *caller_frame = (uhwptr*)frame[0]; if (!IsValidFrame((uptr)caller_frame, stack_top, bottom) || !IsAligned((uptr)caller_frame, sizeof(uhwptr))) break; - // For most ABIs the offset where the return address is saved is two - // register sizes. The exception is the SVR4 ABI, which uses an - // offset of only one register size. -#ifdef _CALL_SYSV - uhwptr pc1 = caller_frame[1]; -#else uhwptr pc1 = caller_frame[2]; -#endif #elif defined(__s390__) uhwptr pc1 = frame[14]; #elif defined(__riscv) diff --git a/libsanitizer/sanitizer_common/sanitizer_stacktrace.h b/libsanitizer/sanitizer_common/sanitizer_stacktrace.h index d9fd88d90a7..0350fe84b04 100644 --- a/libsanitizer/sanitizer_common/sanitizer_stacktrace.h +++ b/libsanitizer/sanitizer_common/sanitizer_stacktrace.h @@ -25,8 +25,6 @@ static const u32 kStackTraceMax = 256; # define SANITIZER_CAN_FAST_UNWIND 0 #elif SANITIZER_WINDOWS # define SANITIZER_CAN_FAST_UNWIND 0 -#elif SANITIZER_OPENBSD -# define SANITIZER_CAN_FAST_UNWIND 0 #else # define SANITIZER_CAN_FAST_UNWIND 1 #endif @@ -34,7 +32,7 @@ static const u32 kStackTraceMax = 256; // Fast unwind is the only option on Mac for now; we will need to // revisit this macro when slow unwind works on Mac, see // https://github.com/google/sanitizers/issues/137 -#if SANITIZER_MAC || SANITIZER_OPENBSD || SANITIZER_RTEMS +#if SANITIZER_MAC || SANITIZER_RTEMS # define SANITIZER_CAN_SLOW_UNWIND 0 #else # define SANITIZER_CAN_SLOW_UNWIND 1 diff --git a/libsanitizer/sanitizer_common/sanitizer_stoptheworld.h b/libsanitizer/sanitizer_common/sanitizer_stoptheworld.h index 7eb7c7684af..7891c1081fe 100644 --- a/libsanitizer/sanitizer_common/sanitizer_stoptheworld.h +++ b/libsanitizer/sanitizer_common/sanitizer_stoptheworld.h @@ -40,10 +40,13 @@ class SuspendedThreadsList { virtual uptr ThreadCount() const { UNIMPLEMENTED(); } virtual tid_t GetThreadID(uptr index) const { UNIMPLEMENTED(); } + protected: + ~SuspendedThreadsList() {} + private: // Prohibit copy and assign. - SuspendedThreadsList(const SuspendedThreadsList&); - void operator=(const SuspendedThreadsList&); + SuspendedThreadsList(const SuspendedThreadsList &) = delete; + void operator=(const SuspendedThreadsList &) = delete; }; typedef void (*StopTheWorldCallback)( diff --git a/libsanitizer/sanitizer_common/sanitizer_stoptheworld_fuchsia.cpp b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_fuchsia.cpp index 3a246443ed9..91bf19e40da 100644 --- a/libsanitizer/sanitizer_common/sanitizer_stoptheworld_fuchsia.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_fuchsia.cpp @@ -17,6 +17,7 @@ #include #include "sanitizer_stoptheworld.h" +#include "sanitizer_stoptheworld_fuchsia.h" namespace __sanitizer { @@ -32,7 +33,7 @@ void StopTheWorld(StopTheWorldCallback callback, void *argument) { nullptr, nullptr, nullptr, nullptr, [](zx_status_t, void *data) { auto params = reinterpret_cast(data); - params->callback({}, params->argument); + params->callback(SuspendedThreadsListFuchsia(), params->argument); }, ¶ms); } diff --git a/libsanitizer/sanitizer_common/sanitizer_stoptheworld_fuchsia.h b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_fuchsia.h new file mode 100644 index 00000000000..6d9ead60508 --- /dev/null +++ b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_fuchsia.h @@ -0,0 +1,20 @@ +//===-- sanitizer_stoptheworld_fuchsia.h ------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef SANITIZER_STOPTHEWORLD_FUCHSIA_H +#define SANITIZER_STOPTHEWORLD_FUCHSIA_H + +#include "sanitizer_stoptheworld.h" + +namespace __sanitizer { + +class SuspendedThreadsListFuchsia final : public SuspendedThreadsList {}; + +} // namespace __sanitizer + +#endif // SANITIZER_STOPTHEWORLD_FUCHSIA_H diff --git a/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp index eb89f1fddc5..0f1cadfeae3 100644 --- a/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp @@ -85,7 +85,7 @@ namespace __sanitizer { -class SuspendedThreadsListLinux : public SuspendedThreadsList { +class SuspendedThreadsListLinux final : public SuspendedThreadsList { public: SuspendedThreadsListLinux() { thread_ids_.reserve(1024); } diff --git a/libsanitizer/sanitizer_common/sanitizer_stoptheworld_mac.cpp b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_mac.cpp index a605d5b9ff6..5ec30803b7a 100644 --- a/libsanitizer/sanitizer_common/sanitizer_stoptheworld_mac.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_mac.cpp @@ -27,7 +27,7 @@ typedef struct { thread_t thread; } SuspendedThreadInfo; -class SuspendedThreadsListMac : public SuspendedThreadsList { +class SuspendedThreadsListMac final : public SuspendedThreadsList { public: SuspendedThreadsListMac() : threads_(1024) {} diff --git a/libsanitizer/sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp index 70df31e6351..9c7cd64255e 100644 --- a/libsanitizer/sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp @@ -48,7 +48,7 @@ namespace __sanitizer { -class SuspendedThreadsListNetBSD : public SuspendedThreadsList { +class SuspendedThreadsListNetBSD final : public SuspendedThreadsList { public: SuspendedThreadsListNetBSD() { thread_ids_.reserve(1024); } diff --git a/libsanitizer/sanitizer_common/sanitizer_symbolizer_internal.h b/libsanitizer/sanitizer_common/sanitizer_symbolizer_internal.h index e4c351e667b..71de1758b3e 100644 --- a/libsanitizer/sanitizer_common/sanitizer_symbolizer_internal.h +++ b/libsanitizer/sanitizer_common/sanitizer_symbolizer_internal.h @@ -74,6 +74,9 @@ class SymbolizerTool { // Usually this is a safe place to call code that might need to use user // memory allocators. virtual void LateInitialize() {} + + protected: + ~SymbolizerTool() {} }; // SymbolizerProcess encapsulates communication between the tool and @@ -85,6 +88,8 @@ class SymbolizerProcess { const char *SendCommand(const char *command); protected: + ~SymbolizerProcess() {} + /// The maximum number of arguments required to invoke a tool process. static const unsigned kArgVMax = 6; @@ -128,7 +133,7 @@ class LLVMSymbolizerProcess; // This tool invokes llvm-symbolizer in a subprocess. It should be as portable // as the llvm-symbolizer tool is. -class LLVMSymbolizer : public SymbolizerTool { +class LLVMSymbolizer final : public SymbolizerTool { public: explicit LLVMSymbolizer(const char *path, LowLevelAllocator *allocator); diff --git a/libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.h b/libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.h index e2a0f71420f..7b039b894b3 100644 --- a/libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.h +++ b/libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.h @@ -28,7 +28,7 @@ namespace __sanitizer { -class LibbacktraceSymbolizer : public SymbolizerTool { +class LibbacktraceSymbolizer final : public SymbolizerTool { public: static LibbacktraceSymbolizer *get(LowLevelAllocator *alloc); diff --git a/libsanitizer/sanitizer_common/sanitizer_symbolizer_libcdep.cpp b/libsanitizer/sanitizer_common/sanitizer_symbolizer_libcdep.cpp index 311d676439c..710da4c1cec 100644 --- a/libsanitizer/sanitizer_common/sanitizer_symbolizer_libcdep.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_symbolizer_libcdep.cpp @@ -237,7 +237,7 @@ const LoadedModule *Symbolizer::FindModuleForAddress(uptr address) { // :: // ... // -class LLVMSymbolizerProcess : public SymbolizerProcess { +class LLVMSymbolizerProcess final : public SymbolizerProcess { public: explicit LLVMSymbolizerProcess(const char *path) : SymbolizerProcess(path, /*use_posix_spawn=*/SANITIZER_MAC) {} diff --git a/libsanitizer/sanitizer_common/sanitizer_symbolizer_mac.cpp b/libsanitizer/sanitizer_common/sanitizer_symbolizer_mac.cpp index f0f150871d3..5c25b28b5dc 100644 --- a/libsanitizer/sanitizer_common/sanitizer_symbolizer_mac.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_symbolizer_mac.cpp @@ -65,7 +65,7 @@ bool DlAddrSymbolizer::SymbolizeData(uptr addr, DataInfo *datainfo) { // kAsanInternalHeapMagic. static char kAtosMachPortEnvEntry[] = K_ATOS_ENV_VAR "=000000000000000"; -class AtosSymbolizerProcess : public SymbolizerProcess { +class AtosSymbolizerProcess final : public SymbolizerProcess { public: explicit AtosSymbolizerProcess(const char *path) : SymbolizerProcess(path, /*use_posix_spawn*/ true) { diff --git a/libsanitizer/sanitizer_common/sanitizer_symbolizer_mac.h b/libsanitizer/sanitizer_common/sanitizer_symbolizer_mac.h index 8996131fc13..401d30fa503 100644 --- a/libsanitizer/sanitizer_common/sanitizer_symbolizer_mac.h +++ b/libsanitizer/sanitizer_common/sanitizer_symbolizer_mac.h @@ -21,7 +21,7 @@ namespace __sanitizer { -class DlAddrSymbolizer : public SymbolizerTool { +class DlAddrSymbolizer final : public SymbolizerTool { public: bool SymbolizePC(uptr addr, SymbolizedStack *stack) override; bool SymbolizeData(uptr addr, DataInfo *info) override; @@ -29,7 +29,7 @@ class DlAddrSymbolizer : public SymbolizerTool { class AtosSymbolizerProcess; -class AtosSymbolizer : public SymbolizerTool { +class AtosSymbolizer final : public SymbolizerTool { public: explicit AtosSymbolizer(const char *path, LowLevelAllocator *allocator); diff --git a/libsanitizer/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp b/libsanitizer/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp index 3c379a84802..4dd5cc3ad7c 100644 --- a/libsanitizer/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp @@ -201,7 +201,7 @@ bool SymbolizerProcess::StartSymbolizerSubprocess() { return true; } -class Addr2LineProcess : public SymbolizerProcess { +class Addr2LineProcess final : public SymbolizerProcess { public: Addr2LineProcess(const char *path, const char *module_name) : SymbolizerProcess(path), module_name_(internal_strdup(module_name)) {} @@ -261,7 +261,7 @@ bool Addr2LineProcess::ReachedEndOfOutput(const char *buffer, output_terminator_, kTerminatorLen); } -class Addr2LinePool : public SymbolizerTool { +class Addr2LinePool final : public SymbolizerTool { public: explicit Addr2LinePool(const char *addr2line_path, LowLevelAllocator *allocator) @@ -328,7 +328,7 @@ int __sanitizer_symbolize_demangle(const char *Name, char *Buffer, int MaxLength); } // extern "C" -class InternalSymbolizer : public SymbolizerTool { +class InternalSymbolizer final : public SymbolizerTool { public: static InternalSymbolizer *get(LowLevelAllocator *alloc) { if (__sanitizer_symbolize_code != 0 && @@ -387,7 +387,7 @@ class InternalSymbolizer : public SymbolizerTool { }; #else // SANITIZER_SUPPORTS_WEAK_HOOKS -class InternalSymbolizer : public SymbolizerTool { +class InternalSymbolizer final : public SymbolizerTool { public: static InternalSymbolizer *get(LowLevelAllocator *alloc) { return 0; } }; diff --git a/libsanitizer/sanitizer_common/sanitizer_symbolizer_win.cpp b/libsanitizer/sanitizer_common/sanitizer_symbolizer_win.cpp index 373437e7ee2..48fa2d1033a 100644 --- a/libsanitizer/sanitizer_common/sanitizer_symbolizer_win.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_symbolizer_win.cpp @@ -33,7 +33,7 @@ decltype(::UnDecorateSymbolName) *UnDecorateSymbolName; namespace { -class WinSymbolizerTool : public SymbolizerTool { +class WinSymbolizerTool final : public SymbolizerTool { public: // The constructor is provided to avoid synthesized memsets. WinSymbolizerTool() {} diff --git a/libsanitizer/sanitizer_common/sanitizer_syscall_generic.inc b/libsanitizer/sanitizer_common/sanitizer_syscall_generic.inc index a43ce3efab1..8829985b5b0 100644 --- a/libsanitizer/sanitizer_common/sanitizer_syscall_generic.inc +++ b/libsanitizer/sanitizer_common/sanitizer_syscall_generic.inc @@ -13,7 +13,7 @@ // NetBSD uses libc calls directly #if !SANITIZER_NETBSD -#if SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_OPENBSD || SANITIZER_SOLARIS +#if SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_SOLARIS # define SYSCALL(name) SYS_ ## name #else # define SYSCALL(name) __NR_ ## name diff --git a/libsanitizer/sanitizer_common/sanitizer_thread_registry.h b/libsanitizer/sanitizer_common/sanitizer_thread_registry.h index 493aa988f7e..85c522a31ca 100644 --- a/libsanitizer/sanitizer_common/sanitizer_thread_registry.h +++ b/libsanitizer/sanitizer_common/sanitizer_thread_registry.h @@ -39,8 +39,6 @@ enum class ThreadType { class ThreadContextBase { public: explicit ThreadContextBase(u32 tid); - ~ThreadContextBase(); // Should never be called. - const u32 tid; // Thread ID. Main thread should have tid = 0. u64 unique_id; // Unique thread ID. u32 reuse_count; // Number of times this tid was reused. @@ -80,6 +78,9 @@ class ThreadContextBase { virtual void OnCreated(void *arg) {} virtual void OnReset() {} virtual void OnDetached(void *arg) {} + + protected: + ~ThreadContextBase(); }; typedef ThreadContextBase* (*ThreadContextFactory)(u32 tid); diff --git a/libsanitizer/sanitizer_common/sanitizer_tls_get_addr.cpp b/libsanitizer/sanitizer_common/sanitizer_tls_get_addr.cpp index 9ca898a306a..10748f96420 100644 --- a/libsanitizer/sanitizer_common/sanitizer_tls_get_addr.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_tls_get_addr.cpp @@ -80,8 +80,13 @@ void DTLS_Destroy() { #if defined(__powerpc64__) || defined(__mips__) // This is glibc's TLS_DTV_OFFSET: // "Dynamic thread vector pointers point 0x8000 past the start of each -// TLS block." +// TLS block." (sysdeps//dl-tls.h) static const uptr kDtvOffset = 0x8000; +#elif defined(__riscv) +// This is glibc's TLS_DTV_OFFSET: +// "Dynamic thread vector pointers point 0x800 past the start of each +// TLS block." (sysdeps/riscv/dl-tls.h) +static const uptr kDtvOffset = 0x800; #else static const uptr kDtvOffset = 0; #endif diff --git a/libsanitizer/sanitizer_common/sanitizer_unwind_win.cpp b/libsanitizer/sanitizer_common/sanitizer_unwind_win.cpp index 8e06940685d..e2edf428004 100644 --- a/libsanitizer/sanitizer_common/sanitizer_unwind_win.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_unwind_win.cpp @@ -37,6 +37,10 @@ void BufferedStackTrace::UnwindSlow(uptr pc, u32 max_depth) { // Skip the RTL frames by searching for the PC in the stacktrace. uptr pc_location = LocatePcInTrace(pc); PopStackFrames(pc_location); + + // Replace the first frame with the PC because the frame in the + // stacktrace might be incorrect. + trace_buffer[0] = pc; } void BufferedStackTrace::UnwindSlow(uptr pc, void *context, u32 max_depth) { diff --git a/libsanitizer/sanitizer_common/sanitizer_win.cpp b/libsanitizer/sanitizer_common/sanitizer_win.cpp index 53a537d3984..85ac2633bde 100644 --- a/libsanitizer/sanitizer_common/sanitizer_win.cpp +++ b/libsanitizer/sanitizer_common/sanitizer_win.cpp @@ -491,8 +491,6 @@ void DumpProcessMap() { } #endif -void PrintModuleMap() { } - void DisableCoreDumperIfNecessary() { // Do nothing. } @@ -1140,6 +1138,8 @@ void LogFullErrorReport(const char *buffer) { } #endif // SANITIZER_WIN_TRACE +void InitializePlatformCommonFlags(CommonFlags *cf) {} + } // namespace __sanitizer #endif // _WIN32 diff --git a/libsanitizer/tsan/tsan_platform.h b/libsanitizer/tsan/tsan_platform.h index 7256d64e507..16169cab666 100644 --- a/libsanitizer/tsan/tsan_platform.h +++ b/libsanitizer/tsan/tsan_platform.h @@ -461,7 +461,7 @@ struct Mapping47 { #elif SANITIZER_GO && defined(__aarch64__) -/* Go on linux/aarch64 (48-bit VMA) +/* Go on linux/aarch64 (48-bit VMA) and darwin/aarch64 (47-bit VMA) 0000 0000 1000 - 0000 1000 0000: executable 0000 1000 0000 - 00c0 0000 0000: - 00c0 0000 0000 - 00e0 0000 0000: heap @@ -488,6 +488,30 @@ struct Mapping { // Indicates the runtime will define the memory regions at runtime. #define TSAN_RUNTIME_VMA 1 +#elif SANITIZER_GO && defined(__mips64) +/* +Go on linux/mips64 (47-bit VMA) +0000 0000 1000 - 0000 1000 0000: executable +0000 1000 0000 - 00c0 0000 0000: - +00c0 0000 0000 - 00e0 0000 0000: heap +00e0 0000 0000 - 2000 0000 0000: - +2000 0000 0000 - 3000 0000 0000: shadow +3000 0000 0000 - 3000 0000 0000: - +3000 0000 0000 - 4000 0000 0000: metainfo (memory blocks and sync objects) +4000 0000 0000 - 6000 0000 0000: - +6000 0000 0000 - 6200 0000 0000: traces +6200 0000 0000 - 8000 0000 0000: - +*/ +struct Mapping { + static const uptr kMetaShadowBeg = 0x300000000000ull; + static const uptr kMetaShadowEnd = 0x400000000000ull; + static const uptr kTraceMemBeg = 0x600000000000ull; + static const uptr kTraceMemEnd = 0x620000000000ull; + static const uptr kShadowBeg = 0x200000000000ull; + static const uptr kShadowEnd = 0x300000000000ull; + static const uptr kAppMemBeg = 0x000000001000ull; + static const uptr kAppMemEnd = 0x00e000000000ull; +}; #else # error "Unknown platform" #endif diff --git a/libsanitizer/tsan/tsan_platform_linux.cpp b/libsanitizer/tsan/tsan_platform_linux.cpp index 710e7ec97b7..d136dcb1cec 100644 --- a/libsanitizer/tsan/tsan_platform_linux.cpp +++ b/libsanitizer/tsan/tsan_platform_linux.cpp @@ -12,14 +12,12 @@ //===----------------------------------------------------------------------===// #include "sanitizer_common/sanitizer_platform.h" -#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \ - SANITIZER_OPENBSD +#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD #include "sanitizer_common/sanitizer_common.h" #include "sanitizer_common/sanitizer_libc.h" #include "sanitizer_common/sanitizer_linux.h" #include "sanitizer_common/sanitizer_platform_limits_netbsd.h" -#include "sanitizer_common/sanitizer_platform_limits_openbsd.h" #include "sanitizer_common/sanitizer_platform_limits_posix.h" #include "sanitizer_common/sanitizer_posix.h" #include "sanitizer_common/sanitizer_procmaps.h" @@ -517,5 +515,4 @@ void cur_thread_finalize() { } // namespace __tsan -#endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || - // SANITIZER_OPENBSD +#endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD diff --git a/libsanitizer/tsan/tsan_platform_mac.cpp b/libsanitizer/tsan/tsan_platform_mac.cpp index eea52a34e97..ec2c5fb1621 100644 --- a/libsanitizer/tsan/tsan_platform_mac.cpp +++ b/libsanitizer/tsan/tsan_platform_mac.cpp @@ -234,7 +234,7 @@ static void my_pthread_introspection_hook(unsigned int event, pthread_t thread, #endif void InitializePlatformEarly() { -#if defined(__aarch64__) +#if !SANITIZER_GO && defined(__aarch64__) uptr max_vm = GetMaxUserVirtualAddress() + 1; if (max_vm != Mapping::kHiAppMemEnd) { Printf("ThreadSanitizer: unsupported vm address limit %p, expected %p.\n", diff --git a/libsanitizer/tsan/tsan_report.cpp b/libsanitizer/tsan/tsan_report.cpp index 4892c446c10..968c7b97553 100644 --- a/libsanitizer/tsan/tsan_report.cpp +++ b/libsanitizer/tsan/tsan_report.cpp @@ -386,7 +386,8 @@ void PrintReport(const ReportDesc *rep) { ReportErrorSummary(rep_typ_str, frame->info); } - if (common_flags()->print_module_map == 2) PrintModuleMap(); + if (common_flags()->print_module_map == 2) + DumpProcessMap(); Printf("==================\n"); } diff --git a/libsanitizer/tsan/tsan_rtl.cpp b/libsanitizer/tsan/tsan_rtl.cpp index 7b37ed50681..3d721eb95a2 100644 --- a/libsanitizer/tsan/tsan_rtl.cpp +++ b/libsanitizer/tsan/tsan_rtl.cpp @@ -446,7 +446,8 @@ void MaybeSpawnBackgroundThread() { int Finalize(ThreadState *thr) { bool failed = false; - if (common_flags()->print_module_map == 1) PrintModuleMap(); + if (common_flags()->print_module_map == 1) + DumpProcessMap(); if (flags()->atexit_sleep_ms > 0 && ThreadCount(thr) > 1) SleepForMillis(flags()->atexit_sleep_ms); diff --git a/libsanitizer/tsan/tsan_rtl.h b/libsanitizer/tsan/tsan_rtl.h index efdc53a1e92..04d474e044e 100644 --- a/libsanitizer/tsan/tsan_rtl.h +++ b/libsanitizer/tsan/tsan_rtl.h @@ -477,7 +477,7 @@ inline void cur_thread_finalize() { } #endif // SANITIZER_MAC || SANITIZER_ANDROID #endif // SANITIZER_GO -class ThreadContext : public ThreadContextBase { +class ThreadContext final : public ThreadContextBase { public: explicit ThreadContext(int tid); ~ThreadContext(); diff --git a/libsanitizer/tsan/tsan_rtl_mutex.cpp b/libsanitizer/tsan/tsan_rtl_mutex.cpp index ebd0d722181..27897f0592b 100644 --- a/libsanitizer/tsan/tsan_rtl_mutex.cpp +++ b/libsanitizer/tsan/tsan_rtl_mutex.cpp @@ -24,7 +24,7 @@ namespace __tsan { void ReportDeadlock(ThreadState *thr, uptr pc, DDReport *r); -struct Callback : DDCallback { +struct Callback final : public DDCallback { ThreadState *thr; uptr pc; diff --git a/libsanitizer/tsan/tsan_rtl_ppc64.S b/libsanitizer/tsan/tsan_rtl_ppc64.S index 9e533a71a9c..8285e21aa1e 100644 --- a/libsanitizer/tsan/tsan_rtl_ppc64.S +++ b/libsanitizer/tsan/tsan_rtl_ppc64.S @@ -1,6 +1,5 @@ #include "tsan_ppc_regs.h" - .machine altivec .section .text .hidden __tsan_setjmp .globl _setjmp diff --git a/libsanitizer/ubsan/ubsan_flags.cpp b/libsanitizer/ubsan/ubsan_flags.cpp index 9a66bd37518..25cefd46ce2 100644 --- a/libsanitizer/ubsan/ubsan_flags.cpp +++ b/libsanitizer/ubsan/ubsan_flags.cpp @@ -50,7 +50,6 @@ void InitializeFlags() { { CommonFlags cf; cf.CopyFrom(*common_flags()); - cf.print_summary = false; cf.external_symbolizer_path = GetFlag("UBSAN_SYMBOLIZER_PATH"); OverrideCommonFlags(cf); } diff --git a/libsanitizer/ubsan/ubsan_handlers.cpp b/libsanitizer/ubsan/ubsan_handlers.cpp index 2184625aa6e..e201e6bba22 100644 --- a/libsanitizer/ubsan/ubsan_handlers.cpp +++ b/libsanitizer/ubsan/ubsan_handlers.cpp @@ -894,21 +894,6 @@ void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data, ValueHandle Vtable, } // namespace __ubsan -void __ubsan::__ubsan_handle_cfi_bad_icall(CFIBadIcallData *CallData, - ValueHandle Function) { - GET_REPORT_OPTIONS(false); - CFICheckFailData Data = {CFITCK_ICall, CallData->Loc, CallData->Type}; - handleCFIBadIcall(&Data, Function, Opts); -} - -void __ubsan::__ubsan_handle_cfi_bad_icall_abort(CFIBadIcallData *CallData, - ValueHandle Function) { - GET_REPORT_OPTIONS(true); - CFICheckFailData Data = {CFITCK_ICall, CallData->Loc, CallData->Type}; - handleCFIBadIcall(&Data, Function, Opts); - Die(); -} - void __ubsan::__ubsan_handle_cfi_check_fail(CFICheckFailData *Data, ValueHandle Value, uptr ValidVtable) { diff --git a/libsanitizer/ubsan/ubsan_handlers.h b/libsanitizer/ubsan/ubsan_handlers.h index 9f412353fc0..219fb15de55 100644 --- a/libsanitizer/ubsan/ubsan_handlers.h +++ b/libsanitizer/ubsan/ubsan_handlers.h @@ -215,20 +215,12 @@ enum CFITypeCheckKind : unsigned char { CFITCK_VMFCall, }; -struct CFIBadIcallData { - SourceLocation Loc; - const TypeDescriptor &Type; -}; - struct CFICheckFailData { CFITypeCheckKind CheckKind; SourceLocation Loc; const TypeDescriptor &Type; }; -/// \brief Handle control flow integrity failure for indirect function calls. -RECOVERABLE(cfi_bad_icall, CFIBadIcallData *Data, ValueHandle Function) - /// \brief Handle control flow integrity failures. RECOVERABLE(cfi_check_fail, CFICheckFailData *Data, ValueHandle Function, uptr VtableIsValid) diff --git a/libsanitizer/ubsan/ubsan_platform.h b/libsanitizer/ubsan/ubsan_platform.h index 58aabbe67b5..32d949d75b9 100644 --- a/libsanitizer/ubsan/ubsan_platform.h +++ b/libsanitizer/ubsan/ubsan_platform.h @@ -12,16 +12,14 @@ #ifndef UBSAN_PLATFORM_H #define UBSAN_PLATFORM_H -#ifndef CAN_SANITIZE_UB // Other platforms should be easy to add, and probably work as-is. #if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || \ - defined(__NetBSD__) || defined(__OpenBSD__) || \ + defined(__NetBSD__) || \ (defined(__sun__) && defined(__svr4__)) || \ defined(_WIN32) || defined(__Fuchsia__) || defined(__rtems__) # define CAN_SANITIZE_UB 1 #else # define CAN_SANITIZE_UB 0 #endif -#endif //CAN_SANITIZE_UB #endif diff --git a/libsanitizer/ubsan/ubsan_type_hash_itanium.cpp b/libsanitizer/ubsan/ubsan_type_hash_itanium.cpp index 4f1708ba190..d82b542a020 100644 --- a/libsanitizer/ubsan/ubsan_type_hash_itanium.cpp +++ b/libsanitizer/ubsan/ubsan_type_hash_itanium.cpp @@ -12,7 +12,7 @@ #include "sanitizer_common/sanitizer_platform.h" #include "ubsan_platform.h" -#if CAN_SANITIZE_UB && !SANITIZER_WINDOWS +#if CAN_SANITIZE_UB && !defined(_MSC_VER) #include "ubsan_type_hash.h" #include "sanitizer_common/sanitizer_common.h" diff --git a/libsanitizer/ubsan/ubsan_type_hash_win.cpp b/libsanitizer/ubsan/ubsan_type_hash_win.cpp index 45dcb758ec4..106fa1b85a5 100644 --- a/libsanitizer/ubsan/ubsan_type_hash_win.cpp +++ b/libsanitizer/ubsan/ubsan_type_hash_win.cpp @@ -12,7 +12,7 @@ #include "sanitizer_common/sanitizer_platform.h" #include "ubsan_platform.h" -#if CAN_SANITIZE_UB && SANITIZER_WINDOWS +#if CAN_SANITIZE_UB && defined(_MSC_VER) #include "ubsan_type_hash.h" #include "sanitizer_common/sanitizer_common.h"