memory/mozalloc/throw_gcc.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:ed32f4f12db7
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/. */
7
8 #ifndef mozilla_throw_gcc_h
9 #define mozilla_throw_gcc_h
10
11 #include "mozilla/Attributes.h"
12
13 #include <stdio.h> // snprintf
14 #include <string.h> // strerror
15
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.
19
20 #include "mozilla/mozalloc_abort.h"
21
22 namespace std {
23
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!
27
28 MOZ_NORETURN MOZ_ALWAYS_INLINE void
29 __throw_bad_exception(void)
30 {
31 mozalloc_abort("fatal: STL threw bad_exception");
32 }
33
34 MOZ_NORETURN MOZ_ALWAYS_INLINE void
35 __throw_bad_alloc(void)
36 {
37 mozalloc_abort("fatal: STL threw bad_alloc");
38 }
39
40 MOZ_NORETURN MOZ_ALWAYS_INLINE void
41 __throw_bad_cast(void)
42 {
43 mozalloc_abort("fatal: STL threw bad_cast");
44 }
45
46 MOZ_NORETURN MOZ_ALWAYS_INLINE void
47 __throw_bad_typeid(void)
48 {
49 mozalloc_abort("fatal: STL threw bad_typeid");
50 }
51
52 MOZ_NORETURN MOZ_ALWAYS_INLINE void
53 __throw_logic_error(const char* msg)
54 {
55 mozalloc_abort(msg);
56 }
57
58 MOZ_NORETURN MOZ_ALWAYS_INLINE void
59 __throw_domain_error(const char* msg)
60 {
61 mozalloc_abort(msg);
62 }
63
64 MOZ_NORETURN MOZ_ALWAYS_INLINE void
65 __throw_invalid_argument(const char* msg)
66 {
67 mozalloc_abort(msg);
68 }
69
70 MOZ_NORETURN MOZ_ALWAYS_INLINE void
71 __throw_length_error(const char* msg)
72 {
73 mozalloc_abort(msg);
74 }
75
76 MOZ_NORETURN MOZ_ALWAYS_INLINE void
77 __throw_out_of_range(const char* msg)
78 {
79 mozalloc_abort(msg);
80 }
81
82 MOZ_NORETURN MOZ_ALWAYS_INLINE void
83 __throw_runtime_error(const char* msg)
84 {
85 mozalloc_abort(msg);
86 }
87
88 MOZ_NORETURN MOZ_ALWAYS_INLINE void
89 __throw_range_error(const char* msg)
90 {
91 mozalloc_abort(msg);
92 }
93
94 MOZ_NORETURN MOZ_ALWAYS_INLINE void
95 __throw_overflow_error(const char* msg)
96 {
97 mozalloc_abort(msg);
98 }
99
100 MOZ_NORETURN MOZ_ALWAYS_INLINE void
101 __throw_underflow_error(const char* msg)
102 {
103 mozalloc_abort(msg);
104 }
105
106 MOZ_NORETURN MOZ_ALWAYS_INLINE void
107 __throw_ios_failure(const char* msg)
108 {
109 mozalloc_abort(msg);
110 }
111
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 }
120
121 } // namespace std
122
123 #endif // mozilla_throw_gcc_h

mercurial