mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 761859 - Make mozalloc_abort use MOZ_CRASH to crash. r=ted
This commit is contained in:
parent
4a95d2f73e
commit
a694790f7c
@ -5,76 +5,27 @@
|
||||
* 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 "mozilla/Assertions.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> // for abort()
|
||||
|
||||
#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 "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
|
||||
|
||||
|
@ -13,6 +13,7 @@ let CrashTestUtils = {
|
||||
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
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include "mozilla/Assertions.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "nscore.h"
|
||||
@ -42,6 +44,7 @@ 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)
|
||||
@ -68,6 +71,10 @@ void Crash(PRInt16 how)
|
||||
(void) moz_xmalloc((size_t) -1);
|
||||
break;
|
||||
}
|
||||
case CRASH_MOZ_CRASH: {
|
||||
MOZ_CRASH();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
14
toolkit/crashreporter/test/unit/test_crash_moz_crash.js
Normal file
14
toolkit/crashreporter/test/unit/test_crash_moz_crash.js
Normal file
@ -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);
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
head = head_crashreporter.js
|
||||
tail =
|
||||
|
||||
[test_crash_moz_crash.js]
|
||||
[test_crash_purevirtual.js]
|
||||
[test_crash_runtimeabort.js]
|
||||
[test_crash_oom.js]
|
||||
|
Loading…
Reference in New Issue
Block a user