This is an automated email from the ASF dual-hosted git repository. truckman pushed a commit to branch AOO42X in repository https://gitbox.apache.org/repos/asf/openoffice.git
commit 22f9e5c0c0cc355e71850a02268a5dae1e44fdee Author: Tijl Coosemans <[email protected]> AuthorDate: Sun Jun 8 01:51:39 2025 -0700 Make robust against __cxa_exception ABI changes Patch OpenOffice to replace __cxa_get_globals()->caughtExceptions, which is a pointer to the start of a struct __cxa_exception, with __cxa_current_primary_exception(), which is a pointer to the end. This allows struct __cxa_exception to be extended at the start as was recently done in FreeBSD main and stable/13 on 64-bit architectures. Recently on FreeBSD main and stable/13 __attribute__((__aligned__)) was added to struct _Unwind_Exception which changes its size on 32-bit architectures, and that of __cxa_exception as well. Patch openoffice to detect this so packages built on 13.0 still work on 13.1. (cherry picked from commit d10e4cc263102d760b56217974702c98f89327b0) (cherry picked from commit 3bfdfb5f4474009ab79d4e0a47aa68a4a684cbd6) --- .../source/cpp_uno/gcc3_freebsd_intel/except.cxx | 6 +++++ .../source/cpp_uno/gcc3_freebsd_intel/uno2cpp.cxx | 30 ++++++++++++++++++++-- .../source/cpp_uno/gcc3_freebsd_x86-64/uno2cpp.cxx | 17 ++++++++++-- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/main/bridges/source/cpp_uno/gcc3_freebsd_intel/except.cxx b/main/bridges/source/cpp_uno/gcc3_freebsd_intel/except.cxx index 4eed6ad739..bacae20d0f 100644 --- a/main/bridges/source/cpp_uno/gcc3_freebsd_intel/except.cxx +++ b/main/bridges/source/cpp_uno/gcc3_freebsd_intel/except.cxx @@ -220,6 +220,12 @@ type_info * RTTI::getRTTI( typelib_CompoundTypeDescription *pTypeDescr ) SAL_THR static void deleteException( void * pExc ) { __cxa_exception const * header = ((__cxa_exception const *)pExc - 1); + if (header->exceptionDestructor != &deleteException) { + // _Unwind_Exception was made __aligned__ which + // increased its size by 12 bytes + header = reinterpret_cast<__cxa_exception const *>( + reinterpret_cast<char const *>( header ) - 12 ); + } typelib_TypeDescription * pTD = 0; OUString unoName( toUNOname( header->exceptionType->name() ) ); ::typelib_typedescription_getByName( &pTD, unoName.pData ); diff --git a/main/bridges/source/cpp_uno/gcc3_freebsd_intel/uno2cpp.cxx b/main/bridges/source/cpp_uno/gcc3_freebsd_intel/uno2cpp.cxx index 180b0c0547..ff6238edd2 100644 --- a/main/bridges/source/cpp_uno/gcc3_freebsd_intel/uno2cpp.cxx +++ b/main/bridges/source/cpp_uno/gcc3_freebsd_intel/uno2cpp.cxx @@ -44,9 +44,12 @@ using namespace ::rtl; using namespace ::com::sun::star::uno; #ifdef __GLIBCXX__ +using CPPU_CURRENT_NAMESPACE::__cxa_exception; using CPPU_CURRENT_NAMESPACE::__cxa_get_globals; #else -using __cxxabiv1::__cxa_get_globals; +using __cxxabiv1::__cxa_exception; +using __cxxabiv1::__cxa_current_primary_exception; +using __cxxabiv1::__cxa_decrement_exception_refcount; #endif namespace @@ -313,8 +316,31 @@ static void cpp_call( } catch (...) { + __cxa_exception *header; +#ifdef __GLIBCXX__ + header = __cxa_get_globals()->caughtExceptions; +#else + header = reinterpret_cast<__cxa_exception *>( __cxa_current_primary_exception() ); + if (header) { + __cxa_decrement_exception_refcount( header ); + header--; + uint64_t exc_class = header->unwindHeader.exception_class + & 0xffffffffffffff00; + if (exc_class != /* "GNUCC++" */ 0x474e5543432b2b00) { + // _Unwind_Exception was made __aligned__ which + // increased its size by 12 bytes. + header = reinterpret_cast<__cxa_exception *>( + reinterpret_cast<char *>( header ) - 12 ); + exc_class = header->unwindHeader.exception_class + & 0xffffffffffffff00; + if (exc_class != /* "GNUCC++" */ 0x474e5543432b2b00) { + header = nullptr; + } + } + } +#endif // fill uno exception - CPPU_CURRENT_NAMESPACE::fillUnoException( __cxa_get_globals()->caughtExceptions, *ppUnoExc, pThis->getBridge()->getCpp2Uno() ); + CPPU_CURRENT_NAMESPACE::fillUnoException( header, *ppUnoExc, pThis->getBridge()->getCpp2Uno() ); // temporary params for ( ; nTempIndizes--; ) diff --git a/main/bridges/source/cpp_uno/gcc3_freebsd_x86-64/uno2cpp.cxx b/main/bridges/source/cpp_uno/gcc3_freebsd_x86-64/uno2cpp.cxx index 7e04926eca..85ada7b200 100644 --- a/main/bridges/source/cpp_uno/gcc3_freebsd_x86-64/uno2cpp.cxx +++ b/main/bridges/source/cpp_uno/gcc3_freebsd_x86-64/uno2cpp.cxx @@ -50,9 +50,12 @@ using namespace ::rtl; using namespace ::com::sun::star::uno; #ifdef __GLIBCXX__ +using CPPU_CURRENT_NAMESPACE::__cxa_exception; using CPPU_CURRENT_NAMESPACE::__cxa_get_globals; #else -using __cxxabiv1::__cxa_get_globals; +using __cxxabiv1::__cxa_exception; +using __cxxabiv1::__cxa_current_primary_exception; +using __cxxabiv1::__cxa_decrement_exception_refcount; #endif //================================================================================================== @@ -452,8 +455,18 @@ static void cpp_call( } catch (...) { + __cxa_exception *header; +#ifdef __GLIBCXX__ + header = __cxa_get_globals()->caughtExceptions; +#else + header = reinterpret_cast<__cxa_exception *>( __cxa_current_primary_exception() ); + if (header) { + __cxa_decrement_exception_refcount( header ); + header--; + } +#endif // fill uno exception - CPPU_CURRENT_NAMESPACE::fillUnoException( __cxa_get_globals()->caughtExceptions, *ppUnoExc, pThis->getBridge()->getCpp2Uno() ); + CPPU_CURRENT_NAMESPACE::fillUnoException( header, *ppUnoExc, pThis->getBridge()->getCpp2Uno() ); // temporary params for ( ; nTempIndizes--; )
