summaryrefslogtreecommitdiffstats
path: root/libcxxabi/test/test_exception_storage_nodynmem.pass.cpp
diff options
context:
space:
mode:
authorIgor Kudrin <ikudrin.dev@gmail.com>2016-09-29 06:38:06 +0000
committerIgor Kudrin <ikudrin.dev@gmail.com>2016-09-29 06:38:06 +0000
commit962750b511e8c5d00967cbb69d7350b70f57b2d0 (patch)
tree51b4ad899cdf4793d1a13e75c9d8a59a3d5cea7e /libcxxabi/test/test_exception_storage_nodynmem.pass.cpp
parent1b60e9d7c0e704031e91cb254d680e1a47712a62 (diff)
downloadbcm5719-llvm-962750b511e8c5d00967cbb69d7350b70f57b2d0.tar.gz
bcm5719-llvm-962750b511e8c5d00967cbb69d7350b70f57b2d0.zip
[libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.
Throwing an exception for the first time may lead to call calloc to allocate memory for __cxa_eh_globals. If the memory pool is exhausted at that moment, it results in abnormal termination of the program. This patch addresses the issue by using fallback_malloc in that case. Differential Revision: https://reviews.llvm.org/D17815 llvm-svn: 282692
Diffstat (limited to 'libcxxabi/test/test_exception_storage_nodynmem.pass.cpp')
-rw-r--r--libcxxabi/test/test_exception_storage_nodynmem.pass.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/libcxxabi/test/test_exception_storage_nodynmem.pass.cpp b/libcxxabi/test/test_exception_storage_nodynmem.pass.cpp
new file mode 100644
index 00000000000..5c6eeacc628
--- /dev/null
+++ b/libcxxabi/test/test_exception_storage_nodynmem.pass.cpp
@@ -0,0 +1,32 @@
+//===--------------- test_exception_storage_nodynmem.cpp ------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <assert.h>
+#include <cstdlib>
+
+static bool OverwrittenCallocCalled = false;
+
+// Override calloc to simulate exhaustion of dynamic memory
+void *calloc(size_t, size_t) {
+ OverwrittenCallocCalled = true;
+ return 0;
+}
+
+int main(int argc, char *argv[]) {
+ // Run the test a couple of times
+ // to ensure that fallback memory doesn't leak.
+ for (int I = 0; I < 1000; ++I)
+ try {
+ throw 42;
+ } catch (...) {
+ }
+
+ assert(OverwrittenCallocCalled);
+ return 0;
+}
OpenPOWER on IntegriCloud