2013-06-12 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libsanitizer / asan / asan_interface_internal.h
blob2fd58b856bcf974b0403aac268965b005710380d
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 // Everytime 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 void __asan_init_v1() SANITIZER_INTERFACE_ATTRIBUTE;
27 #define __asan_init __asan_init_v1
29 // This structure describes an instrumented global variable.
30 struct __asan_global {
31 uptr beg; // The address of the global.
32 uptr size; // The original size of the global.
33 uptr size_with_redzone; // The size with the redzone.
34 const char *name; // Name as a C string.
35 uptr has_dynamic_init; // Non-zero if the global has dynamic initializer.
38 // These two functions should be called by the instrumented code.
39 // 'globals' is an array of structures describing 'n' globals.
40 void __asan_register_globals(__asan_global *globals, uptr n)
41 SANITIZER_INTERFACE_ATTRIBUTE;
42 void __asan_unregister_globals(__asan_global *globals, uptr n)
43 SANITIZER_INTERFACE_ATTRIBUTE;
45 // These two functions should be called before and after dynamic initializers
46 // run, respectively. They should be called with parameters describing all
47 // dynamically initialized globals defined in the calling TU.
48 void __asan_before_dynamic_init(uptr first_addr, uptr last_addr)
49 SANITIZER_INTERFACE_ATTRIBUTE;
50 void __asan_after_dynamic_init()
51 SANITIZER_INTERFACE_ATTRIBUTE;
53 // These two functions are used by the instrumented code in the
54 // use-after-return mode. __asan_stack_malloc allocates size bytes of
55 // fake stack and __asan_stack_free poisons it. real_stack is a pointer to
56 // the real stack region.
57 uptr __asan_stack_malloc(uptr size, uptr real_stack)
58 SANITIZER_INTERFACE_ATTRIBUTE;
59 void __asan_stack_free(uptr ptr, uptr size, uptr real_stack)
60 SANITIZER_INTERFACE_ATTRIBUTE;
62 // These two functions are used by instrumented code in the
63 // use-after-scope mode. They mark memory for local variables as
64 // unaddressable when they leave scope and addressable before the
65 // function exits.
66 void __asan_poison_stack_memory(uptr addr, uptr size)
67 SANITIZER_INTERFACE_ATTRIBUTE;
68 void __asan_unpoison_stack_memory(uptr addr, uptr size)
69 SANITIZER_INTERFACE_ATTRIBUTE;
71 // Performs cleanup before a NoReturn function. Must be called before things
72 // like _exit and execl to avoid false positives on stack.
73 void __asan_handle_no_return() SANITIZER_INTERFACE_ATTRIBUTE;
75 void __asan_poison_memory_region(void const volatile *addr, uptr size)
76 SANITIZER_INTERFACE_ATTRIBUTE;
77 void __asan_unpoison_memory_region(void const volatile *addr, uptr size)
78 SANITIZER_INTERFACE_ATTRIBUTE;
80 bool __asan_address_is_poisoned(void const volatile *addr)
81 SANITIZER_INTERFACE_ATTRIBUTE;
83 uptr __asan_region_is_poisoned(uptr beg, uptr size)
84 SANITIZER_INTERFACE_ATTRIBUTE;
86 void __asan_describe_address(uptr addr)
87 SANITIZER_INTERFACE_ATTRIBUTE;
89 void __asan_report_error(uptr pc, uptr bp, uptr sp,
90 uptr addr, bool is_write, uptr access_size)
91 SANITIZER_INTERFACE_ATTRIBUTE;
93 int __asan_set_error_exit_code(int exit_code)
94 SANITIZER_INTERFACE_ATTRIBUTE;
95 void __asan_set_death_callback(void (*callback)(void))
96 SANITIZER_INTERFACE_ATTRIBUTE;
97 void __asan_set_error_report_callback(void (*callback)(const char*))
98 SANITIZER_INTERFACE_ATTRIBUTE;
100 /* OPTIONAL */ void __asan_on_error()
101 SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE;
103 /* OPTIONAL */ bool __asan_symbolize(const void *pc, char *out_buffer,
104 int out_size)
105 SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE;
107 uptr __asan_get_estimated_allocated_size(uptr size)
108 SANITIZER_INTERFACE_ATTRIBUTE;
109 bool __asan_get_ownership(const void *p)
110 SANITIZER_INTERFACE_ATTRIBUTE;
111 uptr __asan_get_allocated_size(const void *p)
112 SANITIZER_INTERFACE_ATTRIBUTE;
113 uptr __asan_get_current_allocated_bytes()
114 SANITIZER_INTERFACE_ATTRIBUTE;
115 uptr __asan_get_heap_size()
116 SANITIZER_INTERFACE_ATTRIBUTE;
117 uptr __asan_get_free_bytes()
118 SANITIZER_INTERFACE_ATTRIBUTE;
119 uptr __asan_get_unmapped_bytes()
120 SANITIZER_INTERFACE_ATTRIBUTE;
121 void __asan_print_accumulated_stats()
122 SANITIZER_INTERFACE_ATTRIBUTE;
124 /* OPTIONAL */ const char* __asan_default_options()
125 SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE;
127 /* OPTIONAL */ void __asan_malloc_hook(void *ptr, uptr size)
128 SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE;
129 /* OPTIONAL */ void __asan_free_hook(void *ptr)
130 SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE;
131 } // extern "C"
133 #endif // ASAN_INTERFACE_INTERNAL_H