| Index: third_party/crashpad/crashpad/handler/win/crashy_test_program.cc
|
| diff --git a/third_party/crashpad/crashpad/handler/win/crashy_test_program.cc b/third_party/crashpad/crashpad/handler/win/crashy_test_program.cc
|
| index be03d4cd289df1fe4c698fd09a7eeae0f084e773..6fbd514d74ca1313102ec975d74d18ce27f0b3fa 100644
|
| --- a/third_party/crashpad/crashpad/handler/win/crashy_test_program.cc
|
| +++ b/third_party/crashpad/crashpad/handler/win/crashy_test_program.cc
|
| @@ -12,6 +12,7 @@
|
| // See the License for the specific language governing permissions and
|
| // limitations under the License.
|
|
|
| +#include <intrin.h>
|
| #include <stdint.h>
|
| #include <stdlib.h>
|
| #include <sys/types.h>
|
| @@ -25,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"
|
| @@ -39,6 +41,11 @@ namespace {
|
|
|
| CRITICAL_SECTION g_test_critical_section;
|
|
|
| +unsigned char g_test_memory[] = {
|
| + 99, 98, 97, 96, 95, 94, 93, 92, 91, 90,
|
| + 89, 88, 87, 86, 85, 84, 83, 82, 81, 80,
|
| +};
|
| +
|
| ULONG RtlNtStatusToDosError(NTSTATUS status) {
|
| static const auto rtl_nt_status_to_dos_error =
|
| GET_FUNCTION_REQUIRED(L"ntdll.dll", ::RtlNtStatusToDosError);
|
| @@ -84,12 +91,46 @@ 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
|
| // LastStatusError of the TEB as a side-effect, and we'll be setting
|
| // ERROR_FILE_NOT_FOUND for GetLastError().
|
| SetLastError(RtlNtStatusToDosError(STATUS_NO_SUCH_FILE));
|
| +
|
| volatile int* foo = reinterpret_cast<volatile int*>(7);
|
| *foo = 42;
|
| }
|
| @@ -130,6 +171,9 @@ int CrashyMain(int argc, wchar_t* argv[]) {
|
| EnterCriticalSection(&g_test_critical_section);
|
| }
|
|
|
| + if (!CreateThreadWithRegisterPointingToTestMemory())
|
| + return EXIT_FAILURE;
|
| +
|
| SomeCrashyFunction();
|
|
|
| return EXIT_SUCCESS;
|
|
|