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