blob: 32629ea312607a2a3f59de04800377ac35289e0b [file] [log] [blame]
Alexey Samsonovc70fa282013-01-31 13:46:14 +00001//===-- 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 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
17
18#include "sanitizer_common/sanitizer_internal_defs.h"
19
Stephen Hines6a211c52014-07-21 00:49:56 -070020#include "asan_init_version.h"
21
Alexey Samsonovc70fa282013-01-31 13:46:14 +000022using __sanitizer::uptr;
23
24extern "C" {
Stephen Hines6a211c52014-07-21 00:49:56 -070025 // This structure is used to describe the source location of a place where
26 // global was defined.
27 struct __asan_global_source_location {
28 const char *filename;
29 int line_no;
30 int column_no;
31 };
Alexey Samsonovc70fa282013-01-31 13:46:14 +000032
33 // This structure describes an instrumented global variable.
34 struct __asan_global {
35 uptr beg; // The address of the global.
36 uptr size; // The original size of the global.
37 uptr size_with_redzone; // The size with the redzone.
38 const char *name; // Name as a C string.
Alexey Samsonov05e16a02013-03-26 13:06:12 +000039 const char *module_name; // Module name as a C string. This pointer is a
40 // unique identifier of a module.
Alexey Samsonovc70fa282013-01-31 13:46:14 +000041 uptr has_dynamic_init; // Non-zero if the global has dynamic initializer.
Stephen Hines6a211c52014-07-21 00:49:56 -070042 __asan_global_source_location *location; // Source location of a global,
43 // or NULL if it is unknown.
Alexey Samsonovc70fa282013-01-31 13:46:14 +000044 };
45
46 // These two functions should be called by the instrumented code.
47 // 'globals' is an array of structures describing 'n' globals.
Timur Iskhodzhanov3c80c6c2013-08-13 11:42:45 +000048 SANITIZER_INTERFACE_ATTRIBUTE
49 void __asan_register_globals(__asan_global *globals, uptr n);
50 SANITIZER_INTERFACE_ATTRIBUTE
51 void __asan_unregister_globals(__asan_global *globals, uptr n);
Alexey Samsonovc70fa282013-01-31 13:46:14 +000052
53 // These two functions should be called before and after dynamic initializers
Alexey Samsonov05e16a02013-03-26 13:06:12 +000054 // of a single module run, respectively.
Timur Iskhodzhanov3c80c6c2013-08-13 11:42:45 +000055 SANITIZER_INTERFACE_ATTRIBUTE
56 void __asan_before_dynamic_init(const char *module_name);
57 SANITIZER_INTERFACE_ATTRIBUTE
58 void __asan_after_dynamic_init();
Alexey Samsonovc70fa282013-01-31 13:46:14 +000059
Alexey Samsonovc70fa282013-01-31 13:46:14 +000060 // These two functions are used by instrumented code in the
61 // use-after-scope mode. They mark memory for local variables as
62 // unaddressable when they leave scope and addressable before the
63 // function exits.
Timur Iskhodzhanov3c80c6c2013-08-13 11:42:45 +000064 SANITIZER_INTERFACE_ATTRIBUTE
65 void __asan_poison_stack_memory(uptr addr, uptr size);
66 SANITIZER_INTERFACE_ATTRIBUTE
67 void __asan_unpoison_stack_memory(uptr addr, uptr size);
Alexey Samsonovc70fa282013-01-31 13:46:14 +000068
69 // Performs cleanup before a NoReturn function. Must be called before things
70 // like _exit and execl to avoid false positives on stack.
Timur Iskhodzhanov3c80c6c2013-08-13 11:42:45 +000071 SANITIZER_INTERFACE_ATTRIBUTE void __asan_handle_no_return();
Alexey Samsonovc70fa282013-01-31 13:46:14 +000072
Timur Iskhodzhanov3c80c6c2013-08-13 11:42:45 +000073 SANITIZER_INTERFACE_ATTRIBUTE
74 void __asan_poison_memory_region(void const volatile *addr, uptr size);
75 SANITIZER_INTERFACE_ATTRIBUTE
76 void __asan_unpoison_memory_region(void const volatile *addr, uptr size);
Alexey Samsonovc70fa282013-01-31 13:46:14 +000077
Timur Iskhodzhanov3c80c6c2013-08-13 11:42:45 +000078 SANITIZER_INTERFACE_ATTRIBUTE
Stephen Hines2d1fdb22014-05-28 23:58:16 -070079 int __asan_address_is_poisoned(void const volatile *addr);
Alexey Samsonovc70fa282013-01-31 13:46:14 +000080
Timur Iskhodzhanov3c80c6c2013-08-13 11:42:45 +000081 SANITIZER_INTERFACE_ATTRIBUTE
82 uptr __asan_region_is_poisoned(uptr beg, uptr size);
Alexey Samsonovc70fa282013-01-31 13:46:14 +000083
Timur Iskhodzhanov3c80c6c2013-08-13 11:42:45 +000084 SANITIZER_INTERFACE_ATTRIBUTE
85 void __asan_describe_address(uptr addr);
Alexey Samsonovc70fa282013-01-31 13:46:14 +000086
Timur Iskhodzhanov3c80c6c2013-08-13 11:42:45 +000087 SANITIZER_INTERFACE_ATTRIBUTE
Alexey Samsonovc70fa282013-01-31 13:46:14 +000088 void __asan_report_error(uptr pc, uptr bp, uptr sp,
Stephen Hines2d1fdb22014-05-28 23:58:16 -070089 uptr addr, int is_write, uptr access_size);
Alexey Samsonovc70fa282013-01-31 13:46:14 +000090
Timur Iskhodzhanov3c80c6c2013-08-13 11:42:45 +000091 SANITIZER_INTERFACE_ATTRIBUTE
92 int __asan_set_error_exit_code(int exit_code);
93 SANITIZER_INTERFACE_ATTRIBUTE
94 void __asan_set_death_callback(void (*callback)(void));
95 SANITIZER_INTERFACE_ATTRIBUTE
96 void __asan_set_error_report_callback(void (*callback)(const char*));
Alexey Samsonovc70fa282013-01-31 13:46:14 +000097
Timur Iskhodzhanov3c80c6c2013-08-13 11:42:45 +000098 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
99 /* OPTIONAL */ void __asan_on_error();
Alexey Samsonovc70fa282013-01-31 13:46:14 +0000100
Stephen Hines6a211c52014-07-21 00:49:56 -0700101 // ---------------------------
102 // FIXME: Replace these functions with __sanitizer equivalent.
Timur Iskhodzhanov3c80c6c2013-08-13 11:42:45 +0000103 SANITIZER_INTERFACE_ATTRIBUTE
104 uptr __asan_get_estimated_allocated_size(uptr size);
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700105 SANITIZER_INTERFACE_ATTRIBUTE int __asan_get_ownership(const void *p);
Timur Iskhodzhanov3c80c6c2013-08-13 11:42:45 +0000106 SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_allocated_size(const void *p);
107 SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_current_allocated_bytes();
108 SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_heap_size();
109 SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_free_bytes();
110 SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_unmapped_bytes();
Timur Iskhodzhanov3c80c6c2013-08-13 11:42:45 +0000111 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
112 /* OPTIONAL */ void __asan_malloc_hook(void *ptr, uptr size);
113 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
114 /* OPTIONAL */ void __asan_free_hook(void *ptr);
Stephen Hines6a211c52014-07-21 00:49:56 -0700115 // ---------------------------
116
117 SANITIZER_INTERFACE_ATTRIBUTE void __asan_print_accumulated_stats();
118
119 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
120 /* OPTIONAL */ const char* __asan_default_options();
Kostya Serebryany230e52f2013-09-18 10:35:12 +0000121
122 // Global flag, copy of ASAN_OPTIONS=detect_stack_use_after_return
123 SANITIZER_INTERFACE_ATTRIBUTE
124 extern int __asan_option_detect_stack_use_after_return;
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700125
126 SANITIZER_INTERFACE_ATTRIBUTE
127 extern uptr *__asan_test_only_reported_buggy_pointer;
128
129 SANITIZER_INTERFACE_ATTRIBUTE void __asan_load1(uptr p);
130 SANITIZER_INTERFACE_ATTRIBUTE void __asan_load2(uptr p);
131 SANITIZER_INTERFACE_ATTRIBUTE void __asan_load4(uptr p);
132 SANITIZER_INTERFACE_ATTRIBUTE void __asan_load8(uptr p);
133 SANITIZER_INTERFACE_ATTRIBUTE void __asan_load16(uptr p);
134 SANITIZER_INTERFACE_ATTRIBUTE void __asan_store1(uptr p);
135 SANITIZER_INTERFACE_ATTRIBUTE void __asan_store2(uptr p);
136 SANITIZER_INTERFACE_ATTRIBUTE void __asan_store4(uptr p);
137 SANITIZER_INTERFACE_ATTRIBUTE void __asan_store8(uptr p);
138 SANITIZER_INTERFACE_ATTRIBUTE void __asan_store16(uptr p);
139 SANITIZER_INTERFACE_ATTRIBUTE void __asan_loadN(uptr p, uptr size);
140 SANITIZER_INTERFACE_ATTRIBUTE void __asan_storeN(uptr p, uptr size);
141
142 SANITIZER_INTERFACE_ATTRIBUTE
143 void* __asan_memcpy(void *dst, const void *src, uptr size);
144 SANITIZER_INTERFACE_ATTRIBUTE
145 void* __asan_memset(void *s, int c, uptr n);
146 SANITIZER_INTERFACE_ATTRIBUTE
147 void* __asan_memmove(void* dest, const void* src, uptr n);
Alexey Samsonovc70fa282013-01-31 13:46:14 +0000148} // extern "C"
149
150#endif // ASAN_INTERFACE_INTERNAL_H