Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: sw=4 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 #include "mozilla/Attributes.h"
13 #include <stdio.h> // snprintf
14 #include <string.h> // strerror
16 // For gcc, we define these inline to abort so that we're absolutely
17 // certain that (i) no exceptions are thrown from Gecko; (ii) these
18 // errors are always terminal and caught by breakpad.
20 #include "mozilla/mozalloc_abort.h"
22 namespace std {
24 // NB: user code is not supposed to touch the std:: namespace. We're
25 // doing this after careful review because we want to define our own
26 // exception throwing semantics. Don't try this at home!
28 MOZ_NORETURN MOZ_ALWAYS_INLINE void
29 __throw_bad_exception(void)
30 {
31 mozalloc_abort("fatal: STL threw bad_exception");
32 }
34 MOZ_NORETURN MOZ_ALWAYS_INLINE void
35 __throw_bad_alloc(void)
36 {
37 mozalloc_abort("fatal: STL threw bad_alloc");
38 }
40 MOZ_NORETURN MOZ_ALWAYS_INLINE void
41 __throw_bad_cast(void)
42 {
43 mozalloc_abort("fatal: STL threw bad_cast");
44 }
46 MOZ_NORETURN MOZ_ALWAYS_INLINE void
47 __throw_bad_typeid(void)
48 {
49 mozalloc_abort("fatal: STL threw bad_typeid");
50 }
52 MOZ_NORETURN MOZ_ALWAYS_INLINE void
53 __throw_logic_error(const char* msg)
54 {
55 mozalloc_abort(msg);
56 }
58 MOZ_NORETURN MOZ_ALWAYS_INLINE void
59 __throw_domain_error(const char* msg)
60 {
61 mozalloc_abort(msg);
62 }
64 MOZ_NORETURN MOZ_ALWAYS_INLINE void
65 __throw_invalid_argument(const char* msg)
66 {
67 mozalloc_abort(msg);
68 }
70 MOZ_NORETURN MOZ_ALWAYS_INLINE void
71 __throw_length_error(const char* msg)
72 {
73 mozalloc_abort(msg);
74 }
76 MOZ_NORETURN MOZ_ALWAYS_INLINE void
77 __throw_out_of_range(const char* msg)
78 {
79 mozalloc_abort(msg);
80 }
82 MOZ_NORETURN MOZ_ALWAYS_INLINE void
83 __throw_runtime_error(const char* msg)
84 {
85 mozalloc_abort(msg);
86 }
88 MOZ_NORETURN MOZ_ALWAYS_INLINE void
89 __throw_range_error(const char* msg)
90 {
91 mozalloc_abort(msg);
92 }
94 MOZ_NORETURN MOZ_ALWAYS_INLINE void
95 __throw_overflow_error(const char* msg)
96 {
97 mozalloc_abort(msg);
98 }
100 MOZ_NORETURN MOZ_ALWAYS_INLINE void
101 __throw_underflow_error(const char* msg)
102 {
103 mozalloc_abort(msg);
104 }
106 MOZ_NORETURN MOZ_ALWAYS_INLINE void
107 __throw_ios_failure(const char* msg)
108 {
109 mozalloc_abort(msg);
110 }
112 MOZ_NORETURN MOZ_ALWAYS_INLINE void
113 __throw_system_error(int err)
114 {
115 char error[128];
116 snprintf(error, sizeof(error)-1,
117 "fatal: STL threw system_error: %s (%d)", strerror(err), err);
118 mozalloc_abort(error);
119 }
121 } // namespace std
123 #endif // mozilla_throw_gcc_h