LLVM  10.0.0svn
Win64EH.h
Go to the documentation of this file.
1 //===-- llvm/Support/Win64EH.h ---Win64 EH Constants-------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
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
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_SUPPORT_WIN64EH_H
16 #define LLVM_SUPPORT_WIN64EH_H
17 
18 #include "llvm/Support/DataTypes.h"
19 #include "llvm/Support/Endian.h"
20 
21 namespace llvm {
22 namespace Win64EH {
23 
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
55 };
56 
57 /// UnwindCode - This union describes a single operation in a function prolog,
58 /// or part thereof.
59 union UnwindCode {
60  struct {
61  uint8_t CodeOffset;
63  } u;
65 
66  uint8_t getUnwindOp() const {
67  return u.UnwindOpAndOpInfo & 0x0F;
68  }
69  uint8_t getOpInfo() const {
70  return (u.UnwindOpAndOpInfo >> 4) & 0x0F;
71  }
72 };
73 
74 enum {
75  /// UNW_ExceptionHandler - Specifies that this function has an exception
76  /// handler.
78  /// UNW_TerminateHandler - Specifies that this function has a termination
79  /// handler.
81  /// UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to
82  /// another one.
84 };
85 
86 /// RuntimeFunction - An entry in the table of functions with unwind info.
91 };
92 
93 /// UnwindInfo - An entry in the exception table.
94 struct UnwindInfo {
95  uint8_t VersionAndFlags;
96  uint8_t PrologSize;
97  uint8_t NumCodes;
99  UnwindCode UnwindCodes[1];
100 
101  uint8_t getVersion() const {
102  return VersionAndFlags & 0x07;
103  }
104  uint8_t getFlags() const {
105  return (VersionAndFlags >> 3) & 0x1f;
106  }
107  uint8_t getFrameRegister() const {
108  return FrameRegisterAndOffset & 0x0f;
109  }
110  uint8_t getFrameOffset() const {
111  return (FrameRegisterAndOffset >> 4) & 0x0f;
112  }
113 
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
121 
122  /// Return pointer to language specific data part of UnwindInfo.
124  return reinterpret_cast<void *>(&UnwindCodes[(NumCodes+1) & ~1]);
125  }
126 
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]);
130  }
131 
132  /// Return image-relative offset of language-specific exception handler.
134  return *reinterpret_cast<const support::ulittle32_t *>(
135  getLanguageSpecificData());
136  }
137 
138  /// Set image-relative offset of language-specific exception handler.
140  *reinterpret_cast<support::ulittle32_t *>(getLanguageSpecificData()) =
141  offset;
142  }
143 
144  /// Return pointer to exception-specific data.
146  return reinterpret_cast<void *>(reinterpret_cast<uint32_t *>(
147  getLanguageSpecificData())+1);
148  }
149 
150  /// Return pointer to chained unwind info.
152  return reinterpret_cast<RuntimeFunction *>(getLanguageSpecificData());
153  }
154 
155  /// Return pointer to chained unwind info.
157  return reinterpret_cast<const RuntimeFunction *>(getLanguageSpecificData());
158  }
159 };
160 
161 
162 } // End of namespace Win64EH
163 } // End of namespace llvm
164 
165 #endif
uint8_t getFrameRegister() const
Definition: Win64EH.h:107
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void * getExceptionData()
Return pointer to exception-specific data.
Definition: Win64EH.h:145
uint32_t getLanguageSpecificHandlerOffset() const
Return image-relative offset of language-specific exception handler.
Definition: Win64EH.h:133
UnwindCode - This union describes a single operation in a function prolog, or part thereof...
Definition: Win64EH.h:59
struct llvm::Win64EH::UnwindCode::@348 u
support::ulittle32_t EndAddress
Definition: Win64EH.h:89
UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to another one.
Definition: Win64EH.h:83
support::ulittle32_t UnwindInfoOffset
Definition: Win64EH.h:90
RuntimeFunction * getChainedFunctionEntry()
Return pointer to chained unwind info.
Definition: Win64EH.h:151
uint8_t getFlags() const
Definition: Win64EH.h:104
UNW_TerminateHandler - Specifies that this function has a termination handler.
Definition: Win64EH.h:80
uint8_t getVersion() const
Definition: Win64EH.h:101
uint8_t FrameRegisterAndOffset
Definition: Win64EH.h:98
RuntimeFunction - An entry in the table of functions with unwind info.
Definition: Win64EH.h:87
UnwindOpcodes
UnwindOpcodes - Enumeration whose values specify a single operation in the prolog of a function...
Definition: Win64EH.h:26
uint8_t getUnwindOp() const
Definition: Win64EH.h:66
void * getLanguageSpecificData()
Return pointer to language specific data part of UnwindInfo.
Definition: Win64EH.h:123
const void * getLanguageSpecificData() const
Return pointer to language specific data part of UnwindInfo.
Definition: Win64EH.h:128
support::ulittle32_t StartAddress
Definition: Win64EH.h:88
void setLanguageSpecificHandlerOffset(uint32_t offset)
Set image-relative offset of language-specific exception handler.
Definition: Win64EH.h:139
UNW_ExceptionHandler - Specifies that this function has an exception handler.
Definition: Win64EH.h:77
uint8_t getOpInfo() const
Definition: Win64EH.h:69
support::ulittle16_t FrameOffset
Definition: Win64EH.h:64
UnwindInfo - An entry in the exception table.
Definition: Win64EH.h:94
const RuntimeFunction * getChainedFunctionEntry() const
Return pointer to chained unwind info.
Definition: Win64EH.h:156
uint8_t getFrameOffset() const
Definition: Win64EH.h:110