LLVM  14.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.
38  // The following set of unwind opcodes is for ARM64. They are documented at
39  // https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling
61 };
62 
63 /// UnwindCode - This union describes a single operation in a function prolog,
64 /// or part thereof.
65 union UnwindCode {
66  struct {
67  uint8_t CodeOffset;
69  } u;
71 
72  uint8_t getUnwindOp() const {
73  return u.UnwindOpAndOpInfo & 0x0F;
74  }
75  uint8_t getOpInfo() const {
76  return (u.UnwindOpAndOpInfo >> 4) & 0x0F;
77  }
78 };
79 
80 enum {
81  /// UNW_ExceptionHandler - Specifies that this function has an exception
82  /// handler.
84  /// UNW_TerminateHandler - Specifies that this function has a termination
85  /// handler.
87  /// UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to
88  /// another one.
90 };
91 
92 /// RuntimeFunction - An entry in the table of functions with unwind info.
97 };
98 
99 /// UnwindInfo - An entry in the exception table.
100 struct UnwindInfo {
102  uint8_t PrologSize;
103  uint8_t NumCodes;
106 
107  uint8_t getVersion() const {
108  return VersionAndFlags & 0x07;
109  }
110  uint8_t getFlags() const {
111  return (VersionAndFlags >> 3) & 0x1f;
112  }
113  uint8_t getFrameRegister() const {
114  return FrameRegisterAndOffset & 0x0f;
115  }
116  uint8_t getFrameOffset() const {
117  return (FrameRegisterAndOffset >> 4) & 0x0f;
118  }
119 
120  // The data after unwindCodes depends on flags.
121  // If UNW_ExceptionHandler or UNW_TerminateHandler is set then follows
122  // the address of the language-specific exception handler.
123  // If UNW_ChainInfo is set then follows a RuntimeFunction which defines
124  // the chained unwind info.
125  // For more information please see MSDN at:
126  // http://msdn.microsoft.com/en-us/library/ddssxxy8.aspx
127 
128  /// Return pointer to language specific data part of UnwindInfo.
130  return reinterpret_cast<void *>(&UnwindCodes[(NumCodes+1) & ~1]);
131  }
132 
133  /// Return pointer to language specific data part of UnwindInfo.
134  const void *getLanguageSpecificData() const {
135  return reinterpret_cast<const void *>(&UnwindCodes[(NumCodes + 1) & ~1]);
136  }
137 
138  /// Return image-relative offset of language-specific exception handler.
140  return *reinterpret_cast<const support::ulittle32_t *>(
142  }
143 
144  /// Set image-relative offset of language-specific exception handler.
146  *reinterpret_cast<support::ulittle32_t *>(getLanguageSpecificData()) =
147  offset;
148  }
149 
150  /// Return pointer to exception-specific data.
152  return reinterpret_cast<void *>(reinterpret_cast<uint32_t *>(
154  }
155 
156  /// Return pointer to chained unwind info.
158  return reinterpret_cast<RuntimeFunction *>(getLanguageSpecificData());
159  }
160 
161  /// Return pointer to chained unwind info.
163  return reinterpret_cast<const RuntimeFunction *>(getLanguageSpecificData());
164  }
165 };
166 
167 
168 } // End of namespace Win64EH
169 } // End of namespace llvm
170 
171 #endif
llvm::Win64EH::UOP_AllocMedium
@ UOP_AllocMedium
Definition: Win64EH.h:40
llvm::Win64EH::UOP_SaveXMM128
@ UOP_SaveXMM128
Definition: Win64EH.h:35
llvm::Win64EH::UnwindInfo::getFrameRegister
uint8_t getFrameRegister() const
Definition: Win64EH.h:113
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::support::detail::packed_endian_specific_integral
Definition: Endian.h:206
llvm::Win64EH::UnwindInfo::UnwindCodes
UnwindCode UnwindCodes[1]
Definition: Win64EH.h:105
llvm::Win64EH::UNW_TerminateHandler
@ UNW_TerminateHandler
UNW_TerminateHandler - Specifies that this function has a termination handler.
Definition: Win64EH.h:86
llvm::Win64EH::UOP_SaveFRegP
@ UOP_SaveFRegP
Definition: Win64EH.h:51
llvm::Win64EH::UOP_SaveRegPX
@ UOP_SaveRegPX
Definition: Win64EH.h:47
llvm::Win64EH::UOP_SaveNext
@ UOP_SaveNext
Definition: Win64EH.h:57
llvm::Win64EH::UOP_PushNonVol
@ UOP_PushNonVol
Definition: Win64EH.h:27
llvm::Win64EH::UOP_SaveLRPair
@ UOP_SaveLRPair
Definition: Win64EH.h:48
llvm::Win64EH::UnwindCode::u
struct llvm::Win64EH::UnwindCode::@379 u
llvm::Win64EH::UOP_TrapFrame
@ UOP_TrapFrame
Definition: Win64EH.h:58
llvm::Win64EH::UOP_Nop
@ UOP_Nop
Definition: Win64EH.h:55
llvm::Win64EH::UOP_AddFP
@ UOP_AddFP
Definition: Win64EH.h:54
llvm::Win64EH::UnwindInfo
UnwindInfo - An entry in the exception table.
Definition: Win64EH.h:100
llvm::Win64EH::RuntimeFunction::StartAddress
support::ulittle32_t StartAddress
Definition: Win64EH.h:94
llvm::Win64EH::RuntimeFunction::UnwindInfoOffset
support::ulittle32_t UnwindInfoOffset
Definition: Win64EH.h:96
llvm::Win64EH::UOP_SaveRegX
@ UOP_SaveRegX
Definition: Win64EH.h:45
llvm::Win64EH::UOP_SpareCode
@ UOP_SpareCode
Definition: Win64EH.h:34
llvm::Win64EH::UOP_SetFPReg
@ UOP_SetFPReg
Definition: Win64EH.h:30
llvm::Win64EH::UOP_SaveReg
@ UOP_SaveReg
Definition: Win64EH.h:44
llvm::Win64EH::UOP_SaveFRegX
@ UOP_SaveFRegX
Definition: Win64EH.h:50
llvm::Win64EH::UOP_Epilog
@ UOP_Epilog
Definition: Win64EH.h:33
llvm::Win64EH::UOP_SetFP
@ UOP_SetFP
Definition: Win64EH.h:53
llvm::Win64EH::UOP_SaveXMM128Big
@ UOP_SaveXMM128Big
Definition: Win64EH.h:36
llvm::Win64EH::UOP_SaveFPLRX
@ UOP_SaveFPLRX
Definition: Win64EH.h:42
llvm::Win64EH::UnwindCode::UnwindOpAndOpInfo
uint8_t UnwindOpAndOpInfo
Definition: Win64EH.h:68
llvm::Win64EH::UOP_End
@ UOP_End
Definition: Win64EH.h:56
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:145
llvm::Win64EH::UOP_AllocSmall
@ UOP_AllocSmall
Definition: Win64EH.h:29
llvm::Win64EH::UnwindInfo::getExceptionData
void * getExceptionData()
Return pointer to exception-specific data.
Definition: Win64EH.h:151
llvm::Win64EH::UnwindInfo::NumCodes
uint8_t NumCodes
Definition: Win64EH.h:103
llvm::Win64EH::UNW_ExceptionHandler
@ UNW_ExceptionHandler
UNW_ExceptionHandler - Specifies that this function has an exception handler.
Definition: Win64EH.h:83
llvm::Win64EH::RuntimeFunction
RuntimeFunction - An entry in the table of functions with unwind info.
Definition: Win64EH.h:93
llvm::Win64EH::UnwindInfo::getVersion
uint8_t getVersion() const
Definition: Win64EH.h:107
llvm::Win64EH::UnwindInfo::PrologSize
uint8_t PrologSize
Definition: Win64EH.h:102
llvm::Win64EH::UOP_Context
@ UOP_Context
Definition: Win64EH.h:59
llvm::Win64EH::UnwindInfo::getLanguageSpecificData
void * getLanguageSpecificData()
Return pointer to language specific data part of UnwindInfo.
Definition: Win64EH.h:129
llvm::Win64EH::UnwindInfo::FrameRegisterAndOffset
uint8_t FrameRegisterAndOffset
Definition: Win64EH.h:104
llvm::Win64EH::UOP_SaveFReg
@ UOP_SaveFReg
Definition: Win64EH.h:49
llvm::Win64EH::UnwindInfo::getFlags
uint8_t getFlags() const
Definition: Win64EH.h:110
llvm::Win64EH::UOP_SaveNonVol
@ UOP_SaveNonVol
Definition: Win64EH.h:31
llvm::Win64EH::RuntimeFunction::EndAddress
support::ulittle32_t EndAddress
Definition: Win64EH.h:95
llvm::Win64EH::UnwindInfo::getLanguageSpecificHandlerOffset
uint32_t getLanguageSpecificHandlerOffset() const
Return image-relative offset of language-specific exception handler.
Definition: Win64EH.h:139
llvm::Win64EH::UOP_SaveFRegPX
@ UOP_SaveFRegPX
Definition: Win64EH.h:52
llvm::Win64EH::UnwindInfo::getChainedFunctionEntry
RuntimeFunction * getChainedFunctionEntry()
Return pointer to chained unwind info.
Definition: Win64EH.h:157
llvm::Win64EH::UnwindCode::CodeOffset
uint8_t CodeOffset
Definition: Win64EH.h:67
llvm::Win64EH::UnwindInfo::getChainedFunctionEntry
const RuntimeFunction * getChainedFunctionEntry() const
Return pointer to chained unwind info.
Definition: Win64EH.h:162
uint32_t
llvm::Win64EH::UnwindCode::getUnwindOp
uint8_t getUnwindOp() const
Definition: Win64EH.h:72
llvm::Win64EH::UnwindInfo::getLanguageSpecificData
const void * getLanguageSpecificData() const
Return pointer to language specific data part of UnwindInfo.
Definition: Win64EH.h:134
llvm::Win64EH::UOP_ClearUnwoundToCall
@ UOP_ClearUnwoundToCall
Definition: Win64EH.h:60
llvm::Win64EH::UOP_SaveR19R20X
@ UOP_SaveR19R20X
Definition: Win64EH.h:41
llvm::Win64EH::UnwindCode
UnwindCode - This union describes a single operation in a function prolog, or part thereof.
Definition: Win64EH.h:65
llvm::Win64EH::UNW_ChainInfo
@ UNW_ChainInfo
UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to another one.
Definition: Win64EH.h:89
llvm::Win64EH::UOP_SaveNonVolBig
@ UOP_SaveNonVolBig
Definition: Win64EH.h:32
llvm::Win64EH::UnwindCode::getOpInfo
uint8_t getOpInfo() const
Definition: Win64EH.h:75
llvm::Win64EH::UnwindInfo::VersionAndFlags
uint8_t VersionAndFlags
Definition: Win64EH.h:101
llvm::Win64EH::UOP_SaveRegP
@ UOP_SaveRegP
Definition: Win64EH.h:46
llvm::Win64EH::UnwindInfo::getFrameOffset
uint8_t getFrameOffset() const
Definition: Win64EH.h:116
llvm::Win64EH::UOP_SaveFPLR
@ UOP_SaveFPLR
Definition: Win64EH.h:43
DataTypes.h
Endian.h
llvm::Win64EH::UOP_PushMachFrame
@ UOP_PushMachFrame
Definition: Win64EH.h:37
llvm::Win64EH::UnwindCode::FrameOffset
support::ulittle16_t FrameOffset
Definition: Win64EH.h:70
llvm::Win64EH::UOP_AllocLarge
@ UOP_AllocLarge
Definition: Win64EH.h:28