Debian Codegraph @

build/win32/crashinjectdll/crashinjectdll.cpp

raw
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 #include <stdio.h>
6 #include <windows.h>
7
8 // make sure we only ever spawn one thread
9 DWORD tid = -1;
10
11 DWORD WINAPI CrashingThread(LPVOID lpParameter) {
12 // not a very friendly DLL
13 volatile int* x = (int*)0x0;
14 *x = 1;
15 return 0;
16 }
17
18 BOOL WINAPI DllMain(HANDLE hinstDLL, DWORD dwReason, LPVOID lpvReserved) {
19 if (tid == (DWORD)-1)
20 // we have to crash on another thread because LoadLibrary() will
21 // catch memory access errors and return failure to the calling process
22 CreateThread(nullptr, // default security attributes
23 0, // use default stack size
24 CrashingThread, // thread function name
25 nullptr, // argument to thread function
26 0, // use default creation flags
27 &tid); // returns the thread identifier
28 return TRUE;
29 }