1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "vdex_file.h"
18 
19 #include <sys/mman.h>  // For the PROT_* and MAP_* constants.
20 #include <sys/stat.h>  // for mkdir()
21 
22 #include <memory>
23 #include <unordered_set>
24 
25 #include <android-base/logging.h>
26 
27 #include "base/bit_utils.h"
28 #include "base/leb128.h"
29 #include "base/stl_util.h"
30 #include "base/systrace.h"
31 #include "base/unix_file/fd_file.h"
32 #include "class_linker.h"
33 #include "class_loader_context.h"
34 #include "dex/art_dex_file_loader.h"
35 #include "dex/class_accessor-inl.h"
36 #include "dex/dex_file_loader.h"
37 #include "dex_to_dex_decompiler.h"
38 #include "gc/heap.h"
39 #include "gc/space/image_space.h"
40 #include "quicken_info.h"
41 #include "runtime.h"
42 #include "verifier/verifier_deps.h"
43 
44 namespace art {
45 
46 constexpr uint8_t VdexFile::VerifierDepsHeader::kVdexInvalidMagic[4];
47 constexpr uint8_t VdexFile::VerifierDepsHeader::kVdexMagic[4];
48 constexpr uint8_t VdexFile::VerifierDepsHeader::kVerifierDepsVersion[4];
49 constexpr uint8_t VdexFile::VerifierDepsHeader::kDexSectionVersion[4];
50 constexpr uint8_t VdexFile::VerifierDepsHeader::kDexSectionVersionEmpty[4];
51 
IsMagicValid() const52 bool VdexFile::VerifierDepsHeader::IsMagicValid() const {
53   return (memcmp(magic_, kVdexMagic, sizeof(kVdexMagic)) == 0);
54 }
55 
IsVerifierDepsVersionValid() const56 bool VdexFile::VerifierDepsHeader::IsVerifierDepsVersionValid() const {
57   return (memcmp(verifier_deps_version_, kVerifierDepsVersion, sizeof(kVerifierDepsVersion)) == 0);
58 }
59 
IsDexSectionVersionValid() const60 bool VdexFile::VerifierDepsHeader::IsDexSectionVersionValid() const {
61   return (memcmp(dex_section_version_, kDexSectionVersion, sizeof(kDexSectionVersion)) == 0) ||
62       (memcmp(dex_section_version_, kDexSectionVersionEmpty, sizeof(kDexSectionVersionEmpty)) == 0);
63 }
64 
HasDexSection() const65 bool VdexFile::VerifierDepsHeader::HasDexSection() const {
66   return (memcmp(dex_section_version_, kDexSectionVersion, sizeof(kDexSectionVersion)) == 0);
67 }
68 
VerifierDepsHeader(uint32_t number_of_dex_files,uint32_t verifier_deps_size,bool has_dex_section,uint32_t bootclasspath_checksums_size,uint32_t class_loader_context_size)69 VdexFile::VerifierDepsHeader::VerifierDepsHeader(uint32_t number_of_dex_files,
70                                                  uint32_t verifier_deps_size,
71                                                  bool has_dex_section,
72                                                  uint32_t bootclasspath_checksums_size,
73                                                  uint32_t class_loader_context_size)
74     : number_of_dex_files_(number_of_dex_files),
75       verifier_deps_size_(verifier_deps_size),
76       bootclasspath_checksums_size_(bootclasspath_checksums_size),
77       class_loader_context_size_(class_loader_context_size) {
78   memcpy(magic_, kVdexMagic, sizeof(kVdexMagic));
79   memcpy(verifier_deps_version_, kVerifierDepsVersion, sizeof(kVerifierDepsVersion));
80   if (has_dex_section) {
81     memcpy(dex_section_version_, kDexSectionVersion, sizeof(kDexSectionVersion));
82   } else {
83     memcpy(dex_section_version_, kDexSectionVersionEmpty, sizeof(kDexSectionVersionEmpty));
84   }
85   DCHECK(IsMagicValid());
86   DCHECK(IsVerifierDepsVersionValid());
87   DCHECK(IsDexSectionVersionValid());
88 }
89 
DexSectionHeader(uint32_t dex_size,uint32_t dex_shared_data_size,uint32_t quickening_info_size)90 VdexFile::DexSectionHeader::DexSectionHeader(uint32_t dex_size,
91                                              uint32_t dex_shared_data_size,
92                                              uint32_t quickening_info_size)
93     : dex_size_(dex_size),
94       dex_shared_data_size_(dex_shared_data_size),
95       quickening_info_size_(quickening_info_size) {
96 }
97 
OpenAtAddress(uint8_t * mmap_addr,size_t mmap_size,bool mmap_reuse,const std::string & vdex_filename,bool writable,bool low_4gb,bool unquicken,std::string * error_msg)98 std::unique_ptr<VdexFile> VdexFile::OpenAtAddress(uint8_t* mmap_addr,
99                                                   size_t mmap_size,
100                                                   bool mmap_reuse,
101                                                   const std::string& vdex_filename,
102                                                   bool writable,
103                                                   bool low_4gb,
104                                                   bool unquicken,
105                                                   std::string* error_msg) {
106   ScopedTrace trace(("VdexFile::OpenAtAddress " + vdex_filename).c_str());
107   if (!OS::FileExists(vdex_filename.c_str())) {
108     *error_msg = "File " + vdex_filename + " does not exist.";
109     return nullptr;
110   }
111 
112   std::unique_ptr<File> vdex_file;
113   if (writable) {
114     vdex_file.reset(OS::OpenFileReadWrite(vdex_filename.c_str()));
115   } else {
116     vdex_file.reset(OS::OpenFileForReading(vdex_filename.c_str()));
117   }
118   if (vdex_file == nullptr) {
119     *error_msg = "Could not open file " + vdex_filename +
120                  (writable ? " for read/write" : "for reading");
121     return nullptr;
122   }
123 
124   int64_t vdex_length = vdex_file->GetLength();
125   if (vdex_length == -1) {
126     *error_msg = "Could not read the length of file " + vdex_filename;
127     return nullptr;
128   }
129 
130   return OpenAtAddress(mmap_addr,
131                        mmap_size,
132                        mmap_reuse,
133                        vdex_file->Fd(),
134                        vdex_length,
135                        vdex_filename,
136                        writable,
137                        low_4gb,
138                        unquicken,
139                        error_msg);
140 }
141 
OpenAtAddress(uint8_t * mmap_addr,size_t mmap_size,bool mmap_reuse,int file_fd,size_t vdex_length,const std::string & vdex_filename,bool writable,bool low_4gb,bool unquicken,std::string * error_msg)142 std::unique_ptr<VdexFile> VdexFile::OpenAtAddress(uint8_t* mmap_addr,
143                                                   size_t mmap_size,
144                                                   bool mmap_reuse,
145                                                   int file_fd,
146                                                   size_t vdex_length,
147                                                   const std::string& vdex_filename,
148                                                   bool writable,
149                                                   bool low_4gb,
150                                                   bool unquicken,
151                                                   std::string* error_msg) {
152   if (mmap_addr != nullptr && mmap_size < vdex_length) {
153     LOG(WARNING) << "Insufficient pre-allocated space to mmap vdex.";
154     mmap_addr = nullptr;
155     mmap_reuse = false;
156   }
157   CHECK(!mmap_reuse || mmap_addr != nullptr);
158   CHECK(!(writable && unquicken)) << "We don't want to be writing unquickened files out to disk!";
159   // Start as PROT_WRITE so we can mprotect back to it if we want to.
160   MemMap mmap = MemMap::MapFileAtAddress(
161       mmap_addr,
162       vdex_length,
163       PROT_READ | PROT_WRITE,
164       writable ? MAP_SHARED : MAP_PRIVATE,
165       file_fd,
166       /* start= */ 0u,
167       low_4gb,
168       vdex_filename.c_str(),
169       mmap_reuse,
170       /* reservation= */ nullptr,
171       error_msg);
172   if (!mmap.IsValid()) {
173     *error_msg = "Failed to mmap file " + vdex_filename + " : " + *error_msg;
174     return nullptr;
175   }
176 
177   std::unique_ptr<VdexFile> vdex(new VdexFile(std::move(mmap)));
178   if (!vdex->IsValid()) {
179     *error_msg = "Vdex file is not valid";
180     return nullptr;
181   }
182 
183   if (unquicken && vdex->HasDexSection()) {
184     std::vector<std::unique_ptr<const DexFile>> unique_ptr_dex_files;
185     if (!vdex->OpenAllDexFiles(&unique_ptr_dex_files, error_msg)) {
186       return nullptr;
187     }
188     // TODO: It would be nice to avoid doing the return-instruction stuff but then we end up not
189     // being able to tell if we need dequickening later. Instead just get rid of that too.
190     vdex->Unquicken(MakeNonOwningPointerVector(unique_ptr_dex_files),
191                     /* decompile_return_instruction= */ true);
192     // Update the quickening info size to pretend there isn't any.
193     size_t offset = vdex->GetDexSectionHeaderOffset();
194     reinterpret_cast<DexSectionHeader*>(vdex->mmap_.Begin() + offset)->quickening_info_size_ = 0;
195   }
196 
197   if (!writable) {
198     vdex->AllowWriting(false);
199   }
200 
201   return vdex;
202 }
203 
GetNextDexFileData(const uint8_t * cursor) const204 const uint8_t* VdexFile::GetNextDexFileData(const uint8_t* cursor) const {
205   DCHECK(cursor == nullptr || (cursor > Begin() && cursor <= End()));
206   if (cursor == nullptr) {
207     // Beginning of the iteration, return the first dex file if there is one.
208     return HasDexSection() ? DexBegin() + sizeof(QuickeningTableOffsetType) : nullptr;
209   } else {
210     // Fetch the next dex file. Return null if there is none.
211     const uint8_t* data = cursor + reinterpret_cast<const DexFile::Header*>(cursor)->file_size_;
212     // Dex files are required to be 4 byte aligned. the OatWriter makes sure they are, see
213     // OatWriter::SeekToDexFiles.
214     data = AlignUp(data, 4);
215 
216     return (data == DexEnd()) ? nullptr : data + sizeof(QuickeningTableOffsetType);
217   }
218 }
219 
AllowWriting(bool val) const220 void VdexFile::AllowWriting(bool val) const {
221   CHECK(mmap_.Protect(val ? (PROT_READ | PROT_WRITE) : PROT_READ));
222 }
223 
OpenAllDexFiles(std::vector<std::unique_ptr<const DexFile>> * dex_files,std::string * error_msg) const224 bool VdexFile::OpenAllDexFiles(std::vector<std::unique_ptr<const DexFile>>* dex_files,
225                                std::string* error_msg) const {
226   const ArtDexFileLoader dex_file_loader;
227   size_t i = 0;
228   for (const uint8_t* dex_file_start = GetNextDexFileData(nullptr);
229        dex_file_start != nullptr;
230        dex_file_start = GetNextDexFileData(dex_file_start), ++i) {
231     size_t size = reinterpret_cast<const DexFile::Header*>(dex_file_start)->file_size_;
232     // TODO: Supply the location information for a vdex file.
233     static constexpr char kVdexLocation[] = "";
234     std::string location = DexFileLoader::GetMultiDexLocation(i, kVdexLocation);
235     std::unique_ptr<const DexFile> dex(dex_file_loader.OpenWithDataSection(
236         dex_file_start,
237         size,
238         /*data_base=*/ nullptr,
239         /*data_size=*/ 0u,
240         location,
241         GetLocationChecksum(i),
242         /*oat_dex_file=*/ nullptr,
243         /*verify=*/ false,
244         /*verify_checksum=*/ false,
245         error_msg));
246     if (dex == nullptr) {
247       return false;
248     }
249     dex_files->push_back(std::move(dex));
250   }
251   return true;
252 }
253 
UnquickenInPlace(bool decompile_return_instruction) const254 void VdexFile::UnquickenInPlace(bool decompile_return_instruction) const {
255   CHECK_NE(mmap_.GetProtect() & PROT_WRITE, 0)
256       << "File not mapped writable. Cannot unquicken! " << mmap_;
257   if (HasDexSection()) {
258     std::vector<std::unique_ptr<const DexFile>> unique_ptr_dex_files;
259     std::string error_msg;
260     if (!OpenAllDexFiles(&unique_ptr_dex_files, &error_msg)) {
261       return;
262     }
263     Unquicken(MakeNonOwningPointerVector(unique_ptr_dex_files),
264               decompile_return_instruction);
265     // Update the quickening info size to pretend there isn't any.
266     size_t offset = GetDexSectionHeaderOffset();
267     reinterpret_cast<DexSectionHeader*>(mmap_.Begin() + offset)->quickening_info_size_ = 0;
268   }
269 }
270 
Unquicken(const std::vector<const DexFile * > & target_dex_files,bool decompile_return_instruction) const271 void VdexFile::Unquicken(const std::vector<const DexFile*>& target_dex_files,
272                          bool decompile_return_instruction) const {
273   const uint8_t* source_dex = GetNextDexFileData(nullptr);
274   for (const DexFile* target_dex : target_dex_files) {
275     UnquickenDexFile(*target_dex, source_dex, decompile_return_instruction);
276     source_dex = GetNextDexFileData(source_dex);
277   }
278   DCHECK(source_dex == nullptr);
279 }
280 
GetQuickeningInfoTableOffset(const uint8_t * source_dex_begin) const281 uint32_t VdexFile::GetQuickeningInfoTableOffset(const uint8_t* source_dex_begin) const {
282   DCHECK_GE(source_dex_begin, DexBegin());
283   DCHECK_LT(source_dex_begin, DexEnd());
284   return reinterpret_cast<const QuickeningTableOffsetType*>(source_dex_begin)[-1];
285 }
286 
GetQuickenInfoOffsetTable(const uint8_t * source_dex_begin,const ArrayRef<const uint8_t> & quickening_info) const287 CompactOffsetTable::Accessor VdexFile::GetQuickenInfoOffsetTable(
288     const uint8_t* source_dex_begin,
289     const ArrayRef<const uint8_t>& quickening_info) const {
290   // The offset a is in preheader right before the dex file.
291   const uint32_t offset = GetQuickeningInfoTableOffset(source_dex_begin);
292   return CompactOffsetTable::Accessor(quickening_info.SubArray(offset).data());
293 }
294 
GetQuickenInfoOffsetTable(const DexFile & dex_file,const ArrayRef<const uint8_t> & quickening_info) const295 CompactOffsetTable::Accessor VdexFile::GetQuickenInfoOffsetTable(
296     const DexFile& dex_file,
297     const ArrayRef<const uint8_t>& quickening_info) const {
298   return GetQuickenInfoOffsetTable(dex_file.Begin(), quickening_info);
299 }
300 
GetQuickeningInfoAt(const ArrayRef<const uint8_t> & quickening_info,uint32_t quickening_offset)301 static ArrayRef<const uint8_t> GetQuickeningInfoAt(const ArrayRef<const uint8_t>& quickening_info,
302                                                    uint32_t quickening_offset) {
303   // Subtract offset of one since 0 represents unused and cannot be in the table.
304   ArrayRef<const uint8_t> remaining = quickening_info.SubArray(quickening_offset - 1);
305   return remaining.SubArray(0u, QuickenInfoTable::SizeInBytes(remaining));
306 }
307 
UnquickenDexFile(const DexFile & target_dex_file,const DexFile & source_dex_file,bool decompile_return_instruction) const308 void VdexFile::UnquickenDexFile(const DexFile& target_dex_file,
309                                 const DexFile& source_dex_file,
310                                 bool decompile_return_instruction) const {
311   UnquickenDexFile(
312       target_dex_file, source_dex_file.Begin(), decompile_return_instruction);
313 }
314 
UnquickenDexFile(const DexFile & target_dex_file,const uint8_t * source_dex_begin,bool decompile_return_instruction) const315 void VdexFile::UnquickenDexFile(const DexFile& target_dex_file,
316                                 const uint8_t* source_dex_begin,
317                                 bool decompile_return_instruction) const {
318   ArrayRef<const uint8_t> quickening_info = GetQuickeningInfo();
319   if (quickening_info.empty()) {
320     // Bail early if there is no quickening info and no need to decompile. This means there is also
321     // no RETURN_VOID to decompile since the empty table takes a non zero amount of space.
322     return;
323   }
324   // Make sure to not unquicken the same code item multiple times.
325   std::unordered_set<const dex::CodeItem*> unquickened_code_item;
326   CompactOffsetTable::Accessor accessor(GetQuickenInfoOffsetTable(source_dex_begin,
327                                                                   quickening_info));
328   for (ClassAccessor class_accessor : target_dex_file.GetClasses()) {
329     for (const ClassAccessor::Method& method : class_accessor.GetMethods()) {
330       const dex::CodeItem* code_item = method.GetCodeItem();
331       if (code_item != nullptr && unquickened_code_item.emplace(code_item).second) {
332         const uint32_t offset = accessor.GetOffset(method.GetIndex());
333         // Offset being 0 means not quickened.
334         if (offset != 0u) {
335           ArrayRef<const uint8_t> quicken_data = GetQuickeningInfoAt(quickening_info, offset);
336           optimizer::ArtDecompileDEX(
337               target_dex_file,
338               *code_item,
339               quicken_data,
340               decompile_return_instruction);
341         }
342       }
343     }
344   }
345 }
346 
GetQuickenedInfoOf(const DexFile & dex_file,uint32_t dex_method_idx) const347 ArrayRef<const uint8_t> VdexFile::GetQuickenedInfoOf(const DexFile& dex_file,
348                                                      uint32_t dex_method_idx) const {
349   ArrayRef<const uint8_t> quickening_info = GetQuickeningInfo();
350   if (quickening_info.empty()) {
351     return ArrayRef<const uint8_t>();
352   }
353   CHECK_LT(dex_method_idx, dex_file.NumMethodIds());
354   const uint32_t quickening_offset =
355       GetQuickenInfoOffsetTable(dex_file, quickening_info).GetOffset(dex_method_idx);
356   if (quickening_offset == 0u) {
357     return ArrayRef<const uint8_t>();
358   }
359   return GetQuickeningInfoAt(quickening_info, quickening_offset);
360 }
361 
ComputeBootClassPathChecksumString()362 static std::string ComputeBootClassPathChecksumString() {
363   Runtime* const runtime = Runtime::Current();
364   // Do not include boot image extension checksums, use their dex file checksums instead. Unlike
365   // oat files, vdex files do not reference anything in image spaces, so there is no reason why
366   // loading or not loading a boot image extension would affect the validity of the vdex file.
367   // Note: Update of a boot class path module such as conscrypt invalidates the vdex file anyway.
368   ArrayRef<gc::space::ImageSpace* const> image_spaces(runtime->GetHeap()->GetBootImageSpaces());
369   size_t boot_image_components =
370       image_spaces.empty() ? 0u : image_spaces[0]->GetImageHeader().GetComponentCount();
371   return gc::space::ImageSpace::GetBootClassPathChecksums(
372           image_spaces.SubArray(/*pos=*/ 0u, boot_image_components),
373           ArrayRef<const DexFile* const>(runtime->GetClassLinker()->GetBootClassPath()));
374 }
375 
CreateDirectories(const std::string & child_path,std::string * error_msg)376 static bool CreateDirectories(const std::string& child_path, /* out */ std::string* error_msg) {
377   size_t last_slash_pos = child_path.find_last_of('/');
378   CHECK_NE(last_slash_pos, std::string::npos) << "Invalid path: " << child_path;
379   std::string parent_path = child_path.substr(0, last_slash_pos);
380   if (OS::DirectoryExists(parent_path.c_str())) {
381     return true;
382   } else if (CreateDirectories(parent_path, error_msg)) {
383     if (mkdir(parent_path.c_str(), 0700) == 0) {
384       return true;
385     }
386     *error_msg = "Could not create directory " + parent_path;
387     return false;
388   } else {
389     return false;
390   }
391 }
392 
WriteToDisk(const std::string & path,const std::vector<const DexFile * > & dex_files,const verifier::VerifierDeps & verifier_deps,const std::string & class_loader_context,std::string * error_msg)393 bool VdexFile::WriteToDisk(const std::string& path,
394                            const std::vector<const DexFile*>& dex_files,
395                            const verifier::VerifierDeps& verifier_deps,
396                            const std::string& class_loader_context,
397                            std::string* error_msg) {
398   std::vector<uint8_t> verifier_deps_data;
399   verifier_deps.Encode(dex_files, &verifier_deps_data);
400 
401   std::string boot_checksum = ComputeBootClassPathChecksumString();
402   DCHECK_NE(boot_checksum, "");
403 
404   VdexFile::VerifierDepsHeader deps_header(dex_files.size(),
405                                            verifier_deps_data.size(),
406                                            /* has_dex_section= */ false,
407                                            boot_checksum.size(),
408                                            class_loader_context.size());
409 
410   if (!CreateDirectories(path, error_msg)) {
411     return false;
412   }
413 
414   std::unique_ptr<File> out(OS::CreateEmptyFileWriteOnly(path.c_str()));
415   if (out == nullptr) {
416     *error_msg = "Could not open " + path + " for writing";
417     return false;
418   }
419 
420   if (!out->WriteFully(reinterpret_cast<const char*>(&deps_header), sizeof(deps_header))) {
421     *error_msg = "Could not write vdex header to " + path;
422     out->Unlink();
423     return false;
424   }
425 
426   for (const DexFile* dex_file : dex_files) {
427     const uint32_t* checksum_ptr = &dex_file->GetHeader().checksum_;
428     static_assert(sizeof(*checksum_ptr) == sizeof(VdexFile::VdexChecksum));
429     if (!out->WriteFully(reinterpret_cast<const char*>(checksum_ptr),
430                          sizeof(VdexFile::VdexChecksum))) {
431       *error_msg = "Could not write dex checksums to " + path;
432       out->Unlink();
433     return false;
434     }
435   }
436 
437   if (!out->WriteFully(reinterpret_cast<const char*>(verifier_deps_data.data()),
438                        verifier_deps_data.size())) {
439     *error_msg = "Could not write verifier deps to " + path;
440     out->Unlink();
441     return false;
442   }
443 
444   if (!out->WriteFully(boot_checksum.c_str(), boot_checksum.size())) {
445     *error_msg = "Could not write boot classpath checksum to " + path;
446     out->Unlink();
447     return false;
448   }
449 
450   if (!out->WriteFully(class_loader_context.c_str(), class_loader_context.size())) {
451     *error_msg = "Could not write class loader context to " + path;
452     out->Unlink();
453     return false;
454   }
455 
456   if (out->FlushClose() != 0) {
457     *error_msg = "Could not flush and close " + path;
458     out->Unlink();
459     return false;
460   }
461 
462   return true;
463 }
464 
MatchesDexFileChecksums(const std::vector<const DexFile::Header * > & dex_headers) const465 bool VdexFile::MatchesDexFileChecksums(const std::vector<const DexFile::Header*>& dex_headers)
466     const {
467   const VerifierDepsHeader& header = GetVerifierDepsHeader();
468   if (dex_headers.size() != header.GetNumberOfDexFiles()) {
469     LOG(WARNING) << "Mismatch of number of dex files in vdex (expected="
470         << header.GetNumberOfDexFiles() << ", actual=" << dex_headers.size() << ")";
471     return false;
472   }
473   const VdexChecksum* checksums = header.GetDexChecksumsArray();
474   for (size_t i = 0; i < dex_headers.size(); ++i) {
475     if (checksums[i] != dex_headers[i]->checksum_) {
476       LOG(WARNING) << "Mismatch of dex file checksum in vdex (index=" << i << ")";
477       return false;
478     }
479   }
480   return true;
481 }
482 
MatchesBootClassPathChecksums() const483 bool VdexFile::MatchesBootClassPathChecksums() const {
484   ArrayRef<const uint8_t> data = GetBootClassPathChecksumData();
485   std::string vdex(reinterpret_cast<const char*>(data.data()), data.size());
486   std::string runtime = ComputeBootClassPathChecksumString();
487   if (vdex == runtime) {
488     return true;
489   } else {
490     LOG(WARNING) << "Mismatch of boot class path checksum in vdex (expected="
491         << vdex << ", actual=" << runtime << ")";
492     return false;
493   }
494 }
495 
MatchesClassLoaderContext(const ClassLoaderContext & context) const496 bool VdexFile::MatchesClassLoaderContext(const ClassLoaderContext& context) const {
497   ArrayRef<const uint8_t> data = GetClassLoaderContextData();
498   std::string spec(reinterpret_cast<const char*>(data.data()), data.size());
499   ClassLoaderContext::VerificationResult result = context.VerifyClassLoaderContextMatch(spec);
500   if (result != ClassLoaderContext::VerificationResult::kMismatch) {
501     return true;
502   } else {
503     LOG(WARNING) << "Mismatch of class loader context in vdex (expected="
504         << spec << ", actual=" << context.EncodeContextForOatFile("") << ")";
505     return false;
506   }
507 }
508 
509 }  // namespace art
510