memory/mozalloc/throw_gcc.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/memory/mozalloc/throw_gcc.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,123 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: sw=4 ts=4 et :
     1.6 + */
     1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.10 +
    1.11 +#ifndef mozilla_throw_gcc_h
    1.12 +#define mozilla_throw_gcc_h
    1.13 +
    1.14 +#include "mozilla/Attributes.h"
    1.15 +
    1.16 +#include <stdio.h>              // snprintf
    1.17 +#include <string.h>             // strerror
    1.18 +
    1.19 +// For gcc, we define these inline to abort so that we're absolutely
    1.20 +// certain that (i) no exceptions are thrown from Gecko; (ii) these
    1.21 +// errors are always terminal and caught by breakpad.
    1.22 +
    1.23 +#include "mozilla/mozalloc_abort.h"
    1.24 +
    1.25 +namespace std {
    1.26 +
    1.27 +// NB: user code is not supposed to touch the std:: namespace.  We're
    1.28 +// doing this after careful review because we want to define our own
    1.29 +// exception throwing semantics.  Don't try this at home!
    1.30 +
    1.31 +MOZ_NORETURN MOZ_ALWAYS_INLINE void
    1.32 +__throw_bad_exception(void)
    1.33 +{
    1.34 +    mozalloc_abort("fatal: STL threw bad_exception");
    1.35 +}
    1.36 +
    1.37 +MOZ_NORETURN MOZ_ALWAYS_INLINE void
    1.38 +__throw_bad_alloc(void)
    1.39 +{
    1.40 +    mozalloc_abort("fatal: STL threw bad_alloc");
    1.41 +}
    1.42 +
    1.43 +MOZ_NORETURN MOZ_ALWAYS_INLINE void
    1.44 +__throw_bad_cast(void)
    1.45 +{
    1.46 +    mozalloc_abort("fatal: STL threw bad_cast");
    1.47 +}
    1.48 +
    1.49 +MOZ_NORETURN MOZ_ALWAYS_INLINE void
    1.50 +__throw_bad_typeid(void)
    1.51 +{
    1.52 +    mozalloc_abort("fatal: STL threw bad_typeid");
    1.53 +}
    1.54 +
    1.55 +MOZ_NORETURN MOZ_ALWAYS_INLINE void
    1.56 +__throw_logic_error(const char* msg)
    1.57 +{
    1.58 +    mozalloc_abort(msg);
    1.59 +}
    1.60 +
    1.61 +MOZ_NORETURN MOZ_ALWAYS_INLINE void
    1.62 +__throw_domain_error(const char* msg)
    1.63 +{
    1.64 +    mozalloc_abort(msg);
    1.65 +}
    1.66 +
    1.67 +MOZ_NORETURN MOZ_ALWAYS_INLINE void
    1.68 +__throw_invalid_argument(const char* msg)
    1.69 +{
    1.70 +    mozalloc_abort(msg);
    1.71 +}
    1.72 +
    1.73 +MOZ_NORETURN MOZ_ALWAYS_INLINE void
    1.74 +__throw_length_error(const char* msg)
    1.75 +{
    1.76 +    mozalloc_abort(msg);
    1.77 +}
    1.78 +
    1.79 +MOZ_NORETURN MOZ_ALWAYS_INLINE void
    1.80 +__throw_out_of_range(const char* msg)
    1.81 +{
    1.82 +    mozalloc_abort(msg);
    1.83 +}
    1.84 +
    1.85 +MOZ_NORETURN MOZ_ALWAYS_INLINE void
    1.86 +__throw_runtime_error(const char* msg)
    1.87 +{
    1.88 +    mozalloc_abort(msg);
    1.89 +}
    1.90 +
    1.91 +MOZ_NORETURN MOZ_ALWAYS_INLINE void
    1.92 +__throw_range_error(const char* msg)
    1.93 +{
    1.94 +    mozalloc_abort(msg);
    1.95 +}
    1.96 +
    1.97 +MOZ_NORETURN MOZ_ALWAYS_INLINE void
    1.98 +__throw_overflow_error(const char* msg)
    1.99 +{
   1.100 +    mozalloc_abort(msg);
   1.101 +}
   1.102 +
   1.103 +MOZ_NORETURN MOZ_ALWAYS_INLINE void
   1.104 +__throw_underflow_error(const char* msg)
   1.105 +{
   1.106 +    mozalloc_abort(msg);
   1.107 +}
   1.108 +
   1.109 +MOZ_NORETURN MOZ_ALWAYS_INLINE void
   1.110 +__throw_ios_failure(const char* msg)
   1.111 +{
   1.112 +    mozalloc_abort(msg);
   1.113 +}
   1.114 +
   1.115 +MOZ_NORETURN MOZ_ALWAYS_INLINE void
   1.116 +__throw_system_error(int err)
   1.117 +{
   1.118 +    char error[128];
   1.119 +    snprintf(error, sizeof(error)-1,
   1.120 +             "fatal: STL threw system_error: %s (%d)", strerror(err), err);
   1.121 +    mozalloc_abort(error);
   1.122 +}
   1.123 +
   1.124 +} // namespace std
   1.125 +
   1.126 +#endif  // mozilla_throw_gcc_h

mercurial