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

//===-- hwasan_allocator.cpp ------------------------ ---------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file is a part of HWAddressSanitizer.
//
// HWAddressSanitizer allocator.
//===----------------------------------------------------------------------===//

#include "sanitizer_common/sanitizer_atomic.h"
#include "sanitizer_common/sanitizer_errno.h"
#include "sanitizer_common/sanitizer_stackdepot.h"
#include "hwasan.h"
#include "hwasan_allocator.h"
#include "hwasan_checks.h"
#include "hwasan_mapping.h"
#include "hwasan_malloc_bisect.h"
#include "hwasan_thread.h"
#include "hwasan_report.h"
#include "lsan/lsan_common.h"

namespace __hwasan {

static Allocator allocator;
static AllocatorCache fallback_allocator_cache;
static SpinMutex fallback_mutex;
static atomic_uint8_t hwasan_allocator_tagging_enabled;

static constexpr tag_t kFallbackAllocTag =;
static constexpr tag_t kFallbackFreeTag =;

enum {};


// Initialized in HwasanAllocatorInit, an never changed.
alignas(16) static u8 tail_magic[kShadowAlignment - 1];
static uptr max_malloc_size;

bool HwasanChunkView::IsAllocated() const {}

uptr HwasanChunkView::Beg() const {}
uptr HwasanChunkView::End() const {}
uptr HwasanChunkView::UsedSize() const {}
u32 HwasanChunkView::GetAllocStackId() const {}

u32 HwasanChunkView::GetAllocThreadId() const {}

uptr HwasanChunkView::ActualSize() const {}

bool HwasanChunkView::FromSmallHeap() const {}

bool HwasanChunkView::AddrIsInside(uptr addr) const {}

inline void Metadata::SetAllocated(u32 stack, u64 size) {}

inline void Metadata::SetUnallocated() {}

inline bool Metadata::IsAllocated() const {}

inline u64 Metadata::GetRequestedSize() const {}

inline u32 Metadata::GetAllocStackId() const {}

inline u32 Metadata::GetAllocThreadId() const {}

void GetAllocatorStats(AllocatorStatCounters s) {}

inline void Metadata::SetLsanTag(__lsan::ChunkTag tag) {}

inline __lsan::ChunkTag Metadata::GetLsanTag() const {}

uptr GetAliasRegionStart() {}

void HwasanAllocatorInit() {}

void HwasanAllocatorLock() {}

void HwasanAllocatorUnlock() {}

void AllocatorThreadStart(AllocatorCache *cache) {}

void AllocatorThreadFinish(AllocatorCache *cache) {}

static uptr TaggedSize(uptr size) {}

static void *HwasanAllocate(StackTrace *stack, uptr orig_size, uptr alignment,
                            bool zeroise) {}

static bool PointerAndMemoryTagsMatch(void *tagged_ptr) {}

static bool CheckInvalidFree(StackTrace *stack, void *untagged_ptr,
                             void *tagged_ptr) {}

static void HwasanDeallocate(StackTrace *stack, void *tagged_ptr) {}

static void *HwasanReallocate(StackTrace *stack, void *tagged_ptr_old,
                              uptr new_size, uptr alignment) {}

static void *HwasanCalloc(StackTrace *stack, uptr nmemb, uptr size) {}

HwasanChunkView FindHeapChunkByAddress(uptr address) {}

static const void *AllocationBegin(const void *p) {}

static uptr AllocationSize(const void *p) {}

static uptr AllocationSizeFast(const void *p) {}

void *hwasan_malloc(uptr size, StackTrace *stack) {}

void *hwasan_calloc(uptr nmemb, uptr size, StackTrace *stack) {}

void *hwasan_realloc(void *ptr, uptr size, StackTrace *stack) {}

void *hwasan_reallocarray(void *ptr, uptr nmemb, uptr size, StackTrace *stack) {}

void *hwasan_valloc(uptr size, StackTrace *stack) {}

void *hwasan_pvalloc(uptr size, StackTrace *stack) {}

void *hwasan_aligned_alloc(uptr alignment, uptr size, StackTrace *stack) {}

void *hwasan_memalign(uptr alignment, uptr size, StackTrace *stack) {}

int hwasan_posix_memalign(void **memptr, uptr alignment, uptr size,
                        StackTrace *stack) {}

void hwasan_free(void *ptr, StackTrace *stack) {}

}  // namespace __hwasan

// --- Implementation of LSan-specific functions --- {{{1
namespace __lsan {

void LockAllocator() {}

void UnlockAllocator() {}

void GetAllocatorGlobalRange(uptr *begin, uptr *end) {}

uptr PointsIntoChunk(void *p) {}

uptr GetUserBegin(uptr chunk) {}

uptr GetUserAddr(uptr chunk) {}

LsanMetadata::LsanMetadata(uptr chunk) {}

bool LsanMetadata::allocated() const {}

ChunkTag LsanMetadata::tag() const {}

void LsanMetadata::set_tag(ChunkTag value) {}

uptr LsanMetadata::requested_size() const {}

u32 LsanMetadata::stack_trace_id() const {}

void ForEachChunk(ForEachChunkCallback callback, void *arg) {}

IgnoreObjectResult IgnoreObject(const void *p) {}

}  // namespace __lsan

usingnamespace__hwasan;

void __hwasan_enable_allocator_tagging() {}

void __hwasan_disable_allocator_tagging() {}

uptr __sanitizer_get_current_allocated_bytes() {}

uptr __sanitizer_get_heap_size() {}

uptr __sanitizer_get_free_bytes() {}

uptr __sanitizer_get_unmapped_bytes() {}

uptr __sanitizer_get_estimated_allocated_size(uptr size) {}

int __sanitizer_get_ownership(const void *p) {}

const void *__sanitizer_get_allocated_begin(const void *p) {}

uptr __sanitizer_get_allocated_size(const void *p) {}

uptr __sanitizer_get_allocated_size_fast(const void *p) {}

void __sanitizer_purge_allocator() {}