1 //===-- msan_interface.h --------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of MemorySanitizer.
12 // Public interface header.
13 //===----------------------------------------------------------------------===//
14 #ifndef MSAN_INTERFACE_H
15 #define MSAN_INTERFACE_H
17 #include <sanitizer/common_interface_defs.h>
22 /* Set raw origin for the memory range. */
23 void __msan_set_origin(const volatile void *a, size_t size, uint32_t origin);
25 /* Get raw origin for an address. */
26 uint32_t __msan_get_origin(const volatile void *a);
28 /* Test that this_id is a descendant of prev_id (or they are simply equal).
29 * "descendant" here means they are part of the same chain, created with
30 * __msan_chain_origin. */
31 int __msan_origin_is_descendant_or_same(uint32_t this_id, uint32_t prev_id);
33 /* Returns non-zero if tracking origins. */
34 int __msan_get_track_origins();
36 /* Returns the origin id of the latest UMR in the calling thread. */
37 uint32_t __msan_get_umr_origin();
39 /* Make memory region fully initialized (without changing its contents). */
40 void __msan_unpoison(const volatile void *a, size_t size);
42 /* Make a null-terminated string fully initialized (without changing its
44 void __msan_unpoison_string(const volatile char *a);
46 /* Make memory region fully uninitialized (without changing its contents).
47 This is a legacy interface that does not update origin information. Use
48 __msan_allocated_memory() instead. */
49 void __msan_poison(const volatile void *a, size_t size);
51 /* Make memory region partially uninitialized (without changing its contents).
53 void __msan_partial_poison(const volatile void *data, void *shadow,
56 /* Returns the offset of the first (at least partially) poisoned byte in the
57 memory range, or -1 if the whole range is good. */
58 intptr_t __msan_test_shadow(const volatile void *x, size_t size);
60 /* Checks that memory range is fully initialized, and reports an error if it
62 void __msan_check_mem_is_initialized(const volatile void *x, size_t size);
64 /* Set exit code when error(s) were detected.
65 Value of 0 means don't change the program exit code. */
66 void __msan_set_exit_code(int exit_code);
69 __msan_set_expect_umr(1);
70 ... some buggy code ...
71 __msan_set_expect_umr(0);
72 The last line will verify that a UMR happened. */
73 void __msan_set_expect_umr(int expect_umr);
75 /* Change the value of keep_going flag. Non-zero value means don't terminate
76 program execution when an error is detected. This will not affect error in
77 modules that were compiled without the corresponding compiler flag. */
78 void __msan_set_keep_going(int keep_going);
80 /* Print shadow and origin for the memory range to stderr in a human-readable
82 void __msan_print_shadow(const volatile void *x, size_t size);
84 /* Print shadow for the memory range to stderr in a minimalistic
85 human-readable format. */
86 void __msan_dump_shadow(const volatile void *x, size_t size);
88 /* Returns true if running under a dynamic tool (DynamoRio-based). */
89 int __msan_has_dynamic_component();
91 /* Tell MSan about newly allocated memory (ex.: custom allocator).
92 Memory will be marked uninitialized, with origin at the call site. */
93 void __msan_allocated_memory(const volatile void* data, size_t size);
95 /* This function may be optionally provided by user and should return
96 a string containing Msan runtime options. See msan_flags.h for details. */
97 const char* __msan_default_options();
99 /* Sets the callback to be called right before death on error.
100 Passing 0 will unset the callback. */
101 void __msan_set_death_callback(void (*callback)(void));