#ifndef ASAN_ALLOCATOR_H
#define ASAN_ALLOCATOR_H
#include "asan_flags.h"
#include "asan_interceptors.h"
#include "asan_internal.h"
#include "sanitizer_common/sanitizer_allocator.h"
#include "sanitizer_common/sanitizer_list.h"
#include "sanitizer_common/sanitizer_platform.h"
namespace __asan {
enum AllocType { … };
class AsanChunk;
struct AllocatorOptions { … };
void InitializeAllocator(const AllocatorOptions &options);
void ReInitializeAllocator(const AllocatorOptions &options);
void GetAllocatorOptions(AllocatorOptions *options);
class AsanChunkView { … };
AsanChunkView FindHeapChunkByAddress(uptr address);
AsanChunkView FindHeapChunkByAllocBeg(uptr address);
class AsanChunkFifoList: public IntrusiveList<AsanChunk> { … };
struct AsanMapUnmapCallback { … };
#if SANITIZER_CAN_USE_ALLOCATOR64
# if SANITIZER_FUCHSIA
const uptr kAllocatorSpace = ~(uptr)0;
# if SANITIZER_RISCV64
const uptr kAllocatorSize = UINT64_C(1) << 33;
typedef SizeClassMap<2,
5,
8,
18,
8,
10>
SizeClassMap;
static_assert(SizeClassMap::kNumClassesRounded <= 32,
"The above tunings were specifically selected to ensure there "
"would be at most 32 size classes. This restriction could be "
"loosened to 64 size classes if we can find a configuration of "
"allocator size and SizeClassMap tunings that allows us to "
"reliably run all bringup tests in a sanitized environment.");
# else
const uptr kAllocatorSize = 0x40000000000ULL;
typedef DefaultSizeClassMap SizeClassMap;
# endif
# else
# if SANITIZER_APPLE
const uptr kAllocatorSpace = 0x600000000000ULL;
# else
const uptr kAllocatorSpace = …;
# endif
# if defined(__powerpc64__)
const uptr kAllocatorSize = 0x20000000000ULL;
typedef DefaultSizeClassMap SizeClassMap;
# elif defined(__aarch64__) && SANITIZER_ANDROID
const uptr kAllocatorSize = 0x2000000000ULL;
typedef VeryCompactSizeClassMap SizeClassMap;
# elif SANITIZER_RISCV64
const uptr kAllocatorSize = 0x2000000000ULL;
typedef VeryDenseSizeClassMap SizeClassMap;
# elif defined(__sparc__)
const uptr kAllocatorSize = 0x20000000000ULL;
typedef DefaultSizeClassMap SizeClassMap;
# elif SANITIZER_WINDOWS
const uptr kAllocatorSize = 0x8000000000ULL;
typedef DefaultSizeClassMap SizeClassMap;
# elif SANITIZER_APPLE
const uptr kAllocatorSize = 0x40000000000ULL;
typedef DefaultSizeClassMap SizeClassMap;
# else
const uptr kAllocatorSize = …;
SizeClassMap;
# endif
# endif
template <typename AddressSpaceViewTy>
struct AP64 { … };
PrimaryAllocatorASVT;
PrimaryAllocator;
#else
typedef CompactSizeClassMap SizeClassMap;
template <typename AddressSpaceViewTy>
struct AP32 {
static const uptr kSpaceBeg = 0;
static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE;
static const uptr kMetadataSize = 0;
typedef __asan::SizeClassMap SizeClassMap;
static const uptr kRegionSizeLog = 20;
using AddressSpaceView = AddressSpaceViewTy;
typedef AsanMapUnmapCallback MapUnmapCallback;
static const uptr kFlags = 0;
};
template <typename AddressSpaceView>
using PrimaryAllocatorASVT = SizeClassAllocator32<AP32<AddressSpaceView> >;
using PrimaryAllocator = PrimaryAllocatorASVT<LocalAddressSpaceView>;
#endif
static const uptr kNumberOfSizeClasses = …;
AsanAllocatorASVT;
AsanAllocator;
AllocatorCache;
struct AsanThreadLocalMallocStorage { … };
void *asan_memalign(uptr alignment, uptr size, BufferedStackTrace *stack,
AllocType alloc_type);
void asan_free(void *ptr, BufferedStackTrace *stack, AllocType alloc_type);
void asan_delete(void *ptr, uptr size, uptr alignment,
BufferedStackTrace *stack, AllocType alloc_type);
void *asan_malloc(uptr size, BufferedStackTrace *stack);
void *asan_calloc(uptr nmemb, uptr size, BufferedStackTrace *stack);
void *asan_realloc(void *p, uptr size, BufferedStackTrace *stack);
void *asan_reallocarray(void *p, uptr nmemb, uptr size,
BufferedStackTrace *stack);
void *asan_valloc(uptr size, BufferedStackTrace *stack);
void *asan_pvalloc(uptr size, BufferedStackTrace *stack);
void *asan_aligned_alloc(uptr alignment, uptr size, BufferedStackTrace *stack);
int asan_posix_memalign(void **memptr, uptr alignment, uptr size,
BufferedStackTrace *stack);
uptr asan_malloc_usable_size(const void *ptr, uptr pc, uptr bp);
uptr asan_mz_size(const void *ptr);
void asan_mz_force_lock();
void asan_mz_force_unlock();
void PrintInternalAllocatorStats();
void AsanSoftRssLimitExceededCallback(bool exceeded);
}
#endif