Updates to Win64EH.h structures.

Change member types of RuntimeFunction and UnwindInfo from uint64_t to
uint32_t:
These members represent addresses. According to MSDN, they are image
relative, that is, they are 32-bit offsets from the starting address
of the image that contains the function table entry.
See MSDN for more information:
RUNTIME_FUNCTION: http://msdn.microsoft.com/en-us/library/ft9x1kdx.aspx
UNWIND_INFO: http://msdn.microsoft.com/en-us/library/ddssxxy8.aspx

Make Win64.h platform-neutral:
The standard types unit8_t, uint16_t and uint32_t are replaced with
their counterparts from Endian.h. Accessor functions are introduced to
replace bit fields.

Patch by João Matos and Kai Nacke.

llvm-svn: 169414
This commit is contained in:
Michael J. Spencer 2012-12-05 20:12:13 +00:00
parent ae638b3f91
commit fa8e8c5193
1 changed files with 58 additions and 23 deletions

View File

@ -17,6 +17,7 @@
#define LLVM_SUPPORT_WIN64EH_H #define LLVM_SUPPORT_WIN64EH_H
#include "llvm/Support/DataTypes.h" #include "llvm/Support/DataTypes.h"
#include "llvm/Support/Endian.h"
namespace llvm { namespace llvm {
namespace Win64EH { namespace Win64EH {
@ -39,11 +40,17 @@ enum UnwindOpcodes {
/// or part thereof. /// or part thereof.
union UnwindCode { union UnwindCode {
struct { struct {
uint8_t codeOffset; support::ulittle8_t CodeOffset;
uint8_t unwindOp:4, support::ulittle8_t UnwindOpAndOpInfo;
opInfo:4;
} u; } u;
uint16_t frameOffset; support::ulittle16_t FrameOffset;
uint8_t getUnwindOp() const {
return u.UnwindOpAndOpInfo & 0x0F;
}
uint8_t getOpInfo() const {
return (u.UnwindOpAndOpInfo >> 4) & 0x0F;
}
}; };
enum { enum {
@ -60,37 +67,65 @@ enum {
/// RuntimeFunction - An entry in the table of functions with unwind info. /// RuntimeFunction - An entry in the table of functions with unwind info.
struct RuntimeFunction { struct RuntimeFunction {
uint64_t startAddress; support::ulittle32_t StartAddress;
uint64_t endAddress; support::ulittle32_t EndAddress;
uint64_t unwindInfoOffset; support::ulittle32_t UnwindInfoOffset;
}; };
/// UnwindInfo - An entry in the exception table. /// UnwindInfo - An entry in the exception table.
struct UnwindInfo { struct UnwindInfo {
uint8_t version:3, support::ulittle8_t VersionAndFlags;
flags:5; support::ulittle8_t PrologSize;
uint8_t prologSize; support::ulittle8_t NumCodes;
uint8_t numCodes; support::ulittle8_t FrameRegisterAndOffset;
uint8_t frameRegister:4, UnwindCode UnwindCodes[1];
frameOffset:4;
UnwindCode unwindCodes[1];
uint8_t getVersion() const {
return VersionAndFlags & 0x07;
}
uint8_t getFlags() const {
return (VersionAndFlags >> 3) & 0x1f;
}
uint8_t getFrameRegister() const {
return FrameRegisterAndOffset & 0x0f;
}
uint8_t getFrameOffset() const {
return (FrameRegisterAndOffset >> 4) & 0x0f;
}
// The data after unwindCodes depends on flags.
// If UNW_ExceptionHandler or UNW_TerminateHandler is set then follows
// the address of the language-specific exception handler.
// If UNW_ChainInfo is set then follows a RuntimeFunction which defines
// the chained unwind info.
// For more information please see MSDN at:
// http://msdn.microsoft.com/en-us/library/ddssxxy8.aspx
/// \brief Return pointer to language specific data part of UnwindInfo.
void *getLanguageSpecificData() { void *getLanguageSpecificData() {
return reinterpret_cast<void *>(&unwindCodes[(numCodes+1) & ~1]); return reinterpret_cast<void *>(&UnwindCodes[(NumCodes+1) & ~1]);
} }
uint64_t getLanguageSpecificHandlerOffset() {
return *reinterpret_cast<uint64_t *>(getLanguageSpecificData()); /// \brief Return image-relativ offset of language-specific exception handler.
uint32_t getLanguageSpecificHandlerOffset() {
return *reinterpret_cast<uint32_t *>(getLanguageSpecificData());
} }
void setLanguageSpecificHandlerOffset(uint64_t offset) {
*reinterpret_cast<uint64_t *>(getLanguageSpecificData()) = offset; /// \brief Set image-relativ offset of language-specific exception handler.
void setLanguageSpecificHandlerOffset(uint32_t offset) {
*reinterpret_cast<uint32_t *>(getLanguageSpecificData()) = offset;
} }
/// \brief Return pointer to exception-specific data.
void *getExceptionData() {
return reinterpret_cast<void *>(reinterpret_cast<uint32_t *>(
getLanguageSpecificData())+1);
}
/// \brief Return pointer to chained unwind info.
RuntimeFunction *getChainedFunctionEntry() { RuntimeFunction *getChainedFunctionEntry() {
return reinterpret_cast<RuntimeFunction *>(getLanguageSpecificData()); return reinterpret_cast<RuntimeFunction *>(getLanguageSpecificData());
} }
void *getExceptionData() {
return reinterpret_cast<void *>(reinterpret_cast<uint64_t *>(
getLanguageSpecificData())+1);
}
}; };