1 //===-- msan_interface_internal.h -------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file is a part of MemorySanitizer. 10 // 11 // Private MSan interface header. 12 //===----------------------------------------------------------------------===// 13 14 #ifndef MSAN_INTERFACE_INTERNAL_H 15 #define MSAN_INTERFACE_INTERNAL_H 16 17 #include "sanitizer_common/sanitizer_internal_defs.h" 18 19 extern "C" { 20 // FIXME: document all interface functions. 21 22 SANITIZER_INTERFACE_ATTRIBUTE 23 int __msan_get_track_origins(); 24 25 SANITIZER_INTERFACE_ATTRIBUTE 26 void __msan_init(); 27 28 // Print a warning and maybe return. 29 // This function can die based on common_flags()->exitcode. 30 SANITIZER_INTERFACE_ATTRIBUTE 31 void __msan_warning(); 32 33 // Print a warning and die. 34 // Intrumentation inserts calls to this function when building in "fast" mode 35 // (i.e. -mllvm -msan-keep-going) 36 SANITIZER_INTERFACE_ATTRIBUTE __attribute__((noreturn)) 37 void __msan_warning_noreturn(); 38 39 using __sanitizer::uptr; 40 using __sanitizer::sptr; 41 using __sanitizer::uu64; 42 using __sanitizer::uu32; 43 using __sanitizer::uu16; 44 using __sanitizer::u64; 45 using __sanitizer::u32; 46 using __sanitizer::u16; 47 using __sanitizer::u8; 48 49 SANITIZER_INTERFACE_ATTRIBUTE 50 void __msan_maybe_warning_1(u8 s, u32 o); 51 SANITIZER_INTERFACE_ATTRIBUTE 52 void __msan_maybe_warning_2(u16 s, u32 o); 53 SANITIZER_INTERFACE_ATTRIBUTE 54 void __msan_maybe_warning_4(u32 s, u32 o); 55 SANITIZER_INTERFACE_ATTRIBUTE 56 void __msan_maybe_warning_8(u64 s, u32 o); 57 58 SANITIZER_INTERFACE_ATTRIBUTE 59 void __msan_maybe_store_origin_1(u8 s, void *p, u32 o); 60 SANITIZER_INTERFACE_ATTRIBUTE 61 void __msan_maybe_store_origin_2(u16 s, void *p, u32 o); 62 SANITIZER_INTERFACE_ATTRIBUTE 63 void __msan_maybe_store_origin_4(u32 s, void *p, u32 o); 64 SANITIZER_INTERFACE_ATTRIBUTE 65 void __msan_maybe_store_origin_8(u64 s, void *p, u32 o); 66 67 SANITIZER_INTERFACE_ATTRIBUTE 68 void __msan_unpoison(const void *a, uptr size); 69 SANITIZER_INTERFACE_ATTRIBUTE 70 void __msan_unpoison_string(const char *s); 71 SANITIZER_INTERFACE_ATTRIBUTE 72 void __msan_unpoison_param(uptr n); 73 SANITIZER_INTERFACE_ATTRIBUTE 74 void __msan_clear_and_unpoison(void *a, uptr size); 75 SANITIZER_INTERFACE_ATTRIBUTE 76 void* __msan_memcpy(void *dst, const void *src, uptr size); 77 SANITIZER_INTERFACE_ATTRIBUTE 78 void* __msan_memset(void *s, int c, uptr n); 79 SANITIZER_INTERFACE_ATTRIBUTE 80 void* __msan_memmove(void* dest, const void* src, uptr n); 81 SANITIZER_INTERFACE_ATTRIBUTE 82 void __msan_poison(const void *a, uptr size); 83 SANITIZER_INTERFACE_ATTRIBUTE 84 void __msan_poison_stack(void *a, uptr size); 85 86 // Copy size bytes from src to dst and unpoison the result. 87 // Useful to implement unsafe loads. 88 SANITIZER_INTERFACE_ATTRIBUTE 89 void __msan_load_unpoisoned(void *src, uptr size, void *dst); 90 91 // Returns the offset of the first (at least partially) poisoned byte, 92 // or -1 if the whole range is good. 93 SANITIZER_INTERFACE_ATTRIBUTE 94 sptr __msan_test_shadow(const void *x, uptr size); 95 96 SANITIZER_INTERFACE_ATTRIBUTE 97 void __msan_check_mem_is_initialized(const void *x, uptr size); 98 99 SANITIZER_INTERFACE_ATTRIBUTE 100 void __msan_set_origin(const void *a, uptr size, u32 origin); 101 SANITIZER_INTERFACE_ATTRIBUTE 102 void __msan_set_alloca_origin(void *a, uptr size, char *descr); 103 SANITIZER_INTERFACE_ATTRIBUTE 104 void __msan_set_alloca_origin4(void *a, uptr size, char *descr, uptr pc); 105 SANITIZER_INTERFACE_ATTRIBUTE 106 u32 __msan_chain_origin(u32 id); 107 SANITIZER_INTERFACE_ATTRIBUTE 108 u32 __msan_get_origin(const void *a); 109 110 // Test that this_id is a descendant of prev_id (or they are simply equal). 111 // "descendant" here means that are part of the same chain, created with 112 // __msan_chain_origin. 113 SANITIZER_INTERFACE_ATTRIBUTE 114 int __msan_origin_is_descendant_or_same(u32 this_id, u32 prev_id); 115 116 117 SANITIZER_INTERFACE_ATTRIBUTE 118 void __msan_clear_on_return(); 119 120 SANITIZER_INTERFACE_ATTRIBUTE 121 void __msan_set_keep_going(int keep_going); 122 123 SANITIZER_INTERFACE_ATTRIBUTE 124 int __msan_set_poison_in_malloc(int do_poison); 125 126 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE 127 /* OPTIONAL */ const char* __msan_default_options(); 128 129 // For testing. 130 SANITIZER_INTERFACE_ATTRIBUTE 131 void __msan_set_expect_umr(int expect_umr); 132 SANITIZER_INTERFACE_ATTRIBUTE 133 void __msan_print_shadow(const void *x, uptr size); 134 SANITIZER_INTERFACE_ATTRIBUTE 135 void __msan_dump_shadow(const void *x, uptr size); 136 SANITIZER_INTERFACE_ATTRIBUTE 137 int __msan_has_dynamic_component(); 138 139 // For testing. 140 SANITIZER_INTERFACE_ATTRIBUTE 141 u32 __msan_get_umr_origin(); 142 SANITIZER_INTERFACE_ATTRIBUTE 143 void __msan_partial_poison(const void* data, void* shadow, uptr size); 144 145 // Tell MSan about newly allocated memory (ex.: custom allocator). 146 // Memory will be marked uninitialized, with origin at the call site. 147 SANITIZER_INTERFACE_ATTRIBUTE 148 void __msan_allocated_memory(const void* data, uptr size); 149 150 // Tell MSan about newly destroyed memory. Memory will be marked 151 // uninitialized. 152 SANITIZER_INTERFACE_ATTRIBUTE 153 void __sanitizer_dtor_callback(const void* data, uptr size); 154 155 SANITIZER_INTERFACE_ATTRIBUTE 156 u16 __sanitizer_unaligned_load16(const uu16 *p); 157 158 SANITIZER_INTERFACE_ATTRIBUTE 159 u32 __sanitizer_unaligned_load32(const uu32 *p); 160 161 SANITIZER_INTERFACE_ATTRIBUTE 162 u64 __sanitizer_unaligned_load64(const uu64 *p); 163 164 SANITIZER_INTERFACE_ATTRIBUTE 165 void __sanitizer_unaligned_store16(uu16 *p, u16 x); 166 167 SANITIZER_INTERFACE_ATTRIBUTE 168 void __sanitizer_unaligned_store32(uu32 *p, u32 x); 169 170 SANITIZER_INTERFACE_ATTRIBUTE 171 void __sanitizer_unaligned_store64(uu64 *p, u64 x); 172 173 SANITIZER_INTERFACE_ATTRIBUTE 174 void __msan_set_death_callback(void (*callback)(void)); 175 176 SANITIZER_INTERFACE_ATTRIBUTE 177 void __msan_copy_shadow(void *dst, const void *src, uptr size); 178 179 SANITIZER_INTERFACE_ATTRIBUTE 180 void __msan_scoped_disable_interceptor_checks(); 181 182 SANITIZER_INTERFACE_ATTRIBUTE 183 void __msan_scoped_enable_interceptor_checks(); 184 } // extern "C" 185 186 #endif // MSAN_INTERFACE_INTERNAL_H 187