michael@0: #include "mozilla/Assertions.h" michael@0: michael@0: #include michael@0: michael@0: #include "nscore.h" michael@0: #include "nsXULAppAPI.h" michael@0: #include "nsExceptionHandler.h" michael@0: #include "mozilla/unused.h" michael@0: michael@0: /* michael@0: * This pure virtual call example is from MSDN michael@0: */ michael@0: class A; michael@0: michael@0: void fcn( A* ); michael@0: michael@0: class A michael@0: { michael@0: public: michael@0: virtual void f() = 0; michael@0: A() { fcn( this ); } michael@0: }; michael@0: michael@0: class B : A michael@0: { michael@0: void f() { } michael@0: public: michael@0: void use() { } michael@0: }; michael@0: michael@0: void fcn( A* p ) michael@0: { michael@0: p->f(); michael@0: } michael@0: michael@0: void PureVirtualCall() michael@0: { michael@0: // generates a pure virtual function call michael@0: B b; michael@0: b.use(); // make sure b's actually used michael@0: } michael@0: michael@0: // Keep these in sync with CrashTestUtils.jsm! michael@0: const int16_t CRASH_INVALID_POINTER_DEREF = 0; michael@0: const int16_t CRASH_PURE_VIRTUAL_CALL = 1; michael@0: const int16_t CRASH_RUNTIMEABORT = 2; michael@0: const int16_t CRASH_OOM = 3; michael@0: const int16_t CRASH_MOZ_CRASH = 4; michael@0: const int16_t CRASH_ABORT = 5; michael@0: michael@0: extern "C" NS_EXPORT michael@0: void Crash(int16_t how) michael@0: { michael@0: switch (how) { michael@0: case CRASH_INVALID_POINTER_DEREF: { michael@0: volatile int* foo = (int*)0x42; michael@0: *foo = 0; michael@0: // not reached michael@0: break; michael@0: } michael@0: case CRASH_PURE_VIRTUAL_CALL: { michael@0: PureVirtualCall(); michael@0: // not reached michael@0: break; michael@0: } michael@0: case CRASH_RUNTIMEABORT: { michael@0: NS_RUNTIMEABORT("Intentional crash"); michael@0: break; michael@0: } michael@0: case CRASH_OOM: { michael@0: mozilla::unused << moz_xmalloc((size_t) -1); michael@0: mozilla::unused << moz_xmalloc((size_t) -1); michael@0: mozilla::unused << moz_xmalloc((size_t) -1); michael@0: break; michael@0: } michael@0: case CRASH_MOZ_CRASH: { michael@0: MOZ_CRASH(); michael@0: break; michael@0: } michael@0: case CRASH_ABORT: { michael@0: abort(); michael@0: break; michael@0: } michael@0: default: michael@0: break; michael@0: } michael@0: } michael@0: michael@0: extern "C" NS_EXPORT michael@0: nsISupports* LockDir(nsIFile *directory) michael@0: { michael@0: nsISupports* lockfile = nullptr; michael@0: XRE_LockProfileDirectory(directory, &lockfile); michael@0: return lockfile; michael@0: } michael@0: michael@0: char testData[32]; michael@0: michael@0: extern "C" NS_EXPORT michael@0: uint64_t SaveAppMemory() michael@0: { michael@0: for (size_t i=0; i