54ed68c52f27ba15f49c0cee6b48a04e321e094e
[oota-llvm.git] / include / llvm / Support / Win64EH.h
1 //===-- llvm/Support/Win64EH.h ---Win64 EH Constants-------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_SUPPORT_WIN64EH_H
17 #define LLVM_SUPPORT_WIN64EH_H
18
19 namespace llvm {
20 namespace Win64EH {
21
22 extern "C" {
23
24 /// UnwindOpcodes - Enumeration whose values specify a single operation in
25 /// the prolog of a function.
26 enum UnwindOpcodes {
27   UOP_PushNonVol = 0,
28   UOP_AllocLarge,
29   UOP_AllocSmall,
30   UOP_SetFPReg,
31   UOP_SaveNonVol,
32   UOP_SaveNonVolBig,
33   UOP_SaveXMM128,
34   UOP_SaveXMM128Big,
35   UOP_PushMachFrame
36 };
37
38 /// UnwindCode - This union describes a single operation in a function prolog,
39 /// or part thereof.
40 union UnwindCode {
41   struct {
42     uint8_t codeOffset;
43     uint8_t unwindOp:4,
44             opInfo:4;
45   };
46   uint16_t frameOffset;
47 };
48
49 enum {
50   /// UNW_ExceptionHandler - Specifies that this function has an exception
51   /// handler.
52   UNW_ExceptionHandler = 0x01,
53   /// UNW_TerminateHandler - Specifies that this function has a termination
54   /// handler.
55   UNW_TerminateHandler = 0x02,
56   /// UNW_ChainInfo - Specifies that this UnwindInfo structure is chained to
57   /// another one.
58   UNW_ChainInfo = 0x04
59 };
60
61 /// UnwindInfo - An entry in the exception table.
62 struct UnwindInfo {
63   uint8_t version:3,
64           flags:5;
65   uint8_t prologSize;
66   uint8_t numCodes;
67   uint8_t frameRegister:4,
68           frameOffset:4;
69   UnwindCode unwindCodes[1];
70 };
71
72 inline UnwindCode &getUnwindCodeEntry(UnwindInfo &info, uint32_t index) {
73   return info.unwindCodes[index];
74 }
75 inline void *getLanguageSpecificData(UnwindInfo &info) {
76   return reinterpret_cast<void *>(&getUnwindCodeEntry(info,info.numCodes+1)&~1);
77 }
78 inline uint64_t getLanguageSpecificHandlerOffset(UnwindInfo &info) {
79   return *reinterpret_cast<uint64_t *>(getLangaugeSpecificData(info));
80 }
81 inline void setLanguageSpecificHandlerOffset(UnwindInfo &info, uint64_t offset){
82   *reinterpret_cast<uint64_t *>(getLanguageSpecificData(info)) = offset;
83 }
84 inline uint64_t getChainedFunctionEntryOffset(UnwindInfo &info) {
85   return *reinterpret_cast<uint64_t *>(getLanguageSpecificData(info));
86 }
87 inline void setChainedFunctionEntryOffset(UnwindInfo &info, uint64_t offset) {
88   *reinterpret_cast<uint64_t *>(getLanguageSpecificData(info)) = offset;
89 }
90 inline void *getExceptionData(UnwindInfo &info) {
91   return reinterpret_cast<void *>(reinterpret_cast<uint64_t *>(
92                                               getLanguageSpecificData(info))+1);
93 }
94
95 } // End of extern "C"
96
97 } // End of namespace Win64EH
98 } // End of namespace llvm
99
100 #endif