12755751fSHerbert Dürr /**************************************************************
22755751fSHerbert Dürr  *
32755751fSHerbert Dürr  * Licensed to the Apache Software Foundation (ASF) under one
42755751fSHerbert Dürr  * or more contributor license agreements.  See the NOTICE file
52755751fSHerbert Dürr  * distributed with this work for additional information
62755751fSHerbert Dürr  * regarding copyright ownership.  The ASF licenses this file
72755751fSHerbert Dürr  * to you under the Apache License, Version 2.0 (the
82755751fSHerbert Dürr  * "License"); you may not use this file except in compliance
92755751fSHerbert Dürr  * with the License.  You may obtain a copy of the License at
102755751fSHerbert Dürr  *
112755751fSHerbert Dürr  *   http://www.apache.org/licenses/LICENSE-2.0
122755751fSHerbert Dürr  *
132755751fSHerbert Dürr  * Unless required by applicable law or agreed to in writing,
142755751fSHerbert Dürr  * software distributed under the License is distributed on an
152755751fSHerbert Dürr  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162755751fSHerbert Dürr  * KIND, either express or implied.  See the License for the
172755751fSHerbert Dürr  * specific language governing permissions and limitations
182755751fSHerbert Dürr  * under the License.
192755751fSHerbert Dürr  *
202755751fSHerbert Dürr  *************************************************************/
212755751fSHerbert Dürr 
222755751fSHerbert Dürr 
232755751fSHerbert Dürr 
242755751fSHerbert Dürr #include "uno/mapping.h"
252755751fSHerbert Dürr 
262755751fSHerbert Dürr #include <typeinfo>
272755751fSHerbert Dürr #include <exception>
282755751fSHerbert Dürr #include <cstddef>
292755751fSHerbert Dürr 
302755751fSHerbert Dürr namespace CPPU_CURRENT_NAMESPACE
312755751fSHerbert Dürr {
322755751fSHerbert Dürr 
332755751fSHerbert Dürr void dummy_can_throw_anything( char const * );
342755751fSHerbert Dürr 
353e6ea66aSJim Jagielski typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
363e6ea66aSJim Jagielski 
372755751fSHerbert Dürr // ----- the following structure is compatible with the one declared in libunwind's unwind.h
383e6ea66aSJim Jagielski // (use forced types)
392755751fSHerbert Dürr 
402755751fSHerbert Dürr struct _Unwind_Exception
412755751fSHerbert Dürr {
423e6ea66aSJim Jagielski     uint64_t exception_class;
432755751fSHerbert Dürr     void * exception_cleanup;
443e6ea66aSJim Jagielski     uintptr_t private_1;
453e6ea66aSJim Jagielski     uintptr_t private_2;
463e6ea66aSJim Jagielski };
472755751fSHerbert Dürr 
482755751fSHerbert Dürr struct __cxa_exception
493e6ea66aSJim Jagielski {
50db691b76SJim Jagielski     /* From LLVM 10 - Added reserved member at top of struct. Who the hell does that?
51db691b76SJim Jagielski        https://reviews.llvm.org/rG674ec1eb16678b8addc02a4b0534ab383d22fa77
52db691b76SJim Jagielski        NOTE: Apple clang version != real LLVM version. Don't be fooled!
53db691b76SJim Jagielski     */
54db691b76SJim Jagielski #if 0
55db691b76SJim Jagielski     void *reserved;
562755751fSHerbert Dürr #endif
57db691b76SJim Jagielski     size_t referenceCount;
582755751fSHerbert Dürr     ::std::type_info *exceptionType;
592755751fSHerbert Dürr     void (*exceptionDestructor)(void *);
602755751fSHerbert Dürr     ::std::unexpected_handler unexpectedHandler;
612755751fSHerbert Dürr     ::std::terminate_handler terminateHandler;
622755751fSHerbert Dürr     __cxa_exception *nextException;
632755751fSHerbert Dürr     int handlerCount;
642755751fSHerbert Dürr     int handlerSwitchValue;
652755751fSHerbert Dürr     const unsigned char *actionRecord;
662755751fSHerbert Dürr     const unsigned char *languageSpecificData;
672755751fSHerbert Dürr     void *catchTemp;
682755751fSHerbert Dürr     void *adjustedPtr;
692755751fSHerbert Dürr     _Unwind_Exception unwindHeader;
70*f1a18c4fSJim Jagielski };
712755751fSHerbert Dürr 
722755751fSHerbert Dürr extern "C" void *__cxa_allocate_exception(
732755751fSHerbert Dürr     std::size_t thrown_size ) throw();
742755751fSHerbert Dürr extern "C" void __cxa_throw (
752755751fSHerbert Dürr     void *thrown_exception, std::type_info *tinfo, void (*dest) (void *) ) __attribute__((noreturn));
762755751fSHerbert Dürr 
772755751fSHerbert Dürr struct __cxa_eh_globals
782755751fSHerbert Dürr {
792755751fSHerbert Dürr     __cxa_exception *caughtExceptions;
802755751fSHerbert Dürr     unsigned int uncaughtExceptions;
812755751fSHerbert Dürr };
822755751fSHerbert Dürr extern "C" __cxa_eh_globals *__cxa_get_globals () throw();
832755751fSHerbert Dürr 
842755751fSHerbert Dürr // -----
852755751fSHerbert Dürr 
8651a1e52eSHerbert Dürr // on OSX 64bit the class_type_info classes are specified
8751a1e52eSHerbert Dürr // in http://refspecs.linuxbase.org/cxxabi-1.86.html#rtti but
8851a1e52eSHerbert Dürr // these details are not generally available in a public header
8951a1e52eSHerbert Dürr // of most development environments. So we define them here.
9051a1e52eSHerbert Dürr class __class_type_info : public std::type_info
9151a1e52eSHerbert Dürr {
9251a1e52eSHerbert Dürr public:
__class_type_info(const char * pRttiName)9351a1e52eSHerbert Dürr         explicit __class_type_info( const char* pRttiName)
9451a1e52eSHerbert Dürr         : std::type_info( pRttiName)
9551a1e52eSHerbert Dürr         {}
9651a1e52eSHerbert Dürr };
9751a1e52eSHerbert Dürr 
9851a1e52eSHerbert Dürr class __si_class_type_info : public __class_type_info
9951a1e52eSHerbert Dürr {
10051a1e52eSHerbert Dürr         const __class_type_info* mpBaseType;
10151a1e52eSHerbert Dürr public:
__si_class_type_info(const char * pRttiName,__class_type_info * pBaseType)10251a1e52eSHerbert Dürr         explicit __si_class_type_info( const char* pRttiName, __class_type_info* pBaseType)
10351a1e52eSHerbert Dürr         : __class_type_info( pRttiName), mpBaseType( pBaseType)
10451a1e52eSHerbert Dürr         {}
10551a1e52eSHerbert Dürr };
10651a1e52eSHerbert Dürr 
1072755751fSHerbert Dürr //==================================================================================================
1082755751fSHerbert Dürr void raiseException(
1092755751fSHerbert Dürr     uno_Any * pUnoExc, uno_Mapping * pUno2Cpp );
1102755751fSHerbert Dürr //==================================================================================================
1112755751fSHerbert Dürr void fillUnoException(
1122755751fSHerbert Dürr     __cxa_exception * header, uno_Any *, uno_Mapping * pCpp2Uno );
1132755751fSHerbert Dürr }
1142755751fSHerbert Dürr 
115