llvm/compiler-rt/lib/hwasan/hwasan_linux.cpp

//===-- hwasan_linux.cpp ----------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file is a part of HWAddressSanitizer and contains Linux-, NetBSD- and
/// FreeBSD-specific code.
///
//===----------------------------------------------------------------------===//

#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"

// Configurations of HWASAN_WITH_INTERCEPTORS and SANITIZER_ANDROID.
//
// HWASAN_WITH_INTERCEPTORS=OFF, SANITIZER_ANDROID=OFF
//   Not currently tested.
// HWASAN_WITH_INTERCEPTORS=OFF, SANITIZER_ANDROID=ON
//   Integration tests downstream exist.
// HWASAN_WITH_INTERCEPTORS=ON, SANITIZER_ANDROID=OFF
//    Tested with check-hwasan on x86_64-linux.
// HWASAN_WITH_INTERCEPTORS=ON, SANITIZER_ANDROID=ON
//    Tested with check-hwasan on aarch64-linux-android.
#  if !SANITIZER_ANDROID
SANITIZER_INTERFACE_ATTRIBUTE
THREADLOCAL uptr __hwasan_tls;
#  endif

namespace __hwasan {

// With the zero shadow base we can not actually map pages starting from 0.
// This constant is somewhat arbitrary.
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() {}

// ---------------------- TSD ---------------- {{{1

#  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() {}

}  // namespace __hwasan

usingnamespace__hwasan;

extern "C" void __hwasan_thread_enter() {}

extern "C" void __hwasan_thread_exit() {}

#endif  // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD