blob: 00f72bad20598013221e3cfa87a1bf76b0933417 [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 Carlstroma663ea52011-08-19 23:33:41 -070018 ImageHeader(uint32_t base_addr, uint32_t intern_addr)
19 : base_addr_(base_addr), intern_addr_(intern_addr) {
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070020 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 Carlstroma663ea52011-08-19 23:33:41 -070038 ObjectArray<Object>* GetInternedArray() const {
39 return reinterpret_cast<ObjectArray<Object>*>(intern_addr_);
40 }
41
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070042 private:
43 static const byte kImageMagic[4];
44 static const byte kImageVersion[4];
45
46 byte magic_[4];
47 byte version_[4];
Brian Carlstroma663ea52011-08-19 23:33:41 -070048
49 // required base address for mapping the image.
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070050 uint32_t base_addr_;
Brian Carlstroma663ea52011-08-19 23:33:41 -070051
Elliott Hughescf4c6c42011-09-01 15:16:42 -070052 // absolute address of an Object[] of Strings to InternTable::RegisterStrong.
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070053 // TODO: remove after interning all Strings in image
Brian Carlstroma663ea52011-08-19 23:33:41 -070054 uint32_t intern_addr_;
Brian Carlstrom4a289ed2011-08-16 17:17:49 -070055};
56
57} // namespace art
58
59#endif // ART_SRC_IMAGE_H_