#include "sanitizer_common/sanitizer_platform.h"
#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD
# include <dlfcn.h>
# include <elf.h>
# include <errno.h>
# include <link.h>
# include <pthread.h>
# include <signal.h>
# include <stdio.h>
# include <stdlib.h>
# include <sys/prctl.h>
# include <sys/resource.h>
# include <sys/time.h>
# include <unistd.h>
# include <unwind.h>
# include "hwasan.h"
# include "hwasan_dynamic_shadow.h"
# include "hwasan_interface_internal.h"
# include "hwasan_mapping.h"
# include "hwasan_report.h"
# include "hwasan_thread.h"
# include "hwasan_thread_list.h"
# include "sanitizer_common/sanitizer_common.h"
# include "sanitizer_common/sanitizer_procmaps.h"
# include "sanitizer_common/sanitizer_stackdepot.h"
# if !SANITIZER_ANDROID
SANITIZER_INTERFACE_ATTRIBUTE
THREADLOCAL uptr __hwasan_tls;
# endif
namespace __hwasan {
constexpr uptr kZeroBaseShadowStart = …;
constexpr uptr kZeroBaseMaxShadowStart = …;
static void ProtectGap(uptr addr, uptr size) { … }
uptr kLowMemStart;
uptr kLowMemEnd;
uptr kHighMemStart;
uptr kHighMemEnd;
static void PrintRange(uptr start, uptr end, const char *name) { … }
static void PrintAddressSpaceLayout() { … }
static uptr GetHighMemEnd() { … }
static void InitializeShadowBaseAddress(uptr shadow_size_bytes) { … }
static void MaybeDieIfNoTaggingAbi(const char *message) { … }
#define PR_SET_TAGGED_ADDR_CTRL …
#define PR_GET_TAGGED_ADDR_CTRL …
#define PR_TAGGED_ADDR_ENABLE …
#define ARCH_GET_UNTAG_MASK …
#define ARCH_ENABLE_TAGGED_ADDR …
#define ARCH_GET_MAX_TAG_BITS …
static bool CanUseTaggingAbi() { … }
static bool EnableTaggingAbi() { … }
void InitializeOsSupport() { … }
bool InitShadow() { … }
void InitThreads() { … }
bool MemIsApp(uptr p) { … }
void InstallAtExitHandler() { … }
# if HWASAN_WITH_INTERCEPTORS
static pthread_key_t tsd_key;
static bool tsd_key_inited = …;
void HwasanTSDThreadInit() { … }
void HwasanTSDDtor(void *tsd) { … }
void HwasanTSDInit() { … }
# else
void HwasanTSDInit() {}
void HwasanTSDThreadInit() {}
# endif
# if SANITIZER_ANDROID
uptr *GetCurrentThreadLongPtr() { return (uptr *)get_android_tls_ptr(); }
# else
uptr *GetCurrentThreadLongPtr() { … }
# endif
# if SANITIZER_ANDROID
void AndroidTestTlsSlot() {
uptr kMagicValue = 0x010203040A0B0C0D;
uptr *tls_ptr = GetCurrentThreadLongPtr();
uptr old_value = *tls_ptr;
*tls_ptr = kMagicValue;
dlerror();
if (*(uptr *)get_android_tls_ptr() != kMagicValue) {
Printf(
"ERROR: Incompatible version of Android: TLS_SLOT_SANITIZER(6) is used "
"for dlerror().\n");
Die();
}
*tls_ptr = old_value;
}
# else
void AndroidTestTlsSlot() { … }
# endif
static AccessInfo GetAccessInfo(siginfo_t *info, ucontext_t *uc) { … }
static bool HwasanOnSIGTRAP(int signo, siginfo_t *info, ucontext_t *uc) { … }
static void OnStackUnwind(const SignalContext &sig, const void *,
BufferedStackTrace *stack) { … }
void HwasanOnDeadlySignal(int signo, void *info, void *context) { … }
void Thread::InitStackAndTls(const InitState *) { … }
uptr TagMemoryAligned(uptr p, uptr size, tag_t tag) { … }
static void BeforeFork() { … }
static void AfterFork(bool fork_child) { … }
void HwasanInstallAtForkHandler() { … }
void InstallAtExitCheckLeaks() { … }
}
usingnamespace__hwasan;
extern "C" void __hwasan_thread_enter() { … }
extern "C" void __hwasan_thread_exit() { … }
#endif