LLVM  9.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.
36  // The following set of unwind opcodes is for ARM64. They are documented at
37  // https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling
53 };
54 
55 /// UnwindCode - This union describes a single operation in a function prolog,
56 /// or part thereof.
57 union UnwindCode {
58  struct {
59  uint8_t CodeOffset;
61  } u;
63 
64  uint8_t getUnwindOp() const {
65  return u.UnwindOpAndOpInfo & 0x0F;
66  }
67  uint8_t getOpInfo() const {
68  return (u.UnwindOpAndOpInfo >> 4) & 0x0F;
69  }
70 };
71 
72 enum {
73  /// UNW_ExceptionHandler - Specifies that this function has an exception
74  /// handler.
76  /// UNW_TerminateHandler - Specifies that this function has a termination
77  /// handler.
79  /// UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to
80  /// another one.
82 };
83 
84 /// RuntimeFunction - An entry in the table of functions with unwind info.
89 };
90 
91 /// UnwindInfo - An entry in the exception table.
92 struct UnwindInfo {
93  uint8_t VersionAndFlags;
94  uint8_t PrologSize;
95  uint8_t NumCodes;
97  UnwindCode UnwindCodes[1];
98 
99  uint8_t getVersion() const {
100  return VersionAndFlags & 0x07;
101  }
102  uint8_t getFlags() const {
103  return (VersionAndFlags >> 3) & 0x1f;
104  }
105  uint8_t getFrameRegister() const {
106  return FrameRegisterAndOffset & 0x0f;
107  }
108  uint8_t getFrameOffset() const {
109  return (FrameRegisterAndOffset >> 4) & 0x0f;
110  }
111 
112  // The data after unwindCodes depends on flags.
113  // If UNW_ExceptionHandler or UNW_TerminateHandler is set then follows
114  // the address of the language-specific exception handler.
115  // If UNW_ChainInfo is set then follows a RuntimeFunction which defines
116  // the chained unwind info.
117  // For more information please see MSDN at:
118  // http://msdn.microsoft.com/en-us/library/ddssxxy8.aspx
119 
120  /// Return pointer to language specific data part of UnwindInfo.
122  return reinterpret_cast<void *>(&UnwindCodes[(NumCodes+1) & ~1]);
123  }
124 
125  /// Return pointer to language specific data part of UnwindInfo.
126  const void *getLanguageSpecificData() const {
127  return reinterpret_cast<const void *>(&UnwindCodes[(NumCodes + 1) & ~1]);
128  }
129 
130  /// Return image-relative offset of language-specific exception handler.
132  return *reinterpret_cast<const support::ulittle32_t *>(
133  getLanguageSpecificData());
134  }
135 
136  /// Set image-relative offset of language-specific exception handler.
138  *reinterpret_cast<support::ulittle32_t *>(getLanguageSpecificData()) =
139  offset;
140  }
141 
142  /// Return pointer to exception-specific data.
144  return reinterpret_cast<void *>(reinterpret_cast<uint32_t *>(
145  getLanguageSpecificData())+1);
146  }
147 
148  /// Return pointer to chained unwind info.
150  return reinterpret_cast<RuntimeFunction *>(getLanguageSpecificData());
151  }
152 
153  /// Return pointer to chained unwind info.
155  return reinterpret_cast<const RuntimeFunction *>(getLanguageSpecificData());
156  }
157 };
158 
159 
160 } // End of namespace Win64EH
161 } // End of namespace llvm
162 
163 #endif
UNW_ExceptionHandler - Specifies that this function has an exception handler.
Definition: Win64EH.h:75
uint8_t getFrameRegister() const
Definition: Win64EH.h:105
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void * getExceptionData()
Return pointer to exception-specific data.
Definition: Win64EH.h:143
uint32_t getLanguageSpecificHandlerOffset() const
Return image-relative offset of language-specific exception handler.
Definition: Win64EH.h:131
UnwindCode - This union describes a single operation in a function prolog, or part thereof...
Definition: Win64EH.h:57
support::ulittle32_t EndAddress
Definition: Win64EH.h:87
support::ulittle32_t UnwindInfoOffset
Definition: Win64EH.h:88
RuntimeFunction * getChainedFunctionEntry()
Return pointer to chained unwind info.
Definition: Win64EH.h:149
uint8_t getFlags() const
Definition: Win64EH.h:102
uint8_t getVersion() const
Definition: Win64EH.h:99
struct llvm::Win64EH::UnwindCode::@329 u
uint8_t FrameRegisterAndOffset
Definition: Win64EH.h:96
UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to another one.
Definition: Win64EH.h:81
RuntimeFunction - An entry in the table of functions with unwind info.
Definition: Win64EH.h:85
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:64
void * getLanguageSpecificData()
Return pointer to language specific data part of UnwindInfo.
Definition: Win64EH.h:121
const void * getLanguageSpecificData() const
Return pointer to language specific data part of UnwindInfo.
Definition: Win64EH.h:126
support::ulittle32_t StartAddress
Definition: Win64EH.h:86
void setLanguageSpecificHandlerOffset(uint32_t offset)
Set image-relative offset of language-specific exception handler.
Definition: Win64EH.h:137
uint8_t getOpInfo() const
Definition: Win64EH.h:67
support::ulittle16_t FrameOffset
Definition: Win64EH.h:62
UnwindInfo - An entry in the exception table.
Definition: Win64EH.h:92
const RuntimeFunction * getChainedFunctionEntry() const
Return pointer to chained unwind info.
Definition: Win64EH.h:154
uint8_t getFrameOffset() const
Definition: Win64EH.h:108
UNW_TerminateHandler - Specifies that this function has a termination handler.
Definition: Win64EH.h:78