Chromium Code Reviews| 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, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 for (size_t i = 0; i < arraysize(kPageTypes); ++i) { | 83 for (size_t i = 0; i < arraysize(kPageTypes); ++i) { |
| 84 void* result = | 84 void* result = |
| 85 VirtualAlloc(reinterpret_cast<void*>(reserve_as_int + (kPageSize * i)), | 85 VirtualAlloc(reinterpret_cast<void*>(reserve_as_int + (kPageSize * i)), |
| 86 kPageSize, | 86 kPageSize, |
| 87 MEM_COMMIT, | 87 MEM_COMMIT, |
| 88 kPageTypes[i]); | 88 kPageTypes[i]); |
| 89 PCHECK(result) << "VirtualAlloc MEM_COMMIT " << i; | 89 PCHECK(result) << "VirtualAlloc MEM_COMMIT " << i; |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 DWORD WINAPI NullThreadProc(void* param) { | |
| 94 return 0; | |
| 95 } | |
| 96 | |
| 97 // Creates a background thread, suspends it, and sets EDI/RDI to point at | |
|
Mark Mentovai
2016/01/10 04:46:29
Creates a suspended background thread. Otherwise t
scottmg
2016/01/10 21:32:08
Done.
| |
| 98 // g_test_memory so we can confirm it's available in the minidump. | |
| 99 bool CreateThreadWithRegisterPointingToTestMemory() { | |
| 100 HANDLE thread = CreateThread( | |
| 101 nullptr, 0, &NullThreadProc, nullptr, CREATE_SUSPENDED, nullptr); | |
| 102 if (!thread) { | |
| 103 PLOG(ERROR) << "CreateThread"; | |
| 104 return false; | |
| 105 } | |
| 106 | |
| 107 CONTEXT context = {0}; | |
| 108 context.ContextFlags = CONTEXT_INTEGER; | |
| 109 if (!GetThreadContext(thread, &context)) { | |
| 110 PLOG(ERROR) << "GetThreadContext"; | |
| 111 return false; | |
| 112 } | |
| 113 #if defined(ARCH_CPU_X86_64) | |
| 114 context.Rdi = reinterpret_cast<DWORD64>(g_test_memory); | |
| 115 #elif defined(ARCH_CPU_X86) | |
| 116 context.Edi = reinterpret_cast<DWORD>(g_test_memory); | |
| 117 #endif | |
| 118 if (!SetThreadContext(thread, &context)) { | |
| 119 PLOG(ERROR) << "SetThreadContext"; | |
| 120 return false; | |
| 121 } | |
| 122 | |
| 123 return true; | |
| 124 } | |
| 125 | |
| 93 void SomeCrashyFunction() { | 126 void SomeCrashyFunction() { |
| 94 // SetLastError and NTSTATUS so that we have something to view in !gle in | 127 // SetLastError and NTSTATUS so that we have something to view in !gle in |
| 95 // windbg. RtlNtStatusToDosError() stores STATUS_NO_SUCH_FILE into the | 128 // windbg. RtlNtStatusToDosError() stores STATUS_NO_SUCH_FILE into the |
| 96 // LastStatusError of the TEB as a side-effect, and we'll be setting | 129 // LastStatusError of the TEB as a side-effect, and we'll be setting |
| 97 // ERROR_FILE_NOT_FOUND for GetLastError(). | 130 // ERROR_FILE_NOT_FOUND for GetLastError(). |
| 98 SetLastError(RtlNtStatusToDosError(STATUS_NO_SUCH_FILE)); | 131 SetLastError(RtlNtStatusToDosError(STATUS_NO_SUCH_FILE)); |
| 99 | 132 |
| 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); | 133 volatile int* foo = reinterpret_cast<volatile int*>(7); |
| 106 *foo = 42; | 134 *foo = 42; |
| 107 } | 135 } |
| 108 | 136 |
| 109 int CrashyMain(int argc, wchar_t* argv[]) { | 137 int CrashyMain(int argc, wchar_t* argv[]) { |
| 110 CrashpadClient client; | 138 CrashpadClient client; |
| 111 | 139 |
| 112 if (argc == 2) { | 140 if (argc == 2) { |
| 113 if (!client.SetHandlerIPCPipe(argv[1])) { | 141 if (!client.SetHandlerIPCPipe(argv[1])) { |
| 114 LOG(ERROR) << "SetHandler"; | 142 LOG(ERROR) << "SetHandler"; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 135 return EXIT_FAILURE; | 163 return EXIT_FAILURE; |
| 136 } | 164 } |
| 137 | 165 |
| 138 AllocateMemoryOfVariousProtections(); | 166 AllocateMemoryOfVariousProtections(); |
| 139 | 167 |
| 140 if (InitializeCriticalSectionWithDebugInfoIfPossible( | 168 if (InitializeCriticalSectionWithDebugInfoIfPossible( |
| 141 &g_test_critical_section)) { | 169 &g_test_critical_section)) { |
| 142 EnterCriticalSection(&g_test_critical_section); | 170 EnterCriticalSection(&g_test_critical_section); |
| 143 } | 171 } |
| 144 | 172 |
| 173 if (!CreateThreadWithRegisterPointingToTestMemory()) | |
| 174 return EXIT_FAILURE; | |
| 175 | |
| 145 SomeCrashyFunction(); | 176 SomeCrashyFunction(); |
| 146 | 177 |
| 147 return EXIT_SUCCESS; | 178 return EXIT_SUCCESS; |
| 148 } | 179 } |
| 149 | 180 |
| 150 } // namespace | 181 } // namespace |
| 151 } // namespace crashpad | 182 } // namespace crashpad |
| 152 | 183 |
| 153 int wmain(int argc, wchar_t* argv[]) { | 184 int wmain(int argc, wchar_t* argv[]) { |
| 154 return crashpad::CrashyMain(argc, argv); | 185 return crashpad::CrashyMain(argc, argv); |
| 155 } | 186 } |
| OLD | NEW |