1 /* 2 * Copyright (C) 2011 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_IMAGE_H_ 18 #define ART_RUNTIME_IMAGE_H_ 19 20 #include <string.h> 21 22 #include "globals.h" 23 #include "mirror/object.h" 24 #include "utils.h" 25 26 namespace art { 27 28 // header of image files written by ImageWriter, read and validated by Space. 29 class PACKED(4) ImageHeader { 30 public: 31 ImageHeader() {} 32 33 ImageHeader(uint32_t image_begin, 34 uint32_t image_size_, 35 uint32_t image_bitmap_offset, 36 uint32_t image_bitmap_size, 37 uint32_t image_roots, 38 uint32_t oat_checksum, 39 uint32_t oat_file_begin, 40 uint32_t oat_data_begin, 41 uint32_t oat_data_end, 42 uint32_t oat_file_end); 43 44 bool IsValid() const; 45 const char* GetMagic() const; 46 47 byte* GetImageBegin() const { 48 return reinterpret_cast<byte*>(image_begin_); 49 } 50 51 size_t GetImageSize() const { 52 return static_cast<uint32_t>(image_size_); 53 } 54 55 size_t GetImageBitmapOffset() const { 56 return image_bitmap_offset_; 57 } 58 59 size_t GetImageBitmapSize() const { 60 return image_bitmap_size_; 61 } 62 63 uint32_t GetOatChecksum() const { 64 return oat_checksum_; 65 } 66 67 void SetOatChecksum(uint32_t oat_checksum) { 68 oat_checksum_ = oat_checksum; 69 } 70 71 byte* GetOatFileBegin() const { 72 return reinterpret_cast<byte*>(oat_file_begin_); 73 } 74 75 byte* GetOatDataBegin() const { 76 return reinterpret_cast<byte*>(oat_data_begin_); 77 } 78 79 byte* GetOatDataEnd() const { 80 return reinterpret_cast<byte*>(oat_data_end_); 81 } 82 83 byte* GetOatFileEnd() const { 84 return reinterpret_cast<byte*>(oat_file_end_); 85 } 86 87 size_t GetBitmapOffset() const { 88 return RoundUp(image_size_, kPageSize); 89 } 90 91 enum ImageRoot { 92 kResolutionMethod, 93 kCalleeSaveMethod, 94 kRefsOnlySaveMethod, 95 kRefsAndArgsSaveMethod, 96 kOatLocation, 97 kDexCaches, 98 kClassRoots, 99 kImageRootsMax, 100 }; 101 102 mirror::Object* GetImageRoot(ImageRoot image_root) const 103 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 104 105 private: 106 mirror::ObjectArray<mirror::Object>* GetImageRoots() const; 107 108 static const byte kImageMagic[4]; 109 static const byte kImageVersion[4]; 110 111 byte magic_[4]; 112 byte version_[4]; 113 114 // Required base address for mapping the image. 115 uint32_t image_begin_; 116 117 // Image size, not page aligned. 118 uint32_t image_size_; 119 120 // Image bitmap offset in the file. 121 uint32_t image_bitmap_offset_; 122 123 // Size of the image bitmap. 124 uint32_t image_bitmap_size_; 125 126 // Checksum of the oat file we link to for load time sanity check. 127 uint32_t oat_checksum_; 128 129 // Start address for oat file. Will be before oat_data_begin_ for .so files. 130 uint32_t oat_file_begin_; 131 132 // Required oat address expected by image Method::GetCode() pointers. 133 uint32_t oat_data_begin_; 134 135 // End of oat data address range for this image file. 136 uint32_t oat_data_end_; 137 138 // End of oat file address range. will be after oat_data_end_ for 139 // .so files. Used for positioning a following alloc spaces. 140 uint32_t oat_file_end_; 141 142 // Absolute address of an Object[] of objects needed to reinitialize from an image. 143 uint32_t image_roots_; 144 145 friend class ImageWriter; 146 friend class ImageDumper; // For GetImageRoots() 147 }; 148 149 } // namespace art 150 151 #endif // ART_RUNTIME_IMAGE_H_ 152