• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #include "sanitizer_common/sanitizer_internal_defs.h"
19 
20 extern "C" {
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 common_flags()->exitcode.
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
41 void __msan_maybe_warning_1(u8 s, u32 o);
42 SANITIZER_INTERFACE_ATTRIBUTE
43 void __msan_maybe_warning_2(u16 s, u32 o);
44 SANITIZER_INTERFACE_ATTRIBUTE
45 void __msan_maybe_warning_4(u32 s, u32 o);
46 SANITIZER_INTERFACE_ATTRIBUTE
47 void __msan_maybe_warning_8(u64 s, u32 o);
48 
49 SANITIZER_INTERFACE_ATTRIBUTE
50 void __msan_maybe_store_origin_1(u8 s, void *p, u32 o);
51 SANITIZER_INTERFACE_ATTRIBUTE
52 void __msan_maybe_store_origin_2(u16 s, void *p, u32 o);
53 SANITIZER_INTERFACE_ATTRIBUTE
54 void __msan_maybe_store_origin_4(u32 s, void *p, u32 o);
55 SANITIZER_INTERFACE_ATTRIBUTE
56 void __msan_maybe_store_origin_8(u64 s, void *p, u32 o);
57 
58 SANITIZER_INTERFACE_ATTRIBUTE
59 void __msan_unpoison(const void *a, uptr size);
60 SANITIZER_INTERFACE_ATTRIBUTE
61 void __msan_unpoison_string(const char *s);
62 SANITIZER_INTERFACE_ATTRIBUTE
63 void __msan_clear_and_unpoison(void *a, uptr size);
64 SANITIZER_INTERFACE_ATTRIBUTE
65 void* __msan_memcpy(void *dst, const void *src, uptr size);
66 SANITIZER_INTERFACE_ATTRIBUTE
67 void* __msan_memset(void *s, int c, uptr n);
68 SANITIZER_INTERFACE_ATTRIBUTE
69 void* __msan_memmove(void* dest, const void* src, uptr n);
70 SANITIZER_INTERFACE_ATTRIBUTE
71 void __msan_poison(const void *a, uptr size);
72 SANITIZER_INTERFACE_ATTRIBUTE
73 void __msan_poison_stack(void *a, uptr size);
74 
75 // Copy size bytes from src to dst and unpoison the result.
76 // Useful to implement unsafe loads.
77 SANITIZER_INTERFACE_ATTRIBUTE
78 void __msan_load_unpoisoned(void *src, uptr size, void *dst);
79 
80 // Returns the offset of the first (at least partially) poisoned byte,
81 // or -1 if the whole range is good.
82 SANITIZER_INTERFACE_ATTRIBUTE
83 sptr __msan_test_shadow(const void *x, uptr size);
84 
85 SANITIZER_INTERFACE_ATTRIBUTE
86 void __msan_check_mem_is_initialized(const void *x, uptr size);
87 
88 SANITIZER_INTERFACE_ATTRIBUTE
89 void __msan_set_origin(const void *a, uptr size, u32 origin);
90 SANITIZER_INTERFACE_ATTRIBUTE
91 void __msan_set_alloca_origin(void *a, uptr size, char *descr);
92 SANITIZER_INTERFACE_ATTRIBUTE
93 void __msan_set_alloca_origin4(void *a, uptr size, char *descr, uptr pc);
94 SANITIZER_INTERFACE_ATTRIBUTE
95 u32 __msan_chain_origin(u32 id);
96 SANITIZER_INTERFACE_ATTRIBUTE
97 u32 __msan_get_origin(const void *a);
98 
99 // Test that this_id is a descendant of prev_id (or they are simply equal).
100 // "descendant" here means that are part of the same chain, created with
101 // __msan_chain_origin.
102 SANITIZER_INTERFACE_ATTRIBUTE
103 int __msan_origin_is_descendant_or_same(u32 this_id, u32 prev_id);
104 
105 
106 SANITIZER_INTERFACE_ATTRIBUTE
107 void __msan_clear_on_return();
108 
109 SANITIZER_INTERFACE_ATTRIBUTE
110 void __msan_set_keep_going(int keep_going);
111 
112 SANITIZER_INTERFACE_ATTRIBUTE
113 int __msan_set_poison_in_malloc(int do_poison);
114 
115 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
116 /* OPTIONAL */ const char* __msan_default_options();
117 
118 // For testing.
119 SANITIZER_INTERFACE_ATTRIBUTE
120 void __msan_set_expect_umr(int expect_umr);
121 SANITIZER_INTERFACE_ATTRIBUTE
122 void __msan_print_shadow(const void *x, uptr size);
123 SANITIZER_INTERFACE_ATTRIBUTE
124 void __msan_dump_shadow(const void *x, uptr size);
125 SANITIZER_INTERFACE_ATTRIBUTE
126 int  __msan_has_dynamic_component();
127 
128 // For testing.
129 SANITIZER_INTERFACE_ATTRIBUTE
130 u32 __msan_get_umr_origin();
131 SANITIZER_INTERFACE_ATTRIBUTE
132 void __msan_partial_poison(const void* data, void* shadow, uptr size);
133 
134 // Tell MSan about newly allocated memory (ex.: custom allocator).
135 // Memory will be marked uninitialized, with origin at the call site.
136 SANITIZER_INTERFACE_ATTRIBUTE
137 void __msan_allocated_memory(const void* data, uptr size);
138 
139 // Tell MSan about newly destroyed memory. Memory will be marked
140 // uninitialized.
141 SANITIZER_INTERFACE_ATTRIBUTE
142 void __sanitizer_dtor_callback(const void* data, uptr size);
143 
144 SANITIZER_INTERFACE_ATTRIBUTE
145 u16 __sanitizer_unaligned_load16(const uu16 *p);
146 
147 SANITIZER_INTERFACE_ATTRIBUTE
148 u32 __sanitizer_unaligned_load32(const uu32 *p);
149 
150 SANITIZER_INTERFACE_ATTRIBUTE
151 u64 __sanitizer_unaligned_load64(const uu64 *p);
152 
153 SANITIZER_INTERFACE_ATTRIBUTE
154 void __sanitizer_unaligned_store16(uu16 *p, u16 x);
155 
156 SANITIZER_INTERFACE_ATTRIBUTE
157 void __sanitizer_unaligned_store32(uu32 *p, u32 x);
158 
159 SANITIZER_INTERFACE_ATTRIBUTE
160 void __sanitizer_unaligned_store64(uu64 *p, u64 x);
161 
162 SANITIZER_INTERFACE_ATTRIBUTE
163 void __msan_set_death_callback(void (*callback)(void));
164 
165 SANITIZER_INTERFACE_ATTRIBUTE
166 void __msan_copy_shadow(void *dst, const void *src, uptr size);
167 }  // extern "C"
168 
169 #endif  // MSAN_INTERFACE_INTERNAL_H
170