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