Bug 761859 - Make mozalloc_abort use MOZ_CRASH to crash. r=ted
authorJeff Walden <jwalden@mit.edu>
Tue, 05 Jun 2012 16:49:30 -0700
changeset 95995 379e323cede98b5d030dea430d43046da91312a4
parent 95994 ca61695732aa7d2644c77acbda84c201295cefca
child 95996 ba7d94c7eee3002f9b16d42c2df4aec769993769
push id10333
push userjwalden@mit.edu
push dateWed, 06 Jun 2012 18:27:39 +0000
treeherdermozilla-inbound@379e323cede9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs761859
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 761859 - Make mozalloc_abort use MOZ_CRASH to crash. r=ted
memory/mozalloc/mozalloc_abort.cpp
toolkit/crashreporter/test/CrashTestUtils.jsm
toolkit/crashreporter/test/nsTestCrasher.cpp
toolkit/crashreporter/test/unit/test_crash_moz_crash.js
toolkit/crashreporter/test/unit/xpcshell.ini
--- a/memory/mozalloc/mozalloc_abort.cpp
+++ b/memory/mozalloc/mozalloc_abort.cpp
@@ -1,80 +1,31 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * vim: sw=4 ts=4 et :
  */
 /* 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/. */
 
-#include <stdio.h>
-#include <stdlib.h>             // for abort()
+#include "mozilla/Assertions.h"
 
-#if defined(_MSC_VER)           // MSVC
-#  include <intrin.h>           // for __debugbreak()
-#elif defined(XP_WIN)           // mingw
-#  include <windows.h>          // for DebugBreak
-#elif defined(XP_UNIX)
-#  include <unistd.h>           // for _exit
-#  include <signal.h>
-#endif
-
-#if defined(XP_WIN) || defined(XP_OS2)
-#  define MOZALLOC_EXPORT __declspec(dllexport)
-#endif
+#include <stdio.h>
 
 #include "mozilla/mozalloc_abort.h"
 
-static int gDummyCounter;
-
-// Not inlining this function avoids the compiler making optimizations
-// that end up corrupting stack traces.
-MOZ_NEVER_INLINE static void
-TouchBadMemory()
-{
-    // XXX this should use the frame poisoning code
-    volatile int *p = 0;
-    gDummyCounter += *p;   // TODO annotation saying we know 
-                           // this is crazy
-}
-
 void
 mozalloc_abort(const char* const msg)
 {
     fputs(msg, stderr);
     fputs("\n", stderr);
-
-#if defined(_MSC_VER)
-    __debugbreak();
-#elif defined(XP_WIN)
-    DebugBreak();
-#endif
-
-    // On *NIX platforms the prefered way to abort is by touching bad memory,
-    // since this generates a stack trace inside our own code (avoiding
-    // problems with starting the trace inside libc, where we might not have
-    // symbols and can get lost).
-
-    TouchBadMemory();
-
-    // If we haven't aborted yet, we can try to raise SIGABRT which might work
-    // on some *NIXs, but not OS X (it doesn't trigger breakpad there).
-    // Note that we don't call abort(), since raise is likelier to give us
-    // useful stack data, and also since abort() is redirected to call this
-    // function (see below).
-#if defined(XP_UNIX) && !defined(XP_MACOSX)
-    raise(SIGABRT);
-#endif
-
-    // Still haven't aborted?  Try _exit().
-    _exit(127);
+    MOZ_CRASH();
 }
 
 #if defined(XP_UNIX)
 // Define abort() here, so that it is used instead of the system abort(). This
 // lets us control the behavior when aborting, in order to get better results
-// on *NIX platfrorms. See mozalloc_abort for details.
+// on *NIX platforms. See mozalloc_abort for details.
 void abort(void)
 {
-  mozalloc_abort("Redirecting call to abort() to mozalloc_abort\n");
+    mozalloc_abort("Redirecting call to abort() to mozalloc_abort\n");
 }
 #endif
 
