gecko/toolkit/crashreporter/test/nsTestCrasher.cpp
Ehsan Akhgari 8c296bbcd4 Bug 579517 - Part 1: Automated conversion of NSPR numeric types to stdint types in Gecko; r=bsmedberg
This patch was generated by a script.  Here's the source of the script for
future reference:

function convert() {
echo "Converting $1 to $2..."
find . ! -wholename "*nsprpub*" \
       ! -wholename "*security/nss*" \
       ! -wholename "*/.hg*" \
       ! -wholename "obj-ff-dbg*" \
       ! -name nsXPCOMCID.h \
       ! -name prtypes.h \
         -type f \
      \( -iname "*.cpp" \
         -o -iname "*.h" \
         -o -iname "*.c" \
         -o -iname "*.cc" \
         -o -iname "*.idl" \
         -o -iname "*.ipdl" \
         -o -iname "*.ipdlh" \
         -o -iname "*.mm" \) | \
    xargs -n 1 sed -i -e "s/\b$1\b/$2/g"
}

convert PRInt8 int8_t
convert PRUint8 uint8_t
convert PRInt16 int16_t
convert PRUint16 uint16_t
convert PRInt32 int32_t
convert PRUint32 uint32_t
convert PRInt64 int64_t
convert PRUint64 uint64_t

convert PRIntn int
convert PRUintn unsigned

convert PRSize size_t

convert PROffset32 int32_t
convert PROffset64 int64_t

convert PRPtrdiff ptrdiff_t

convert PRFloat64 double
2012-08-22 11:56:38 -04:00

107 lines
1.8 KiB
C++

#include "mozilla/Assertions.h"
#include <stdio.h>
#include "nscore.h"
#include "nsXULAppAPI.h"
#include "nsExceptionHandler.h"
/*
* 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() { }
public:
void use() { }
};
void fcn( A* p )
{
p->f();
}
void PureVirtualCall()
{
// generates a pure virtual function call
B b;
b.use(); // make sure b's actually used
}
// Keep these in sync with CrashTestUtils.jsm!
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;
extern "C" NS_EXPORT
void Crash(int16_t how)
{
switch (how) {
case CRASH_INVALID_POINTER_DEREF: {
volatile int* foo = (int*)0x42;
*foo = 0;
// not reached
break;
}
case CRASH_PURE_VIRTUAL_CALL: {
PureVirtualCall();
// not reached
break;
}
case CRASH_RUNTIMEABORT: {
NS_RUNTIMEABORT("Intentional crash");
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)
{
nsISupports* lockfile = nullptr;
XRE_LockProfileDirectory(directory, &lockfile);
return lockfile;
}
char testData[32];
extern "C" NS_EXPORT
uint64_t SaveAppMemory()
{
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);
return (int64_t)testData;
}