2012-10-29 Wei Mi <wmi@google.com>
[official-gcc.git] / libasan / asan_new_delete.cc
bloba2180ae94442b28af76c4ed9239843da9cd8f5f3
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>
18 #include <new>
20 namespace __asan {
21 // This function is a no-op. We need it to make sure that object file
22 // with our replacements will actually be loaded from static ASan
23 // run-time library at link-time.
24 void ReplaceOperatorsNewAndDelete() { }
27 using namespace __asan; // NOLINT
29 #define OPERATOR_NEW_BODY \
30 GET_STACK_TRACE_HERE_FOR_MALLOC;\
31 return asan_memalign(0, size, &stack);
33 #if ASAN_ANDROID
34 void *operator new(size_t size) { OPERATOR_NEW_BODY; }
35 void *operator new[](size_t size) { OPERATOR_NEW_BODY; }
36 #else
37 void *operator new(size_t size) throw(std::bad_alloc) { OPERATOR_NEW_BODY; }
38 void *operator new[](size_t size) throw(std::bad_alloc) { OPERATOR_NEW_BODY; }
39 void *operator new(size_t size, std::nothrow_t const&) throw()
40 { OPERATOR_NEW_BODY; }
41 void *operator new[](size_t size, std::nothrow_t const&) throw()
42 { OPERATOR_NEW_BODY; }
43 #endif
45 #define OPERATOR_DELETE_BODY \
46 GET_STACK_TRACE_HERE_FOR_FREE(ptr);\
47 asan_free(ptr, &stack);
49 void operator delete(void *ptr) throw() { OPERATOR_DELETE_BODY; }
50 void operator delete[](void *ptr) throw() { OPERATOR_DELETE_BODY; }
51 void operator delete(void *ptr, std::nothrow_t const&) throw()
52 { OPERATOR_DELETE_BODY; }
53 void operator delete[](void *ptr, std::nothrow_t const&) throw()
54 { OPERATOR_DELETE_BODY; }