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, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include <windows.h> | 15 #include <windows.h> |
16 #include <winternl.h> | 16 #include <winternl.h> |
17 | 17 |
18 // ntstatus.h conflicts with windows.h so define this locally. | 18 // ntstatus.h conflicts with windows.h so define this locally. |
19 #ifndef STATUS_NO_SUCH_FILE | 19 #ifndef STATUS_NO_SUCH_FILE |
20 #define STATUS_NO_SUCH_FILE static_cast<NTSTATUS>(0xC000000F) | 20 #define STATUS_NO_SUCH_FILE static_cast<NTSTATUS>(0xC000000F) |
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 #include "util/win/critical_section_with_debug_info.h" |
27 | 28 |
28 namespace crashpad { | 29 namespace crashpad { |
29 namespace { | 30 namespace { |
30 | 31 |
31 CRITICAL_SECTION g_test_critical_section; | 32 CRITICAL_SECTION g_test_critical_section; |
32 | 33 |
33 ULONG RtlNtStatusToDosError(NTSTATUS status) { | 34 ULONG RtlNtStatusToDosError(NTSTATUS status) { |
34 static decltype(::RtlNtStatusToDosError)* rtl_nt_status_to_dos_error = | 35 static decltype(::RtlNtStatusToDosError)* rtl_nt_status_to_dos_error = |
35 reinterpret_cast<decltype(::RtlNtStatusToDosError)*>( | 36 reinterpret_cast<decltype(::RtlNtStatusToDosError)*>( |
36 GetProcAddress(LoadLibrary(L"ntdll.dll"), "RtlNtStatusToDosError")); | 37 GetProcAddress(LoadLibrary(L"ntdll.dll"), "RtlNtStatusToDosError")); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 for (size_t i = 0; i < arraysize(kPageTypes); ++i) { | 71 for (size_t i = 0; i < arraysize(kPageTypes); ++i) { |
71 void* result = | 72 void* result = |
72 VirtualAlloc(reinterpret_cast<void*>(reserve_as_int + (kPageSize * i)), | 73 VirtualAlloc(reinterpret_cast<void*>(reserve_as_int + (kPageSize * i)), |
73 kPageSize, | 74 kPageSize, |
74 MEM_COMMIT, | 75 MEM_COMMIT, |
75 kPageTypes[i]); | 76 kPageTypes[i]); |
76 PCHECK(result) << "VirtualAlloc MEM_COMMIT " << i; | 77 PCHECK(result) << "VirtualAlloc MEM_COMMIT " << i; |
77 } | 78 } |
78 } | 79 } |
79 | 80 |
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 | |
92 void SomeCrashyFunction() { | 81 void SomeCrashyFunction() { |
93 // SetLastError and NTSTATUS so that we have something to view in !gle in | 82 // SetLastError and NTSTATUS so that we have something to view in !gle in |
94 // windbg. RtlNtStatusToDosError() stores STATUS_NO_SUCH_FILE into the | 83 // windbg. RtlNtStatusToDosError() stores STATUS_NO_SUCH_FILE into the |
95 // LastStatusError of the TEB as a side-effect, and we'll be setting | 84 // LastStatusError of the TEB as a side-effect, and we'll be setting |
96 // ERROR_FILE_NOT_FOUND for GetLastError(). | 85 // ERROR_FILE_NOT_FOUND for GetLastError(). |
97 SetLastError(RtlNtStatusToDosError(STATUS_NO_SUCH_FILE)); | 86 SetLastError(RtlNtStatusToDosError(STATUS_NO_SUCH_FILE)); |
98 volatile int* foo = reinterpret_cast<volatile int*>(7); | 87 volatile int* foo = reinterpret_cast<volatile int*>(7); |
99 *foo = 42; | 88 *foo = 42; |
100 } | 89 } |
101 | 90 |
102 int CrashyMain(int argc, char* argv[]) { | 91 int CrashyMain(int argc, char* argv[]) { |
103 if (argc != 2) { | 92 if (argc != 2) { |
104 fprintf(stderr, "Usage: %s <server_pipe_name>\n", argv[0]); | 93 fprintf(stderr, "Usage: %s <server_pipe_name>\n", argv[0]); |
105 return 1; | 94 return 1; |
106 } | 95 } |
107 | 96 |
108 CrashpadClient client; | 97 CrashpadClient client; |
109 if (!client.SetHandler(argv[1])) { | 98 if (!client.SetHandler(argv[1])) { |
110 LOG(ERROR) << "SetHandler"; | 99 LOG(ERROR) << "SetHandler"; |
111 return 1; | 100 return 1; |
112 } | 101 } |
113 if (!client.UseHandler()) { | 102 if (!client.UseHandler()) { |
114 LOG(ERROR) << "UseHandler"; | 103 LOG(ERROR) << "UseHandler"; |
115 return 1; | 104 return 1; |
116 } | 105 } |
117 | 106 |
118 AllocateMemoryOfVariousProtections(); | 107 AllocateMemoryOfVariousProtections(); |
119 | 108 |
120 CrashpadInitializeCriticalSectionEx( | 109 if (InitializeCriticalSectionWithDebugInfoIfPossible( |
121 &g_test_critical_section, 0, RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO); | 110 &g_test_critical_section)) { |
122 EnterCriticalSection(&g_test_critical_section); | 111 EnterCriticalSection(&g_test_critical_section); |
| 112 } |
123 | 113 |
124 SomeCrashyFunction(); | 114 SomeCrashyFunction(); |
125 | 115 |
126 return 0; | 116 return 0; |
127 } | 117 } |
128 | 118 |
129 } // namespace | 119 } // namespace |
130 } // namespace crashpad | 120 } // namespace crashpad |
131 | 121 |
132 int wmain(int argc, wchar_t* argv[]) { | 122 int wmain(int argc, wchar_t* argv[]) { |
133 return crashpad::ToolSupport::Wmain(argc, argv, crashpad::CrashyMain); | 123 return crashpad::ToolSupport::Wmain(argc, argv, crashpad::CrashyMain); |
134 } | 124 } |
OLD | NEW |