blob: c5773ec41232f69d1a1ec38d6a286b27078da418 [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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_IMAGE_H_
18#define ART_RUNTIME_IMAGE_H_
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070019
20#include <string.h>
21
Andreas Gampe542451c2016-07-26 09:02:02 -070022#include "base/enums.h"
Mathieu Chartier1a842962018-11-13 15:09:51 -080023#include "base/iteration_range.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024#include "mirror/object.h"
Andreas Gampe5a0430d2019-01-04 14:33:57 -080025#include "runtime_globals.h"
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070026
27namespace art {
28
Mathieu Chartier54d220e2015-07-30 16:20:06 -070029class ArtField;
30class ArtMethod;
Vladimir Markoc13fbd82018-06-04 16:16:28 +010031template <class MirrorType> class ObjPtr;
Mathieu Chartier54d220e2015-07-30 16:20:06 -070032
Vladimir Marko74527972016-11-29 15:57:32 +000033namespace linker {
34class ImageWriter;
35} // namespace linker
36
David Sehra49e0532017-08-25 08:05:29 -070037class ObjectVisitor {
38 public:
39 virtual ~ObjectVisitor() {}
40
41 virtual void Visit(mirror::Object* object) = 0;
42};
43
Mathieu Chartiere401d142015-04-22 13:56:20 -070044class PACKED(4) ImageSection {
45 public:
46 ImageSection() : offset_(0), size_(0) { }
47 ImageSection(uint32_t offset, uint32_t size) : offset_(offset), size_(size) { }
48 ImageSection(const ImageSection& section) = default;
49 ImageSection& operator=(const ImageSection& section) = default;
50
51 uint32_t Offset() const {
52 return offset_;
53 }
54
55 uint32_t Size() const {
56 return size_;
57 }
58
59 uint32_t End() const {
60 return Offset() + Size();
61 }
62
63 bool Contains(uint64_t offset) const {
64 return offset - offset_ < size_;
65 }
66
67 private:
68 uint32_t offset_;
69 uint32_t size_;
70};
71
Mathieu Chartier1a842962018-11-13 15:09:51 -080072// Header of image files written by ImageWriter, read and validated by Space.
73// Packed to object alignment since the first object follows directly after the header.
74static_assert(kObjectAlignment == 8, "Alignment check");
75class PACKED(8) ImageHeader {
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070076 public:
Mathieu Chartierceb07b32015-12-10 09:33:21 -080077 enum StorageMode : uint32_t {
78 kStorageModeUncompressed,
79 kStorageModeLZ4,
Mathieu Chartiera6e81ed2016-02-25 13:52:10 -080080 kStorageModeLZ4HC,
Mathieu Chartierceb07b32015-12-10 09:33:21 -080081 kStorageModeCount, // Number of elements in enum.
82 };
83 static constexpr StorageMode kDefaultStorageMode = kStorageModeUncompressed;
84
Mathieu Chartier1a842962018-11-13 15:09:51 -080085 // Solid block of the image. May be compressed or uncompressed.
86 class PACKED(4) Block final {
87 public:
88 Block(StorageMode storage_mode,
89 uint32_t data_offset,
90 uint32_t data_size,
91 uint32_t image_offset,
92 uint32_t image_size)
93 : storage_mode_(storage_mode),
94 data_offset_(data_offset),
95 data_size_(data_size),
96 image_offset_(image_offset),
97 image_size_(image_size) {}
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070098
Mathieu Chartier1a842962018-11-13 15:09:51 -080099 bool Decompress(uint8_t* out_ptr, const uint8_t* in_ptr, std::string* error_msg) const;
100
101 StorageMode GetStorageMode() const {
102 return storage_mode_;
103 }
104
Mathieu Chartierc6068c72018-11-13 16:00:58 -0800105 uint32_t GetDataSize() const {
106 return data_size_;
107 }
108
109 uint32_t GetImageSize() const {
110 return image_size_;
111 }
112
Mathieu Chartier1a842962018-11-13 15:09:51 -0800113 private:
114 // Storage method for the image, the image may be compressed.
115 StorageMode storage_mode_ = kDefaultStorageMode;
116
117 // Compressed offset and size.
118 uint32_t data_offset_ = 0u;
119 uint32_t data_size_ = 0u;
120
121 // Image offset and size (decompressed or mapped location).
122 uint32_t image_offset_ = 0u;
123 uint32_t image_size_ = 0u;
124 };
125
126 ImageHeader() {}
Vladimir Marko7391c8c2018-11-21 17:58:44 +0000127 ImageHeader(uint32_t image_reservation_size,
128 uint32_t component_count,
129 uint32_t image_begin,
Mathieu Chartier763a31e2015-11-16 16:05:55 -0800130 uint32_t image_size,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700131 ImageSection* sections,
Brian Carlstrome24fa612011-09-29 00:53:55 -0700132 uint32_t image_roots,
133 uint32_t oat_checksum,
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800134 uint32_t oat_file_begin,
135 uint32_t oat_data_begin,
136 uint32_t oat_data_end,
Igor Murashkin46774762014-10-22 11:37:02 -0700137 uint32_t oat_file_end,
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800138 uint32_t boot_image_begin,
139 uint32_t boot_image_size,
Vladimir Marko92eec3a2019-11-05 10:59:36 +0000140 uint32_t boot_image_component_count,
141 uint32_t boot_image_checksum,
Mathieu Chartier1a842962018-11-13 15:09:51 -0800142 uint32_t pointer_size);
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700143
Brian Carlstrom68708f52013-09-03 14:15:31 -0700144 bool IsValid() const;
145 const char* GetMagic() const;
Brian Carlstrom78128a62011-09-15 17:21:19 -0700146
Vladimir Marko7391c8c2018-11-21 17:58:44 +0000147 uint32_t GetImageReservationSize() const {
148 return image_reservation_size_;
149 }
150
151 uint32_t GetComponentCount() const {
152 return component_count_;
153 }
154
Ian Rogers13735952014-10-08 12:43:28 -0700155 uint8_t* GetImageBegin() const {
156 return reinterpret_cast<uint8_t*>(image_begin_);
Brian Carlstrome24fa612011-09-29 00:53:55 -0700157 }
158
Mathieu Chartier31e89252013-08-28 11:29:12 -0700159 size_t GetImageSize() const {
Vladimir Markoc10a0c62018-11-16 11:39:22 +0000160 return image_size_;
161 }
162
163 uint32_t GetImageChecksum() const {
164 return image_checksum_;
165 }
166
167 void SetImageChecksum(uint32_t image_checksum) {
168 image_checksum_ = image_checksum;
Mathieu Chartier31e89252013-08-28 11:29:12 -0700169 }
170
Brian Carlstrome24fa612011-09-29 00:53:55 -0700171 uint32_t GetOatChecksum() const {
172 return oat_checksum_;
173 }
174
Brian Carlstroma85b8372012-10-18 17:00:32 -0700175 void SetOatChecksum(uint32_t oat_checksum) {
176 oat_checksum_ = oat_checksum;
177 }
178
Mathieu Chartier5351da02016-02-17 16:19:53 -0800179 // The location that the oat file was expected to be when the image was created. The actual
180 // oat file may be at a different location for application images.
Ian Rogers13735952014-10-08 12:43:28 -0700181 uint8_t* GetOatFileBegin() const {
182 return reinterpret_cast<uint8_t*>(oat_file_begin_);
Brian Carlstrome24fa612011-09-29 00:53:55 -0700183 }
184
Ian Rogers13735952014-10-08 12:43:28 -0700185 uint8_t* GetOatDataBegin() const {
186 return reinterpret_cast<uint8_t*>(oat_data_begin_);
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800187 }
188
Ian Rogers13735952014-10-08 12:43:28 -0700189 uint8_t* GetOatDataEnd() const {
190 return reinterpret_cast<uint8_t*>(oat_data_end_);
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800191 }
192
Ian Rogers13735952014-10-08 12:43:28 -0700193 uint8_t* GetOatFileEnd() const {
194 return reinterpret_cast<uint8_t*>(oat_file_end_);
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700195 }
196
Andreas Gampebda1d602016-08-29 17:43:45 -0700197 PointerSize GetPointerSize() const;
Andreas Gampe542451c2016-07-26 09:02:02 -0700198
199 uint32_t GetPointerSizeUnchecked() const {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700200 return pointer_size_;
201 }
202
Nicolas Geoffray9583fbc2014-02-28 15:21:07 +0000203 static std::string GetOatLocationFromImageLocation(const std::string& image) {
David Brazdil7b49e6c2016-09-01 11:06:18 +0100204 return GetLocationFromImageLocation(image, "oat");
205 }
206
207 static std::string GetVdexLocationFromImageLocation(const std::string& image) {
208 return GetLocationFromImageLocation(image, "vdex");
Nicolas Geoffray9583fbc2014-02-28 15:21:07 +0000209 }
210
Mathieu Chartiere401d142015-04-22 13:56:20 -0700211 enum ImageMethod {
Ian Rogers19846512012-02-24 11:42:47 -0800212 kResolutionMethod,
Jeff Hao88474b42013-10-23 16:24:40 -0700213 kImtConflictMethod,
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700214 kImtUnimplementedMethod,
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100215 kSaveAllCalleeSavesMethod,
216 kSaveRefsOnlyMethod,
217 kSaveRefsAndArgsMethod,
Vladimir Marko952dbb12016-07-28 12:01:51 +0100218 kSaveEverythingMethod,
Mingyao Yang0a87a652017-04-12 13:43:15 -0700219 kSaveEverythingMethodForClinit,
220 kSaveEverythingMethodForSuspendCheck,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700221 kImageMethodsCount, // Number of elements in enum.
222 };
223
224 enum ImageRoot {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700225 kDexCaches,
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700226 kClassRoots,
Vladimir Markof75613c2018-06-05 12:51:04 +0100227 kSpecialRoots, // Different for boot image and app image, see aliases below.
Brian Carlstrom16192862011-09-12 17:50:06 -0700228 kImageRootsMax,
Vladimir Markof75613c2018-06-05 12:51:04 +0100229
230 // Aliases.
231 kAppImageClassLoader = kSpecialRoots, // The class loader used to build the app image.
232 kBootImageLiveObjects = kSpecialRoots, // Array of boot image objects that must be kept live.
Brian Carlstrom16192862011-09-12 17:50:06 -0700233 };
234
Vladimir Marko024d69f2019-06-13 10:52:32 +0100235 enum BootImageLiveObjects {
236 kOomeWhenThrowingException, // Pre-allocated OOME when throwing exception.
237 kOomeWhenThrowingOome, // Pre-allocated OOME when throwing OOME.
238 kOomeWhenHandlingStackOverflow, // Pre-allocated OOME when handling StackOverflowError.
239 kNoClassDefFoundError, // Pre-allocated NoClassDefFoundError.
240 kClearedJniWeakSentinel, // Pre-allocated sentinel for cleared weak JNI references.
241 kIntrinsicObjectsStart
242 };
243
Chris Wailes0c61be42018-09-26 17:27:34 -0700244 /*
245 * This describes the number and ordering of sections inside of Boot
246 * and App Images. It is very important that changes to this struct
247 * are reflected in the compiler and loader.
248 *
249 * See:
250 * - ImageWriter::ImageInfo::CreateImageSections()
251 * - ImageWriter::Write()
252 * - ImageWriter::AllocMemory()
253 */
Mathieu Chartiere401d142015-04-22 13:56:20 -0700254 enum ImageSections {
255 kSectionObjects,
256 kSectionArtFields,
257 kSectionArtMethods,
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700258 kSectionRuntimeMethods,
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000259 kSectionImTables,
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700260 kSectionIMTConflictTables,
Mathieu Chartierd39645e2015-06-09 17:50:29 -0700261 kSectionInternedStrings,
Mathieu Chartier208a5cb2015-12-02 15:44:07 -0800262 kSectionClassTable,
Chris Wailes0c61be42018-09-26 17:27:34 -0700263 kSectionStringReferenceOffsets,
Mathieu Chartier1ca718e2018-10-23 12:55:34 -0700264 kSectionMetadata,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700265 kSectionImageBitmap,
266 kSectionCount, // Number of elements in enum.
267 };
268
Vladimir Markof75613c2018-06-05 12:51:04 +0100269 static size_t NumberOfImageRoots(bool app_image ATTRIBUTE_UNUSED) {
270 // At the moment, boot image and app image have the same number of roots,
271 // though the meaning of the kSpecialRoots is different.
272 return kImageRootsMax;
Vladimir Markoeca3eda2016-11-09 16:26:44 +0000273 }
274
Mathieu Chartiere401d142015-04-22 13:56:20 -0700275 ArtMethod* GetImageMethod(ImageMethod index) const;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700276
David Srbeckybc1748f2021-02-22 10:51:32 +0000277 static const char* GetImageSectionName(ImageSections index);
278
Mathieu Chartier1a842962018-11-13 15:09:51 -0800279 ImageSection& GetImageSection(ImageSections index) {
280 DCHECK_LT(static_cast<size_t>(index), kSectionCount);
281 return sections_[index];
282 }
283
Vladimir Markocd87c3e2017-09-05 13:11:57 +0100284 const ImageSection& GetImageSection(ImageSections index) const {
285 DCHECK_LT(static_cast<size_t>(index), kSectionCount);
286 return sections_[index];
287 }
288
289 const ImageSection& GetObjectsSection() const {
290 return GetImageSection(kSectionObjects);
291 }
292
293 const ImageSection& GetFieldsSection() const {
294 return GetImageSection(ImageHeader::kSectionArtFields);
295 }
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700296
Mathieu Chartiere401d142015-04-22 13:56:20 -0700297 const ImageSection& GetMethodsSection() const {
298 return GetImageSection(kSectionArtMethods);
299 }
300
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700301 const ImageSection& GetRuntimeMethodsSection() const {
302 return GetImageSection(kSectionRuntimeMethods);
303 }
304
Vladimir Markocd87c3e2017-09-05 13:11:57 +0100305 const ImageSection& GetImTablesSection() const {
306 return GetImageSection(kSectionImTables);
307 }
308
309 const ImageSection& GetIMTConflictTablesSection() const {
310 return GetImageSection(kSectionIMTConflictTables);
311 }
312
Vladimir Markocd87c3e2017-09-05 13:11:57 +0100313 const ImageSection& GetInternedStringsSection() const {
314 return GetImageSection(kSectionInternedStrings);
315 }
316
317 const ImageSection& GetClassTableSection() const {
318 return GetImageSection(kSectionClassTable);
319 }
320
Chris Wailes0c61be42018-09-26 17:27:34 -0700321 const ImageSection& GetImageStringReferenceOffsetsSection() const {
322 return GetImageSection(kSectionStringReferenceOffsets);
323 }
324
Mathieu Chartier1ca718e2018-10-23 12:55:34 -0700325 const ImageSection& GetMetadataSection() const {
326 return GetImageSection(kSectionMetadata);
327 }
328
Vladimir Marko6d3c1812018-10-24 14:00:00 +0100329 const ImageSection& GetImageBitmapSection() const {
330 return GetImageSection(kSectionImageBitmap);
331 }
332
Mathieu Chartier4a26f172016-01-26 14:26:18 -0800333 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Vladimir Markoc13fbd82018-06-04 16:16:28 +0100334 ObjPtr<mirror::Object> GetImageRoot(ImageRoot image_root) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700335 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4a26f172016-01-26 14:26:18 -0800336
337 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Vladimir Markoc13fbd82018-06-04 16:16:28 +0100338 ObjPtr<mirror::ObjectArray<mirror::Object>> GetImageRoots() const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700339 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700340
Vladimir Markoc0b30c92019-07-23 14:58:25 +0100341 void RelocateImageReferences(int64_t delta);
342 void RelocateBootImageReferences(int64_t delta);
Alex Light53cb16b2014-06-12 11:26:29 -0700343
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800344 uint32_t GetBootImageBegin() const {
345 return boot_image_begin_;
346 }
347
348 uint32_t GetBootImageSize() const {
349 return boot_image_size_;
350 }
351
Vladimir Marko92eec3a2019-11-05 10:59:36 +0000352 uint32_t GetBootImageComponentCount() const {
353 return boot_image_component_count_;
354 }
355
356 uint32_t GetBootImageChecksum() const {
357 return boot_image_checksum_;
358 }
359
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800360 uint64_t GetDataSize() const {
361 return data_size_;
362 }
363
Vladimir Marko21910692019-11-06 13:27:03 +0000364 bool IsAppImage() const;
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800365
Vladimir Markod0036ac2019-11-21 11:47:12 +0000366 uint32_t GetImageSpaceCount() const;
367
David Sehra49e0532017-08-25 08:05:29 -0700368 // Visit mirror::Objects in the section starting at base.
369 // TODO: Delete base parameter if it is always equal to GetImageBegin.
370 void VisitObjects(ObjectVisitor* visitor,
371 uint8_t* base,
372 PointerSize pointer_size) const
373 REQUIRES_SHARED(Locks::mutator_lock_);
374
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700375 // Visit ArtMethods in the section starting at base. Includes runtime methods.
376 // TODO: Delete base parameter if it is always equal to GetImageBegin.
Mathieu Chartier9d5956a2019-03-22 11:29:08 -0700377 // NO_THREAD_SAFETY_ANALYSIS for template visitor pattern.
378 template <typename Visitor>
379 void VisitPackedArtMethods(const Visitor& visitor,
Andreas Gampe542451c2016-07-26 09:02:02 -0700380 uint8_t* base,
Mathieu Chartier9d5956a2019-03-22 11:29:08 -0700381 PointerSize pointer_size) const NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700382
383 // Visit ArtMethods in the section starting at base.
384 // TODO: Delete base parameter if it is always equal to GetImageBegin.
Mathieu Chartier9d5956a2019-03-22 11:29:08 -0700385 // NO_THREAD_SAFETY_ANALYSIS for template visitor pattern.
386 template <typename Visitor>
387 void VisitPackedArtFields(const Visitor& visitor, uint8_t* base) const NO_THREAD_SAFETY_ANALYSIS;
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700388
389 template <typename Visitor>
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000390 void VisitPackedImTables(const Visitor& visitor,
391 uint8_t* base,
Andreas Gampe542451c2016-07-26 09:02:02 -0700392 PointerSize pointer_size) const;
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000393
394 template <typename Visitor>
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700395 void VisitPackedImtConflictTables(const Visitor& visitor,
396 uint8_t* base,
Andreas Gampe542451c2016-07-26 09:02:02 -0700397 PointerSize pointer_size) const;
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700398
Mathieu Chartier1a842962018-11-13 15:09:51 -0800399 IterationRange<const Block*> GetBlocks() const {
400 return GetBlocks(GetImageBegin());
401 }
402
403 IterationRange<const Block*> GetBlocks(const uint8_t* image_begin) const {
404 const Block* begin = reinterpret_cast<const Block*>(image_begin + blocks_offset_);
405 return {begin, begin + blocks_count_};
406 }
407
408 // Return true if the image has any compressed blocks.
409 bool HasCompressedBlock() const {
410 return blocks_count_ != 0u;
411 }
412
413 uint32_t GetBlockCount() const {
414 return blocks_count_;
415 }
416
Alex Light53cb16b2014-06-12 11:26:29 -0700417 private:
Ian Rogers13735952014-10-08 12:43:28 -0700418 static const uint8_t kImageMagic[4];
419 static const uint8_t kImageVersion[4];
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700420
David Brazdil7b49e6c2016-09-01 11:06:18 +0100421 static std::string GetLocationFromImageLocation(const std::string& image,
422 const std::string& extension) {
423 std::string filename = image;
424 if (filename.length() <= 3) {
425 filename += "." + extension;
426 } else {
427 filename.replace(filename.length() - 3, 3, extension);
428 }
429 return filename;
430 }
431
Ian Rogers13735952014-10-08 12:43:28 -0700432 uint8_t magic_[4];
433 uint8_t version_[4];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700434
Vladimir Marko7391c8c2018-11-21 17:58:44 +0000435 // The total memory reservation size for the image.
436 // For boot image or boot image extension, the primary image includes the reservation
437 // for all image files and oat files, secondary images have the reservation set to 0.
438 // App images have reservation equal to `image_size_` rounded up to page size because
439 // their oat files are mmapped independently.
440 uint32_t image_reservation_size_ = 0u;
441
Orion Hodson771708f2021-01-06 15:45:16 +0000442 // The number of components (jar files contributing to the image).
Vladimir Marko7391c8c2018-11-21 17:58:44 +0000443 // For boot image or boot image extension, the primary image stores the total number
Orion Hodson771708f2021-01-06 15:45:16 +0000444 // of components, secondary images have this set to 0. App images have 1 component.
445 // The component count usually matches the total number of images (one image per component), but
446 // if multiple components are compiled with --single-image there will only be 1 image associated
447 // with those components.
Vladimir Marko7391c8c2018-11-21 17:58:44 +0000448 uint32_t component_count_ = 0u;
449
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800450 // Required base address for mapping the image.
Vladimir Marko312f10e2018-11-21 12:35:24 +0000451 uint32_t image_begin_ = 0u;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700452
Mathieu Chartier31e89252013-08-28 11:29:12 -0700453 // Image size, not page aligned.
Vladimir Marko312f10e2018-11-21 12:35:24 +0000454 uint32_t image_size_ = 0u;
Mathieu Chartier31e89252013-08-28 11:29:12 -0700455
Vladimir Markoc10a0c62018-11-16 11:39:22 +0000456 // Image file checksum (calculated with the checksum field set to 0).
Vladimir Marko312f10e2018-11-21 12:35:24 +0000457 uint32_t image_checksum_ = 0u;
Vladimir Markoc10a0c62018-11-16 11:39:22 +0000458
David Srbecky346fd962020-07-27 16:51:00 +0100459 // Checksum of the oat file we link to for load time consistency check.
Vladimir Marko312f10e2018-11-21 12:35:24 +0000460 uint32_t oat_checksum_ = 0u;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700461
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800462 // Start address for oat file. Will be before oat_data_begin_ for .so files.
Vladimir Marko312f10e2018-11-21 12:35:24 +0000463 uint32_t oat_file_begin_ = 0u;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700464
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800465 // Required oat address expected by image Method::GetCode() pointers.
Vladimir Marko312f10e2018-11-21 12:35:24 +0000466 uint32_t oat_data_begin_ = 0u;
Brian Carlstrom16192862011-09-12 17:50:06 -0700467
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800468 // End of oat data address range for this image file.
Vladimir Marko312f10e2018-11-21 12:35:24 +0000469 uint32_t oat_data_end_ = 0u;
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800470
471 // End of oat file address range. will be after oat_data_end_ for
472 // .so files. Used for positioning a following alloc spaces.
Vladimir Marko312f10e2018-11-21 12:35:24 +0000473 uint32_t oat_file_end_ = 0u;
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800474
Vladimir Marko92eec3a2019-11-05 10:59:36 +0000475 // Boot image begin and end (only applies to boot image extension and app image headers).
Vladimir Marko312f10e2018-11-21 12:35:24 +0000476 uint32_t boot_image_begin_ = 0u;
477 uint32_t boot_image_size_ = 0u; // Includes heap (*.art) and code (.oat).
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800478
Vladimir Marko92eec3a2019-11-05 10:59:36 +0000479 // Number of boot image components that this image depends on and their composite checksum
480 // (only applies to boot image extension and app image headers).
481 uint32_t boot_image_component_count_ = 0u;
482 uint32_t boot_image_checksum_ = 0u;
483
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800484 // Absolute address of an Object[] of objects needed to reinitialize from an image.
Vladimir Marko312f10e2018-11-21 12:35:24 +0000485 uint32_t image_roots_ = 0u;
Brian Carlstrom16192862011-09-12 17:50:06 -0700486
Mathieu Chartiere401d142015-04-22 13:56:20 -0700487 // Pointer size, this affects the size of the ArtMethods.
Vladimir Marko312f10e2018-11-21 12:35:24 +0000488 uint32_t pointer_size_ = 0u;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700489
Mathieu Chartier67ad20e2015-12-09 15:41:09 -0800490 // Image section sizes/offsets correspond to the uncompressed form.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700491 ImageSection sections_[kSectionCount];
492
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800493 // Image methods, may be inside of the boot image for app images.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700494 uint64_t image_methods_[kImageMethodsCount];
495
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800496 // Data size for the image data excluding the bitmap and the header. For compressed images, this
497 // is the compressed size in the file.
Vladimir Marko312f10e2018-11-21 12:35:24 +0000498 uint32_t data_size_ = 0u;
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800499
Mathieu Chartier1a842962018-11-13 15:09:51 -0800500 // Image blocks, only used for compressed images.
501 uint32_t blocks_offset_ = 0u;
502 uint32_t blocks_count_ = 0u;
503
Vladimir Marko74527972016-11-29 15:57:32 +0000504 friend class linker::ImageWriter;
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700505};
506
Chris Wailes0c61be42018-09-26 17:27:34 -0700507/*
Chris Wailesfbeef462018-10-19 14:16:35 -0700508 * This type holds the information necessary to fix up AppImage string
509 * references.
510 *
David Srbecky86d6cd52020-12-02 18:13:10 +0000511 * The first element indicates the location of a managed object with a field that needs fixing up.
512 * The second element of the pair is an object-relative offset to the field in question.
Chris Wailesfbeef462018-10-19 14:16:35 -0700513 */
514typedef std::pair<uint32_t, uint32_t> AppImageReferenceOffsetInfo;
515
Vladimir Marko9974e3c2020-06-10 16:27:06 +0100516std::ostream& operator<<(std::ostream& os, ImageHeader::ImageMethod method);
517std::ostream& operator<<(std::ostream& os, ImageHeader::ImageRoot root);
518std::ostream& operator<<(std::ostream& os, ImageHeader::ImageSections section);
519std::ostream& operator<<(std::ostream& os, ImageHeader::StorageMode mode);
520
Mathieu Chartiere401d142015-04-22 13:56:20 -0700521std::ostream& operator<<(std::ostream& os, const ImageSection& section);
522
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700523} // namespace art
524
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700525#endif // ART_RUNTIME_IMAGE_H_