Bug 1851451 [wpt PR 41799] - Update wpt metadata, a=testonly
[gecko.git] / memory / mozalloc / throw_gcc.h
blob6a452ca5fc258adf3440e774e0e060b0b0819ad5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=4 et :
3 */
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]]
31 # endif
32 # endif
33 # ifndef MOZ_THROW_NORETURN
34 # define MOZ_THROW_NORETURN MOZ_NORETURN
35 # endif
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
39 # ifdef __MINGW32__
40 # define MOZ_THROW_INLINE MOZ_ALWAYS_INLINE_EVEN_DEBUG
41 # define MOZ_THROW_EXPORT
42 # else
43 # define MOZ_THROW_INLINE MOZ_ALWAYS_INLINE
44 # define MOZ_THROW_EXPORT MOZ_EXPORT
45 # endif
47 namespace std {
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(
54 void) {
55 mozalloc_abort("fatal: STL threw bad_exception");
58 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_bad_alloc(
59 void) {
60 mozalloc_abort("fatal: STL threw bad_alloc");
63 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_bad_cast(
64 void) {
65 mozalloc_abort("fatal: STL threw bad_cast");
68 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_bad_typeid(
69 void) {
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(
80 const char* msg) {
81 mozalloc_abort(msg);
84 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_domain_error(
85 const char* msg) {
86 mozalloc_abort(msg);
89 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void
90 __throw_invalid_argument(const char* msg) {
91 mozalloc_abort(msg);
94 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_length_error(
95 const char* msg) {
96 mozalloc_abort(msg);
99 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_out_of_range(
100 const char* msg) {
101 mozalloc_abort(msg);
104 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_runtime_error(
105 const char* msg) {
106 mozalloc_abort(msg);
109 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_range_error(
110 const char* msg) {
111 mozalloc_abort(msg);
114 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void
115 __throw_overflow_error(const char* msg) {
116 mozalloc_abort(msg);
119 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void
120 __throw_underflow_error(const char* msg) {
121 mozalloc_abort(msg);
124 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_ios_failure(
125 const char* msg) {
126 mozalloc_abort(msg);
129 MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_system_error(
130 int err) {
131 char error[128];
132 snprintf(error, sizeof(error) - 1, "fatal: STL threw system_error: %s (%d)",
133 strerror(err), err);
134 mozalloc_abort(error);
137 MOZ_THROW_NORETURN MOZ_EXPORT MOZ_ALWAYS_INLINE void __throw_regex_error(
138 int err) {
139 char error[128];
140 snprintf(error, sizeof(error) - 1, "fatal: STL threw regex_error: %s (%d)",
141 strerror(err), err);
142 mozalloc_abort(error);
145 } // namespace std
147 # undef MOZ_THROW_NORETURN
148 # undef MOZ_THROW_INLINE
150 #endif
152 #endif // mozilla_throw_gcc_h