[ARM 4/5 big.LITTLE] Add support for -mcpu=cortex-a57
[official-gcc.git] / libsanitizer / asan / asan_dll_thunk.cc
blob19c31f0def8f39740e65e41d299820f707203326
1 //===-- asan_dll_thunk.cc -------------------------------------------------===//
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 file defines a family of thunks that should be statically linked into
11 // the DLLs that have ASan instrumentation in order to delegate the calls to the
12 // shared runtime that lives in the main binary.
13 // See https://code.google.com/p/address-sanitizer/issues/detail?id=209 for the
14 // details.
15 //===----------------------------------------------------------------------===//
17 // Only compile this code when buidling asan_dll_thunk.lib
18 // Using #ifdef rather than relying on Makefiles etc.
19 // simplifies the build procedure.
20 #ifdef ASAN_DLL_THUNK
22 // ----------------- Helper functions and macros --------------------- {{{1
23 extern "C" {
24 void *__stdcall GetModuleHandleA(const char *module_name);
25 void *__stdcall GetProcAddress(void *module, const char *proc_name);
26 void abort();
29 static void *getRealProcAddressOrDie(const char *name) {
30 void *ret = GetProcAddress(GetModuleHandleA(0), name);
31 if (!ret)
32 abort();
33 return ret;
36 #define WRAP_V_V(name) \
37 extern "C" void name() { \
38 typedef void (*fntype)(); \
39 static fntype fn = (fntype)getRealProcAddressOrDie(#name); \
40 fn(); \
43 #define WRAP_V_W(name) \
44 extern "C" void name(void *arg) { \
45 typedef void (*fntype)(void *arg); \
46 static fntype fn = (fntype)getRealProcAddressOrDie(#name); \
47 fn(arg); \
50 #define WRAP_V_WW(name) \
51 extern "C" void name(void *arg1, void *arg2) { \
52 typedef void (*fntype)(void *, void *); \
53 static fntype fn = (fntype)getRealProcAddressOrDie(#name); \
54 fn(arg1, arg2); \
57 #define WRAP_V_WWW(name) \
58 extern "C" void name(void *arg1, void *arg2, void *arg3) { \
59 typedef void *(*fntype)(void *, void *, void *); \
60 static fntype fn = (fntype)getRealProcAddressOrDie(#name); \
61 fn(arg1, arg2, arg3); \
64 #define WRAP_W_V(name) \
65 extern "C" void *name() { \
66 typedef void *(*fntype)(); \
67 static fntype fn = (fntype)getRealProcAddressOrDie(#name); \
68 return fn(); \
71 #define WRAP_W_W(name) \
72 extern "C" void *name(void *arg) { \
73 typedef void *(*fntype)(void *arg); \
74 static fntype fn = (fntype)getRealProcAddressOrDie(#name); \
75 return fn(arg); \
78 #define WRAP_W_WW(name) \
79 extern "C" void *name(void *arg1, void *arg2) { \
80 typedef void *(*fntype)(void *, void *); \
81 static fntype fn = (fntype)getRealProcAddressOrDie(#name); \
82 return fn(arg1, arg2); \
85 #define WRAP_W_WWW(name) \
86 extern "C" void *name(void *arg1, void *arg2, void *arg3) { \
87 typedef void *(*fntype)(void *, void *, void *); \
88 static fntype fn = (fntype)getRealProcAddressOrDie(#name); \
89 return fn(arg1, arg2, arg3); \
92 #define WRAP_W_WWWW(name) \
93 extern "C" void *name(void *arg1, void *arg2, void *arg3, void *arg4) { \
94 typedef void *(*fntype)(void *, void *, void *, void *); \
95 static fntype fn = (fntype)getRealProcAddressOrDie(#name); \
96 return fn(arg1, arg2, arg3, arg4); \
99 #define WRAP_W_WWWWW(name) \
100 extern "C" void *name(void *arg1, void *arg2, void *arg3, void *arg4, \
101 void *arg5) { \
102 typedef void *(*fntype)(void *, void *, void *, void *, void *); \
103 static fntype fn = (fntype)getRealProcAddressOrDie(#name); \
104 return fn(arg1, arg2, arg3, arg4, arg5); \
107 #define WRAP_W_WWWWWW(name) \
108 extern "C" void *name(void *arg1, void *arg2, void *arg3, void *arg4, \
109 void *arg5, void *arg6) { \
110 typedef void *(*fntype)(void *, void *, void *, void *, void *, void *); \
111 static fntype fn = (fntype)getRealProcAddressOrDie(#name); \
112 return fn(arg1, arg2, arg3, arg4, arg5, arg6); \
114 // }}}
116 // ----------------- ASan own interface functions --------------------
117 WRAP_W_V(__asan_should_detect_stack_use_after_return)
119 extern "C" {
120 int __asan_option_detect_stack_use_after_return;
122 // Manually wrap __asan_init as we need to initialize
123 // __asan_option_detect_stack_use_after_return afterwards.
124 void __asan_init_v3() {
125 typedef void (*fntype)();
126 static fntype fn = (fntype)getRealProcAddressOrDie("__asan_init_v3");
127 fn();
128 __asan_option_detect_stack_use_after_return =
129 (__asan_should_detect_stack_use_after_return() != 0);
133 WRAP_V_V(__asan_handle_no_return)
135 WRAP_V_W(__asan_report_store1)
136 WRAP_V_W(__asan_report_store2)
137 WRAP_V_W(__asan_report_store4)
138 WRAP_V_W(__asan_report_store8)
139 WRAP_V_W(__asan_report_store16)
140 WRAP_V_WW(__asan_report_store_n)
142 WRAP_V_W(__asan_report_load1)
143 WRAP_V_W(__asan_report_load2)
144 WRAP_V_W(__asan_report_load4)
145 WRAP_V_W(__asan_report_load8)
146 WRAP_V_W(__asan_report_load16)
147 WRAP_V_WW(__asan_report_load_n)
149 WRAP_V_WW(__asan_register_globals)
150 WRAP_V_WW(__asan_unregister_globals)
152 WRAP_W_WW(__asan_stack_malloc_0)
153 WRAP_W_WW(__asan_stack_malloc_1)
154 WRAP_W_WW(__asan_stack_malloc_2)
155 WRAP_W_WW(__asan_stack_malloc_3)
156 WRAP_W_WW(__asan_stack_malloc_4)
157 WRAP_W_WW(__asan_stack_malloc_5)
158 WRAP_W_WW(__asan_stack_malloc_6)
159 WRAP_W_WW(__asan_stack_malloc_7)
160 WRAP_W_WW(__asan_stack_malloc_8)
161 WRAP_W_WW(__asan_stack_malloc_9)
162 WRAP_W_WW(__asan_stack_malloc_10)
164 WRAP_V_WWW(__asan_stack_free_0)
165 WRAP_V_WWW(__asan_stack_free_1)
166 WRAP_V_WWW(__asan_stack_free_2)
167 WRAP_V_WWW(__asan_stack_free_4)
168 WRAP_V_WWW(__asan_stack_free_5)
169 WRAP_V_WWW(__asan_stack_free_6)
170 WRAP_V_WWW(__asan_stack_free_7)
171 WRAP_V_WWW(__asan_stack_free_8)
172 WRAP_V_WWW(__asan_stack_free_9)
173 WRAP_V_WWW(__asan_stack_free_10)
175 // TODO(timurrrr): Add more interface functions on the as-needed basis.
177 // ----------------- Memory allocation functions ---------------------
178 WRAP_V_W(free)
179 WRAP_V_WW(_free_dbg)
181 WRAP_W_W(malloc)
182 WRAP_W_WWWW(_malloc_dbg)
184 WRAP_W_WW(calloc)
185 WRAP_W_WWWWW(_calloc_dbg)
186 WRAP_W_WWW(_calloc_impl)
188 WRAP_W_WW(realloc)
189 WRAP_W_WWW(_realloc_dbg)
190 WRAP_W_WWW(_recalloc)
192 WRAP_W_W(_msize)
194 // TODO(timurrrr): Do we need to add _Crt* stuff here? (see asan_malloc_win.cc).
196 #endif // ASAN_DLL_THUNK