diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-09-03 13:32:17 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-10-01 14:31:55 +0200 |
commit | 21ba0c5d4bf8fba15dddd97cd693bad2358b77fd (patch) | |
tree | 91be119f694044dfc1ff9fdc054459e925de9df0 /chromium/components/zucchini | |
parent | 03c549e0392f92c02536d3f86d5e1d8dfa3435ac (diff) | |
download | qtwebengine-chromium-21ba0c5d4bf8fba15dddd97cd693bad2358b77fd.tar.gz |
BASELINE: Update Chromium to 92.0.4515.166
Change-Id: I42a050486714e9e54fc271f2a8939223a02ae364
Diffstat (limited to 'chromium/components/zucchini')
41 files changed, 165 insertions, 167 deletions
diff --git a/chromium/components/zucchini/abs32_utils.cc b/chromium/components/zucchini/abs32_utils.cc index 5d3d6ea8429..ad1c85e382d 100644 --- a/chromium/components/zucchini/abs32_utils.cc +++ b/chromium/components/zucchini/abs32_utils.cc @@ -110,7 +110,7 @@ Abs32RvaExtractorWin32::Abs32RvaExtractorWin32(Abs32RvaExtractorWin32&&) = Abs32RvaExtractorWin32::~Abs32RvaExtractorWin32() = default; -base::Optional<Abs32RvaExtractorWin32::Unit> Abs32RvaExtractorWin32::GetNext() { +absl::optional<Abs32RvaExtractorWin32::Unit> Abs32RvaExtractorWin32::GetNext() { while (cur_abs32_ < end_abs32_) { offset_t location = *(cur_abs32_++); if (!addr_.Read(location, image_)) @@ -120,7 +120,7 @@ base::Optional<Abs32RvaExtractorWin32::Unit> Abs32RvaExtractorWin32::GetNext() { continue; return Unit{location, target_rva}; } - return base::nullopt; + return absl::nullopt; } /******** Abs32ReaderWin32 ********/ @@ -132,7 +132,7 @@ Abs32ReaderWin32::Abs32ReaderWin32(Abs32RvaExtractorWin32&& abs32_rva_extractor, Abs32ReaderWin32::~Abs32ReaderWin32() = default; -base::Optional<Reference> Abs32ReaderWin32::GetNext() { +absl::optional<Reference> Abs32ReaderWin32::GetNext() { for (auto unit = abs32_rva_extractor_.GetNext(); unit.has_value(); unit = abs32_rva_extractor_.GetNext()) { offset_t location = unit->location; @@ -140,7 +140,7 @@ base::Optional<Reference> Abs32ReaderWin32::GetNext() { if (unsafe_target != kInvalidOffset) return Reference{location, unsafe_target}; } - return base::nullopt; + return absl::nullopt; } /******** Abs32WriterWin32 ********/ diff --git a/chromium/components/zucchini/abs32_utils.h b/chromium/components/zucchini/abs32_utils.h index 5bc9cf21161..f13f562d474 100644 --- a/chromium/components/zucchini/abs32_utils.h +++ b/chromium/components/zucchini/abs32_utils.h @@ -11,10 +11,10 @@ #include <vector> #include "base/macros.h" -#include "base/optional.h" #include "components/zucchini/address_translator.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -78,8 +78,8 @@ class Abs32RvaExtractorWin32 { ~Abs32RvaExtractorWin32(); // Visits given abs32 locations, rejects invalid locations and non-existent - // RVAs, and returns reference as Unit, or base::nullopt on completion. - base::Optional<Unit> GetNext(); + // RVAs, and returns reference as Unit, or absl::nullopt on completion. + absl::optional<Unit> GetNext(); private: ConstBufferView image_; @@ -97,7 +97,7 @@ class Abs32ReaderWin32 : public ReferenceReader { ~Abs32ReaderWin32() override; // ReferenceReader: - base::Optional<Reference> GetNext() override; + absl::optional<Reference> GetNext() override; private: Abs32RvaExtractorWin32 abs32_rva_extractor_; diff --git a/chromium/components/zucchini/abs32_utils_unittest.cc b/chromium/components/zucchini/abs32_utils_unittest.cc index 77a25998e4e..ddbb685a2df 100644 --- a/chromium/components/zucchini/abs32_utils_unittest.cc +++ b/chromium/components/zucchini/abs32_utils_unittest.cc @@ -287,7 +287,7 @@ TEST(Abs32UtilsTest, Win32Read32) { Abs32ReaderWin32 reader(std::move(extractor), translator); // Loop over |expected_ref| to check element-by-element. - base::Optional<Reference> ref; + absl::optional<Reference> ref; for (const auto& expected_ref : test_case.expected_refs) { ref = reader.GetNext(); EXPECT_TRUE(ref.has_value()); @@ -322,7 +322,7 @@ TEST(Abs32UtilsTest, Win32Read64) { Abs32ReaderWin32 reader(std::move(extractor), translator); std::vector<Reference> refs; - base::Optional<Reference> ref; + absl::optional<Reference> ref; for (ref = reader.GetNext(); ref.has_value(); ref = reader.GetNext()) refs.push_back(ref.value()); EXPECT_EQ(expected_refs, refs); diff --git a/chromium/components/zucchini/disassembler.cc b/chromium/components/zucchini/disassembler.cc index 0411791c971..4a210acde44 100644 --- a/chromium/components/zucchini/disassembler.cc +++ b/chromium/components/zucchini/disassembler.cc @@ -10,8 +10,8 @@ namespace zucchini { /******** EmptyReferenceReader ********/ -base::Optional<Reference> EmptyReferenceReader::GetNext() { - return base::nullopt; +absl::optional<Reference> EmptyReferenceReader::GetNext() { + return absl::nullopt; } /******** EmptyReferenceWriter ********/ diff --git a/chromium/components/zucchini/disassembler.h b/chromium/components/zucchini/disassembler.h index 52c69a47fe2..8fd5a3ac462 100644 --- a/chromium/components/zucchini/disassembler.h +++ b/chromium/components/zucchini/disassembler.h @@ -20,7 +20,7 @@ namespace zucchini { // A vacuous ReferenceReader that produces no references. class EmptyReferenceReader : public ReferenceReader { public: - base::Optional<Reference> GetNext() override; + absl::optional<Reference> GetNext() override; }; // A vacuous EmptyReferenceWriter that does not write. diff --git a/chromium/components/zucchini/disassembler_dex.cc b/chromium/components/zucchini/disassembler_dex.cc index 373d6457d79..256ccdeb931 100644 --- a/chromium/components/zucchini/disassembler_dex.cc +++ b/chromium/components/zucchini/disassembler_dex.cc @@ -18,11 +18,11 @@ #include "base/callback.h" #include "base/logging.h" #include "base/numerics/safe_conversions.h" -#include "base/optional.h" #include "base/strings/stringprintf.h" #include "components/zucchini/buffer_source.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/io_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -363,13 +363,13 @@ class InstructionReferenceReader : public ReferenceReader { } // ReferenceReader: - base::Optional<Reference> GetNext() override { + absl::optional<Reference> GetNext() override { while (true) { while (parser_.ReadNext()) { const auto& v = parser_.value(); DCHECK_NE(v.instr, nullptr); if (v.instr_offset >= hi_) - return base::nullopt; + return absl::nullopt; const offset_t location = filter_.Run(v); if (location == kInvalidOffset || location < lo_) continue; @@ -377,7 +377,7 @@ class InstructionReferenceReader : public ReferenceReader { // assumption |hi_| and |lo_| do not straddle the body of a Reference. // So |reference_width| is unneeded. if (location >= hi_) - return base::nullopt; + return absl::nullopt; offset_t target = mapper_.Run(location); if (target != kInvalidOffset) return Reference{location, target}; @@ -386,7 +386,7 @@ class InstructionReferenceReader : public ReferenceReader { } ++cur_it_; if (cur_it_ == end_it_) - return base::nullopt; + return absl::nullopt; parser_ = InstructionParser(image_, *cur_it_); } } @@ -447,7 +447,7 @@ class ItemReferenceReader : public ReferenceReader { } // ReferenceReader: - base::Optional<Reference> GetNext() override { + absl::optional<Reference> GetNext() override { while (cur_idx_ < num_items_) { const offset_t item_offset = OffsetOfIndex(cur_idx_); const offset_t location = item_offset + rel_location_; @@ -478,7 +478,7 @@ class ItemReferenceReader : public ReferenceReader { ++cur_idx_; return Reference{location, target}; } - return base::nullopt; + return absl::nullopt; } private: @@ -631,7 +631,7 @@ class CachedItemListReferenceReader : public ReferenceReader { } // ReferenceReader: - base::Optional<Reference> GetNext() override { + absl::optional<Reference> GetNext() override { while (cur_it_ < end_it_) { const offset_t location = *cur_it_ + rel_location_; if (location >= hi_) // Check is simplified by atomicity assumption. @@ -649,7 +649,7 @@ class CachedItemListReferenceReader : public ReferenceReader { continue; return Reference{location, target}; } - return base::nullopt; + return absl::nullopt; } private: diff --git a/chromium/components/zucchini/disassembler_elf.h b/chromium/components/zucchini/disassembler_elf.h index e279c291092..60d524ce06a 100644 --- a/chromium/components/zucchini/disassembler_elf.h +++ b/chromium/components/zucchini/disassembler_elf.h @@ -7,6 +7,7 @@ #include <stdint.h> +#include <deque> #include <memory> #include <string> #include <vector> @@ -178,7 +179,8 @@ class DisassemblerElfIntel : public DisassemblerElf<Traits> { private: // Sorted file offsets of rel32 locations. - std::vector<offset_t> rel32_locations_; + // Using std::deque to reduce peak memory footprint. + std::deque<offset_t> rel32_locations_; DISALLOW_COPY_AND_ASSIGN(DisassemblerElfIntel); }; diff --git a/chromium/components/zucchini/disassembler_win32.h b/chromium/components/zucchini/disassembler_win32.h index 6c7ba91ceaa..8f9fd58a518 100644 --- a/chromium/components/zucchini/disassembler_win32.h +++ b/chromium/components/zucchini/disassembler_win32.h @@ -8,6 +8,7 @@ #include <stddef.h> #include <stdint.h> +#include <deque> #include <memory> #include <string> #include <utility> @@ -108,7 +109,8 @@ class DisassemblerWin32 : public Disassembler { std::vector<offset_t> reloc_block_offsets_; offset_t reloc_end_ = 0; std::vector<offset_t> abs32_locations_; - std::vector<offset_t> rel32_locations_; + // Using std::deque to reduce peak memory footprint. + std::deque<offset_t> rel32_locations_; // Initialization states of reference storage, used for lazy initialization. // TODO(huangs): Investigate whether lazy initialization is useful for memory diff --git a/chromium/components/zucchini/disassembler_ztf.cc b/chromium/components/zucchini/disassembler_ztf.cc index c54a7b02f2e..f822d8b14e2 100644 --- a/chromium/components/zucchini/disassembler_ztf.cc +++ b/chromium/components/zucchini/disassembler_ztf.cc @@ -290,7 +290,7 @@ class ZtfReferenceReader : public ReferenceReader { // Walks |offset_| from |lo| to |hi_| running |parser_|. If any matches are // found they are returned. - base::Optional<Reference> GetNext() override { + absl::optional<Reference> GetNext() override { T line_col; for (; offset_ < hi_; ++offset_) { if (!parser_.MatchAtOffset(offset_, &line_col)) @@ -304,7 +304,7 @@ class ZtfReferenceReader : public ReferenceReader { offset_ += config_.Width(line_col); return Reference{location, target}; } - return base::nullopt; + return absl::nullopt; } private: @@ -456,12 +456,12 @@ offset_t ZtfTranslator::LineColToOffset(ztf::LineCol lc) const { return target; } -base::Optional<ztf::LineCol> ZtfTranslator::OffsetToLineCol( +absl::optional<ztf::LineCol> ZtfTranslator::OffsetToLineCol( offset_t offset) const { DCHECK(!line_starts_.empty()); // Don't place a target outside the image. if (offset >= line_starts_.back()) - return base::nullopt; + return absl::nullopt; auto it = SearchForRange(offset); ztf::LineCol lc; lc.line = std::distance(line_starts_.cbegin(), it) + 1; diff --git a/chromium/components/zucchini/disassembler_ztf.h b/chromium/components/zucchini/disassembler_ztf.h index 0719093792d..adbead52d19 100644 --- a/chromium/components/zucchini/disassembler_ztf.h +++ b/chromium/components/zucchini/disassembler_ztf.h @@ -13,10 +13,10 @@ #include <vector> #include "base/macros.h" -#include "base/optional.h" #include "components/zucchini/disassembler.h" #include "components/zucchini/image_utils.h" #include "components/zucchini/type_ztf.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -97,8 +97,8 @@ class ZtfTranslator { offset_t LineColToOffset(ztf::LineCol line_col) const; // Returns the ztf::LineCol for an |offset| if it is valid. Otherwise returns - // base::nullopt. - base::Optional<ztf::LineCol> OffsetToLineCol(offset_t offset) const; + // absl::nullopt. + absl::optional<ztf::LineCol> OffsetToLineCol(offset_t offset) const; private: // Returns an iterator to the range containing |offset|. Which is represented diff --git a/chromium/components/zucchini/element_detection.cc b/chromium/components/zucchini/element_detection.cc index bec16be36dd..8682c787340 100644 --- a/chromium/components/zucchini/element_detection.cc +++ b/chromium/components/zucchini/element_detection.cc @@ -118,11 +118,11 @@ std::unique_ptr<Disassembler> MakeDisassemblerOfType(ConstBufferView image, } } -base::Optional<Element> DetectElementFromDisassembler(ConstBufferView image) { +absl::optional<Element> DetectElementFromDisassembler(ConstBufferView image) { std::unique_ptr<Disassembler> disasm = MakeDisassemblerWithoutFallback(image); if (disasm) return Element({0, disasm->size()}, disasm->GetExeType()); - return base::nullopt; + return absl::nullopt; } /******** ProgramScanner ********/ @@ -132,18 +132,18 @@ ElementFinder::ElementFinder(ConstBufferView image, ElementDetector&& detector) ElementFinder::~ElementFinder() = default; -base::Optional<Element> ElementFinder::GetNext() { +absl::optional<Element> ElementFinder::GetNext() { for (; pos_ < image_.size(); ++pos_) { ConstBufferView test_image = ConstBufferView::FromRange(image_.begin() + pos_, image_.end()); - base::Optional<Element> element = detector_.Run(test_image); + absl::optional<Element> element = detector_.Run(test_image); if (element) { element->offset += pos_; pos_ = element->EndOffset(); return element; } } - return base::nullopt; + return absl::nullopt; } } // namespace zucchini diff --git a/chromium/components/zucchini/element_detection.h b/chromium/components/zucchini/element_detection.h index f90c03326fa..d3dcb470d6e 100644 --- a/chromium/components/zucchini/element_detection.h +++ b/chromium/components/zucchini/element_detection.h @@ -11,9 +11,9 @@ #include "base/callback.h" #include "base/macros.h" -#include "base/optional.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -32,10 +32,10 @@ std::unique_ptr<Disassembler> MakeDisassemblerOfType(ConstBufferView image, // Attempts to detect an element associated with |image| and returns it, or // returns nullopt if no element is detected. using ElementDetector = - base::RepeatingCallback<base::Optional<Element>(ConstBufferView image)>; + base::RepeatingCallback<absl::optional<Element>(ConstBufferView image)>; // Implementation of ElementDetector using disassemblers. -base::Optional<Element> DetectElementFromDisassembler(ConstBufferView image); +absl::optional<Element> DetectElementFromDisassembler(ConstBufferView image); // A class to scan through an image and iteratively detect elements. class ElementFinder { @@ -45,7 +45,7 @@ class ElementFinder { // Scans for the next executable using |detector|. Returns the next element // found, or nullopt if no more element can be found. - base::Optional<Element> GetNext(); + absl::optional<Element> GetNext(); private: ConstBufferView image_; diff --git a/chromium/components/zucchini/element_detection_unittest.cc b/chromium/components/zucchini/element_detection_unittest.cc index 769c839d882..319a88a9f46 100644 --- a/chromium/components/zucchini/element_detection_unittest.cc +++ b/chromium/components/zucchini/element_detection_unittest.cc @@ -45,7 +45,7 @@ class ElementDetectionTest : public ::testing::Test { image, base::BindRepeating( [](ExeTypeMap exe_map, ConstBufferView image, - ConstBufferView region) -> base::Optional<Element> { + ConstBufferView region) -> absl::optional<Element> { EXPECT_GE(region.begin(), image.begin()); EXPECT_LE(region.end(), image.end()); EXPECT_GE(region.size(), 0U); @@ -56,7 +56,7 @@ class ElementDetectionTest : public ::testing::Test { ++length; return Element{{0, length}, exe_map[region[0]]}; } - return base::nullopt; + return absl::nullopt; }, exe_map_, image)); std::vector<Element> elements; @@ -74,10 +74,10 @@ TEST_F(ElementDetectionTest, ElementFinderEmpty) { std::vector<uint8_t> buffer(10, 0); ElementFinder finder( ConstBufferView(buffer.data(), buffer.size()), - base::BindRepeating([](ConstBufferView image) -> base::Optional<Element> { - return base::nullopt; + base::BindRepeating([](ConstBufferView image) -> absl::optional<Element> { + return absl::nullopt; })); - EXPECT_EQ(base::nullopt, finder.GetNext()); + EXPECT_EQ(absl::nullopt, finder.GetNext()); } TEST_F(ElementDetectionTest, ElementFinder) { diff --git a/chromium/components/zucchini/ensemble_matcher.cc b/chromium/components/zucchini/ensemble_matcher.cc index 42079d617a8..0ed8a2a72bd 100644 --- a/chromium/components/zucchini/ensemble_matcher.cc +++ b/chromium/components/zucchini/ensemble_matcher.cc @@ -9,7 +9,6 @@ #include "base/logging.h" #include "base/stl_util.h" -#include "base/strings/stringprintf.h" namespace zucchini { diff --git a/chromium/components/zucchini/fuzzers/BUILD.gn b/chromium/components/zucchini/fuzzers/BUILD.gn index 613ac99add2..90c436e8aca 100644 --- a/chromium/components/zucchini/fuzzers/BUILD.gn +++ b/chromium/components/zucchini/fuzzers/BUILD.gn @@ -2,7 +2,6 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -import("//build/config/python.gni") import("//testing/libfuzzer/fuzzer_test.gni") import("//third_party/protobuf/proto_library.gni") @@ -72,8 +71,7 @@ proto_library("zucchini_file_pair_proto") { # Disabled on Windows due to crbug/844826. if (current_toolchain == host_toolchain && !is_win) { # Raw Apply Fuzzer Seed: - # TODO(crbug.com/1112471): Get this to run cleanly under Python 3. - python2_action("zucchini_raw_apply_seed") { + action("zucchini_raw_apply_seed") { script = "generate_fuzzer_data.py" args = [ @@ -109,8 +107,7 @@ if (current_toolchain == host_toolchain && !is_win) { } # ZTF Apply Fuzzer Seed: - # TODO(crbug.com/1112471): Get this to run cleanly under Python 3. - python2_action("zucchini_ztf_apply_seed") { + action("zucchini_ztf_apply_seed") { script = "generate_fuzzer_data.py" # *.ztf files are expected to be valid ZTF format. diff --git a/chromium/components/zucchini/heuristic_ensemble_matcher.cc b/chromium/components/zucchini/heuristic_ensemble_matcher.cc index d6acdbd8355..c812cb4bdcb 100644 --- a/chromium/components/zucchini/heuristic_ensemble_matcher.cc +++ b/chromium/components/zucchini/heuristic_ensemble_matcher.cc @@ -26,9 +26,9 @@ namespace { /******** Helper Functions ********/ // Uses |detector| to find embedded executables inside |image|, and returns the -// result on success, or base::nullopt on failure, which occurs if too many (> +// result on success, or absl::nullopt on failure, which occurs if too many (> // |kElementLimit|) elements are found. -base::Optional<std::vector<Element>> FindEmbeddedElements( +absl::optional<std::vector<Element>> FindEmbeddedElements( ConstBufferView image, const std::string& name, ElementDetector&& detector) { @@ -46,7 +46,7 @@ base::Optional<std::vector<Element>> FindEmbeddedElements( } if (elements.size() >= kElementLimit) { LOG(WARNING) << name << ": Found too many elements."; - return base::nullopt; + return absl::nullopt; } LOG(INFO) << name << ": Found " << elements.size() << " elements."; return elements; @@ -246,12 +246,12 @@ bool HeuristicEnsembleMatcher::RunMatch(ConstBufferView old_image, LOG(INFO) << "Start matching."; // Find all elements in "old" and "new". - base::Optional<std::vector<Element>> old_elements = + absl::optional<std::vector<Element>> old_elements = FindEmbeddedElements(old_image, "Old file", base::BindRepeating(DetectElementFromDisassembler)); if (!old_elements.has_value()) return false; - base::Optional<std::vector<Element>> new_elements = + absl::optional<std::vector<Element>> new_elements = FindEmbeddedElements(new_image, "New file", base::BindRepeating(DetectElementFromDisassembler)); if (!new_elements.has_value()) diff --git a/chromium/components/zucchini/image_utils.h b/chromium/components/zucchini/image_utils.h index b34b9dcc243..3d4a83ac7e7 100644 --- a/chromium/components/zucchini/image_utils.h +++ b/chromium/components/zucchini/image_utils.h @@ -13,10 +13,10 @@ #include "base/format_macros.h" #include "base/macros.h" #include "base/numerics/safe_conversions.h" -#include "base/optional.h" #include "base/strings/stringprintf.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/typed_value.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -94,7 +94,7 @@ class ReferenceReader { // Returns the next available Reference, or nullopt_t if exhausted. // Extracted References must be ordered by their location in the image. - virtual base::Optional<Reference> GetNext() = 0; + virtual absl::optional<Reference> GetNext() = 0; }; // Interface for writing References through member function diff --git a/chromium/components/zucchini/imposed_ensemble_matcher.cc b/chromium/components/zucchini/imposed_ensemble_matcher.cc index e735bc4e79e..1c1301b0653 100644 --- a/chromium/components/zucchini/imposed_ensemble_matcher.cc +++ b/chromium/components/zucchini/imposed_ensemble_matcher.cc @@ -89,8 +89,8 @@ ImposedMatchParser::Status ImposedMatchParser::Parse( continue; } // Check executable types of sub-images. - base::Optional<Element> old_element = detector.Run(old_sub_image); - base::Optional<Element> new_element = detector.Run(new_sub_image); + absl::optional<Element> old_element = detector.Run(old_sub_image); + absl::optional<Element> new_element = detector.Run(new_sub_image); if (!old_element || !new_element) { // Skip unknown types, including those mixed with known types. bad_matches_.push_back(matches_[read_idx]); diff --git a/chromium/components/zucchini/imposed_ensemble_matcher_unittest.cc b/chromium/components/zucchini/imposed_ensemble_matcher_unittest.cc index 85f1016447c..9a6dc7d0fbf 100644 --- a/chromium/components/zucchini/imposed_ensemble_matcher_unittest.cc +++ b/chromium/components/zucchini/imposed_ensemble_matcher_unittest.cc @@ -14,12 +14,12 @@ #include "base/bind.h" #include "base/callback_helpers.h" #include "base/check_op.h" -#include "base/optional.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/disassembler.h" #include "components/zucchini/element_detection.h" #include "components/zucchini/image_utils.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -36,14 +36,14 @@ class TestElementDetector { public: TestElementDetector() {} - base::Optional<Element> Run(ConstBufferView image) const { + absl::optional<Element> Run(ConstBufferView image) const { DCHECK_GT(image.size(), 0U); char first_char = *image.begin(); if (first_char == 'W' || first_char == 'w') return Element(image.local_region(), kExeTypeWin32X86); if (first_char == 'E' || first_char == 'e') return Element(image.local_region(), kExeTypeElfX86); - return base::nullopt; + return absl::nullopt; } }; diff --git a/chromium/components/zucchini/integration_test.cc b/chromium/components/zucchini/integration_test.cc index 2d2e61f7456..1baccc351b3 100644 --- a/chromium/components/zucchini/integration_test.cc +++ b/chromium/components/zucchini/integration_test.cc @@ -10,13 +10,13 @@ #include "base/files/file_path.h" #include "base/files/memory_mapped_file.h" -#include "base/optional.h" #include "base/path_service.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/patch_reader.h" #include "components/zucchini/patch_writer.h" #include "components/zucchini/zucchini.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -59,7 +59,7 @@ void TestGenApply(const std::string& old_filename, patch_writer.SerializeInto({patch_buffer.data(), patch_buffer.size()}); // Read back generated patch. - base::Optional<EnsemblePatchReader> patch_reader = + absl::optional<EnsemblePatchReader> patch_reader = EnsemblePatchReader::Create({patch_buffer.data(), patch_buffer.size()}); ASSERT_TRUE(patch_reader.has_value()); diff --git a/chromium/components/zucchini/main_utils.h b/chromium/components/zucchini/main_utils.h index addb8302406..6c97aad7674 100644 --- a/chromium/components/zucchini/main_utils.h +++ b/chromium/components/zucchini/main_utils.h @@ -7,7 +7,6 @@ #include <iosfwd> -#include "base/files/file_path.h" #include "components/zucchini/zucchini.h" // Utilities to run Zucchini command based on command-line input, and to print diff --git a/chromium/components/zucchini/patch_reader.cc b/chromium/components/zucchini/patch_reader.cc index 3ec17e45487..99951da1742 100644 --- a/chromium/components/zucchini/patch_reader.cc +++ b/chromium/components/zucchini/patch_reader.cc @@ -78,42 +78,42 @@ bool EquivalenceSource::Initialize(BufferSource* source) { patch::ParseBuffer(source, ©_count_); } -base::Optional<Equivalence> EquivalenceSource::GetNext() { +absl::optional<Equivalence> EquivalenceSource::GetNext() { if (src_skip_.empty() || dst_skip_.empty() || copy_count_.empty()) - return base::nullopt; + return absl::nullopt; Equivalence equivalence = {}; uint32_t length = 0; if (!patch::ParseVarUInt<uint32_t>(©_count_, &length)) - return base::nullopt; + return absl::nullopt; equivalence.length = base::strict_cast<offset_t>(length); int32_t src_offset_diff = 0; // Intentionally signed. if (!patch::ParseVarInt<int32_t>(&src_skip_, &src_offset_diff)) - return base::nullopt; + return absl::nullopt; base::CheckedNumeric<offset_t> src_offset = previous_src_offset_ + src_offset_diff; if (!src_offset.IsValid()) - return base::nullopt; + return absl::nullopt; equivalence.src_offset = src_offset.ValueOrDie(); previous_src_offset_ = src_offset + equivalence.length; if (!previous_src_offset_.IsValid()) - return base::nullopt; + return absl::nullopt; uint32_t dst_offset_diff = 0; // Intentionally unsigned. if (!patch::ParseVarUInt<uint32_t>(&dst_skip_, &dst_offset_diff)) - return base::nullopt; + return absl::nullopt; base::CheckedNumeric<offset_t> dst_offset = previous_dst_offset_ + dst_offset_diff; if (!dst_offset.IsValid()) - return base::nullopt; + return absl::nullopt; equivalence.dst_offset = dst_offset.ValueOrDie(); previous_dst_offset_ = equivalence.dst_offset + equivalence.length; if (!previous_dst_offset_.IsValid()) - return base::nullopt; + return absl::nullopt; // Caveat: |equivalence| is assumed to be safe only once the // ValidateEquivalencesAndExtraData() method has returned true. Prior to this @@ -131,10 +131,10 @@ bool ExtraDataSource::Initialize(BufferSource* source) { return patch::ParseBuffer(source, &extra_data_); } -base::Optional<ConstBufferView> ExtraDataSource::GetNext(offset_t size) { +absl::optional<ConstBufferView> ExtraDataSource::GetNext(offset_t size) { ConstBufferView buffer; if (!extra_data_.GetRegion(size, &buffer)) - return base::nullopt; + return absl::nullopt; // |buffer| is assumed to always be safe/valid. return buffer; } @@ -150,32 +150,32 @@ bool RawDeltaSource::Initialize(BufferSource* source) { patch::ParseBuffer(source, &raw_delta_diff_); } -base::Optional<RawDeltaUnit> RawDeltaSource::GetNext() { +absl::optional<RawDeltaUnit> RawDeltaSource::GetNext() { if (raw_delta_skip_.empty() || raw_delta_diff_.empty()) - return base::nullopt; + return absl::nullopt; RawDeltaUnit raw_delta = {}; uint32_t copy_offset_diff = 0; if (!patch::ParseVarUInt<uint32_t>(&raw_delta_skip_, ©_offset_diff)) - return base::nullopt; + return absl::nullopt; base::CheckedNumeric<offset_t> copy_offset = copy_offset_diff + copy_offset_compensation_; if (!copy_offset.IsValid()) - return base::nullopt; + return absl::nullopt; raw_delta.copy_offset = copy_offset.ValueOrDie(); if (!raw_delta_diff_.GetValue<int8_t>(&raw_delta.diff)) - return base::nullopt; + return absl::nullopt; // A 0 value for a delta.diff is considered invalid since it has no meaning. if (!raw_delta.diff) - return base::nullopt; + return absl::nullopt; // We keep track of the compensation needed for next offset, taking into // account delta encoding and bias of -1. copy_offset_compensation_ = copy_offset + 1; if (!copy_offset_compensation_.IsValid()) - return base::nullopt; + return absl::nullopt; // |raw_delta| is assumed to always be safe/valid. return raw_delta; } @@ -191,12 +191,12 @@ bool ReferenceDeltaSource::Initialize(BufferSource* source) { return patch::ParseBuffer(source, &source_); } -base::Optional<int32_t> ReferenceDeltaSource::GetNext() { +absl::optional<int32_t> ReferenceDeltaSource::GetNext() { if (source_.empty()) - return base::nullopt; + return absl::nullopt; int32_t ref_delta = 0; if (!patch::ParseVarInt<int32_t>(&source_, &ref_delta)) - return base::nullopt; + return absl::nullopt; // |ref_delta| is assumed to always be safe/valid. return ref_delta; } @@ -211,22 +211,22 @@ bool TargetSource::Initialize(BufferSource* source) { return patch::ParseBuffer(source, &extra_targets_); } -base::Optional<offset_t> TargetSource::GetNext() { +absl::optional<offset_t> TargetSource::GetNext() { if (extra_targets_.empty()) - return base::nullopt; + return absl::nullopt; uint32_t target_diff = 0; if (!patch::ParseVarUInt<uint32_t>(&extra_targets_, &target_diff)) - return base::nullopt; + return absl::nullopt; base::CheckedNumeric<offset_t> target = target_diff + target_compensation_; if (!target.IsValid()) - return base::nullopt; + return absl::nullopt; // We keep track of the compensation needed for next target, taking into // account delta encoding and bias of -1. target_compensation_ = target + 1; if (!target_compensation_.IsValid()) - return base::nullopt; + return absl::nullopt; // Caveat: |target| will be a valid offset_t, but it's up to the caller to // check whether it's a valid offset for an image. return offset_t(target.ValueOrDie()); @@ -312,12 +312,12 @@ bool PatchElementReader::ValidateEquivalencesAndExtraData() { /******** EnsemblePatchReader ********/ -base::Optional<EnsemblePatchReader> EnsemblePatchReader::Create( +absl::optional<EnsemblePatchReader> EnsemblePatchReader::Create( ConstBufferView buffer) { BufferSource source(buffer); EnsemblePatchReader patch; if (!patch.Initialize(&source)) - return base::nullopt; + return absl::nullopt; return patch; } diff --git a/chromium/components/zucchini/patch_reader.h b/chromium/components/zucchini/patch_reader.h index 515da500144..93d64b04747 100644 --- a/chromium/components/zucchini/patch_reader.h +++ b/chromium/components/zucchini/patch_reader.h @@ -14,11 +14,11 @@ #include "base/debug/stack_trace.h" #include "base/logging.h" #include "base/numerics/checked_math.h" -#include "base/optional.h" #include "components/zucchini/buffer_source.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" #include "components/zucchini/patch_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -77,8 +77,8 @@ bool ParseVarInt(BufferSource* source, T* value) { // - bool Initialize(BufferSource* source): Consumes data from BufferSource and // initializes internal states. Returns true if successful, and false // otherwise (|source| may be partially consumed). -// - base::Optional<MAIN_TYPE> GetNext(OPT_PARAMS): Decodes consumed data and -// returns the next item as base::Optional (returns base::nullopt on failure). +// - absl::optional<MAIN_TYPE> GetNext(OPT_PARAMS): Decodes consumed data and +// returns the next item as absl::optional (returns absl::nullopt on failure). // - bool Done() const: Returns true if no more items remain; otherwise false. // // Usage of *Source instances don't mix, and GetNext() have dissimilar @@ -94,7 +94,7 @@ class EquivalenceSource { // Core functions. bool Initialize(BufferSource* source); - base::Optional<Equivalence> GetNext(); + absl::optional<Equivalence> GetNext(); bool Done() const { return src_skip_.empty() && dst_skip_.empty() && copy_count_.empty(); } @@ -123,7 +123,7 @@ class ExtraDataSource { // Core functions. bool Initialize(BufferSource* source); // |size| is the size in bytes of the buffer requested. - base::Optional<ConstBufferView> GetNext(offset_t size); + absl::optional<ConstBufferView> GetNext(offset_t size); bool Done() const { return extra_data_.empty(); } // Accessors for unittest. @@ -142,7 +142,7 @@ class RawDeltaSource { // Core functions. bool Initialize(BufferSource* source); - base::Optional<RawDeltaUnit> GetNext(); + absl::optional<RawDeltaUnit> GetNext(); bool Done() const { return raw_delta_skip_.empty() && raw_delta_diff_.empty(); } @@ -167,7 +167,7 @@ class ReferenceDeltaSource { // Core functions. bool Initialize(BufferSource* source); - base::Optional<int32_t> GetNext(); + absl::optional<int32_t> GetNext(); bool Done() const { return source_.empty(); } // Accessors for unittest. @@ -186,7 +186,7 @@ class TargetSource { // Core functions. bool Initialize(BufferSource* source); - base::Optional<offset_t> GetNext(); + absl::optional<offset_t> GetNext(); bool Done() const { return extra_targets_.empty(); } // Accessors for unittest. @@ -256,8 +256,8 @@ class PatchElementReader { class EnsemblePatchReader { public: // If data read from |buffer| is well-formed, initializes and returns - // an instance of EnsemblePatchReader. Otherwise returns base::nullopt. - static base::Optional<EnsemblePatchReader> Create(ConstBufferView buffer); + // an instance of EnsemblePatchReader. Otherwise returns absl::nullopt. + static absl::optional<EnsemblePatchReader> Create(ConstBufferView buffer); EnsemblePatchReader(); EnsemblePatchReader(EnsemblePatchReader&&); diff --git a/chromium/components/zucchini/patch_writer.h b/chromium/components/zucchini/patch_writer.h index 34acaf1ce57..3d42173dc47 100644 --- a/chromium/components/zucchini/patch_writer.h +++ b/chromium/components/zucchini/patch_writer.h @@ -14,11 +14,11 @@ #include "base/check.h" #include "base/macros.h" -#include "base/optional.h" #include "components/zucchini/buffer_sink.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" #include "components/zucchini/patch_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -224,10 +224,10 @@ class PatchElementWriter { private: ElementMatch element_match_; - base::Optional<EquivalenceSink> equivalences_; - base::Optional<ExtraDataSink> extra_data_; - base::Optional<RawDeltaSink> raw_delta_; - base::Optional<ReferenceDeltaSink> reference_delta_; + absl::optional<EquivalenceSink> equivalences_; + absl::optional<ExtraDataSink> extra_data_; + absl::optional<RawDeltaSink> raw_delta_; + absl::optional<ReferenceDeltaSink> reference_delta_; std::map<PoolTag, TargetSink> extra_targets_; }; diff --git a/chromium/components/zucchini/rel32_finder.cc b/chromium/components/zucchini/rel32_finder.cc index 8fb88f5aaa0..45810d6eea5 100644 --- a/chromium/components/zucchini/rel32_finder.cc +++ b/chromium/components/zucchini/rel32_finder.cc @@ -41,7 +41,7 @@ Abs32GapFinder::Abs32GapFinder(ConstBufferView image, Abs32GapFinder::~Abs32GapFinder() = default; -base::Optional<ConstBufferView> Abs32GapFinder::GetNext() { +absl::optional<ConstBufferView> Abs32GapFinder::GetNext() { // Iterate over |[abs32_current_, abs32_end_)| and emit segments. while (abs32_current_ != abs32_end_ && base_ + *abs32_current_ < region_end_) { @@ -58,7 +58,7 @@ base::Optional<ConstBufferView> Abs32GapFinder::GetNext() { current_lo_ = region_end_; return gap; } - return base::nullopt; + return absl::nullopt; } /******** Rel32Finder ********/ diff --git a/chromium/components/zucchini/rel32_finder.h b/chromium/components/zucchini/rel32_finder.h index b70b1be961e..5953755a808 100644 --- a/chromium/components/zucchini/rel32_finder.h +++ b/chromium/components/zucchini/rel32_finder.h @@ -10,9 +10,9 @@ #include <vector> #include "base/macros.h" -#include "base/optional.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -52,7 +52,7 @@ class Abs32GapFinder { ~Abs32GapFinder(); // Returns the next available gap, or nullopt if exhausted. - base::Optional<ConstBufferView> GetNext(); + absl::optional<ConstBufferView> GetNext(); private: const ConstBufferView::const_iterator base_; @@ -134,10 +134,10 @@ class Rel32FinderIntel : public Rel32Finder { using Rel32Finder::Rel32Finder; // Returns the next available Result, or nullopt if exhausted. - base::Optional<Result> GetNext() { + absl::optional<Result> GetNext() { if (FindNext()) return rel32_; - return base::nullopt; + return absl::nullopt; } protected: diff --git a/chromium/components/zucchini/rel32_finder_unittest.cc b/chromium/components/zucchini/rel32_finder_unittest.cc index 9da88bfbd0e..42a442c430f 100644 --- a/chromium/components/zucchini/rel32_finder_unittest.cc +++ b/chromium/components/zucchini/rel32_finder_unittest.cc @@ -234,7 +234,7 @@ TEST(Rel32FinderX86Test, FindNext) { EXPECT_FALSE(result->can_point_outside_section); rel_finder.Accept(); } - EXPECT_EQ(base::nullopt, rel_finder.GetNext()); + EXPECT_EQ(absl::nullopt, rel_finder.GetNext()); } TEST(Rel32FinderX86Test, Accept) { @@ -349,7 +349,7 @@ TEST(Rel32FinderX64Test, FindNext) { EXPECT_TRUE(result->can_point_outside_section); rel_finder.Accept(); } - EXPECT_EQ(base::nullopt, rel_finder.GetNext()); + EXPECT_EQ(absl::nullopt, rel_finder.GetNext()); } // TODO(huangs): Test that integrates Abs32GapFinder and Rel32Finder. diff --git a/chromium/components/zucchini/rel32_utils.cc b/chromium/components/zucchini/rel32_utils.cc index 37bcb6f43ec..c22cb23159d 100644 --- a/chromium/components/zucchini/rel32_utils.cc +++ b/chromium/components/zucchini/rel32_utils.cc @@ -16,7 +16,7 @@ namespace zucchini { Rel32ReaderX86::Rel32ReaderX86(ConstBufferView image, offset_t lo, offset_t hi, - const std::vector<offset_t>* locations, + const std::deque<offset_t>* locations, const AddressTranslator& translator) : image_(image), target_rva_to_offset_(translator), @@ -30,7 +30,7 @@ Rel32ReaderX86::Rel32ReaderX86(ConstBufferView image, Rel32ReaderX86::~Rel32ReaderX86() = default; -base::Optional<Reference> Rel32ReaderX86::GetNext() { +absl::optional<Reference> Rel32ReaderX86::GetNext() { while (current_ < last_ && *current_ < hi_) { offset_t loc_offset = *(current_++); DCHECK_LE(loc_offset + 4, image_.size()); // Sanity check. @@ -41,7 +41,7 @@ base::Optional<Reference> Rel32ReaderX86::GetNext() { DCHECK_NE(kInvalidOffset, target_offset); return Reference{loc_offset, target_offset}; } - return base::nullopt; + return absl::nullopt; } /******** Rel32ReceptorX86 ********/ diff --git a/chromium/components/zucchini/rel32_utils.h b/chromium/components/zucchini/rel32_utils.h index 618ed0d5a38..4f7e0f30ed4 100644 --- a/chromium/components/zucchini/rel32_utils.h +++ b/chromium/components/zucchini/rel32_utils.h @@ -6,17 +6,17 @@ #define COMPONENTS_ZUCCHINI_REL32_UTILS_H_ #include <algorithm> +#include <deque> #include <memory> -#include <vector> #include "base/logging.h" #include "base/macros.h" -#include "base/optional.h" #include "components/zucchini/address_translator.h" #include "components/zucchini/arm_utils.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" #include "components/zucchini/io_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -32,20 +32,20 @@ class Rel32ReaderX86 : public ReferenceReader { Rel32ReaderX86(ConstBufferView image, offset_t lo, offset_t hi, - const std::vector<offset_t>* locations, + const std::deque<offset_t>* locations, const AddressTranslator& translator); ~Rel32ReaderX86() override; - // Returns the next reference, or base::nullopt if exhausted. - base::Optional<Reference> GetNext() override; + // Returns the next reference, or absl::nullopt if exhausted. + absl::optional<Reference> GetNext() override; private: ConstBufferView image_; AddressTranslator::RvaToOffsetCache target_rva_to_offset_; AddressTranslator::OffsetToRvaCache location_offset_to_rva_; const offset_t hi_; - const std::vector<offset_t>::const_iterator last_; - std::vector<offset_t>::const_iterator current_; + const std::deque<offset_t>::const_iterator last_; + std::deque<offset_t>::const_iterator current_; DISALLOW_COPY_AND_ASSIGN(Rel32ReaderX86); }; @@ -79,7 +79,7 @@ class Rel32ReaderArm : public ReferenceReader { Rel32ReaderArm(const AddressTranslator& translator, ConstBufferView view, - const std::vector<offset_t>& rel32_locations, + const std::deque<offset_t>& rel32_locations, offset_t lo, offset_t hi) : view_(view), @@ -91,7 +91,7 @@ class Rel32ReaderArm : public ReferenceReader { rel32_end_ = rel32_locations.end(); } - base::Optional<Reference> GetNext() override { + absl::optional<Reference> GetNext() override { while (cur_it_ < rel32_end_ && *cur_it_ < hi_) { offset_t location = *(cur_it_++); CODE_T code = ADDR_TRAITS::Fetch(view_, location); @@ -103,15 +103,15 @@ class Rel32ReaderArm : public ReferenceReader { return Reference{location, target}; } } - return base::nullopt; + return absl::nullopt; } private: ConstBufferView view_; AddressTranslator::OffsetToRvaCache offset_to_rva_; AddressTranslator::RvaToOffsetCache rva_to_offset_; - std::vector<offset_t>::const_iterator cur_it_; - std::vector<offset_t>::const_iterator rel32_end_; + std::deque<offset_t>::const_iterator cur_it_; + std::deque<offset_t>::const_iterator rel32_end_; offset_t hi_; DISALLOW_COPY_AND_ASSIGN(Rel32ReaderArm); diff --git a/chromium/components/zucchini/rel32_utils_unittest.cc b/chromium/components/zucchini/rel32_utils_unittest.cc index e3d34f41432..32fd7ae6a4a 100644 --- a/chromium/components/zucchini/rel32_utils_unittest.cc +++ b/chromium/components/zucchini/rel32_utils_unittest.cc @@ -6,16 +6,17 @@ #include <stdint.h> +#include <deque> #include <memory> #include <utility> #include <vector> -#include "base/optional.h" #include "base/test/gtest_util.h" #include "components/zucchini/address_translator.h" #include "components/zucchini/arm_utils.h" #include "components/zucchini/image_utils.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -39,7 +40,7 @@ void CheckReader(const std::vector<Reference>& expected_refs, EXPECT_TRUE(ref.has_value()); EXPECT_EQ(expected_ref, ref.value()); } - EXPECT_EQ(base::nullopt, reader->GetNext()); // Nothing should be left. + EXPECT_EQ(absl::nullopt, reader->GetNext()); // Nothing should be left. } // Copies displacements from |bytes1| to |bytes2| and checks results against @@ -88,7 +89,7 @@ TEST(Rel32UtilsTest, Rel32ReaderX86) { }; ConstBufferView buffer(bytes.data(), bytes.size()); // Specify rel32 locations directly, instead of parsing. - std::vector<offset_t> rel32_locations = {0x0008U, 0x0010U, 0x0018U, 0x001CU}; + std::deque<offset_t> rel32_locations = {0x0008U, 0x0010U, 0x0018U, 0x001CU}; // Generate everything. auto reader1 = std::make_unique<Rel32ReaderX86>(buffer, 0x0000U, 0x0020U, @@ -163,8 +164,8 @@ TEST(Rel32UtilsTest, Rel32ReaderArm_Arm32) { }; ConstBufferView region(&bytes[0], bytes.size()); // Specify rel32 locations directly, instead of parsing. - std::vector<offset_t> rel32_locations_A24 = {0x0008U, 0x0010U, 0x0018U, - 0x001CU}; + std::deque<offset_t> rel32_locations_A24 = {0x0008U, 0x0010U, 0x0018U, + 0x001CU}; // Generate everything. auto reader1 = @@ -427,21 +428,21 @@ TEST(Rel32UtilsTest, Rel32ReaderArm_AArch64) { MutableBufferView region(&bytes[0], bytes.size()); // Generate Immd26. We specify rel32 locations directly. - std::vector<offset_t> rel32_locations_Immd26 = {0x0008U}; + std::deque<offset_t> rel32_locations_Immd26 = {0x0008U}; auto reader1 = std::make_unique< Rel32ReaderArm<AArch64Rel32Translator::AddrTraits_Immd26>>( translator, region, rel32_locations_Immd26, 0x0000U, 0x0020U); CheckReader({{0x0008U, 0x0010U}}, std::move(reader1)); // Generate Immd19. - std::vector<offset_t> rel32_locations_Immd19 = {0x0010U, 0x0018U}; + std::deque<offset_t> rel32_locations_Immd19 = {0x0010U, 0x0018U}; auto reader2 = std::make_unique< Rel32ReaderArm<AArch64Rel32Translator::AddrTraits_Immd19>>( translator, region, rel32_locations_Immd19, 0x0000U, 0x0020U); CheckReader({{0x0010U, 0x0014U}, {0x0018U, 0x0010U}}, std::move(reader2)); // Generate Immd14. - std::vector<offset_t> rel32_locations_Immd14 = {0x001CU}; + std::deque<offset_t> rel32_locations_Immd14 = {0x001CU}; auto reader3 = std::make_unique< Rel32ReaderArm<AArch64Rel32Translator::AddrTraits_Immd14>>( translator, region, rel32_locations_Immd14, 0x0000U, 0x0020U); diff --git a/chromium/components/zucchini/reloc_elf.cc b/chromium/components/zucchini/reloc_elf.cc index d4857e86c47..a7d1b38207a 100644 --- a/chromium/components/zucchini/reloc_elf.cc +++ b/chromium/components/zucchini/reloc_elf.cc @@ -89,7 +89,7 @@ rva_t RelocReaderElf::GetRelocationTarget(elf::Elf64_Rel rel) const { return kInvalidRva; } -base::Optional<Reference> RelocReaderElf::GetNext() { +absl::optional<Reference> RelocReaderElf::GetNext() { offset_t cur_entry_size = cur_section_dimensions_->entry_size; offset_t cur_section_dimensions_end = base::checked_cast<offset_t>(cur_section_dimensions_->region.hi()); @@ -98,12 +98,12 @@ base::Optional<Reference> RelocReaderElf::GetNext() { while (cursor_ >= cur_section_dimensions_end) { ++cur_section_dimensions_; if (cur_section_dimensions_ == reloc_section_dimensions_.end()) - return base::nullopt; + return absl::nullopt; cur_entry_size = cur_section_dimensions_->entry_size; cursor_ = base::checked_cast<offset_t>(cur_section_dimensions_->region.offset); if (cursor_ + cur_entry_size > hi_) - return base::nullopt; + return absl::nullopt; cur_section_dimensions_end = base::checked_cast<offset_t>(cur_section_dimensions_->region.hi()); } @@ -132,7 +132,7 @@ base::Optional<Reference> RelocReaderElf::GetNext() { cursor_ += cur_entry_size; return Reference{location, target}; } - return base::nullopt; + return absl::nullopt; } /******** RelocWriterElf ********/ diff --git a/chromium/components/zucchini/reloc_elf.h b/chromium/components/zucchini/reloc_elf.h index 7fcdbd3521f..ebf2577bbd0 100644 --- a/chromium/components/zucchini/reloc_elf.h +++ b/chromium/components/zucchini/reloc_elf.h @@ -11,11 +11,11 @@ #include <vector> #include "base/numerics/safe_conversions.h" -#include "base/optional.h" #include "components/zucchini/address_translator.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" #include "components/zucchini/type_elf.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -68,7 +68,7 @@ class RelocReaderElf : public ReferenceReader { rva_t GetRelocationTarget(elf::Elf64_Rel rel) const; // ReferenceReader: - base::Optional<Reference> GetNext() override; + absl::optional<Reference> GetNext() override; private: const ConstBufferView image_; diff --git a/chromium/components/zucchini/reloc_elf_unittest.cc b/chromium/components/zucchini/reloc_elf_unittest.cc index acbc1863c9f..ac5086abd25 100644 --- a/chromium/components/zucchini/reloc_elf_unittest.cc +++ b/chromium/components/zucchini/reloc_elf_unittest.cc @@ -85,7 +85,7 @@ class FakeImageWithReloc { // Read all references and check. std::vector<Reference> refs; - for (base::Optional<Reference> ref = reader->GetNext(); ref.has_value(); + for (absl::optional<Reference> ref = reader->GetNext(); ref.has_value(); ref = reader->GetNext()) { refs.push_back(ref.value()); } diff --git a/chromium/components/zucchini/reloc_win32.cc b/chromium/components/zucchini/reloc_win32.cc index 6da48f2ab41..b70aa8a187c 100644 --- a/chromium/components/zucchini/reloc_win32.cc +++ b/chromium/components/zucchini/reloc_win32.cc @@ -93,14 +93,14 @@ RelocRvaReaderWin32::RelocRvaReaderWin32(RelocRvaReaderWin32&&) = default; RelocRvaReaderWin32::~RelocRvaReaderWin32() = default; // Unrolls a nested loop: outer = reloc blocks and inner = reloc entries. -base::Optional<RelocUnitWin32> RelocRvaReaderWin32::GetNext() { +absl::optional<RelocUnitWin32> RelocRvaReaderWin32::GetNext() { // "Outer loop" to find non-empty reloc block. while (cur_reloc_units_.Remaining() < kRelocUnitSize) { if (!LoadRelocBlock(cur_reloc_units_.end())) - return base::nullopt; + return absl::nullopt; } if (end_it_ - cur_reloc_units_.begin() < kRelocUnitSize) - return base::nullopt; + return absl::nullopt; // "Inner loop" to extract single reloc unit. offset_t location = base::checked_cast<offset_t>(cur_reloc_units_.begin() - image_.begin()); @@ -144,8 +144,8 @@ RelocReaderWin32::RelocReaderWin32(RelocRvaReaderWin32&& reloc_rva_reader, RelocReaderWin32::~RelocReaderWin32() = default; // ReferenceReader: -base::Optional<Reference> RelocReaderWin32::GetNext() { - for (base::Optional<RelocUnitWin32> unit = reloc_rva_reader_.GetNext(); +absl::optional<Reference> RelocReaderWin32::GetNext() { + for (absl::optional<RelocUnitWin32> unit = reloc_rva_reader_.GetNext(); unit.has_value(); unit = reloc_rva_reader_.GetNext()) { if (unit->type != reloc_type_) continue; @@ -158,7 +158,7 @@ base::Optional<Reference> RelocReaderWin32::GetNext() { offset_t location = unit->location; return Reference{location, target}; } - return base::nullopt; + return absl::nullopt; } /******** RelocWriterWin32 ********/ diff --git a/chromium/components/zucchini/reloc_win32.h b/chromium/components/zucchini/reloc_win32.h index 207c6e7dfe3..6393702f6cd 100644 --- a/chromium/components/zucchini/reloc_win32.h +++ b/chromium/components/zucchini/reloc_win32.h @@ -10,11 +10,11 @@ #include <vector> -#include "base/optional.h" #include "components/zucchini/address_translator.h" #include "components/zucchini/buffer_source.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -65,9 +65,9 @@ class RelocRvaReaderWin32 { RelocRvaReaderWin32(RelocRvaReaderWin32&&); ~RelocRvaReaderWin32(); - // Successively visits and returns data for each reloc unit, or base::nullopt + // Successively visits and returns data for each reloc unit, or absl::nullopt // when all reloc units are found. Encapsulates block transition details. - base::Optional<RelocUnitWin32> GetNext(); + absl::optional<RelocUnitWin32> GetNext(); private: // Assuming that |block_begin| points to the beginning of a reloc block, loads @@ -102,7 +102,7 @@ class RelocReaderWin32 : public ReferenceReader { ~RelocReaderWin32() override; // ReferenceReader: - base::Optional<Reference> GetNext() override; + absl::optional<Reference> GetNext() override; private: RelocRvaReaderWin32 reloc_rva_reader_; diff --git a/chromium/components/zucchini/reloc_win32_unittest.cc b/chromium/components/zucchini/reloc_win32_unittest.cc index 1b9894f3c8a..e3d33ca2193 100644 --- a/chromium/components/zucchini/reloc_win32_unittest.cc +++ b/chromium/components/zucchini/reloc_win32_unittest.cc @@ -219,7 +219,7 @@ TEST_F(RelocUtilsWin32Test, ReadWrite) { // Read all references and check. std::vector<Reference> refs; - for (base::Optional<Reference> ref = reader->GetNext(); ref.has_value(); + for (absl::optional<Reference> ref = reader->GetNext(); ref.has_value(); ref = reader->GetNext()) { refs.push_back(ref.value()); } diff --git a/chromium/components/zucchini/test_reference_reader.cc b/chromium/components/zucchini/test_reference_reader.cc index 5517fa0003d..b7f8ece8963 100644 --- a/chromium/components/zucchini/test_reference_reader.cc +++ b/chromium/components/zucchini/test_reference_reader.cc @@ -11,9 +11,9 @@ TestReferenceReader::TestReferenceReader(const std::vector<Reference>& refs) TestReferenceReader::~TestReferenceReader() = default; -base::Optional<Reference> TestReferenceReader::GetNext() { +absl::optional<Reference> TestReferenceReader::GetNext() { if (index_ == references_.size()) - return base::nullopt; + return absl::nullopt; return references_[index_++]; } diff --git a/chromium/components/zucchini/test_reference_reader.h b/chromium/components/zucchini/test_reference_reader.h index afae1888b21..cc8c0de043a 100644 --- a/chromium/components/zucchini/test_reference_reader.h +++ b/chromium/components/zucchini/test_reference_reader.h @@ -9,8 +9,8 @@ #include <vector> -#include "base/optional.h" #include "components/zucchini/image_utils.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { @@ -20,7 +20,7 @@ class TestReferenceReader : public ReferenceReader { explicit TestReferenceReader(const std::vector<Reference>& refs); ~TestReferenceReader() override; - base::Optional<Reference> GetNext() override; + absl::optional<Reference> GetNext() override; private: std::vector<Reference> references_; diff --git a/chromium/components/zucchini/zucchini_apply.cc b/chromium/components/zucchini/zucchini_apply.cc index 2d001a1bb3c..10c5638e9ff 100644 --- a/chromium/components/zucchini/zucchini_apply.cc +++ b/chromium/components/zucchini/zucchini_apply.cc @@ -32,7 +32,7 @@ bool ApplyEquivalenceAndExtraData(ConstBufferView old_image, CHECK(next_dst_it >= dst_it); offset_t gap = static_cast<offset_t>(next_dst_it - dst_it); - base::Optional<ConstBufferView> extra_data = extra_data_source.GetNext(gap); + absl::optional<ConstBufferView> extra_data = extra_data_source.GetNext(gap); if (!extra_data) { LOG(ERROR) << "Error reading extra_data"; return false; @@ -46,7 +46,7 @@ bool ApplyEquivalenceAndExtraData(ConstBufferView old_image, CHECK_EQ(dst_it, next_dst_it + equivalence->length); } offset_t gap = static_cast<offset_t>(new_image.end() - dst_it); - base::Optional<ConstBufferView> extra_data = extra_data_source.GetNext(gap); + absl::optional<ConstBufferView> extra_data = extra_data_source.GetNext(gap); if (!extra_data) { LOG(ERROR) << "Error reading extra_data"; return false; diff --git a/chromium/components/zucchini/zucchini_apply.h b/chromium/components/zucchini/zucchini_apply.h index 559812eaaeb..abab3843247 100644 --- a/chromium/components/zucchini/zucchini_apply.h +++ b/chromium/components/zucchini/zucchini_apply.h @@ -5,8 +5,6 @@ #ifndef COMPONENTS_ZUCCHINI_ZUCCHINI_APPLY_H_ #define COMPONENTS_ZUCCHINI_ZUCCHINI_APPLY_H_ -#include <vector> - #include "components/zucchini/image_utils.h" #include "components/zucchini/patch_reader.h" #include "components/zucchini/zucchini.h" diff --git a/chromium/components/zucchini/zucchini_gen.h b/chromium/components/zucchini/zucchini_gen.h index 17f1fd4b2a4..c92248d7619 100644 --- a/chromium/components/zucchini/zucchini_gen.h +++ b/chromium/components/zucchini/zucchini_gen.h @@ -7,10 +7,10 @@ #include <vector> -#include "base/optional.h" #include "components/zucchini/buffer_view.h" #include "components/zucchini/image_utils.h" #include "components/zucchini/zucchini.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace zucchini { |