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

Side by Side Diff: util/win/process_info_test.cc

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

Powered by Google App Engine
This is Rietveld 408576698