]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/lib/msan/msan_new_delete.cc
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / compiler-rt / lib / msan / msan_new_delete.cc
CommitLineData
1a4d82fc
JJ
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.
11//
12// Interceptors for operators new and delete.
13//===----------------------------------------------------------------------===//
14
15#include "msan.h"
92a42be0 16#include "interception/interception.h"
1a4d82fc
JJ
17
18#if MSAN_REPLACE_OPERATORS_NEW_AND_DELETE
19
20#include <stddef.h>
21
1a4d82fc
JJ
22using namespace __msan; // NOLINT
23
24// Fake std::nothrow_t to avoid including <new>.
25namespace std {
26 struct nothrow_t {};
27} // namespace std
28
29
30#define OPERATOR_NEW_BODY \
31 GET_MALLOC_STACK_TRACE; \
32 return MsanReallocate(&stack, 0, size, sizeof(u64), false)
33
34INTERCEPTOR_ATTRIBUTE
35void *operator new(size_t size) { OPERATOR_NEW_BODY; }
36INTERCEPTOR_ATTRIBUTE
37void *operator new[](size_t size) { OPERATOR_NEW_BODY; }
38INTERCEPTOR_ATTRIBUTE
39void *operator new(size_t size, std::nothrow_t const&) { OPERATOR_NEW_BODY; }
40INTERCEPTOR_ATTRIBUTE
41void *operator new[](size_t size, std::nothrow_t const&) { OPERATOR_NEW_BODY; }
42
43#define OPERATOR_DELETE_BODY \
44 GET_MALLOC_STACK_TRACE; \
45 if (ptr) MsanDeallocate(&stack, ptr)
46
47INTERCEPTOR_ATTRIBUTE
92a42be0 48void operator delete(void *ptr) NOEXCEPT { OPERATOR_DELETE_BODY; }
1a4d82fc 49INTERCEPTOR_ATTRIBUTE
92a42be0 50void operator delete[](void *ptr) NOEXCEPT { OPERATOR_DELETE_BODY; }
1a4d82fc
JJ
51INTERCEPTOR_ATTRIBUTE
52void operator delete(void *ptr, std::nothrow_t const&) { OPERATOR_DELETE_BODY; }
53INTERCEPTOR_ATTRIBUTE
54void operator delete[](void *ptr, std::nothrow_t const&) {
55 OPERATOR_DELETE_BODY;
56}
57
58#endif // MSAN_REPLACE_OPERATORS_NEW_AND_DELETE