1 //===-- msan.h --------------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file is a part of MemorySanitizer. 11 // 12 // Private MSan header. 13 //===----------------------------------------------------------------------===// 14 15 #ifndef MSAN_H 16 #define MSAN_H 17 18 #include "sanitizer_common/sanitizer_flags.h" 19 #include "sanitizer_common/sanitizer_internal_defs.h" 20 #include "sanitizer_common/sanitizer_stacktrace.h" 21 #include "msan_interface_internal.h" 22 #include "msan_flags.h" 23 24 #ifndef MSAN_REPLACE_OPERATORS_NEW_AND_DELETE 25 # define MSAN_REPLACE_OPERATORS_NEW_AND_DELETE 1 26 #endif 27 28 #define MEM_TO_SHADOW(mem) (((uptr)mem) & ~0x400000000000ULL) 29 #define MEM_TO_ORIGIN(mem) (MEM_TO_SHADOW(mem) + 0x200000000000ULL) 30 #define MEM_IS_APP(mem) ((uptr)mem >= 0x600000000000ULL) 31 #define MEM_IS_SHADOW(mem) ((uptr)mem >= 0x200000000000ULL && \ 32 (uptr)mem <= 0x400000000000ULL) 33 34 const int kMsanParamTlsSizeInWords = 100; 35 const int kMsanRetvalTlsSizeInWords = 100; 36 37 namespace __msan { 38 extern int msan_inited; 39 extern bool msan_init_is_running; 40 extern int msan_report_count; 41 42 bool ProtectRange(uptr beg, uptr end); 43 bool InitShadow(bool prot1, bool prot2, bool map_shadow, bool init_origins); 44 char *GetProcSelfMaps(); 45 void InitializeInterceptors(); 46 47 void *MsanReallocate(StackTrace *stack, void *oldp, uptr size, 48 uptr alignment, bool zeroise); 49 void MsanDeallocate(void *ptr); 50 void InstallTrapHandler(); 51 void InstallAtExitHandler(); 52 void ReplaceOperatorsNewAndDelete(); 53 54 void EnterSymbolizer(); 55 void ExitSymbolizer(); 56 bool IsInSymbolizer(); 57 58 struct SymbolizerScope { 59 SymbolizerScope() { EnterSymbolizer(); } 60 ~SymbolizerScope() { ExitSymbolizer(); } 61 }; 62 63 void EnterLoader(); 64 void ExitLoader(); 65 66 void MsanDie(); 67 void PrintWarning(uptr pc, uptr bp); 68 void PrintWarningWithOrigin(uptr pc, uptr bp, u32 origin); 69 70 void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp, 71 bool fast); 72 73 void ReportUMR(StackTrace *stack, u32 origin); 74 void ReportExpectedUMRNotFound(StackTrace *stack); 75 void ReportAtExitStatistics(); 76 77 // Unpoison first n function arguments. 78 void UnpoisonParam(uptr n); 79 80 #define GET_MALLOC_STACK_TRACE \ 81 StackTrace stack; \ 82 stack.size = 0; \ 83 if (__msan_get_track_origins() && msan_inited) \ 84 GetStackTrace(&stack, common_flags()->malloc_context_size, \ 85 StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(), \ 86 common_flags()->fast_unwind_on_malloc) 87 88 } // namespace __msan 89 90 #define MSAN_MALLOC_HOOK(ptr, size) \ 91 if (&__msan_malloc_hook) __msan_malloc_hook(ptr, size) 92 #define MSAN_FREE_HOOK(ptr) \ 93 if (&__msan_free_hook) __msan_free_hook(ptr) 94 95 #endif // MSAN_H 96