LLVM  16.0.0git
Win64EH.h
Go to the documentation of this file.
1 //===-- llvm/Support/Win64EH.h ---Win64 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 // This file contains constants and structures used for implementing
10 // exception handling on Win64 platforms. For more information, see
11 // http://msdn.microsoft.com/en-us/library/1eyas8tf.aspx
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_SUPPORT_WIN64EH_H
16 #define LLVM_SUPPORT_WIN64EH_H
17 
18 #include "llvm/Support/DataTypes.h"
19 #include "llvm/Support/Endian.h"
20 
21 namespace llvm {
22 namespace Win64EH {
23 
24 /// UnwindOpcodes - Enumeration whose values specify a single operation in
25 /// the prolog of a function.
27  // The following set of unwind opcodes is for x86_64. They are documented at
28  // https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64.
29  // Some generic values from this set are used for other architectures too.
41  // The following set of unwind opcodes is for ARM64. They are documented at
42  // https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling
77 
78  // The following set of unwind opcodes is for ARM. They are documented at
79  // https://docs.microsoft.com/en-us/cpp/build/arm-exception-handling
80 
81  // Stack allocations use UOP_AllocSmall, UOP_AllocLarge from above, plus
82  // the following. AllocSmall, AllocLarge and AllocHuge represent a 16 bit
83  // instruction, while the WideAlloc* opcodes represent a 32 bit instruction.
84  // Small can represent a stack offset of 0x7f*4 (252) bytes, Medium can
85  // represent up to 0x3ff*4 (4092) bytes, Large up to 0xffff*4 (262140) bytes,
86  // and Huge up to 0xffffff*4 (67108860) bytes.
91 
101  // Using UOP_Nop from above
103  // Using UOP_End from above
106  // A custom unspecified opcode, consisting of one or more bytes. This
107  // allows producing opcodes in the implementation defined/reserved range.
109 };
110 
111 /// UnwindCode - This union describes a single operation in a function prolog,
112 /// or part thereof.
113 union UnwindCode {
114  struct {
115  uint8_t CodeOffset;
117  } u;
119 
120  uint8_t getUnwindOp() const {
121  return u.UnwindOpAndOpInfo & 0x0F;
122  }
123  uint8_t getOpInfo() const {
124  return (u.UnwindOpAndOpInfo >> 4) & 0x0F;
125  }
126 };
127 
128 enum {
129  /// UNW_ExceptionHandler - Specifies that this function has an exception
130  /// handler.
132  /// UNW_TerminateHandler - Specifies that this function has a termination
133  /// handler.
135  /// UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to
136  /// another one.
138 };
139 
140 /// RuntimeFunction - An entry in the table of functions with unwind info.
145 };
146 
147 /// UnwindInfo - An entry in the exception table.
148 struct UnwindInfo {
150  uint8_t PrologSize;
151  uint8_t NumCodes;
154 
155  uint8_t getVersion() const {
156  return VersionAndFlags & 0x07;
157  }
158  uint8_t getFlags() const {
159  return (VersionAndFlags >> 3) & 0x1f;
160  }
161  uint8_t getFrameRegister() const {
162  return FrameRegisterAndOffset & 0x0f;
163  }
164  uint8_t getFrameOffset() const {
165  return (FrameRegisterAndOffset >> 4) & 0x0f;
166  }
167 
168  // The data after unwindCodes depends on flags.
169  // If UNW_ExceptionHandler or UNW_TerminateHandler is set then follows
170  // the address of the language-specific exception handler.
171  // If UNW_ChainInfo is set then follows a RuntimeFunction which defines
172  // the chained unwind info.
173  // For more information please see MSDN at:
174  // http://msdn.microsoft.com/en-us/library/ddssxxy8.aspx
175 
176  /// Return pointer to language specific data part of UnwindInfo.
178  return reinterpret_cast<void *>(&UnwindCodes[(NumCodes+1) & ~1]);
179  }
180 
181  /// Return pointer to language specific data part of UnwindInfo.
182  const void *getLanguageSpecificData() const {
183  return reinterpret_cast<const void *>(&UnwindCodes[(NumCodes + 1) & ~1]);
184  }
185 
186  /// Return image-relative offset of language-specific exception handler.
188  return *reinterpret_cast<const support::ulittle32_t *>(
190  }
191 
192  /// Set image-relative offset of language-specific exception handler.
194  *reinterpret_cast<support::ulittle32_t *>(getLanguageSpecificData()) =
195  offset;
196  }
197 
198  /// Return pointer to exception-specific data.
200  return reinterpret_cast<void *>(reinterpret_cast<uint32_t *>(
202  }
203 
204  /// Return pointer to chained unwind info.
206  return reinterpret_cast<RuntimeFunction *>(getLanguageSpecificData());
207  }
208 
209  /// Return pointer to chained unwind info.
211  return reinterpret_cast<const RuntimeFunction *>(getLanguageSpecificData());
212  }
213 };
214 
215 
216 } // End of namespace Win64EH
217 } // End of namespace llvm
218 
219 #endif
llvm::Win64EH::UOP_AllocMedium
@ UOP_AllocMedium
Definition: Win64EH.h:43
llvm::Win64EH::UOP_SaveXMM128
@ UOP_SaveXMM128
Definition: Win64EH.h:38
llvm::Win64EH::UnwindInfo::getFrameRegister
uint8_t getFrameRegister() const
Definition: Win64EH.h:161
llvm::Win64EH::UOP_SaveFRegD0D15
@ UOP_SaveFRegD0D15
Definition: Win64EH.h:99
llvm::Win64EH::UOP_SaveAnyRegDX
@ UOP_SaveAnyRegDX
Definition: Win64EH.h:73
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::Win64EH::UOP_PACSignLR
@ UOP_PACSignLR
Definition: Win64EH.h:64
llvm::support::detail::packed_endian_specific_integral
Definition: Endian.h:206
llvm::Win64EH::UOP_SaveAnyRegQX
@ UOP_SaveAnyRegQX
Definition: Win64EH.h:75
llvm::Win64EH::UnwindInfo::UnwindCodes
UnwindCode UnwindCodes[1]
Definition: Win64EH.h:153
llvm::Win64EH::UOP_SaveFRegP
@ UOP_SaveFRegP
Definition: Win64EH.h:54
llvm::Win64EH::UOP_SaveRegPX
@ UOP_SaveRegPX
Definition: Win64EH.h:50
llvm::Win64EH::UOP_SaveNext
@ UOP_SaveNext
Definition: Win64EH.h:60
llvm::Win64EH::UOP_PushNonVol
@ UOP_PushNonVol
Definition: Win64EH.h:30
llvm::Win64EH::UOP_SaveLRPair
@ UOP_SaveLRPair
Definition: Win64EH.h:51
llvm::Win64EH::UOP_SaveAnyRegQPX
@ UOP_SaveAnyRegQPX
Definition: Win64EH.h:76
llvm::Win64EH::UOP_WideNop
@ UOP_WideNop
Definition: Win64EH.h:102
llvm::Win64EH::UOP_EndNop
@ UOP_EndNop
Definition: Win64EH.h:104
llvm::Win64EH::UOP_SaveRegsR4R7LR
@ UOP_SaveRegsR4R7LR
Definition: Win64EH.h:94
llvm::Win64EH::UOP_TrapFrame
@ UOP_TrapFrame
Definition: Win64EH.h:61
llvm::Win64EH::UOP_Nop
@ UOP_Nop
Definition: Win64EH.h:58
llvm::Win64EH::UOP_SaveAnyRegIX
@ UOP_SaveAnyRegIX
Definition: Win64EH.h:71
llvm::Win64EH::UOP_SaveSP
@ UOP_SaveSP
Definition: Win64EH.h:93
llvm::Win64EH::UOP_AddFP
@ UOP_AddFP
Definition: Win64EH.h:57
llvm::Win64EH::UnwindInfo
UnwindInfo - An entry in the exception table.
Definition: Win64EH.h:148
llvm::Win64EH::RuntimeFunction::StartAddress
support::ulittle32_t StartAddress
Definition: Win64EH.h:142
llvm::Win64EH::RuntimeFunction::UnwindInfoOffset
support::ulittle32_t UnwindInfoOffset
Definition: Win64EH.h:144
llvm::Win64EH::UOP_SaveRegX
@ UOP_SaveRegX
Definition: Win64EH.h:48
llvm::Win64EH::UOP_SpareCode
@ UOP_SpareCode
Definition: Win64EH.h:37
llvm::Win64EH::UOP_SetFPReg
@ UOP_SetFPReg
Definition: Win64EH.h:33
llvm::Win64EH::UOP_SaveReg
@ UOP_SaveReg
Definition: Win64EH.h:47
llvm::Win64EH::UOP_WideAllocMedium
@ UOP_WideAllocMedium
Definition: Win64EH.h:88
llvm::Win64EH::UOP_SaveAnyRegQ
@ UOP_SaveAnyRegQ
Definition: Win64EH.h:69
llvm::Win64EH::UOP_SaveFRegX
@ UOP_SaveFRegX
Definition: Win64EH.h:53
llvm::Win64EH::UOP_Epilog
@ UOP_Epilog
Definition: Win64EH.h:36
llvm::Win64EH::UOP_SetFP
@ UOP_SetFP
Definition: Win64EH.h:56
llvm::Win64EH::UOP_WideSaveRegsR4R11LR
@ UOP_WideSaveRegsR4R11LR
Definition: Win64EH.h:95
llvm::Win64EH::UOP_WideAllocHuge
@ UOP_WideAllocHuge
Definition: Win64EH.h:90
llvm::Win64EH::UOP_SaveXMM128Big
@ UOP_SaveXMM128Big
Definition: Win64EH.h:39
llvm::Win64EH::UOP_SaveFPLRX
@ UOP_SaveFPLRX
Definition: Win64EH.h:45
llvm::Win64EH::UnwindCode::UnwindOpAndOpInfo
uint8_t UnwindOpAndOpInfo
Definition: Win64EH.h:116
llvm::Win64EH::UOP_End
@ UOP_End
Definition: Win64EH.h:59
llvm::Win64EH::UOP_SaveAnyRegI
@ UOP_SaveAnyRegI
Definition: Win64EH.h:65
llvm::Win64EH::UnwindOpcodes
UnwindOpcodes
UnwindOpcodes - Enumeration whose values specify a single operation in the prolog of a function.
Definition: Win64EH.h:26
llvm::Win64EH::UnwindInfo::setLanguageSpecificHandlerOffset
void setLanguageSpecificHandlerOffset(uint32_t offset)
Set image-relative offset of language-specific exception handler.
Definition: Win64EH.h:193
llvm::Win64EH::UOP_AllocSmall
@ UOP_AllocSmall
Definition: Win64EH.h:32
llvm::Win64EH::UOP_WideSaveRegMask
@ UOP_WideSaveRegMask
Definition: Win64EH.h:92
llvm::Win64EH::UnwindInfo::getExceptionData
void * getExceptionData()
Return pointer to exception-specific data.
Definition: Win64EH.h:199
llvm::Win64EH::UOP_AllocHuge
@ UOP_AllocHuge
Definition: Win64EH.h:87
llvm::Win64EH::UnwindInfo::NumCodes
uint8_t NumCodes
Definition: Win64EH.h:151
llvm::Win64EH::UNW_ExceptionHandler
@ UNW_ExceptionHandler
UNW_ExceptionHandler - Specifies that this function has an exception handler.
Definition: Win64EH.h:131
llvm::Win64EH::UOP_SaveAnyRegDPX
@ UOP_SaveAnyRegDPX
Definition: Win64EH.h:74
llvm::Win64EH::UNW_TerminateHandler
@ UNW_TerminateHandler
UNW_TerminateHandler - Specifies that this function has a termination handler.
Definition: Win64EH.h:134
llvm::Win64EH::UOP_SaveFRegD16D31
@ UOP_SaveFRegD16D31
Definition: Win64EH.h:100
llvm::Win64EH::RuntimeFunction
RuntimeFunction - An entry in the table of functions with unwind info.
Definition: Win64EH.h:141
llvm::Win64EH::UNW_ChainInfo
@ UNW_ChainInfo
UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to another one.
Definition: Win64EH.h:137
llvm::Win64EH::UnwindInfo::getVersion
uint8_t getVersion() const
Definition: Win64EH.h:155
llvm::Win64EH::UnwindInfo::PrologSize
uint8_t PrologSize
Definition: Win64EH.h:150
llvm::Win64EH::UOP_Context
@ UOP_Context
Definition: Win64EH.h:62
llvm::Win64EH::UnwindInfo::getLanguageSpecificData
void * getLanguageSpecificData()
Return pointer to language specific data part of UnwindInfo.
Definition: Win64EH.h:177
llvm::Win64EH::UnwindInfo::FrameRegisterAndOffset
uint8_t FrameRegisterAndOffset
Definition: Win64EH.h:152
llvm::Win64EH::UOP_SaveFReg
@ UOP_SaveFReg
Definition: Win64EH.h:52
llvm::Win64EH::UnwindInfo::getFlags
uint8_t getFlags() const
Definition: Win64EH.h:158
llvm::Win64EH::UOP_SaveLR
@ UOP_SaveLR
Definition: Win64EH.h:98
llvm::Win64EH::UOP_SaveNonVol
@ UOP_SaveNonVol
Definition: Win64EH.h:34
llvm::Win64EH::RuntimeFunction::EndAddress
support::ulittle32_t EndAddress
Definition: Win64EH.h:143
llvm::Win64EH::UnwindInfo::getLanguageSpecificHandlerOffset
uint32_t getLanguageSpecificHandlerOffset() const
Return image-relative offset of language-specific exception handler.
Definition: Win64EH.h:187
llvm::Win64EH::UOP_SaveFRegPX
@ UOP_SaveFRegPX
Definition: Win64EH.h:55
llvm::Win64EH::UnwindInfo::getChainedFunctionEntry
RuntimeFunction * getChainedFunctionEntry()
Return pointer to chained unwind info.
Definition: Win64EH.h:205
llvm::Win64EH::UnwindCode::CodeOffset
uint8_t CodeOffset
Definition: Win64EH.h:115
llvm::Win64EH::UnwindInfo::getChainedFunctionEntry
const RuntimeFunction * getChainedFunctionEntry() const
Return pointer to chained unwind info.
Definition: Win64EH.h:210
uint32_t
llvm::Win64EH::UOP_SaveAnyRegIP
@ UOP_SaveAnyRegIP
Definition: Win64EH.h:66
llvm::Win64EH::UnwindCode::getUnwindOp
uint8_t getUnwindOp() const
Definition: Win64EH.h:120
llvm::Win64EH::UnwindInfo::getLanguageSpecificData
const void * getLanguageSpecificData() const
Return pointer to language specific data part of UnwindInfo.
Definition: Win64EH.h:182
llvm::Win64EH::UnwindCode::u
struct llvm::Win64EH::UnwindCode::@400 u
llvm::Win64EH::UOP_ClearUnwoundToCall
@ UOP_ClearUnwoundToCall
Definition: Win64EH.h:63
llvm::Win64EH::UOP_Custom
@ UOP_Custom
Definition: Win64EH.h:108
llvm::Win64EH::UOP_SaveAnyRegIPX
@ UOP_SaveAnyRegIPX
Definition: Win64EH.h:72
llvm::Win64EH::UOP_SaveR19R20X
@ UOP_SaveR19R20X
Definition: Win64EH.h:44
llvm::Win64EH::UOP_SaveAnyRegD
@ UOP_SaveAnyRegD
Definition: Win64EH.h:67
llvm::Win64EH::UOP_SaveFRegD8D15
@ UOP_SaveFRegD8D15
Definition: Win64EH.h:96
llvm::Win64EH::UnwindCode
UnwindCode - This union describes a single operation in a function prolog, or part thereof.
Definition: Win64EH.h:113
llvm::Win64EH::UOP_SaveNonVolBig
@ UOP_SaveNonVolBig
Definition: Win64EH.h:35
llvm::Win64EH::UnwindCode::getOpInfo
uint8_t getOpInfo() const
Definition: Win64EH.h:123
llvm::Win64EH::UOP_SaveAnyRegQP
@ UOP_SaveAnyRegQP
Definition: Win64EH.h:70
llvm::Win64EH::UnwindInfo::VersionAndFlags
uint8_t VersionAndFlags
Definition: Win64EH.h:149
llvm::Win64EH::UOP_SaveRegP
@ UOP_SaveRegP
Definition: Win64EH.h:49
llvm::Win64EH::UnwindInfo::getFrameOffset
uint8_t getFrameOffset() const
Definition: Win64EH.h:164
llvm::Win64EH::UOP_SaveFPLR
@ UOP_SaveFPLR
Definition: Win64EH.h:46
llvm::Win64EH::UOP_SaveAnyRegDP
@ UOP_SaveAnyRegDP
Definition: Win64EH.h:68
llvm::Win64EH::UOP_WideAllocLarge
@ UOP_WideAllocLarge
Definition: Win64EH.h:89
DataTypes.h
Endian.h
llvm::Win64EH::UOP_PushMachFrame
@ UOP_PushMachFrame
Definition: Win64EH.h:40
llvm::Win64EH::UnwindCode::FrameOffset
support::ulittle16_t FrameOffset
Definition: Win64EH.h:118
llvm::Win64EH::UOP_WideEndNop
@ UOP_WideEndNop
Definition: Win64EH.h:105
llvm::Win64EH::UOP_SaveRegMask
@ UOP_SaveRegMask
Definition: Win64EH.h:97
llvm::Win64EH::UOP_AllocLarge
@ UOP_AllocLarge
Definition: Win64EH.h:31