--- a/toolkit/crashreporter/test/CrashTestUtils.jsm
+++ b/toolkit/crashreporter/test/CrashTestUtils.jsm
@@ -8,16 +8,17 @@ let CrashTestUtils = {
   dumpHasInstructionPointerMemory: null,
 
   // Constants for crash()
   // Keep these in sync with nsTestCrasher.cpp!
   CRASH_INVALID_POINTER_DEREF: 0,
   CRASH_PURE_VIRTUAL_CALL:     1,
   CRASH_RUNTIMEABORT:          2,
   CRASH_OOM:                   3,
+  CRASH_MOZ_CRASH:             4,
 
   // Constants for dumpHasStream()
   // From google_breakpad/common/minidump_format.h
   MD_THREAD_LIST_STREAM:       3,
   MD_MEMORY_INFO_LIST_STREAM:  16
 };
 
 // Grab APIs from the testcrasher shared library
--- a/toolkit/crashreporter/test/nsTestCrasher.cpp
+++ b/toolkit/crashreporter/test/nsTestCrasher.cpp
@@ -1,8 +1,10 @@
+#include "mozilla/Assertions.h"
+
 #include <stdio.h>
 
 #include "nscore.h"
 #include "nsXULAppAPI.h"
 #include "nsExceptionHandler.h"
 
 /*
  * This pure virtual call example is from MSDN
@@ -37,16 +39,17 @@ void PureVirtualCall()
   b.use(); // make sure b's actually used
 }
 
 // Keep these in sync with CrashTestUtils.jsm!
 const PRInt16 CRASH_INVALID_POINTER_DEREF = 0;
 const PRInt16 CRASH_PURE_VIRTUAL_CALL     = 1;
 const PRInt16 CRASH_RUNTIMEABORT          = 2;
 const PRInt16 CRASH_OOM                   = 3;
+const PRInt16 CRASH_MOZ_CRASH             = 4;
 
 extern "C" NS_EXPORT
 void Crash(PRInt16 how)
 {
   switch (how) {
   case CRASH_INVALID_POINTER_DEREF: {
     volatile int* foo = (int*)0x42;
     *foo = 0;
@@ -63,16 +66,20 @@ void Crash(PRInt16 how)
     break;
   }
   case CRASH_OOM: {
     (void) moz_xmalloc((size_t) -1);
     (void) moz_xmalloc((size_t) -1);
     (void) moz_xmalloc((size_t) -1);
     break;
   }
+  case CRASH_MOZ_CRASH: {
+    MOZ_CRASH();
+    break;
+  }
   default:
     break;
   }
 }
 
 extern "C" NS_EXPORT
 nsISupports* LockDir(nsIFile *directory)
 {
new file mode 100644
--- /dev/null
+++ b/toolkit/crashreporter/test/unit/test_crash_moz_crash.js
@@ -0,0 +1,14 @@
+function run_test()
+{
+  // Try crashing with a runtime abort
+  do_crash(function() {
+             crashType = CrashTestUtils.CRASH_MOZ_CRASH;
+             crashReporter.annotateCrashReport("TestKey", "TestValue");
+           },
+           function(mdump, extra) {
+             do_check_eq(extra.TestKey, "TestValue");
+             do_check_false("OOMAllocationSize" in extra);
+           },
+          // process will exit with a zero exit status
+          true);
+}
--- a/toolkit/crashreporter/test/unit/xpcshell.ini
+++ b/toolkit/crashreporter/test/unit/xpcshell.ini
@@ -1,12 +1,13 @@
 [DEFAULT]
 head = head_crashreporter.js
 tail = 
 
+[test_crash_moz_crash.js]
 [test_crash_purevirtual.js]
 [test_crash_runtimeabort.js]
 [test_crash_oom.js]
 [test_crashreporter.js]
 [test_crashreporter_crash.js]
 [test_crashreporter_crash_profile_lock.js]
 
 [test_crashreporter_appmem.js]