Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(800)

Unified Diff: handler/win/crashy_test_program.cc

Issue 1563273004: win: Better setting of DI for register capture test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: fix comment Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | snapshot/win/end_to_end_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..6fbd514d74ca1313102ec975d74d18ce27f0b3fa 100644
--- a/handler/win/crashy_test_program.cc
+++ b/handler/win/crashy_test_program.cc
@@ -26,6 +26,7 @@
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/macros.h"
+#include "build/build_config.h"
#include "client/crashpad_client.h"
#include "util/win/critical_section_with_debug_info.h"
#include "util/win/get_function.h"
@@ -90,6 +91,39 @@ void AllocateMemoryOfVariousProtections() {
}
}
+DWORD WINAPI NullThreadProc(void* param) {
+ return 0;
+}
+
+// Creates a suspended background thread, and sets EDI/RDI to point at
+// 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 +131,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 +171,9 @@ int CrashyMain(int argc, wchar_t* argv[]) {
EnterCriticalSection(&g_test_critical_section);
}
+ if (!CreateThreadWithRegisterPointingToTestMemory())
+ return EXIT_FAILURE;
+
SomeCrashyFunction();
return EXIT_SUCCESS;
« no previous file with comments | « no previous file | snapshot/win/end_to_end_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698