* config/rs6000/rs6000.c (rs6000_deligitimze_address): Do not
[official-gcc.git] / libsanitizer / asan / asan_new_delete.cc
blob8132e58b6e2e7b94ec26f1c311920f54b44aa718
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 //===----------------------------------------------------------------------===//
13 #include "asan_allocator.h"
14 #include "asan_internal.h"
15 #include "asan_stack.h"
17 #include <stddef.h>
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() { }
26 using namespace __asan; // NOLINT
28 // On Android new() goes through malloc interceptors.
29 #if !ASAN_ANDROID
31 // Fake std::nothrow_t to avoid including <new>.
32 namespace std {
33 struct nothrow_t {};
34 } // namespace std
36 #define OPERATOR_NEW_BODY \
37 GET_STACK_TRACE_HERE_FOR_MALLOC;\
38 return asan_memalign(0, size, &stack);
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; }
49 #define OPERATOR_DELETE_BODY \
50 GET_STACK_TRACE_HERE_FOR_FREE(ptr);\
51 asan_free(ptr, &stack);
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; }
64 #endif