OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 | |
15 #include <malloc.h> | |
16 #include <windows.h> | |
17 #include <winternl.h> | |
18 | |
19 #include "base/logging.h" | |
20 #include "base/strings/stringprintf.h" | |
21 #include "client/crashpad_client.h" | |
22 #include "snapshot/win/process_reader_win.h" | |
23 #include "tools/tool_support.h" | |
24 | |
25 namespace crashpad { | |
26 namespace { | |
27 | |
28 // We VirtualFree a region in ourselves (the stack) to confirm that the | |
29 // exception reporter captures as much as possible in the minidump and doesn't | |
30 // abort. __debugbreak() immediately after doing so because the process is | |
31 // clearly in a very broken state at this point. | |
32 bool FreeOwnStackAndBreak() { | |
33 ProcessReaderWin process_reader; | |
34 if (!process_reader.Initialize(GetCurrentProcess(), | |
35 ProcessSuspensionState::kRunning)) { | |
Mark Mentovai
2015/10/21 22:49:29
Align
scottmg
2015/10/21 22:58:08
Done.
| |
36 LOG(ERROR) << "ProcessReaderWin Initialize"; | |
37 return false; | |
38 } | |
39 | |
40 const std::vector<ProcessReaderWin::Thread> threads = | |
41 process_reader.Threads(); | |
42 if (threads.empty()) { | |
43 LOG(ERROR) << "no threads"; | |
44 return false; | |
45 } | |
46 | |
47 // Push the stack up a bit so that hopefully the crash handler can succeed, | |
48 // but won't be able to read the base of the stack. | |
49 _alloca(16384); | |
50 | |
51 // We can't succeed at MEM_RELEASEing this memory, but MEM_DECOMMIT is good | |
52 // enough to make it inaccessible. | |
53 if (!VirtualFree(reinterpret_cast<void*>(threads[0].stack_region_address), | |
54 100, | |
55 MEM_DECOMMIT)) { | |
56 PLOG(ERROR) << "VirtualFree"; | |
57 return false; | |
58 } | |
59 | |
60 // If the VirtualFree() succeeds, we may have already crashed. __debugbreak() | |
61 // just to be sure. | |
62 __debugbreak(); | |
63 | |
64 return true; | |
65 } | |
66 | |
67 int SelfDestroyingMain(int argc, char* argv[]) { | |
68 if (argc != 2) { | |
69 fprintf(stderr, "Usage: %s <server_pipe_name>\n", argv[0]); | |
70 return 1; | |
Mark Mentovai
2015/10/21 22:49:29
<stdlib.h> EXIT_FAILURE, EXIT_SUCCESS
scottmg
2015/10/21 22:58:08
Done.
| |
71 } | |
72 | |
73 CrashpadClient client; | |
74 if (!client.SetHandler(argv[1])) { | |
75 LOG(ERROR) << "SetHandler"; | |
76 return 1; | |
77 } | |
78 if (!client.UseHandler()) { | |
79 LOG(ERROR) << "UseHandler"; | |
80 return 1; | |
81 } | |
82 | |
83 if (!FreeOwnStackAndBreak()) | |
84 return 1; | |
85 | |
86 return 0; | |
Mark Mentovai
2015/10/21 22:49:28
Comment that this is not reached.
scottmg
2015/10/21 22:58:08
Done.
| |
87 } | |
88 | |
89 } // namespace | |
90 } // namespace crashpad | |
91 | |
92 int wmain(int argc, wchar_t* argv[]) { | |
93 return crashpad::ToolSupport::Wmain(argc, argv, crashpad::SelfDestroyingMain); | |
94 } | |
OLD | NEW |