blob: fdf6443ad66b359ca5d2879c2bc80dff478f0d1a [file] [log] [blame]
Brian Carlstrom4a289ed2011-08-16 17:17:49 -07001// 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 Carlstroma663ea52011-08-19 23:33:41 -07009#include "object.h"
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070010
11namespace art {
12
13// header of image files written by ImageWriter, read and validated by Space.
14class ImageHeader {
15 public:
16 ImageHeader() {}
17
Brian Carlstrom16192862011-09-12 17:50:06 -070018 ImageHeader(uint32_t base_addr, uint32_t image_roots)
19 : base_addr_(base_addr), image_roots_(image_roots) {
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070020 memcpy(magic_, kImageMagic, sizeof(kImageMagic));
21 memcpy(version_, kImageVersion, sizeof(kImageVersion));
22 }
23
Brian Carlstrom78128a62011-09-15 17:21:19 -070024 bool IsValid() const {
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070025 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 Carlstrom78128a62011-09-15 17:21:19 -070034 const char* GetMagic() const {
35 CHECK(IsValid());
36 return reinterpret_cast<const char*>(magic_);
37 }
38
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070039 byte* GetBaseAddr() const {
40 return reinterpret_cast<byte*>(base_addr_);
41 }
42
Brian Carlstrom16192862011-09-12 17:50:06 -070043 enum ImageRoot {
44 kJniStubArray,
Ian Rogersff1ed472011-09-20 13:46:24 -070045 kCalleeSaveMethod,
Brian Carlstrom16192862011-09-12 17:50:06 -070046 kImageRootsMax,
47 };
48
49 Object* GetImageRoot(ImageRoot image_root) const {
50 return reinterpret_cast<ObjectArray<Object>*>(image_roots_)->Get(image_root);
51 }
52
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070053 private:
54 static const byte kImageMagic[4];
55 static const byte kImageVersion[4];
56
57 byte magic_[4];
58 byte version_[4];
Brian Carlstroma663ea52011-08-19 23:33:41 -070059
60 // required base address for mapping the image.
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070061 uint32_t base_addr_;
Brian Carlstrom16192862011-09-12 17:50:06 -070062
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 Carlstrom4a289ed2011-08-16 17:17:49 -070067};
68
69} // namespace art
70
71#endif // ART_SRC_IMAGE_H_