blob: b0e8a3df3d159db112455ab254e65ca1671bce1c [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"
David Sehr1979c642018-04-26 14:41:18 -070023#include "base/globals.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024#include "mirror/object.h"
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070025
26namespace art {
27
Mathieu Chartier54d220e2015-07-30 16:20:06 -070028class ArtField;
29class ArtMethod;
Vladimir Markoc13fbd82018-06-04 16:16:28 +010030template <class MirrorType> class ObjPtr;
Mathieu Chartier54d220e2015-07-30 16:20:06 -070031
Vladimir Marko74527972016-11-29 15:57:32 +000032namespace linker {
33class ImageWriter;
34} // namespace linker
35
David Sehra49e0532017-08-25 08:05:29 -070036class ObjectVisitor {
37 public:
38 virtual ~ObjectVisitor() {}
39
40 virtual void Visit(mirror::Object* object) = 0;
41};
42
Mathieu Chartier54d220e2015-07-30 16:20:06 -070043class ArtMethodVisitor {
44 public:
45 virtual ~ArtMethodVisitor() {}
46
47 virtual void Visit(ArtMethod* method) = 0;
48};
49
50class ArtFieldVisitor {
51 public:
52 virtual ~ArtFieldVisitor() {}
53
54 virtual void Visit(ArtField* method) = 0;
55};
56
Mathieu Chartiere401d142015-04-22 13:56:20 -070057class PACKED(4) ImageSection {
58 public:
59 ImageSection() : offset_(0), size_(0) { }
60 ImageSection(uint32_t offset, uint32_t size) : offset_(offset), size_(size) { }
61 ImageSection(const ImageSection& section) = default;
62 ImageSection& operator=(const ImageSection& section) = default;
63
64 uint32_t Offset() const {
65 return offset_;
66 }
67
68 uint32_t Size() const {
69 return size_;
70 }
71
72 uint32_t End() const {
73 return Offset() + Size();
74 }
75
76 bool Contains(uint64_t offset) const {
77 return offset - offset_ < size_;
78 }
79
80 private:
81 uint32_t offset_;
82 uint32_t size_;
83};
84
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070085// header of image files written by ImageWriter, read and validated by Space.
Ian Rogersdf1ce912012-11-27 17:07:11 -080086class PACKED(4) ImageHeader {
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070087 public:
Mathieu Chartierceb07b32015-12-10 09:33:21 -080088 enum StorageMode : uint32_t {
89 kStorageModeUncompressed,
90 kStorageModeLZ4,
Mathieu Chartiera6e81ed2016-02-25 13:52:10 -080091 kStorageModeLZ4HC,
Mathieu Chartierceb07b32015-12-10 09:33:21 -080092 kStorageModeCount, // Number of elements in enum.
93 };
94 static constexpr StorageMode kDefaultStorageMode = kStorageModeUncompressed;
95
Sebastien Hertzaa50d3a2015-08-25 15:25:41 +020096 ImageHeader()
Mathieu Chartierceb07b32015-12-10 09:33:21 -080097 : image_begin_(0U),
98 image_size_(0U),
99 oat_checksum_(0U),
100 oat_file_begin_(0U),
101 oat_data_begin_(0U),
102 oat_data_end_(0U),
103 oat_file_end_(0U),
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800104 boot_image_begin_(0U),
105 boot_image_size_(0U),
106 boot_oat_begin_(0U),
107 boot_oat_size_(0U),
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800108 patch_delta_(0),
109 image_roots_(0U),
110 pointer_size_(0U),
111 compile_pic_(0),
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800112 is_pic_(0),
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800113 storage_mode_(kDefaultStorageMode),
114 data_size_(0) {}
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700115
Ian Rogers30fab402012-01-23 15:43:46 -0800116 ImageHeader(uint32_t image_begin,
Mathieu Chartier763a31e2015-11-16 16:05:55 -0800117 uint32_t image_size,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700118 ImageSection* sections,
Brian Carlstrome24fa612011-09-29 00:53:55 -0700119 uint32_t image_roots,
120 uint32_t oat_checksum,
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800121 uint32_t oat_file_begin,
122 uint32_t oat_data_begin,
123 uint32_t oat_data_end,
Igor Murashkin46774762014-10-22 11:37:02 -0700124 uint32_t oat_file_end,
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800125 uint32_t boot_image_begin,
126 uint32_t boot_image_size,
127 uint32_t boot_oat_begin,
128 uint32_t boot_oat_size,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700129 uint32_t pointer_size,
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800130 bool compile_pic,
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800131 bool is_pic,
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800132 StorageMode storage_mode,
133 size_t data_size);
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700134
Brian Carlstrom68708f52013-09-03 14:15:31 -0700135 bool IsValid() const;
136 const char* GetMagic() const;
Brian Carlstrom78128a62011-09-15 17:21:19 -0700137
Ian Rogers13735952014-10-08 12:43:28 -0700138 uint8_t* GetImageBegin() const {
139 return reinterpret_cast<uint8_t*>(image_begin_);
Brian Carlstrome24fa612011-09-29 00:53:55 -0700140 }
141
Mathieu Chartier31e89252013-08-28 11:29:12 -0700142 size_t GetImageSize() const {
143 return static_cast<uint32_t>(image_size_);
144 }
145
Brian Carlstrome24fa612011-09-29 00:53:55 -0700146 uint32_t GetOatChecksum() const {
147 return oat_checksum_;
148 }
149
Brian Carlstroma85b8372012-10-18 17:00:32 -0700150 void SetOatChecksum(uint32_t oat_checksum) {
151 oat_checksum_ = oat_checksum;
152 }
153
Mathieu Chartier5351da02016-02-17 16:19:53 -0800154 // The location that the oat file was expected to be when the image was created. The actual
155 // oat file may be at a different location for application images.
Ian Rogers13735952014-10-08 12:43:28 -0700156 uint8_t* GetOatFileBegin() const {
157 return reinterpret_cast<uint8_t*>(oat_file_begin_);
Brian Carlstrome24fa612011-09-29 00:53:55 -0700158 }
159
Ian Rogers13735952014-10-08 12:43:28 -0700160 uint8_t* GetOatDataBegin() const {
161 return reinterpret_cast<uint8_t*>(oat_data_begin_);
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800162 }
163
Ian Rogers13735952014-10-08 12:43:28 -0700164 uint8_t* GetOatDataEnd() const {
165 return reinterpret_cast<uint8_t*>(oat_data_end_);
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800166 }
167
Ian Rogers13735952014-10-08 12:43:28 -0700168 uint8_t* GetOatFileEnd() const {
169 return reinterpret_cast<uint8_t*>(oat_file_end_);
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700170 }
171
Andreas Gampebda1d602016-08-29 17:43:45 -0700172 PointerSize GetPointerSize() const;
Andreas Gampe542451c2016-07-26 09:02:02 -0700173
174 uint32_t GetPointerSizeUnchecked() const {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700175 return pointer_size_;
176 }
177
Alex Light53cb16b2014-06-12 11:26:29 -0700178 off_t GetPatchDelta() const {
179 return patch_delta_;
180 }
181
Alex Klyubind1d5c952017-12-15 12:57:33 -0800182 void SetPatchDelta(off_t patch_delta) {
183 patch_delta_ = patch_delta;
184 }
185
Nicolas Geoffray9583fbc2014-02-28 15:21:07 +0000186 static std::string GetOatLocationFromImageLocation(const std::string& image) {
David Brazdil7b49e6c2016-09-01 11:06:18 +0100187 return GetLocationFromImageLocation(image, "oat");
188 }
189
190 static std::string GetVdexLocationFromImageLocation(const std::string& image) {
191 return GetLocationFromImageLocation(image, "vdex");
Nicolas Geoffray9583fbc2014-02-28 15:21:07 +0000192 }
193
Mathieu Chartiere401d142015-04-22 13:56:20 -0700194 enum ImageMethod {
Ian Rogers19846512012-02-24 11:42:47 -0800195 kResolutionMethod,
Jeff Hao88474b42013-10-23 16:24:40 -0700196 kImtConflictMethod,
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700197 kImtUnimplementedMethod,
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100198 kSaveAllCalleeSavesMethod,
199 kSaveRefsOnlyMethod,
200 kSaveRefsAndArgsMethod,
Vladimir Marko952dbb12016-07-28 12:01:51 +0100201 kSaveEverythingMethod,
Mingyao Yang0a87a652017-04-12 13:43:15 -0700202 kSaveEverythingMethodForClinit,
203 kSaveEverythingMethodForSuspendCheck,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700204 kImageMethodsCount, // Number of elements in enum.
205 };
206
207 enum ImageRoot {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700208 kDexCaches,
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700209 kClassRoots,
Vladimir Markoc13fbd82018-06-04 16:16:28 +0100210 kOomeWhenThrowingException, // Pre-allocated OOME when throwing exception.
211 kOomeWhenThrowingOome, // Pre-allocated OOME when throwing OOME.
212 kOomeWhenHandlingStackOverflow, // Pre-allocated OOME when handling StackOverflowError.
213 kNoClassDefFoundError, // Pre-allocated NoClassDefFoundError.
Vladimir Markof75613c2018-06-05 12:51:04 +0100214 kSpecialRoots, // Different for boot image and app image, see aliases below.
Brian Carlstrom16192862011-09-12 17:50:06 -0700215 kImageRootsMax,
Vladimir Markof75613c2018-06-05 12:51:04 +0100216
217 // Aliases.
218 kAppImageClassLoader = kSpecialRoots, // The class loader used to build the app image.
219 kBootImageLiveObjects = kSpecialRoots, // Array of boot image objects that must be kept live.
Brian Carlstrom16192862011-09-12 17:50:06 -0700220 };
221
Chris Wailes0c61be42018-09-26 17:27:34 -0700222 /*
223 * This describes the number and ordering of sections inside of Boot
224 * and App Images. It is very important that changes to this struct
225 * are reflected in the compiler and loader.
226 *
227 * See:
228 * - ImageWriter::ImageInfo::CreateImageSections()
229 * - ImageWriter::Write()
230 * - ImageWriter::AllocMemory()
231 */
Mathieu Chartiere401d142015-04-22 13:56:20 -0700232 enum ImageSections {
233 kSectionObjects,
234 kSectionArtFields,
235 kSectionArtMethods,
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700236 kSectionRuntimeMethods,
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000237 kSectionImTables,
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700238 kSectionIMTConflictTables,
Vladimir Marko05792b92015-08-03 11:56:49 +0100239 kSectionDexCacheArrays,
Mathieu Chartierd39645e2015-06-09 17:50:29 -0700240 kSectionInternedStrings,
Mathieu Chartier208a5cb2015-12-02 15:44:07 -0800241 kSectionClassTable,
Chris Wailes0c61be42018-09-26 17:27:34 -0700242 kSectionStringReferenceOffsets,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700243 kSectionImageBitmap,
Vladimir Marko6121aa62018-07-06 10:04:35 +0100244 kSectionImageRelocations,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700245 kSectionCount, // Number of elements in enum.
246 };
247
Vladimir Markof75613c2018-06-05 12:51:04 +0100248 static size_t NumberOfImageRoots(bool app_image ATTRIBUTE_UNUSED) {
249 // At the moment, boot image and app image have the same number of roots,
250 // though the meaning of the kSpecialRoots is different.
251 return kImageRootsMax;
Vladimir Markoeca3eda2016-11-09 16:26:44 +0000252 }
253
Mathieu Chartiere401d142015-04-22 13:56:20 -0700254 ArtMethod* GetImageMethod(ImageMethod index) const;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700255
Vladimir Markocd87c3e2017-09-05 13:11:57 +0100256 const ImageSection& GetImageSection(ImageSections index) const {
257 DCHECK_LT(static_cast<size_t>(index), kSectionCount);
258 return sections_[index];
259 }
260
261 const ImageSection& GetObjectsSection() const {
262 return GetImageSection(kSectionObjects);
263 }
264
265 const ImageSection& GetFieldsSection() const {
266 return GetImageSection(ImageHeader::kSectionArtFields);
267 }
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700268
Mathieu Chartiere401d142015-04-22 13:56:20 -0700269 const ImageSection& GetMethodsSection() const {
270 return GetImageSection(kSectionArtMethods);
271 }
272
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700273 const ImageSection& GetRuntimeMethodsSection() const {
274 return GetImageSection(kSectionRuntimeMethods);
275 }
276
Vladimir Markocd87c3e2017-09-05 13:11:57 +0100277 const ImageSection& GetImTablesSection() const {
278 return GetImageSection(kSectionImTables);
279 }
280
281 const ImageSection& GetIMTConflictTablesSection() const {
282 return GetImageSection(kSectionIMTConflictTables);
283 }
284
285 const ImageSection& GetDexCacheArraysSection() const {
286 return GetImageSection(kSectionDexCacheArrays);
287 }
288
289 const ImageSection& GetInternedStringsSection() const {
290 return GetImageSection(kSectionInternedStrings);
291 }
292
293 const ImageSection& GetClassTableSection() const {
294 return GetImageSection(kSectionClassTable);
295 }
296
297 const ImageSection& GetImageBitmapSection() const {
298 return GetImageSection(kSectionImageBitmap);
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700299 }
300
Vladimir Marko6121aa62018-07-06 10:04:35 +0100301 const ImageSection& GetImageRelocationsSection() const {
302 return GetImageSection(kSectionImageRelocations);
303 }
304
Chris Wailes0c61be42018-09-26 17:27:34 -0700305 const ImageSection& GetImageStringReferenceOffsetsSection() const {
306 return GetImageSection(kSectionStringReferenceOffsets);
307 }
308
Mathieu Chartier4a26f172016-01-26 14:26:18 -0800309 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Vladimir Markoc13fbd82018-06-04 16:16:28 +0100310 ObjPtr<mirror::Object> GetImageRoot(ImageRoot image_root) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700311 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4a26f172016-01-26 14:26:18 -0800312
313 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Vladimir Markoc13fbd82018-06-04 16:16:28 +0100314 ObjPtr<mirror::ObjectArray<mirror::Object>> GetImageRoots() const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700315 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700316
Alex Light53cb16b2014-06-12 11:26:29 -0700317 void RelocateImage(off_t delta);
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800318 void RelocateImageMethods(off_t delta);
319 void RelocateImageObjects(off_t delta);
Alex Light53cb16b2014-06-12 11:26:29 -0700320
Igor Murashkin46774762014-10-22 11:37:02 -0700321 bool CompilePic() const {
322 return compile_pic_ != 0;
323 }
324
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800325 bool IsPic() const {
326 return is_pic_ != 0;
327 }
328
329 uint32_t GetBootImageBegin() const {
330 return boot_image_begin_;
331 }
332
333 uint32_t GetBootImageSize() const {
334 return boot_image_size_;
335 }
336
337 uint32_t GetBootOatBegin() const {
338 return boot_oat_begin_;
339 }
340
341 uint32_t GetBootOatSize() const {
342 return boot_oat_size_;
343 }
344
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800345 StorageMode GetStorageMode() const {
346 return storage_mode_;
347 }
348
349 uint64_t GetDataSize() const {
350 return data_size_;
351 }
352
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800353 bool IsAppImage() const {
354 // App images currently require a boot image, if the size is non zero then it is an app image
355 // header.
356 return boot_image_size_ != 0u;
357 }
358
David Sehra49e0532017-08-25 08:05:29 -0700359 // Visit mirror::Objects in the section starting at base.
360 // TODO: Delete base parameter if it is always equal to GetImageBegin.
361 void VisitObjects(ObjectVisitor* visitor,
362 uint8_t* base,
363 PointerSize pointer_size) const
364 REQUIRES_SHARED(Locks::mutator_lock_);
365
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700366 // Visit ArtMethods in the section starting at base. Includes runtime methods.
367 // TODO: Delete base parameter if it is always equal to GetImageBegin.
Andreas Gampe542451c2016-07-26 09:02:02 -0700368 void VisitPackedArtMethods(ArtMethodVisitor* visitor,
369 uint8_t* base,
370 PointerSize pointer_size) const;
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700371
372 // Visit ArtMethods in the section starting at base.
373 // TODO: Delete base parameter if it is always equal to GetImageBegin.
374 void VisitPackedArtFields(ArtFieldVisitor* visitor, uint8_t* base) const;
375
376 template <typename Visitor>
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000377 void VisitPackedImTables(const Visitor& visitor,
378 uint8_t* base,
Andreas Gampe542451c2016-07-26 09:02:02 -0700379 PointerSize pointer_size) const;
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000380
381 template <typename Visitor>
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700382 void VisitPackedImtConflictTables(const Visitor& visitor,
383 uint8_t* base,
Andreas Gampe542451c2016-07-26 09:02:02 -0700384 PointerSize pointer_size) const;
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700385
Alex Light53cb16b2014-06-12 11:26:29 -0700386 private:
Ian Rogers13735952014-10-08 12:43:28 -0700387 static const uint8_t kImageMagic[4];
388 static const uint8_t kImageVersion[4];
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700389
David Brazdil7b49e6c2016-09-01 11:06:18 +0100390 static std::string GetLocationFromImageLocation(const std::string& image,
391 const std::string& extension) {
392 std::string filename = image;
393 if (filename.length() <= 3) {
394 filename += "." + extension;
395 } else {
396 filename.replace(filename.length() - 3, 3, extension);
397 }
398 return filename;
399 }
400
Ian Rogers13735952014-10-08 12:43:28 -0700401 uint8_t magic_[4];
402 uint8_t version_[4];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700403
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800404 // Required base address for mapping the image.
Ian Rogers30fab402012-01-23 15:43:46 -0800405 uint32_t image_begin_;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700406
Mathieu Chartier31e89252013-08-28 11:29:12 -0700407 // Image size, not page aligned.
408 uint32_t image_size_;
409
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800410 // Checksum of the oat file we link to for load time sanity check.
Brian Carlstrome24fa612011-09-29 00:53:55 -0700411 uint32_t oat_checksum_;
412
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800413 // Start address for oat file. Will be before oat_data_begin_ for .so files.
414 uint32_t oat_file_begin_;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700415
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800416 // Required oat address expected by image Method::GetCode() pointers.
417 uint32_t oat_data_begin_;
Brian Carlstrom16192862011-09-12 17:50:06 -0700418
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800419 // End of oat data address range for this image file.
420 uint32_t oat_data_end_;
421
422 // End of oat file address range. will be after oat_data_end_ for
423 // .so files. Used for positioning a following alloc spaces.
424 uint32_t oat_file_end_;
425
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800426 // Boot image begin and end (app image headers only).
427 uint32_t boot_image_begin_;
428 uint32_t boot_image_size_;
429
430 // Boot oat begin and end (app image headers only).
431 uint32_t boot_oat_begin_;
432 uint32_t boot_oat_size_;
433
434 // TODO: We should probably insert a boot image checksum for app images.
435
Alex Light53cb16b2014-06-12 11:26:29 -0700436 // The total delta that this image has been patched.
437 int32_t patch_delta_;
438
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800439 // Absolute address of an Object[] of objects needed to reinitialize from an image.
Brian Carlstrom16192862011-09-12 17:50:06 -0700440 uint32_t image_roots_;
441
Mathieu Chartiere401d142015-04-22 13:56:20 -0700442 // Pointer size, this affects the size of the ArtMethods.
443 uint32_t pointer_size_;
444
Igor Murashkin46774762014-10-22 11:37:02 -0700445 // Boolean (0 or 1) to denote if the image was compiled with --compile-pic option
446 const uint32_t compile_pic_;
447
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800448 // Boolean (0 or 1) to denote if the image can be mapped at a random address, this only refers to
449 // the .art file. Currently, app oat files do not depend on their app image. There are no pointers
450 // from the app oat code to the app image.
451 const uint32_t is_pic_;
452
Mathieu Chartier67ad20e2015-12-09 15:41:09 -0800453 // Image section sizes/offsets correspond to the uncompressed form.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700454 ImageSection sections_[kSectionCount];
455
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800456 // Image methods, may be inside of the boot image for app images.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700457 uint64_t image_methods_[kImageMethodsCount];
458
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800459 // Storage method for the image, the image may be compressed.
460 StorageMode storage_mode_;
461
462 // Data size for the image data excluding the bitmap and the header. For compressed images, this
463 // is the compressed size in the file.
464 uint32_t data_size_;
465
Vladimir Marko74527972016-11-29 15:57:32 +0000466 friend class linker::ImageWriter;
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700467};
468
Chris Wailes0c61be42018-09-26 17:27:34 -0700469/*
470 * Tags the last bit. Used by AppImage logic to differentiate between managed
471 * and native references.
472 */
473template<typename T>
474T SetNativeRefTag(T val) {
475 static_assert(std::is_integral<T>::value, "Expected integral type.");
476
477 return val | 1u;
478}
479
480/*
481 * Retrieves the value of the last bit. Used by AppImage logic to
482 * differentiate between managed and native references.
483 */
484template<typename T>
485bool HasNativeRefTag(T val) {
486 static_assert(std::is_integral<T>::value, "Expected integral type.");
487
488 return (val & 1u) == 1u;
489}
490
491/*
492 * Sets the last bit of the value to 0. Used by AppImage logic to
493 * differentiate between managed and native references.
494 */
495template<typename T>
496T ClearNativeRefTag(T val) {
497 static_assert(std::is_integral<T>::value, "Expected integral type.");
498
499 return val & ~1u;
500}
501
Mathieu Chartiere401d142015-04-22 13:56:20 -0700502std::ostream& operator<<(std::ostream& os, const ImageHeader::ImageMethod& policy);
503std::ostream& operator<<(std::ostream& os, const ImageHeader::ImageRoot& policy);
504std::ostream& operator<<(std::ostream& os, const ImageHeader::ImageSections& section);
505std::ostream& operator<<(std::ostream& os, const ImageSection& section);
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800506std::ostream& operator<<(std::ostream& os, const ImageHeader::StorageMode& mode);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700507
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700508} // namespace art
509
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700510#endif // ART_RUNTIME_IMAGE_H_