2012-06-05 16:49:30 -07:00
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
|
2011-07-07 17:31:11 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2011-01-12 11:14:15 -08:00
|
|
|
#include "nscore.h"
|
2009-12-14 03:44:27 -08:00
|
|
|
#include "nsXULAppAPI.h"
|
2011-07-07 17:31:11 -07:00
|
|
|
#include "nsExceptionHandler.h"
|
2012-05-14 04:38:46 -07:00
|
|
|
#include "mozilla/unused.h"
|
2009-09-10 04:49:42 -07:00
|
|
|
|
2010-05-04 12:34:55 -07:00
|
|
|
/*
|
|
|
|
* This pure virtual call example is from MSDN
|
|
|
|
*/
|
|
|
|
class A;
|
|
|
|
|
|
|
|
void fcn( A* );
|
|
|
|
|
|
|
|
class A
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void f() = 0;
|
|
|
|
A() { fcn( this ); }
|
|
|
|
};
|
|
|
|
|
|
|
|
class B : A
|
|
|
|
{
|
|
|
|
void f() { }
|
2011-12-17 22:00:42 -08:00
|
|
|
public:
|
|
|
|
void use() { }
|
2010-05-04 12:34:55 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void fcn( A* p )
|
|
|
|
{
|
|
|
|
p->f();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PureVirtualCall()
|
|
|
|
{
|
|
|
|
// generates a pure virtual function call
|
|
|
|
B b;
|
2011-12-17 22:00:42 -08:00
|
|
|
b.use(); // make sure b's actually used
|
2010-05-04 12:34:55 -07:00
|
|
|
}
|
|
|
|
|
2011-01-12 11:14:15 -08:00
|
|
|
// Keep these in sync with CrashTestUtils.jsm!
|
2012-08-22 08:56:38 -07:00
|
|
|
const int16_t CRASH_INVALID_POINTER_DEREF = 0;
|
|
|
|
const int16_t CRASH_PURE_VIRTUAL_CALL = 1;
|
|
|
|
const int16_t CRASH_RUNTIMEABORT = 2;
|
|
|
|
const int16_t CRASH_OOM = 3;
|
|
|
|
const int16_t CRASH_MOZ_CRASH = 4;
|
2013-09-16 11:44:25 -07:00
|
|
|
const int16_t CRASH_ABORT = 5;
|
2011-01-12 11:14:15 -08:00
|
|
|
|
|
|
|
extern "C" NS_EXPORT
|
2012-08-22 08:56:38 -07:00
|
|
|
void Crash(int16_t how)
|
2009-09-10 04:49:42 -07:00
|
|
|
{
|
2010-05-04 12:34:55 -07:00
|
|
|
switch (how) {
|
2011-01-12 11:14:15 -08:00
|
|
|
case CRASH_INVALID_POINTER_DEREF: {
|
2010-05-04 12:34:55 -07:00
|
|
|
volatile int* foo = (int*)0x42;
|
|
|
|
*foo = 0;
|
|
|
|
// not reached
|
|
|
|
break;
|
|
|
|
}
|
2011-01-12 11:14:15 -08:00
|
|
|
case CRASH_PURE_VIRTUAL_CALL: {
|
2010-05-04 12:34:55 -07:00
|
|
|
PureVirtualCall();
|
|
|
|
// not reached
|
|
|
|
break;
|
|
|
|
}
|
2011-01-12 11:14:15 -08:00
|
|
|
case CRASH_RUNTIMEABORT: {
|
2011-01-12 06:20:06 -08:00
|
|
|
NS_RUNTIMEABORT("Intentional crash");
|
|
|
|
break;
|
|
|
|
}
|
2012-01-24 08:08:51 -08:00
|
|
|
case CRASH_OOM: {
|
2012-05-14 04:38:46 -07:00
|
|
|
mozilla::unused << moz_xmalloc((size_t) -1);
|
|
|
|
mozilla::unused << moz_xmalloc((size_t) -1);
|
|
|
|
mozilla::unused << moz_xmalloc((size_t) -1);
|
2012-01-24 08:08:51 -08:00
|
|
|
break;
|
|
|
|
}
|
2012-06-05 16:49:30 -07:00
|
|
|
case CRASH_MOZ_CRASH: {
|
|
|
|
MOZ_CRASH();
|
|
|
|
break;
|
|
|
|
}
|
2013-09-16 11:44:25 -07:00
|
|
|
case CRASH_ABORT: {
|
|
|
|
abort();
|
|
|
|
break;
|
|
|
|
}
|
2010-05-04 12:34:55 -07:00
|
|
|
default:
|
2011-01-12 11:14:15 -08:00
|
|
|
break;
|
2010-05-04 12:34:55 -07:00
|
|
|
}
|
2009-09-10 04:49:42 -07:00
|
|
|
}
|
|
|
|
|
2011-01-12 11:14:15 -08:00
|
|
|
extern "C" NS_EXPORT
|
2012-06-05 19:08:30 -07:00
|
|
|
nsISupports* LockDir(nsIFile *directory)
|
2009-12-14 03:44:27 -08:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsISupports* lockfile = nullptr;
|
2011-01-12 11:14:15 -08:00
|
|
|
XRE_LockProfileDirectory(directory, &lockfile);
|
|
|
|
return lockfile;
|
2009-12-14 03:44:27 -08:00
|
|
|
}
|
2011-07-07 17:31:11 -07:00
|
|
|
|
|
|
|
char testData[32];
|
|
|
|
|
|
|
|
extern "C" NS_EXPORT
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t SaveAppMemory()
|
2011-07-07 17:31:11 -07:00
|
|
|
{
|
|
|
|
for (size_t i=0; i<sizeof(testData); i++)
|
|
|
|
testData[i] = i;
|
|
|
|
|
|
|
|
FILE *fp = fopen("crash-addr", "w");
|
|
|
|
if (!fp)
|
|
|
|
return 0;
|
|
|
|
fprintf(fp, "%p\n", (void *)testData);
|
|
|
|
fclose(fp);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
return (int64_t)testData;
|
2011-07-07 17:31:11 -07:00
|
|
|
}
|
2012-09-20 07:57:08 -07:00
|
|
|
|
|
|
|
#ifdef XP_WIN32
|
|
|
|
static LONG WINAPI HandleException(EXCEPTION_POINTERS* exinfo)
|
|
|
|
{
|
|
|
|
TerminateProcess(GetCurrentProcess(), 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" NS_EXPORT
|
|
|
|
void TryOverrideExceptionHandler()
|
|
|
|
{
|
|
|
|
SetUnhandledExceptionFilter(HandleException);
|
|
|
|
}
|
|
|
|
#endif
|