LCOV - code coverage report
Current view: top level - memory/mozalloc - throw_gcc.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 12 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : // libc++ 4.0.0 and higher use C++11 [[noreturn]] attributes for the functions
      23             : // below, and since clang does not allow mixing __attribute__((noreturn)) and
      24             : // [[noreturn]], we have to explicitly use the latter here.  See bug 1329520.
      25             : #if defined(__clang__)
      26             : #  if __has_feature(cxx_attributes) && \
      27             :       defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 4000
      28             : #    define MOZ_THROW_NORETURN [[noreturn]]
      29             : #  endif
      30             : #endif
      31             : #ifndef MOZ_THROW_NORETURN
      32             : #  define MOZ_THROW_NORETURN MOZ_NORETURN
      33             : #endif
      34             : 
      35             : 
      36             : // MinGW doesn't appropriately inline these functions in debug builds,
      37             : // so we need to do some extra coercion for it to do so. Bug 1332747
      38             : #ifdef __MINGW32__
      39             : #  define MOZ_THROW_INLINE MOZ_ALWAYS_INLINE_EVEN_DEBUG
      40             : #else
      41             : #  define MOZ_THROW_INLINE MOZ_ALWAYS_INLINE
      42             : #endif
      43             : 
      44             : namespace std {
      45             : 
      46             : // NB: user code is not supposed to touch the std:: namespace.  We're
      47             : // doing this after careful review because we want to define our own
      48             : // exception throwing semantics.  Don't try this at home!
      49             : 
      50             : MOZ_THROW_NORETURN MOZ_EXPORT MOZ_THROW_INLINE void
      51             : __throw_bad_exception(void)
      52             : {
      53             :     mozalloc_abort("fatal: STL threw bad_exception");
      54             : }
      55             : 
      56             : MOZ_THROW_NORETURN MOZ_EXPORT MOZ_THROW_INLINE void
      57           0 : __throw_bad_alloc(void)
      58             : {
      59           0 :     mozalloc_abort("fatal: STL threw bad_alloc");
      60             : }
      61             : 
      62             : MOZ_THROW_NORETURN MOZ_EXPORT MOZ_THROW_INLINE void
      63           0 : __throw_bad_cast(void)
      64             : {
      65           0 :     mozalloc_abort("fatal: STL threw bad_cast");
      66             : }
      67             : 
      68             : MOZ_THROW_NORETURN MOZ_EXPORT MOZ_THROW_INLINE void
      69             : __throw_bad_typeid(void)
      70             : {
      71             :     mozalloc_abort("fatal: STL threw bad_typeid");
      72             : }
      73             : 
      74             : // used by <functional>
      75             : MOZ_THROW_NORETURN MOZ_EXPORT MOZ_THROW_INLINE void
      76           0 : __throw_bad_function_call(void)
      77             : {
      78           0 :     mozalloc_abort("fatal: STL threw bad_function_call");
      79             : }
      80             : 
      81             : MOZ_THROW_NORETURN MOZ_EXPORT MOZ_THROW_INLINE void
      82           0 : __throw_logic_error(const char* msg)
      83             : {
      84           0 :     mozalloc_abort(msg);
      85             : }
      86             : 
      87             : MOZ_THROW_NORETURN MOZ_EXPORT MOZ_THROW_INLINE void
      88             : __throw_domain_error(const char* msg)
      89             : {
      90             :     mozalloc_abort(msg);
      91             : }
      92             : 
      93             : MOZ_THROW_NORETURN MOZ_EXPORT MOZ_THROW_INLINE void
      94             : __throw_invalid_argument(const char* msg)
      95             : {
      96             :     mozalloc_abort(msg);
      97             : }
      98             : 
      99             : MOZ_THROW_NORETURN MOZ_EXPORT MOZ_THROW_INLINE void
     100           0 : __throw_length_error(const char* msg)
     101             : {
     102           0 :     mozalloc_abort(msg);
     103             : }
     104             : 
     105             : MOZ_THROW_NORETURN MOZ_EXPORT MOZ_THROW_INLINE void
     106           0 : __throw_out_of_range(const char* msg)
     107             : {
     108           0 :     mozalloc_abort(msg);
     109             : }
     110             : 
     111             : MOZ_THROW_NORETURN MOZ_EXPORT MOZ_THROW_INLINE void
     112             : __throw_runtime_error(const char* msg)
     113             : {
     114             :     mozalloc_abort(msg);
     115             : }
     116             : 
     117             : MOZ_THROW_NORETURN MOZ_EXPORT MOZ_THROW_INLINE void
     118             : __throw_range_error(const char* msg)
     119             : {
     120             :     mozalloc_abort(msg);
     121             : }
     122             : 
     123             : MOZ_THROW_NORETURN MOZ_EXPORT MOZ_THROW_INLINE void
     124             : __throw_overflow_error(const char* msg)
     125             : {
     126             :     mozalloc_abort(msg);
     127             : }
     128             : 
     129             : MOZ_THROW_NORETURN MOZ_EXPORT MOZ_THROW_INLINE void
     130             : __throw_underflow_error(const char* msg)
     131             : {
     132             :     mozalloc_abort(msg);
     133             : }
     134             : 
     135             : MOZ_THROW_NORETURN MOZ_EXPORT MOZ_THROW_INLINE void
     136             : __throw_ios_failure(const char* msg)
     137             : {
     138             :     mozalloc_abort(msg);
     139             : }
     140             : 
     141             : MOZ_THROW_NORETURN MOZ_EXPORT MOZ_THROW_INLINE void
     142             : __throw_system_error(int err)
     143             : {
     144             :     char error[128];
     145             :     snprintf(error, sizeof(error)-1,
     146             :              "fatal: STL threw system_error: %s (%d)", strerror(err), err);
     147             :     mozalloc_abort(error);
     148             : }
     149             : 
     150             : } // namespace std
     151             : 
     152             : #undef MOZ_THROW_NORETURN
     153             : #undef MOZ_THROW_INLINE
     154             : 
     155             : #endif  // mozilla_throw_gcc_h

Generated by: LCOV version 1.13