mozalloc_abort.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #include "mozilla/mozalloc_abort.h"
  8. #include <stdio.h>
  9. #include "mozilla/Assertions.h"
  10. void
  11. mozalloc_abort(const char* const msg)
  12. {
  13. fputs(msg, stderr);
  14. fputs("\n", stderr);
  15. MOZ_CRASH();
  16. }
  17. #if defined(XP_UNIX) && !defined(MOZ_ASAN)
  18. // Define abort() here, so that it is used instead of the system abort(). This
  19. // lets us control the behavior when aborting, in order to get better results
  20. // on *NIX platforms. See mozalloc_abort for details.
  21. //
  22. // For AddressSanitizer, we must not redefine system abort because the ASan
  23. // option "abort_on_error=1" calls abort() and therefore causes the following
  24. // call chain with our redefined abort:
  25. //
  26. // ASan -> abort() -> moz_abort() -> MOZ_CRASH() -> Segmentation fault
  27. //
  28. // That segmentation fault will be interpreted as another bug by ASan and as a
  29. // result, ASan will just exit(1) instead of aborting.
  30. extern "C" void abort(void)
  31. {
  32. const char* const msg = "Redirecting call to abort() to mozalloc_abort\n";
  33. mozalloc_abort(msg);
  34. // We won't reach here because mozalloc_abort() is MOZ_NORETURN. But that
  35. // annotation isn't used on ARM (see mozalloc_abort.h for why) so we add a
  36. // redundant MOZ_CRASH() here to avoid a "'noreturn' function does return"
  37. // warning.
  38. MOZ_CRASH();
  39. }
  40. #endif