OLD | NEW |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include <intrin.h> | 15 #include <intrin.h> |
16 #include <stdint.h> | 16 #include <stdint.h> |
17 #include <stdlib.h> | 17 #include <stdlib.h> |
18 #include <sys/types.h> | 18 #include <sys/types.h> |
19 #include <windows.h> | 19 #include <windows.h> |
20 #include <winternl.h> | 20 #include <winternl.h> |
21 | 21 |
22 #include <map> | 22 #include <map> |
23 #include <string> | 23 #include <string> |
24 #include <vector> | 24 #include <vector> |
25 | 25 |
26 #include "base/files/file_path.h" | 26 #include "base/files/file_path.h" |
27 #include "base/logging.h" | 27 #include "base/logging.h" |
28 #include "base/macros.h" | 28 #include "base/macros.h" |
| 29 #include "build/build_config.h" |
29 #include "client/crashpad_client.h" | 30 #include "client/crashpad_client.h" |
30 #include "util/win/critical_section_with_debug_info.h" | 31 #include "util/win/critical_section_with_debug_info.h" |
31 #include "util/win/get_function.h" | 32 #include "util/win/get_function.h" |
32 | 33 |
33 // ntstatus.h conflicts with windows.h so define this locally. | 34 // ntstatus.h conflicts with windows.h so define this locally. |
34 #ifndef STATUS_NO_SUCH_FILE | 35 #ifndef STATUS_NO_SUCH_FILE |
35 #define STATUS_NO_SUCH_FILE static_cast<NTSTATUS>(0xC000000F) | 36 #define STATUS_NO_SUCH_FILE static_cast<NTSTATUS>(0xC000000F) |
36 #endif | 37 #endif |
37 | 38 |
38 namespace crashpad { | 39 namespace crashpad { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 for (size_t i = 0; i < arraysize(kPageTypes); ++i) { | 84 for (size_t i = 0; i < arraysize(kPageTypes); ++i) { |
84 void* result = | 85 void* result = |
85 VirtualAlloc(reinterpret_cast<void*>(reserve_as_int + (kPageSize * i)), | 86 VirtualAlloc(reinterpret_cast<void*>(reserve_as_int + (kPageSize * i)), |
86 kPageSize, | 87 kPageSize, |
87 MEM_COMMIT, | 88 MEM_COMMIT, |
88 kPageTypes[i]); | 89 kPageTypes[i]); |
89 PCHECK(result) << "VirtualAlloc MEM_COMMIT " << i; | 90 PCHECK(result) << "VirtualAlloc MEM_COMMIT " << i; |
90 } | 91 } |
91 } | 92 } |
92 | 93 |
| 94 DWORD WINAPI NullThreadProc(void* param) { |
| 95 return 0; |
| 96 } |
| 97 |
| 98 // Creates a suspended background thread, and sets EDI/RDI to point at |
| 99 // g_test_memory so we can confirm it's available in the minidump. |
| 100 bool CreateThreadWithRegisterPointingToTestMemory() { |
| 101 HANDLE thread = CreateThread( |
| 102 nullptr, 0, &NullThreadProc, nullptr, CREATE_SUSPENDED, nullptr); |
| 103 if (!thread) { |
| 104 PLOG(ERROR) << "CreateThread"; |
| 105 return false; |
| 106 } |
| 107 |
| 108 CONTEXT context = {0}; |
| 109 context.ContextFlags = CONTEXT_INTEGER; |
| 110 if (!GetThreadContext(thread, &context)) { |
| 111 PLOG(ERROR) << "GetThreadContext"; |
| 112 return false; |
| 113 } |
| 114 #if defined(ARCH_CPU_X86_64) |
| 115 context.Rdi = reinterpret_cast<DWORD64>(g_test_memory); |
| 116 #elif defined(ARCH_CPU_X86) |
| 117 context.Edi = reinterpret_cast<DWORD>(g_test_memory); |
| 118 #endif |
| 119 if (!SetThreadContext(thread, &context)) { |
| 120 PLOG(ERROR) << "SetThreadContext"; |
| 121 return false; |
| 122 } |
| 123 |
| 124 return true; |
| 125 } |
| 126 |
93 void SomeCrashyFunction() { | 127 void SomeCrashyFunction() { |
94 // SetLastError and NTSTATUS so that we have something to view in !gle in | 128 // SetLastError and NTSTATUS so that we have something to view in !gle in |
95 // windbg. RtlNtStatusToDosError() stores STATUS_NO_SUCH_FILE into the | 129 // windbg. RtlNtStatusToDosError() stores STATUS_NO_SUCH_FILE into the |
96 // LastStatusError of the TEB as a side-effect, and we'll be setting | 130 // LastStatusError of the TEB as a side-effect, and we'll be setting |
97 // ERROR_FILE_NOT_FOUND for GetLastError(). | 131 // ERROR_FILE_NOT_FOUND for GetLastError(). |
98 SetLastError(RtlNtStatusToDosError(STATUS_NO_SUCH_FILE)); | 132 SetLastError(RtlNtStatusToDosError(STATUS_NO_SUCH_FILE)); |
99 | 133 |
100 // Set a register to point at some memory we can test to confirm it makes it | |
101 // into the minidump. We use __movsb as a way to set SI/DI without needing an | |
102 // external .asm file. | |
103 __movsb(g_test_memory, g_test_memory, 0); | |
104 | |
105 volatile int* foo = reinterpret_cast<volatile int*>(7); | 134 volatile int* foo = reinterpret_cast<volatile int*>(7); |
106 *foo = 42; | 135 *foo = 42; |
107 } | 136 } |
108 | 137 |
109 int CrashyMain(int argc, wchar_t* argv[]) { | 138 int CrashyMain(int argc, wchar_t* argv[]) { |
110 CrashpadClient client; | 139 CrashpadClient client; |
111 | 140 |
112 if (argc == 2) { | 141 if (argc == 2) { |
113 if (!client.SetHandlerIPCPipe(argv[1])) { | 142 if (!client.SetHandlerIPCPipe(argv[1])) { |
114 LOG(ERROR) << "SetHandler"; | 143 LOG(ERROR) << "SetHandler"; |
(...skipping 20 matching lines...) Expand all Loading... |
135 return EXIT_FAILURE; | 164 return EXIT_FAILURE; |
136 } | 165 } |
137 | 166 |
138 AllocateMemoryOfVariousProtections(); | 167 AllocateMemoryOfVariousProtections(); |
139 | 168 |
140 if (InitializeCriticalSectionWithDebugInfoIfPossible( | 169 if (InitializeCriticalSectionWithDebugInfoIfPossible( |
141 &g_test_critical_section)) { | 170 &g_test_critical_section)) { |
142 EnterCriticalSection(&g_test_critical_section); | 171 EnterCriticalSection(&g_test_critical_section); |
143 } | 172 } |
144 | 173 |
| 174 if (!CreateThreadWithRegisterPointingToTestMemory()) |
| 175 return EXIT_FAILURE; |
| 176 |
145 SomeCrashyFunction(); | 177 SomeCrashyFunction(); |
146 | 178 |
147 return EXIT_SUCCESS; | 179 return EXIT_SUCCESS; |
148 } | 180 } |
149 | 181 |
150 } // namespace | 182 } // namespace |
151 } // namespace crashpad | 183 } // namespace crashpad |
152 | 184 |
153 int wmain(int argc, wchar_t* argv[]) { | 185 int wmain(int argc, wchar_t* argv[]) { |
154 return crashpad::CrashyMain(argc, argv); | 186 return crashpad::CrashyMain(argc, argv); |
155 } | 187 } |
OLD | NEW |