1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/build/win32/crashinjectdll/crashinjectdll.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,38 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include <stdio.h> 1.9 +#include <windows.h> 1.10 + 1.11 +// make sure we only ever spawn one thread 1.12 +DWORD tid = -1; 1.13 + 1.14 +DWORD WINAPI CrashingThread( 1.15 + LPVOID lpParameter 1.16 +) 1.17 +{ 1.18 + // not a very friendly DLL 1.19 + volatile int* x = (int *)0x0; 1.20 + *x = 1; 1.21 + return 0; 1.22 +} 1.23 + 1.24 +BOOL WINAPI DllMain( 1.25 + HANDLE hinstDLL, 1.26 + DWORD dwReason, 1.27 + LPVOID lpvReserved 1.28 +) 1.29 +{ 1.30 + if (tid == -1) 1.31 + // we have to crash on another thread because LoadLibrary() will 1.32 + // catch memory access errors and return failure to the calling process 1.33 + CreateThread( 1.34 + nullptr, // default security attributes 1.35 + 0, // use default stack size 1.36 + CrashingThread, // thread function name 1.37 + nullptr, // argument to thread function 1.38 + 0, // use default creation flags 1.39 + &tid); // returns the thread identifier 1.40 + return TRUE; 1.41 +}