2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2018-11-30 18:39:55 +03:00
|
|
|
* vim: sw=2 ts=4 et :
|
2010-04-02 21:58:11 +04:00
|
|
|
*/
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-04-02 21:58:11 +04:00
|
|
|
|
2010-04-21 00:12:02 +04:00
|
|
|
#ifndef mozilla_throw_gcc_h
|
|
|
|
#define mozilla_throw_gcc_h
|
2010-04-02 21:58:11 +04:00
|
|
|
|
2011-12-18 01:45:29 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
|
2010-04-21 00:12:02 +04:00
|
|
|
#include <stdio.h> // snprintf
|
2010-04-22 08:41:41 +04:00
|
|
|
#include <string.h> // strerror
|
2010-04-02 21:58:11 +04:00
|
|
|
|
|
|
|
// For gcc, we define these inline to abort so that we're absolutely
|
|
|
|
// certain that (i) no exceptions are thrown from Gecko; (ii) these
|
|
|
|
// errors are always terminal and caught by breakpad.
|
|
|
|
|
2010-04-21 00:12:02 +04:00
|
|
|
#include "mozilla/mozalloc_abort.h"
|
2010-04-02 21:58:11 +04:00
|
|
|
|
2017-01-27 15:55:00 +03:00
|
|
|
// libc++ 4.0.0 and higher use C++11 [[noreturn]] attributes for the functions
|
|
|
|
// below, and since clang does not allow mixing __attribute__((noreturn)) and
|
|
|
|
// [[noreturn]], we have to explicitly use the latter here. See bug 1329520.
|
|
|
|
#if defined(__clang__)
|
|
|
|
#if __has_feature(cxx_attributes) && defined(_LIBCPP_VERSION) && \
|
|
|
|
_LIBCPP_VERSION >= 4000
|
|
|
|
#define MOZ_THROW_NORETURN [[noreturn]]
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifndef MOZ_THROW_NORETURN
|
|
|
|
#define MOZ_THROW_NORETURN MOZ_NORETURN
|
|
|
|
#endif
|
|
|
|
|
2017-04-11 20:53:58 +03:00
|
|
|
// MinGW doesn't appropriately inline these functions in debug builds,
|
|
|
|
// so we need to do some extra coercion for it to do so. Bug 1332747
|
|
|
|
#ifdef __MINGW32__
|
|
|
|
#define MOZ_THROW_INLINE MOZ_ALWAYS_INLINE_EVEN_DEBUG
|
2018-06-26 19:55:14 +03:00
|
|
|
#define MOZ_THROW_EXPORT
|
2017-04-11 20:53:58 +03:00
|
|
|
#else
|
|
|
|
#define MOZ_THROW_INLINE MOZ_ALWAYS_INLINE
|
2018-06-26 19:55:14 +03:00
|
|
|
#define MOZ_THROW_EXPORT MOZ_EXPORT
|
2017-04-11 20:53:58 +03:00
|
|
|
#endif
|
|
|
|
|
2010-04-02 21:58:11 +04:00
|
|
|
namespace std {
|
|
|
|
|
2010-04-21 00:12:02 +04:00
|
|
|
// NB: user code is not supposed to touch the std:: namespace. We're
|
|
|
|
// doing this after careful review because we want to define our own
|
|
|
|
// exception throwing semantics. Don't try this at home!
|
|
|
|
|
2018-06-26 19:55:14 +03:00
|
|
|
MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_bad_exception(
|
2010-04-02 21:58:11 +04:00
|
|
|
void) {
|
2010-04-21 00:12:02 +04:00
|
|
|
mozalloc_abort("fatal: STL threw bad_exception");
|
2010-04-02 21:58:11 +04:00
|
|
|
}
|
|
|
|
|
2018-06-26 19:55:14 +03:00
|
|
|
MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_bad_alloc(
|
2010-04-02 21:58:11 +04:00
|
|
|
void) {
|
2010-04-21 00:12:02 +04:00
|
|
|
mozalloc_abort("fatal: STL threw bad_alloc");
|
2010-04-02 21:58:11 +04:00
|
|
|
}
|
|
|
|
|
2018-06-26 19:55:14 +03:00
|
|
|
MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_bad_cast(
|
2010-04-02 21:58:11 +04:00
|
|
|
void) {
|
2010-04-21 00:12:02 +04:00
|
|
|
mozalloc_abort("fatal: STL threw bad_cast");
|
2010-04-02 21:58:11 +04:00
|
|
|
}
|
|
|
|
|
2018-06-26 19:55:14 +03:00
|
|
|
MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_bad_typeid(
|
2010-04-02 21:58:11 +04:00
|
|
|
void) {
|
2010-04-21 00:12:02 +04:00
|
|
|
mozalloc_abort("fatal: STL threw bad_typeid");
|
2010-04-02 21:58:11 +04:00
|
|
|
}
|
|
|
|
|
2016-02-25 04:00:10 +03:00
|
|
|
// used by <functional>
|
2018-06-26 19:55:14 +03:00
|
|
|
MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void
|
2016-02-25 04:00:10 +03:00
|
|
|
__throw_bad_function_call(void) {
|
|
|
|
mozalloc_abort("fatal: STL threw bad_function_call");
|
|
|
|
}
|
|
|
|
|
2018-06-26 19:55:14 +03:00
|
|
|
MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_logic_error(
|
2010-04-02 21:58:11 +04:00
|
|
|
const char* msg) {
|
2010-04-21 00:12:02 +04:00
|
|
|
mozalloc_abort(msg);
|
2010-04-02 21:58:11 +04:00
|
|
|
}
|
|
|
|
|
2018-06-26 19:55:14 +03:00
|
|
|
MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_domain_error(
|
2010-04-02 21:58:11 +04:00
|
|
|
const char* msg) {
|
2010-04-21 00:12:02 +04:00
|
|
|
mozalloc_abort(msg);
|
2010-04-02 21:58:11 +04:00
|
|
|
}
|
|
|
|
|
2018-06-26 19:55:14 +03:00
|
|
|
MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void
|
2011-12-18 01:45:29 +04:00
|
|
|
__throw_invalid_argument(const char* msg) {
|
2010-04-21 00:12:02 +04:00
|
|
|
mozalloc_abort(msg);
|
2010-04-02 21:58:11 +04:00
|
|
|
}
|
|
|
|
|
2018-06-26 19:55:14 +03:00
|
|
|
MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_length_error(
|
2011-12-18 01:45:29 +04:00
|
|
|
const char* msg) {
|
2010-04-21 00:12:02 +04:00
|
|
|
mozalloc_abort(msg);
|
2010-04-02 21:58:11 +04:00
|
|
|
}
|
|
|
|
|
2018-06-26 19:55:14 +03:00
|
|
|
MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_out_of_range(
|
2011-12-18 01:45:29 +04:00
|
|
|
const char* msg) {
|
2010-04-21 00:12:02 +04:00
|
|
|
mozalloc_abort(msg);
|
2010-04-02 21:58:11 +04:00
|
|
|
}
|
|
|
|
|
2018-06-26 19:55:14 +03:00
|
|
|
MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_runtime_error(
|
2011-12-18 01:45:29 +04:00
|
|
|
const char* msg) {
|
2010-04-21 00:12:02 +04:00
|
|
|
mozalloc_abort(msg);
|
2010-04-02 21:58:11 +04:00
|
|
|
}
|
|
|
|
|
2018-06-26 19:55:14 +03:00
|
|
|
MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_range_error(
|
2011-12-18 01:45:29 +04:00
|
|
|
const char* msg) {
|
2010-04-21 00:12:02 +04:00
|
|
|
mozalloc_abort(msg);
|
2010-04-02 21:58:11 +04:00
|
|
|
}
|
|
|
|
|
2018-06-26 19:55:14 +03:00
|
|
|
MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void
|
2011-12-18 01:45:29 +04:00
|
|
|
__throw_overflow_error(const char* msg) {
|
2010-04-21 00:12:02 +04:00
|
|
|
mozalloc_abort(msg);
|
2010-04-02 21:58:11 +04:00
|
|
|
}
|
|
|
|
|
2018-06-26 19:55:14 +03:00
|
|
|
MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void
|
2011-12-18 01:45:29 +04:00
|
|
|
__throw_underflow_error(const char* msg) {
|
2010-04-21 00:12:02 +04:00
|
|
|
mozalloc_abort(msg);
|
2010-04-02 21:58:11 +04:00
|
|
|
}
|
|
|
|
|
2018-06-26 19:55:14 +03:00
|
|
|
MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_ios_failure(
|
2011-12-18 01:45:29 +04:00
|
|
|
const char* msg) {
|
2010-04-21 00:12:02 +04:00
|
|
|
mozalloc_abort(msg);
|
2010-04-02 21:58:11 +04:00
|
|
|
}
|
|
|
|
|
2018-06-26 19:55:14 +03:00
|
|
|
MOZ_THROW_NORETURN MOZ_THROW_EXPORT MOZ_THROW_INLINE void __throw_system_error(
|
2011-12-18 01:45:29 +04:00
|
|
|
int err) {
|
2010-04-21 00:12:02 +04:00
|
|
|
char error[128];
|
|
|
|
snprintf(error, sizeof(error) - 1, "fatal: STL threw system_error: %s (%d)",
|
|
|
|
strerror(err), err);
|
|
|
|
mozalloc_abort(error);
|
2010-04-02 21:58:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace std
|
|
|
|
|
2017-01-27 15:55:00 +03:00
|
|
|
#undef MOZ_THROW_NORETURN
|
2017-04-11 20:53:58 +03:00
|
|
|
#undef MOZ_THROW_INLINE
|
2017-01-27 15:55:00 +03:00
|
|
|
|
2010-04-21 00:12:02 +04:00
|
|
|
#endif // mozilla_throw_gcc_h
|