Chromium Code Reviews| Index: handler/win/crashy_test_program.cc |
| diff --git a/handler/win/crashy_test_program.cc b/handler/win/crashy_test_program.cc |
| index 4355ae00f981b2df0f77cb087dc9f70d1919025c..963fca836fea4ae78858935b157fa0e708fe1b08 100644 |
| --- a/handler/win/crashy_test_program.cc |
| +++ b/handler/win/crashy_test_program.cc |
| @@ -90,6 +90,39 @@ void AllocateMemoryOfVariousProtections() { |
| } |
| } |
| +DWORD WINAPI NullThreadProc(void* param) { |
| + return 0; |
| +} |
| + |
| +// 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.
|
| +// g_test_memory so we can confirm it's available in the minidump. |
| +bool CreateThreadWithRegisterPointingToTestMemory() { |
| + HANDLE thread = CreateThread( |
| + nullptr, 0, &NullThreadProc, nullptr, CREATE_SUSPENDED, nullptr); |
| + if (!thread) { |
| + PLOG(ERROR) << "CreateThread"; |
| + return false; |
| + } |
| + |
| + CONTEXT context = {0}; |
| + context.ContextFlags = CONTEXT_INTEGER; |
| + if (!GetThreadContext(thread, &context)) { |
| + PLOG(ERROR) << "GetThreadContext"; |
| + return false; |
| + } |
| +#if defined(ARCH_CPU_X86_64) |
| + context.Rdi = reinterpret_cast<DWORD64>(g_test_memory); |
| +#elif defined(ARCH_CPU_X86) |
| + context.Edi = reinterpret_cast<DWORD>(g_test_memory); |
| +#endif |
| + if (!SetThreadContext(thread, &context)) { |
| + PLOG(ERROR) << "SetThreadContext"; |
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| void SomeCrashyFunction() { |
| // SetLastError and NTSTATUS so that we have something to view in !gle in |
| // windbg. RtlNtStatusToDosError() stores STATUS_NO_SUCH_FILE into the |
| @@ -97,11 +130,6 @@ void SomeCrashyFunction() { |
| // ERROR_FILE_NOT_FOUND for GetLastError(). |
| SetLastError(RtlNtStatusToDosError(STATUS_NO_SUCH_FILE)); |
| - // Set a register to point at some memory we can test to confirm it makes it |
| - // into the minidump. We use __movsb as a way to set SI/DI without needing an |
| - // external .asm file. |
| - __movsb(g_test_memory, g_test_memory, 0); |
| - |
| volatile int* foo = reinterpret_cast<volatile int*>(7); |
| *foo = 42; |
| } |
| @@ -142,6 +170,9 @@ int CrashyMain(int argc, wchar_t* argv[]) { |
| EnterCriticalSection(&g_test_critical_section); |
| } |
| + if (!CreateThreadWithRegisterPointingToTestMemory()) |
| + return EXIT_FAILURE; |
| + |
| SomeCrashyFunction(); |
| return EXIT_SUCCESS; |