mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
* third_party: Add libcxxabi Added libcxxabi from LLVM 17.0.6 The library implements the Itanium C++ exception handling ABI. * third_party/libcxxabi: Enable __cxa_thread_atexit Enable `__cxa_thread_atexit` from libcxxabi. `__cxa_thread_atexit_impl` is still implemented by the cosmo libc. The original `__cxa_thread_atexit` has been removed. * third_party/libcxx: Build with exceptions Build libcxx with exceptions enabled. - Removed `_LIBCPP_NO_EXCEPTIONS` from `__config`. - Switched the exception implementation to `libcxxabi`. These two files are taken from the same `libcxx` version as mentioned in `README.cosmo`. - Removed `new_handler_fallback` in favor of `libcxxabi` implementation. - Enable `-fexceptions` and `-frtti` for `libcxx`. - Removed `THIRD_PARTY_LIBCXX` dependency from `libcxxabi` and `libunwind`. These libraries do not use any runtime `libcxx` functions, just headers. * libc: Remove remaining redundant cxa functions - `__cxa_pure_virtual` in `libcxxabi` is also a stub similar to the existing one. - `__cxa_guard_*` from `libcxxabi` is used instead of the ones from Android. Now there should be no more duplicate implementations. `__cxa_thread_atexit_impl`, `__cxa_atexit`, and related supporting functions, are still left to other libraries as in `libcxxabi`. `libcxxabi` is also now added to `cosmopolitan.a` to make up for the removed functions. Affected in-tree libraries (`third_party/double-conversion`) have been updated.
73 lines
1.8 KiB
C++
73 lines
1.8 KiB
C++
// -*- C++ -*-
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "third_party/libcxxabi/include/cxxabi.h"
|
|
#include "third_party/libcxx/exception"
|
|
using namespace __cxxabiv1;
|
|
|
|
namespace std {
|
|
|
|
exception_ptr::~exception_ptr() _NOEXCEPT {
|
|
__cxa_decrement_exception_refcount(__ptr_);
|
|
}
|
|
|
|
exception_ptr::exception_ptr(const exception_ptr& other) _NOEXCEPT
|
|
: __ptr_(other.__ptr_)
|
|
{
|
|
__cxa_increment_exception_refcount(__ptr_);
|
|
}
|
|
|
|
exception_ptr& exception_ptr::operator=(const exception_ptr& other) _NOEXCEPT
|
|
{
|
|
if (__ptr_ != other.__ptr_)
|
|
{
|
|
__cxa_increment_exception_refcount(other.__ptr_);
|
|
__cxa_decrement_exception_refcount(__ptr_);
|
|
__ptr_ = other.__ptr_;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
nested_exception::nested_exception() _NOEXCEPT
|
|
: __ptr_(current_exception())
|
|
{
|
|
}
|
|
|
|
nested_exception::~nested_exception() _NOEXCEPT
|
|
{
|
|
}
|
|
|
|
_LIBCPP_NORETURN
|
|
void
|
|
nested_exception::rethrow_nested() const
|
|
{
|
|
if (__ptr_ == nullptr)
|
|
terminate();
|
|
rethrow_exception(__ptr_);
|
|
}
|
|
|
|
exception_ptr current_exception() _NOEXCEPT
|
|
{
|
|
// be nicer if there was a constructor that took a ptr, then
|
|
// this whole function would be just:
|
|
// return exception_ptr(__cxa_current_primary_exception());
|
|
exception_ptr ptr;
|
|
ptr.__ptr_ = __cxa_current_primary_exception();
|
|
return ptr;
|
|
}
|
|
|
|
_LIBCPP_NORETURN
|
|
void rethrow_exception(exception_ptr p)
|
|
{
|
|
__cxa_rethrow_primary_exception(p.__ptr_);
|
|
// if p.__ptr_ is NULL, above returns so we terminate
|
|
terminate();
|
|
}
|
|
|
|
} // namespace std
|