• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- asan_interface_internal.h -------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file is a part of AddressSanitizer, an address sanity checker.
11 //
12 // This header declares the AddressSanitizer runtime interface functions.
13 // The runtime library has to define these functions so the instrumented program
14 // could call them.
15 //
16 // See also include/sanitizer/asan_interface.h
17 //===----------------------------------------------------------------------===//
18 #ifndef ASAN_INTERFACE_INTERNAL_H
19 #define ASAN_INTERFACE_INTERNAL_H
20 
21 #include "sanitizer_common/sanitizer_internal_defs.h"
22 
23 #include "asan_init_version.h"
24 
25 using __sanitizer::uptr;
26 
27 extern "C" {
28   // This function should be called at the very beginning of the process,
29   // before any instrumented code is executed and before any call to malloc.
30   SANITIZER_INTERFACE_ATTRIBUTE void __asan_init();
31 
32   // This function exists purely to get a linker/loader error when using
33   // incompatible versions of instrumentation and runtime library. Please note
34   // that __asan_version_mismatch_check is a macro that is replaced with
35   // __asan_version_mismatch_check_vXXX at compile-time.
36   SANITIZER_INTERFACE_ATTRIBUTE void __asan_version_mismatch_check();
37 
38   // This structure is used to describe the source location of a place where
39   // global was defined.
40   struct __asan_global_source_location {
41     const char *filename;
42     int line_no;
43     int column_no;
44   };
45 
46   // This structure describes an instrumented global variable.
47   struct __asan_global {
48     uptr beg;                // The address of the global.
49     uptr size;               // The original size of the global.
50     uptr size_with_redzone;  // The size with the redzone.
51     const char *name;        // Name as a C string.
52     const char *module_name; // Module name as a C string. This pointer is a
53                              // unique identifier of a module.
54     uptr has_dynamic_init;   // Non-zero if the global has dynamic initializer.
55     __asan_global_source_location *location;  // Source location of a global,
56                                               // or NULL if it is unknown.
57     uptr odr_indicator;      // The address of the ODR indicator symbol.
58   };
59 
60   // These functions can be called on some platforms to find globals in the same
61   // loaded image as `flag' and apply __asan_(un)register_globals to them,
62   // filtering out redundant calls.
63   SANITIZER_INTERFACE_ATTRIBUTE
64   void __asan_register_image_globals(uptr *flag);
65   SANITIZER_INTERFACE_ATTRIBUTE
66   void __asan_unregister_image_globals(uptr *flag);
67 
68   // These two functions should be called by the instrumented code.
69   // 'globals' is an array of structures describing 'n' globals.
70   SANITIZER_INTERFACE_ATTRIBUTE
71   void __asan_register_globals(__asan_global *globals, uptr n);
72   SANITIZER_INTERFACE_ATTRIBUTE
73   void __asan_unregister_globals(__asan_global *globals, uptr n);
74 
75   // These two functions should be called before and after dynamic initializers
76   // of a single module run, respectively.
77   SANITIZER_INTERFACE_ATTRIBUTE
78   void __asan_before_dynamic_init(const char *module_name);
79   SANITIZER_INTERFACE_ATTRIBUTE
80   void __asan_after_dynamic_init();
81 
82   // These two functions are used by instrumented code in the
83   // use-after-scope mode. They mark memory for local variables as
84   // unaddressable when they leave scope and addressable before the
85   // function exits.
86   SANITIZER_INTERFACE_ATTRIBUTE
87   void __asan_poison_stack_memory(uptr addr, uptr size);
88   SANITIZER_INTERFACE_ATTRIBUTE
89   void __asan_unpoison_stack_memory(uptr addr, uptr size);
90 
91   // Performs cleanup before a NoReturn function. Must be called before things
92   // like _exit and execl to avoid false positives on stack.
93   SANITIZER_INTERFACE_ATTRIBUTE void __asan_handle_no_return();
94 
95   SANITIZER_INTERFACE_ATTRIBUTE
96   void __asan_poison_memory_region(void const volatile *addr, uptr size);
97   SANITIZER_INTERFACE_ATTRIBUTE
98   void __asan_unpoison_memory_region(void const volatile *addr, uptr size);
99 
100   SANITIZER_INTERFACE_ATTRIBUTE
101   int __asan_address_is_poisoned(void const volatile *addr);
102 
103   SANITIZER_INTERFACE_ATTRIBUTE
104   uptr __asan_region_is_poisoned(uptr beg, uptr size);
105 
106   SANITIZER_INTERFACE_ATTRIBUTE
107   void __asan_describe_address(uptr addr);
108 
109   SANITIZER_INTERFACE_ATTRIBUTE
110   int __asan_report_present();
111 
112   SANITIZER_INTERFACE_ATTRIBUTE
113   uptr __asan_get_report_pc();
114   SANITIZER_INTERFACE_ATTRIBUTE
115   uptr __asan_get_report_bp();
116   SANITIZER_INTERFACE_ATTRIBUTE
117   uptr __asan_get_report_sp();
118   SANITIZER_INTERFACE_ATTRIBUTE
119   uptr __asan_get_report_address();
120   SANITIZER_INTERFACE_ATTRIBUTE
121   int __asan_get_report_access_type();
122   SANITIZER_INTERFACE_ATTRIBUTE
123   uptr __asan_get_report_access_size();
124   SANITIZER_INTERFACE_ATTRIBUTE
125   const char * __asan_get_report_description();
126 
127   SANITIZER_INTERFACE_ATTRIBUTE
128   const char * __asan_locate_address(uptr addr, char *name, uptr name_size,
129                                      uptr *region_address, uptr *region_size);
130 
131   SANITIZER_INTERFACE_ATTRIBUTE
132   uptr __asan_get_alloc_stack(uptr addr, uptr *trace, uptr size,
133                               u32 *thread_id);
134 
135   SANITIZER_INTERFACE_ATTRIBUTE
136   uptr __asan_get_free_stack(uptr addr, uptr *trace, uptr size,
137                              u32 *thread_id);
138 
139   SANITIZER_INTERFACE_ATTRIBUTE
140   void __asan_get_shadow_mapping(uptr *shadow_scale, uptr *shadow_offset);
141 
142   SANITIZER_INTERFACE_ATTRIBUTE
143   void __asan_report_error(uptr pc, uptr bp, uptr sp,
144                            uptr addr, int is_write, uptr access_size, u32 exp);
145 
146   SANITIZER_INTERFACE_ATTRIBUTE
147   void __asan_set_death_callback(void (*callback)(void));
148   SANITIZER_INTERFACE_ATTRIBUTE
149   void __asan_set_error_report_callback(void (*callback)(const char*));
150 
151   SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
152   /* OPTIONAL */ void __asan_on_error();
153 
154   SANITIZER_INTERFACE_ATTRIBUTE void __asan_print_accumulated_stats();
155 
156   SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
157   /* OPTIONAL */ const char* __asan_default_options();
158 
159   // Global flag, copy of ASAN_OPTIONS=detect_stack_use_after_return
160   SANITIZER_INTERFACE_ATTRIBUTE
161   extern int __asan_option_detect_stack_use_after_return;
162 
163   SANITIZER_INTERFACE_ATTRIBUTE
164   extern uptr *__asan_test_only_reported_buggy_pointer;
165 
166   SANITIZER_INTERFACE_ATTRIBUTE void __asan_load1(uptr p);
167   SANITIZER_INTERFACE_ATTRIBUTE void __asan_load2(uptr p);
168   SANITIZER_INTERFACE_ATTRIBUTE void __asan_load4(uptr p);
169   SANITIZER_INTERFACE_ATTRIBUTE void __asan_load8(uptr p);
170   SANITIZER_INTERFACE_ATTRIBUTE void __asan_load16(uptr p);
171   SANITIZER_INTERFACE_ATTRIBUTE void __asan_store1(uptr p);
172   SANITIZER_INTERFACE_ATTRIBUTE void __asan_store2(uptr p);
173   SANITIZER_INTERFACE_ATTRIBUTE void __asan_store4(uptr p);
174   SANITIZER_INTERFACE_ATTRIBUTE void __asan_store8(uptr p);
175   SANITIZER_INTERFACE_ATTRIBUTE void __asan_store16(uptr p);
176   SANITIZER_INTERFACE_ATTRIBUTE void __asan_loadN(uptr p, uptr size);
177   SANITIZER_INTERFACE_ATTRIBUTE void __asan_storeN(uptr p, uptr size);
178 
179   SANITIZER_INTERFACE_ATTRIBUTE void __asan_load1_noabort(uptr p);
180   SANITIZER_INTERFACE_ATTRIBUTE void __asan_load2_noabort(uptr p);
181   SANITIZER_INTERFACE_ATTRIBUTE void __asan_load4_noabort(uptr p);
182   SANITIZER_INTERFACE_ATTRIBUTE void __asan_load8_noabort(uptr p);
183   SANITIZER_INTERFACE_ATTRIBUTE void __asan_load16_noabort(uptr p);
184   SANITIZER_INTERFACE_ATTRIBUTE void __asan_store1_noabort(uptr p);
185   SANITIZER_INTERFACE_ATTRIBUTE void __asan_store2_noabort(uptr p);
186   SANITIZER_INTERFACE_ATTRIBUTE void __asan_store4_noabort(uptr p);
187   SANITIZER_INTERFACE_ATTRIBUTE void __asan_store8_noabort(uptr p);
188   SANITIZER_INTERFACE_ATTRIBUTE void __asan_store16_noabort(uptr p);
189   SANITIZER_INTERFACE_ATTRIBUTE void __asan_loadN_noabort(uptr p, uptr size);
190   SANITIZER_INTERFACE_ATTRIBUTE void __asan_storeN_noabort(uptr p, uptr size);
191 
192   SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_load1(uptr p, u32 exp);
193   SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_load2(uptr p, u32 exp);
194   SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_load4(uptr p, u32 exp);
195   SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_load8(uptr p, u32 exp);
196   SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_load16(uptr p, u32 exp);
197   SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_store1(uptr p, u32 exp);
198   SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_store2(uptr p, u32 exp);
199   SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_store4(uptr p, u32 exp);
200   SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_store8(uptr p, u32 exp);
201   SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_store16(uptr p, u32 exp);
202   SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_loadN(uptr p, uptr size,
203                                                       u32 exp);
204   SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_storeN(uptr p, uptr size,
205                                                        u32 exp);
206 
207   SANITIZER_INTERFACE_ATTRIBUTE
208       void* __asan_memcpy(void *dst, const void *src, uptr size);
209   SANITIZER_INTERFACE_ATTRIBUTE
210       void* __asan_memset(void *s, int c, uptr n);
211   SANITIZER_INTERFACE_ATTRIBUTE
212       void* __asan_memmove(void* dest, const void* src, uptr n);
213 
214   SANITIZER_INTERFACE_ATTRIBUTE
215   void __asan_poison_cxx_array_cookie(uptr p);
216   SANITIZER_INTERFACE_ATTRIBUTE
217   uptr __asan_load_cxx_array_cookie(uptr *p);
218   SANITIZER_INTERFACE_ATTRIBUTE
219   void __asan_poison_intra_object_redzone(uptr p, uptr size);
220   SANITIZER_INTERFACE_ATTRIBUTE
221   void __asan_unpoison_intra_object_redzone(uptr p, uptr size);
222   SANITIZER_INTERFACE_ATTRIBUTE
223   void __asan_alloca_poison(uptr addr, uptr size);
224   SANITIZER_INTERFACE_ATTRIBUTE
225   void __asan_allocas_unpoison(uptr top, uptr bottom);
226 }  // extern "C"
227 
228 #endif  // ASAN_INTERFACE_INTERNAL_H
229