Eric Fiselier | d22c9dc | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Eric Fiselier | d22c9dc | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_ABI_MICROSOFT |
| 11 | #error this header can only be used when targeting the MSVC ABI |
| 12 | #endif |
| 13 | |
| 14 | #include <stdio.h> |
| 15 | #include <stdlib.h> |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 16 | |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 17 | extern "C" { |
Peter Collingbourne | 4bdb80f | 2018-01-17 04:37:04 +0000 | [diff] [blame] | 18 | typedef void (__cdecl* terminate_handler)(); |
| 19 | _LIBCPP_CRT_FUNC terminate_handler __cdecl set_terminate( |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 20 | terminate_handler _NewTerminateHandler) throw(); |
Peter Collingbourne | 4bdb80f | 2018-01-17 04:37:04 +0000 | [diff] [blame] | 21 | _LIBCPP_CRT_FUNC terminate_handler __cdecl _get_terminate(); |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 22 | |
Peter Collingbourne | 4bdb80f | 2018-01-17 04:37:04 +0000 | [diff] [blame] | 23 | typedef void (__cdecl* unexpected_handler)(); |
Peter Collingbourne | 5e27cce | 2018-01-18 00:33:35 +0000 | [diff] [blame] | 24 | unexpected_handler __cdecl set_unexpected( |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 25 | unexpected_handler _NewUnexpectedHandler) throw(); |
Peter Collingbourne | 5e27cce | 2018-01-18 00:33:35 +0000 | [diff] [blame] | 26 | unexpected_handler __cdecl _get_unexpected(); |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 27 | |
Peter Collingbourne | 5e27cce | 2018-01-18 00:33:35 +0000 | [diff] [blame] | 28 | int __cdecl __uncaught_exceptions(); |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 29 | } |
Eric Fiselier | d22c9dc | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 30 | |
| 31 | namespace std { |
| 32 | |
Eric Fiselier | d22c9dc | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 33 | unexpected_handler |
| 34 | set_unexpected(unexpected_handler func) _NOEXCEPT { |
| 35 | return ::set_unexpected(func); |
| 36 | } |
| 37 | |
| 38 | unexpected_handler get_unexpected() _NOEXCEPT { |
| 39 | return ::_get_unexpected(); |
| 40 | } |
| 41 | |
| 42 | _LIBCPP_NORETURN |
| 43 | void unexpected() { |
| 44 | (*get_unexpected())(); |
| 45 | // unexpected handler should not return |
| 46 | terminate(); |
| 47 | } |
| 48 | |
| 49 | terminate_handler set_terminate(terminate_handler func) _NOEXCEPT { |
| 50 | return ::set_terminate(func); |
| 51 | } |
| 52 | |
| 53 | terminate_handler get_terminate() _NOEXCEPT { |
| 54 | return ::_get_terminate(); |
| 55 | } |
| 56 | |
| 57 | _LIBCPP_NORETURN |
| 58 | void terminate() _NOEXCEPT |
| 59 | { |
| 60 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 61 | try |
| 62 | { |
| 63 | #endif // _LIBCPP_NO_EXCEPTIONS |
| 64 | (*get_terminate())(); |
| 65 | // handler should not return |
| 66 | fprintf(stderr, "terminate_handler unexpectedly returned\n"); |
| 67 | ::abort(); |
| 68 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 69 | } |
| 70 | catch (...) |
| 71 | { |
| 72 | // handler should not throw exception |
| 73 | fprintf(stderr, "terminate_handler unexpectedly threw an exception\n"); |
| 74 | ::abort(); |
| 75 | } |
| 76 | #endif // _LIBCPP_NO_EXCEPTIONS |
| 77 | } |
| 78 | |
| 79 | bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; } |
| 80 | |
| 81 | int uncaught_exceptions() _NOEXCEPT { |
| 82 | return __uncaught_exceptions(); |
| 83 | } |
| 84 | |
Eric Fiselier | e69290d | 2019-03-05 01:57:01 +0000 | [diff] [blame] | 85 | #if !defined(_LIBCPP_ABI_VCRUNTIME) |
Saleem Abdulrasool | e7b38cd | 2017-09-15 05:42:39 +0000 | [diff] [blame] | 86 | bad_cast::bad_cast() _NOEXCEPT |
| 87 | { |
| 88 | } |
| 89 | |
| 90 | bad_cast::~bad_cast() _NOEXCEPT |
| 91 | { |
| 92 | } |
| 93 | |
| 94 | const char * |
| 95 | bad_cast::what() const _NOEXCEPT |
| 96 | { |
| 97 | return "std::bad_cast"; |
| 98 | } |
| 99 | |
| 100 | bad_typeid::bad_typeid() _NOEXCEPT |
| 101 | { |
| 102 | } |
| 103 | |
| 104 | bad_typeid::~bad_typeid() _NOEXCEPT |
| 105 | { |
| 106 | } |
| 107 | |
| 108 | const char * |
| 109 | bad_typeid::what() const _NOEXCEPT |
| 110 | { |
| 111 | return "std::bad_typeid"; |
| 112 | } |
| 113 | |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 114 | exception::~exception() _NOEXCEPT |
| 115 | { |
| 116 | } |
| 117 | |
| 118 | const char* exception::what() const _NOEXCEPT |
| 119 | { |
| 120 | return "std::exception"; |
| 121 | } |
| 122 | |
| 123 | |
| 124 | bad_exception::~bad_exception() _NOEXCEPT |
| 125 | { |
| 126 | } |
| 127 | |
| 128 | const char* bad_exception::what() const _NOEXCEPT |
| 129 | { |
| 130 | return "std::bad_exception"; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | bad_alloc::bad_alloc() _NOEXCEPT |
| 135 | { |
| 136 | } |
| 137 | |
| 138 | bad_alloc::~bad_alloc() _NOEXCEPT |
| 139 | { |
| 140 | } |
| 141 | |
| 142 | const char* |
| 143 | bad_alloc::what() const _NOEXCEPT |
| 144 | { |
| 145 | return "std::bad_alloc"; |
| 146 | } |
| 147 | |
| 148 | bad_array_new_length::bad_array_new_length() _NOEXCEPT |
| 149 | { |
| 150 | } |
| 151 | |
| 152 | bad_array_new_length::~bad_array_new_length() _NOEXCEPT |
| 153 | { |
| 154 | } |
| 155 | |
| 156 | const char* |
| 157 | bad_array_new_length::what() const _NOEXCEPT |
| 158 | { |
| 159 | return "bad_array_new_length"; |
| 160 | } |
Eric Fiselier | e69290d | 2019-03-05 01:57:01 +0000 | [diff] [blame] | 161 | #endif // !_LIBCPP_ABI_VCRUNTIME |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 162 | |
Eric Fiselier | d22c9dc | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 163 | } // namespace std |