]>
Commit | Line | Data |
---|---|---|
f35db108 WM |
1 | //===-- asan_interceptors.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 | // Interceptors for operators new and delete. | |
11 | //===----------------------------------------------------------------------===// | |
12 | ||
13 | #include "asan_allocator.h" | |
14 | #include "asan_internal.h" | |
15 | #include "asan_stack.h" | |
16 | ||
17 | #include <stddef.h> | |
f35db108 WM |
18 | |
19 | namespace __asan { | |
20 | // This function is a no-op. We need it to make sure that object file | |
21 | // with our replacements will actually be loaded from static ASan | |
22 | // run-time library at link-time. | |
23 | void ReplaceOperatorsNewAndDelete() { } | |
24 | } | |
25 | ||
26 | using namespace __asan; // NOLINT | |
27 | ||
e297eb60 KS |
28 | // On Android new() goes through malloc interceptors. |
29 | #if !ASAN_ANDROID | |
30 | ||
31 | // Fake std::nothrow_t to avoid including <new>. | |
32 | namespace std { | |
33 | struct nothrow_t {}; | |
34 | } // namespace std | |
35 | ||
f35db108 WM |
36 | #define OPERATOR_NEW_BODY \ |
37 | GET_STACK_TRACE_HERE_FOR_MALLOC;\ | |
38 | return asan_memalign(0, size, &stack); | |
39 | ||
e297eb60 | 40 | INTERCEPTOR_ATTRIBUTE |
f35db108 | 41 | void *operator new(size_t size) { OPERATOR_NEW_BODY; } |
e297eb60 | 42 | INTERCEPTOR_ATTRIBUTE |
f35db108 | 43 | void *operator new[](size_t size) { OPERATOR_NEW_BODY; } |
e297eb60 KS |
44 | INTERCEPTOR_ATTRIBUTE |
45 | void *operator new(size_t size, std::nothrow_t const&) { OPERATOR_NEW_BODY; } | |
46 | INTERCEPTOR_ATTRIBUTE | |
47 | void *operator new[](size_t size, std::nothrow_t const&) { OPERATOR_NEW_BODY; } | |
f35db108 WM |
48 | |
49 | #define OPERATOR_DELETE_BODY \ | |
50 | GET_STACK_TRACE_HERE_FOR_FREE(ptr);\ | |
51 | asan_free(ptr, &stack); | |
52 | ||
e297eb60 KS |
53 | INTERCEPTOR_ATTRIBUTE |
54 | void operator delete(void *ptr) { OPERATOR_DELETE_BODY; } | |
55 | INTERCEPTOR_ATTRIBUTE | |
56 | void operator delete[](void *ptr) { OPERATOR_DELETE_BODY; } | |
57 | INTERCEPTOR_ATTRIBUTE | |
58 | void operator delete(void *ptr, std::nothrow_t const&) | |
f35db108 | 59 | { OPERATOR_DELETE_BODY; } |
e297eb60 KS |
60 | INTERCEPTOR_ATTRIBUTE |
61 | void operator delete[](void *ptr, std::nothrow_t const&) | |
f35db108 | 62 | { OPERATOR_DELETE_BODY; } |
e297eb60 KS |
63 | |
64 | #endif |