blob: bd8bc28e0c0146b56e9f64e9f2ef235fae9cf6c8 [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),
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800111 storage_mode_(kDefaultStorageMode),
112 data_size_(0) {}
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700113
Ian Rogers30fab402012-01-23 15:43:46 -0800114 ImageHeader(uint32_t image_begin,
Mathieu Chartier763a31e2015-11-16 16:05:55 -0800115 uint32_t image_size,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700116 ImageSection* sections,
Brian Carlstrome24fa612011-09-29 00:53:55 -0700117 uint32_t image_roots,
118 uint32_t oat_checksum,
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800119 uint32_t oat_file_begin,
120 uint32_t oat_data_begin,
121 uint32_t oat_data_end,
Igor Murashkin46774762014-10-22 11:37:02 -0700122 uint32_t oat_file_end,
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800123 uint32_t boot_image_begin,
124 uint32_t boot_image_size,
125 uint32_t boot_oat_begin,
126 uint32_t boot_oat_size,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700127 uint32_t pointer_size,
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800128 StorageMode storage_mode,
129 size_t data_size);
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700130
Brian Carlstrom68708f52013-09-03 14:15:31 -0700131 bool IsValid() const;
132 const char* GetMagic() const;
Brian Carlstrom78128a62011-09-15 17:21:19 -0700133
Ian Rogers13735952014-10-08 12:43:28 -0700134 uint8_t* GetImageBegin() const {
135 return reinterpret_cast<uint8_t*>(image_begin_);
Brian Carlstrome24fa612011-09-29 00:53:55 -0700136 }
137
Mathieu Chartier31e89252013-08-28 11:29:12 -0700138 size_t GetImageSize() const {
139 return static_cast<uint32_t>(image_size_);
140 }
141
Brian Carlstrome24fa612011-09-29 00:53:55 -0700142 uint32_t GetOatChecksum() const {
143 return oat_checksum_;
144 }
145
Brian Carlstroma85b8372012-10-18 17:00:32 -0700146 void SetOatChecksum(uint32_t oat_checksum) {
147 oat_checksum_ = oat_checksum;
148 }
149
Mathieu Chartier5351da02016-02-17 16:19:53 -0800150 // The location that the oat file was expected to be when the image was created. The actual
151 // oat file may be at a different location for application images.
Ian Rogers13735952014-10-08 12:43:28 -0700152 uint8_t* GetOatFileBegin() const {
153 return reinterpret_cast<uint8_t*>(oat_file_begin_);
Brian Carlstrome24fa612011-09-29 00:53:55 -0700154 }
155
Ian Rogers13735952014-10-08 12:43:28 -0700156 uint8_t* GetOatDataBegin() const {
157 return reinterpret_cast<uint8_t*>(oat_data_begin_);
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800158 }
159
Ian Rogers13735952014-10-08 12:43:28 -0700160 uint8_t* GetOatDataEnd() const {
161 return reinterpret_cast<uint8_t*>(oat_data_end_);
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800162 }
163
Ian Rogers13735952014-10-08 12:43:28 -0700164 uint8_t* GetOatFileEnd() const {
165 return reinterpret_cast<uint8_t*>(oat_file_end_);
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700166 }
167
Andreas Gampebda1d602016-08-29 17:43:45 -0700168 PointerSize GetPointerSize() const;
Andreas Gampe542451c2016-07-26 09:02:02 -0700169
170 uint32_t GetPointerSizeUnchecked() const {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700171 return pointer_size_;
172 }
173
Vladimir Marko4df2d802018-09-27 16:42:44 +0000174 int32_t GetPatchDelta() const {
Alex Light53cb16b2014-06-12 11:26:29 -0700175 return patch_delta_;
176 }
177
Vladimir Marko4df2d802018-09-27 16:42:44 +0000178 void SetPatchDelta(int32_t patch_delta) {
Alex Klyubind1d5c952017-12-15 12:57:33 -0800179 patch_delta_ = patch_delta;
180 }
181
Nicolas Geoffray9583fbc2014-02-28 15:21:07 +0000182 static std::string GetOatLocationFromImageLocation(const std::string& image) {
David Brazdil7b49e6c2016-09-01 11:06:18 +0100183 return GetLocationFromImageLocation(image, "oat");
184 }
185
186 static std::string GetVdexLocationFromImageLocation(const std::string& image) {
187 return GetLocationFromImageLocation(image, "vdex");
Nicolas Geoffray9583fbc2014-02-28 15:21:07 +0000188 }
189
Mathieu Chartiere401d142015-04-22 13:56:20 -0700190 enum ImageMethod {
Ian Rogers19846512012-02-24 11:42:47 -0800191 kResolutionMethod,
Jeff Hao88474b42013-10-23 16:24:40 -0700192 kImtConflictMethod,
Mathieu Chartier2d2621a2014-10-23 16:48:06 -0700193 kImtUnimplementedMethod,
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100194 kSaveAllCalleeSavesMethod,
195 kSaveRefsOnlyMethod,
196 kSaveRefsAndArgsMethod,
Vladimir Marko952dbb12016-07-28 12:01:51 +0100197 kSaveEverythingMethod,
Mingyao Yang0a87a652017-04-12 13:43:15 -0700198 kSaveEverythingMethodForClinit,
199 kSaveEverythingMethodForSuspendCheck,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700200 kImageMethodsCount, // Number of elements in enum.
201 };
202
203 enum ImageRoot {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700204 kDexCaches,
Brian Carlstrom34f426c2011-10-04 12:58:02 -0700205 kClassRoots,
Vladimir Markoc13fbd82018-06-04 16:16:28 +0100206 kOomeWhenThrowingException, // Pre-allocated OOME when throwing exception.
207 kOomeWhenThrowingOome, // Pre-allocated OOME when throwing OOME.
208 kOomeWhenHandlingStackOverflow, // Pre-allocated OOME when handling StackOverflowError.
209 kNoClassDefFoundError, // Pre-allocated NoClassDefFoundError.
Vladimir Markof75613c2018-06-05 12:51:04 +0100210 kSpecialRoots, // Different for boot image and app image, see aliases below.
Brian Carlstrom16192862011-09-12 17:50:06 -0700211 kImageRootsMax,
Vladimir Markof75613c2018-06-05 12:51:04 +0100212
213 // Aliases.
214 kAppImageClassLoader = kSpecialRoots, // The class loader used to build the app image.
215 kBootImageLiveObjects = kSpecialRoots, // Array of boot image objects that must be kept live.
Brian Carlstrom16192862011-09-12 17:50:06 -0700216 };
217
Chris Wailes0c61be42018-09-26 17:27:34 -0700218 /*
219 * This describes the number and ordering of sections inside of Boot
220 * and App Images. It is very important that changes to this struct
221 * are reflected in the compiler and loader.
222 *
223 * See:
224 * - ImageWriter::ImageInfo::CreateImageSections()
225 * - ImageWriter::Write()
226 * - ImageWriter::AllocMemory()
227 */
Mathieu Chartiere401d142015-04-22 13:56:20 -0700228 enum ImageSections {
229 kSectionObjects,
230 kSectionArtFields,
231 kSectionArtMethods,
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700232 kSectionRuntimeMethods,
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000233 kSectionImTables,
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700234 kSectionIMTConflictTables,
Vladimir Marko05792b92015-08-03 11:56:49 +0100235 kSectionDexCacheArrays,
Mathieu Chartierd39645e2015-06-09 17:50:29 -0700236 kSectionInternedStrings,
Mathieu Chartier208a5cb2015-12-02 15:44:07 -0800237 kSectionClassTable,
Chris Wailes0c61be42018-09-26 17:27:34 -0700238 kSectionStringReferenceOffsets,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700239 kSectionImageBitmap,
Vladimir Marko6121aa62018-07-06 10:04:35 +0100240 kSectionImageRelocations,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700241 kSectionCount, // Number of elements in enum.
242 };
243
Vladimir Markof75613c2018-06-05 12:51:04 +0100244 static size_t NumberOfImageRoots(bool app_image ATTRIBUTE_UNUSED) {
245 // At the moment, boot image and app image have the same number of roots,
246 // though the meaning of the kSpecialRoots is different.
247 return kImageRootsMax;
Vladimir Markoeca3eda2016-11-09 16:26:44 +0000248 }
249
Mathieu Chartiere401d142015-04-22 13:56:20 -0700250 ArtMethod* GetImageMethod(ImageMethod index) const;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700251
Vladimir Markocd87c3e2017-09-05 13:11:57 +0100252 const ImageSection& GetImageSection(ImageSections index) const {
253 DCHECK_LT(static_cast<size_t>(index), kSectionCount);
254 return sections_[index];
255 }
256
257 const ImageSection& GetObjectsSection() const {
258 return GetImageSection(kSectionObjects);
259 }
260
261 const ImageSection& GetFieldsSection() const {
262 return GetImageSection(ImageHeader::kSectionArtFields);
263 }
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700264
Mathieu Chartiere401d142015-04-22 13:56:20 -0700265 const ImageSection& GetMethodsSection() const {
266 return GetImageSection(kSectionArtMethods);
267 }
268
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700269 const ImageSection& GetRuntimeMethodsSection() const {
270 return GetImageSection(kSectionRuntimeMethods);
271 }
272
Vladimir Markocd87c3e2017-09-05 13:11:57 +0100273 const ImageSection& GetImTablesSection() const {
274 return GetImageSection(kSectionImTables);
275 }
276
277 const ImageSection& GetIMTConflictTablesSection() const {
278 return GetImageSection(kSectionIMTConflictTables);
279 }
280
281 const ImageSection& GetDexCacheArraysSection() const {
282 return GetImageSection(kSectionDexCacheArrays);
283 }
284
285 const ImageSection& GetInternedStringsSection() const {
286 return GetImageSection(kSectionInternedStrings);
287 }
288
289 const ImageSection& GetClassTableSection() const {
290 return GetImageSection(kSectionClassTable);
291 }
292
293 const ImageSection& GetImageBitmapSection() const {
294 return GetImageSection(kSectionImageBitmap);
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700295 }
296
Vladimir Marko6121aa62018-07-06 10:04:35 +0100297 const ImageSection& GetImageRelocationsSection() const {
298 return GetImageSection(kSectionImageRelocations);
299 }
300
Chris Wailes0c61be42018-09-26 17:27:34 -0700301 const ImageSection& GetImageStringReferenceOffsetsSection() const {
302 return GetImageSection(kSectionStringReferenceOffsets);
303 }
304
Mathieu Chartier4a26f172016-01-26 14:26:18 -0800305 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Vladimir Markoc13fbd82018-06-04 16:16:28 +0100306 ObjPtr<mirror::Object> GetImageRoot(ImageRoot image_root) const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700307 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier4a26f172016-01-26 14:26:18 -0800308
309 template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Vladimir Markoc13fbd82018-06-04 16:16:28 +0100310 ObjPtr<mirror::ObjectArray<mirror::Object>> GetImageRoots() const
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700311 REQUIRES_SHARED(Locks::mutator_lock_);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700312
Vladimir Marko4df2d802018-09-27 16:42:44 +0000313 void RelocateImage(int64_t delta);
314 void RelocateImageMethods(int64_t delta);
315 void RelocateImageObjects(int64_t delta);
Alex Light53cb16b2014-06-12 11:26:29 -0700316
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800317 uint32_t GetBootImageBegin() const {
318 return boot_image_begin_;
319 }
320
321 uint32_t GetBootImageSize() const {
322 return boot_image_size_;
323 }
324
325 uint32_t GetBootOatBegin() const {
326 return boot_oat_begin_;
327 }
328
329 uint32_t GetBootOatSize() const {
330 return boot_oat_size_;
331 }
332
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800333 StorageMode GetStorageMode() const {
334 return storage_mode_;
335 }
336
337 uint64_t GetDataSize() const {
338 return data_size_;
339 }
340
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800341 bool IsAppImage() const {
342 // App images currently require a boot image, if the size is non zero then it is an app image
343 // header.
344 return boot_image_size_ != 0u;
345 }
346
David Sehra49e0532017-08-25 08:05:29 -0700347 // Visit mirror::Objects in the section starting at base.
348 // TODO: Delete base parameter if it is always equal to GetImageBegin.
349 void VisitObjects(ObjectVisitor* visitor,
350 uint8_t* base,
351 PointerSize pointer_size) const
352 REQUIRES_SHARED(Locks::mutator_lock_);
353
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700354 // Visit ArtMethods in the section starting at base. Includes runtime methods.
355 // TODO: Delete base parameter if it is always equal to GetImageBegin.
Andreas Gampe542451c2016-07-26 09:02:02 -0700356 void VisitPackedArtMethods(ArtMethodVisitor* visitor,
357 uint8_t* base,
358 PointerSize pointer_size) const;
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700359
360 // Visit ArtMethods in the section starting at base.
361 // TODO: Delete base parameter if it is always equal to GetImageBegin.
362 void VisitPackedArtFields(ArtFieldVisitor* visitor, uint8_t* base) const;
363
364 template <typename Visitor>
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000365 void VisitPackedImTables(const Visitor& visitor,
366 uint8_t* base,
Andreas Gampe542451c2016-07-26 09:02:02 -0700367 PointerSize pointer_size) const;
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000368
369 template <typename Visitor>
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700370 void VisitPackedImtConflictTables(const Visitor& visitor,
371 uint8_t* base,
Andreas Gampe542451c2016-07-26 09:02:02 -0700372 PointerSize pointer_size) const;
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700373
Alex Light53cb16b2014-06-12 11:26:29 -0700374 private:
Ian Rogers13735952014-10-08 12:43:28 -0700375 static const uint8_t kImageMagic[4];
376 static const uint8_t kImageVersion[4];
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700377
David Brazdil7b49e6c2016-09-01 11:06:18 +0100378 static std::string GetLocationFromImageLocation(const std::string& image,
379 const std::string& extension) {
380 std::string filename = image;
381 if (filename.length() <= 3) {
382 filename += "." + extension;
383 } else {
384 filename.replace(filename.length() - 3, 3, extension);
385 }
386 return filename;
387 }
388
Ian Rogers13735952014-10-08 12:43:28 -0700389 uint8_t magic_[4];
390 uint8_t version_[4];
Brian Carlstroma663ea52011-08-19 23:33:41 -0700391
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800392 // Required base address for mapping the image.
Ian Rogers30fab402012-01-23 15:43:46 -0800393 uint32_t image_begin_;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700394
Mathieu Chartier31e89252013-08-28 11:29:12 -0700395 // Image size, not page aligned.
396 uint32_t image_size_;
397
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800398 // Checksum of the oat file we link to for load time sanity check.
Brian Carlstrome24fa612011-09-29 00:53:55 -0700399 uint32_t oat_checksum_;
400
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800401 // Start address for oat file. Will be before oat_data_begin_ for .so files.
402 uint32_t oat_file_begin_;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700403
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800404 // Required oat address expected by image Method::GetCode() pointers.
405 uint32_t oat_data_begin_;
Brian Carlstrom16192862011-09-12 17:50:06 -0700406
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800407 // End of oat data address range for this image file.
408 uint32_t oat_data_end_;
409
410 // End of oat file address range. will be after oat_data_end_ for
411 // .so files. Used for positioning a following alloc spaces.
412 uint32_t oat_file_end_;
413
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800414 // Boot image begin and end (app image headers only).
415 uint32_t boot_image_begin_;
416 uint32_t boot_image_size_;
417
418 // Boot oat begin and end (app image headers only).
419 uint32_t boot_oat_begin_;
420 uint32_t boot_oat_size_;
421
422 // TODO: We should probably insert a boot image checksum for app images.
423
Alex Light53cb16b2014-06-12 11:26:29 -0700424 // The total delta that this image has been patched.
425 int32_t patch_delta_;
426
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800427 // Absolute address of an Object[] of objects needed to reinitialize from an image.
Brian Carlstrom16192862011-09-12 17:50:06 -0700428 uint32_t image_roots_;
429
Mathieu Chartiere401d142015-04-22 13:56:20 -0700430 // Pointer size, this affects the size of the ArtMethods.
431 uint32_t pointer_size_;
432
Mathieu Chartier67ad20e2015-12-09 15:41:09 -0800433 // Image section sizes/offsets correspond to the uncompressed form.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700434 ImageSection sections_[kSectionCount];
435
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800436 // Image methods, may be inside of the boot image for app images.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700437 uint64_t image_methods_[kImageMethodsCount];
438
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800439 // Storage method for the image, the image may be compressed.
440 StorageMode storage_mode_;
441
442 // Data size for the image data excluding the bitmap and the header. For compressed images, this
443 // is the compressed size in the file.
444 uint32_t data_size_;
445
Vladimir Marko74527972016-11-29 15:57:32 +0000446 friend class linker::ImageWriter;
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700447};
448
Chris Wailes0c61be42018-09-26 17:27:34 -0700449/*
450 * Tags the last bit. Used by AppImage logic to differentiate between managed
451 * and native references.
452 */
453template<typename T>
454T SetNativeRefTag(T val) {
455 static_assert(std::is_integral<T>::value, "Expected integral type.");
456
457 return val | 1u;
458}
459
460/*
461 * Retrieves the value of the last bit. Used by AppImage logic to
462 * differentiate between managed and native references.
463 */
464template<typename T>
465bool HasNativeRefTag(T val) {
466 static_assert(std::is_integral<T>::value, "Expected integral type.");
467
468 return (val & 1u) == 1u;
469}
470
471/*
472 * Sets the last bit of the value to 0. Used by AppImage logic to
473 * differentiate between managed and native references.
474 */
475template<typename T>
476T ClearNativeRefTag(T val) {
477 static_assert(std::is_integral<T>::value, "Expected integral type.");
478
479 return val & ~1u;
480}
481
Mathieu Chartiere401d142015-04-22 13:56:20 -0700482std::ostream& operator<<(std::ostream& os, const ImageHeader::ImageMethod& policy);
483std::ostream& operator<<(std::ostream& os, const ImageHeader::ImageRoot& policy);
484std::ostream& operator<<(std::ostream& os, const ImageHeader::ImageSections& section);
485std::ostream& operator<<(std::ostream& os, const ImageSection& section);
Mathieu Chartierceb07b32015-12-10 09:33:21 -0800486std::ostream& operator<<(std::ostream& os, const ImageHeader::StorageMode& mode);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700487
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700488} // namespace art
489
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700490#endif // ART_RUNTIME_IMAGE_H_