[Sanitizer/interception Win] Break into the debugger on unknown instructions
[blocksruntime.git] / lib / msan / msan_new_delete.cc
blob3bae49c0cc94773266ca1911b6a86c46843da14c
1 //===-- msan_new_delete.cc ------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file is a part of MemorySanitizer.
12 // Interceptors for operators new and delete.
13 //===----------------------------------------------------------------------===//
15 #include "msan.h"
16 #include "sanitizer_common/sanitizer_interception.h"
18 #if MSAN_REPLACE_OPERATORS_NEW_AND_DELETE
20 #include <stddef.h>
22 namespace __msan {
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>.
32 namespace std {
33 struct nothrow_t {};
34 } // namespace std
37 #define OPERATOR_NEW_BODY \
38 GET_MALLOC_STACK_TRACE; \
39 return MsanReallocate(&stack, 0, size, sizeof(u64), false)
41 INTERCEPTOR_ATTRIBUTE
42 void *operator new(size_t size) { OPERATOR_NEW_BODY; }
43 INTERCEPTOR_ATTRIBUTE
44 void *operator new[](size_t size) { OPERATOR_NEW_BODY; }
45 INTERCEPTOR_ATTRIBUTE
46 void *operator new(size_t size, std::nothrow_t const&) { OPERATOR_NEW_BODY; }
47 INTERCEPTOR_ATTRIBUTE
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)
54 INTERCEPTOR_ATTRIBUTE
55 void operator delete(void *ptr) throw() { OPERATOR_DELETE_BODY; }
56 INTERCEPTOR_ATTRIBUTE
57 void operator delete[](void *ptr) throw() { OPERATOR_DELETE_BODY; }
58 INTERCEPTOR_ATTRIBUTE
59 void operator delete(void *ptr, std::nothrow_t const&) { OPERATOR_DELETE_BODY; }
60 INTERCEPTOR_ATTRIBUTE
61 void operator delete[](void *ptr, std::nothrow_t const&) {
62 OPERATOR_DELETE_BODY;
65 #endif // MSAN_REPLACE_OPERATORS_NEW_AND_DELETE