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 "interception/interception.h"
18 #if MSAN_REPLACE_OPERATORS_NEW_AND_DELETE
22 using namespace __msan; // NOLINT
24 // Fake std::nothrow_t to avoid including <new>.
30 #define OPERATOR_NEW_BODY \
31 GET_MALLOC_STACK_TRACE; \
32 return MsanReallocate(&stack, 0, size, sizeof(u64), false)
35 void *operator new(size_t size) { OPERATOR_NEW_BODY; }
37 void *operator new[](size_t size) { OPERATOR_NEW_BODY; }
39 void *operator new(size_t size, std::nothrow_t const&) { OPERATOR_NEW_BODY; }
41 void *operator new[](size_t size, std::nothrow_t const&) { OPERATOR_NEW_BODY; }
43 #define OPERATOR_DELETE_BODY \
44 GET_MALLOC_STACK_TRACE; \
45 if (ptr) MsanDeallocate(&stack, ptr)
48 void operator delete(void *ptr) NOEXCEPT { OPERATOR_DELETE_BODY; }
50 void operator delete[](void *ptr) NOEXCEPT { OPERATOR_DELETE_BODY; }
52 void operator delete(void *ptr, std::nothrow_t const&) { OPERATOR_DELETE_BODY; }
54 void operator delete[](void *ptr, std::nothrow_t const&) {
58 #endif // MSAN_REPLACE_OPERATORS_NEW_AND_DELETE