ARMWinEH.h revision 274955
1274955Ssvnmir//===-- llvm/Support/WinARMEH.h - Windows on ARM EH Constants ---*- C++ -*-===//
2274955Ssvnmir//
3274955Ssvnmir//                     The LLVM Compiler Infrastructure
4274955Ssvnmir//
5274955Ssvnmir// This file is distributed under the University of Illinois Open Source
6274955Ssvnmir// License. See LICENSE.TXT for details.
7274955Ssvnmir//
8274955Ssvnmir//===----------------------------------------------------------------------===//
9274955Ssvnmir
10274955Ssvnmir#ifndef LLVM_SUPPORT_WINARMEH_H
11274955Ssvnmir#define LLVM_SUPPORT_WINARMEH_H
12274955Ssvnmir
13274955Ssvnmir#include "llvm/ADT/ArrayRef.h"
14274955Ssvnmir#include "llvm/Support/Endian.h"
15274955Ssvnmir
16274955Ssvnmirnamespace llvm {
17274955Ssvnmirnamespace ARM {
18274955Ssvnmirnamespace WinEH {
19274955Ssvnmirenum class RuntimeFunctionFlag {
20274955Ssvnmir  RFF_Unpacked,       /// unpacked entry
21274955Ssvnmir  RFF_Packed,         /// packed entry
22274955Ssvnmir  RFF_PackedFragment, /// packed entry representing a fragment
23274955Ssvnmir  RFF_Reserved,       /// reserved
24274955Ssvnmir};
25274955Ssvnmir
26274955Ssvnmirenum class ReturnType {
27274955Ssvnmir  RT_POP,             /// return via pop {pc} (L flag must be set)
28274955Ssvnmir  RT_B,               /// 16-bit branch
29274955Ssvnmir  RT_BW,              /// 32-bit branch
30274955Ssvnmir  RT_NoEpilogue,      /// no epilogue (fragment)
31274955Ssvnmir};
32274955Ssvnmir
33274955Ssvnmir/// RuntimeFunction - An entry in the table of procedure data (.pdata)
34274955Ssvnmir///
35274955Ssvnmir///  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
36274955Ssvnmir///  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
37274955Ssvnmir/// +---------------------------------------------------------------+
38274955Ssvnmir/// |                     Function Start RVA                        |
39274955Ssvnmir/// +-------------------+-+-+-+-----+-+---+---------------------+---+
40274955Ssvnmir/// |    Stack Adjust   |C|L|R| Reg |H|Ret|   Function Length   |Flg|
41274955Ssvnmir/// +-------------------+-+-+-+-----+-+---+---------------------+---+
42274955Ssvnmir///
43274955Ssvnmir/// Flag : 2-bit field with the following meanings:
44274955Ssvnmir///   - 00 = packed unwind data not used; reamining bits point to .xdata record
45274955Ssvnmir///   - 01 = packed unwind data
46274955Ssvnmir///   - 10 = packed unwind data, function assumed to have no prologue; useful
47274955Ssvnmir///          for function fragments that are discontiguous with the start of the
48274955Ssvnmir///          function
49274955Ssvnmir///   - 11 = reserved
50274955Ssvnmir/// Function Length : 11-bit field providing the length of the entire function
51274955Ssvnmir///                   in bytes, divided by 2; if the function is greater than
52274955Ssvnmir///                   4KB, a full .xdata record must be used instead
53274955Ssvnmir/// Ret : 2-bit field indicating how the function returns
54274955Ssvnmir///   - 00 = return via pop {pc} (the L bit must be set)
55274955Ssvnmir///   - 01 = return via 16-bit branch
56274955Ssvnmir///   - 10 = return via 32-bit branch
57274955Ssvnmir///   - 11 = no epilogue; useful for function fragments that may only contain a
58274955Ssvnmir///          prologue but the epilogue is elsewhere
59274955Ssvnmir/// H : 1-bit flag indicating whether the function "homes" the integer parameter
60274955Ssvnmir///     registers (r0-r3), allocating 16-bytes on the stack
61274955Ssvnmir/// Reg : 3-bit field indicating the index of the last saved non-volatile
62274955Ssvnmir///       register.  If the R bit is set to 0, then only integer registers are
63274955Ssvnmir///       saved (r4-rN, where N is 4 + Reg).  If the R bit is set to 1, then
64274955Ssvnmir///       only floating-point registers are being saved (d8-dN, where N is
65274955Ssvnmir///       8 + Reg).  The special case of the R bit being set to 1 and Reg equal
66274955Ssvnmir///       to 7 indicates that no registers are saved.
67274955Ssvnmir/// R : 1-bit flag indicating whether the non-volatile registers are integer or
68274955Ssvnmir///     floating-point.  0 indicates integer, 1 indicates floating-point.  The
69274955Ssvnmir///     special case of the R-flag being set and Reg being set to 7 indicates
70274955Ssvnmir///     that no non-volatile registers are saved.
71274955Ssvnmir/// L : 1-bit flag indicating whether the function saves/restores the link
72274955Ssvnmir///     register (LR)
73274955Ssvnmir/// C : 1-bit flag indicating whether the function includes extra instructions
74274955Ssvnmir///     to setup a frame chain for fast walking.  If this flag is set, r11 is
75274955Ssvnmir///     implicitly added to the list of saved non-volatile integer registers.
76274955Ssvnmir/// Stack Adjust : 10-bit field indicating the number of bytes of stack that are
77274955Ssvnmir///                allocated for this function.  Only values between 0x000 and
78274955Ssvnmir///                0x3f3 can be directly encoded.  If the value is 0x3f4 or
79274955Ssvnmir///                greater, then the low 4 bits have special meaning as follows:
80274955Ssvnmir///                - Bit 0-1
81274955Ssvnmir///                  indicate the number of words' of adjustment (1-4), minus 1
82274955Ssvnmir///                - Bit 2
83274955Ssvnmir///                  indicates if the prologue combined adjustment into push
84274955Ssvnmir///                - Bit 3
85274955Ssvnmir///                  indicates if the epilogue combined adjustment into pop
86274955Ssvnmir///
87274955Ssvnmir/// RESTRICTIONS:
88274955Ssvnmir///   - IF C is SET:
89274955Ssvnmir///     + L flag must be set since frame chaining requires r11 and lr
90274955Ssvnmir///     + r11 must NOT be included in the set of registers described by Reg
91274955Ssvnmir///   - IF Ret is 0:
92274955Ssvnmir///     + L flag must be set
93274955Ssvnmir
94274955Ssvnmir// NOTE: RuntimeFunction is meant to be a simple class that provides raw access
95274955Ssvnmir// to all fields in the structure.  The accessor methods reflect the names of
96274955Ssvnmir// the bitfields that they correspond to.  Although some obvious simplifications
97274955Ssvnmir// are possible via merging of methods, it would prevent the use of this class
98274955Ssvnmir// to fully inspect the contents of the data structure which is particularly
99274955Ssvnmir// useful for scenarios such as llvm-readobj to aid in testing.
100274955Ssvnmir
101274955Ssvnmirclass RuntimeFunction {
102274955Ssvnmirpublic:
103274955Ssvnmir  const support::ulittle32_t BeginAddress;
104274955Ssvnmir  const support::ulittle32_t UnwindData;
105274955Ssvnmir
106274955Ssvnmir  RuntimeFunction(const support::ulittle32_t *Data)
107274955Ssvnmir    : BeginAddress(Data[0]), UnwindData(Data[1]) {}
108274955Ssvnmir
109274955Ssvnmir  RuntimeFunction(const support::ulittle32_t BeginAddress,
110274955Ssvnmir                  const support::ulittle32_t UnwindData)
111274955Ssvnmir    : BeginAddress(BeginAddress), UnwindData(UnwindData) {}
112274955Ssvnmir
113274955Ssvnmir  RuntimeFunctionFlag Flag() const {
114274955Ssvnmir    return RuntimeFunctionFlag(UnwindData & 0x3);
115274955Ssvnmir  }
116274955Ssvnmir
117274955Ssvnmir  uint32_t ExceptionInformationRVA() const {
118274955Ssvnmir    assert(Flag() == RuntimeFunctionFlag::RFF_Unpacked &&
119274955Ssvnmir           "unpacked form required for this operation");
120274955Ssvnmir    return (UnwindData & ~0x3);
121274955Ssvnmir  }
122274955Ssvnmir
123274955Ssvnmir  uint32_t PackedUnwindData() const {
124274955Ssvnmir    assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
125274955Ssvnmir            Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
126274955Ssvnmir           "packed form required for this operation");
127274955Ssvnmir    return (UnwindData & ~0x3);
128274955Ssvnmir  }
129274955Ssvnmir  uint32_t FunctionLength() const {
130274955Ssvnmir    assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
131274955Ssvnmir            Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
132274955Ssvnmir           "packed form required for this operation");
133274955Ssvnmir    return (((UnwindData & 0x00001ffc) >> 2) << 1);
134274955Ssvnmir  }
135274955Ssvnmir  ReturnType Ret() const {
136274955Ssvnmir    assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
137274955Ssvnmir            Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
138274955Ssvnmir           "packed form required for this operation");
139274955Ssvnmir    assert(((UnwindData & 0x00006000) || L()) && "L must be set to 1");
140274955Ssvnmir    return ReturnType((UnwindData & 0x00006000) >> 13);
141274955Ssvnmir  }
142274955Ssvnmir  bool H() const {
143274955Ssvnmir    assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
144274955Ssvnmir            Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
145274955Ssvnmir           "packed form required for this operation");
146274955Ssvnmir    return ((UnwindData & 0x00008000) >> 15);
147274955Ssvnmir  }
148274955Ssvnmir  uint8_t Reg() const {
149274955Ssvnmir    assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
150274955Ssvnmir            Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
151274955Ssvnmir           "packed form required for this operation");
152274955Ssvnmir    return ((UnwindData & 0x00070000) >> 16);
153274955Ssvnmir  }
154274955Ssvnmir  bool R() const {
155274955Ssvnmir    assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
156274955Ssvnmir            Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
157274955Ssvnmir           "packed form required for this operation");
158274955Ssvnmir    return ((UnwindData & 0x00080000) >> 19);
159274955Ssvnmir  }
160274955Ssvnmir  bool L() const {
161274955Ssvnmir    assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
162274955Ssvnmir            Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
163274955Ssvnmir           "packed form required for this operation");
164274955Ssvnmir    return ((UnwindData & 0x00100000) >> 20);
165274955Ssvnmir  }
166274955Ssvnmir  bool C() const {
167274955Ssvnmir    assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
168274955Ssvnmir            Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
169274955Ssvnmir           "packed form required for this operation");
170274955Ssvnmir    assert(((~UnwindData & 0x00200000) || L()) &&
171274955Ssvnmir           "L flag must be set, chaining requires r11 and LR");
172274955Ssvnmir    assert(((~UnwindData & 0x00200000) || (Reg() < 7) || R()) &&
173274955Ssvnmir           "r11 must not be included in Reg; C implies r11");
174274955Ssvnmir    return ((UnwindData & 0x00200000) >> 21);
175274955Ssvnmir  }
176274955Ssvnmir  uint16_t StackAdjust() const {
177274955Ssvnmir    assert((Flag() == RuntimeFunctionFlag::RFF_Packed ||
178274955Ssvnmir            Flag() == RuntimeFunctionFlag::RFF_PackedFragment) &&
179274955Ssvnmir           "packed form required for this operation");
180274955Ssvnmir    return ((UnwindData & 0xffc00000) >> 22);
181274955Ssvnmir  }
182274955Ssvnmir};
183274955Ssvnmir
184274955Ssvnmir/// PrologueFolding - pseudo-flag derived from Stack Adjust indicating that the
185274955Ssvnmir/// prologue has stack adjustment combined into the push
186274955Ssvnmirinline bool PrologueFolding(const RuntimeFunction &RF) {
187274955Ssvnmir  return RF.StackAdjust() >= 0x3f4 && (RF.StackAdjust() & 0x4);
188274955Ssvnmir}
189274955Ssvnmir/// Epilogue - pseudo-flag derived from Stack Adjust indicating that the
190274955Ssvnmir/// epilogue has stack adjustment combined into the pop
191274955Ssvnmirinline bool EpilogueFolding(const RuntimeFunction &RF) {
192274955Ssvnmir  return RF.StackAdjust() >= 0x3f4 && (RF.StackAdjust() & 0x8);
193274955Ssvnmir}
194274955Ssvnmir/// StackAdjustment - calculated stack adjustment in words.  The stack
195274955Ssvnmir/// adjustment should be determined via this function to account for the special
196274955Ssvnmir/// handling the special encoding when the value is >= 0x3f4.
197274955Ssvnmirinline uint16_t StackAdjustment(const RuntimeFunction &RF) {
198274955Ssvnmir  uint16_t Adjustment = RF.StackAdjust();
199274955Ssvnmir  if (Adjustment >= 0x3f4)
200274955Ssvnmir    return (Adjustment & 0x3) ? ((Adjustment & 0x3) << 2) - 1 : 0;
201274955Ssvnmir  return Adjustment;
202274955Ssvnmir}
203274955Ssvnmir
204274955Ssvnmir/// SavedRegisterMask - Utility function to calculate the set of saved general
205274955Ssvnmir/// purpose (r0-r15) and VFP (d0-d31) registers.
206274955Ssvnmirstd::pair<uint16_t, uint32_t> SavedRegisterMask(const RuntimeFunction &RF);
207274955Ssvnmir
208274955Ssvnmir/// ExceptionDataRecord - An entry in the table of exception data (.xdata)
209274955Ssvnmir///
210274955Ssvnmir///  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
211274955Ssvnmir///  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
212274955Ssvnmir/// +-------+---------+-+-+-+---+-----------------------------------+
213274955Ssvnmir/// | C Wrd | Epi Cnt |F|E|X|Ver|         Function Length           |
214274955Ssvnmir/// +-------+--------+'-'-'-'---'---+-------------------------------+
215274955Ssvnmir/// |    Reserved    |Ex. Code Words|   (Extended Epilogue Count)   |
216274955Ssvnmir/// +-------+--------+--------------+-------------------------------+
217274955Ssvnmir///
218274955Ssvnmir/// Function Length : 18-bit field indicating the total length of the function
219274955Ssvnmir///                   in bytes divided by 2.  If a function is larger than
220274955Ssvnmir///                   512KB, then multiple pdata and xdata records must be used.
221274955Ssvnmir/// Vers : 2-bit field describing the version of the remaining structure.  Only
222274955Ssvnmir///        version 0 is currently defined (values 1-3 are not permitted).
223274955Ssvnmir/// X : 1-bit field indicating the presence of exception data
224274955Ssvnmir/// E : 1-bit field indicating that the single epilogue is packed into the
225274955Ssvnmir///     header
226274955Ssvnmir/// F : 1-bit field indicating that the record describes a function fragment
227274955Ssvnmir///     (implies that no prologue is present, and prologue processing should be
228274955Ssvnmir///     skipped)
229274955Ssvnmir/// Epilogue Count : 5-bit field that differs in meaning based on the E field.
230274955Ssvnmir///
231274955Ssvnmir///                  If E is set, then this field specifies the index of the
232274955Ssvnmir///                  first unwind code describing the (only) epilogue.
233274955Ssvnmir///
234274955Ssvnmir///                  Otherwise, this field indicates the number of exception
235274955Ssvnmir///                  scopes.  If more than 31 scopes exist, then this field and
236274955Ssvnmir///                  the Code Words field must both be set to 0 to indicate that
237274955Ssvnmir///                  an extension word is required.
238274955Ssvnmir/// Code Words : 4-bit field that species the number of 32-bit words needed to
239274955Ssvnmir///              contain all the unwind codes.  If more than 15 words (63 code
240274955Ssvnmir///              bytes) are required, then this field and the Epilogue Count
241274955Ssvnmir///              field must both be set to 0 to indicate that an extension word
242274955Ssvnmir///              is required.
243274955Ssvnmir/// Extended Epilogue Count, Extended Code Words :
244274955Ssvnmir///                          Valid only if Epilog Count and Code Words are both
245274955Ssvnmir///                          set to 0.  Provides an 8-bit extended code word
246274955Ssvnmir///                          count and 16-bits for epilogue count
247274955Ssvnmir///
248274955Ssvnmir///  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
249274955Ssvnmir///  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
250274955Ssvnmir/// +----------------+------+---+---+-------------------------------+
251274955Ssvnmir/// |  Ep Start Idx  | Cond |Res|       Epilogue Start Offset       |
252274955Ssvnmir/// +----------------+------+---+-----------------------------------+
253274955Ssvnmir///
254274955Ssvnmir/// If the E bit is unset in the header, the header is followed by a series of
255274955Ssvnmir/// epilogue scopes, which are sorted by their offset.
256274955Ssvnmir///
257274955Ssvnmir/// Epilogue Start Offset: 18-bit field encoding the offset of epilogue relative
258274955Ssvnmir///                        to the start of the function in bytes divided by two
259274955Ssvnmir/// Res : 2-bit field reserved for future expansion (must be set to 0)
260274955Ssvnmir/// Condition : 4-bit field providing the condition under which the epilogue is
261274955Ssvnmir///             executed.  Unconditional epilogues should set this field to 0xe.
262274955Ssvnmir///             Epilogues must be entirely conditional or unconditional, and in
263274955Ssvnmir///             Thumb-2 mode.  The epilogue beings with the first instruction
264274955Ssvnmir///             after the IT opcode.
265274955Ssvnmir/// Epilogue Start Index : 8-bit field indicating the byte index of the first
266274955Ssvnmir///                        unwind code describing the epilogue
267274955Ssvnmir///
268274955Ssvnmir///  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
269274955Ssvnmir///  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
270274955Ssvnmir/// +---------------+---------------+---------------+---------------+
271274955Ssvnmir/// | Unwind Code 3 | Unwind Code 2 | Unwind Code 1 | Unwind Code 0 |
272274955Ssvnmir/// +---------------+---------------+---------------+---------------+
273274955Ssvnmir///
274274955Ssvnmir/// Following the epilogue scopes, the byte code describing the unwinding
275274955Ssvnmir/// follows.  This is padded to align up to word alignment.  Bytes are stored in
276274955Ssvnmir/// little endian.
277274955Ssvnmir///
278274955Ssvnmir///  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
279274955Ssvnmir///  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
280274955Ssvnmir/// +---------------------------------------------------------------+
281274955Ssvnmir/// |           Exception Handler RVA (requires X = 1)              |
282274955Ssvnmir/// +---------------------------------------------------------------+
283274955Ssvnmir/// |  (possibly followed by data required for exception handler)   |
284274955Ssvnmir/// +---------------------------------------------------------------+
285274955Ssvnmir///
286274955Ssvnmir/// If the X bit is set in the header, the unwind byte code is followed by the
287274955Ssvnmir/// exception handler information.  This constants of one Exception Handler RVA
288274955Ssvnmir/// which is the address to the exception handler, followed immediately by the
289274955Ssvnmir/// variable length data associated with the exception handler.
290274955Ssvnmir///
291274955Ssvnmir
292274955Ssvnmirstruct EpilogueScope {
293274955Ssvnmir  const support::ulittle32_t ES;
294274955Ssvnmir
295274955Ssvnmir  EpilogueScope(const support::ulittle32_t Data) : ES(Data) {}
296274955Ssvnmir  uint32_t EpilogueStartOffset() const {
297274955Ssvnmir    return (ES & 0x0003ffff);
298274955Ssvnmir  }
299274955Ssvnmir  uint8_t Res() const {
300274955Ssvnmir    return ((ES & 0x000c0000) >> 18);
301274955Ssvnmir  }
302274955Ssvnmir  uint8_t Condition() const {
303274955Ssvnmir    return ((ES & 0x00f00000) >> 20);
304274955Ssvnmir  }
305274955Ssvnmir  uint8_t EpilogueStartIndex() const {
306274955Ssvnmir    return ((ES & 0xff000000) >> 24);
307274955Ssvnmir  }
308274955Ssvnmir};
309274955Ssvnmir
310274955Ssvnmirstruct ExceptionDataRecord;
311274955Ssvnmirinline size_t HeaderWords(const ExceptionDataRecord &XR);
312274955Ssvnmir
313274955Ssvnmirstruct ExceptionDataRecord {
314274955Ssvnmir  const support::ulittle32_t *Data;
315274955Ssvnmir
316274955Ssvnmir  ExceptionDataRecord(const support::ulittle32_t *Data) : Data(Data) {}
317274955Ssvnmir
318274955Ssvnmir  uint32_t FunctionLength() const {
319274955Ssvnmir    return (Data[0] & 0x0003ffff);
320274955Ssvnmir  }
321274955Ssvnmir
322274955Ssvnmir  uint8_t Vers() const {
323274955Ssvnmir    return (Data[0] & 0x000C0000) >> 18;
324274955Ssvnmir  }
325274955Ssvnmir
326274955Ssvnmir  bool X() const {
327274955Ssvnmir    return ((Data[0] & 0x00100000) >> 20);
328274955Ssvnmir  }
329274955Ssvnmir
330274955Ssvnmir  bool E() const {
331274955Ssvnmir    return ((Data[0] & 0x00200000) >> 21);
332274955Ssvnmir  }
333274955Ssvnmir
334274955Ssvnmir  bool F() const {
335274955Ssvnmir    return ((Data[0] & 0x00400000) >> 22);
336274955Ssvnmir  }
337274955Ssvnmir
338274955Ssvnmir  uint8_t EpilogueCount() const {
339274955Ssvnmir    if (HeaderWords(*this) == 1)
340274955Ssvnmir      return (Data[0] & 0x0f800000) >> 23;
341274955Ssvnmir    return Data[1] & 0x0000ffff;
342274955Ssvnmir  }
343274955Ssvnmir
344274955Ssvnmir  uint8_t CodeWords() const {
345274955Ssvnmir    if (HeaderWords(*this) == 1)
346274955Ssvnmir      return (Data[0] & 0xf0000000) >> 28;
347274955Ssvnmir    return (Data[1] & 0x00ff0000) >> 16;
348274955Ssvnmir  }
349274955Ssvnmir
350274955Ssvnmir  ArrayRef<support::ulittle32_t> EpilogueScopes() const {
351274955Ssvnmir    assert(E() == 0 && "epilogue scopes are only present when the E bit is 0");
352274955Ssvnmir    size_t Offset = HeaderWords(*this);
353274955Ssvnmir    return ArrayRef<support::ulittle32_t>(&Data[Offset], EpilogueCount());
354274955Ssvnmir  }
355274955Ssvnmir
356274955Ssvnmir  ArrayRef<support::ulittle8_t> UnwindByteCode() const {
357274955Ssvnmir    const size_t Offset = HeaderWords(*this)
358274955Ssvnmir                        + (E() ? 0 :  EpilogueCount());
359274955Ssvnmir    const support::ulittle8_t *ByteCode =
360274955Ssvnmir      reinterpret_cast<const support::ulittle8_t *>(&Data[Offset]);
361274955Ssvnmir    return ArrayRef<support::ulittle8_t>(ByteCode,
362274955Ssvnmir                                         CodeWords() * sizeof(uint32_t));
363274955Ssvnmir  }
364274955Ssvnmir
365274955Ssvnmir  uint32_t ExceptionHandlerRVA() const {
366274955Ssvnmir    assert(X() && "Exception Handler RVA is only valid if the X bit is set");
367274955Ssvnmir    return Data[HeaderWords(*this) + EpilogueCount() + CodeWords()];
368274955Ssvnmir  }
369274955Ssvnmir
370274955Ssvnmir  uint32_t ExceptionHandlerParameter() const {
371274955Ssvnmir    assert(X() && "Exception Handler RVA is only valid if the X bit is set");
372274955Ssvnmir    return Data[HeaderWords(*this) + EpilogueCount() + CodeWords() + 1];
373274955Ssvnmir  }
374274955Ssvnmir};
375274955Ssvnmir
376274955Ssvnmirinline size_t HeaderWords(const ExceptionDataRecord &XR) {
377274955Ssvnmir  return (XR.Data[0] & 0xff800000) ? 1 : 2;
378274955Ssvnmir}
379274955Ssvnmir}
380274955Ssvnmir}
381274955Ssvnmir}
382274955Ssvnmir
383274955Ssvnmir#endif
384274955Ssvnmir
385