Add libstdc++-raw-cxx.m4 and use it in libsanitizer
[gcc.git] / libsanitizer / asan / asan_new_delete.cc
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>
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
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
36 #define OPERATOR_NEW_BODY \
37 GET_STACK_TRACE_HERE_FOR_MALLOC;\
38 return asan_memalign(0, size, &stack);
39
40 INTERCEPTOR_ATTRIBUTE
41 void *operator new(size_t size) { OPERATOR_NEW_BODY; }
42 INTERCEPTOR_ATTRIBUTE
43 void *operator new[](size_t size) { OPERATOR_NEW_BODY; }
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; }
48
49 #define OPERATOR_DELETE_BODY \
50 GET_STACK_TRACE_HERE_FOR_FREE(ptr);\
51 asan_free(ptr, &stack);
52
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&)
59 { OPERATOR_DELETE_BODY; }
60 INTERCEPTOR_ATTRIBUTE
61 void operator delete[](void *ptr, std::nothrow_t const&)
62 { OPERATOR_DELETE_BODY; }
63
64 #endif