| 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 10 matching lines...) Expand all Loading... |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 #include "base/basictypes.h" | 23 #include "base/basictypes.h" |
| 24 #include "base/logging.h" | 24 #include "base/logging.h" |
| 25 #include "client/crashpad_client.h" | 25 #include "client/crashpad_client.h" |
| 26 #include "tools/tool_support.h" | 26 #include "tools/tool_support.h" |
| 27 | 27 |
| 28 namespace crashpad { | 28 namespace crashpad { |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 CRITICAL_SECTION g_test_critical_section; |
| 32 |
| 31 ULONG RtlNtStatusToDosError(NTSTATUS status) { | 33 ULONG RtlNtStatusToDosError(NTSTATUS status) { |
| 32 static decltype(::RtlNtStatusToDosError)* rtl_nt_status_to_dos_error = | 34 static decltype(::RtlNtStatusToDosError)* rtl_nt_status_to_dos_error = |
| 33 reinterpret_cast<decltype(::RtlNtStatusToDosError)*>( | 35 reinterpret_cast<decltype(::RtlNtStatusToDosError)*>( |
| 34 GetProcAddress(LoadLibrary(L"ntdll.dll"), "RtlNtStatusToDosError")); | 36 GetProcAddress(LoadLibrary(L"ntdll.dll"), "RtlNtStatusToDosError")); |
| 35 DCHECK(rtl_nt_status_to_dos_error); | 37 DCHECK(rtl_nt_status_to_dos_error); |
| 36 return rtl_nt_status_to_dos_error(status); | 38 return rtl_nt_status_to_dos_error(status); |
| 37 } | 39 } |
| 38 | 40 |
| 39 void AllocateMemoryOfVariousProtections() { | 41 void AllocateMemoryOfVariousProtections() { |
| 40 SYSTEM_INFO system_info; | 42 SYSTEM_INFO system_info; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 68 for (size_t i = 0; i < arraysize(kPageTypes); ++i) { | 70 for (size_t i = 0; i < arraysize(kPageTypes); ++i) { |
| 69 void* result = | 71 void* result = |
| 70 VirtualAlloc(reinterpret_cast<void*>(reserve_as_int + (kPageSize * i)), | 72 VirtualAlloc(reinterpret_cast<void*>(reserve_as_int + (kPageSize * i)), |
| 71 kPageSize, | 73 kPageSize, |
| 72 MEM_COMMIT, | 74 MEM_COMMIT, |
| 73 kPageTypes[i]); | 75 kPageTypes[i]); |
| 74 PCHECK(result) << "VirtualAlloc MEM_COMMIT " << i; | 76 PCHECK(result) << "VirtualAlloc MEM_COMMIT " << i; |
| 75 } | 77 } |
| 76 } | 78 } |
| 77 | 79 |
| 80 BOOL CrashpadInitializeCriticalSectionEx( |
| 81 CRITICAL_SECTION* critical_section, |
| 82 DWORD spin_count, |
| 83 DWORD flags) { |
| 84 static decltype(InitializeCriticalSectionEx)* initialize_critical_section_ex = |
| 85 reinterpret_cast<decltype(InitializeCriticalSectionEx)*>(GetProcAddress( |
| 86 LoadLibrary(L"kernel32.dll"), "InitializeCriticalSectionEx")); |
| 87 if (!initialize_critical_section_ex) |
| 88 return false; |
| 89 return initialize_critical_section_ex(critical_section, spin_count, flags); |
| 90 } |
| 91 |
| 78 void SomeCrashyFunction() { | 92 void SomeCrashyFunction() { |
| 79 // SetLastError and NTSTATUS so that we have something to view in !gle in | 93 // SetLastError and NTSTATUS so that we have something to view in !gle in |
| 80 // windbg. RtlNtStatusToDosError() stores STATUS_NO_SUCH_FILE into the | 94 // windbg. RtlNtStatusToDosError() stores STATUS_NO_SUCH_FILE into the |
| 81 // LastStatusError of the TEB as a side-effect, and we'll be setting | 95 // LastStatusError of the TEB as a side-effect, and we'll be setting |
| 82 // ERROR_FILE_NOT_FOUND for GetLastError(). | 96 // ERROR_FILE_NOT_FOUND for GetLastError(). |
| 83 SetLastError(RtlNtStatusToDosError(STATUS_NO_SUCH_FILE)); | 97 SetLastError(RtlNtStatusToDosError(STATUS_NO_SUCH_FILE)); |
| 84 volatile int* foo = reinterpret_cast<volatile int*>(7); | 98 volatile int* foo = reinterpret_cast<volatile int*>(7); |
| 85 *foo = 42; | 99 *foo = 42; |
| 86 } | 100 } |
| 87 | 101 |
| 88 int CrashyMain(int argc, char* argv[]) { | 102 int CrashyMain(int argc, char* argv[]) { |
| 89 if (argc != 2) { | 103 if (argc != 2) { |
| 90 fprintf(stderr, "Usage: %s <server_pipe_name>\n", argv[0]); | 104 fprintf(stderr, "Usage: %s <server_pipe_name>\n", argv[0]); |
| 91 return 1; | 105 return 1; |
| 92 } | 106 } |
| 93 | 107 |
| 94 CrashpadClient client; | 108 CrashpadClient client; |
| 95 if (!client.SetHandler(argv[1])) { | 109 if (!client.SetHandler(argv[1])) { |
| 96 LOG(ERROR) << "SetHandler"; | 110 LOG(ERROR) << "SetHandler"; |
| 97 return 1; | 111 return 1; |
| 98 } | 112 } |
| 99 if (!client.UseHandler()) { | 113 if (!client.UseHandler()) { |
| 100 LOG(ERROR) << "UseHandler"; | 114 LOG(ERROR) << "UseHandler"; |
| 101 return 1; | 115 return 1; |
| 102 } | 116 } |
| 103 | 117 |
| 104 AllocateMemoryOfVariousProtections(); | 118 AllocateMemoryOfVariousProtections(); |
| 105 | 119 |
| 120 CrashpadInitializeCriticalSectionEx( |
| 121 &g_test_critical_section, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO); |
| 122 EnterCriticalSection(&g_test_critical_section); |
| 123 |
| 106 SomeCrashyFunction(); | 124 SomeCrashyFunction(); |
| 107 | 125 |
| 108 return 0; | 126 return 0; |
| 109 } | 127 } |
| 110 | 128 |
| 111 } // namespace | 129 } // namespace |
| 112 } // namespace crashpad | 130 } // namespace crashpad |
| 113 | 131 |
| 114 int wmain(int argc, wchar_t* argv[]) { | 132 int wmain(int argc, wchar_t* argv[]) { |
| 115 return crashpad::ToolSupport::Wmain(argc, argv, crashpad::CrashyMain); | 133 return crashpad::ToolSupport::Wmain(argc, argv, crashpad::CrashyMain); |
| 116 } | 134 } |
| OLD | NEW |