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.
39 /// UnwindCode - This union describes a single operation in a function prolog,
43 support::ulittle8_t CodeOffset;
44 support::ulittle8_t UnwindOpAndOpInfo;
46 support::ulittle16_t FrameOffset;
48 uint8_t getUnwindOp() const {
49 return u.UnwindOpAndOpInfo & 0x0F;
51 uint8_t getOpInfo() const {
52 return (u.UnwindOpAndOpInfo >> 4) & 0x0F;
57 /// UNW_ExceptionHandler - Specifies that this function has an exception
59 UNW_ExceptionHandler = 0x01,
60 /// UNW_TerminateHandler - Specifies that this function has a termination
62 UNW_TerminateHandler = 0x02,
63 /// UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to
68 /// RuntimeFunction - An entry in the table of functions with unwind info.
69 struct RuntimeFunction {
70 support::ulittle32_t StartAddress;
71 support::ulittle32_t EndAddress;
72 support::ulittle32_t UnwindInfoOffset;
75 /// UnwindInfo - An entry in the exception table.
77 support::ulittle8_t VersionAndFlags;
78 support::ulittle8_t PrologSize;
79 support::ulittle8_t NumCodes;
80 support::ulittle8_t FrameRegisterAndOffset;
81 UnwindCode UnwindCodes[1];
83 uint8_t getVersion() const {
84 return VersionAndFlags & 0x07;
86 uint8_t getFlags() const {
87 return (VersionAndFlags >> 3) & 0x1f;
89 uint8_t getFrameRegister() const {
90 return FrameRegisterAndOffset & 0x0f;
92 uint8_t getFrameOffset() const {
93 return (FrameRegisterAndOffset >> 4) & 0x0f;
96 // The data after unwindCodes depends on flags.
97 // If UNW_ExceptionHandler or UNW_TerminateHandler is set then follows
98 // the address of the language-specific exception handler.
99 // If UNW_ChainInfo is set then follows a RuntimeFunction which defines
100 // the chained unwind info.
101 // For more information please see MSDN at:
102 // http://msdn.microsoft.com/en-us/library/ddssxxy8.aspx
104 /// \brief Return pointer to language specific data part of UnwindInfo.
105 void *getLanguageSpecificData() {
106 return reinterpret_cast<void *>(&UnwindCodes[(NumCodes+1) & ~1]);
109 /// \brief Return pointer to language specific data part of UnwindInfo.
110 const void *getLanguageSpecificData() const {
111 return reinterpret_cast<const void *>(&UnwindCodes[(NumCodes + 1) & ~1]);
114 /// \brief Return image-relative offset of language-specific exception handler.
115 uint32_t getLanguageSpecificHandlerOffset() const {
116 return *reinterpret_cast<const support::ulittle32_t *>(
117 getLanguageSpecificData());
120 /// \brief Set image-relative offset of language-specific exception handler.
121 void setLanguageSpecificHandlerOffset(uint32_t offset) {
122 *reinterpret_cast<support::ulittle32_t *>(getLanguageSpecificData()) =
126 /// \brief Return pointer to exception-specific data.
127 void *getExceptionData() {
128 return reinterpret_cast<void *>(reinterpret_cast<uint32_t *>(
129 getLanguageSpecificData())+1);
132 /// \brief Return pointer to chained unwind info.
133 RuntimeFunction *getChainedFunctionEntry() {
134 return reinterpret_cast<RuntimeFunction *>(getLanguageSpecificData());
137 /// \brief Return pointer to chained unwind info.
138 const RuntimeFunction *getChainedFunctionEntry() const {
139 return reinterpret_cast<const RuntimeFunction *>(getLanguageSpecificData());
144 } // End of namespace Win64EH
145 } // End of namespace llvm