MCPcopy Create free account
hub / github.com/chromium/crashpad / FreeOwnStackAndBreak

Function FreeOwnStackAndBreak

handler/win/self_destroying_test_program.cc:37–70  ·  view source on GitHub ↗

We VirtualFree a region in ourselves (the stack) to confirm that the exception reporter captures as much as possible in the minidump and doesn't abort. __debugbreak() immediately after doing so because the process is clearly in a very broken state at this point.

Source from the content-addressed store, hash-verified

35// abort. __debugbreak() immediately after doing so because the process is
36// clearly in a very broken state at this point.
37__declspec(noinline) bool FreeOwnStackAndBreak() {
38 ProcessReaderWin process_reader;
39 if (!process_reader.Initialize(GetCurrentProcess(),
40 ProcessSuspensionState::kRunning)) {
41 LOG(ERROR) << "ProcessReaderWin Initialize";
42 return false;
43 }
44
45 const std::vector<ProcessReaderWin::Thread> threads =
46 process_reader.Threads();
47 if (threads.empty()) {
48 LOG(ERROR) << "no threads";
49 return false;
50 }
51
52 // Push the stack up a bit so that hopefully the crash handler can succeed,
53 // but won't be able to read the base of the stack.
54 [[maybe_unused]] volatile void* do_not_optimize_away = _alloca(16384);
55
56 // We can't succeed at MEM_RELEASEing this memory, but MEM_DECOMMIT is good
57 // enough to make it inaccessible.
58 if (!VirtualFree(reinterpret_cast<void*>(threads[0].stack_region_address),
59 100,
60 MEM_DECOMMIT)) {
61 PLOG(ERROR) << "VirtualFree";
62 return false;
63 }
64
65 // If the VirtualFree() succeeds, we may have already crashed. __debugbreak()
66 // just to be sure.
67 __debugbreak();
68
69 return true;
70}
71
72__declspec(noinline) int SelfDestroyingMain(int argc, wchar_t* argv[]) {
73 if (argc != 2) {

Callers 1

SelfDestroyingMainFunction · 0.85

Calls 3

InitializeMethod · 0.45
ThreadsMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected