#include "msan_allocator.h"
#include "msan.h"
#include "msan_interface_internal.h"
#include "msan_origin.h"
#include "msan_poisoning.h"
#include "msan_thread.h"
#include "sanitizer_common/sanitizer_allocator.h"
#include "sanitizer_common/sanitizer_allocator_checks.h"
#include "sanitizer_common/sanitizer_allocator_interface.h"
#include "sanitizer_common/sanitizer_allocator_report.h"
#include "sanitizer_common/sanitizer_errno.h"
usingnamespace__msan;
namespace {
struct Metadata { … };
struct MsanMapUnmapCallback { … };
#if defined(__mips64)
const uptr kMaxAllowedMallocSize = 2UL << 30;
struct AP32 {
static const uptr kSpaceBeg = 0;
static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE;
static const uptr kMetadataSize = sizeof(Metadata);
using SizeClassMap = __sanitizer::CompactSizeClassMap;
static const uptr kRegionSizeLog = 20;
using AddressSpaceView = LocalAddressSpaceView;
using MapUnmapCallback = MsanMapUnmapCallback;
static const uptr kFlags = 0;
};
using PrimaryAllocator = SizeClassAllocator32<AP32>;
#elif defined(__x86_64__)
#if SANITIZER_NETBSD || SANITIZER_LINUX
const uptr kAllocatorSpace = …;
#else
const uptr kAllocatorSpace = 0x600000000000ULL;
#endif
const uptr kMaxAllowedMallocSize = …;
struct AP64 { … };
PrimaryAllocator;
#elif defined(__loongarch_lp64)
const uptr kAllocatorSpace = 0x700000000000ULL;
const uptr kMaxAllowedMallocSize = 8UL << 30;
struct AP64 {
static const uptr kSpaceBeg = kAllocatorSpace;
static const uptr kSpaceSize = 0x40000000000;
static const uptr kMetadataSize = sizeof(Metadata);
using SizeClassMap = DefaultSizeClassMap;
using MapUnmapCallback = MsanMapUnmapCallback;
static const uptr kFlags = 0;
using AddressSpaceView = LocalAddressSpaceView;
};
using PrimaryAllocator = SizeClassAllocator64<AP64>;
#elif defined(__powerpc64__)
const uptr kMaxAllowedMallocSize = 2UL << 30;
struct AP64 {
static const uptr kSpaceBeg = 0x300000000000;
static const uptr kSpaceSize = 0x020000000000;
static const uptr kMetadataSize = sizeof(Metadata);
using SizeClassMap = DefaultSizeClassMap;
using MapUnmapCallback = MsanMapUnmapCallback;
static const uptr kFlags = 0;
using AddressSpaceView = LocalAddressSpaceView;
};
using PrimaryAllocator = SizeClassAllocator64<AP64>;
#elif defined(__s390x__)
const uptr kMaxAllowedMallocSize = 2UL << 30;
struct AP64 {
static const uptr kSpaceBeg = 0x440000000000;
static const uptr kSpaceSize = 0x020000000000;
static const uptr kMetadataSize = sizeof(Metadata);
using SizeClassMap = DefaultSizeClassMap;
using MapUnmapCallback = MsanMapUnmapCallback;
static const uptr kFlags = 0;
using AddressSpaceView = LocalAddressSpaceView;
};
using PrimaryAllocator = SizeClassAllocator64<AP64>;
#elif defined(__aarch64__)
const uptr kMaxAllowedMallocSize = 8UL << 30;
struct AP64 {
static const uptr kSpaceBeg = 0xE00000000000ULL;
static const uptr kSpaceSize = 0x40000000000;
static const uptr kMetadataSize = sizeof(Metadata);
using SizeClassMap = DefaultSizeClassMap;
using MapUnmapCallback = MsanMapUnmapCallback;
static const uptr kFlags = 0;
using AddressSpaceView = LocalAddressSpaceView;
};
using PrimaryAllocator = SizeClassAllocator64<AP64>;
#endif
Allocator;
AllocatorCache;
}
static Allocator allocator;
static AllocatorCache fallback_allocator_cache;
static StaticSpinMutex fallback_mutex;
static uptr max_malloc_size;
void __msan::MsanAllocatorInit() { … }
void __msan::LockAllocator() { … }
void __msan::UnlockAllocator() { … }
AllocatorCache *GetAllocatorCache(MsanThreadLocalMallocStorage *ms) { … }
void MsanThreadLocalMallocStorage::Init() { … }
void MsanThreadLocalMallocStorage::CommitBack() { … }
static void *MsanAllocate(BufferedStackTrace *stack, uptr size, uptr alignment,
bool zero) { … }
void __msan::MsanDeallocate(BufferedStackTrace *stack, void *p) { … }
static void *MsanReallocate(BufferedStackTrace *stack, void *old_p,
uptr new_size, uptr alignment) { … }
static void *MsanCalloc(BufferedStackTrace *stack, uptr nmemb, uptr size) { … }
static const void *AllocationBegin(const void *p) { … }
static uptr AllocationSizeFast(const void *p) { … }
static uptr AllocationSize(const void *p) { … }
void *__msan::msan_malloc(uptr size, BufferedStackTrace *stack) { … }
void *__msan::msan_calloc(uptr nmemb, uptr size, BufferedStackTrace *stack) { … }
void *__msan::msan_realloc(void *ptr, uptr size, BufferedStackTrace *stack) { … }
void *__msan::msan_reallocarray(void *ptr, uptr nmemb, uptr size,
BufferedStackTrace *stack) { … }
void *__msan::msan_valloc(uptr size, BufferedStackTrace *stack) { … }
void *__msan::msan_pvalloc(uptr size, BufferedStackTrace *stack) { … }
void *__msan::msan_aligned_alloc(uptr alignment, uptr size,
BufferedStackTrace *stack) { … }
void *__msan::msan_memalign(uptr alignment, uptr size,
BufferedStackTrace *stack) { … }
int __msan::msan_posix_memalign(void **memptr, uptr alignment, uptr size,
BufferedStackTrace *stack) { … }
extern "C" {
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() { … }
}