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;
27 /// True if the object should be copied rather that
28 /// just writing a reference.
33 /// File-relative offset to the image's path string.
34 unsigned int pathOffset;
35 /// File-relative offset of the target position of the
36 /// image's reference.
37 unsigned int destOffset;
57 struct ObjectFileHeader {
61 /// Version ID of the object file format
62 /// For now it must match FORMAT_ID for the loader to be
64 /// Backwards compatibility might be implemented at some
65 /// point in the future, but don't bet on that ever
67 unsigned int versionId;
69 /// File-relative offsets of the export section's begin
70 /// and end respectively.
71 /// Exports are named and typed addresses within the
72 /// file. This is essentially an array of Export structs.
73 unsigned int exportsBegin;
74 unsigned int exportsEnd;
76 /// File-relative offsets of the externals section's
77 /// begin and end respectively.
78 /// Each external names an entity which must be linked in
79 /// for this object file to function properly. This is
80 /// essentially an array of External structs.
81 unsigned int externalsBegin;
82 unsigned int externalsEnd;
84 /// File-relative offsets of the image section's begin and
86 /// Denotes an array of Image structs.
87 unsigned int imagesBegin;
88 unsigned int imagesEnd;
90 /// File-relative offsets of the objet section's begin
91 /// and end respectively.
92 /// Each object begins with its type ID followed by its
93 /// size and finally the raw object data.
94 /// All referecte type fields should contain either a
95 /// file-relative offset or zero to indicate a null
97 /// This can be sen as a linked list where the next
98 /// object for a node can be obtained by adding the size
99 /// of to int and the object to the current node's
101 unsigned int objectsBegin;
102 unsigned int objectsEnd;
104 /// File-relative offsets of the array section's begin
105 /// and end respectively.
106 /// Each array consists of an unsigned integer indicating
107 /// its size followed by a boolean flag which is true if
108 /// the arrays consists of pointers followed by the data.
109 unsigned int arraysBegin;
110 unsigned int arraysEnd;
114 /// Check if there are any problems with the file header.
115 /// Throws a std::runtime_error on failure.
116 void IntegrityCheck(unsigned int fileSize) const;
117 Export *ExportsBegin();
118 Export *ExportsEnd();
119 External *ExternalsBegin();
120 External *ExternalsEnd();
121 Image *ImagesBegin();
123 Object *ObjectsBegin();
124 Object *ObjectsEnd();
125 Array *ArraysBegin();
132 unsigned int fsize) const;
135 struct LoadedExport {