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 "util/win/process_info.h" | 15 #include "util/win/process_info.h" |
16 | 16 |
17 #include <imagehlp.h> | |
18 #include <intrin.h> | 17 #include <intrin.h> |
19 #include <wchar.h> | 18 #include <wchar.h> |
20 | 19 |
21 #include "base/files/file_path.h" | 20 #include "base/files/file_path.h" |
22 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
23 #include "build/build_config.h" | 22 #include "build/build_config.h" |
24 #include "gtest/gtest.h" | 23 #include "gtest/gtest.h" |
25 #include "test/paths.h" | 24 #include "test/paths.h" |
26 #include "test/win/child_launcher.h" | 25 #include "test/win/child_launcher.h" |
27 #include "util/file/file_io.h" | 26 #include "util/file/file_io.h" |
28 #include "util/misc/uuid.h" | 27 #include "util/misc/uuid.h" |
29 #include "util/win/scoped_handle.h" | 28 #include "util/win/scoped_handle.h" |
30 | 29 |
31 namespace crashpad { | 30 namespace crashpad { |
32 namespace test { | 31 namespace test { |
33 namespace { | 32 namespace { |
34 | 33 |
35 const wchar_t kNtdllName[] = L"\\ntdll.dll"; | 34 const wchar_t kNtdllName[] = L"\\ntdll.dll"; |
36 | 35 |
37 time_t GetTimestampForModule(HMODULE module) { | |
38 char filename[MAX_PATH]; | |
39 // `char` and GetModuleFileNameA because ImageLoad is ANSI only. | |
40 if (!GetModuleFileNameA(module, filename, arraysize(filename))) | |
41 return 0; | |
42 LOADED_IMAGE* loaded_image = ImageLoad(filename, nullptr); | |
43 return loaded_image->FileHeader->FileHeader.TimeDateStamp; | |
44 } | |
45 | |
46 bool IsProcessWow64(HANDLE process_handle) { | 36 bool IsProcessWow64(HANDLE process_handle) { |
47 static decltype(IsWow64Process)* is_wow64_process = | 37 static decltype(IsWow64Process)* is_wow64_process = |
48 reinterpret_cast<decltype(IsWow64Process)*>( | 38 reinterpret_cast<decltype(IsWow64Process)*>( |
49 GetProcAddress(LoadLibrary(L"kernel32.dll"), "IsWow64Process")); | 39 GetProcAddress(LoadLibrary(L"kernel32.dll"), "IsWow64Process")); |
50 if (!is_wow64_process) | 40 if (!is_wow64_process) |
51 return false; | 41 return false; |
52 BOOL is_wow64; | 42 BOOL is_wow64; |
53 if (!is_wow64_process(process_handle, &is_wow64)) { | 43 if (!is_wow64_process(process_handle, &is_wow64)) { |
54 PLOG(ERROR) << "IsWow64Process"; | 44 PLOG(ERROR) << "IsWow64Process"; |
55 return false; | 45 return false; |
56 } | 46 } |
57 return is_wow64; | 47 return is_wow64; |
58 } | 48 } |
59 | 49 |
60 void VerifyAddressInInCodePage(const ProcessInfo& process_info, | 50 void VerifyAddressInInCodePage(const ProcessInfo& process_info, |
61 WinVMAddress code_address) { | 51 WinVMAddress code_address) { |
62 // Make sure the child code address is an code page address with the right | 52 // Make sure the child code address is an code page address with the right |
63 // information. | 53 // information. |
64 const std::vector<ProcessInfo::MemoryInfo>& memory_info = | 54 const std::vector<MINIDUMP_MEMORY_INFO>& memory_info = |
65 process_info.MemoryInformation(); | 55 process_info.MemoryInfo(); |
66 bool found_region = false; | 56 bool found_region = false; |
67 for (const auto& mi : memory_info) { | 57 for (const auto& mi : memory_info) { |
68 if (mi.base_address <= code_address && | 58 if (mi.BaseAddress <= code_address && |
69 mi.base_address + mi.region_size > code_address) { | 59 mi.BaseAddress + mi.RegionSize > code_address) { |
70 EXPECT_EQ(MEM_COMMIT, mi.state); | 60 EXPECT_EQ(MEM_COMMIT, mi.State); |
71 EXPECT_EQ(PAGE_EXECUTE_READ, mi.protect); | 61 EXPECT_EQ(PAGE_EXECUTE_READ, mi.Protect); |
72 EXPECT_EQ(MEM_IMAGE, mi.type); | 62 EXPECT_EQ(MEM_IMAGE, mi.Type); |
73 EXPECT_FALSE(found_region); | 63 EXPECT_FALSE(found_region); |
74 found_region = true; | 64 found_region = true; |
75 } | 65 } |
76 } | 66 } |
77 EXPECT_TRUE(found_region); | 67 EXPECT_TRUE(found_region); |
78 } | 68 } |
79 | 69 |
80 TEST(ProcessInfo, Self) { | 70 TEST(ProcessInfo, Self) { |
81 ProcessInfo process_info; | 71 ProcessInfo process_info; |
82 ASSERT_TRUE(process_info.Initialize(GetCurrentProcess())); | 72 ASSERT_TRUE(process_info.Initialize(GetCurrentProcess())); |
(...skipping 29 matching lines...) Expand all Loading... |
112 | 102 |
113 EXPECT_EQ(modules[0].dll_base, | 103 EXPECT_EQ(modules[0].dll_base, |
114 reinterpret_cast<uintptr_t>(GetModuleHandle(nullptr))); | 104 reinterpret_cast<uintptr_t>(GetModuleHandle(nullptr))); |
115 EXPECT_EQ(modules[1].dll_base, | 105 EXPECT_EQ(modules[1].dll_base, |
116 reinterpret_cast<uintptr_t>(GetModuleHandle(L"ntdll.dll"))); | 106 reinterpret_cast<uintptr_t>(GetModuleHandle(L"ntdll.dll"))); |
117 | 107 |
118 EXPECT_GT(modules[0].size, 0); | 108 EXPECT_GT(modules[0].size, 0); |
119 EXPECT_GT(modules[1].size, 0); | 109 EXPECT_GT(modules[1].size, 0); |
120 | 110 |
121 EXPECT_EQ(modules[0].timestamp, | 111 EXPECT_EQ(modules[0].timestamp, |
122 GetTimestampForModule(GetModuleHandle(nullptr))); | 112 GetTimestampForLoadedLibrary(GetModuleHandle(nullptr))); |
123 // System modules are forced to particular stamps and the file header values | 113 // System modules are forced to particular stamps and the file header values |
124 // don't match the on-disk times. Just make sure we got some data here. | 114 // don't match the on-disk times. Just make sure we got some data here. |
125 EXPECT_GT(modules[1].timestamp, 0); | 115 EXPECT_GT(modules[1].timestamp, 0); |
126 | 116 |
127 // Find something we know is a code address and confirm expected memory | 117 // Find something we know is a code address and confirm expected memory |
128 // information settings. | 118 // information settings. |
129 VerifyAddressInInCodePage(process_info, | 119 VerifyAddressInInCodePage(process_info, |
130 reinterpret_cast<WinVMAddress>(_ReturnAddress())); | 120 reinterpret_cast<WinVMAddress>(_ReturnAddress())); |
131 } | 121 } |
132 | 122 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 TEST(ProcessInfo, OtherProcessWOW64) { | 184 TEST(ProcessInfo, OtherProcessWOW64) { |
195 #ifndef NDEBUG | 185 #ifndef NDEBUG |
196 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Debug")); | 186 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Debug")); |
197 #else | 187 #else |
198 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Release")); | 188 TestOtherProcess(FILE_PATH_LITERAL("..\\..\\out\\Release")); |
199 #endif | 189 #endif |
200 } | 190 } |
201 #endif // ARCH_CPU_64_BITS | 191 #endif // ARCH_CPU_64_BITS |
202 | 192 |
203 TEST(ProcessInfo, AccessibleRangesNone) { | 193 TEST(ProcessInfo, AccessibleRangesNone) { |
204 std::vector<ProcessInfo::MemoryInfo> memory_info; | 194 std::vector<MINIDUMP_MEMORY_INFO> memory_info; |
205 MEMORY_BASIC_INFORMATION mbi = {0}; | 195 MINIDUMP_MEMORY_INFO mmi = {0}; |
206 | 196 |
207 mbi.BaseAddress = 0; | 197 mmi.BaseAddress = 0; |
208 mbi.RegionSize = 10; | 198 mmi.RegionSize = 10; |
209 mbi.State = MEM_FREE; | 199 mmi.State = MEM_FREE; |
210 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 200 memory_info.push_back(mmi); |
211 | 201 |
212 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = | 202 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
213 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(2, 4), | 203 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(2, 4), |
214 memory_info); | 204 memory_info); |
215 | 205 |
216 EXPECT_TRUE(result.empty()); | 206 EXPECT_TRUE(result.empty()); |
217 } | 207 } |
218 | 208 |
219 TEST(ProcessInfo, AccessibleRangesOneInside) { | 209 TEST(ProcessInfo, AccessibleRangesOneInside) { |
220 std::vector<ProcessInfo::MemoryInfo> memory_info; | 210 std::vector<MINIDUMP_MEMORY_INFO> memory_info; |
221 MEMORY_BASIC_INFORMATION mbi = {0}; | 211 MINIDUMP_MEMORY_INFO mmi = {0}; |
222 | 212 |
223 mbi.BaseAddress = 0; | 213 mmi.BaseAddress = 0; |
224 mbi.RegionSize = 10; | 214 mmi.RegionSize = 10; |
225 mbi.State = MEM_COMMIT; | 215 mmi.State = MEM_COMMIT; |
226 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 216 memory_info.push_back(mmi); |
227 | 217 |
228 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = | 218 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
229 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(2, 4), | 219 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(2, 4), |
230 memory_info); | 220 memory_info); |
231 | 221 |
232 ASSERT_EQ(1u, result.size()); | 222 ASSERT_EQ(1u, result.size()); |
233 EXPECT_EQ(2, result[0].base()); | 223 EXPECT_EQ(2, result[0].base()); |
234 EXPECT_EQ(4, result[0].size()); | 224 EXPECT_EQ(4, result[0].size()); |
235 } | 225 } |
236 | 226 |
237 TEST(ProcessInfo, AccessibleRangesOneTruncatedSize) { | 227 TEST(ProcessInfo, AccessibleRangesOneTruncatedSize) { |
238 std::vector<ProcessInfo::MemoryInfo> memory_info; | 228 std::vector<MINIDUMP_MEMORY_INFO> memory_info; |
239 MEMORY_BASIC_INFORMATION mbi = {0}; | 229 MINIDUMP_MEMORY_INFO mmi = {0}; |
240 | 230 |
241 mbi.BaseAddress = 0; | 231 mmi.BaseAddress = 0; |
242 mbi.RegionSize = 10; | 232 mmi.RegionSize = 10; |
243 mbi.State = MEM_COMMIT; | 233 mmi.State = MEM_COMMIT; |
244 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 234 memory_info.push_back(mmi); |
245 | 235 |
246 mbi.BaseAddress = reinterpret_cast<void*>(10); | 236 mmi.BaseAddress = 10; |
247 mbi.RegionSize = 20; | 237 mmi.RegionSize = 20; |
248 mbi.State = MEM_FREE; | 238 mmi.State = MEM_FREE; |
249 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 239 memory_info.push_back(mmi); |
250 | 240 |
251 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = | 241 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
252 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 10), | 242 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 10), |
253 memory_info); | 243 memory_info); |
254 | 244 |
255 ASSERT_EQ(1u, result.size()); | 245 ASSERT_EQ(1u, result.size()); |
256 EXPECT_EQ(5, result[0].base()); | 246 EXPECT_EQ(5, result[0].base()); |
257 EXPECT_EQ(5, result[0].size()); | 247 EXPECT_EQ(5, result[0].size()); |
258 } | 248 } |
259 | 249 |
260 TEST(ProcessInfo, AccessibleRangesOneMovedStart) { | 250 TEST(ProcessInfo, AccessibleRangesOneMovedStart) { |
261 std::vector<ProcessInfo::MemoryInfo> memory_info; | 251 std::vector<MINIDUMP_MEMORY_INFO> memory_info; |
262 MEMORY_BASIC_INFORMATION mbi = {0}; | 252 MINIDUMP_MEMORY_INFO mmi = {0}; |
263 | 253 |
264 mbi.BaseAddress = 0; | 254 mmi.BaseAddress = 0; |
265 mbi.RegionSize = 10; | 255 mmi.RegionSize = 10; |
266 mbi.State = MEM_FREE; | 256 mmi.State = MEM_FREE; |
267 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 257 memory_info.push_back(mmi); |
268 | 258 |
269 mbi.BaseAddress = reinterpret_cast<void*>(10); | 259 mmi.BaseAddress = 10; |
270 mbi.RegionSize = 20; | 260 mmi.RegionSize = 20; |
271 mbi.State = MEM_COMMIT; | 261 mmi.State = MEM_COMMIT; |
272 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 262 memory_info.push_back(mmi); |
273 | 263 |
274 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = | 264 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
275 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 10), | 265 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 10), |
276 memory_info); | 266 memory_info); |
277 | 267 |
278 ASSERT_EQ(1u, result.size()); | 268 ASSERT_EQ(1u, result.size()); |
279 EXPECT_EQ(10, result[0].base()); | 269 EXPECT_EQ(10, result[0].base()); |
280 EXPECT_EQ(5, result[0].size()); | 270 EXPECT_EQ(5, result[0].size()); |
281 } | 271 } |
282 | 272 |
283 TEST(ProcessInfo, ReserveIsInaccessible) { | 273 TEST(ProcessInfo, ReserveIsInaccessible) { |
284 std::vector<ProcessInfo::MemoryInfo> memory_info; | 274 std::vector<MINIDUMP_MEMORY_INFO> memory_info; |
285 MEMORY_BASIC_INFORMATION mbi = {0}; | 275 MINIDUMP_MEMORY_INFO mmi = {0}; |
286 | 276 |
287 mbi.BaseAddress = 0; | 277 mmi.BaseAddress = 0; |
288 mbi.RegionSize = 10; | 278 mmi.RegionSize = 10; |
289 mbi.State = MEM_RESERVE; | 279 mmi.State = MEM_RESERVE; |
290 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 280 memory_info.push_back(mmi); |
291 | 281 |
292 mbi.BaseAddress = reinterpret_cast<void*>(10); | 282 mmi.BaseAddress = 10; |
293 mbi.RegionSize = 20; | 283 mmi.RegionSize = 20; |
294 mbi.State = MEM_COMMIT; | 284 mmi.State = MEM_COMMIT; |
295 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 285 memory_info.push_back(mmi); |
296 | 286 |
297 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = | 287 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
298 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 10), | 288 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 10), |
299 memory_info); | 289 memory_info); |
300 | 290 |
301 ASSERT_EQ(1u, result.size()); | 291 ASSERT_EQ(1u, result.size()); |
302 EXPECT_EQ(10, result[0].base()); | 292 EXPECT_EQ(10, result[0].base()); |
303 EXPECT_EQ(5, result[0].size()); | 293 EXPECT_EQ(5, result[0].size()); |
304 } | 294 } |
305 | 295 |
306 TEST(ProcessInfo, PageGuardIsInaccessible) { | 296 TEST(ProcessInfo, PageGuardIsInaccessible) { |
307 std::vector<ProcessInfo::MemoryInfo> memory_info; | 297 std::vector<MINIDUMP_MEMORY_INFO> memory_info; |
308 MEMORY_BASIC_INFORMATION mbi = {0}; | 298 MINIDUMP_MEMORY_INFO mmi = {0}; |
309 | 299 |
310 mbi.BaseAddress = 0; | 300 mmi.BaseAddress = 0; |
311 mbi.RegionSize = 10; | 301 mmi.RegionSize = 10; |
312 mbi.State = MEM_COMMIT; | 302 mmi.State = MEM_COMMIT; |
313 mbi.Protect = PAGE_GUARD; | 303 mmi.Protect = PAGE_GUARD; |
314 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 304 memory_info.push_back(mmi); |
315 | 305 |
316 mbi.BaseAddress = reinterpret_cast<void*>(10); | 306 mmi.BaseAddress = 10; |
317 mbi.RegionSize = 20; | 307 mmi.RegionSize = 20; |
318 mbi.State = MEM_COMMIT; | 308 mmi.State = MEM_COMMIT; |
319 mbi.Protect = 0; | 309 mmi.Protect = 0; |
320 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 310 memory_info.push_back(mmi); |
321 | 311 |
322 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = | 312 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
323 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 10), | 313 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 10), |
324 memory_info); | 314 memory_info); |
325 | 315 |
326 ASSERT_EQ(1u, result.size()); | 316 ASSERT_EQ(1u, result.size()); |
327 EXPECT_EQ(10, result[0].base()); | 317 EXPECT_EQ(10, result[0].base()); |
328 EXPECT_EQ(5, result[0].size()); | 318 EXPECT_EQ(5, result[0].size()); |
329 } | 319 } |
330 | 320 |
331 TEST(ProcessInfo, PageNoAccessIsInaccessible) { | 321 TEST(ProcessInfo, PageNoAccessIsInaccessible) { |
332 std::vector<ProcessInfo::MemoryInfo> memory_info; | 322 std::vector<MINIDUMP_MEMORY_INFO> memory_info; |
333 MEMORY_BASIC_INFORMATION mbi = {0}; | 323 MINIDUMP_MEMORY_INFO mmi = {0}; |
334 | 324 |
335 mbi.BaseAddress = 0; | 325 mmi.BaseAddress = 0; |
336 mbi.RegionSize = 10; | 326 mmi.RegionSize = 10; |
337 mbi.State = MEM_COMMIT; | 327 mmi.State = MEM_COMMIT; |
338 mbi.Protect = PAGE_NOACCESS; | 328 mmi.Protect = PAGE_NOACCESS; |
339 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 329 memory_info.push_back(mmi); |
340 | 330 |
341 mbi.BaseAddress = reinterpret_cast<void*>(10); | 331 mmi.BaseAddress = 10; |
342 mbi.RegionSize = 20; | 332 mmi.RegionSize = 20; |
343 mbi.State = MEM_COMMIT; | 333 mmi.State = MEM_COMMIT; |
344 mbi.Protect = 0; | 334 mmi.Protect = 0; |
345 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 335 memory_info.push_back(mmi); |
346 | 336 |
347 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = | 337 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
348 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 10), | 338 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 10), |
349 memory_info); | 339 memory_info); |
350 | 340 |
351 ASSERT_EQ(1u, result.size()); | 341 ASSERT_EQ(1u, result.size()); |
352 EXPECT_EQ(10, result[0].base()); | 342 EXPECT_EQ(10, result[0].base()); |
353 EXPECT_EQ(5, result[0].size()); | 343 EXPECT_EQ(5, result[0].size()); |
354 } | 344 } |
355 | 345 |
356 TEST(ProcessInfo, AccessibleRangesCoalesced) { | 346 TEST(ProcessInfo, AccessibleRangesCoalesced) { |
357 std::vector<ProcessInfo::MemoryInfo> memory_info; | 347 std::vector<MINIDUMP_MEMORY_INFO> memory_info; |
358 MEMORY_BASIC_INFORMATION mbi = {0}; | 348 MINIDUMP_MEMORY_INFO mmi = {0}; |
359 | 349 |
360 mbi.BaseAddress = 0; | 350 mmi.BaseAddress = 0; |
361 mbi.RegionSize = 10; | 351 mmi.RegionSize = 10; |
362 mbi.State = MEM_FREE; | 352 mmi.State = MEM_FREE; |
363 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 353 memory_info.push_back(mmi); |
364 | 354 |
365 mbi.BaseAddress = reinterpret_cast<void*>(10); | 355 mmi.BaseAddress = 10; |
366 mbi.RegionSize = 2; | 356 mmi.RegionSize = 2; |
367 mbi.State = MEM_COMMIT; | 357 mmi.State = MEM_COMMIT; |
368 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 358 memory_info.push_back(mmi); |
369 | 359 |
370 mbi.BaseAddress = reinterpret_cast<void*>(12); | 360 mmi.BaseAddress = 12; |
371 mbi.RegionSize = 5; | 361 mmi.RegionSize = 5; |
372 mbi.State = MEM_COMMIT; | 362 mmi.State = MEM_COMMIT; |
373 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 363 memory_info.push_back(mmi); |
374 | 364 |
375 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = | 365 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
376 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(11, 4), | 366 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(11, 4), |
377 memory_info); | 367 memory_info); |
378 | 368 |
379 ASSERT_EQ(1u, result.size()); | 369 ASSERT_EQ(1u, result.size()); |
380 EXPECT_EQ(11, result[0].base()); | 370 EXPECT_EQ(11, result[0].base()); |
381 EXPECT_EQ(4, result[0].size()); | 371 EXPECT_EQ(4, result[0].size()); |
382 } | 372 } |
383 | 373 |
384 TEST(ProcessInfo, AccessibleRangesMiddleUnavailable) { | 374 TEST(ProcessInfo, AccessibleRangesMiddleUnavailable) { |
385 std::vector<ProcessInfo::MemoryInfo> memory_info; | 375 std::vector<MINIDUMP_MEMORY_INFO> memory_info; |
386 MEMORY_BASIC_INFORMATION mbi = {0}; | 376 MINIDUMP_MEMORY_INFO mmi = {0}; |
387 | 377 |
388 mbi.BaseAddress = 0; | 378 mmi.BaseAddress = 0; |
389 mbi.RegionSize = 10; | 379 mmi.RegionSize = 10; |
390 mbi.State = MEM_COMMIT; | 380 mmi.State = MEM_COMMIT; |
391 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 381 memory_info.push_back(mmi); |
392 | 382 |
393 mbi.BaseAddress = reinterpret_cast<void*>(10); | 383 mmi.BaseAddress = 10; |
394 mbi.RegionSize = 5; | 384 mmi.RegionSize = 5; |
395 mbi.State = MEM_FREE; | 385 mmi.State = MEM_FREE; |
396 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 386 memory_info.push_back(mmi); |
397 | 387 |
398 mbi.BaseAddress = reinterpret_cast<void*>(15); | 388 mmi.BaseAddress = 15; |
399 mbi.RegionSize = 100; | 389 mmi.RegionSize = 100; |
400 mbi.State = MEM_COMMIT; | 390 mmi.State = MEM_COMMIT; |
401 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 391 memory_info.push_back(mmi); |
402 | 392 |
403 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = | 393 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
404 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 45), | 394 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 45), |
405 memory_info); | 395 memory_info); |
406 | 396 |
407 ASSERT_EQ(2u, result.size()); | 397 ASSERT_EQ(2u, result.size()); |
408 EXPECT_EQ(5, result[0].base()); | 398 EXPECT_EQ(5, result[0].base()); |
409 EXPECT_EQ(5, result[0].size()); | 399 EXPECT_EQ(5, result[0].size()); |
410 EXPECT_EQ(15, result[1].base()); | 400 EXPECT_EQ(15, result[1].base()); |
411 EXPECT_EQ(35, result[1].size()); | 401 EXPECT_EQ(35, result[1].size()); |
412 } | 402 } |
413 | 403 |
414 TEST(ProcessInfo, RequestedBeforeMap) { | 404 TEST(ProcessInfo, RequestedBeforeMap) { |
415 std::vector<ProcessInfo::MemoryInfo> memory_info; | 405 std::vector<MINIDUMP_MEMORY_INFO> memory_info; |
416 MEMORY_BASIC_INFORMATION mbi = {0}; | 406 MINIDUMP_MEMORY_INFO mmi = {0}; |
417 | 407 |
418 mbi.BaseAddress = reinterpret_cast<void*>(10); | 408 mmi.BaseAddress = 10; |
419 mbi.RegionSize = 10; | 409 mmi.RegionSize = 10; |
420 mbi.State = MEM_COMMIT; | 410 mmi.State = MEM_COMMIT; |
421 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 411 memory_info.push_back(mmi); |
422 | 412 |
423 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = | 413 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
424 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 10), | 414 GetReadableRangesOfMemoryMap(CheckedRange<WinVMAddress, WinVMSize>(5, 10), |
425 memory_info); | 415 memory_info); |
426 | 416 |
427 ASSERT_EQ(1u, result.size()); | 417 ASSERT_EQ(1u, result.size()); |
428 EXPECT_EQ(10, result[0].base()); | 418 EXPECT_EQ(10, result[0].base()); |
429 EXPECT_EQ(5, result[0].size()); | 419 EXPECT_EQ(5, result[0].size()); |
430 } | 420 } |
431 | 421 |
432 TEST(ProcessInfo, RequestedAfterMap) { | 422 TEST(ProcessInfo, RequestedAfterMap) { |
433 std::vector<ProcessInfo::MemoryInfo> memory_info; | 423 std::vector<MINIDUMP_MEMORY_INFO> memory_info; |
434 MEMORY_BASIC_INFORMATION mbi = {0}; | 424 MINIDUMP_MEMORY_INFO mmi = {0}; |
435 | 425 |
436 mbi.BaseAddress = reinterpret_cast<void*>(10); | 426 mmi.BaseAddress = 10; |
437 mbi.RegionSize = 10; | 427 mmi.RegionSize = 10; |
438 mbi.State = MEM_COMMIT; | 428 mmi.State = MEM_COMMIT; |
439 memory_info.push_back(ProcessInfo::MemoryInfo(mbi)); | 429 memory_info.push_back(mmi); |
440 | 430 |
441 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = | 431 std::vector<CheckedRange<WinVMAddress, WinVMSize>> result = |
442 GetReadableRangesOfMemoryMap( | 432 GetReadableRangesOfMemoryMap( |
443 CheckedRange<WinVMAddress, WinVMSize>(15, 100), memory_info); | 433 CheckedRange<WinVMAddress, WinVMSize>(15, 100), memory_info); |
444 | 434 |
445 ASSERT_EQ(1u, result.size()); | 435 ASSERT_EQ(1u, result.size()); |
446 EXPECT_EQ(15, result[0].base()); | 436 EXPECT_EQ(15, result[0].base()); |
447 EXPECT_EQ(5, result[0].size()); | 437 EXPECT_EQ(5, result[0].size()); |
448 } | 438 } |
449 | 439 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 EXPECT_FALSE(ReadProcessMemory(current_process, | 505 EXPECT_FALSE(ReadProcessMemory(current_process, |
516 reserve_region, | 506 reserve_region, |
517 into.get(), | 507 into.get(), |
518 kBlockSize * 6, | 508 kBlockSize * 6, |
519 &bytes_read)); | 509 &bytes_read)); |
520 } | 510 } |
521 | 511 |
522 } // namespace | 512 } // namespace |
523 } // namespace test | 513 } // namespace test |
524 } // namespace crashpad | 514 } // namespace crashpad |
OLD | NEW |