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 | |
| 17 | #include "image.h" |
| 18 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame^] | 19 | #include "mirror/object_array.h" |
| 20 | #include "mirror/object_array-inl.h" |
| 21 | #include "utils.h" |
| 22 | |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 23 | namespace art { |
| 24 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 25 | const byte ImageHeader::kImageMagic[] = { 'a', 'r', 't', '\n' }; |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 26 | const byte ImageHeader::kImageVersion[] = { '0', '0', '2', '\0' }; |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 27 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame^] | 28 | ImageHeader::ImageHeader(uint32_t image_begin, |
| 29 | uint32_t image_roots, |
| 30 | uint32_t oat_checksum, |
| 31 | uint32_t oat_file_begin, |
| 32 | uint32_t oat_data_begin, |
| 33 | uint32_t oat_data_end, |
| 34 | uint32_t oat_file_end) |
| 35 | : image_begin_(image_begin), |
| 36 | oat_checksum_(oat_checksum), |
| 37 | oat_file_begin_(oat_file_begin), |
| 38 | oat_data_begin_(oat_data_begin), |
| 39 | oat_data_end_(oat_data_end), |
| 40 | oat_file_end_(oat_file_end), |
| 41 | image_roots_(image_roots) { |
| 42 | CHECK_EQ(image_begin, RoundUp(image_begin, kPageSize)); |
| 43 | CHECK_EQ(oat_file_begin, RoundUp(oat_file_begin, kPageSize)); |
| 44 | CHECK_EQ(oat_data_begin, RoundUp(oat_data_begin, kPageSize)); |
| 45 | CHECK_LT(image_begin, image_roots); |
| 46 | CHECK_LT(image_roots, oat_file_begin); |
| 47 | CHECK_LE(oat_file_begin, oat_data_begin); |
| 48 | CHECK_LT(oat_data_begin, oat_data_end); |
| 49 | CHECK_LE(oat_data_end, oat_file_end); |
| 50 | memcpy(magic_, kImageMagic, sizeof(kImageMagic)); |
| 51 | memcpy(version_, kImageVersion, sizeof(kImageVersion)); |
| 52 | } |
| 53 | |
| 54 | mirror::Object* ImageHeader::GetImageRoot(ImageRoot image_root) const { |
| 55 | return GetImageRoots()->Get(image_root); |
| 56 | } |
| 57 | |
| 58 | mirror::ObjectArray<mirror::Object>* ImageHeader::GetImageRoots() const { |
| 59 | return reinterpret_cast<mirror::ObjectArray<mirror::Object>*>(image_roots_); |
| 60 | } |
| 61 | |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 62 | } // namespace art |