Revert r282692: Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.
The test breaks build bots.
llvm-svn: 282703
diff --git a/libcxxabi/src/cxa_exception.cpp b/libcxxabi/src/cxa_exception.cpp
index 757b3d4..603f869 100644
--- a/libcxxabi/src/cxa_exception.cpp
+++ b/libcxxabi/src/cxa_exception.cpp
@@ -15,10 +15,13 @@
#include "cxxabi.h"
#include <exception> // for std::terminate
+#include <cstdlib> // for malloc, free
#include <cstring> // for memset
+#ifndef _LIBCXXABI_HAS_NO_THREADS
+# include <pthread.h> // for fallback_malloc.ipp's mutexes
+#endif
#include "cxa_exception.hpp"
#include "cxa_handlers.hpp"
-#include "fallback_malloc.h"
// +---------------------------+-----------------------------+---------------+
// | __cxa_exception | _Unwind_Exception CLNGC++\0 | thrown object |
@@ -101,6 +104,20 @@
return --exception->handlerCount;
}
+#include "fallback_malloc.ipp"
+
+// Allocate some memory from _somewhere_
+static void *do_malloc(size_t size) {
+ void *ptr = std::malloc(size);
+ if (NULL == ptr) // if malloc fails, fall back to emergency stash
+ ptr = fallback_malloc(size);
+ return ptr;
+}
+
+static void do_free(void *ptr) {
+ is_fallback_ptr(ptr) ? fallback_free(ptr) : std::free(ptr);
+}
+
/*
If reason isn't _URC_FOREIGN_EXCEPTION_CAUGHT, then the terminateHandler
stored in exc is called. Otherwise the exceptionDestructor stored in
@@ -141,8 +158,7 @@
// user's exception object.
_LIBCXXABI_FUNC_VIS void *__cxa_allocate_exception(size_t thrown_size) throw() {
size_t actual_size = cxa_exception_size_from_exception_thrown_size(thrown_size);
- __cxa_exception *exception_header =
- static_cast<__cxa_exception *>(__malloc_with_fallback(actual_size));
+ __cxa_exception* exception_header = static_cast<__cxa_exception*>(do_malloc(actual_size));
if (NULL == exception_header)
std::terminate();
std::memset(exception_header, 0, actual_size);
@@ -152,7 +168,7 @@
// Free a __cxa_exception object allocated with __cxa_allocate_exception.
_LIBCXXABI_FUNC_VIS void __cxa_free_exception(void *thrown_object) throw() {
- __free_with_fallback(cxa_exception_from_thrown_object(thrown_object));
+ do_free(cxa_exception_from_thrown_object(thrown_object));
}
@@ -161,7 +177,7 @@
// Otherwise, it will work like __cxa_allocate_exception.
void * __cxa_allocate_dependent_exception () {
size_t actual_size = sizeof(__cxa_dependent_exception);
- void *ptr = __malloc_with_fallback(actual_size);
+ void *ptr = do_malloc(actual_size);
if (NULL == ptr)
std::terminate();
std::memset(ptr, 0, actual_size);
@@ -172,7 +188,7 @@
// This function shall free a dependent_exception.
// It does not affect the reference count of the primary exception.
void __cxa_free_dependent_exception (void * dependent_exception) {
- __free_with_fallback(dependent_exception);
+ do_free(dependent_exception);
}