LLVM  8.0.1
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  // The following set of unwind opcodes is for ARM64. They are documented at
38  // https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling
54 };
55 
56 /// UnwindCode - This union describes a single operation in a function prolog,
57 /// or part thereof.
58 union UnwindCode {
59  struct {
60  uint8_t CodeOffset;
62  } u;
64 
65  uint8_t getUnwindOp() const {
66  return u.UnwindOpAndOpInfo & 0x0F;
67  }
68  uint8_t getOpInfo() const {
69  return (u.UnwindOpAndOpInfo >> 4) & 0x0F;
70  }
71 };
72 
73 enum {
74  /// UNW_ExceptionHandler - Specifies that this function has an exception
75  /// handler.
77  /// UNW_TerminateHandler - Specifies that this function has a termination
78  /// handler.
80  /// UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to
81  /// another one.
83 };
84 
85 /// RuntimeFunction - An entry in the table of functions with unwind info.
90 };
91 
92 /// UnwindInfo - An entry in the exception table.
93 struct UnwindInfo {
94  uint8_t VersionAndFlags;
95  uint8_t PrologSize;
96  uint8_t NumCodes;
98  UnwindCode UnwindCodes[1];
99 
100  uint8_t getVersion() const {
101  return VersionAndFlags & 0x07;
102  }
103  uint8_t getFlags() const {
104  return (VersionAndFlags >> 3) & 0x1f;
105  }
106  uint8_t getFrameRegister() const {
107  return FrameRegisterAndOffset & 0x0f;
108  }
109  uint8_t getFrameOffset() const {
110  return (FrameRegisterAndOffset >> 4) & 0x0f;
111  }
112 
113  // The data after unwindCodes depends on flags.
114  // If UNW_ExceptionHandler or UNW_TerminateHandler is set then follows
115  // the address of the language-specific exception handler.
116  // If UNW_ChainInfo is set then follows a RuntimeFunction which defines
117  // the chained unwind info.
118  // For more information please see MSDN at:
119  // http://msdn.microsoft.com/en-us/library/ddssxxy8.aspx
120 
121  /// Return pointer to language specific data part of UnwindInfo.
123  return reinterpret_cast<void *>(&UnwindCodes[(NumCodes+1) & ~1]);
124  }
125 
126  /// Return pointer to language specific data part of UnwindInfo.
127  const void *getLanguageSpecificData() const {
128  return reinterpret_cast<const void *>(&UnwindCodes[(NumCodes + 1) & ~1]);
129  }
130 
131  /// Return image-relative offset of language-specific exception handler.
133  return *reinterpret_cast<const support::ulittle32_t *>(
134  getLanguageSpecificData());
135  }
136 
137  /// Set image-relative offset of language-specific exception handler.
139  *reinterpret_cast<support::ulittle32_t *>(getLanguageSpecificData()) =
140  offset;
141  }
142 
143  /// Return pointer to exception-specific data.
145  return reinterpret_cast<void *>(reinterpret_cast<uint32_t *>(
146  getLanguageSpecificData())+1);
147  }
148 
149  /// Return pointer to chained unwind info.
151  return reinterpret_cast<RuntimeFunction *>(getLanguageSpecificData());
152  }
153 
154  /// Return pointer to chained unwind info.
156  return reinterpret_cast<const RuntimeFunction *>(getLanguageSpecificData());
157  }
158 };
159 
160 
161 } // End of namespace Win64EH
162 } // End of namespace llvm
163 
164 #endif
uint8_t getFrameRegister() const
Definition: Win64EH.h:106
This class represents lattice values for constants.
Definition: AllocatorList.h:24
void * getExceptionData()
Return pointer to exception-specific data.
Definition: Win64EH.h:144
uint32_t getLanguageSpecificHandlerOffset() const
Return image-relative offset of language-specific exception handler.
Definition: Win64EH.h:132
UnwindCode - This union describes a single operation in a function prolog, or part thereof...
Definition: Win64EH.h:58
support::ulittle32_t EndAddress
Definition: Win64EH.h:88
support::ulittle32_t UnwindInfoOffset
Definition: Win64EH.h:89
UNW_ExceptionHandler - Specifies that this function has an exception handler.
Definition: Win64EH.h:76
RuntimeFunction * getChainedFunctionEntry()
Return pointer to chained unwind info.
Definition: Win64EH.h:150
uint8_t getFlags() const
Definition: Win64EH.h:103
uint8_t getVersion() const
Definition: Win64EH.h:100
uint8_t FrameRegisterAndOffset
Definition: Win64EH.h:97
RuntimeFunction - An entry in the table of functions with unwind info.
Definition: Win64EH.h:86
UnwindOpcodes
UnwindOpcodes - Enumeration whose values specify a single operation in the prolog of a function...
Definition: Win64EH.h:27
uint8_t getUnwindOp() const
Definition: Win64EH.h:65
void * getLanguageSpecificData()
Return pointer to language specific data part of UnwindInfo.
Definition: Win64EH.h:122
UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to another one.
Definition: Win64EH.h:82
const void * getLanguageSpecificData() const
Return pointer to language specific data part of UnwindInfo.
Definition: Win64EH.h:127
support::ulittle32_t StartAddress
Definition: Win64EH.h:87
void setLanguageSpecificHandlerOffset(uint32_t offset)
Set image-relative offset of language-specific exception handler.
Definition: Win64EH.h:138
uint8_t getOpInfo() const
Definition: Win64EH.h:68
support::ulittle16_t FrameOffset
Definition: Win64EH.h:63
UnwindInfo - An entry in the exception table.
Definition: Win64EH.h:93
const RuntimeFunction * getChainedFunctionEntry() const
Return pointer to chained unwind info.
Definition: Win64EH.h:155
uint8_t getFrameOffset() const
Definition: Win64EH.h:109
UNW_TerminateHandler - Specifies that this function has a termination handler.
Definition: Win64EH.h:79
struct llvm::Win64EH::UnwindCode::@324 u