aboutsummaryrefslogtreecommitdiff
path: root/lib/msan/msan_new_delete.cc
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-07-01 13:24:15 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-07-01 13:24:15 +0000
commit50aa32eff79f252ab05a0c0a589cf2ca37cd9923 (patch)
tree26de9fb78670a86ae63c21707b85c414cbf9d012 /lib/msan/msan_new_delete.cc
parent10fcf738d732204a1f1e28878d68a27c5f12cf3b (diff)
downloadsrc-50aa32eff79f252ab05a0c0a589cf2ca37cd9923.tar.gz
src-50aa32eff79f252ab05a0c0a589cf2ca37cd9923.zip
Vendor import of compiler-rt trunk r306956:vendor/compiler-rt/compiler-rt-trunk-r306956
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=320537 svn path=/vendor/compiler-rt/compiler-rt-trunk-r306956/; revision=320538; tag=vendor/compiler-rt/compiler-rt-trunk-r306956
Diffstat (limited to 'lib/msan/msan_new_delete.cc')
-rw-r--r--lib/msan/msan_new_delete.cc20
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/msan/msan_new_delete.cc b/lib/msan/msan_new_delete.cc
index 540100316693..c7295feebfe4 100644
--- a/lib/msan/msan_new_delete.cc
+++ b/lib/msan/msan_new_delete.cc
@@ -14,6 +14,7 @@
#include "msan.h"
#include "interception/interception.h"
+#include "sanitizer_common/sanitizer_allocator.h"
#if MSAN_REPLACE_OPERATORS_NEW_AND_DELETE
@@ -27,18 +28,25 @@ namespace std {
} // namespace std
-#define OPERATOR_NEW_BODY \
+// TODO(alekseys): throw std::bad_alloc instead of dying on OOM.
+#define OPERATOR_NEW_BODY(nothrow) \
GET_MALLOC_STACK_TRACE; \
- return MsanReallocate(&stack, 0, size, sizeof(u64), false)
+ void *res = MsanReallocate(&stack, 0, size, sizeof(u64), false);\
+ if (!nothrow && UNLIKELY(!res)) DieOnFailure::OnOOM();\
+ return res
INTERCEPTOR_ATTRIBUTE
-void *operator new(size_t size) { OPERATOR_NEW_BODY; }
+void *operator new(size_t size) { OPERATOR_NEW_BODY(false /*nothrow*/); }
INTERCEPTOR_ATTRIBUTE
-void *operator new[](size_t size) { OPERATOR_NEW_BODY; }
+void *operator new[](size_t size) { OPERATOR_NEW_BODY(false /*nothrow*/); }
INTERCEPTOR_ATTRIBUTE
-void *operator new(size_t size, std::nothrow_t const&) { OPERATOR_NEW_BODY; }
+void *operator new(size_t size, std::nothrow_t const&) {
+ OPERATOR_NEW_BODY(true /*nothrow*/);
+}
INTERCEPTOR_ATTRIBUTE
-void *operator new[](size_t size, std::nothrow_t const&) { OPERATOR_NEW_BODY; }
+void *operator new[](size_t size, std::nothrow_t const&) {
+ OPERATOR_NEW_BODY(true /*nothrow*/);
+}
#define OPERATOR_DELETE_BODY \
GET_MALLOC_STACK_TRACE; \