Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #ifndef ART_SRC_IMAGE_H_ |
| 4 | #define ART_SRC_IMAGE_H_ |
| 5 | |
| 6 | #include <string.h> |
| 7 | |
| 8 | #include "globals.h" |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 9 | #include "object.h" |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 10 | |
| 11 | namespace art { |
| 12 | |
| 13 | // header of image files written by ImageWriter, read and validated by Space. |
| 14 | class ImageHeader { |
| 15 | public: |
| 16 | ImageHeader() {} |
| 17 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 18 | ImageHeader(uint32_t base_addr, uint32_t intern_addr) |
| 19 | : base_addr_(base_addr), intern_addr_(intern_addr) { |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 20 | memcpy(magic_, kImageMagic, sizeof(kImageMagic)); |
| 21 | memcpy(version_, kImageVersion, sizeof(kImageVersion)); |
| 22 | } |
| 23 | |
| 24 | bool IsValid() { |
| 25 | if (memcmp(magic_, kImageMagic, sizeof(kImageMagic) != 0)) { |
| 26 | return false; |
| 27 | } |
| 28 | if (memcmp(version_, kImageVersion, sizeof(kImageVersion) != 0)) { |
| 29 | return false; |
| 30 | } |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | byte* GetBaseAddr() const { |
| 35 | return reinterpret_cast<byte*>(base_addr_); |
| 36 | } |
| 37 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 38 | ObjectArray<Object>* GetInternedArray() const { |
| 39 | return reinterpret_cast<ObjectArray<Object>*>(intern_addr_); |
| 40 | } |
| 41 | |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 42 | private: |
| 43 | static const byte kImageMagic[4]; |
| 44 | static const byte kImageVersion[4]; |
| 45 | |
| 46 | byte magic_[4]; |
| 47 | byte version_[4]; |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 48 | |
| 49 | // required base address for mapping the image. |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 50 | uint32_t base_addr_; |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 51 | |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 52 | // absolute address of an Object[] of Strings to InternTable::RegisterStrong. |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 53 | // TODO: remove after interning all Strings in image |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 54 | uint32_t intern_addr_; |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | } // namespace art |
| 58 | |
| 59 | #endif // ART_SRC_IMAGE_H_ |