LLVM  4.0.0
Win64EH.h
Go to the documentation of this file.
1 //===-- llvm/Support/Win64EH.h ---Win64 EH Constants-------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains constants and structures used for implementing
11 // exception handling on Win64 platforms. For more information, see
12 // http://msdn.microsoft.com/en-us/library/1eyas8tf.aspx
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_SUPPORT_WIN64EH_H
17 #define LLVM_SUPPORT_WIN64EH_H
18 
19 #include "llvm/Support/DataTypes.h"
20 #include "llvm/Support/Endian.h"
21 
22 namespace llvm {
23 namespace Win64EH {
24 
25 /// UnwindOpcodes - Enumeration whose values specify a single operation in
26 /// the prolog of a function.
37 };
38 
39 /// UnwindCode - This union describes a single operation in a function prolog,
40 /// or part thereof.
41 union UnwindCode {
42  struct {
43  uint8_t CodeOffset;
45  } u;
47 
48  uint8_t getUnwindOp() const {
49  return u.UnwindOpAndOpInfo & 0x0F;
50  }
51  uint8_t getOpInfo() const {
52  return (u.UnwindOpAndOpInfo >> 4) & 0x0F;
53  }
54 };
55 
56 enum {
57  /// UNW_ExceptionHandler - Specifies that this function has an exception
58  /// handler.
60  /// UNW_TerminateHandler - Specifies that this function has a termination
61  /// handler.
63  /// UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to
64  /// another one.
66 };
67 
68 /// RuntimeFunction - An entry in the table of functions with unwind info.
73 };
74 
75 /// UnwindInfo - An entry in the exception table.
76 struct UnwindInfo {
77  uint8_t VersionAndFlags;
78  uint8_t PrologSize;
79  uint8_t NumCodes;
82 
83  uint8_t getVersion() const {
84  return VersionAndFlags & 0x07;
85  }
86  uint8_t getFlags() const {
87  return (VersionAndFlags >> 3) & 0x1f;
88  }
89  uint8_t getFrameRegister() const {
90  return FrameRegisterAndOffset & 0x0f;
91  }
92  uint8_t getFrameOffset() const {
93  return (FrameRegisterAndOffset >> 4) & 0x0f;
94  }
95 
96  // The data after unwindCodes depends on flags.
97  // If UNW_ExceptionHandler or UNW_TerminateHandler is set then follows
98  // the address of the language-specific exception handler.
99  // If UNW_ChainInfo is set then follows a RuntimeFunction which defines
100  // the chained unwind info.
101  // For more information please see MSDN at:
102  // http://msdn.microsoft.com/en-us/library/ddssxxy8.aspx
103 
104  /// \brief Return pointer to language specific data part of UnwindInfo.
106  return reinterpret_cast<void *>(&UnwindCodes[(NumCodes+1) & ~1]);
107  }
108 
109  /// \brief Return pointer to language specific data part of UnwindInfo.
110  const void *getLanguageSpecificData() const {
111  return reinterpret_cast<const void *>(&UnwindCodes[(NumCodes + 1) & ~1]);
112  }
113 
114  /// \brief Return image-relative offset of language-specific exception handler.
116  return *reinterpret_cast<const support::ulittle32_t *>(
118  }
119 
120  /// \brief Set image-relative offset of language-specific exception handler.
122  *reinterpret_cast<support::ulittle32_t *>(getLanguageSpecificData()) =
123  offset;
124  }
125 
126  /// \brief Return pointer to exception-specific data.
128  return reinterpret_cast<void *>(reinterpret_cast<uint32_t *>(
130  }
131 
132  /// \brief Return pointer to chained unwind info.
134  return reinterpret_cast<RuntimeFunction *>(getLanguageSpecificData());
135  }
136 
137  /// \brief Return pointer to chained unwind info.
139  return reinterpret_cast<const RuntimeFunction *>(getLanguageSpecificData());
140  }
141 };
142 
143 
144 } // End of namespace Win64EH
145 } // End of namespace llvm
146 
147 #endif
uint8_t getFrameRegister() const
Definition: Win64EH.h:89
struct llvm::Win64EH::UnwindCode::@232 u
void * getExceptionData()
Return pointer to exception-specific data.
Definition: Win64EH.h:127
uint8_t getUnwindOp() const
Definition: Win64EH.h:48
UNW_ExceptionHandler - Specifies that this function has an exception handler.
Definition: Win64EH.h:59
UnwindCode UnwindCodes[1]
Definition: Win64EH.h:81
UnwindCode - This union describes a single operation in a function prolog, or part thereof...
Definition: Win64EH.h:41
support::ulittle32_t EndAddress
Definition: Win64EH.h:71
support::ulittle32_t UnwindInfoOffset
Definition: Win64EH.h:72
uint8_t getFlags() const
Definition: Win64EH.h:86
RuntimeFunction * getChainedFunctionEntry()
Return pointer to chained unwind info.
Definition: Win64EH.h:133
uint32_t getLanguageSpecificHandlerOffset() const
Return image-relative offset of language-specific exception handler.
Definition: Win64EH.h:115
uint8_t FrameRegisterAndOffset
Definition: Win64EH.h:80
const void * getLanguageSpecificData() const
Return pointer to language specific data part of UnwindInfo.
Definition: Win64EH.h:110
RuntimeFunction - An entry in the table of functions with unwind info.
Definition: Win64EH.h:69
UnwindOpcodes
UnwindOpcodes - Enumeration whose values specify a single operation in the prolog of a function...
Definition: Win64EH.h:27
UNW_TerminateHandler - Specifies that this function has a termination handler.
Definition: Win64EH.h:62
void * getLanguageSpecificData()
Return pointer to language specific data part of UnwindInfo.
Definition: Win64EH.h:105
uint8_t getVersion() const
Definition: Win64EH.h:83
support::ulittle32_t StartAddress
Definition: Win64EH.h:70
void setLanguageSpecificHandlerOffset(uint32_t offset)
Set image-relative offset of language-specific exception handler.
Definition: Win64EH.h:121
UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to another one.
Definition: Win64EH.h:65
uint8_t getOpInfo() const
Definition: Win64EH.h:51
const RuntimeFunction * getChainedFunctionEntry() const
Return pointer to chained unwind info.
Definition: Win64EH.h:138
uint8_t getFrameOffset() const
Definition: Win64EH.h:92
support::ulittle16_t FrameOffset
Definition: Win64EH.h:46
UnwindInfo - An entry in the exception table.
Definition: Win64EH.h:76