blob: 650132830004db98666486863ec9af156f28e80c [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#ifndef ART_SRC_IMAGE_H_
18#define ART_SRC_IMAGE_H_
19
20#include <string.h>
21
22#include "globals.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080023#include "mirror/object.h"
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070024
25namespace art {
26
27// header of image files written by ImageWriter, read and validated by Space.
Ian Rogersdf1ce912012-11-27 17:07:11 -080028class PACKED(4) ImageHeader {
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070029 public:
30 ImageHeader() {}
31
Ian Rogers30fab402012-01-23 15:43:46 -080032 ImageHeader(uint32_t image_begin,
Brian Carlstrome24fa612011-09-29 00:53:55 -070033 uint32_t image_roots,
34 uint32_t oat_checksum,
Brian Carlstrom700c8d32012-11-05 10:42:02 -080035 uint32_t oat_file_begin,
36 uint32_t oat_data_begin,
37 uint32_t oat_data_end,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038 uint32_t oat_file_end);
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070039
Brian Carlstrom78128a62011-09-15 17:21:19 -070040 bool IsValid() const {
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070041 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 Carlstrom78128a62011-09-15 17:21:19 -070050 const char* GetMagic() const {
51 CHECK(IsValid());
52 return reinterpret_cast<const char*>(magic_);
53 }
54
Ian Rogers30fab402012-01-23 15:43:46 -080055 byte* GetImageBegin() const {
56 return reinterpret_cast<byte*>(image_begin_);
Brian Carlstrome24fa612011-09-29 00:53:55 -070057 }
58
59 uint32_t GetOatChecksum() const {
60 return oat_checksum_;
61 }
62
Brian Carlstroma85b8372012-10-18 17:00:32 -070063 void SetOatChecksum(uint32_t oat_checksum) {
64 oat_checksum_ = oat_checksum;
65 }
66
Brian Carlstrom700c8d32012-11-05 10:42:02 -080067 byte* GetOatFileBegin() const {
68 return reinterpret_cast<byte*>(oat_file_begin_);
Brian Carlstrome24fa612011-09-29 00:53:55 -070069 }
70
Brian Carlstrom700c8d32012-11-05 10:42:02 -080071 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 Carlstrom4a289ed2011-08-16 17:17:49 -070081 }
82
Brian Carlstrom16192862011-09-12 17:50:06 -070083 enum ImageRoot {
84 kJniStubArray,
Brian Carlstrome24fa612011-09-29 00:53:55 -070085 kAbstractMethodErrorStubArray,
Ian Rogersad25ac52011-10-04 19:13:33 -070086 kStaticResolutionStubArray,
Ian Rogers1cb0a1d2011-10-06 15:24:35 -070087 kUnknownMethodResolutionStubArray,
Ian Rogers19846512012-02-24 11:42:47 -080088 kResolutionMethod,
Ian Rogersff1ed472011-09-20 13:46:24 -070089 kCalleeSaveMethod,
Ian Rogers4f0d07c2011-10-06 23:38:47 -070090 kRefsOnlySaveMethod,
91 kRefsAndArgsSaveMethod,
Brian Carlstrome24fa612011-09-29 00:53:55 -070092 kOatLocation,
Brian Carlstrom58ae9412011-10-04 00:56:06 -070093 kDexCaches,
Brian Carlstrom34f426c2011-10-04 12:58:02 -070094 kClassRoots,
Brian Carlstrom16192862011-09-12 17:50:06 -070095 kImageRootsMax,
96 };
97
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080098 mirror::Object* GetImageRoot(ImageRoot image_root) const
99 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom16192862011-09-12 17:50:06 -0700100
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700101 private:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800102 mirror::ObjectArray<mirror::Object>* GetImageRoots() const;
Brian Carlstromaded5f72011-10-07 17:15:04 -0700103
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700104 static const byte kImageMagic[4];
105 static const byte kImageVersion[4];
106
107 byte magic_[4];
108 byte version_[4];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700109
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800110 // Required base address for mapping the image.
Ian Rogers30fab402012-01-23 15:43:46 -0800111 uint32_t image_begin_;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700112
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800113 // Checksum of the oat file we link to for load time sanity check.
Brian Carlstrome24fa612011-09-29 00:53:55 -0700114 uint32_t oat_checksum_;
115
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800116 // Start address for oat file. Will be before oat_data_begin_ for .so files.
117 uint32_t oat_file_begin_;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700118
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800119 // Required oat address expected by image Method::GetCode() pointers.
120 uint32_t oat_data_begin_;
Brian Carlstrom16192862011-09-12 17:50:06 -0700121
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800122 // End of oat data address range for this image file.
123 uint32_t oat_data_end_;
124
125 // End of oat file address range. will be after oat_data_end_ for
126 // .so files. Used for positioning a following alloc spaces.
127 uint32_t oat_file_end_;
128
129 // Absolute address of an Object[] of objects needed to reinitialize from an image.
Brian Carlstrom16192862011-09-12 17:50:06 -0700130 uint32_t image_roots_;
131
132 friend class ImageWriter;
Ian Rogers3a5c1ce2012-02-29 10:06:46 -0800133 friend class ImageDumper; // For GetImageRoots()
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700134};
135
136} // namespace art
137
138#endif // ART_SRC_IMAGE_H_