David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 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 | #ifndef ART_RUNTIME_VDEX_FILE_H_ |
| 18 | #define ART_RUNTIME_VDEX_FILE_H_ |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <string> |
| 22 | |
Nicolas Geoffray | e70dd56 | 2016-10-30 21:03:35 +0000 | [diff] [blame] | 23 | #include "base/array_ref.h" |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 24 | #include "base/macros.h" |
David Sehr | 79e2607 | 2018-04-06 17:58:50 -0700 | [diff] [blame] | 25 | #include "base/mem_map.h" |
David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 26 | #include "base/os.h" |
Nicolas Geoffray | 6df4511 | 2021-02-07 21:51:58 +0000 | [diff] [blame] | 27 | #include "class_status.h" |
Mathieu Chartier | 2daa134 | 2018-02-20 16:19:28 -0800 | [diff] [blame] | 28 | #include "dex/compact_offset_table.h" |
David Brazdil | 35a3f6a | 2019-03-04 15:59:06 +0000 | [diff] [blame] | 29 | #include "dex/dex_file.h" |
Mathieu Chartier | 210531f | 2018-01-12 10:15:51 -0800 | [diff] [blame] | 30 | #include "quicken_info.h" |
Nicolas Geoffray | 6df4511 | 2021-02-07 21:51:58 +0000 | [diff] [blame] | 31 | #include "handle.h" |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 32 | |
| 33 | namespace art { |
| 34 | |
David Brazdil | 35a3f6a | 2019-03-04 15:59:06 +0000 | [diff] [blame] | 35 | class ClassLoaderContext; |
Nicolas Geoffray | 6df4511 | 2021-02-07 21:51:58 +0000 | [diff] [blame] | 36 | class Thread; |
| 37 | |
| 38 | namespace mirror { |
| 39 | class Class; |
| 40 | } |
David Brazdil | 35a3f6a | 2019-03-04 15:59:06 +0000 | [diff] [blame] | 41 | |
| 42 | namespace verifier { |
| 43 | class VerifierDeps; |
| 44 | } // namespace verifier |
David Sehr | beca4fe | 2017-03-30 17:50:24 -0700 | [diff] [blame] | 45 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 46 | // VDEX files contain extracted DEX files. The VdexFile class maps the file to |
| 47 | // memory and provides tools for accessing its individual sections. |
| 48 | // |
Nicolas Geoffray | 07b62e3 | 2020-11-07 15:54:08 +0000 | [diff] [blame] | 49 | // In the description below, D is the number of dex files. |
| 50 | // |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 51 | // File format: |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 52 | // VdexFileHeader fixed-length header |
| 53 | // VdexSectionHeader[kNumberOfSections] |
| 54 | // |
| 55 | // Checksum section |
| 56 | // VdexChecksum[D] |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 57 | // |
Nicolas Geoffray | 3a29355 | 2018-03-02 10:52:16 +0000 | [diff] [blame] | 58 | // Optionally: |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 59 | // DexSection |
| 60 | // DEX[0] array of the input DEX files |
| 61 | // DEX[1] |
| 62 | // ... |
| 63 | // DEX[D-1] |
Nicolas Geoffray | 3a29355 | 2018-03-02 10:52:16 +0000 | [diff] [blame] | 64 | // |
Nicolas Geoffray | b4c6acb | 2017-11-10 12:48:14 +0000 | [diff] [blame] | 65 | // VerifierDeps |
Nicolas Geoffray | 07b62e3 | 2020-11-07 15:54:08 +0000 | [diff] [blame] | 66 | // 4-byte alignment |
| 67 | // uint32[D] DexFileDeps offsets for each dex file |
| 68 | // DexFileDeps[D][] verification dependencies |
| 69 | // 4-byte alignment |
| 70 | // uint32[class_def_size] TypeAssignability offsets (kNotVerifiedMarker for a class |
| 71 | // that isn't verified) |
| 72 | // uint32 Offset of end of AssignabilityType sets |
| 73 | // uint8[] AssignabilityType sets |
| 74 | // 4-byte alignment |
| 75 | // uint32 Number of strings |
| 76 | // uint32[] String data offsets for each string |
| 77 | // uint8[] String data |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 78 | |
| 79 | |
| 80 | enum VdexSection : uint32_t { |
| 81 | kChecksumSection = 0, |
| 82 | kDexFileSection = 1, |
| 83 | kVerifierDepsSection = 2, |
Nicolas Geoffray | 0b94328 | 2021-04-16 09:16:00 +0000 | [diff] [blame] | 84 | kTypeLookupTableSection = 3, |
| 85 | kNumberOfSections = 4, |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 86 | }; |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 87 | |
| 88 | class VdexFile { |
| 89 | public: |
David Brazdil | 35a3f6a | 2019-03-04 15:59:06 +0000 | [diff] [blame] | 90 | using VdexChecksum = uint32_t; |
David Brazdil | 35a3f6a | 2019-03-04 15:59:06 +0000 | [diff] [blame] | 91 | |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 92 | struct VdexSectionHeader { |
| 93 | VdexSection section_kind; |
| 94 | uint32_t section_offset; |
| 95 | uint32_t section_size; |
| 96 | |
| 97 | VdexSectionHeader(VdexSection kind, uint32_t offset, uint32_t size) |
| 98 | : section_kind(kind), section_offset(offset), section_size(size) {} |
| 99 | |
| 100 | VdexSectionHeader() {} |
| 101 | }; |
| 102 | |
| 103 | struct VdexFileHeader { |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 104 | public: |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 105 | explicit VdexFileHeader(bool has_dex_section); |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 106 | |
Nicolas Geoffray | e70dd56 | 2016-10-30 21:03:35 +0000 | [diff] [blame] | 107 | const char* GetMagic() const { return reinterpret_cast<const char*>(magic_); } |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 108 | const char* GetVdexVersion() const { |
| 109 | return reinterpret_cast<const char*>(vdex_version_); |
David Brazdil | 93592f5 | 2017-12-08 10:53:27 +0000 | [diff] [blame] | 110 | } |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 111 | uint32_t GetNumberOfSections() const { |
| 112 | return number_of_sections_; |
Nicolas Geoffray | 3a29355 | 2018-03-02 10:52:16 +0000 | [diff] [blame] | 113 | } |
| 114 | bool IsMagicValid() const; |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 115 | bool IsVdexVersionValid() const; |
Nicolas Geoffray | 3a29355 | 2018-03-02 10:52:16 +0000 | [diff] [blame] | 116 | bool IsValid() const { |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 117 | return IsMagicValid() && IsVdexVersionValid(); |
David Brazdil | 35a3f6a | 2019-03-04 15:59:06 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Nicolas Geoffray | 36930ec | 2017-05-09 13:23:34 +0100 | [diff] [blame] | 120 | static constexpr uint8_t kVdexInvalidMagic[] = { 'w', 'd', 'e', 'x' }; |
| 121 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 122 | private: |
| 123 | static constexpr uint8_t kVdexMagic[] = { 'v', 'd', 'e', 'x' }; |
Nicolas Geoffray | 3a29355 | 2018-03-02 10:52:16 +0000 | [diff] [blame] | 124 | |
| 125 | // The format version of the verifier deps header and the verifier deps. |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 126 | // Last update: Introduce vdex sections. |
| 127 | static constexpr uint8_t kVdexVersion[] = { '0', '2', '7', '\0' }; |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 128 | |
| 129 | uint8_t magic_[4]; |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 130 | uint8_t vdex_version_[4]; |
| 131 | uint32_t number_of_sections_; |
Nicolas Geoffray | 3a29355 | 2018-03-02 10:52:16 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 134 | const VdexSectionHeader& GetSectionHeaderAt(uint32_t index) const { |
| 135 | DCHECK_LT(index, GetVdexFileHeader().GetNumberOfSections()); |
| 136 | return *reinterpret_cast<const VdexSectionHeader*>( |
| 137 | Begin() + sizeof(VdexFileHeader) + index * sizeof(VdexSectionHeader)); |
| 138 | } |
Nicolas Geoffray | 3a29355 | 2018-03-02 10:52:16 +0000 | [diff] [blame] | 139 | |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 140 | const VdexSectionHeader& GetSectionHeader(VdexSection kind) const { |
| 141 | return GetSectionHeaderAt(static_cast<uint32_t>(kind)); |
| 142 | } |
Nicolas Geoffray | 3a29355 | 2018-03-02 10:52:16 +0000 | [diff] [blame] | 143 | |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 144 | static size_t GetChecksumsOffset() { |
| 145 | return sizeof(VdexFileHeader) + |
| 146 | static_cast<size_t>(VdexSection::kNumberOfSections) * sizeof(VdexSectionHeader); |
| 147 | } |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 148 | |
Nicolas Geoffray | 3a29355 | 2018-03-02 10:52:16 +0000 | [diff] [blame] | 149 | size_t GetComputedFileSize() const { |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 150 | const VdexFileHeader& header = GetVdexFileHeader(); |
| 151 | uint32_t size = sizeof(VdexFileHeader) + |
| 152 | header.GetNumberOfSections() * sizeof(VdexSectionHeader); |
| 153 | for (uint32_t i = 0; i < header.GetNumberOfSections(); ++i) { |
| 154 | size = std::max(size, |
| 155 | GetSectionHeaderAt(i).section_offset + GetSectionHeaderAt(i).section_size); |
Nicolas Geoffray | 3a29355 | 2018-03-02 10:52:16 +0000 | [diff] [blame] | 156 | } |
| 157 | return size; |
| 158 | } |
| 159 | |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 160 | bool HasDexSection() const { |
| 161 | return GetSectionHeader(VdexSection::kDexFileSection).section_size != 0u; |
| 162 | } |
| 163 | uint32_t GetVerifierDepsSize() const { |
| 164 | return GetSectionHeader(VdexSection::kVerifierDepsSection).section_size; |
| 165 | } |
| 166 | uint32_t GetNumberOfDexFiles() const { |
| 167 | return GetSectionHeader(VdexSection::kChecksumSection).section_size / sizeof(VdexChecksum); |
| 168 | } |
| 169 | |
Nicolas Geoffray | 0b94328 | 2021-04-16 09:16:00 +0000 | [diff] [blame] | 170 | bool HasTypeLookupTableSection() const { |
| 171 | return GetVdexFileHeader().GetNumberOfSections() >= (kTypeLookupTableSection + 1); |
| 172 | } |
| 173 | |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 174 | const VdexChecksum* GetDexChecksumsArray() const { |
| 175 | return reinterpret_cast<const VdexChecksum*>( |
| 176 | Begin() + GetSectionHeader(VdexSection::kChecksumSection).section_offset); |
| 177 | } |
| 178 | |
| 179 | VdexChecksum GetDexChecksumAt(size_t idx) const { |
| 180 | DCHECK_LT(idx, GetNumberOfDexFiles()); |
| 181 | return GetDexChecksumsArray()[idx]; |
| 182 | } |
| 183 | |
Nicolas Geoffray | baeaa9b | 2018-01-26 14:31:17 +0000 | [diff] [blame] | 184 | // Note: The file is called "primary" to match the naming with profiles. |
| 185 | static const constexpr char* kVdexNameInDmFile = "primary.vdex"; |
| 186 | |
Vladimir Marko | c34bebf | 2018-08-16 16:12:49 +0100 | [diff] [blame] | 187 | explicit VdexFile(MemMap&& mmap) : mmap_(std::move(mmap)) {} |
Anestis Bechtsoudis | a1f56a8 | 2017-10-08 23:37:10 +0300 | [diff] [blame] | 188 | |
Richard Uhler | b8ab63a | 2017-01-31 11:27:37 +0000 | [diff] [blame] | 189 | // Returns nullptr if the vdex file cannot be opened or is not valid. |
David Srbecky | ec2cdf4 | 2017-12-08 16:21:25 +0000 | [diff] [blame] | 190 | // The mmap_* parameters can be left empty (nullptr/0/false) to allocate at random address. |
| 191 | static std::unique_ptr<VdexFile> OpenAtAddress(uint8_t* mmap_addr, |
| 192 | size_t mmap_size, |
| 193 | bool mmap_reuse, |
| 194 | const std::string& vdex_filename, |
| 195 | bool writable, |
| 196 | bool low_4gb, |
David Srbecky | ec2cdf4 | 2017-12-08 16:21:25 +0000 | [diff] [blame] | 197 | std::string* error_msg); |
| 198 | |
| 199 | // Returns nullptr if the vdex file cannot be opened or is not valid. |
| 200 | // The mmap_* parameters can be left empty (nullptr/0/false) to allocate at random address. |
| 201 | static std::unique_ptr<VdexFile> OpenAtAddress(uint8_t* mmap_addr, |
| 202 | size_t mmap_size, |
| 203 | bool mmap_reuse, |
| 204 | int file_fd, |
| 205 | size_t vdex_length, |
| 206 | const std::string& vdex_filename, |
| 207 | bool writable, |
| 208 | bool low_4gb, |
David Srbecky | ec2cdf4 | 2017-12-08 16:21:25 +0000 | [diff] [blame] | 209 | std::string* error_msg); |
| 210 | |
| 211 | // Returns nullptr if the vdex file cannot be opened or is not valid. |
Richard Uhler | b8ab63a | 2017-01-31 11:27:37 +0000 | [diff] [blame] | 212 | static std::unique_ptr<VdexFile> Open(const std::string& vdex_filename, |
| 213 | bool writable, |
| 214 | bool low_4gb, |
David Srbecky | ec2cdf4 | 2017-12-08 16:21:25 +0000 | [diff] [blame] | 215 | std::string* error_msg) { |
| 216 | return OpenAtAddress(nullptr, |
| 217 | 0, |
| 218 | false, |
| 219 | vdex_filename, |
| 220 | writable, |
| 221 | low_4gb, |
David Srbecky | ec2cdf4 | 2017-12-08 16:21:25 +0000 | [diff] [blame] | 222 | error_msg); |
| 223 | } |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 224 | |
Richard Uhler | b8ab63a | 2017-01-31 11:27:37 +0000 | [diff] [blame] | 225 | // Returns nullptr if the vdex file cannot be opened or is not valid. |
| 226 | static std::unique_ptr<VdexFile> Open(int file_fd, |
| 227 | size_t vdex_length, |
| 228 | const std::string& vdex_filename, |
| 229 | bool writable, |
| 230 | bool low_4gb, |
David Srbecky | ec2cdf4 | 2017-12-08 16:21:25 +0000 | [diff] [blame] | 231 | std::string* error_msg) { |
| 232 | return OpenAtAddress(nullptr, |
| 233 | 0, |
| 234 | false, |
| 235 | file_fd, |
| 236 | vdex_length, |
| 237 | vdex_filename, |
| 238 | writable, |
| 239 | low_4gb, |
David Srbecky | ec2cdf4 | 2017-12-08 16:21:25 +0000 | [diff] [blame] | 240 | error_msg); |
| 241 | } |
Nicolas Geoffray | b0bbe8e | 2016-11-19 10:42:37 +0000 | [diff] [blame] | 242 | |
Nicolas Geoffray | 327cfcf | 2021-10-12 14:13:25 +0100 | [diff] [blame] | 243 | static std::unique_ptr<VdexFile> OpenFromDm(const std::string& filename, |
| 244 | const ZipArchive& archive); |
| 245 | |
Vladimir Marko | c34bebf | 2018-08-16 16:12:49 +0100 | [diff] [blame] | 246 | const uint8_t* Begin() const { return mmap_.Begin(); } |
| 247 | const uint8_t* End() const { return mmap_.End(); } |
| 248 | size_t Size() const { return mmap_.Size(); } |
Nicolas Geoffray | a74a707 | 2021-09-09 17:06:46 +0100 | [diff] [blame] | 249 | bool Contains(const uint8_t* pointer) const { |
| 250 | return pointer >= Begin() && pointer < End(); |
| 251 | } |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 252 | |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 253 | const VdexFileHeader& GetVdexFileHeader() const { |
| 254 | return *reinterpret_cast<const VdexFileHeader*>(Begin()); |
Nicolas Geoffray | e70dd56 | 2016-10-30 21:03:35 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | ArrayRef<const uint8_t> GetVerifierDepsData() const { |
| 258 | return ArrayRef<const uint8_t>( |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 259 | Begin() + GetSectionHeader(VdexSection::kVerifierDepsSection).section_offset, |
| 260 | GetSectionHeader(VdexSection::kVerifierDepsSection).section_size); |
Nicolas Geoffray | b0bbe8e | 2016-11-19 10:42:37 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | bool IsValid() const { |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 264 | return mmap_.Size() >= sizeof(VdexFileHeader) && GetVdexFileHeader().IsValid(); |
Nicolas Geoffray | b0bbe8e | 2016-11-19 10:42:37 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | // This method is for iterating over the dex files in the vdex. If `cursor` is null, |
| 268 | // the first dex file is returned. If `cursor` is not null, it must point to a dex |
| 269 | // file and this method returns the next dex file if there is one, or null if there |
| 270 | // is none. |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 271 | const uint8_t* GetNextDexFileData(const uint8_t* cursor, uint32_t dex_file_index) const; |
Nicolas Geoffray | b0bbe8e | 2016-11-19 10:42:37 +0000 | [diff] [blame] | 272 | |
Nicolas Geoffray | 0b94328 | 2021-04-16 09:16:00 +0000 | [diff] [blame] | 273 | const uint8_t* GetNextTypeLookupTableData(const uint8_t* cursor, uint32_t dex_file_index) const; |
| 274 | |
Nicolas Geoffray | f54e5df | 2016-12-01 10:45:08 +0000 | [diff] [blame] | 275 | // Get the location checksum of the dex file number `dex_file_index`. |
| 276 | uint32_t GetLocationChecksum(uint32_t dex_file_index) const { |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 277 | DCHECK_LT(dex_file_index, GetNumberOfDexFiles()); |
| 278 | return GetDexChecksumAt(dex_file_index); |
Nicolas Geoffray | f54e5df | 2016-12-01 10:45:08 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Nicolas Geoffray | b02ba93 | 2017-07-13 15:53:54 +0100 | [diff] [blame] | 281 | // Open all the dex files contained in this vdex file. |
David Sehr | beca4fe | 2017-03-30 17:50:24 -0700 | [diff] [blame] | 282 | bool OpenAllDexFiles(std::vector<std::unique_ptr<const DexFile>>* dex_files, |
Alex Light | abd8f05 | 2019-12-06 10:49:17 -0800 | [diff] [blame] | 283 | std::string* error_msg) const; |
David Sehr | beca4fe | 2017-03-30 17:50:24 -0700 | [diff] [blame] | 284 | |
David Brazdil | 35a3f6a | 2019-03-04 15:59:06 +0000 | [diff] [blame] | 285 | // Writes a vdex into `path` and returns true on success. |
| 286 | // The vdex will not contain a dex section but will store checksums of `dex_files`, |
| 287 | // encoded `verifier_deps`, as well as the current boot class path cheksum and |
| 288 | // encoded `class_loader_context`. |
| 289 | static bool WriteToDisk(const std::string& path, |
| 290 | const std::vector<const DexFile*>& dex_files, |
| 291 | const verifier::VerifierDeps& verifier_deps, |
David Brazdil | 35a3f6a | 2019-03-04 15:59:06 +0000 | [diff] [blame] | 292 | std::string* error_msg); |
| 293 | |
David Brazdil | 7126c5b | 2019-03-05 00:02:51 +0000 | [diff] [blame] | 294 | // Returns true if the dex file checksums stored in the vdex header match |
| 295 | // the checksums in `dex_headers`. Both the number of dex files and their |
| 296 | // order must match too. |
| 297 | bool MatchesDexFileChecksums(const std::vector<const DexFile::Header*>& dex_headers) const; |
| 298 | |
Nicolas Geoffray | 6df4511 | 2021-02-07 21:51:58 +0000 | [diff] [blame] | 299 | ClassStatus ComputeClassStatus(Thread* self, Handle<mirror::Class> cls) const |
| 300 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 301 | |
Nicolas Geoffray | 16f60dc | 2021-02-16 15:35:16 +0000 | [diff] [blame] | 302 | // Return the name of the underlying `MemMap` of the vdex file, typically the |
| 303 | // location on disk of the vdex file. |
| 304 | const std::string& GetName() const { |
| 305 | return mmap_.GetName(); |
| 306 | } |
| 307 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 308 | private: |
Mathieu Chartier | 210531f | 2018-01-12 10:15:51 -0800 | [diff] [blame] | 309 | bool ContainsDexFile(const DexFile& dex_file) const; |
| 310 | |
Nicolas Geoffray | b0bbe8e | 2016-11-19 10:42:37 +0000 | [diff] [blame] | 311 | const uint8_t* DexBegin() const { |
Nicolas Geoffray | 3a29355 | 2018-03-02 10:52:16 +0000 | [diff] [blame] | 312 | DCHECK(HasDexSection()); |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 313 | return Begin() + GetSectionHeader(VdexSection::kDexFileSection).section_offset; |
Nicolas Geoffray | b0bbe8e | 2016-11-19 10:42:37 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Nicolas Geoffray | 0b94328 | 2021-04-16 09:16:00 +0000 | [diff] [blame] | 316 | const uint8_t* TypeLookupTableDataBegin() const { |
| 317 | DCHECK(HasTypeLookupTableSection()); |
| 318 | return Begin() + GetSectionHeader(VdexSection::kTypeLookupTableSection).section_offset; |
| 319 | } |
| 320 | |
Nicolas Geoffray | a129d8a | 2021-03-18 22:23:04 +0000 | [diff] [blame] | 321 | MemMap mmap_; |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 322 | |
| 323 | DISALLOW_COPY_AND_ASSIGN(VdexFile); |
| 324 | }; |
| 325 | |
| 326 | } // namespace art |
| 327 | |
| 328 | #endif // ART_RUNTIME_VDEX_FILE_H_ |