Eric Fiselier | d22c9dc | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_ABI_MICROSOFT |
| 12 | #error this header can only be used when targeting the MSVC ABI |
| 13 | #endif |
| 14 | |
| 15 | #include <stdio.h> |
| 16 | #include <stdlib.h> |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 17 | |
| 18 | #if !defined(_ACRTIMP) |
| 19 | #define _ACRTIMP __declspec(dllimport) |
| 20 | #endif |
| 21 | |
| 22 | #if !defined(_VCRTIMP) |
| 23 | #define _VCRTIMP __declspec(dllimport) |
| 24 | #endif |
| 25 | |
| 26 | #if !defined(__CRTDECL) |
| 27 | #define __CRTDECL __cdecl |
| 28 | #endif |
| 29 | |
| 30 | extern "C" { |
| 31 | typedef void (__CRTDECL* terminate_handler)(); |
| 32 | _ACRTIMP terminate_handler __cdecl set_terminate( |
| 33 | terminate_handler _NewTerminateHandler) throw(); |
| 34 | _ACRTIMP terminate_handler __cdecl _get_terminate(); |
| 35 | |
| 36 | typedef void (__CRTDECL* unexpected_handler)(); |
| 37 | _VCRTIMP unexpected_handler __cdecl set_unexpected( |
| 38 | unexpected_handler _NewUnexpectedHandler) throw(); |
| 39 | _VCRTIMP unexpected_handler __cdecl _get_unexpected(); |
| 40 | |
| 41 | _VCRTIMP int __cdecl __uncaught_exceptions(); |
| 42 | } |
Eric Fiselier | d22c9dc | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 43 | |
| 44 | namespace std { |
| 45 | |
Eric Fiselier | d22c9dc | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 46 | unexpected_handler |
| 47 | set_unexpected(unexpected_handler func) _NOEXCEPT { |
| 48 | return ::set_unexpected(func); |
| 49 | } |
| 50 | |
| 51 | unexpected_handler get_unexpected() _NOEXCEPT { |
| 52 | return ::_get_unexpected(); |
| 53 | } |
| 54 | |
| 55 | _LIBCPP_NORETURN |
| 56 | void unexpected() { |
| 57 | (*get_unexpected())(); |
| 58 | // unexpected handler should not return |
| 59 | terminate(); |
| 60 | } |
| 61 | |
| 62 | terminate_handler set_terminate(terminate_handler func) _NOEXCEPT { |
| 63 | return ::set_terminate(func); |
| 64 | } |
| 65 | |
| 66 | terminate_handler get_terminate() _NOEXCEPT { |
| 67 | return ::_get_terminate(); |
| 68 | } |
| 69 | |
| 70 | _LIBCPP_NORETURN |
| 71 | void terminate() _NOEXCEPT |
| 72 | { |
| 73 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 74 | try |
| 75 | { |
| 76 | #endif // _LIBCPP_NO_EXCEPTIONS |
| 77 | (*get_terminate())(); |
| 78 | // handler should not return |
| 79 | fprintf(stderr, "terminate_handler unexpectedly returned\n"); |
| 80 | ::abort(); |
| 81 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 82 | } |
| 83 | catch (...) |
| 84 | { |
| 85 | // handler should not throw exception |
| 86 | fprintf(stderr, "terminate_handler unexpectedly threw an exception\n"); |
| 87 | ::abort(); |
| 88 | } |
| 89 | #endif // _LIBCPP_NO_EXCEPTIONS |
| 90 | } |
| 91 | |
| 92 | bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; } |
| 93 | |
| 94 | int uncaught_exceptions() _NOEXCEPT { |
| 95 | return __uncaught_exceptions(); |
| 96 | } |
| 97 | |
| 98 | bad_array_length::bad_array_length() _NOEXCEPT |
| 99 | { |
| 100 | } |
| 101 | |
| 102 | bad_array_length::~bad_array_length() _NOEXCEPT |
| 103 | { |
| 104 | } |
| 105 | |
| 106 | const char* |
| 107 | bad_array_length::what() const _NOEXCEPT |
| 108 | { |
| 109 | return "bad_array_length"; |
| 110 | } |
| 111 | |
Saleem Abdulrasool | e7b38cd | 2017-09-15 05:42:39 +0000 | [diff] [blame] | 112 | bad_cast::bad_cast() _NOEXCEPT |
| 113 | { |
| 114 | } |
| 115 | |
| 116 | bad_cast::~bad_cast() _NOEXCEPT |
| 117 | { |
| 118 | } |
| 119 | |
| 120 | const char * |
| 121 | bad_cast::what() const _NOEXCEPT |
| 122 | { |
| 123 | return "std::bad_cast"; |
| 124 | } |
| 125 | |
| 126 | bad_typeid::bad_typeid() _NOEXCEPT |
| 127 | { |
| 128 | } |
| 129 | |
| 130 | bad_typeid::~bad_typeid() _NOEXCEPT |
| 131 | { |
| 132 | } |
| 133 | |
| 134 | const char * |
| 135 | bad_typeid::what() const _NOEXCEPT |
| 136 | { |
| 137 | return "std::bad_typeid"; |
| 138 | } |
| 139 | |
Shoaib Meenai | 492d713 | 2017-10-09 19:25:17 +0000 | [diff] [blame] | 140 | #if defined(_LIBCPP_NO_VCRUNTIME) |
| 141 | exception::~exception() _NOEXCEPT |
| 142 | { |
| 143 | } |
| 144 | |
| 145 | const char* exception::what() const _NOEXCEPT |
| 146 | { |
| 147 | return "std::exception"; |
| 148 | } |
| 149 | |
| 150 | |
| 151 | bad_exception::~bad_exception() _NOEXCEPT |
| 152 | { |
| 153 | } |
| 154 | |
| 155 | const char* bad_exception::what() const _NOEXCEPT |
| 156 | { |
| 157 | return "std::bad_exception"; |
| 158 | } |
| 159 | |
| 160 | |
| 161 | bad_alloc::bad_alloc() _NOEXCEPT |
| 162 | { |
| 163 | } |
| 164 | |
| 165 | bad_alloc::~bad_alloc() _NOEXCEPT |
| 166 | { |
| 167 | } |
| 168 | |
| 169 | const char* |
| 170 | bad_alloc::what() const _NOEXCEPT |
| 171 | { |
| 172 | return "std::bad_alloc"; |
| 173 | } |
| 174 | |
| 175 | bad_array_new_length::bad_array_new_length() _NOEXCEPT |
| 176 | { |
| 177 | } |
| 178 | |
| 179 | bad_array_new_length::~bad_array_new_length() _NOEXCEPT |
| 180 | { |
| 181 | } |
| 182 | |
| 183 | const char* |
| 184 | bad_array_new_length::what() const _NOEXCEPT |
| 185 | { |
| 186 | return "bad_array_new_length"; |
| 187 | } |
| 188 | #endif // _LIBCPP_NO_VCRUNTIME |
| 189 | |
Eric Fiselier | d22c9dc | 2017-02-10 08:57:35 +0000 | [diff] [blame] | 190 | } // namespace std |