• 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 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
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 // Default: -1 (don't exit on error).
110 SANITIZER_INTERFACE_ATTRIBUTE
111 void __msan_set_exit_code(int exit_code);
112 
113 SANITIZER_INTERFACE_ATTRIBUTE
114 void __msan_set_keep_going(int keep_going);
115 
116 SANITIZER_INTERFACE_ATTRIBUTE
117 int __msan_set_poison_in_malloc(int do_poison);
118 
119 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
120 /* OPTIONAL */ const char* __msan_default_options();
121 
122 // For testing.
123 SANITIZER_INTERFACE_ATTRIBUTE
124 void __msan_set_expect_umr(int expect_umr);
125 SANITIZER_INTERFACE_ATTRIBUTE
126 void __msan_print_shadow(const void *x, uptr size);
127 SANITIZER_INTERFACE_ATTRIBUTE
128 void __msan_dump_shadow(const void *x, uptr size);
129 SANITIZER_INTERFACE_ATTRIBUTE
130 int  __msan_has_dynamic_component();
131 
132 // For testing.
133 SANITIZER_INTERFACE_ATTRIBUTE
134 u32 __msan_get_umr_origin();
135 SANITIZER_INTERFACE_ATTRIBUTE
136 void __msan_partial_poison(const void* data, void* shadow, uptr size);
137 
138 // Tell MSan about newly allocated memory (ex.: custom allocator).
139 // Memory will be marked uninitialized, with origin at the call site.
140 SANITIZER_INTERFACE_ATTRIBUTE
141 void __msan_allocated_memory(const void* data, uptr size);
142 
143 SANITIZER_INTERFACE_ATTRIBUTE
144 u16 __sanitizer_unaligned_load16(const uu16 *p);
145 
146 SANITIZER_INTERFACE_ATTRIBUTE
147 u32 __sanitizer_unaligned_load32(const uu32 *p);
148 
149 SANITIZER_INTERFACE_ATTRIBUTE
150 u64 __sanitizer_unaligned_load64(const uu64 *p);
151 
152 SANITIZER_INTERFACE_ATTRIBUTE
153 void __sanitizer_unaligned_store16(uu16 *p, u16 x);
154 
155 SANITIZER_INTERFACE_ATTRIBUTE
156 void __sanitizer_unaligned_store32(uu32 *p, u32 x);
157 
158 SANITIZER_INTERFACE_ATTRIBUTE
159 void __sanitizer_unaligned_store64(uu64 *p, u64 x);
160 
161 SANITIZER_INTERFACE_ATTRIBUTE
162 void __msan_set_death_callback(void (*callback)(void));
163 }  // extern "C"
164 
165 #endif  // MSAN_INTERFACE_INTERNAL_H
166