@@ -38,13 +38,18 @@ class NaClBitcodeHeaderField {
38
38
// Defines the ID associated with the value. Valid values are in
39
39
// {0x0, ..., 0xFFF}
40
40
typedef enum {
41
- kInvalid = 0 , // KUnknownType.
42
- kPNaClVersion = 1 // kUint32.
41
+ kInvalid = 0 , // KUnknownType.
42
+ kPNaClVersion = 1 , // kUint32Type.
43
+ kAlignBitcodeRecords = 2 , // kFlagType.
44
+ kTag_MAX = kAlignBitcodeRecords
43
45
} Tag;
44
46
// Defines the type of value.
45
47
typedef enum {
46
48
kBufferType , // Buffer of form uint8_t[len].
47
- kUInt32Type
49
+ kUInt32Type ,
50
+ kFlagType ,
51
+ kUnknownType ,
52
+ kFieldType_MAX = kUnknownType
48
53
} FieldType;
49
54
// Defines the number of bytes in a (32-bit) word.
50
55
static const int WordSize = 4 ;
@@ -55,6 +60,9 @@ class NaClBitcodeHeaderField {
55
60
// Create an invalid header field.
56
61
NaClBitcodeHeaderField ();
57
62
63
+ // Creates a header field where MyID is a flag.
64
+ NaClBitcodeHeaderField (Tag MyID);
65
+
58
66
// Create a header field with an uint32_t value.
59
67
NaClBitcodeHeaderField (Tag MyID, uint32_t value);
60
68
@@ -78,6 +86,18 @@ class NaClBitcodeHeaderField {
78
86
// / \brief Read field from Buf[BufLen].
79
87
bool Read (const uint8_t *Buf, size_t BufLen);
80
88
89
+ // / \brief Returns string describing ID of field.
90
+ static const char *IDName (Tag ID);
91
+ const char *IDName () const {
92
+ return IDName (ID);
93
+ }
94
+
95
+ // / \brief Returns string describing type of field.
96
+ static const char *TypeName (FieldType FType);
97
+ const char *TypeName () const {
98
+ return TypeName (FType);
99
+ }
100
+
81
101
// / \brief Returns string describing field.
82
102
std::string Contents () const ;
83
103
@@ -108,8 +128,11 @@ class NaClBitcodeHeaderField {
108
128
FixedSubfield EncodeTypedID () const { return (ID << 4 ) | FType; }
109
129
// Extract out ID and Type from a fixed subfield.
110
130
void DecodeTypedID (FixedSubfield Subfield, Tag &ID, FieldType &FType) {
111
- ID = static_cast <Tag>(Subfield >> 4 );
112
- FType = static_cast <FieldType>(Subfield & 0xF );
131
+ FixedSubfield PossibleID = Subfield >> 4 ;
132
+ ID = (PossibleID > kTag_MAX ? kInvalid : static_cast <Tag>(PossibleID));
133
+ FixedSubfield PossibleFType = Subfield & 0xF ;
134
+ FType = (PossibleFType > kFieldType_MAX
135
+ ? kUnknownType : static_cast <FieldType>(PossibleFType));
113
136
}
114
137
// Combined size of the fixed subfields
115
138
const static size_t kTagLenSize = 2 * sizeof (FixedSubfield);
@@ -144,6 +167,8 @@ class NaClBitcodeHeader {
144
167
bool IsReadableFlag;
145
168
// Defines the PNaCl version defined by the header file.
146
169
uint32_t PNaClVersion;
170
+ // Byte align bitcode records when nonzero.
171
+ bool AlignBitcodeRecords = false ;
147
172
148
173
public:
149
174
static const int WordSize = NaClBitcodeHeaderField::WordSize;
@@ -173,7 +198,7 @@ class NaClBitcodeHeader {
173
198
// / field.
174
199
// /
175
200
// / Returns false if able to read (all of) the bitcode header.
176
- bool Read (const unsigned char *& BufPtr, const unsigned char *& BufEnd);
201
+ bool Read (const unsigned char *BufPtr, const unsigned char *BufEnd);
177
202
178
203
// \brief Read the PNaCl bitcode header, recording the fields found
179
204
// in the header. Returns false if able to read (all of) the bitcode header.
@@ -209,6 +234,9 @@ class NaClBitcodeHeader {
209
234
// / \brief Returns the PNaClVersion, as defined by the header.
210
235
uint32_t GetPNaClVersion () const { return PNaClVersion; }
211
236
237
+ // / \brief Returns if one should byte align bitcode records.
238
+ bool getAlignBitcodeRecords () const { return AlignBitcodeRecords; }
239
+
212
240
private:
213
241
// Reads and verifies the first 8 bytes of the header, consisting
214
242
// of the magic number 'PEXE', and the value defining the number
0 commit comments