Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #include "mozilla/Assertions.h" |
michael@0 | 2 | |
michael@0 | 3 | #include <stdio.h> |
michael@0 | 4 | |
michael@0 | 5 | #include "nscore.h" |
michael@0 | 6 | #include "nsXULAppAPI.h" |
michael@0 | 7 | #include "nsExceptionHandler.h" |
michael@0 | 8 | #include "mozilla/unused.h" |
michael@0 | 9 | |
michael@0 | 10 | /* |
michael@0 | 11 | * This pure virtual call example is from MSDN |
michael@0 | 12 | */ |
michael@0 | 13 | class A; |
michael@0 | 14 | |
michael@0 | 15 | void fcn( A* ); |
michael@0 | 16 | |
michael@0 | 17 | class A |
michael@0 | 18 | { |
michael@0 | 19 | public: |
michael@0 | 20 | virtual void f() = 0; |
michael@0 | 21 | A() { fcn( this ); } |
michael@0 | 22 | }; |
michael@0 | 23 | |
michael@0 | 24 | class B : A |
michael@0 | 25 | { |
michael@0 | 26 | void f() { } |
michael@0 | 27 | public: |
michael@0 | 28 | void use() { } |
michael@0 | 29 | }; |
michael@0 | 30 | |
michael@0 | 31 | void fcn( A* p ) |
michael@0 | 32 | { |
michael@0 | 33 | p->f(); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | void PureVirtualCall() |
michael@0 | 37 | { |
michael@0 | 38 | // generates a pure virtual function call |
michael@0 | 39 | B b; |
michael@0 | 40 | b.use(); // make sure b's actually used |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | // Keep these in sync with CrashTestUtils.jsm! |
michael@0 | 44 | const int16_t CRASH_INVALID_POINTER_DEREF = 0; |
michael@0 | 45 | const int16_t CRASH_PURE_VIRTUAL_CALL = 1; |
michael@0 | 46 | const int16_t CRASH_RUNTIMEABORT = 2; |
michael@0 | 47 | const int16_t CRASH_OOM = 3; |
michael@0 | 48 | const int16_t CRASH_MOZ_CRASH = 4; |
michael@0 | 49 | const int16_t CRASH_ABORT = 5; |
michael@0 | 50 | |
michael@0 | 51 | extern "C" NS_EXPORT |
michael@0 | 52 | void Crash(int16_t how) |
michael@0 | 53 | { |
michael@0 | 54 | switch (how) { |
michael@0 | 55 | case CRASH_INVALID_POINTER_DEREF: { |
michael@0 | 56 | volatile int* foo = (int*)0x42; |
michael@0 | 57 | *foo = 0; |
michael@0 | 58 | // not reached |
michael@0 | 59 | break; |
michael@0 | 60 | } |
michael@0 | 61 | case CRASH_PURE_VIRTUAL_CALL: { |
michael@0 | 62 | PureVirtualCall(); |
michael@0 | 63 | // not reached |
michael@0 | 64 | break; |
michael@0 | 65 | } |
michael@0 | 66 | case CRASH_RUNTIMEABORT: { |
michael@0 | 67 | NS_RUNTIMEABORT("Intentional crash"); |
michael@0 | 68 | break; |
michael@0 | 69 | } |
michael@0 | 70 | case CRASH_OOM: { |
michael@0 | 71 | mozilla::unused << moz_xmalloc((size_t) -1); |
michael@0 | 72 | mozilla::unused << moz_xmalloc((size_t) -1); |
michael@0 | 73 | mozilla::unused << moz_xmalloc((size_t) -1); |
michael@0 | 74 | break; |
michael@0 | 75 | } |
michael@0 | 76 | case CRASH_MOZ_CRASH: { |
michael@0 | 77 | MOZ_CRASH(); |
michael@0 | 78 | break; |
michael@0 | 79 | } |
michael@0 | 80 | case CRASH_ABORT: { |
michael@0 | 81 | abort(); |
michael@0 | 82 | break; |
michael@0 | 83 | } |
michael@0 | 84 | default: |
michael@0 | 85 | break; |
michael@0 | 86 | } |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | extern "C" NS_EXPORT |
michael@0 | 90 | nsISupports* LockDir(nsIFile *directory) |
michael@0 | 91 | { |
michael@0 | 92 | nsISupports* lockfile = nullptr; |
michael@0 | 93 | XRE_LockProfileDirectory(directory, &lockfile); |
michael@0 | 94 | return lockfile; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | char testData[32]; |
michael@0 | 98 | |
michael@0 | 99 | extern "C" NS_EXPORT |
michael@0 | 100 | uint64_t SaveAppMemory() |
michael@0 | 101 | { |
michael@0 | 102 | for (size_t i=0; i<sizeof(testData); i++) |
michael@0 | 103 | testData[i] = i; |
michael@0 | 104 | |
michael@0 | 105 | FILE *fp = fopen("crash-addr", "w"); |
michael@0 | 106 | if (!fp) |
michael@0 | 107 | return 0; |
michael@0 | 108 | fprintf(fp, "%p\n", (void *)testData); |
michael@0 | 109 | fclose(fp); |
michael@0 | 110 | |
michael@0 | 111 | return (int64_t)testData; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | #ifdef XP_WIN32 |
michael@0 | 115 | static LONG WINAPI HandleException(EXCEPTION_POINTERS* exinfo) |
michael@0 | 116 | { |
michael@0 | 117 | TerminateProcess(GetCurrentProcess(), 0); |
michael@0 | 118 | return 0; |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | extern "C" NS_EXPORT |
michael@0 | 122 | void TryOverrideExceptionHandler() |
michael@0 | 123 | { |
michael@0 | 124 | SetUnhandledExceptionFilter(HandleException); |
michael@0 | 125 | } |
michael@0 | 126 | #endif |