1 //===-- llvm/Support/ARMWinEH.h - Windows on ARM EH Constants ---*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_SUPPORT_ARMWINEH_H
10 #define LLVM_SUPPORT_ARMWINEH_H
11
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/Support/Endian.h"
14
15 namespace llvm {
16 namespace ARM {
17 namespace WinEH {
18 enum class RuntimeFunctionFlag {
19 RFF_Unpacked, /// unpacked entry
20 RFF_Packed, /// packed entry
21 RFF_PackedFragment, /// packed entry representing a fragment
22 RFF_Reserved, /// reserved
23 };
24
25 enum class ReturnType {
26 RT_POP, /// return via pop {pc} (L flag must be set)
27 RT_B, /// 16-bit branch
28 RT_BW, /// 32-bit branch
29 RT_NoEpilogue, /// no epilogue (fragment)
30 };
31
32 /// RuntimeFunction - An entry in the table of procedure data (.pdata)
33 ///
34 /// This is ARM specific, but the Function Start RVA, Flag and
35 /// ExceptionInformationRVA fields work identically for ARM64.
36 ///
37 /// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
38 /// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
39 /// +---------------------------------------------------------------+
40 /// | Function Start RVA |
41 /// +-------------------+-+-+-+-----+-+---+---------------------+---+
42 /// | Stack Adjust |C|L|R| Reg |H|Ret| Function Length |Flg|
43 /// +-------------------+-+-+-+-----+-+---+---------------------+---+
44 ///
45 /// Flag : 2-bit field with the following meanings:
46 /// - 00 = packed unwind data not used; reamining bits point to .xdata record
47 /// - 01 = packed unwind data
48 /// - 10 = packed unwind data, function assumed to have no prologue; useful
49 /// for function fragments that are discontiguous with the start of the
50 /// function
51 /// - 11 = reserved
52 /// Function Length : 11-bit field providing the length of the entire function
53 /// in bytes, divided by 2; if the function is greater than
54 /// 4KB, a full .xdata record must be used instead
55 /// Ret : 2-bit field indicating how the function returns
56 /// - 00 = return via pop {pc} (the L bit must be set)
57 /// - 01 = return via 16-bit branch
58 /// - 10 = return via 32-bit branch
59 /// - 11 = no epilogue; useful for function fragments that may only contain a
60 /// prologue but the epilogue is elsewhere
61 /// H : 1-bit flag indicating whether the function "homes" the integer parameter
62 /// registers (r0-r3), allocating 16-bytes on the stack
63 /// Reg : 3-bit field indicating the index of the last saved non-volatile
64 /// register. If the R bit is set to 0, then only integer registers are
65 /// saved (r4-rN, where N is 4 + Reg). If the R bit is set to 1, then
66 /// only floating-point registers are being saved (d8-dN, where N is
67 /// 8 + Reg). The special case of the R bit being set to 1 and Reg equal
68 /// to 7 indicates that no registers are saved.
69 /// R : 1-bit flag indicating whether the non-volatile registers are integer or
70 /// floating-point. 0 indicates integer, 1 indicates floating-point. The
71 /// special case of the R-flag being set and Reg being set to 7 indicates
72 /// that no non-volatile registers are saved.
73 /// L : 1-bit flag indicating whether the function saves/restores the link
74 /// register (LR)
75 /// C : 1-bit flag indicating whether the function includes extra instructions
76 /// to setup a frame chain for fast walking. If this flag is set, r11 is
77 /// implicitly added to the list of saved non-volatile integer registers.
78 /// Stack Adjust : 10-bit field indicating the number of bytes of stack that are
79 /// allocated for this function. Only values between 0x000 and
80 /// 0x3f3 can be directly encoded. If the value is 0x3f4 or
81 /// greater, then the low 4 bits have special meaning as follows:
82 /// - Bit 0-1
83 /// indicate the number of words' of adjustment (1-4), minus 1
84 /// - Bit 2
85 /// indicates if the prologue combined adjustment into push
86 /// - Bit 3
87 /// indicates if the epilogue combined adjustment into pop
88 ///
89 /// RESTRICTIONS:
90 /// - IF C is SET:
91 /// + L flag must be set since frame chaining requires r11 and lr
92 /// + r11 must NOT be included in the set of registers described by Reg
93 /// - IF Ret is 0:
94 /// + L flag must be set
95
96 // NOTE: RuntimeFunction is meant to be a simple class that provides raw access
97 // to all fields in the structure. The accessor methods reflect the names of
98 // the bitfields that they correspond to. Although some obvious simplifications
99 // are possible via merging of methods, it would prevent the use of this class
100 // to fully inspect the contents of the data structure which is particularly
101 // useful for scenarios such as llvm-readobj to aid in testing.
102
103 class RuntimeFunction {
104 public:
105 const support::ulittle32_t BeginAddress;
106 const support::ulittle32_t UnwindData;
107
RuntimeFunction(const support::ulittle32_t * Data)108 RuntimeFunction(const support::ulittle32_t *Data)
109 : BeginAddress(Data[0]), UnwindData(Data[1]) {}
110
RuntimeFunction(const support::ulittle32_t BeginAddress,const support::ulittle32_t UnwindData)111 RuntimeFunction(const support::ulittle32_t BeginAddress,
112 const support::ulittle32_t UnwindData)
113 : BeginAddress(BeginAddress), UnwindData(UnwindData) {}
114
Flag()115 RuntimeFunctionFlag Flag() const {
116 return RuntimeFunctionFlag(UnwindData & 0x3);
117 }
118
ExceptionInformationRVA()119 uint32_t ExceptionInformationRVA() const {
120 assert(Flag() == RuntimeFunctionFlag::RFF_Unpacked &&
121 "unpacked form required for this operation");
122 return (UnwindData & ~0x3);
123 }
124
PackedUnwindData()125 uint32_t PackedUnwindData() const {
126 assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
127 Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
128 "packed form required for this operation");
129 return (UnwindData & ~0x3);
130 }
FunctionLength()131 uint32_t FunctionLength() const {
132 assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
133 Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
134 "packed form required for this operation");
135 return (((UnwindData & 0x00001ffc) >> 2) << 1);
136 }
Ret()137 ReturnType Ret() const {
138 assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
139 Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
140 "packed form required for this operation");
141 assert(((UnwindData & 0x00006000) || L()) && "L must be set to 1");
142 return ReturnType((UnwindData & 0x00006000) >> 13);
143 }
H()144 bool H() const {
145 assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
146 Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
147 "packed form required for this operation");
148 return ((UnwindData & 0x00008000) >> 15);
149 }
Reg()150 uint8_t Reg() const {
151 assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
152 Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
153 "packed form required for this operation");
154 return ((UnwindData & 0x00070000) >> 16);
155 }
R()156 bool R() const {
157 assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
158 Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
159 "packed form required for this operation");
160 return ((UnwindData & 0x00080000) >> 19);
161 }
L()162 bool L() const {
163 assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
164 Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
165 "packed form required for this operation");
166 return ((UnwindData & 0x00100000) >> 20);
167 }
C()168 bool C() const {
169 assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
170 Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
171 "packed form required for this operation");
172 assert(((~UnwindData & 0x00200000) || L()) &&
173 "L flag must be set, chaining requires r11 and LR");
174 assert(((~UnwindData & 0x00200000) || (Reg() < 7) || R()) &&
175 "r11 must not be included in Reg; C implies r11");
176 return ((UnwindData & 0x00200000) >> 21);
177 }
StackAdjust()178 uint16_t StackAdjust() const {
179 assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
180 Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
181 "packed form required for this operation");
182 return ((UnwindData & 0xffc00000) >> 22);
183 }
184 };
185
186 /// PrologueFolding - pseudo-flag derived from Stack Adjust indicating that the
187 /// prologue has stack adjustment combined into the push
PrologueFolding(const RuntimeFunction & RF)188 inline bool PrologueFolding(const RuntimeFunction &RF) {
189 return RF.StackAdjust() >= 0x3f4 && (RF.StackAdjust() & 0x4);
190 }
191 /// Epilogue - pseudo-flag derived from Stack Adjust indicating that the
192 /// epilogue has stack adjustment combined into the pop
EpilogueFolding(const RuntimeFunction & RF)193 inline bool EpilogueFolding(const RuntimeFunction &RF) {
194 return RF.StackAdjust() >= 0x3f4 && (RF.StackAdjust() & 0x8);
195 }
196 /// StackAdjustment - calculated stack adjustment in words. The stack
197 /// adjustment should be determined via this function to account for the special
198 /// handling the special encoding when the value is >= 0x3f4.
StackAdjustment(const RuntimeFunction & RF)199 inline uint16_t StackAdjustment(const RuntimeFunction &RF) {
200 uint16_t Adjustment = RF.StackAdjust();
201 if (Adjustment >= 0x3f4)
202 return (Adjustment & 0x3) ? ((Adjustment & 0x3) << 2) - 1 : 0;
203 return Adjustment;
204 }
205
206 /// SavedRegisterMask - Utility function to calculate the set of saved general
207 /// purpose (r0-r15) and VFP (d0-d31) registers.
208 std::pair<uint16_t, uint32_t> SavedRegisterMask(const RuntimeFunction &RF);
209
210 /// RuntimeFunctionARM64 - An entry in the table of procedure data (.pdata)
211 ///
212 /// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
213 /// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
214 /// +---------------------------------------------------------------+
215 /// | Function Start RVA |
216 /// +-----------------+---+-+-------+-----+---------------------+---+
217 /// | Frame Size |CR |H| RegI |RegF | Function Length |Flg|
218 /// +-----------------+---+-+-------+-----+---------------------+---+
219 ///
220 /// See https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling
221 /// for the full reference for this struct.
222
223 class RuntimeFunctionARM64 {
224 public:
225 const support::ulittle32_t BeginAddress;
226 const support::ulittle32_t UnwindData;
227
RuntimeFunctionARM64(const support::ulittle32_t * Data)228 RuntimeFunctionARM64(const support::ulittle32_t *Data)
229 : BeginAddress(Data[0]), UnwindData(Data[1]) {}
230
RuntimeFunctionARM64(const support::ulittle32_t BeginAddress,const support::ulittle32_t UnwindData)231 RuntimeFunctionARM64(const support::ulittle32_t BeginAddress,
232 const support::ulittle32_t UnwindData)
233 : BeginAddress(BeginAddress), UnwindData(UnwindData) {}
234
Flag()235 RuntimeFunctionFlag Flag() const {
236 return RuntimeFunctionFlag(UnwindData & 0x3);
237 }
238
ExceptionInformationRVA()239 uint32_t ExceptionInformationRVA() const {
240 assert(Flag() == RuntimeFunctionFlag::RFF_Unpacked &&
241 "unpacked form required for this operation");
242 return (UnwindData & ~0x3);
243 }
244
PackedUnwindData()245 uint32_t PackedUnwindData() const {
246 assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
247 Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
248 "packed form required for this operation");
249 return (UnwindData & ~0x3);
250 }
FunctionLength()251 uint32_t FunctionLength() const {
252 assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
253 Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
254 "packed form required for this operation");
255 return (((UnwindData & 0x00001ffc) >> 2) << 2);
256 }
RegF()257 uint8_t RegF() const {
258 assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
259 Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
260 "packed form required for this operation");
261 return ((UnwindData & 0x0000e000) >> 13);
262 }
RegI()263 uint8_t RegI() const {
264 assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
265 Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
266 "packed form required for this operation");
267 return ((UnwindData & 0x000f0000) >> 16);
268 }
H()269 bool H() const {
270 assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
271 Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
272 "packed form required for this operation");
273 return ((UnwindData & 0x00100000) >> 20);
274 }
CR()275 uint8_t CR() const {
276 assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
277 Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
278 "packed form required for this operation");
279 return ((UnwindData & 0x600000) >> 21);
280 }
FrameSize()281 uint16_t FrameSize() const {
282 assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
283 Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
284 "packed form required for this operation");
285 return ((UnwindData & 0xff800000) >> 23);
286 }
287 };
288
289 /// ExceptionDataRecord - An entry in the table of exception data (.xdata)
290 ///
291 /// The format on ARM is:
292 ///
293 /// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
294 /// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
295 /// +-------+---------+-+-+-+---+-----------------------------------+
296 /// | C Wrd | Epi Cnt |F|E|X|Ver| Function Length |
297 /// +-------+--------+'-'-'-'---'---+-------------------------------+
298 /// | Reserved |Ex. Code Words| (Extended Epilogue Count) |
299 /// +-------+--------+--------------+-------------------------------+
300 ///
301 /// The format on ARM64 is:
302 ///
303 /// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
304 /// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
305 /// +---------+---------+-+-+---+-----------------------------------+
306 /// | C Wrd | Epi Cnt |E|X|Ver| Function Length |
307 /// +---------+------+--'-'-'---'---+-------------------------------+
308 /// | Reserved |Ex. Code Words| (Extended Epilogue Count) |
309 /// +-------+--------+--------------+-------------------------------+
310 ///
311 /// Function Length : 18-bit field indicating the total length of the function
312 /// in bytes divided by 2. If a function is larger than
313 /// 512KB, then multiple pdata and xdata records must be used.
314 /// Vers : 2-bit field describing the version of the remaining structure. Only
315 /// version 0 is currently defined (values 1-3 are not permitted).
316 /// X : 1-bit field indicating the presence of exception data
317 /// E : 1-bit field indicating that the single epilogue is packed into the
318 /// header
319 /// F : 1-bit field indicating that the record describes a function fragment
320 /// (implies that no prologue is present, and prologue processing should be
321 /// skipped) (ARM only)
322 /// Epilogue Count : 5-bit field that differs in meaning based on the E field.
323 ///
324 /// If E is set, then this field specifies the index of the
325 /// first unwind code describing the (only) epilogue.
326 ///
327 /// Otherwise, this field indicates the number of exception
328 /// scopes. If more than 31 scopes exist, then this field and
329 /// the Code Words field must both be set to 0 to indicate that
330 /// an extension word is required.
331 /// Code Words : 4-bit (5-bit on ARM64) field that specifies the number of
332 /// 32-bit words needed to contain all the unwind codes. If more
333 /// than 15 words (31 words on ARM64) are required, then this field
334 /// and the Epilogue Count field must both be set to 0 to indicate
335 /// that an extension word is required.
336 /// Extended Epilogue Count, Extended Code Words :
337 /// Valid only if Epilog Count and Code Words are both
338 /// set to 0. Provides an 8-bit extended code word
339 /// count and 16-bits for epilogue count
340 ///
341 /// The epilogue scope format on ARM is:
342 ///
343 /// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
344 /// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
345 /// +----------------+------+---+---+-------------------------------+
346 /// | Ep Start Idx | Cond |Res| Epilogue Start Offset |
347 /// +----------------+------+---+-----------------------------------+
348 ///
349 /// The epilogue scope format on ARM64 is:
350 ///
351 /// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
352 /// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
353 /// +-------------------+-------+---+-------------------------------+
354 /// | Ep Start Idx | Res | Epilogue Start Offset |
355 /// +-------------------+-------+-----------------------------------+
356 ///
357 /// If the E bit is unset in the header, the header is followed by a series of
358 /// epilogue scopes, which are sorted by their offset.
359 ///
360 /// Epilogue Start Offset: 18-bit field encoding the offset of epilogue relative
361 /// to the start of the function in bytes divided by two
362 /// Res : 2-bit field reserved for future expansion (must be set to 0)
363 /// Condition : (ARM only) 4-bit field providing the condition under which the
364 /// epilogue is executed. Unconditional epilogues should set this
365 /// field to 0xe. Epilogues must be entirely conditional or
366 /// unconditional, and in Thumb-2 mode. The epilogue begins with
367 /// the first instruction after the IT opcode.
368 /// Epilogue Start Index : 8-bit field indicating the byte index of the first
369 /// unwind code describing the epilogue
370 ///
371 /// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
372 /// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
373 /// +---------------+---------------+---------------+---------------+
374 /// | Unwind Code 3 | Unwind Code 2 | Unwind Code 1 | Unwind Code 0 |
375 /// +---------------+---------------+---------------+---------------+
376 ///
377 /// Following the epilogue scopes, the byte code describing the unwinding
378 /// follows. This is padded to align up to word alignment. Bytes are stored in
379 /// little endian.
380 ///
381 /// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
382 /// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
383 /// +---------------------------------------------------------------+
384 /// | Exception Handler RVA (requires X = 1) |
385 /// +---------------------------------------------------------------+
386 /// | (possibly followed by data required for exception handler) |
387 /// +---------------------------------------------------------------+
388 ///
389 /// If the X bit is set in the header, the unwind byte code is followed by the
390 /// exception handler information. This constants of one Exception Handler RVA
391 /// which is the address to the exception handler, followed immediately by the
392 /// variable length data associated with the exception handler.
393 ///
394
395 struct EpilogueScope {
396 const support::ulittle32_t ES;
397
EpilogueScopeEpilogueScope398 EpilogueScope(const support::ulittle32_t Data) : ES(Data) {}
399 // Same for both ARM and AArch64.
EpilogueStartOffsetEpilogueScope400 uint32_t EpilogueStartOffset() const {
401 return (ES & 0x0003ffff);
402 }
403
404 // Different implementations for ARM and AArch64.
ResARMEpilogueScope405 uint8_t ResARM() const {
406 return ((ES & 0x000c0000) >> 18);
407 }
408
ResAArch64EpilogueScope409 uint8_t ResAArch64() const {
410 return ((ES & 0x000f0000) >> 18);
411 }
412
413 // Condition is only applicable to ARM.
ConditionEpilogueScope414 uint8_t Condition() const {
415 return ((ES & 0x00f00000) >> 20);
416 }
417
418 // Different implementations for ARM and AArch64.
EpilogueStartIndexARMEpilogueScope419 uint8_t EpilogueStartIndexARM() const {
420 return ((ES & 0xff000000) >> 24);
421 }
422
EpilogueStartIndexAArch64EpilogueScope423 uint16_t EpilogueStartIndexAArch64() const {
424 return ((ES & 0xffc00000) >> 22);
425 }
426 };
427
428 struct ExceptionDataRecord;
429 inline size_t HeaderWords(const ExceptionDataRecord &XR);
430
431 struct ExceptionDataRecord {
432 const support::ulittle32_t *Data;
433 bool isAArch64;
434
ExceptionDataRecordExceptionDataRecord435 ExceptionDataRecord(const support::ulittle32_t *Data, bool isAArch64) :
436 Data(Data), isAArch64(isAArch64) {}
437
FunctionLengthExceptionDataRecord438 uint32_t FunctionLength() const {
439 return (Data[0] & 0x0003ffff);
440 }
441
FunctionLengthInBytesARMExceptionDataRecord442 uint32_t FunctionLengthInBytesARM() const {
443 return FunctionLength() << 1;
444 }
445
FunctionLengthInBytesAArch64ExceptionDataRecord446 uint32_t FunctionLengthInBytesAArch64() const {
447 return FunctionLength() << 2;
448 }
449
VersExceptionDataRecord450 uint8_t Vers() const {
451 return (Data[0] & 0x000C0000) >> 18;
452 }
453
XExceptionDataRecord454 bool X() const {
455 return ((Data[0] & 0x00100000) >> 20);
456 }
457
EExceptionDataRecord458 bool E() const {
459 return ((Data[0] & 0x00200000) >> 21);
460 }
461
FExceptionDataRecord462 bool F() const {
463 assert(!isAArch64 && "Fragments are only supported on ARMv7 WinEH");
464 return ((Data[0] & 0x00400000) >> 22);
465 }
466
EpilogueCountExceptionDataRecord467 uint16_t EpilogueCount() const {
468 if (HeaderWords(*this) == 1) {
469 if (isAArch64)
470 return (Data[0] & 0x07C00000) >> 22;
471 return (Data[0] & 0x0f800000) >> 23;
472 }
473 return Data[1] & 0x0000ffff;
474 }
475
CodeWordsExceptionDataRecord476 uint8_t CodeWords() const {
477 if (HeaderWords(*this) == 1) {
478 if (isAArch64)
479 return (Data[0] & 0xf8000000) >> 27;
480 return (Data[0] & 0xf0000000) >> 28;
481 }
482 return (Data[1] & 0x00ff0000) >> 16;
483 }
484
EpilogueScopesExceptionDataRecord485 ArrayRef<support::ulittle32_t> EpilogueScopes() const {
486 assert(E() == 0 && "epilogue scopes are only present when the E bit is 0");
487 size_t Offset = HeaderWords(*this);
488 return makeArrayRef(&Data[Offset], EpilogueCount());
489 }
490
UnwindByteCodeExceptionDataRecord491 ArrayRef<uint8_t> UnwindByteCode() const {
492 const size_t Offset = HeaderWords(*this)
493 + (E() ? 0 : EpilogueCount());
494 const uint8_t *ByteCode =
495 reinterpret_cast<const uint8_t *>(&Data[Offset]);
496 return makeArrayRef(ByteCode, CodeWords() * sizeof(uint32_t));
497 }
498
ExceptionHandlerRVAExceptionDataRecord499 uint32_t ExceptionHandlerRVA() const {
500 assert(X() && "Exception Handler RVA is only valid if the X bit is set");
501 return Data[HeaderWords(*this) + (E() ? 0 : EpilogueCount()) + CodeWords()];
502 }
503
ExceptionHandlerParameterExceptionDataRecord504 uint32_t ExceptionHandlerParameter() const {
505 assert(X() && "Exception Handler RVA is only valid if the X bit is set");
506 return Data[HeaderWords(*this) + (E() ? 0 : EpilogueCount()) + CodeWords() +
507 1];
508 }
509 };
510
HeaderWords(const ExceptionDataRecord & XR)511 inline size_t HeaderWords(const ExceptionDataRecord &XR) {
512 if (XR.isAArch64)
513 return (XR.Data[0] & 0xffc00000) ? 1 : 2;
514 return (XR.Data[0] & 0xff800000) ? 1 : 2;
515 }
516 }
517 }
518 }
519
520 #endif
521