1 //===-- llvm/Support/Win64EH.h ---Win64 EH Constants-------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_SUPPORT_WIN64EH_H
16 #define LLVM_SUPPORT_WIN64EH_H
18 #include "llvm/Support/DataTypes.h"
19 #include "llvm/Support/Endian.h"
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
57 /// UnwindCode - This union describes a single operation in a function prolog,
62 uint8_t UnwindOpAndOpInfo
;
64 support::ulittle16_t FrameOffset
;
66 uint8_t getUnwindOp() const {
67 return u
.UnwindOpAndOpInfo
& 0x0F;
69 uint8_t getOpInfo() const {
70 return (u
.UnwindOpAndOpInfo
>> 4) & 0x0F;
75 /// UNW_ExceptionHandler - Specifies that this function has an exception
77 UNW_ExceptionHandler
= 0x01,
78 /// UNW_TerminateHandler - Specifies that this function has a termination
80 UNW_TerminateHandler
= 0x02,
81 /// UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to
86 /// RuntimeFunction - An entry in the table of functions with unwind info.
87 struct RuntimeFunction
{
88 support::ulittle32_t StartAddress
;
89 support::ulittle32_t EndAddress
;
90 support::ulittle32_t UnwindInfoOffset
;
93 /// UnwindInfo - An entry in the exception table.
95 uint8_t VersionAndFlags
;
98 uint8_t FrameRegisterAndOffset
;
99 UnwindCode UnwindCodes
[1];
101 uint8_t getVersion() const {
102 return VersionAndFlags
& 0x07;
104 uint8_t getFlags() const {
105 return (VersionAndFlags
>> 3) & 0x1f;
107 uint8_t getFrameRegister() const {
108 return FrameRegisterAndOffset
& 0x0f;
110 uint8_t getFrameOffset() const {
111 return (FrameRegisterAndOffset
>> 4) & 0x0f;
114 // The data after unwindCodes depends on flags.
115 // If UNW_ExceptionHandler or UNW_TerminateHandler is set then follows
116 // the address of the language-specific exception handler.
117 // If UNW_ChainInfo is set then follows a RuntimeFunction which defines
118 // the chained unwind info.
119 // For more information please see MSDN at:
120 // http://msdn.microsoft.com/en-us/library/ddssxxy8.aspx
122 /// Return pointer to language specific data part of UnwindInfo.
123 void *getLanguageSpecificData() {
124 return reinterpret_cast<void *>(&UnwindCodes
[(NumCodes
+1) & ~1]);
127 /// Return pointer to language specific data part of UnwindInfo.
128 const void *getLanguageSpecificData() const {
129 return reinterpret_cast<const void *>(&UnwindCodes
[(NumCodes
+ 1) & ~1]);
132 /// Return image-relative offset of language-specific exception handler.
133 uint32_t getLanguageSpecificHandlerOffset() const {
134 return *reinterpret_cast<const support::ulittle32_t
*>(
135 getLanguageSpecificData());
138 /// Set image-relative offset of language-specific exception handler.
139 void setLanguageSpecificHandlerOffset(uint32_t offset
) {
140 *reinterpret_cast<support::ulittle32_t
*>(getLanguageSpecificData()) =
144 /// Return pointer to exception-specific data.
145 void *getExceptionData() {
146 return reinterpret_cast<void *>(reinterpret_cast<uint32_t *>(
147 getLanguageSpecificData())+1);
150 /// Return pointer to chained unwind info.
151 RuntimeFunction
*getChainedFunctionEntry() {
152 return reinterpret_cast<RuntimeFunction
*>(getLanguageSpecificData());
155 /// Return pointer to chained unwind info.
156 const RuntimeFunction
*getChainedFunctionEntry() const {
157 return reinterpret_cast<const RuntimeFunction
*>(getLanguageSpecificData());
162 } // End of namespace Win64EH
163 } // End of namespace llvm