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

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

Issue 1422503015: win: Add HandleToInt() and IntToHandle() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 1 month 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
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,
(...skipping 15 matching lines...) Expand all
26 #include "build/build_config.h" 26 #include "build/build_config.h"
27 #include "gtest/gtest.h" 27 #include "gtest/gtest.h"
28 #include "test/errors.h" 28 #include "test/errors.h"
29 #include "test/scoped_temp_dir.h" 29 #include "test/scoped_temp_dir.h"
30 #include "test/paths.h" 30 #include "test/paths.h"
31 #include "test/win/child_launcher.h" 31 #include "test/win/child_launcher.h"
32 #include "util/file/file_io.h" 32 #include "util/file/file_io.h"
33 #include "util/misc/uuid.h" 33 #include "util/misc/uuid.h"
34 #include "util/win/command_line.h" 34 #include "util/win/command_line.h"
35 #include "util/win/get_function.h" 35 #include "util/win/get_function.h"
36 #include "util/win/handle.h"
36 #include "util/win/scoped_handle.h" 37 #include "util/win/scoped_handle.h"
37 38
38 namespace crashpad { 39 namespace crashpad {
39 namespace test { 40 namespace test {
40 namespace { 41 namespace {
41 42
42 const wchar_t kNtdllName[] = L"\\ntdll.dll"; 43 const wchar_t kNtdllName[] = L"\\ntdll.dll";
43 44
44 bool IsProcessWow64(HANDLE process_handle) { 45 bool IsProcessWow64(HANDLE process_handle) {
45 static const auto is_wow64_process = 46 static const auto is_wow64_process =
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 mapping_name.c_str())); 567 mapping_name.c_str()));
567 ASSERT_TRUE(mapping.is_valid()) << ErrorMessage("CreateFileMapping"); 568 ASSERT_TRUE(mapping.is_valid()) << ErrorMessage("CreateFileMapping");
568 569
569 ProcessInfo info; 570 ProcessInfo info;
570 info.Initialize(GetCurrentProcess()); 571 info.Initialize(GetCurrentProcess());
571 bool found_file_handle = false; 572 bool found_file_handle = false;
572 bool found_inherited_file_handle = false; 573 bool found_inherited_file_handle = false;
573 bool found_key_handle = false; 574 bool found_key_handle = false;
574 bool found_mapping_handle = false; 575 bool found_mapping_handle = false;
575 for (auto handle : info.Handles()) { 576 for (auto handle : info.Handles()) {
576 if (reinterpret_cast<uint32_t>(file.get()) == handle.handle) { 577 const int handle_int = implicit_cast<int>(handle.handle);
578 if (handle_int == HandleToInt(file.get())) {
577 EXPECT_FALSE(found_file_handle); 579 EXPECT_FALSE(found_file_handle);
578 found_file_handle = true; 580 found_file_handle = true;
579 EXPECT_EQ(L"File", handle.type_name); 581 EXPECT_EQ(L"File", handle.type_name);
580 EXPECT_EQ(1, handle.handle_count); 582 EXPECT_EQ(1, handle.handle_count);
581 EXPECT_NE(0u, handle.pointer_count); 583 EXPECT_NE(0u, handle.pointer_count);
582 EXPECT_EQ(STANDARD_RIGHTS_READ | STANDARD_RIGHTS_WRITE | SYNCHRONIZE, 584 EXPECT_EQ(STANDARD_RIGHTS_READ | STANDARD_RIGHTS_WRITE | SYNCHRONIZE,
583 handle.granted_access & STANDARD_RIGHTS_ALL); 585 handle.granted_access & STANDARD_RIGHTS_ALL);
584 EXPECT_EQ(0, handle.attributes); 586 EXPECT_EQ(0, handle.attributes);
585 } 587 }
586 if (reinterpret_cast<uint32_t>(inherited_file.get()) == handle.handle) { 588 if (handle_int == HandleToInt(inherited_file.get())) {
587 EXPECT_FALSE(found_inherited_file_handle); 589 EXPECT_FALSE(found_inherited_file_handle);
588 found_inherited_file_handle = true; 590 found_inherited_file_handle = true;
589 EXPECT_EQ(L"File", handle.type_name); 591 EXPECT_EQ(L"File", handle.type_name);
590 EXPECT_EQ(1, handle.handle_count); 592 EXPECT_EQ(1, handle.handle_count);
591 EXPECT_NE(0u, handle.pointer_count); 593 EXPECT_NE(0u, handle.pointer_count);
592 EXPECT_EQ(STANDARD_RIGHTS_READ | STANDARD_RIGHTS_WRITE | SYNCHRONIZE, 594 EXPECT_EQ(STANDARD_RIGHTS_READ | STANDARD_RIGHTS_WRITE | SYNCHRONIZE,
593 handle.granted_access & STANDARD_RIGHTS_ALL); 595 handle.granted_access & STANDARD_RIGHTS_ALL);
594 596
595 // OBJ_INHERIT from ntdef.h, but including that conflicts with other 597 // OBJ_INHERIT from ntdef.h, but including that conflicts with other
596 // headers. 598 // headers.
597 const int kObjInherit = 0x2; 599 const int kObjInherit = 0x2;
598 EXPECT_EQ(kObjInherit, handle.attributes); 600 EXPECT_EQ(kObjInherit, handle.attributes);
599 } 601 }
600 if (reinterpret_cast<uint32_t>(scoped_key.get()) == handle.handle) { 602 if (handle_int == HandleToInt(scoped_key.get())) {
601 EXPECT_FALSE(found_key_handle); 603 EXPECT_FALSE(found_key_handle);
602 found_key_handle = true; 604 found_key_handle = true;
603 EXPECT_EQ(L"Key", handle.type_name); 605 EXPECT_EQ(L"Key", handle.type_name);
604 EXPECT_EQ(1, handle.handle_count); 606 EXPECT_EQ(1, handle.handle_count);
605 EXPECT_NE(0u, handle.pointer_count); 607 EXPECT_NE(0u, handle.pointer_count);
606 EXPECT_EQ(STANDARD_RIGHTS_READ, 608 EXPECT_EQ(STANDARD_RIGHTS_READ,
607 handle.granted_access & STANDARD_RIGHTS_ALL); 609 handle.granted_access & STANDARD_RIGHTS_ALL);
608 EXPECT_EQ(0, handle.attributes); 610 EXPECT_EQ(0, handle.attributes);
609 } 611 }
610 if (reinterpret_cast<uint32_t>(mapping.get()) == handle.handle) { 612 if (handle_int == HandleToInt(mapping.get())) {
611 EXPECT_FALSE(found_mapping_handle); 613 EXPECT_FALSE(found_mapping_handle);
612 found_mapping_handle = true; 614 found_mapping_handle = true;
613 EXPECT_EQ(L"Section", handle.type_name); 615 EXPECT_EQ(L"Section", handle.type_name);
614 EXPECT_EQ(1, handle.handle_count); 616 EXPECT_EQ(1, handle.handle_count);
615 EXPECT_NE(0u, handle.pointer_count); 617 EXPECT_NE(0u, handle.pointer_count);
616 EXPECT_EQ(DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER | 618 EXPECT_EQ(DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER |
617 STANDARD_RIGHTS_READ | STANDARD_RIGHTS_WRITE, 619 STANDARD_RIGHTS_READ | STANDARD_RIGHTS_WRITE,
618 handle.granted_access & STANDARD_RIGHTS_ALL); 620 handle.granted_access & STANDARD_RIGHTS_ALL);
619 EXPECT_EQ(0, handle.attributes); 621 EXPECT_EQ(0, handle.attributes);
620 } 622 }
621 } 623 }
622 EXPECT_TRUE(found_file_handle); 624 EXPECT_TRUE(found_file_handle);
625 EXPECT_TRUE(found_inherited_file_handle);
623 EXPECT_TRUE(found_key_handle); 626 EXPECT_TRUE(found_key_handle);
624 EXPECT_TRUE(found_mapping_handle); 627 EXPECT_TRUE(found_mapping_handle);
625 } 628 }
626 629
627 TEST(ProcessInfo, OutOfRangeCheck) { 630 TEST(ProcessInfo, OutOfRangeCheck) {
628 const size_t kAllocationSize = 12345; 631 const size_t kAllocationSize = 12345;
629 scoped_ptr<char[]> safe_memory(new char[kAllocationSize]); 632 scoped_ptr<char[]> safe_memory(new char[kAllocationSize]);
630 633
631 ProcessInfo info; 634 ProcessInfo info;
632 info.Initialize(GetCurrentProcess()); 635 info.Initialize(GetCurrentProcess());
633 636
634 EXPECT_TRUE( 637 EXPECT_TRUE(
635 info.LoggingRangeIsFullyReadable(CheckedRange<WinVMAddress, WinVMSize>( 638 info.LoggingRangeIsFullyReadable(CheckedRange<WinVMAddress, WinVMSize>(
636 reinterpret_cast<WinVMAddress>(safe_memory.get()), kAllocationSize))); 639 reinterpret_cast<WinVMAddress>(safe_memory.get()), kAllocationSize)));
637 EXPECT_FALSE(info.LoggingRangeIsFullyReadable( 640 EXPECT_FALSE(info.LoggingRangeIsFullyReadable(
638 CheckedRange<WinVMAddress, WinVMSize>(0, 1024))); 641 CheckedRange<WinVMAddress, WinVMSize>(0, 1024)));
639 } 642 }
640 643
641 } // namespace 644 } // namespace
642 } // namespace test 645 } // namespace test
643 } // namespace crashpad 646 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698