xref: /netbsd-src/external/gpl3/gcc/dist/libsanitizer/include/sanitizer/msan_interface.h (revision 9616dacfef448e70e3fbbd865bddf60d54b656c5)
1 //===-- msan_interface.h --------------------------------------------------===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is a part of MemorySanitizer.
9 //
10 // Public interface header.
11 //===----------------------------------------------------------------------===//
12 #ifndef MSAN_INTERFACE_H
13 #define MSAN_INTERFACE_H
14 
15 #include <sanitizer/common_interface_defs.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20   /* Set raw origin for the memory range. */
21   void __msan_set_origin(const volatile void *a, size_t size, uint32_t origin);
22 
23   /* Get raw origin for an address. */
24   uint32_t __msan_get_origin(const volatile void *a);
25 
26   /* Returns non-zero if tracking origins. */
27   int __msan_get_track_origins();
28 
29   /* Returns the origin id of the latest UMR in the calling thread. */
30   uint32_t __msan_get_umr_origin();
31 
32   /* Make memory region fully initialized (without changing its contents). */
33   void __msan_unpoison(const volatile void *a, size_t size);
34 
35   /* Make a null-terminated string fully initialized (without changing its
36      contents). */
37   void __msan_unpoison_string(const volatile char *a);
38 
39   /* Make memory region fully uninitialized (without changing its contents). */
40   void __msan_poison(const volatile void *a, size_t size);
41 
42   /* Make memory region partially uninitialized (without changing its contents).
43    */
44   void __msan_partial_poison(const volatile void *data, void *shadow,
45                              size_t size);
46 
47   /* Returns the offset of the first (at least partially) poisoned byte in the
48      memory range, or -1 if the whole range is good. */
49   intptr_t __msan_test_shadow(const volatile void *x, size_t size);
50 
51   /* Checks that memory range is fully initialized, and reports an error if it
52    * is not. */
53   void __msan_check_mem_is_initialized(const volatile void *x, size_t size);
54 
55   /* Set exit code when error(s) were detected.
56      Value of 0 means don't change the program exit code. */
57   void __msan_set_exit_code(int exit_code);
58 
59   /* For testing:
60      __msan_set_expect_umr(1);
61      ... some buggy code ...
62      __msan_set_expect_umr(0);
63      The last line will verify that a UMR happened. */
64   void __msan_set_expect_umr(int expect_umr);
65 
66   /* Change the value of keep_going flag. Non-zero value means don't terminate
67      program execution when an error is detected. This will not affect error in
68      modules that were compiled without the corresponding compiler flag. */
69   void __msan_set_keep_going(int keep_going);
70 
71   /* Print shadow and origin for the memory range to stderr in a human-readable
72      format. */
73   void __msan_print_shadow(const volatile void *x, size_t size);
74 
75   /* Print shadow for the memory range to stderr in a minimalistic
76      human-readable format. */
77   void __msan_dump_shadow(const volatile void *x, size_t size);
78 
79   /* Returns true if running under a dynamic tool (DynamoRio-based). */
80   int  __msan_has_dynamic_component();
81 
82   /* Tell MSan about newly allocated memory (ex.: custom allocator).
83      Memory will be marked uninitialized, with origin at the call site. */
84   void __msan_allocated_memory(const volatile void* data, size_t size);
85 
86   /* This function may be optionally provided by user and should return
87      a string containing Msan runtime options. See msan_flags.h for details. */
88   const char* __msan_default_options();
89 
90   /* Sets the callback to be called right before death on error.
91      Passing 0 will unset the callback. */
92   void __msan_set_death_callback(void (*callback)(void));
93 
94 #ifdef __cplusplus
95 }  // extern "C"
96 #endif
97 
98 #endif
99