Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.1 KiB

  1. //===- MCWin64EH.h - Machine Code Win64 EH support --------------*- 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 declarations to support the Win64 Exception Handling
  11. // scheme in MC.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_MC_MCWIN64EH_H
  15. #define LLVM_MC_MCWIN64EH_H
  16. #include "llvm/Support/Win64EH.h"
  17. #include <cassert>
  18. #include <vector>
  19. namespace llvm {
  20. class StringRef;
  21. class MCStreamer;
  22. class MCSymbol;
  23. class MCWin64EHInstruction {
  24. public:
  25. typedef Win64EH::UnwindOpcodes OpType;
  26. private:
  27. OpType Operation;
  28. MCSymbol *Label;
  29. unsigned Offset;
  30. unsigned Register;
  31. public:
  32. MCWin64EHInstruction(OpType Op, MCSymbol *L, unsigned Reg)
  33. : Operation(Op), Label(L), Offset(0), Register(Reg) {
  34. assert(Op == Win64EH::UOP_PushNonVol);
  35. }
  36. MCWin64EHInstruction(MCSymbol *L, unsigned Size)
  37. : Operation(Size>128 ? Win64EH::UOP_AllocLarge : Win64EH::UOP_AllocSmall),
  38. Label(L), Offset(Size) { }
  39. MCWin64EHInstruction(OpType Op, MCSymbol *L, unsigned Reg, unsigned Off)
  40. : Operation(Op), Label(L), Offset(Off), Register(Reg) {
  41. assert(Op == Win64EH::UOP_SetFPReg ||
  42. Op == Win64EH::UOP_SaveNonVol ||
  43. Op == Win64EH::UOP_SaveNonVolBig ||
  44. Op == Win64EH::UOP_SaveXMM128 ||
  45. Op == Win64EH::UOP_SaveXMM128Big);
  46. }
  47. MCWin64EHInstruction(OpType Op, MCSymbol *L, bool Code)
  48. : Operation(Op), Label(L), Offset(Code ? 1 : 0) {
  49. assert(Op == Win64EH::UOP_PushMachFrame);
  50. }
  51. OpType getOperation() const { return Operation; }
  52. MCSymbol *getLabel() const { return Label; }
  53. unsigned getOffset() const { return Offset; }
  54. unsigned getSize() const { return Offset; }
  55. unsigned getRegister() const { return Register; }
  56. bool isPushCodeFrame() const { return Offset == 1; }
  57. };
  58. struct MCWin64EHUnwindInfo {
  59. MCWin64EHUnwindInfo() : Begin(0), End(0), ExceptionHandler(0),
  60. Function(0), PrologEnd(0), Symbol(0),
  61. HandlesUnwind(false), HandlesExceptions(false),
  62. LastFrameInst(-1), ChainedParent(0),
  63. Instructions() {}
  64. MCSymbol *Begin;
  65. MCSymbol *End;
  66. const MCSymbol *ExceptionHandler;
  67. const MCSymbol *Function;
  68. MCSymbol *PrologEnd;
  69. MCSymbol *Symbol;
  70. bool HandlesUnwind;
  71. bool HandlesExceptions;
  72. int LastFrameInst;
  73. MCWin64EHUnwindInfo *ChainedParent;
  74. std::vector<MCWin64EHInstruction> Instructions;
  75. };
  76. class MCWin64EHUnwindEmitter {
  77. public:
  78. static StringRef GetSectionSuffix(const MCSymbol *func);
  79. //
  80. // This emits the unwind info sections (.pdata and .xdata in PE/COFF).
  81. //
  82. static void Emit(MCStreamer &streamer);
  83. static void EmitUnwindInfo(MCStreamer &streamer, MCWin64EHUnwindInfo *info);
  84. };
  85. } // end namespace llvm
  86. #endif