llvm/compiler-rt/lib/asan/asan_fake_stack.cpp

//===-- asan_fake_stack.cpp -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file is a part of AddressSanitizer, an address sanity checker.
//
// FakeStack is used to detect use-after-return bugs.
//===----------------------------------------------------------------------===//

#include "asan_allocator.h"
#include "asan_poisoning.h"
#include "asan_thread.h"

namespace __asan {

static const u64 kMagic1 =;
static const u64 kMagic2 =;
static const u64 kMagic4 =;
static const u64 kMagic8 =;

static const u64 kAllocaRedzoneSize =;
static const u64 kAllocaRedzoneMask =;

// For small size classes inline PoisonShadow for better performance.
ALWAYS_INLINE void SetShadow(uptr ptr, uptr size, uptr class_id, u64 magic) {}

FakeStack *FakeStack::Create(uptr stack_size_log) {}

void FakeStack::Destroy(int tid) {}

void FakeStack::PoisonAll(u8 magic) {}

#if !defined(_MSC_VER) || defined(__clang__)
ALWAYS_INLINE USED
#endif
FakeFrame *FakeStack::Allocate(uptr stack_size_log, uptr class_id,
                               uptr real_stack) {}

uptr FakeStack::AddrIsInFakeStack(uptr ptr, uptr *frame_beg, uptr *frame_end) {}

void FakeStack::HandleNoReturn() {}

// Hack: The statement below is not true if we take into account sigaltstack or
// makecontext. It should be possible to make GC to discard wrong stack frame if
// we use these tools. For now, let's support the simplest case and allow GC to
// discard only frames from the default stack, assuming there is no buffer on
// the stack which is used for makecontext or sigaltstack.
//
// When throw, longjmp or some such happens we don't call OnFree() and
// as the result may leak one or more fake frames, but the good news is that
// we are notified about all such events by HandleNoReturn().
// If we recently had such no-return event we need to collect garbage frames.
// We do it based on their 'real_stack' values -- everything that is lower
// than the current real_stack is garbage.
NOINLINE void FakeStack::GC(uptr real_stack) {}

void FakeStack::ForEachFakeFrame(RangeIteratorCallback callback, void *arg) {}

#if (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_FUCHSIA
static THREADLOCAL FakeStack *fake_stack_tls;

FakeStack *GetTLSFakeStack() {}
void SetTLSFakeStack(FakeStack *fs) {}
#else
FakeStack *GetTLSFakeStack() { return 0; }
void SetTLSFakeStack(FakeStack *fs) { }
#endif  // (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_FUCHSIA

static FakeStack *GetFakeStack() {}

static FakeStack *GetFakeStackFast() {}

static FakeStack *GetFakeStackFastAlways() {}

static ALWAYS_INLINE uptr OnMalloc(uptr class_id, uptr size) {}

static ALWAYS_INLINE uptr OnMallocAlways(uptr class_id, uptr size) {}

static ALWAYS_INLINE void OnFree(uptr ptr, uptr class_id, uptr size) {}

} // namespace __asan

// ---------------------- Interface ---------------- {{{1
usingnamespace__asan;
#define DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID(class_id)

DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID()
DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID()
DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID()
DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID()
DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID()
DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID()
DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID()
DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID()
DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID()
DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID()
DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID()

extern "C" {
// TODO: remove this method and fix tests that use it by setting
// -asan-use-after-return=never, after modal UAR flag lands
// (https://github.com/google/sanitizers/issues/1394)
SANITIZER_INTERFACE_ATTRIBUTE
void *__asan_get_current_fake_stack() {}

SANITIZER_INTERFACE_ATTRIBUTE
void *__asan_addr_is_in_fake_stack(void *fake_stack, void *addr, void **beg,
                                   void **end) {}

SANITIZER_INTERFACE_ATTRIBUTE
void __asan_alloca_poison(uptr addr, uptr size) {}

SANITIZER_INTERFACE_ATTRIBUTE
void __asan_allocas_unpoison(uptr top, uptr bottom) {}
} // extern "C"