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"
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);
34 void *operator new(size_t size
) { OPERATOR_NEW_BODY
; }
35 void *operator new[](size_t size
) { OPERATOR_NEW_BODY
; }
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
; }
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
; }