Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: sw=4 ts=4 et : |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef mozilla_throw_gcc_h |
michael@0 | 9 | #define mozilla_throw_gcc_h |
michael@0 | 10 | |
michael@0 | 11 | #include "mozilla/Attributes.h" |
michael@0 | 12 | |
michael@0 | 13 | #include <stdio.h> // snprintf |
michael@0 | 14 | #include <string.h> // strerror |
michael@0 | 15 | |
michael@0 | 16 | // For gcc, we define these inline to abort so that we're absolutely |
michael@0 | 17 | // certain that (i) no exceptions are thrown from Gecko; (ii) these |
michael@0 | 18 | // errors are always terminal and caught by breakpad. |
michael@0 | 19 | |
michael@0 | 20 | #include "mozilla/mozalloc_abort.h" |
michael@0 | 21 | |
michael@0 | 22 | namespace std { |
michael@0 | 23 | |
michael@0 | 24 | // NB: user code is not supposed to touch the std:: namespace. We're |
michael@0 | 25 | // doing this after careful review because we want to define our own |
michael@0 | 26 | // exception throwing semantics. Don't try this at home! |
michael@0 | 27 | |
michael@0 | 28 | MOZ_NORETURN MOZ_ALWAYS_INLINE void |
michael@0 | 29 | __throw_bad_exception(void) |
michael@0 | 30 | { |
michael@0 | 31 | mozalloc_abort("fatal: STL threw bad_exception"); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | MOZ_NORETURN MOZ_ALWAYS_INLINE void |
michael@0 | 35 | __throw_bad_alloc(void) |
michael@0 | 36 | { |
michael@0 | 37 | mozalloc_abort("fatal: STL threw bad_alloc"); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | MOZ_NORETURN MOZ_ALWAYS_INLINE void |
michael@0 | 41 | __throw_bad_cast(void) |
michael@0 | 42 | { |
michael@0 | 43 | mozalloc_abort("fatal: STL threw bad_cast"); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | MOZ_NORETURN MOZ_ALWAYS_INLINE void |
michael@0 | 47 | __throw_bad_typeid(void) |
michael@0 | 48 | { |
michael@0 | 49 | mozalloc_abort("fatal: STL threw bad_typeid"); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | MOZ_NORETURN MOZ_ALWAYS_INLINE void |
michael@0 | 53 | __throw_logic_error(const char* msg) |
michael@0 | 54 | { |
michael@0 | 55 | mozalloc_abort(msg); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | MOZ_NORETURN MOZ_ALWAYS_INLINE void |
michael@0 | 59 | __throw_domain_error(const char* msg) |
michael@0 | 60 | { |
michael@0 | 61 | mozalloc_abort(msg); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | MOZ_NORETURN MOZ_ALWAYS_INLINE void |
michael@0 | 65 | __throw_invalid_argument(const char* msg) |
michael@0 | 66 | { |
michael@0 | 67 | mozalloc_abort(msg); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | MOZ_NORETURN MOZ_ALWAYS_INLINE void |
michael@0 | 71 | __throw_length_error(const char* msg) |
michael@0 | 72 | { |
michael@0 | 73 | mozalloc_abort(msg); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | MOZ_NORETURN MOZ_ALWAYS_INLINE void |
michael@0 | 77 | __throw_out_of_range(const char* msg) |
michael@0 | 78 | { |
michael@0 | 79 | mozalloc_abort(msg); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | MOZ_NORETURN MOZ_ALWAYS_INLINE void |
michael@0 | 83 | __throw_runtime_error(const char* msg) |
michael@0 | 84 | { |
michael@0 | 85 | mozalloc_abort(msg); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | MOZ_NORETURN MOZ_ALWAYS_INLINE void |
michael@0 | 89 | __throw_range_error(const char* msg) |
michael@0 | 90 | { |
michael@0 | 91 | mozalloc_abort(msg); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | MOZ_NORETURN MOZ_ALWAYS_INLINE void |
michael@0 | 95 | __throw_overflow_error(const char* msg) |
michael@0 | 96 | { |
michael@0 | 97 | mozalloc_abort(msg); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | MOZ_NORETURN MOZ_ALWAYS_INLINE void |
michael@0 | 101 | __throw_underflow_error(const char* msg) |
michael@0 | 102 | { |
michael@0 | 103 | mozalloc_abort(msg); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | MOZ_NORETURN MOZ_ALWAYS_INLINE void |
michael@0 | 107 | __throw_ios_failure(const char* msg) |
michael@0 | 108 | { |
michael@0 | 109 | mozalloc_abort(msg); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | MOZ_NORETURN MOZ_ALWAYS_INLINE void |
michael@0 | 113 | __throw_system_error(int err) |
michael@0 | 114 | { |
michael@0 | 115 | char error[128]; |
michael@0 | 116 | snprintf(error, sizeof(error)-1, |
michael@0 | 117 | "fatal: STL threw system_error: %s (%d)", strerror(err), err); |
michael@0 | 118 | mozalloc_abort(error); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | } // namespace std |
michael@0 | 122 | |
michael@0 | 123 | #endif // mozilla_throw_gcc_h |