LLVM API Documentation
00001 //===-- llvm/Support/Win64EH.h ---Win64 EH Constants-------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file contains constants and structures used for implementing 00011 // exception handling on Win64 platforms. For more information, see 00012 // http://msdn.microsoft.com/en-us/library/1eyas8tf.aspx 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef LLVM_SUPPORT_WIN64EH_H 00017 #define LLVM_SUPPORT_WIN64EH_H 00018 00019 #include "llvm/Support/DataTypes.h" 00020 #include "llvm/Support/Endian.h" 00021 00022 namespace llvm { 00023 namespace Win64EH { 00024 00025 /// UnwindOpcodes - Enumeration whose values specify a single operation in 00026 /// the prolog of a function. 00027 enum UnwindOpcodes { 00028 UOP_PushNonVol = 0, 00029 UOP_AllocLarge, 00030 UOP_AllocSmall, 00031 UOP_SetFPReg, 00032 UOP_SaveNonVol, 00033 UOP_SaveNonVolBig, 00034 UOP_SaveXMM128 = 8, 00035 UOP_SaveXMM128Big, 00036 UOP_PushMachFrame 00037 }; 00038 00039 /// UnwindCode - This union describes a single operation in a function prolog, 00040 /// or part thereof. 00041 union UnwindCode { 00042 struct { 00043 uint8_t CodeOffset; 00044 uint8_t UnwindOpAndOpInfo; 00045 } u; 00046 support::ulittle16_t FrameOffset; 00047 00048 uint8_t getUnwindOp() const { 00049 return u.UnwindOpAndOpInfo & 0x0F; 00050 } 00051 uint8_t getOpInfo() const { 00052 return (u.UnwindOpAndOpInfo >> 4) & 0x0F; 00053 } 00054 }; 00055 00056 enum { 00057 /// UNW_ExceptionHandler - Specifies that this function has an exception 00058 /// handler. 00059 UNW_ExceptionHandler = 0x01, 00060 /// UNW_TerminateHandler - Specifies that this function has a termination 00061 /// handler. 00062 UNW_TerminateHandler = 0x02, 00063 /// UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to 00064 /// another one. 00065 UNW_ChainInfo = 0x04 00066 }; 00067 00068 /// RuntimeFunction - An entry in the table of functions with unwind info. 00069 struct RuntimeFunction { 00070 support::ulittle32_t StartAddress; 00071 support::ulittle32_t EndAddress; 00072 support::ulittle32_t UnwindInfoOffset; 00073 }; 00074 00075 /// UnwindInfo - An entry in the exception table. 00076 struct UnwindInfo { 00077 uint8_t VersionAndFlags; 00078 uint8_t PrologSize; 00079 uint8_t NumCodes; 00080 uint8_t FrameRegisterAndOffset; 00081 UnwindCode UnwindCodes[1]; 00082 00083 uint8_t getVersion() const { 00084 return VersionAndFlags & 0x07; 00085 } 00086 uint8_t getFlags() const { 00087 return (VersionAndFlags >> 3) & 0x1f; 00088 } 00089 uint8_t getFrameRegister() const { 00090 return FrameRegisterAndOffset & 0x0f; 00091 } 00092 uint8_t getFrameOffset() const { 00093 return (FrameRegisterAndOffset >> 4) & 0x0f; 00094 } 00095 00096 // The data after unwindCodes depends on flags. 00097 // If UNW_ExceptionHandler or UNW_TerminateHandler is set then follows 00098 // the address of the language-specific exception handler. 00099 // If UNW_ChainInfo is set then follows a RuntimeFunction which defines 00100 // the chained unwind info. 00101 // For more information please see MSDN at: 00102 // http://msdn.microsoft.com/en-us/library/ddssxxy8.aspx 00103 00104 /// \brief Return pointer to language specific data part of UnwindInfo. 00105 void *getLanguageSpecificData() { 00106 return reinterpret_cast<void *>(&UnwindCodes[(NumCodes+1) & ~1]); 00107 } 00108 00109 /// \brief Return pointer to language specific data part of UnwindInfo. 00110 const void *getLanguageSpecificData() const { 00111 return reinterpret_cast<const void *>(&UnwindCodes[(NumCodes + 1) & ~1]); 00112 } 00113 00114 /// \brief Return image-relative offset of language-specific exception handler. 00115 uint32_t getLanguageSpecificHandlerOffset() const { 00116 return *reinterpret_cast<const support::ulittle32_t *>( 00117 getLanguageSpecificData()); 00118 } 00119 00120 /// \brief Set image-relative offset of language-specific exception handler. 00121 void setLanguageSpecificHandlerOffset(uint32_t offset) { 00122 *reinterpret_cast<support::ulittle32_t *>(getLanguageSpecificData()) = 00123 offset; 00124 } 00125 00126 /// \brief Return pointer to exception-specific data. 00127 void *getExceptionData() { 00128 return reinterpret_cast<void *>(reinterpret_cast<uint32_t *>( 00129 getLanguageSpecificData())+1); 00130 } 00131 00132 /// \brief Return pointer to chained unwind info. 00133 RuntimeFunction *getChainedFunctionEntry() { 00134 return reinterpret_cast<RuntimeFunction *>(getLanguageSpecificData()); 00135 } 00136 00137 /// \brief Return pointer to chained unwind info. 00138 const RuntimeFunction *getChainedFunctionEntry() const { 00139 return reinterpret_cast<const RuntimeFunction *>(getLanguageSpecificData()); 00140 } 00141 }; 00142 00143 00144 } // End of namespace Win64EH 00145 } // End of namespace llvm 00146 00147 #endif