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