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 | #ifndef ART_RUNTIME_CDEX_COMPACT_DEX_FILE_H_ |
| 18 | #define ART_RUNTIME_CDEX_COMPACT_DEX_FILE_H_ |
| 19 | |
| 20 | #include "dex_file.h" |
| 21 | |
| 22 | namespace art { |
| 23 | |
| 24 | // CompactDex is a currently ART internal dex file format that aims to reduce storage/RAM usage. |
| 25 | class CompactDexFile : public DexFile { |
| 26 | public: |
| 27 | static constexpr uint8_t kDexMagic[kDexMagicSize] = { 'c', 'd', 'e', 'x' }; |
| 28 | static constexpr uint8_t kDexMagicVersion[] = {'0', '0', '1', '\0'}; |
| 29 | |
Mathieu Chartier | 603ccab | 2017-10-20 14:34:28 -0700 | [diff] [blame^] | 30 | // Write the compact dex specific magic. |
| 31 | static void WriteMagic(uint8_t* magic); |
| 32 | |
| 33 | // Write the current version, note that the input is the address of the magic. |
| 34 | static void WriteCurrentVersion(uint8_t* magic); |
| 35 | |
Mathieu Chartier | cf76bf8 | 2017-09-25 16:22:36 -0700 | [diff] [blame] | 36 | // Returns true if the byte string points to the magic value. |
| 37 | static bool IsMagicValid(const uint8_t* magic); |
| 38 | virtual bool IsMagicValid() const OVERRIDE; |
| 39 | |
| 40 | // Returns true if the byte string after the magic is the correct value. |
| 41 | static bool IsVersionValid(const uint8_t* magic); |
| 42 | virtual bool IsVersionValid() const OVERRIDE; |
| 43 | |
Mathieu Chartier | 603ccab | 2017-10-20 14:34:28 -0700 | [diff] [blame^] | 44 | bool IsCompactDexFile() const OVERRIDE { |
| 45 | return true; |
| 46 | } |
| 47 | |
Mathieu Chartier | cf76bf8 | 2017-09-25 16:22:36 -0700 | [diff] [blame] | 48 | private: |
| 49 | // Not supported yet. |
| 50 | CompactDexFile(const uint8_t* base, |
| 51 | size_t size, |
| 52 | const std::string& location, |
| 53 | uint32_t location_checksum, |
| 54 | const OatDexFile* oat_dex_file) |
| 55 | : DexFile(base, size, location, location_checksum, oat_dex_file) {} |
| 56 | |
| 57 | friend class DexFile; |
Mathieu Chartier | 603ccab | 2017-10-20 14:34:28 -0700 | [diff] [blame^] | 58 | friend class DexFileLoader; |
Mathieu Chartier | cf76bf8 | 2017-09-25 16:22:36 -0700 | [diff] [blame] | 59 | |
| 60 | DISALLOW_COPY_AND_ASSIGN(CompactDexFile); |
| 61 | }; |
| 62 | |
| 63 | } // namespace art |
| 64 | |
| 65 | #endif // ART_RUNTIME_CDEX_COMPACT_DEX_FILE_H_ |