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
19extern "C" {
20// FIXME: document all interface functions.
21
22SANITIZER_INTERFACE_ATTRIBUTE
23int __msan_get_track_origins();
24
25SANITIZER_INTERFACE_ATTRIBUTE
26void __msan_init();
27
28// Print a warning and maybe return.
29// This function can die based on common_flags()->exitcode.
30SANITIZER_INTERFACE_ATTRIBUTE
31void __msan_warning();
32
33// Print a warning and die.
34// Instrumentation inserts calls to this function when building in "fast" mode
35// (i.e. -mllvm -msan-keep-going)
36SANITIZER_INTERFACE_ATTRIBUTE __attribute__((noreturn))
37void __msan_warning_noreturn();
38
39using __sanitizer::uptr;
40using __sanitizer::sptr;
41using __sanitizer::uu64;
42using __sanitizer::uu32;
43using __sanitizer::uu16;
44using __sanitizer::u64;
45using __sanitizer::u32;
46using __sanitizer::u16;
47using __sanitizer::u8;
48
49// Versions of the above which take Origin as a parameter
50SANITIZER_INTERFACE_ATTRIBUTE
51void __msan_warning_with_origin(u32 origin);
52SANITIZER_INTERFACE_ATTRIBUTE __attribute__((noreturn)) void
53__msan_warning_with_origin_noreturn(u32 origin);
54
55SANITIZER_INTERFACE_ATTRIBUTE
56void __msan_maybe_warning_1(u8 s, u32 o);
57SANITIZER_INTERFACE_ATTRIBUTE
58void __msan_maybe_warning_2(u16 s, u32 o);
59SANITIZER_INTERFACE_ATTRIBUTE
60void __msan_maybe_warning_4(u32 s, u32 o);
61SANITIZER_INTERFACE_ATTRIBUTE
62void __msan_maybe_warning_8(u64 s, u32 o);
63
64SANITIZER_INTERFACE_ATTRIBUTE
65void __msan_maybe_store_origin_1(u8 s, void *p, u32 o);
66SANITIZER_INTERFACE_ATTRIBUTE
67void __msan_maybe_store_origin_2(u16 s, void *p, u32 o);
68SANITIZER_INTERFACE_ATTRIBUTE
69void __msan_maybe_store_origin_4(u32 s, void *p, u32 o);
70SANITIZER_INTERFACE_ATTRIBUTE
71void __msan_maybe_store_origin_8(u64 s, void *p, u32 o);
72
73SANITIZER_INTERFACE_ATTRIBUTE
74void __msan_unpoison(const void *a, uptr size);
75SANITIZER_INTERFACE_ATTRIBUTE
76void __msan_unpoison_string(const char *s);
77SANITIZER_INTERFACE_ATTRIBUTE
78void __msan_unpoison_param(uptr n);
79SANITIZER_INTERFACE_ATTRIBUTE
80void __msan_clear_and_unpoison(void *a, uptr size);
81SANITIZER_INTERFACE_ATTRIBUTE
82void* __msan_memcpy(void *dst, const void *src, uptr size);
83SANITIZER_INTERFACE_ATTRIBUTE
84void* __msan_memset(void *s, int c, uptr n);
85SANITIZER_INTERFACE_ATTRIBUTE
86void* __msan_memmove(void* dest, const void* src, uptr n);
87SANITIZER_INTERFACE_ATTRIBUTE
88void __msan_poison(const void *a, uptr size);
89SANITIZER_INTERFACE_ATTRIBUTE
90void __msan_poison_stack(void *a, uptr size);
91
92// Copy size bytes from src to dst and unpoison the result.
93// Useful to implement unsafe loads.
94SANITIZER_INTERFACE_ATTRIBUTE
95void __msan_load_unpoisoned(void *src, uptr size, void *dst);
96
97// Returns the offset of the first (at least partially) poisoned byte,
98// or -1 if the whole range is good.
99SANITIZER_INTERFACE_ATTRIBUTE
100sptr __msan_test_shadow(const void *x, uptr size);
101
102SANITIZER_INTERFACE_ATTRIBUTE
103void __msan_check_mem_is_initialized(const void *x, uptr size);
104
105SANITIZER_INTERFACE_ATTRIBUTE
106void __msan_set_origin(const void *a, uptr size, u32 origin);
107SANITIZER_INTERFACE_ATTRIBUTE
108void __msan_set_alloca_origin(void *a, uptr size, char *descr);
109SANITIZER_INTERFACE_ATTRIBUTE
110void __msan_set_alloca_origin4(void *a, uptr size, char *descr, uptr pc);
111SANITIZER_INTERFACE_ATTRIBUTE
112void __msan_set_alloca_origin_with_descr(void *a, uptr size, u32 *id_ptr,
113 char *descr);
114SANITIZER_INTERFACE_ATTRIBUTE
115void __msan_set_alloca_origin_no_descr(void *a, uptr size, u32 *id_ptr);
116SANITIZER_INTERFACE_ATTRIBUTE
117u32 __msan_chain_origin(u32 id);
118SANITIZER_INTERFACE_ATTRIBUTE
119u32 __msan_get_origin(const void *a);
120
121// Test that this_id is a descendant of prev_id (or they are simply equal).
122// "descendant" here means that are part of the same chain, created with
123// __msan_chain_origin.
124SANITIZER_INTERFACE_ATTRIBUTE
125int __msan_origin_is_descendant_or_same(u32 this_id, u32 prev_id);
126
127
128SANITIZER_INTERFACE_ATTRIBUTE
129void __msan_clear_on_return();
130
131SANITIZER_INTERFACE_ATTRIBUTE
132void __msan_set_keep_going(int keep_going);
133
134SANITIZER_INTERFACE_ATTRIBUTE
135int __msan_set_poison_in_malloc(int do_poison);
136
137SANITIZER_INTERFACE_ATTRIBUTE
138const char *__msan_default_options();
139
140// For testing.
141SANITIZER_INTERFACE_ATTRIBUTE
142void __msan_set_expect_umr(int expect_umr);
143SANITIZER_INTERFACE_ATTRIBUTE
144void __msan_print_shadow(const void *x, uptr size);
145SANITIZER_INTERFACE_ATTRIBUTE
146void __msan_dump_shadow(const void *x, uptr size);
147SANITIZER_INTERFACE_ATTRIBUTE
148int __msan_has_dynamic_component();
149
150// For testing.
151SANITIZER_INTERFACE_ATTRIBUTE
152u32 __msan_get_umr_origin();
153SANITIZER_INTERFACE_ATTRIBUTE
154void __msan_partial_poison(const void* data, void* shadow, uptr size);
155
156// Tell MSan about newly allocated memory (ex.: custom allocator).
157// Memory will be marked uninitialized, with origin at the call site.
158SANITIZER_INTERFACE_ATTRIBUTE
159void __msan_allocated_memory(const void* data, uptr size);
160
161// Tell MSan about newly destroyed memory. Memory will be marked
162// uninitialized.
163SANITIZER_INTERFACE_ATTRIBUTE
164void __sanitizer_dtor_callback(const void* data, uptr size);
165SANITIZER_INTERFACE_ATTRIBUTE
166void __sanitizer_dtor_callback_fields(const void *data, uptr size);
167SANITIZER_INTERFACE_ATTRIBUTE
168void __sanitizer_dtor_callback_vptr(const void *data);
169
170SANITIZER_INTERFACE_ATTRIBUTE
171u16 __sanitizer_unaligned_load16(const uu16 *p);
172
173SANITIZER_INTERFACE_ATTRIBUTE
174u32 __sanitizer_unaligned_load32(const uu32 *p);
175
176SANITIZER_INTERFACE_ATTRIBUTE
177u64 __sanitizer_unaligned_load64(const uu64 *p);
178
179SANITIZER_INTERFACE_ATTRIBUTE
180void __sanitizer_unaligned_store16(uu16 *p, u16 x);
181
182SANITIZER_INTERFACE_ATTRIBUTE
183void __sanitizer_unaligned_store32(uu32 *p, u32 x);
184
185SANITIZER_INTERFACE_ATTRIBUTE
186void __sanitizer_unaligned_store64(uu64 *p, u64 x);
187
188SANITIZER_INTERFACE_ATTRIBUTE
189void __msan_set_death_callback(void (*callback)(void));
190
191SANITIZER_INTERFACE_ATTRIBUTE
192void __msan_copy_shadow(void *dst, const void *src, uptr size);
193
194SANITIZER_INTERFACE_ATTRIBUTE
195void __msan_scoped_disable_interceptor_checks();
196
197SANITIZER_INTERFACE_ATTRIBUTE
198void __msan_scoped_enable_interceptor_checks();
199
200SANITIZER_INTERFACE_ATTRIBUTE
201void __msan_start_switch_fiber(const void *bottom, uptr size);
202
203SANITIZER_INTERFACE_ATTRIBUTE
204void __msan_finish_switch_fiber(const void **bottom_old, uptr *size_old);
205} // extern "C"
206
207#endif // MSAN_INTERFACE_INTERNAL_H
208