From 962750b511e8c5d00967cbb69d7350b70f57b2d0 Mon Sep 17 00:00:00 2001 From: Igor Kudrin Date: Thu, 29 Sep 2016 06:38:06 +0000 Subject: [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 --- .../test/test_exception_storage_nodynmem.pass.cpp | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 libcxxabi/test/test_exception_storage_nodynmem.pass.cpp (limited to 'libcxxabi/test/test_exception_storage_nodynmem.pass.cpp') 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 +#include + +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; +} -- cgit v1.2.3