aboutsummaryrefslogtreecommitdiff
path: root/contrib/libcxxrt
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-07-26 16:55:06 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-07-26 16:55:06 +0000
commite91d723ad446b5429318b24f4578a4f7a160f65e (patch)
tree50cb45f1c34f42b4a9cde2f5683f22549aa4d377 /contrib/libcxxrt
parent473fe2c000b69c68b13bafc9d1e11e424fbb8132 (diff)
parent0d08e8ebf50805e543626b4e87157578fbad5d2b (diff)
downloadsrc-e91d723ad446b5429318b24f4578a4f7a160f65e.tar.gz
src-e91d723ad446b5429318b24f4578a4f7a160f65e.zip
Notes
Diffstat (limited to 'contrib/libcxxrt')
-rw-r--r--contrib/libcxxrt/exception.cc25
-rw-r--r--contrib/libcxxrt/memory.cc17
2 files changed, 41 insertions, 1 deletions
diff --git a/contrib/libcxxrt/exception.cc b/contrib/libcxxrt/exception.cc
index dbc9c628f0b8..0de878e9e6db 100644
--- a/contrib/libcxxrt/exception.cc
+++ b/contrib/libcxxrt/exception.cc
@@ -879,6 +879,13 @@ extern "C" void __cxa_rethrow()
assert(ex->handlerCount > 0 && "Rethrowing uncaught exception!");
+ // `globals->uncaughtExceptions` was decremented by `__cxa_begin_catch`.
+ // It's normally incremented by `throw_exception`, but this path invokes
+ // `_Unwind_Resume_or_Rethrow` directly to rethrow the exception.
+ // This path is only reachable if we're rethrowing a C++ exception -
+ // foreign exceptions don't adjust any of this state.
+ globals->uncaughtExceptions++;
+
// ex->handlerCount will be decremented in __cxa_end_catch in enclosing
// catch block
@@ -1224,11 +1231,13 @@ extern "C" void *__cxa_begin_catch(void *e)
// we see is a foreign exception then we won't have called it yet.
__cxa_thread_info *ti = thread_info();
__cxa_eh_globals *globals = &ti->globals;
- globals->uncaughtExceptions--;
_Unwind_Exception *exceptionObject = static_cast<_Unwind_Exception*>(e);
if (isCXXException(exceptionObject->exception_class))
{
+ // Only exceptions thrown with a C++ exception throwing function will
+ // increment this, so don't decrement it here.
+ globals->uncaughtExceptions--;
__cxa_exception *ex = exceptionFromPointer(exceptionObject);
if (ex->handlerCount == 0)
@@ -1365,6 +1374,14 @@ extern "C" std::type_info *__cxa_current_exception_type()
}
/**
+ * Cleanup, ensures that `__cxa_end_catch` is called to balance an explicit
+ * `__cxa_begin_catch` call.
+ */
+static void end_catch(char *)
+{
+ __cxa_end_catch();
+}
+/**
* ABI function, called when an exception specification is violated.
*
* This function does not return.
@@ -1372,6 +1389,12 @@ extern "C" std::type_info *__cxa_current_exception_type()
extern "C" void __cxa_call_unexpected(void*exception)
{
_Unwind_Exception *exceptionObject = static_cast<_Unwind_Exception*>(exception);
+ // Wrap the call to the unexpected handler in calls to `__cxa_begin_catch`
+ // and `__cxa_end_catch` so that we correctly update exception counts if
+ // the unexpected handler throws an exception.
+ __cxa_begin_catch(exceptionObject);
+ __attribute__((cleanup(end_catch)))
+ char unused;
if (exceptionObject->exception_class == exception_class)
{
__cxa_exception *ex = exceptionFromPointer(exceptionObject);
diff --git a/contrib/libcxxrt/memory.cc b/contrib/libcxxrt/memory.cc
index 9fa9d2a7aec5..5f1aad76961f 100644
--- a/contrib/libcxxrt/memory.cc
+++ b/contrib/libcxxrt/memory.cc
@@ -151,4 +151,21 @@ void operator delete[](void * ptr) NOEXCEPT
::operator delete(ptr);
}
+// C++14 additional delete operators
+#if __cplusplus >= 201402L
+
+__attribute__((weak))
+void operator delete(void * ptr, size_t) NOEXCEPT
+{
+ ::operator delete(ptr);
+}
+
+
+__attribute__((weak))
+void operator delete[](void * ptr, size_t) NOEXCEPT
+{
+ ::operator delete(ptr);
+}
+
+#endif