Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 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 | */ |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_IMAGE_H_ |
| 18 | #define ART_RUNTIME_IMAGE_H_ |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 19 | |
| 20 | #include <string.h> |
| 21 | |
| 22 | #include "globals.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 23 | #include "mirror/object.h" |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | // header of image files written by ImageWriter, read and validated by Space. |
Ian Rogers | df1ce91 | 2012-11-27 17:07:11 -0800 | [diff] [blame] | 28 | class PACKED(4) ImageHeader { |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 29 | public: |
| 30 | ImageHeader() {} |
| 31 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 32 | ImageHeader(uint32_t image_begin, |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 33 | uint32_t image_roots, |
| 34 | uint32_t oat_checksum, |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 35 | uint32_t oat_file_begin, |
| 36 | uint32_t oat_data_begin, |
| 37 | uint32_t oat_data_end, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 38 | uint32_t oat_file_end); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 39 | |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 40 | bool IsValid() const { |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 41 | if (memcmp(magic_, kImageMagic, sizeof(kImageMagic) != 0)) { |
| 42 | return false; |
| 43 | } |
| 44 | if (memcmp(version_, kImageVersion, sizeof(kImageVersion) != 0)) { |
| 45 | return false; |
| 46 | } |
| 47 | return true; |
| 48 | } |
| 49 | |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 50 | const char* GetMagic() const { |
| 51 | CHECK(IsValid()); |
| 52 | return reinterpret_cast<const char*>(magic_); |
| 53 | } |
| 54 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 55 | byte* GetImageBegin() const { |
| 56 | return reinterpret_cast<byte*>(image_begin_); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | uint32_t GetOatChecksum() const { |
| 60 | return oat_checksum_; |
| 61 | } |
| 62 | |
Brian Carlstrom | a85b837 | 2012-10-18 17:00:32 -0700 | [diff] [blame] | 63 | void SetOatChecksum(uint32_t oat_checksum) { |
| 64 | oat_checksum_ = oat_checksum; |
| 65 | } |
| 66 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 67 | byte* GetOatFileBegin() const { |
| 68 | return reinterpret_cast<byte*>(oat_file_begin_); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 71 | byte* GetOatDataBegin() const { |
| 72 | return reinterpret_cast<byte*>(oat_data_begin_); |
| 73 | } |
| 74 | |
| 75 | byte* GetOatDataEnd() const { |
| 76 | return reinterpret_cast<byte*>(oat_data_end_); |
| 77 | } |
| 78 | |
| 79 | byte* GetOatFileEnd() const { |
| 80 | return reinterpret_cast<byte*>(oat_file_end_); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 83 | enum ImageRoot { |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 84 | kResolutionMethod, |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 85 | kCalleeSaveMethod, |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 86 | kRefsOnlySaveMethod, |
| 87 | kRefsAndArgsSaveMethod, |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 88 | kOatLocation, |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 89 | kDexCaches, |
Brian Carlstrom | 34f426c | 2011-10-04 12:58:02 -0700 | [diff] [blame] | 90 | kClassRoots, |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 91 | kImageRootsMax, |
| 92 | }; |
| 93 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 94 | mirror::Object* GetImageRoot(ImageRoot image_root) const |
| 95 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 96 | |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 97 | private: |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 98 | mirror::ObjectArray<mirror::Object>* GetImageRoots() const; |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 99 | |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 100 | static const byte kImageMagic[4]; |
| 101 | static const byte kImageVersion[4]; |
| 102 | |
| 103 | byte magic_[4]; |
| 104 | byte version_[4]; |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 105 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 106 | // Required base address for mapping the image. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 107 | uint32_t image_begin_; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 108 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 109 | // Checksum of the oat file we link to for load time sanity check. |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 110 | uint32_t oat_checksum_; |
| 111 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 112 | // Start address for oat file. Will be before oat_data_begin_ for .so files. |
| 113 | uint32_t oat_file_begin_; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 114 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 115 | // Required oat address expected by image Method::GetCode() pointers. |
| 116 | uint32_t oat_data_begin_; |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 117 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 118 | // End of oat data address range for this image file. |
| 119 | uint32_t oat_data_end_; |
| 120 | |
| 121 | // End of oat file address range. will be after oat_data_end_ for |
| 122 | // .so files. Used for positioning a following alloc spaces. |
| 123 | uint32_t oat_file_end_; |
| 124 | |
| 125 | // Absolute address of an Object[] of objects needed to reinitialize from an image. |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 126 | uint32_t image_roots_; |
| 127 | |
| 128 | friend class ImageWriter; |
Ian Rogers | 3a5c1ce | 2012-02-29 10:06:46 -0800 | [diff] [blame] | 129 | friend class ImageDumper; // For GetImageRoots() |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | } // namespace art |
| 133 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 134 | #endif // ART_RUNTIME_IMAGE_H_ |