#ifndef MSAN_H
#define MSAN_H
#include "sanitizer_common/sanitizer_flags.h"
#include "sanitizer_common/sanitizer_internal_defs.h"
#include "sanitizer_common/sanitizer_stacktrace.h"
#include "msan_interface_internal.h"
#include "msan_flags.h"
#include "ubsan/ubsan_platform.h"
#ifndef MSAN_REPLACE_OPERATORS_NEW_AND_DELETE
#define MSAN_REPLACE_OPERATORS_NEW_AND_DELETE …
#endif
#ifndef MSAN_CONTAINS_UBSAN
#define MSAN_CONTAINS_UBSAN …
#endif
struct MappingDesc { … };
#if SANITIZER_LINUX && defined(__mips64)
const MappingDesc kMemoryLayout[] = {
{0x000000000000ULL, 0x000200000000ULL, MappingDesc::APP, "app-1"},
{0x000200000000ULL, 0x002200000000ULL, MappingDesc::INVALID, "invalid"},
{0x002200000000ULL, 0x004000000000ULL, MappingDesc::SHADOW, "shadow-2"},
{0x004000000000ULL, 0x004200000000ULL, MappingDesc::INVALID, "invalid"},
{0x004200000000ULL, 0x006000000000ULL, MappingDesc::ORIGIN, "origin-2"},
{0x006000000000ULL, 0x006200000000ULL, MappingDesc::INVALID, "invalid"},
{0x006200000000ULL, 0x008000000000ULL, MappingDesc::SHADOW, "shadow-3"},
{0x008000000000ULL, 0x008200000000ULL, MappingDesc::SHADOW, "shadow-1"},
{0x008200000000ULL, 0x00a000000000ULL, MappingDesc::ORIGIN, "origin-3"},
{0x00a000000000ULL, 0x00a200000000ULL, MappingDesc::ORIGIN, "origin-1"},
{0x00a200000000ULL, 0x00c000000000ULL, MappingDesc::APP, "app-2"},
{0x00c000000000ULL, 0x00e200000000ULL, MappingDesc::INVALID, "invalid"},
{0x00e200000000ULL, 0x00ffffffffffULL, MappingDesc::APP, "app-3"}};
#define MEM_TO_SHADOW …
#define SHADOW_TO_ORIGIN …
#elif SANITIZER_LINUX && defined(__aarch64__)
const MappingDesc kMemoryLayout[] = {
{0X0000000000000, 0X0100000000000, MappingDesc::APP, "app-10-13"},
{0X0100000000000, 0X0200000000000, MappingDesc::SHADOW, "shadow-14"},
{0X0200000000000, 0X0300000000000, MappingDesc::INVALID, "invalid"},
{0X0300000000000, 0X0400000000000, MappingDesc::ORIGIN, "origin-14"},
{0X0400000000000, 0X0600000000000, MappingDesc::SHADOW, "shadow-15"},
{0X0600000000000, 0X0800000000000, MappingDesc::ORIGIN, "origin-15"},
{0X0800000000000, 0X0A00000000000, MappingDesc::INVALID, "invalid"},
{0X0A00000000000, 0X0B00000000000, MappingDesc::APP, "app-14"},
{0X0B00000000000, 0X0C00000000000, MappingDesc::SHADOW, "shadow-10-13"},
{0X0C00000000000, 0X0D00000000000, MappingDesc::INVALID, "invalid"},
{0X0D00000000000, 0X0E00000000000, MappingDesc::ORIGIN, "origin-10-13"},
{0x0E00000000000, 0x0E40000000000, MappingDesc::ALLOCATOR, "allocator"},
{0X0E40000000000, 0X1000000000000, MappingDesc::APP, "app-15"},
};
#define MEM_TO_SHADOW …
#define SHADOW_TO_ORIGIN …
#elif SANITIZER_LINUX && SANITIZER_LOONGARCH64
const MappingDesc kMemoryLayout[] = {
{0x000000000000ULL, 0x010000000000ULL, MappingDesc::APP, "app-1"},
{0x010000000000ULL, 0x100000000000ULL, MappingDesc::SHADOW, "shadow-2"},
{0x100000000000ULL, 0x110000000000ULL, MappingDesc::INVALID, "invalid"},
{0x110000000000ULL, 0x200000000000ULL, MappingDesc::ORIGIN, "origin-2"},
{0x200000000000ULL, 0x300000000000ULL, MappingDesc::SHADOW, "shadow-3"},
{0x300000000000ULL, 0x400000000000ULL, MappingDesc::ORIGIN, "origin-3"},
{0x400000000000ULL, 0x500000000000ULL, MappingDesc::INVALID, "invalid"},
{0x500000000000ULL, 0x510000000000ULL, MappingDesc::SHADOW, "shadow-1"},
{0x510000000000ULL, 0x600000000000ULL, MappingDesc::APP, "app-2"},
{0x600000000000ULL, 0x610000000000ULL, MappingDesc::ORIGIN, "origin-1"},
{0x610000000000ULL, 0x700000000000ULL, MappingDesc::INVALID, "invalid"},
{0x700000000000ULL, 0x740000000000ULL, MappingDesc::ALLOCATOR, "allocator"},
{0x740000000000ULL, 0x800000000000ULL, MappingDesc::APP, "app-3"}};
#define MEM_TO_SHADOW …
#define SHADOW_TO_ORIGIN …
#elif SANITIZER_LINUX && SANITIZER_PPC64
const MappingDesc kMemoryLayout[] = {
{0x000000000000ULL, 0x000200000000ULL, MappingDesc::APP, "low memory"},
{0x000200000000ULL, 0x080000000000ULL, MappingDesc::INVALID, "invalid"},
{0x080000000000ULL, 0x180200000000ULL, MappingDesc::SHADOW, "shadow"},
{0x180200000000ULL, 0x1C0000000000ULL, MappingDesc::INVALID, "invalid"},
{0x1C0000000000ULL, 0x2C0200000000ULL, MappingDesc::ORIGIN, "origin"},
{0x2C0200000000ULL, 0x300000000000ULL, MappingDesc::INVALID, "invalid"},
{0x300000000000ULL, 0x320000000000ULL, MappingDesc::ALLOCATOR, "allocator"},
{0x320000000000ULL, 0x800000000000ULL, MappingDesc::APP, "high memory"}};
#define LINEARIZE_MEM …
#define MEM_TO_SHADOW …
#define SHADOW_TO_ORIGIN …
#elif SANITIZER_LINUX && SANITIZER_S390_64
const MappingDesc kMemoryLayout[] = {
{0x000000000000ULL, 0x040000000000ULL, MappingDesc::APP, "low memory"},
{0x040000000000ULL, 0x080000000000ULL, MappingDesc::INVALID, "invalid"},
{0x080000000000ULL, 0x180000000000ULL, MappingDesc::SHADOW, "shadow"},
{0x180000000000ULL, 0x1C0000000000ULL, MappingDesc::INVALID, "invalid"},
{0x1C0000000000ULL, 0x2C0000000000ULL, MappingDesc::ORIGIN, "origin"},
{0x2C0000000000ULL, 0x440000000000ULL, MappingDesc::INVALID, "invalid"},
{0x440000000000ULL, 0x460000000000ULL, MappingDesc::ALLOCATOR, "allocator"},
{0x460000000000ULL, 0x500000000000ULL, MappingDesc::APP, "high memory"}};
#define MEM_TO_SHADOW …
#define SHADOW_TO_ORIGIN …
#elif SANITIZER_FREEBSD && defined(__aarch64__)
const MappingDesc kMemoryLayout[] = {
{0x000000000000ULL, 0x020000000000ULL, MappingDesc::APP, "low memory"},
{0x020000000000ULL, 0x200000000000ULL, MappingDesc::INVALID, "invalid"},
{0x200000000000ULL, 0x620000000000ULL, MappingDesc::SHADOW, "shadow"},
{0x620000000000ULL, 0x700000000000ULL, MappingDesc::INVALID, "invalid"},
{0x700000000000ULL, 0xb20000000000ULL, MappingDesc::ORIGIN, "origin"},
{0xb20000000000ULL, 0xc00000000000ULL, MappingDesc::INVALID, "invalid"},
{0xc00000000000ULL, 0x1000000000000ULL, MappingDesc::APP, "high memory"}};
#define LINEARIZE_MEM …
#define MEM_TO_SHADOW …
#define SHADOW_TO_ORIGIN …
#elif SANITIZER_FREEBSD && SANITIZER_WORDSIZE == 64
const MappingDesc kMemoryLayout[] = {
{0x000000000000ULL, 0x010000000000ULL, MappingDesc::APP, "low memory"},
{0x010000000000ULL, 0x100000000000ULL, MappingDesc::INVALID, "invalid"},
{0x100000000000ULL, 0x310000000000ULL, MappingDesc::SHADOW, "shadow"},
{0x310000000000ULL, 0x380000000000ULL, MappingDesc::INVALID, "invalid"},
{0x380000000000ULL, 0x590000000000ULL, MappingDesc::ORIGIN, "origin"},
{0x590000000000ULL, 0x600000000000ULL, MappingDesc::INVALID, "invalid"},
{0x600000000000ULL, 0x800000000000ULL, MappingDesc::APP, "high memory"}};
#define LINEARIZE_MEM …
#define MEM_TO_SHADOW …
#define SHADOW_TO_ORIGIN …
#elif SANITIZER_NETBSD || (SANITIZER_LINUX && SANITIZER_WORDSIZE == 64)
const MappingDesc kMemoryLayout[] = …;
#define MEM_TO_SHADOW(mem) …
#define SHADOW_TO_ORIGIN(mem) …
#else
#error "Unsupported platform"
#endif
const uptr kMemoryLayoutSize = …;
#define MEM_TO_ORIGIN(mem) …
#ifndef __clang__
__attribute__((optimize("unroll-loops")))
#endif
inline bool
addr_is_type(uptr addr, int mapping_types) { … }
#define MEM_IS_APP(mem) …
#define MEM_IS_SHADOW(mem) …
#define MEM_IS_ORIGIN(mem) …
const int kMsanParamTlsSize = …;
const int kMsanRetvalTlsSize = …;
namespace __msan {
extern int msan_inited;
extern bool msan_init_is_running;
extern int msan_report_count;
bool ProtectRange(uptr beg, uptr end);
bool InitShadowWithReExec(bool init_origins);
char *GetProcSelfMaps();
void InitializeInterceptors();
void MsanAllocatorInit();
void MsanDeallocate(BufferedStackTrace *stack, void *ptr);
void *msan_malloc(uptr size, BufferedStackTrace *stack);
void *msan_calloc(uptr nmemb, uptr size, BufferedStackTrace *stack);
void *msan_realloc(void *ptr, uptr size, BufferedStackTrace *stack);
void *msan_reallocarray(void *ptr, uptr nmemb, uptr size,
BufferedStackTrace *stack);
void *msan_valloc(uptr size, BufferedStackTrace *stack);
void *msan_pvalloc(uptr size, BufferedStackTrace *stack);
void *msan_aligned_alloc(uptr alignment, uptr size, BufferedStackTrace *stack);
void *msan_memalign(uptr alignment, uptr size, BufferedStackTrace *stack);
int msan_posix_memalign(void **memptr, uptr alignment, uptr size,
BufferedStackTrace *stack);
void InstallTrapHandler();
void InstallAtExitHandler();
const char *GetStackOriginDescr(u32 id, uptr *pc);
bool IsInSymbolizerOrUnwider();
void PrintWarning(uptr pc, uptr bp);
void PrintWarningWithOrigin(uptr pc, uptr bp, u32 origin);
void UnpoisonParam(uptr n);
void UnpoisonThreadLocalState();
u32 ChainOrigin(u32 id, StackTrace *stack);
const int STACK_TRACE_TAG_POISON = …;
const int STACK_TRACE_TAG_FIELDS = …;
const int STACK_TRACE_TAG_VPTR = …;
#define GET_MALLOC_STACK_TRACE …
#define GET_STORE_STACK_TRACE_PC_BP(pc, bp) …
#define GET_STORE_STACK_TRACE …
#define GET_FATAL_STACK_TRACE_PC_BP(pc, bp) …
#define GET_FATAL_STACK_TRACE …
#define GET_FATAL_STACK_TRACE_IF_EMPTY(STACK) …
class ScopedThreadLocalStateBackup { … };
void MsanTSDInit(void (*destructor)(void *tsd));
void *MsanTSDGet();
void MsanTSDSet(void *tsd);
void MsanTSDDtor(void *tsd);
void InstallAtForkHandler();
}
#endif