Evgeniy Stepanov | 97edeb3 | 2012-12-25 11:53:51 +0000 | [diff] [blame] | 1 | //===-- msan.h --------------------------------------------------*- C++ -*-===// |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 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 | |
Sergey Matveev | 0b4bf4d | 2013-05-06 13:15:14 +0000 | [diff] [blame] | 18 | #include "sanitizer_common/sanitizer_flags.h" |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 19 | #include "sanitizer_common/sanitizer_internal_defs.h" |
| 20 | #include "sanitizer_common/sanitizer_stacktrace.h" |
Evgeniy Stepanov | 12c4693 | 2013-01-29 14:33:29 +0000 | [diff] [blame] | 21 | #include "msan_interface_internal.h" |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 22 | #include "msan_flags.h" |
| 23 | |
Evgeniy Stepanov | a897400 | 2013-04-05 12:03:47 +0000 | [diff] [blame] | 24 | #ifndef MSAN_REPLACE_OPERATORS_NEW_AND_DELETE |
| 25 | # define MSAN_REPLACE_OPERATORS_NEW_AND_DELETE 1 |
| 26 | #endif |
| 27 | |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 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 | |
Reid Kleckner | 0f92deb | 2013-03-11 18:07:42 +0000 | [diff] [blame] | 34 | struct link_map; // Opaque type returned by dlopen(). |
| 35 | |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 36 | const int kMsanParamTlsSizeInWords = 100; |
| 37 | const int kMsanRetvalTlsSizeInWords = 100; |
| 38 | |
| 39 | namespace __msan { |
| 40 | extern int msan_inited; |
| 41 | extern bool msan_init_is_running; |
Evgeniy Stepanov | 99bf1d7 | 2013-01-10 11:17:55 +0000 | [diff] [blame] | 42 | extern int msan_report_count; |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 43 | |
| 44 | bool ProtectRange(uptr beg, uptr end); |
| 45 | bool InitShadow(bool prot1, bool prot2, bool map_shadow, bool init_origins); |
| 46 | char *GetProcSelfMaps(); |
| 47 | void InitializeInterceptors(); |
| 48 | |
| 49 | void *MsanReallocate(StackTrace *stack, void *oldp, uptr size, |
| 50 | uptr alignment, bool zeroise); |
| 51 | void MsanDeallocate(void *ptr); |
| 52 | void InstallTrapHandler(); |
Evgeniy Stepanov | 99bf1d7 | 2013-01-10 11:17:55 +0000 | [diff] [blame] | 53 | void InstallAtExitHandler(); |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 54 | void ReplaceOperatorsNewAndDelete(); |
| 55 | |
Kostya Serebryany | 70c6e3f | 2013-02-13 07:19:47 +0000 | [diff] [blame] | 56 | void EnterSymbolizer(); |
| 57 | void ExitSymbolizer(); |
| 58 | bool IsInSymbolizer(); |
| 59 | |
Reid Kleckner | 93c2602 | 2013-03-06 16:11:58 +0000 | [diff] [blame] | 60 | struct SymbolizerScope { |
| 61 | SymbolizerScope() { EnterSymbolizer(); } |
| 62 | ~SymbolizerScope() { ExitSymbolizer(); } |
| 63 | }; |
| 64 | |
Reid Kleckner | 0f92deb | 2013-03-11 18:07:42 +0000 | [diff] [blame] | 65 | void EnterLoader(); |
| 66 | void ExitLoader(); |
| 67 | |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 68 | void MsanDie(); |
| 69 | void PrintWarning(uptr pc, uptr bp); |
| 70 | void PrintWarningWithOrigin(uptr pc, uptr bp, u32 origin); |
| 71 | |
Evgeniy Stepanov | efbc435 | 2013-02-19 12:43:18 +0000 | [diff] [blame] | 72 | void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp, |
| 73 | bool fast); |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 74 | |
Evgeniy Stepanov | db010da | 2012-12-26 09:32:05 +0000 | [diff] [blame] | 75 | void ReportUMR(StackTrace *stack, u32 origin); |
| 76 | void ReportExpectedUMRNotFound(StackTrace *stack); |
Evgeniy Stepanov | 99bf1d7 | 2013-01-10 11:17:55 +0000 | [diff] [blame] | 77 | void ReportAtExitStatistics(); |
Evgeniy Stepanov | db010da | 2012-12-26 09:32:05 +0000 | [diff] [blame] | 78 | |
Reid Kleckner | 0f92deb | 2013-03-11 18:07:42 +0000 | [diff] [blame] | 79 | void UnpoisonMappedDSO(struct link_map *map); |
Alexey Samsonov | c2918bf | 2013-06-27 07:50:56 +0000 | [diff] [blame] | 80 | // Unpoison first n function arguments. |
| 81 | void UnpoisonParam(uptr n); |
Reid Kleckner | 0f92deb | 2013-03-11 18:07:42 +0000 | [diff] [blame] | 82 | |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 83 | #define GET_MALLOC_STACK_TRACE \ |
| 84 | StackTrace stack; \ |
| 85 | stack.size = 0; \ |
| 86 | if (__msan_get_track_origins() && msan_inited) \ |
Sergey Matveev | 0b4bf4d | 2013-05-06 13:15:14 +0000 | [diff] [blame] | 87 | GetStackTrace(&stack, common_flags()->malloc_context_size, \ |
Evgeniy Stepanov | efbc435 | 2013-02-19 12:43:18 +0000 | [diff] [blame] | 88 | StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(), \ |
Sergey Matveev | 0b4bf4d | 2013-05-06 13:15:14 +0000 | [diff] [blame] | 89 | common_flags()->fast_unwind_on_malloc) |
Evgeniy Stepanov | 78c56c3 | 2012-12-11 12:27:27 +0000 | [diff] [blame] | 90 | |
| 91 | } // namespace __msan |
| 92 | |
| 93 | #endif // MSAN_H |