1 //===-- msan_new_delete.cc ------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of MemorySanitizer.
12 // Interceptors for operators new and delete.
13 //===----------------------------------------------------------------------===//
16 #include "sanitizer_common/sanitizer_interception.h"
18 #if MSAN_REPLACE_OPERATORS_NEW_AND_DELETE
23 // This function is a no-op. We need it to make sure that object file
24 // with our replacements will actually be loaded from static MSan
25 // run-time library at link-time.
26 void ReplaceOperatorsNewAndDelete() { }
29 using namespace __msan
; // NOLINT
31 // Fake std::nothrow_t to avoid including <new>.
37 #define OPERATOR_NEW_BODY \
38 GET_MALLOC_STACK_TRACE; \
39 return MsanReallocate(&stack, 0, size, sizeof(u64), false)
42 void *operator new(size_t size
) { OPERATOR_NEW_BODY
; }
44 void *operator new[](size_t size
) { OPERATOR_NEW_BODY
; }
46 void *operator new(size_t size
, std::nothrow_t
const&) { OPERATOR_NEW_BODY
; }
48 void *operator new[](size_t size
, std::nothrow_t
const&) { OPERATOR_NEW_BODY
; }
50 #define OPERATOR_DELETE_BODY \
51 GET_MALLOC_STACK_TRACE; \
52 if (ptr) MsanDeallocate(&stack, ptr)
55 void operator delete(void *ptr
) throw() { OPERATOR_DELETE_BODY
; }
57 void operator delete[](void *ptr
) throw() { OPERATOR_DELETE_BODY
; }
59 void operator delete(void *ptr
, std::nothrow_t
const&) { OPERATOR_DELETE_BODY
; }
61 void operator delete[](void *ptr
, std::nothrow_t
const&) {
65 #endif // MSAN_REPLACE_OPERATORS_NEW_AND_DELETE