Path: blob/main/system/lib/libcxxabi/src/cxa_exception.h
6174 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//7// This file implements the "Exception Handling APIs"8// https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html9//10//===----------------------------------------------------------------------===//1112#ifndef _CXA_EXCEPTION_H13#define _CXA_EXCEPTION_H1415#include <exception> // for std::unexpected_handler and std::terminate_handler16#include "cxxabi.h"17#include "unwind.h"1819namespace __cxxabiv1 {2021#ifdef __EMSCRIPTEN_EXCEPTIONS__2223struct _LIBCXXABI_HIDDEN __cxa_exception {24size_t referenceCount;25std::type_info *exceptionType;26// In wasm, destructors return 'this' as in ARM27void* (*exceptionDestructor)(void *);28uint8_t caught;29uint8_t rethrown;30void *adjustedPtr;31// Add padding to ensure that the size of __cxa_exception is a multiple of32// the maximum useful alignment for the target machine. This ensures that33// the thrown object that follows has that correct alignment.34void *padding;35};3637static_assert(sizeof(__cxa_exception) % alignof(max_align_t) == 0, "__cxa_exception must have a size that is multiple of max alignment");3839#else4041static const uint64_t kOurExceptionClass = 0x434C4E47432B2B00; // CLNGC++\042static const uint64_t kOurDependentExceptionClass = 0x434C4E47432B2B01; // CLNGC++\143static const uint64_t get_vendor_and_language = 0xFFFFFFFFFFFFFF00; // mask for CLNGC++4445_LIBCXXABI_HIDDEN uint64_t __getExceptionClass (const _Unwind_Exception*);46_LIBCXXABI_HIDDEN void __setExceptionClass ( _Unwind_Exception*, uint64_t);47_LIBCXXABI_HIDDEN bool __isOurExceptionClass(const _Unwind_Exception*);4849struct _LIBCXXABI_HIDDEN __cxa_exception {50#if defined(__LP64__) || defined(_WIN64) || defined(_LIBCXXABI_ARM_EHABI)51// Now _Unwind_Exception is marked with __attribute__((aligned)),52// which implies __cxa_exception is also aligned. Insert padding53// in the beginning of the struct, rather than before unwindHeader.54void *reserve;5556// This is a new field to support C++11 exception_ptr.57// For binary compatibility it is at the start of this58// struct which is prepended to the object thrown in59// __cxa_allocate_exception.60size_t referenceCount;61#endif6263// Manage the exception object itself.64std::type_info *exceptionType;65#ifdef __wasm__66// In Wasm, a destructor returns its argument67void *(_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);68#else69void (_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);70#endif71std::unexpected_handler unexpectedHandler;72std::terminate_handler terminateHandler;7374__cxa_exception *nextException;7576int handlerCount;7778#if defined(_LIBCXXABI_ARM_EHABI)79__cxa_exception* nextPropagatingException;80int propagationCount;81#else82int handlerSwitchValue;83const unsigned char *actionRecord;84const unsigned char *languageSpecificData;85void *catchTemp;86void *adjustedPtr;87#endif8889#if !defined(__LP64__) && !defined(_WIN64) && !defined(_LIBCXXABI_ARM_EHABI)90// This is a new field to support C++11 exception_ptr.91// For binary compatibility it is placed where the compiler92// previously added padding to 64-bit align unwindHeader.93size_t referenceCount;94#endif95_Unwind_Exception unwindHeader;96};9798// http://sourcery.mentor.com/archives/cxx-abi-dev/msg01924.html99// The layout of this structure MUST match the layout of __cxa_exception, with100// primaryException instead of referenceCount.101struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {102#if defined(__LP64__) || defined(_WIN64) || defined(_LIBCXXABI_ARM_EHABI)103void* reserve; // padding.104void* primaryException;105#endif106107std::type_info *exceptionType;108void (_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);109std::unexpected_handler unexpectedHandler;110std::terminate_handler terminateHandler;111112__cxa_exception *nextException;113114int handlerCount;115116#if defined(_LIBCXXABI_ARM_EHABI)117__cxa_exception* nextPropagatingException;118int propagationCount;119#else120int handlerSwitchValue;121const unsigned char *actionRecord;122const unsigned char *languageSpecificData;123void * catchTemp;124void *adjustedPtr;125#endif126127#if !defined(__LP64__) && !defined(_WIN64) && !defined(_LIBCXXABI_ARM_EHABI)128void* primaryException;129#endif130_Unwind_Exception unwindHeader;131};132133// Verify the negative offsets of different fields.134static_assert(sizeof(_Unwind_Exception) +135offsetof(__cxa_exception, unwindHeader) ==136sizeof(__cxa_exception),137"unwindHeader has wrong negative offsets");138static_assert(sizeof(_Unwind_Exception) +139offsetof(__cxa_dependent_exception, unwindHeader) ==140sizeof(__cxa_dependent_exception),141"unwindHeader has wrong negative offsets");142143#if defined(_LIBCXXABI_ARM_EHABI)144static_assert(offsetof(__cxa_exception, propagationCount) +145sizeof(_Unwind_Exception) + sizeof(void*) ==146sizeof(__cxa_exception),147"propagationCount has wrong negative offset");148static_assert(offsetof(__cxa_dependent_exception, propagationCount) +149sizeof(_Unwind_Exception) + sizeof(void*) ==150sizeof(__cxa_dependent_exception),151"propagationCount has wrong negative offset");152#elif defined(__LP64__) || defined(_WIN64)153static_assert(offsetof(__cxa_exception, adjustedPtr) +154sizeof(_Unwind_Exception) + sizeof(void*) ==155sizeof(__cxa_exception),156"adjustedPtr has wrong negative offset");157static_assert(offsetof(__cxa_dependent_exception, adjustedPtr) +158sizeof(_Unwind_Exception) + sizeof(void*) ==159sizeof(__cxa_dependent_exception),160"adjustedPtr has wrong negative offset");161#else162static_assert(offsetof(__cxa_exception, referenceCount) +163sizeof(_Unwind_Exception) + sizeof(void*) ==164sizeof(__cxa_exception),165"referenceCount has wrong negative offset");166static_assert(offsetof(__cxa_dependent_exception, primaryException) +167sizeof(_Unwind_Exception) + sizeof(void*) ==168sizeof(__cxa_dependent_exception),169"primaryException has wrong negative offset");170#endif171172struct _LIBCXXABI_HIDDEN __cxa_eh_globals {173__cxa_exception * caughtExceptions;174unsigned int uncaughtExceptions;175#if defined(_LIBCXXABI_ARM_EHABI)176__cxa_exception* propagatingExceptions;177#endif178};179180extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals ();181extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals_fast ();182183extern "C" _LIBCXXABI_FUNC_VIS void * __cxa_allocate_dependent_exception ();184extern "C" _LIBCXXABI_FUNC_VIS void __cxa_free_dependent_exception (void * dependent_exception);185186#endif // !__EMSCRIPTEN_EXCEPTIONS__187188} // namespace __cxxabiv1189190#endif // _CXA_EXCEPTION_H191192193