xref: /aosp_15_r20/external/compiler-rt/include/sanitizer/msan_interface.h (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //===-- msan_interface.h --------------------------------------------------===//
2*7c3d14c8STreehugger Robot //
3*7c3d14c8STreehugger Robot //                     The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot //
5*7c3d14c8STreehugger Robot // This file is distributed under the University of Illinois Open Source
6*7c3d14c8STreehugger Robot // License. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot //
8*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
9*7c3d14c8STreehugger Robot //
10*7c3d14c8STreehugger Robot // This file is a part of MemorySanitizer.
11*7c3d14c8STreehugger Robot //
12*7c3d14c8STreehugger Robot // Public interface header.
13*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
14*7c3d14c8STreehugger Robot #ifndef MSAN_INTERFACE_H
15*7c3d14c8STreehugger Robot #define MSAN_INTERFACE_H
16*7c3d14c8STreehugger Robot 
17*7c3d14c8STreehugger Robot #include <sanitizer/common_interface_defs.h>
18*7c3d14c8STreehugger Robot 
19*7c3d14c8STreehugger Robot #ifdef __cplusplus
20*7c3d14c8STreehugger Robot extern "C" {
21*7c3d14c8STreehugger Robot #endif
22*7c3d14c8STreehugger Robot   /* Set raw origin for the memory range. */
23*7c3d14c8STreehugger Robot   void __msan_set_origin(const volatile void *a, size_t size, uint32_t origin);
24*7c3d14c8STreehugger Robot 
25*7c3d14c8STreehugger Robot   /* Get raw origin for an address. */
26*7c3d14c8STreehugger Robot   uint32_t __msan_get_origin(const volatile void *a);
27*7c3d14c8STreehugger Robot 
28*7c3d14c8STreehugger Robot   /* Test that this_id is a descendant of prev_id (or they are simply equal).
29*7c3d14c8STreehugger Robot    * "descendant" here means they are part of the same chain, created with
30*7c3d14c8STreehugger Robot    * __msan_chain_origin. */
31*7c3d14c8STreehugger Robot   int __msan_origin_is_descendant_or_same(uint32_t this_id, uint32_t prev_id);
32*7c3d14c8STreehugger Robot 
33*7c3d14c8STreehugger Robot   /* Returns non-zero if tracking origins. */
34*7c3d14c8STreehugger Robot   int __msan_get_track_origins();
35*7c3d14c8STreehugger Robot 
36*7c3d14c8STreehugger Robot   /* Returns the origin id of the latest UMR in the calling thread. */
37*7c3d14c8STreehugger Robot   uint32_t __msan_get_umr_origin();
38*7c3d14c8STreehugger Robot 
39*7c3d14c8STreehugger Robot   /* Make memory region fully initialized (without changing its contents). */
40*7c3d14c8STreehugger Robot   void __msan_unpoison(const volatile void *a, size_t size);
41*7c3d14c8STreehugger Robot 
42*7c3d14c8STreehugger Robot   /* Make a null-terminated string fully initialized (without changing its
43*7c3d14c8STreehugger Robot      contents). */
44*7c3d14c8STreehugger Robot   void __msan_unpoison_string(const volatile char *a);
45*7c3d14c8STreehugger Robot 
46*7c3d14c8STreehugger Robot   /* Make memory region fully uninitialized (without changing its contents).
47*7c3d14c8STreehugger Robot      This is a legacy interface that does not update origin information. Use
48*7c3d14c8STreehugger Robot      __msan_allocated_memory() instead. */
49*7c3d14c8STreehugger Robot   void __msan_poison(const volatile void *a, size_t size);
50*7c3d14c8STreehugger Robot 
51*7c3d14c8STreehugger Robot   /* Make memory region partially uninitialized (without changing its contents).
52*7c3d14c8STreehugger Robot    */
53*7c3d14c8STreehugger Robot   void __msan_partial_poison(const volatile void *data, void *shadow,
54*7c3d14c8STreehugger Robot                              size_t size);
55*7c3d14c8STreehugger Robot 
56*7c3d14c8STreehugger Robot   /* Returns the offset of the first (at least partially) poisoned byte in the
57*7c3d14c8STreehugger Robot      memory range, or -1 if the whole range is good. */
58*7c3d14c8STreehugger Robot   intptr_t __msan_test_shadow(const volatile void *x, size_t size);
59*7c3d14c8STreehugger Robot 
60*7c3d14c8STreehugger Robot   /* Checks that memory range is fully initialized, and reports an error if it
61*7c3d14c8STreehugger Robot    * is not. */
62*7c3d14c8STreehugger Robot   void __msan_check_mem_is_initialized(const volatile void *x, size_t size);
63*7c3d14c8STreehugger Robot 
64*7c3d14c8STreehugger Robot   /* For testing:
65*7c3d14c8STreehugger Robot      __msan_set_expect_umr(1);
66*7c3d14c8STreehugger Robot      ... some buggy code ...
67*7c3d14c8STreehugger Robot      __msan_set_expect_umr(0);
68*7c3d14c8STreehugger Robot      The last line will verify that a UMR happened. */
69*7c3d14c8STreehugger Robot   void __msan_set_expect_umr(int expect_umr);
70*7c3d14c8STreehugger Robot 
71*7c3d14c8STreehugger Robot   /* Change the value of keep_going flag. Non-zero value means don't terminate
72*7c3d14c8STreehugger Robot      program execution when an error is detected. This will not affect error in
73*7c3d14c8STreehugger Robot      modules that were compiled without the corresponding compiler flag. */
74*7c3d14c8STreehugger Robot   void __msan_set_keep_going(int keep_going);
75*7c3d14c8STreehugger Robot 
76*7c3d14c8STreehugger Robot   /* Print shadow and origin for the memory range to stderr in a human-readable
77*7c3d14c8STreehugger Robot      format. */
78*7c3d14c8STreehugger Robot   void __msan_print_shadow(const volatile void *x, size_t size);
79*7c3d14c8STreehugger Robot 
80*7c3d14c8STreehugger Robot   /* Print shadow for the memory range to stderr in a minimalistic
81*7c3d14c8STreehugger Robot      human-readable format. */
82*7c3d14c8STreehugger Robot   void __msan_dump_shadow(const volatile void *x, size_t size);
83*7c3d14c8STreehugger Robot 
84*7c3d14c8STreehugger Robot   /* Returns true if running under a dynamic tool (DynamoRio-based). */
85*7c3d14c8STreehugger Robot   int  __msan_has_dynamic_component();
86*7c3d14c8STreehugger Robot 
87*7c3d14c8STreehugger Robot   /* Tell MSan about newly allocated memory (ex.: custom allocator).
88*7c3d14c8STreehugger Robot      Memory will be marked uninitialized, with origin at the call site. */
89*7c3d14c8STreehugger Robot   void __msan_allocated_memory(const volatile void* data, size_t size);
90*7c3d14c8STreehugger Robot 
91*7c3d14c8STreehugger Robot   /* Tell MSan about newly destroyed memory. Mark memory as uninitialized. */
92*7c3d14c8STreehugger Robot   void __sanitizer_dtor_callback(const volatile void* data, size_t size);
93*7c3d14c8STreehugger Robot 
94*7c3d14c8STreehugger Robot   /* This function may be optionally provided by user and should return
95*7c3d14c8STreehugger Robot      a string containing Msan runtime options. See msan_flags.h for details. */
96*7c3d14c8STreehugger Robot   const char* __msan_default_options();
97*7c3d14c8STreehugger Robot 
98*7c3d14c8STreehugger Robot   /* Deprecated. Call __sanitizer_set_death_callback instead. */
99*7c3d14c8STreehugger Robot   void __msan_set_death_callback(void (*callback)(void));
100*7c3d14c8STreehugger Robot 
101*7c3d14c8STreehugger Robot   /* Update shadow for the application copy of size bytes from src to dst.
102*7c3d14c8STreehugger Robot      Src and dst are application addresses. This function does not copy the
103*7c3d14c8STreehugger Robot      actual application memory, it only updates shadow and origin for such
104*7c3d14c8STreehugger Robot      copy. Source and destination regions can overlap. */
105*7c3d14c8STreehugger Robot   void __msan_copy_shadow(const volatile void *dst, const volatile void *src,
106*7c3d14c8STreehugger Robot                           size_t size);
107*7c3d14c8STreehugger Robot #ifdef __cplusplus
108*7c3d14c8STreehugger Robot }  // extern "C"
109*7c3d14c8STreehugger Robot #endif
110*7c3d14c8STreehugger Robot 
111*7c3d14c8STreehugger Robot #endif
112