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 | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 18 | ImageHeader(uint32_t base_addr, uint32_t image_roots) |
| 19 | : base_addr_(base_addr), image_roots_(image_roots) { |
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 | |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 24 | bool IsValid() const { |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 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 | |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 34 | const char* GetMagic() const { |
| 35 | CHECK(IsValid()); |
| 36 | return reinterpret_cast<const char*>(magic_); |
| 37 | } |
| 38 | |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 39 | byte* GetBaseAddr() const { |
| 40 | return reinterpret_cast<byte*>(base_addr_); |
| 41 | } |
| 42 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 43 | enum ImageRoot { |
| 44 | kJniStubArray, |
Ian Rogers | ff1ed47 | 2011-09-20 13:46:24 -0700 | [diff] [blame] | 45 | kCalleeSaveMethod, |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 46 | kImageRootsMax, |
| 47 | }; |
| 48 | |
| 49 | Object* GetImageRoot(ImageRoot image_root) const { |
| 50 | return reinterpret_cast<ObjectArray<Object>*>(image_roots_)->Get(image_root); |
| 51 | } |
| 52 | |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 53 | private: |
| 54 | static const byte kImageMagic[4]; |
| 55 | static const byte kImageVersion[4]; |
| 56 | |
| 57 | byte magic_[4]; |
| 58 | byte version_[4]; |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 59 | |
| 60 | // required base address for mapping the image. |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 61 | uint32_t base_addr_; |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 62 | |
| 63 | // absolute address of an Object[] of objects needed to reinitialize from an image |
| 64 | uint32_t image_roots_; |
| 65 | |
| 66 | friend class ImageWriter; |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | } // namespace art |
| 70 | |
| 71 | #endif // ART_SRC_IMAGE_H_ |