1 //===-- llvm/Support/Win64EH.h ---Win64 EH Constants-------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_SUPPORT_WIN64EH_H
17 #define LLVM_SUPPORT_WIN64EH_H
19 #include "llvm/Support/DataTypes.h"
20 #include "llvm/Support/Endian.h"
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
56 /// UnwindCode - This union describes a single operation in a function prolog,
61 uint8_t UnwindOpAndOpInfo;
63 support::ulittle16_t FrameOffset;
65 uint8_t getUnwindOp() const {
66 return u.UnwindOpAndOpInfo & 0x0F;
68 uint8_t getOpInfo() const {
69 return (u.UnwindOpAndOpInfo >> 4) & 0x0F;
74 /// UNW_ExceptionHandler - Specifies that this function has an exception
76 UNW_ExceptionHandler = 0x01,
77 /// UNW_TerminateHandler - Specifies that this function has a termination
79 UNW_TerminateHandler = 0x02,
80 /// UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to
85 /// RuntimeFunction - An entry in the table of functions with unwind info.
86 struct RuntimeFunction {
87 support::ulittle32_t StartAddress;
88 support::ulittle32_t EndAddress;
89 support::ulittle32_t UnwindInfoOffset;
92 /// UnwindInfo - An entry in the exception table.
94 uint8_t VersionAndFlags;
97 uint8_t FrameRegisterAndOffset;
98 UnwindCode UnwindCodes[1];
100 uint8_t getVersion() const {
101 return VersionAndFlags & 0x07;
103 uint8_t getFlags() const {
104 return (VersionAndFlags >> 3) & 0x1f;
106 uint8_t getFrameRegister() const {
107 return FrameRegisterAndOffset & 0x0f;
109 uint8_t getFrameOffset() const {
110 return (FrameRegisterAndOffset >> 4) & 0x0f;
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
121 /// Return pointer to language specific data part of UnwindInfo.
122 void *getLanguageSpecificData() {
123 return reinterpret_cast<void *>(&UnwindCodes[(NumCodes+1) & ~1]);
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]);
131 /// Return image-relative offset of language-specific exception handler.
132 uint32_t getLanguageSpecificHandlerOffset() const {
133 return *reinterpret_cast<const support::ulittle32_t *>(
134 getLanguageSpecificData());
137 /// Set image-relative offset of language-specific exception handler.
138 void setLanguageSpecificHandlerOffset(uint32_t offset) {
139 *reinterpret_cast<support::ulittle32_t *>(getLanguageSpecificData()) =
143 /// Return pointer to exception-specific data.
144 void *getExceptionData() {
145 return reinterpret_cast<void *>(reinterpret_cast<uint32_t *>(
146 getLanguageSpecificData())+1);
149 /// Return pointer to chained unwind info.
150 RuntimeFunction *getChainedFunctionEntry() {
151 return reinterpret_cast<RuntimeFunction *>(getLanguageSpecificData());
154 /// Return pointer to chained unwind info.
155 const RuntimeFunction *getChainedFunctionEntry() const {
156 return reinterpret_cast<const RuntimeFunction *>(getLanguageSpecificData());
161 } // End of namespace Win64EH
162 } // End of namespace llvm