Path: blob/main/system/lib/libcxxabi/src/cxa_noexception.cpp
6173 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// Support functions for the no-exceptions libc++ library1314#include "cxxabi.h"1516#include <exception> // for std::terminate17#include "cxa_exception.h"18#include "cxa_handlers.h"1920namespace __cxxabiv1 {2122extern "C" {2324void25__cxa_increment_exception_refcount(void *thrown_object) throw() {26if (thrown_object != nullptr)27std::terminate();28}2930void31__cxa_decrement_exception_refcount(void *thrown_object) throw() {32if (thrown_object != nullptr)33std::terminate();34}353637void *__cxa_current_primary_exception() throw() { return nullptr; }3839void40__cxa_rethrow_primary_exception(void* thrown_object) {41if (thrown_object != nullptr)42std::terminate();43}4445bool46__cxa_uncaught_exception() throw() { return false; }4748unsigned int49__cxa_uncaught_exceptions() throw() { return 0; }5051#if __EMSCRIPTEN__52// Under emscripten this code is also linked when building when53// DISABLE_EXCEPTION_CATCHING is set but DISABLE_EXCEPTION_THROWING is not.54// TODO(sbc): Perhaps just call std::terminate here. It could55// just be some test code that needs updating.56void *__cxa_allocate_exception(size_t thrown_size) throw() {57char* allocation = (char*)malloc(thrown_size + sizeof(__cxa_exception));58return allocation + sizeof(__cxa_exception);59}6061static62inline63__cxa_exception*64cxa_exception_from_thrown_object(void* thrown_object)65{66return static_cast<__cxa_exception*>(thrown_object) - 1;67}6869// Free a __cxa_exception object allocated with __cxa_allocate_exception.70void __cxa_free_exception(void *thrown_object) throw() {71// Compute the size of the padding before the header.72char *raw_buffer =73((char *)cxa_exception_from_thrown_object(thrown_object));74free((void *)raw_buffer);75}7677// This function is called from make_exception_ptr in libcxx unless78// -fno-exceptions is not given. We have definitions of this function in79// cxa_exception.cpp and cxa_exception_emscripten.cpp, but unlike other80// platforms, we use those files only when one of Emscripten EH or Wasm EH is81// used, and we use this cxa_noexceptions.cpp in case of -fignore-exceptions,82// which is our default. So we add a definition here to prevent a link failure.83__cxa_exception*84__cxa_init_primary_exception(void* object,85std::type_info* tinfo,86void*(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw() {87__cxa_exception* exception_header = cxa_exception_from_thrown_object(object);88return exception_header;89}90#endif9192} // extern "C"9394// provide dummy implementations for the 'no exceptions' case.95uint64_t __getExceptionClass (const _Unwind_Exception*) { return 0; }96void __setExceptionClass ( _Unwind_Exception*, uint64_t) {}97bool __isOurExceptionClass(const _Unwind_Exception*) { return false; }9899} // abi100101102