summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dex2oat/linker/oat_writer.cc24
-rw-r--r--libdexfile/dex/dex_file_loader.cc12
-rw-r--r--libdexfile/dex/dex_file_loader.h20
-rw-r--r--libdexfile/external/dex_file_ext.cc11
-rw-r--r--runtime/oat_file.cc12
-rw-r--r--runtime/vdex_file.cc12
6 files changed, 48 insertions, 43 deletions
diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc
index 6125ccbc22..a3efc4ac00 100644
--- a/dex2oat/linker/oat_writer.cc
+++ b/dex2oat/linker/oat_writer.cc
@@ -467,12 +467,12 @@ bool OatWriter::AddRawDexFileSource(std::shared_ptr<DexFileContainer> container,
ArtDexFileLoader loader(container->Begin(), container->Size(), location);
CHECK_GE(dex_file_begin, container->Begin());
CHECK_LE(dex_file_begin, container->End());
- auto dex_file = loader.Open(dex_file_begin - container->Begin(),
- location_checksum,
- nullptr,
- /*verify=*/false,
- /*verify_checksum=*/false,
- &error_msg);
+ auto dex_file = loader.OpenOne(dex_file_begin - container->Begin(),
+ location_checksum,
+ nullptr,
+ /*verify=*/false,
+ /*verify_checksum=*/false,
+ &error_msg);
if (dex_file == nullptr) {
LOG(ERROR) << "Failed to open dex file '" << location << "': " << error_msg;
return false;
@@ -3435,12 +3435,12 @@ bool OatWriter::OpenDexFiles(
std::string error_msg;
ArtDexFileLoader dex_file_loader(dex_container, oat_dex_file.GetLocation());
// All dex files have been already verified in WriteDexFiles before we copied them.
- dex_files.emplace_back(dex_file_loader.Open(oat_dex_file.dex_file_offset_,
- oat_dex_file.dex_file_location_checksum_,
- /*oat_dex_file=*/nullptr,
- /*verify=*/false,
- /*verify_checksum=*/false,
- &error_msg));
+ dex_files.emplace_back(dex_file_loader.OpenOne(oat_dex_file.dex_file_offset_,
+ oat_dex_file.dex_file_location_checksum_,
+ /*oat_dex_file=*/nullptr,
+ /*verify=*/false,
+ /*verify_checksum=*/false,
+ &error_msg));
if (dex_files.back() == nullptr) {
LOG(ERROR) << "Failed to open dex file from oat file. File: " << oat_dex_file.GetLocation()
<< " Error: " << error_msg;
diff --git a/libdexfile/dex/dex_file_loader.cc b/libdexfile/dex/dex_file_loader.cc
index 2fdb16eada..daefa2f0dd 100644
--- a/libdexfile/dex/dex_file_loader.cc
+++ b/libdexfile/dex/dex_file_loader.cc
@@ -256,12 +256,12 @@ DexFileLoader::DexFileLoader(std::vector<uint8_t>&& memory, const std::string& l
DexFileLoader::DexFileLoader(MemMap&& mem_map, const std::string& location)
: DexFileLoader(std::make_shared<MemMapContainer>(std::move(mem_map)), location) {}
-std::unique_ptr<const DexFile> DexFileLoader::Open(size_t header_offset,
- uint32_t location_checksum,
- const OatDexFile* oat_dex_file,
- bool verify,
- bool verify_checksum,
- std::string* error_msg) {
+std::unique_ptr<const DexFile> DexFileLoader::OpenOne(size_t header_offset,
+ uint32_t location_checksum,
+ const OatDexFile* oat_dex_file,
+ bool verify,
+ bool verify_checksum,
+ std::string* error_msg) {
DEXFILE_SCOPED_TRACE(std::string("Open dex file ") + location_);
uint32_t magic;
diff --git a/libdexfile/dex/dex_file_loader.h b/libdexfile/dex/dex_file_loader.h
index f912053d8b..6530303542 100644
--- a/libdexfile/dex/dex_file_loader.h
+++ b/libdexfile/dex/dex_file_loader.h
@@ -187,19 +187,23 @@ class DexFileLoader {
virtual ~DexFileLoader() {}
- std::unique_ptr<const DexFile> Open(size_t header_offset,
- uint32_t location_checksum,
- const OatDexFile* oat_dex_file,
- bool verify,
- bool verify_checksum,
- std::string* error_msg);
-
+ // Open singe dex file at the given offset within the container (usually 0).
+ // This intentionally ignores all other dex files in the container
+ std::unique_ptr<const DexFile> OpenOne(size_t header_offset,
+ uint32_t location_checksum,
+ const OatDexFile* oat_dex_file,
+ bool verify,
+ bool verify_checksum,
+ std::string* error_msg);
+
+ // Open single dex file (starting at offset 0 of the container).
+ // It expects only single dex file to be present and will fail otherwise.
std::unique_ptr<const DexFile> Open(uint32_t location_checksum,
const OatDexFile* oat_dex_file,
bool verify,
bool verify_checksum,
std::string* error_msg) {
- std::unique_ptr<const DexFile> dex_file = Open(
+ std::unique_ptr<const DexFile> dex_file = OpenOne(
/*header_offset=*/0, location_checksum, oat_dex_file, verify, verify_checksum, error_msg);
// This API returns only singe DEX file, so check there is just single dex in the container.
CHECK(dex_file == nullptr || dex_file->IsDexContainerLastEntry()) << location_;
diff --git a/libdexfile/external/dex_file_ext.cc b/libdexfile/external/dex_file_ext.cc
index 5a6dc219cb..3a511ea1c9 100644
--- a/libdexfile/external/dex_file_ext.cc
+++ b/libdexfile/external/dex_file_ext.cc
@@ -192,11 +192,12 @@ ADexFile_Error ADexFile_create(const void* _Nonnull address,
std::string loc_str(location);
std::string error_msg;
art::DexFileLoader loader(static_cast<const uint8_t*>(address), full_size, loc_str);
- std::unique_ptr<const art::DexFile> dex_file = loader.Open(header->checksum_,
- /*oat_dex_file=*/nullptr,
- /*verify=*/false,
- /*verify_checksum=*/false,
- &error_msg);
+ std::unique_ptr<const art::DexFile> dex_file = loader.OpenOne(/*header_offset=*/0,
+ header->checksum_,
+ /*oat_dex_file=*/nullptr,
+ /*verify=*/false,
+ /*verify_checksum=*/false,
+ &error_msg);
if (dex_file == nullptr) {
LOG(ERROR) << "Can not open dex file " << loc_str << ": " << error_msg;
return ADEXFILE_ERROR_INVALID_DEX;
diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc
index 6addf25b99..c4c6dca9f3 100644
--- a/runtime/oat_file.cc
+++ b/runtime/oat_file.cc
@@ -2280,12 +2280,12 @@ std::unique_ptr<const DexFile> OatDexFile::OpenDexFile(std::string* error_msg) c
static constexpr bool kVerify = false;
static constexpr bool kVerifyChecksum = false;
ArtDexFileLoader dex_file_loader(dex_file_container_, dex_file_location_);
- return dex_file_loader.Open(dex_file_pointer_ - dex_file_container_->Begin(),
- dex_file_location_checksum_,
- this,
- kVerify,
- kVerifyChecksum,
- error_msg);
+ return dex_file_loader.OpenOne(dex_file_pointer_ - dex_file_container_->Begin(),
+ dex_file_location_checksum_,
+ this,
+ kVerify,
+ kVerifyChecksum,
+ error_msg);
}
uint32_t OatDexFile::GetOatClassOffset(uint16_t class_def_index) const {
diff --git a/runtime/vdex_file.cc b/runtime/vdex_file.cc
index 868e5e56bd..2dc925f7a2 100644
--- a/runtime/vdex_file.cc
+++ b/runtime/vdex_file.cc
@@ -223,12 +223,12 @@ bool VdexFile::OpenAllDexFiles(std::vector<std::unique_ptr<const DexFile>>* dex_
static constexpr char kVdexLocation[] = "";
std::string location = DexFileLoader::GetMultiDexLocation(i, kVdexLocation);
ArtDexFileLoader dex_file_loader(dex_file_container, location);
- std::unique_ptr<const DexFile> dex(dex_file_loader.Open(dex_file_start - Begin(),
- GetLocationChecksum(i),
- /*oat_dex_file=*/nullptr,
- /*verify=*/false,
- /*verify_checksum=*/false,
- error_msg));
+ std::unique_ptr<const DexFile> dex(dex_file_loader.OpenOne(dex_file_start - Begin(),
+ GetLocationChecksum(i),
+ /*oat_dex_file=*/nullptr,
+ /*verify=*/false,
+ /*verify_checksum=*/false,
+ error_msg));
if (dex == nullptr) {
return false;
}