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

Side by Side 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: 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 unified diff | Download patch
« no previous file with comments | « no previous file | snapshot/win/end_to_end_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« 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