1 //===-- asan_interface_internal.h -------------------------------*- C++ -*-===//
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 AddressSanitizer, an address sanity checker.
12 // This header can be included by the instrumented program to fetch
13 // data (mostly allocator statistics) from ASan runtime library.
14 //===----------------------------------------------------------------------===//
15 #ifndef ASAN_INTERFACE_INTERNAL_H
16 #define ASAN_INTERFACE_INTERNAL_H
18 #include "sanitizer_common/sanitizer_internal_defs.h"
20 #include "asan_init_version.h"
22 using __sanitizer::uptr;
25 // This function should be called at the very beginning of the process,
26 // before any instrumented code is executed and before any call to malloc.
27 // Please note that __asan_init is a macro that is replaced with
28 // __asan_init_vXXX at compile-time.
29 SANITIZER_INTERFACE_ATTRIBUTE void __asan_init();
31 // This structure is used to describe the source location of a place where
32 // global was defined.
33 struct __asan_global_source_location {
39 // This structure describes an instrumented global variable.
40 struct __asan_global {
41 uptr beg; // The address of the global.
42 uptr size; // The original size of the global.
43 uptr size_with_redzone; // The size with the redzone.
44 const char *name; // Name as a C string.
45 const char *module_name; // Module name as a C string. This pointer is a
46 // unique identifier of a module.
47 uptr has_dynamic_init; // Non-zero if the global has dynamic initializer.
48 __asan_global_source_location *location; // Source location of a global,
49 // or NULL if it is unknown.
52 // These two functions should be called by the instrumented code.
53 // 'globals' is an array of structures describing 'n' globals.
54 SANITIZER_INTERFACE_ATTRIBUTE
55 void __asan_register_globals(__asan_global *globals, uptr n);
56 SANITIZER_INTERFACE_ATTRIBUTE
57 void __asan_unregister_globals(__asan_global *globals, uptr n);
59 // These two functions should be called before and after dynamic initializers
60 // of a single module run, respectively.
61 SANITIZER_INTERFACE_ATTRIBUTE
62 void __asan_before_dynamic_init(const char *module_name);
63 SANITIZER_INTERFACE_ATTRIBUTE
64 void __asan_after_dynamic_init();
66 // These two functions are used by instrumented code in the
67 // use-after-scope mode. They mark memory for local variables as
68 // unaddressable when they leave scope and addressable before the
70 SANITIZER_INTERFACE_ATTRIBUTE
71 void __asan_poison_stack_memory(uptr addr, uptr size);
72 SANITIZER_INTERFACE_ATTRIBUTE
73 void __asan_unpoison_stack_memory(uptr addr, uptr size);
75 // Performs cleanup before a NoReturn function. Must be called before things
76 // like _exit and execl to avoid false positives on stack.
77 SANITIZER_INTERFACE_ATTRIBUTE void __asan_handle_no_return();
79 SANITIZER_INTERFACE_ATTRIBUTE
80 void __asan_poison_memory_region(void const volatile *addr, uptr size);
81 SANITIZER_INTERFACE_ATTRIBUTE
82 void __asan_unpoison_memory_region(void const volatile *addr, uptr size);
84 SANITIZER_INTERFACE_ATTRIBUTE
85 int __asan_address_is_poisoned(void const volatile *addr);
87 SANITIZER_INTERFACE_ATTRIBUTE
88 uptr __asan_region_is_poisoned(uptr beg, uptr size);
90 SANITIZER_INTERFACE_ATTRIBUTE
91 void __asan_describe_address(uptr addr);
93 SANITIZER_INTERFACE_ATTRIBUTE
94 int __asan_report_present();
96 SANITIZER_INTERFACE_ATTRIBUTE
97 uptr __asan_get_report_pc();
98 SANITIZER_INTERFACE_ATTRIBUTE
99 uptr __asan_get_report_bp();
100 SANITIZER_INTERFACE_ATTRIBUTE
101 uptr __asan_get_report_sp();
102 SANITIZER_INTERFACE_ATTRIBUTE
103 uptr __asan_get_report_address();
104 SANITIZER_INTERFACE_ATTRIBUTE
105 int __asan_get_report_access_type();
106 SANITIZER_INTERFACE_ATTRIBUTE
107 uptr __asan_get_report_access_size();
108 SANITIZER_INTERFACE_ATTRIBUTE
109 const char * __asan_get_report_description();
111 SANITIZER_INTERFACE_ATTRIBUTE
112 const char * __asan_locate_address(uptr addr, char *name, uptr name_size,
113 uptr *region_address, uptr *region_size);
115 SANITIZER_INTERFACE_ATTRIBUTE
116 uptr __asan_get_alloc_stack(uptr addr, uptr *trace, uptr size,
119 SANITIZER_INTERFACE_ATTRIBUTE
120 uptr __asan_get_free_stack(uptr addr, uptr *trace, uptr size,
123 SANITIZER_INTERFACE_ATTRIBUTE
124 void __asan_get_shadow_mapping(uptr *shadow_scale, uptr *shadow_offset);
126 SANITIZER_INTERFACE_ATTRIBUTE
127 void __asan_report_error(uptr pc, uptr bp, uptr sp,
128 uptr addr, int is_write, uptr access_size);
130 SANITIZER_INTERFACE_ATTRIBUTE
131 int __asan_set_error_exit_code(int exit_code);
132 SANITIZER_INTERFACE_ATTRIBUTE
133 void __asan_set_death_callback(void (*callback)(void));
134 SANITIZER_INTERFACE_ATTRIBUTE
135 void __asan_set_error_report_callback(void (*callback)(const char*));
137 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
138 /* OPTIONAL */ void __asan_on_error();
140 SANITIZER_INTERFACE_ATTRIBUTE void __asan_print_accumulated_stats();
142 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
143 /* OPTIONAL */ const char* __asan_default_options();
145 // Global flag, copy of ASAN_OPTIONS=detect_stack_use_after_return
146 SANITIZER_INTERFACE_ATTRIBUTE
147 extern int __asan_option_detect_stack_use_after_return;
149 SANITIZER_INTERFACE_ATTRIBUTE
150 extern uptr *__asan_test_only_reported_buggy_pointer;
152 SANITIZER_INTERFACE_ATTRIBUTE void __asan_load1(uptr p);
153 SANITIZER_INTERFACE_ATTRIBUTE void __asan_load2(uptr p);
154 SANITIZER_INTERFACE_ATTRIBUTE void __asan_load4(uptr p);
155 SANITIZER_INTERFACE_ATTRIBUTE void __asan_load8(uptr p);
156 SANITIZER_INTERFACE_ATTRIBUTE void __asan_load16(uptr p);
157 SANITIZER_INTERFACE_ATTRIBUTE void __asan_store1(uptr p);
158 SANITIZER_INTERFACE_ATTRIBUTE void __asan_store2(uptr p);
159 SANITIZER_INTERFACE_ATTRIBUTE void __asan_store4(uptr p);
160 SANITIZER_INTERFACE_ATTRIBUTE void __asan_store8(uptr p);
161 SANITIZER_INTERFACE_ATTRIBUTE void __asan_store16(uptr p);
162 SANITIZER_INTERFACE_ATTRIBUTE void __asan_loadN(uptr p, uptr size);
163 SANITIZER_INTERFACE_ATTRIBUTE void __asan_storeN(uptr p, uptr size);
165 SANITIZER_INTERFACE_ATTRIBUTE
166 void* __asan_memcpy(void *dst, const void *src, uptr size);
167 SANITIZER_INTERFACE_ATTRIBUTE
168 void* __asan_memset(void *s, int c, uptr n);
169 SANITIZER_INTERFACE_ATTRIBUTE
170 void* __asan_memmove(void* dest, const void* src, uptr n);
172 SANITIZER_INTERFACE_ATTRIBUTE
173 void __asan_poison_cxx_array_cookie(uptr p);
174 SANITIZER_INTERFACE_ATTRIBUTE
175 uptr __asan_load_cxx_array_cookie(uptr *p);
176 SANITIZER_INTERFACE_ATTRIBUTE
177 void __asan_poison_intra_object_redzone(uptr p, uptr size);
178 SANITIZER_INTERFACE_ATTRIBUTE
179 void __asan_unpoison_intra_object_redzone(uptr p, uptr size);
182 #endif // ASAN_INTERFACE_INTERNAL_H