1 //===-- asan_interceptors.cc ----------------------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of AddressSanitizer, an address sanity checker.
10 // Interceptors for operators new and delete.
11 //===----------------------------------------------------------------------===//
13 #include "asan_allocator.h"
14 #include "asan_internal.h"
15 #include "asan_stack.h"
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.
31 // Fake std::nothrow_t to avoid including <new>.
36 #define OPERATOR_NEW_BODY \
37 GET_STACK_TRACE_HERE_FOR_MALLOC;\
38 return asan_memalign(0, size, &stack);
41 void *operator new(size_t size
) { OPERATOR_NEW_BODY
; }
43 void *operator new[](size_t size
) { OPERATOR_NEW_BODY
; }
45 void *operator new(size_t size
, std::nothrow_t
const&) { OPERATOR_NEW_BODY
; }
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);
54 void operator delete(void *ptr
) { OPERATOR_DELETE_BODY
; }
56 void operator delete[](void *ptr
) { OPERATOR_DELETE_BODY
; }
58 void operator delete(void *ptr
, std::nothrow_t
const&)
59 { OPERATOR_DELETE_BODY
; }
61 void operator delete[](void *ptr
, std::nothrow_t
const&)
62 { OPERATOR_DELETE_BODY
; }