1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef mozilla_throw_gcc_h
9 #define mozilla_throw_gcc_h
11 #if !defined(_LIBCPP_VERSION) || _LIBCPP_VERSION < 14000
13 # include "mozilla/Attributes.h"
15 # include <stdio.h> // snprintf
16 # include <string.h> // strerror
18 // For gcc, we define these inline to abort so that we're absolutely
19 // certain that (i) no exceptions are thrown from Gecko; (ii) these
20 // errors are always terminal and caught by breakpad.
22 # include "mozilla/mozalloc_abort.h"
24 // libc++ 4.0.0 and higher use C++11 [[noreturn]] attributes for the functions
25 // below, and since clang does not allow mixing __attribute__((noreturn)) and
26 // [[noreturn]], we have to explicitly use the latter here. See bug 1329520.
27 # if defined(__clang__)
28 # if __has_feature(cxx_attributes) && defined(_LIBCPP_VERSION) && \
29 _LIBCPP_VERSION >= 4000
30 # define MOZ_THROW_NORETURN [[noreturn]]
33 # ifndef MOZ_THROW_NORETURN
34 # define MOZ_THROW_NORETURN MOZ_NORETURN
37 // MinGW doesn't appropriately inline these functions in debug builds,
38 // so we need to do some extra coercion for it to do so. Bug 1332747
40 # define MOZ_THROW_INLINE MOZ_ALWAYS_INLINE_EVEN_DEBUG
41 # define MOZ_THROW_EXPORT
43 # define MOZ_THROW_INLINE MOZ_ALWAYS_INLINE
44 # define MOZ_THROW_EXPORT MOZ_EXPORT
49 // NB: user code is not supposed to touch the std:: namespace. We're
50 // doing this after careful review because we want to define our own
51 // exception throwing semantics. Don't try this at home!
53 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE
void __throw_bad_exception(
55 mozalloc_abort("fatal: STL threw bad_exception");
58 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE
void __throw_bad_alloc(
60 mozalloc_abort("fatal: STL threw bad_alloc");
63 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE
void __throw_bad_cast(
65 mozalloc_abort("fatal: STL threw bad_cast");
68 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE
void __throw_bad_typeid(
70 mozalloc_abort("fatal: STL threw bad_typeid");
73 // used by <functional>
74 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE
void
75 __throw_bad_function_call(void) {
76 mozalloc_abort("fatal: STL threw bad_function_call");
79 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE
void __throw_logic_error(
84 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE
void __throw_domain_error(
89 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE
void
90 __throw_invalid_argument(const char* msg
) {
94 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE
void __throw_length_error(
99 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE
void __throw_out_of_range(
104 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE
void __throw_runtime_error(
109 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE
void __throw_range_error(
114 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE
void
115 __throw_overflow_error(const char* msg
) {
119 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE
void
120 __throw_underflow_error(const char* msg
) {
124 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE
void __throw_ios_failure(
129 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE
void __throw_system_error(
132 snprintf(error
, sizeof(error
) - 1, "fatal: STL threw system_error: %s (%d)",
134 mozalloc_abort(error
);
137 MOZ_THROW_NORETURN MOZ_EXPORT MOZ_ALWAYS_INLINE
void __throw_regex_error(
140 snprintf(error
, sizeof(error
) - 1, "fatal: STL threw regex_error: %s (%d)",
142 mozalloc_abort(error
);
147 # undef MOZ_THROW_NORETURN
148 # undef MOZ_THROW_INLINE
152 #endif // mozilla_throw_gcc_h