1// -*- C++ -*- 2//===----------------------------------------------------------------------===// 3// 4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5// See https://llvm.org/LICENSE.txt for license information. 6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7// 8//===----------------------------------------------------------------------===// 9 10#include <stdio.h> 11#include <stdlib.h> 12 13_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCreate(void*); 14_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrDestroy(void*); 15_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCopy(void*, const void*); 16_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrAssign(void*, const void*); 17_LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrCompare(const void*, const void*); 18_LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrToBool(const void*); 19_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrSwap(void*, void*); 20_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCurrentException(void*); 21[[noreturn]] _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrRethrow(const void*); 22_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCopyException(void*, const void*, const void*); 23 24namespace std { 25 26exception_ptr::exception_ptr() noexcept { __ExceptionPtrCreate(this); } 27exception_ptr::exception_ptr(nullptr_t) noexcept { __ExceptionPtrCreate(this); } 28 29exception_ptr::exception_ptr(const exception_ptr& __other) noexcept { __ExceptionPtrCopy(this, &__other); } 30exception_ptr& exception_ptr::operator=(const exception_ptr& __other) noexcept { 31 __ExceptionPtrAssign(this, &__other); 32 return *this; 33} 34 35exception_ptr& exception_ptr::operator=(nullptr_t) noexcept { 36 exception_ptr dummy; 37 __ExceptionPtrAssign(this, &dummy); 38 return *this; 39} 40 41exception_ptr::~exception_ptr() noexcept { __ExceptionPtrDestroy(this); } 42 43exception_ptr::operator bool() const noexcept { return __ExceptionPtrToBool(this); } 44 45bool operator==(const exception_ptr& __x, const exception_ptr& __y) noexcept { 46 return __ExceptionPtrCompare(&__x, &__y); 47} 48 49void swap(exception_ptr& lhs, exception_ptr& rhs) noexcept { __ExceptionPtrSwap(&rhs, &lhs); } 50 51exception_ptr __copy_exception_ptr(void* __except, const void* __ptr) { 52 exception_ptr __ret = nullptr; 53 if (__ptr) 54 __ExceptionPtrCopyException(&__ret, __except, __ptr); 55 return __ret; 56} 57 58exception_ptr current_exception() noexcept { 59 exception_ptr __ret; 60 __ExceptionPtrCurrentException(&__ret); 61 return __ret; 62} 63 64_LIBCPP_NORETURN void rethrow_exception(exception_ptr p) { __ExceptionPtrRethrow(&p); } 65 66nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {} 67 68nested_exception::~nested_exception() noexcept {} 69 70_LIBCPP_NORETURN void nested_exception::rethrow_nested() const { 71 if (__ptr_ == nullptr) 72 terminate(); 73 rethrow_exception(__ptr_); 74} 75 76} // namespace std 77