1 #ifndef LOADER_OBJECTFILE_H_
2 #define LOADER_OBJECTFILE_H_
8 const unsigned int FORMAT_ID = 2;
11 /// Offset of the identifier in the file.
12 unsigned int nameOffset;
13 /// Type ID of referenced object.
15 /// File-offset of the object's actual data.
16 unsigned int dataOffset;
20 /// File-relative offset of the referenced object's
22 unsigned int nameOffset;
23 /// Target position for linking/inlining.
24 unsigned int referenceOffset;
25 /// Nonzero if the object should be copied rather that
26 /// just writing a reference.
31 /// File-relative offset to the image's path string.
32 unsigned int pathOffset;
33 /// File-relative offset of the target position of the
34 /// image's reference.
35 unsigned int destOffset;
53 struct ObjectFileHeader {
57 /// Version ID of the object file format
58 /// For now it must match FORMAT_ID for the loader to be
60 /// Backwards compatibility might be implemented at some
61 /// point in the future, but don't bet on that ever
63 unsigned int versionId;
65 /// File-relative offsets of the export section's begin
66 /// and end respectively.
67 /// Exports are named and typed addresses within the
68 /// file. This is essentially an array of Export structs.
69 unsigned int exportsBegin;
70 unsigned int exportsEnd;
72 /// File-relative offsets of the externals section's
73 /// begin and end respectively.
74 /// Each external names an entity which must be linked in
75 /// for this object file to function properly. This is
76 /// essentially an array of External structs.
77 unsigned int externalsBegin;
78 unsigned int externalsEnd;
80 /// File-relative offsets of the image section's begin and
82 /// Denotes an array of Image structs.
83 unsigned int imagesBegin;
84 unsigned int imagesEnd;
86 /// File-relative offsets of the objet section's begin
87 /// and end respectively.
88 /// Each object begins with its type ID followed by its
89 /// size and finally the raw object data.
90 /// All referecte type fields should contain either a
91 /// file-relative offset or zero to indicate a null
93 /// This can be sen as a linked list where the next
94 /// object for a node can be obtained by adding the size
95 /// of to int and the object to the current node's
97 unsigned int objectsBegin;
98 unsigned int objectsEnd;
100 /// File-relative offsets of the array section's begin
101 /// and end respectively.
102 /// Each array consists of an unsigned integer indicating
103 /// its size followed by a boolean flag which is true if
104 /// the arrays consists of pointers followed by the data.
105 unsigned int arraysBegin;
106 unsigned int arraysEnd;
110 /// Check if there are any problems with the file header.
111 /// Throws a std::runtime_error on failure.
112 void IntegrityCheck(unsigned int fileSize) const;
113 Export *ExportsBegin();
114 Export *ExportsEnd();
115 External *ExternalsBegin();
116 External *ExternalsEnd();
117 Image *ImagesBegin();
119 Object *ObjectsBegin();
120 Object *ObjectsEnd();
121 Array *ArraysBegin();
128 unsigned int fsize) const;
131 struct LoadedExport {