Home | History | Annotate | Download | only in Support
      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 #include "llvm/Support/DataTypes.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.
     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 = 8,
     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   } u;
     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 /// RuntimeFunction - An entry in the table of functions with unwind info.
     62 struct RuntimeFunction {
     63   uint64_t startAddress;
     64   uint64_t endAddress;
     65   uint64_t unwindInfoOffset;
     66 };
     67 
     68 /// UnwindInfo - An entry in the exception table.
     69 struct UnwindInfo {
     70   uint8_t version:3,
     71           flags:5;
     72   uint8_t prologSize;
     73   uint8_t numCodes;
     74   uint8_t frameRegister:4,
     75           frameOffset:4;
     76   UnwindCode unwindCodes[1];
     77 
     78   void *getLanguageSpecificData() {
     79     return reinterpret_cast<void *>(&unwindCodes[(numCodes+1) & ~1]);
     80   }
     81   uint64_t getLanguageSpecificHandlerOffset() {
     82     return *reinterpret_cast<uint64_t *>(getLanguageSpecificData());
     83   }
     84   void setLanguageSpecificHandlerOffset(uint64_t offset) {
     85     *reinterpret_cast<uint64_t *>(getLanguageSpecificData()) = offset;
     86   }
     87   RuntimeFunction *getChainedFunctionEntry() {
     88     return reinterpret_cast<RuntimeFunction *>(getLanguageSpecificData());
     89   }
     90   void *getExceptionData() {
     91     return reinterpret_cast<void *>(reinterpret_cast<uint64_t *>(
     92                                                   getLanguageSpecificData())+1);
     93   }
     94 };
     95 
     96 
     97 } // End of namespace Win64EH
     98 } // End of namespace llvm
     99 
    100 #endif
    101