// Methods for Exception Support for -*- C++ -*-
-// Copyright (C) 2014-2016 Free Software Foundation, Inc.
+// Copyright (C) 2014-2024 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
- // Copy constructors and assignment operators defined using COW std::string
+ // Copy/move constructors and assignment operators defined using COW string.
+ // These operations are noexcept even though copying a COW string is not,
+ // but we know that the string member in an exception has not been "leaked"
+ // so copying is a simple reference count increment.
logic_error::logic_error(const logic_error& e) noexcept
- : _M_msg(e._M_msg) { }
+ : exception(e), _M_msg(e._M_msg) { }
logic_error& logic_error::operator=(const logic_error& e) noexcept
{ _M_msg = e._M_msg; return *this; }
+ logic_error::logic_error(logic_error&& e) noexcept = default;
+
+ logic_error&
+ logic_error::operator=(logic_error&& e) noexcept = default;
+
runtime_error::runtime_error(const runtime_error& e) noexcept
- : _M_msg(e._M_msg) { }
+ : exception(e), _M_msg(e._M_msg) { }
runtime_error&
runtime_error::operator=(const runtime_error& e) noexcept
{ _M_msg = e._M_msg; return *this; }
+ runtime_error::runtime_error(runtime_error&& e) noexcept = default;
+
+ runtime_error&
+ runtime_error::operator=(runtime_error&& e) noexcept = default;
+
// New C++11 constructors:
logic_error::logic_error(const char* __arg)
// Furthermore, _Rep will always have been allocated or deallocated via
// global new or delete, so nontransactional writes we do to _Rep cannot
// interfere with transactional accesses.
+
+// We depend on having support for referencing functions declared weak that
+// are not defined by us. Without such support, the exceptions will not be
+// declared transaction-safe, so we just don't provide transactional clones
+// in this case.
+#if _GLIBCXX_USE_WEAK_REF
+#ifdef _GLIBCXX_USE_C99_STDINT
+
+#include <stdint.h>
+
+using std::size_t;
+
extern "C" {
#ifndef _GLIBCXX_MANGLE_SIZE_T
# define ITM_REGPARM
#endif
-#if __GXX_WEAK__
// Declare all libitm symbols we rely on, but make them weak so that we do
// not depend on libitm.
extern void* _ZGTtnaX (size_t sz) __attribute__((weak));
extern void _ZGTtdlPv (void* ptr) __attribute__((weak));
extern uint8_t _ITM_RU1(const uint8_t *p)
ITM_REGPARM __attribute__((weak));
+extern uint16_t _ITM_RU2(const uint16_t *p)
+ ITM_REGPARM __attribute__((weak));
extern uint32_t _ITM_RU4(const uint32_t *p)
ITM_REGPARM __attribute__((weak));
extern uint64_t _ITM_RU8(const uint64_t *p)
extern void _ITM_addUserCommitAction(void (*)(void *), uint64_t, void *)
ITM_REGPARM __attribute__((weak));
-#else
-// If there is no support for weak symbols, create dummies. The exceptions
-// will not be declared transaction_safe in this case.
-void* _ZGTtnaX (size_t) { return NULL; }
-void _ZGTtdlPv (void*) { }
-uint8_t _ITM_RU1(const uint8_t *) { return 0; }
-uint32_t _ITM_RU4(const uint32_t *) { return 0; }
-uint64_t _ITM_RU8(const uint64_t *) { return 0; }
-void _ITM_memcpyRtWn(void *, const void *, size_t) { }
-void _ITM_memcpyRnWt(void *, const void *, size_t) { }
-void _ITM_addUserCommitAction(void (*)(void *), uint64_t, void *) { };
-#endif
-
}
// A transactional version of basic_string::basic_string(const char *s)
// that also notifies the TM runtime about allocations belonging to this
// exception.
void
-_txnal_cow_string_C1_for_exceptions(void* that, const char* s, void *exc)
+_txnal_cow_string_C1_for_exceptions(void* that, const char* s,
+ void *exc __attribute__((unused)))
{
typedef std::basic_string<char> bs_type;
bs_type *bs = (bs_type*) that;
// TODO Once this is supported, link the following allocation to this
// exception: void *prev = _ITM_setAssociatedException(exc);
bs_type::_Rep *rep;
- try
+ __try
{
rep = (bs_type::_Rep*) _ZGTtnaX (len + sizeof (bs_type::_Rep));
}
- catch (...)
+ __catch (...)
{
// Pop the association with this exception.
// TODO Once this is supported, link the following allocation to this
// exception: _ITM_setAssociatedException(prev);
// We do not need to instrument a rethrow.
- throw;
+ __throw_exception_again;
}
// Pop the association with this exception.
// TODO Once this is supported, link the following allocation to this
static void* txnal_read_ptr(void* const * ptr)
{
static_assert(sizeof(uint64_t) == sizeof(void*)
- || sizeof(uint32_t) == sizeof(void*));
- // FIXME make a true compile-time choice to prevent warnings.
+ || sizeof(uint32_t) == sizeof(void*)
+ || sizeof(uint16_t) == sizeof(void*),
+ "Pointers must be 16 bits, 32 bits or 64 bits wide");
#if __UINTPTR_MAX__ == __UINT64_MAX__
return (void*)_ITM_RU8((const uint64_t*)ptr);
-#else
+#elif __UINTPTR_MAX__ == __UINT32_MAX__
return (void*)_ITM_RU4((const uint32_t*)ptr);
+#else
+ return (void*)_ITM_RU2((const uint16_t*)ptr);
#endif
}
return (const char*) txnal_read_ptr((void**)&bs->_M_dataplus._M_p);
}
+#if _GLIBCXX_USE_DUAL_ABI
const char*
_txnal_sso_string_c_str(const void* that)
{
(void* const*)const_cast<char* const*>(
&((const std::__sso_string*) that)->_M_s._M_p));
}
+#endif
void
_txnal_cow_string_D1_commit(void* data)
// result in undefined behavior, which is in this case not initializing this
// string.
#if _GLIBCXX_USE_DUAL_ABI
-#define CTORDTORSTRINGCSTR(s) _txnal_sso_string_c_str((s))
+#define CTORS_FROM_SSOSTRING(NAME, CLASS, BASE) \
+void \
+_ZGTtNSt##NAME##C1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE( \
+ CLASS* that, const std::__sso_string& s) \
+{ \
+ CLASS e(""); \
+ _ITM_memcpyRnWt(that, &e, sizeof(CLASS)); \
+ /* Get the C string from the SSO string. */ \
+ _txnal_cow_string_C1_for_exceptions(_txnal_##BASE##_get_msg(that), \
+ _txnal_sso_string_c_str(&s), that); \
+} \
+void \
+_ZGTtNSt##NAME##C2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE( \
+ CLASS*, const std::__sso_string&) __attribute__((alias \
+("_ZGTtNSt" #NAME \
+ "C1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE")));
#else
-#define CTORDTORSTRINGCSTR(s) ""
+#define CTORS_FROM_SSOSTRING(NAME, CLASS, BASE)
#endif
// This macro defines transaction constructors and destructors for a specific
void \
_ZGTtNSt##NAME##C2EPKc (CLASS*, const char*) \
__attribute__((alias ("_ZGTtNSt" #NAME "C1EPKc"))); \
-void \
-_ZGTtNSt##NAME##C1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE( \
- CLASS* that, const std::__sso_string& s) \
-{ \
- CLASS e(""); \
- _ITM_memcpyRnWt(that, &e, sizeof(CLASS)); \
- /* Get the C string from the SSO string. */ \
- _txnal_cow_string_C1_for_exceptions(_txnal_##BASE##_get_msg(that), \
- CTORDTORSTRINGCSTR(&s), that); \
-} \
-void \
-_ZGTtNSt##NAME##C2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE( \
- CLASS*, const std::__sso_string&) __attribute__((alias \
-("_ZGTtNSt" #NAME \
- "C1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE"))); \
+CTORS_FROM_SSOSTRING(NAME, CLASS, BASE) \
void \
_ZGTtNSt##NAME##D1Ev(CLASS* that) \
{ _txnal_cow_string_D1(_txnal_##BASE##_get_msg(that)); } \
CTORDTOR(15underflow_error, std::underflow_error, runtime_error)
}
+
+#endif // _GLIBCXX_USE_C99_STDINT
+#endif // _GLIBCXX_USE_WEAK_REF