blob: 528bfc631c8bc7964ed1e255f8a818b6588386af [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 Carlstrom4a289ed2011-08-16 17:17:49 -070016
17#include "image.h"
18
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019#include "mirror/object_array.h"
20#include "mirror/object_array-inl.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070021#include "mirror/object-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022#include "utils.h"
23
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070024namespace art {
25
Brian Carlstrome24fa612011-09-29 00:53:55 -070026const byte ImageHeader::kImageMagic[] = { 'a', 'r', 't', '\n' };
Nicolas Geoffray9583fbc2014-02-28 15:21:07 +000027const byte ImageHeader::kImageVersion[] = { '0', '0', '7', '\0' };
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070028
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080029ImageHeader::ImageHeader(uint32_t image_begin,
Mathieu Chartier31e89252013-08-28 11:29:12 -070030 uint32_t image_size,
31 uint32_t image_bitmap_offset,
32 uint32_t image_bitmap_size,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080033 uint32_t image_roots,
34 uint32_t oat_checksum,
35 uint32_t oat_file_begin,
36 uint32_t oat_data_begin,
37 uint32_t oat_data_end,
38 uint32_t oat_file_end)
39 : image_begin_(image_begin),
Mathieu Chartier31e89252013-08-28 11:29:12 -070040 image_size_(image_size),
41 image_bitmap_offset_(image_bitmap_offset),
42 image_bitmap_size_(image_bitmap_size),
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080043 oat_checksum_(oat_checksum),
44 oat_file_begin_(oat_file_begin),
45 oat_data_begin_(oat_data_begin),
46 oat_data_end_(oat_data_end),
47 oat_file_end_(oat_file_end),
48 image_roots_(image_roots) {
49 CHECK_EQ(image_begin, RoundUp(image_begin, kPageSize));
50 CHECK_EQ(oat_file_begin, RoundUp(oat_file_begin, kPageSize));
51 CHECK_EQ(oat_data_begin, RoundUp(oat_data_begin, kPageSize));
52 CHECK_LT(image_begin, image_roots);
53 CHECK_LT(image_roots, oat_file_begin);
54 CHECK_LE(oat_file_begin, oat_data_begin);
55 CHECK_LT(oat_data_begin, oat_data_end);
56 CHECK_LE(oat_data_end, oat_file_end);
57 memcpy(magic_, kImageMagic, sizeof(kImageMagic));
58 memcpy(version_, kImageVersion, sizeof(kImageVersion));
59}
60
Brian Carlstrom68708f52013-09-03 14:15:31 -070061bool ImageHeader::IsValid() const {
62 if (memcmp(magic_, kImageMagic, sizeof(kImageMagic)) != 0) {
63 return false;
64 }
65 if (memcmp(version_, kImageVersion, sizeof(kImageVersion)) != 0) {
66 return false;
67 }
68 return true;
69}
70
71const char* ImageHeader::GetMagic() const {
72 CHECK(IsValid());
73 return reinterpret_cast<const char*>(magic_);
74}
75
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076mirror::Object* ImageHeader::GetImageRoot(ImageRoot image_root) const {
77 return GetImageRoots()->Get(image_root);
78}
79
80mirror::ObjectArray<mirror::Object>* ImageHeader::GetImageRoots() const {
81 return reinterpret_cast<mirror::ObjectArray<mirror::Object>*>(image_roots_);
82}
83
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070084} // namespace art