Mathieu Chartier | cf76bf8 | 2017-09-25 16:22:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 "compact_dex_file.h" |
| 18 | |
Mathieu Chartier | 698ebbc | 2018-01-05 11:00:42 -0800 | [diff] [blame] | 19 | #include "code_item_accessors-no_art-inl.h" |
Mathieu Chartier | 6238c83 | 2018-01-04 09:55:13 -0800 | [diff] [blame] | 20 | #include "dex_file-inl.h" |
| 21 | #include "leb128.h" |
| 22 | |
Mathieu Chartier | cf76bf8 | 2017-09-25 16:22:36 -0700 | [diff] [blame] | 23 | namespace art { |
| 24 | |
| 25 | constexpr uint8_t CompactDexFile::kDexMagic[kDexMagicSize]; |
| 26 | constexpr uint8_t CompactDexFile::kDexMagicVersion[]; |
| 27 | |
Mathieu Chartier | 603ccab | 2017-10-20 14:34:28 -0700 | [diff] [blame] | 28 | void CompactDexFile::WriteMagic(uint8_t* magic) { |
| 29 | std::copy_n(kDexMagic, kDexMagicSize, magic); |
| 30 | } |
| 31 | |
| 32 | void CompactDexFile::WriteCurrentVersion(uint8_t* magic) { |
| 33 | std::copy_n(kDexMagicVersion, kDexVersionLen, magic + kDexMagicSize); |
| 34 | } |
| 35 | |
Mathieu Chartier | cf76bf8 | 2017-09-25 16:22:36 -0700 | [diff] [blame] | 36 | bool CompactDexFile::IsMagicValid(const uint8_t* magic) { |
| 37 | return (memcmp(magic, kDexMagic, sizeof(kDexMagic)) == 0); |
| 38 | } |
| 39 | |
| 40 | bool CompactDexFile::IsVersionValid(const uint8_t* magic) { |
| 41 | const uint8_t* version = &magic[sizeof(kDexMagic)]; |
| 42 | return memcmp(version, kDexMagicVersion, kDexVersionLen) == 0; |
| 43 | } |
| 44 | |
| 45 | bool CompactDexFile::IsMagicValid() const { |
| 46 | return IsMagicValid(header_->magic_); |
| 47 | } |
| 48 | |
| 49 | bool CompactDexFile::IsVersionValid() const { |
| 50 | return IsVersionValid(header_->magic_); |
| 51 | } |
| 52 | |
Mathieu Chartier | f6e3147 | 2017-12-28 13:32:08 -0800 | [diff] [blame] | 53 | bool CompactDexFile::SupportsDefaultMethods() const { |
| 54 | return (GetHeader().GetFeatureFlags() & |
| 55 | static_cast<uint32_t>(FeatureFlags::kDefaultMethods)) != 0; |
| 56 | } |
| 57 | |
Mathieu Chartier | 6238c83 | 2018-01-04 09:55:13 -0800 | [diff] [blame] | 58 | uint32_t CompactDexFile::GetCodeItemSize(const DexFile::CodeItem& item) const { |
| 59 | // TODO: Clean up this temporary code duplication with StandardDexFile. Eventually the |
| 60 | // implementations will differ. |
| 61 | DCHECK(HasAddress(&item)); |
Mathieu Chartier | 698ebbc | 2018-01-05 11:00:42 -0800 | [diff] [blame] | 62 | return reinterpret_cast<uintptr_t>(CodeItemDataAccessor(*this, &item).CodeItemDataEnd()) - |
| 63 | reinterpret_cast<uintptr_t>(&item); |
Mathieu Chartier | 6238c83 | 2018-01-04 09:55:13 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Mathieu Chartier | 8892c6b | 2018-01-09 15:10:17 -0800 | [diff] [blame] | 66 | CompactDexFile::CompactDexFile(const uint8_t* base, |
| 67 | size_t size, |
| 68 | const std::string& location, |
| 69 | uint32_t location_checksum, |
| 70 | const OatDexFile* oat_dex_file, |
| 71 | DexFileContainer* container) |
| 72 | : DexFile(base, |
| 73 | size, |
| 74 | location, |
| 75 | location_checksum, |
| 76 | oat_dex_file, |
| 77 | container, |
| 78 | /*is_compact_dex*/ true), |
| 79 | debug_info_offsets_(Begin() + GetHeader().debug_info_offsets_pos_, |
| 80 | GetHeader().debug_info_base_, |
| 81 | GetHeader().debug_info_offsets_table_offset_) {} |
| 82 | |
Mathieu Chartier | cf76bf8 | 2017-09-25 16:22:36 -0700 | [diff] [blame] | 83 | } // namespace art |