gcc/
[official-gcc.git] / libsanitizer / asan / asan_interface_internal.h
blob1940477f247642cefb56af143d58b668da9138e0
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 using __sanitizer::uptr;
20 extern "C" {
21 // This function should be called at the very beginning of the process,
22 // before any instrumented code is executed and before any call to malloc.
23 // Every time the asan ABI changes we also change the version number in this
24 // name. Objects build with incompatible asan ABI version
25 // will not link with run-time.
26 // Changes between ABI versions:
27 // v1=>v2: added 'module_name' to __asan_global
28 // v2=>v3: stack frame description (created by the compiler)
29 // contains the function PC as the 3-rd field (see
30 // DescribeAddressIfStack).
31 SANITIZER_INTERFACE_ATTRIBUTE void __asan_init_v3();
32 #define __asan_init __asan_init_v3
34 // This structure describes an instrumented global variable.
35 struct __asan_global {
36 uptr beg; // The address of the global.
37 uptr size; // The original size of the global.
38 uptr size_with_redzone; // The size with the redzone.
39 const char *name; // Name as a C string.
40 const char *module_name; // Module name as a C string. This pointer is a
41 // unique identifier of a module.
42 uptr has_dynamic_init; // Non-zero if the global has dynamic initializer.
45 // These two functions should be called by the instrumented code.
46 // 'globals' is an array of structures describing 'n' globals.
47 SANITIZER_INTERFACE_ATTRIBUTE
48 void __asan_register_globals(__asan_global *globals, uptr n);
49 SANITIZER_INTERFACE_ATTRIBUTE
50 void __asan_unregister_globals(__asan_global *globals, uptr n);
52 // These two functions should be called before and after dynamic initializers
53 // of a single module run, respectively.
54 SANITIZER_INTERFACE_ATTRIBUTE
55 void __asan_before_dynamic_init(const char *module_name);
56 SANITIZER_INTERFACE_ATTRIBUTE
57 void __asan_after_dynamic_init();
59 // These two functions are used by instrumented code in the
60 // use-after-scope mode. They mark memory for local variables as
61 // unaddressable when they leave scope and addressable before the
62 // function exits.
63 SANITIZER_INTERFACE_ATTRIBUTE
64 void __asan_poison_stack_memory(uptr addr, uptr size);
65 SANITIZER_INTERFACE_ATTRIBUTE
66 void __asan_unpoison_stack_memory(uptr addr, uptr size);
68 // Performs cleanup before a NoReturn function. Must be called before things
69 // like _exit and execl to avoid false positives on stack.
70 SANITIZER_INTERFACE_ATTRIBUTE void __asan_handle_no_return();
72 SANITIZER_INTERFACE_ATTRIBUTE
73 void __asan_poison_memory_region(void const volatile *addr, uptr size);
74 SANITIZER_INTERFACE_ATTRIBUTE
75 void __asan_unpoison_memory_region(void const volatile *addr, uptr size);
77 SANITIZER_INTERFACE_ATTRIBUTE
78 int __asan_address_is_poisoned(void const volatile *addr);
80 SANITIZER_INTERFACE_ATTRIBUTE
81 uptr __asan_region_is_poisoned(uptr beg, uptr size);
83 SANITIZER_INTERFACE_ATTRIBUTE
84 void __asan_describe_address(uptr addr);
86 SANITIZER_INTERFACE_ATTRIBUTE
87 void __asan_report_error(uptr pc, uptr bp, uptr sp,
88 uptr addr, int is_write, uptr access_size);
90 SANITIZER_INTERFACE_ATTRIBUTE
91 int __asan_set_error_exit_code(int exit_code);
92 SANITIZER_INTERFACE_ATTRIBUTE
93 void __asan_set_death_callback(void (*callback)(void));
94 SANITIZER_INTERFACE_ATTRIBUTE
95 void __asan_set_error_report_callback(void (*callback)(const char*));
97 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
98 /* OPTIONAL */ void __asan_on_error();
100 SANITIZER_INTERFACE_ATTRIBUTE
101 uptr __asan_get_estimated_allocated_size(uptr size);
103 SANITIZER_INTERFACE_ATTRIBUTE int __asan_get_ownership(const void *p);
104 SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_allocated_size(const void *p);
105 SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_current_allocated_bytes();
106 SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_heap_size();
107 SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_free_bytes();
108 SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_unmapped_bytes();
109 SANITIZER_INTERFACE_ATTRIBUTE void __asan_print_accumulated_stats();
111 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
112 /* OPTIONAL */ const char* __asan_default_options();
114 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
115 /* OPTIONAL */ void __asan_malloc_hook(void *ptr, uptr size);
116 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
117 /* OPTIONAL */ void __asan_free_hook(void *ptr);
119 // Global flag, copy of ASAN_OPTIONS=detect_stack_use_after_return
120 SANITIZER_INTERFACE_ATTRIBUTE
121 extern int __asan_option_detect_stack_use_after_return;
123 SANITIZER_INTERFACE_ATTRIBUTE
124 extern uptr *__asan_test_only_reported_buggy_pointer;
126 SANITIZER_INTERFACE_ATTRIBUTE void __asan_load1(uptr p);
127 SANITIZER_INTERFACE_ATTRIBUTE void __asan_load2(uptr p);
128 SANITIZER_INTERFACE_ATTRIBUTE void __asan_load4(uptr p);
129 SANITIZER_INTERFACE_ATTRIBUTE void __asan_load8(uptr p);
130 SANITIZER_INTERFACE_ATTRIBUTE void __asan_load16(uptr p);
131 SANITIZER_INTERFACE_ATTRIBUTE void __asan_store1(uptr p);
132 SANITIZER_INTERFACE_ATTRIBUTE void __asan_store2(uptr p);
133 SANITIZER_INTERFACE_ATTRIBUTE void __asan_store4(uptr p);
134 SANITIZER_INTERFACE_ATTRIBUTE void __asan_store8(uptr p);
135 SANITIZER_INTERFACE_ATTRIBUTE void __asan_store16(uptr p);
136 SANITIZER_INTERFACE_ATTRIBUTE void __asan_loadN(uptr p, uptr size);
137 SANITIZER_INTERFACE_ATTRIBUTE void __asan_storeN(uptr p, uptr size);
139 SANITIZER_INTERFACE_ATTRIBUTE
140 void* __asan_memcpy(void *dst, const void *src, uptr size);
141 SANITIZER_INTERFACE_ATTRIBUTE
142 void* __asan_memset(void *s, int c, uptr n);
143 SANITIZER_INTERFACE_ATTRIBUTE
144 void* __asan_memmove(void* dest, const void* src, uptr n);
145 } // extern "C"
147 #endif // ASAN_INTERFACE_INTERNAL_H