Evgeniy Stepanov | 12c4693 | 2013-01-29 14:33:29 +0000 | [diff] [blame] | 1 | //===-- msan_interface_internal.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 interface header. |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef MSAN_INTERFACE_INTERNAL_H |
| 16 | #define MSAN_INTERFACE_INTERNAL_H |
| 17 | |
Evgeniy Stepanov | 250f221 | 2013-01-30 13:12:08 +0000 | [diff] [blame] | 18 | #include "sanitizer_common/sanitizer_internal_defs.h" |
Evgeniy Stepanov | 12c4693 | 2013-01-29 14:33:29 +0000 | [diff] [blame] | 19 | |
| 20 | extern "C" { |
Evgeniy Stepanov | 12c4693 | 2013-01-29 14:33:29 +0000 | [diff] [blame] | 21 | // FIXME: document all interface functions. |
| 22 | |
| 23 | SANITIZER_INTERFACE_ATTRIBUTE |
| 24 | int __msan_get_track_origins(); |
| 25 | |
| 26 | SANITIZER_INTERFACE_ATTRIBUTE |
| 27 | void __msan_init(); |
| 28 | |
| 29 | // Print a warning and maybe return. |
| 30 | // This function can die based on flags()->exit_code. |
| 31 | SANITIZER_INTERFACE_ATTRIBUTE |
| 32 | void __msan_warning(); |
| 33 | |
| 34 | // Print a warning and die. |
| 35 | // Intrumentation inserts calls to this function when building in "fast" mode |
| 36 | // (i.e. -mllvm -msan-keep-going) |
| 37 | SANITIZER_INTERFACE_ATTRIBUTE __attribute__((noreturn)) |
| 38 | void __msan_warning_noreturn(); |
| 39 | |
| 40 | SANITIZER_INTERFACE_ATTRIBUTE |
Alexey Samsonov | 11347bf | 2013-04-23 13:34:19 +0000 | [diff] [blame] | 41 | void __msan_unpoison(const void *a, uptr size); |
Evgeniy Stepanov | 12c4693 | 2013-01-29 14:33:29 +0000 | [diff] [blame] | 42 | SANITIZER_INTERFACE_ATTRIBUTE |
| 43 | void __msan_clear_and_unpoison(void *a, uptr size); |
| 44 | SANITIZER_INTERFACE_ATTRIBUTE |
| 45 | void* __msan_memcpy(void *dst, const void *src, uptr size); |
| 46 | SANITIZER_INTERFACE_ATTRIBUTE |
| 47 | void* __msan_memset(void *s, int c, uptr n); |
| 48 | SANITIZER_INTERFACE_ATTRIBUTE |
| 49 | void* __msan_memmove(void* dest, const void* src, uptr n); |
| 50 | SANITIZER_INTERFACE_ATTRIBUTE |
| 51 | void __msan_copy_poison(void *dst, const void *src, uptr size); |
| 52 | SANITIZER_INTERFACE_ATTRIBUTE |
| 53 | void __msan_copy_origin(void *dst, const void *src, uptr size); |
| 54 | SANITIZER_INTERFACE_ATTRIBUTE |
| 55 | void __msan_move_poison(void *dst, const void *src, uptr size); |
| 56 | SANITIZER_INTERFACE_ATTRIBUTE |
Alexey Samsonov | 11347bf | 2013-04-23 13:34:19 +0000 | [diff] [blame] | 57 | void __msan_poison(const void *a, uptr size); |
Evgeniy Stepanov | 12c4693 | 2013-01-29 14:33:29 +0000 | [diff] [blame] | 58 | SANITIZER_INTERFACE_ATTRIBUTE |
| 59 | void __msan_poison_stack(void *a, uptr size); |
| 60 | |
| 61 | // Copy size bytes from src to dst and unpoison the result. |
| 62 | // Useful to implement unsafe loads. |
| 63 | SANITIZER_INTERFACE_ATTRIBUTE |
| 64 | void __msan_load_unpoisoned(void *src, uptr size, void *dst); |
| 65 | |
| 66 | // Returns the offset of the first (at least partially) poisoned byte, |
| 67 | // or -1 if the whole range is good. |
| 68 | SANITIZER_INTERFACE_ATTRIBUTE |
| 69 | sptr __msan_test_shadow(const void *x, uptr size); |
| 70 | |
| 71 | SANITIZER_INTERFACE_ATTRIBUTE |
Alexey Samsonov | 11347bf | 2013-04-23 13:34:19 +0000 | [diff] [blame] | 72 | void __msan_set_origin(const void *a, uptr size, u32 origin); |
Evgeniy Stepanov | 12c4693 | 2013-01-29 14:33:29 +0000 | [diff] [blame] | 73 | SANITIZER_INTERFACE_ATTRIBUTE |
| 74 | void __msan_set_alloca_origin(void *a, uptr size, const char *descr); |
| 75 | SANITIZER_INTERFACE_ATTRIBUTE |
Alexey Samsonov | 11347bf | 2013-04-23 13:34:19 +0000 | [diff] [blame] | 76 | u32 __msan_get_origin(const void *a); |
Evgeniy Stepanov | 12c4693 | 2013-01-29 14:33:29 +0000 | [diff] [blame] | 77 | |
| 78 | SANITIZER_INTERFACE_ATTRIBUTE |
| 79 | void __msan_clear_on_return(); |
| 80 | |
| 81 | // Default: -1 (don't exit on error). |
| 82 | SANITIZER_INTERFACE_ATTRIBUTE |
| 83 | void __msan_set_exit_code(int exit_code); |
| 84 | |
| 85 | SANITIZER_INTERFACE_ATTRIBUTE |
Evgeniy Stepanov | bb881c7 | 2013-06-21 12:37:58 +0000 | [diff] [blame] | 86 | void __msan_set_keep_going(int keep_going); |
| 87 | |
| 88 | SANITIZER_INTERFACE_ATTRIBUTE |
Evgeniy Stepanov | 12c4693 | 2013-01-29 14:33:29 +0000 | [diff] [blame] | 89 | int __msan_set_poison_in_malloc(int do_poison); |
| 90 | |
Kostya Serebryany | 70c6e3f | 2013-02-13 07:19:47 +0000 | [diff] [blame] | 91 | SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE |
| 92 | /* OPTIONAL */ const char* __msan_default_options(); |
| 93 | |
Evgeniy Stepanov | 12c4693 | 2013-01-29 14:33:29 +0000 | [diff] [blame] | 94 | // For testing. |
| 95 | SANITIZER_INTERFACE_ATTRIBUTE |
| 96 | void __msan_set_expect_umr(int expect_umr); |
| 97 | SANITIZER_INTERFACE_ATTRIBUTE |
| 98 | void __msan_print_shadow(const void *x, uptr size); |
| 99 | SANITIZER_INTERFACE_ATTRIBUTE |
| 100 | void __msan_print_param_shadow(); |
| 101 | SANITIZER_INTERFACE_ATTRIBUTE |
| 102 | int __msan_has_dynamic_component(); |
| 103 | |
| 104 | // Returns x such that %fs:x is the first byte of __msan_retval_tls. |
| 105 | SANITIZER_INTERFACE_ATTRIBUTE |
| 106 | int __msan_get_retval_tls_offset(); |
| 107 | SANITIZER_INTERFACE_ATTRIBUTE |
| 108 | int __msan_get_param_tls_offset(); |
| 109 | |
Reid Kleckner | 0f92deb | 2013-03-11 18:07:42 +0000 | [diff] [blame] | 110 | // For intercepting mmap from ld.so in msandr. |
| 111 | SANITIZER_INTERFACE_ATTRIBUTE |
| 112 | bool __msan_is_in_loader(); |
| 113 | |
Evgeniy Stepanov | 12c4693 | 2013-01-29 14:33:29 +0000 | [diff] [blame] | 114 | // For testing. |
| 115 | SANITIZER_INTERFACE_ATTRIBUTE |
| 116 | u32 __msan_get_umr_origin(); |
| 117 | SANITIZER_INTERFACE_ATTRIBUTE |
| 118 | const char *__msan_get_origin_descr_if_stack(u32 id); |
| 119 | SANITIZER_INTERFACE_ATTRIBUTE |
Alexey Samsonov | 11347bf | 2013-04-23 13:34:19 +0000 | [diff] [blame] | 120 | void __msan_partial_poison(const void* data, void* shadow, uptr size); |
Evgeniy Stepanov | 12c4693 | 2013-01-29 14:33:29 +0000 | [diff] [blame] | 121 | |
| 122 | // Tell MSan about newly allocated memory (ex.: custom allocator). |
| 123 | // Memory will be marked uninitialized, with origin at the call site. |
| 124 | SANITIZER_INTERFACE_ATTRIBUTE |
Alexey Samsonov | 11347bf | 2013-04-23 13:34:19 +0000 | [diff] [blame] | 125 | void __msan_allocated_memory(const void* data, uptr size); |
Evgeniy Stepanov | 12c4693 | 2013-01-29 14:33:29 +0000 | [diff] [blame] | 126 | |
Evgeniy Stepanov | f43f602 | 2013-06-04 13:08:36 +0000 | [diff] [blame] | 127 | SANITIZER_INTERFACE_ATTRIBUTE |
Evgeniy Stepanov | 2e9ffcb | 2013-06-04 13:49:10 +0000 | [diff] [blame] | 128 | u16 __sanitizer_unaligned_load16(const uu16 *p); |
Evgeniy Stepanov | f43f602 | 2013-06-04 13:08:36 +0000 | [diff] [blame] | 129 | |
| 130 | SANITIZER_INTERFACE_ATTRIBUTE |
Evgeniy Stepanov | 2e9ffcb | 2013-06-04 13:49:10 +0000 | [diff] [blame] | 131 | u32 __sanitizer_unaligned_load32(const uu32 *p); |
Evgeniy Stepanov | f43f602 | 2013-06-04 13:08:36 +0000 | [diff] [blame] | 132 | |
| 133 | SANITIZER_INTERFACE_ATTRIBUTE |
Evgeniy Stepanov | 2e9ffcb | 2013-06-04 13:49:10 +0000 | [diff] [blame] | 134 | u64 __sanitizer_unaligned_load64(const uu64 *p); |
Evgeniy Stepanov | f43f602 | 2013-06-04 13:08:36 +0000 | [diff] [blame] | 135 | |
| 136 | SANITIZER_INTERFACE_ATTRIBUTE |
Evgeniy Stepanov | 2e9ffcb | 2013-06-04 13:49:10 +0000 | [diff] [blame] | 137 | void __sanitizer_unaligned_store16(uu16 *p, u16 x); |
Evgeniy Stepanov | f43f602 | 2013-06-04 13:08:36 +0000 | [diff] [blame] | 138 | |
| 139 | SANITIZER_INTERFACE_ATTRIBUTE |
Evgeniy Stepanov | 2e9ffcb | 2013-06-04 13:49:10 +0000 | [diff] [blame] | 140 | void __sanitizer_unaligned_store32(uu32 *p, u32 x); |
Evgeniy Stepanov | f43f602 | 2013-06-04 13:08:36 +0000 | [diff] [blame] | 141 | |
| 142 | SANITIZER_INTERFACE_ATTRIBUTE |
Evgeniy Stepanov | 2e9ffcb | 2013-06-04 13:49:10 +0000 | [diff] [blame] | 143 | void __sanitizer_unaligned_store64(uu64 *p, u64 x); |
Evgeniy Stepanov | f43f602 | 2013-06-04 13:08:36 +0000 | [diff] [blame] | 144 | } // extern "C" |
| 145 | |
Evgeniy Stepanov | 12c4693 | 2013-01-29 14:33:29 +0000 | [diff] [blame] | 146 | #endif // MSAN_INTERFACE_INTERNAL_H |