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.

145 lines
4.5 KiB

  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. #ifndef LLVM_SUPPORT_WIN64EH_H
  16. #define LLVM_SUPPORT_WIN64EH_H
  17. #include "llvm/Support/DataTypes.h"
  18. #include "llvm/Support/Endian.h"
  19. namespace llvm {
  20. namespace Win64EH {
  21. /// UnwindOpcodes - Enumeration whose values specify a single operation in
  22. /// the prolog of a function.
  23. enum UnwindOpcodes {
  24. UOP_PushNonVol = 0,
  25. UOP_AllocLarge,
  26. UOP_AllocSmall,
  27. UOP_SetFPReg,
  28. UOP_SaveNonVol,
  29. UOP_SaveNonVolBig,
  30. UOP_SaveXMM128 = 8,
  31. UOP_SaveXMM128Big,
  32. UOP_PushMachFrame
  33. };
  34. /// UnwindCode - This union describes a single operation in a function prolog,
  35. /// or part thereof.
  36. union UnwindCode {
  37. struct {
  38. support::ulittle8_t CodeOffset;
  39. support::ulittle8_t UnwindOpAndOpInfo;
  40. } u;
  41. support::ulittle16_t FrameOffset;
  42. uint8_t getUnwindOp() const {
  43. return u.UnwindOpAndOpInfo & 0x0F;
  44. }
  45. uint8_t getOpInfo() const {
  46. return (u.UnwindOpAndOpInfo >> 4) & 0x0F;
  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. /// RuntimeFunction - An entry in the table of functions with unwind info.
  61. struct RuntimeFunction {
  62. support::ulittle32_t StartAddress;
  63. support::ulittle32_t EndAddress;
  64. support::ulittle32_t UnwindInfoOffset;
  65. };
  66. /// UnwindInfo - An entry in the exception table.
  67. struct UnwindInfo {
  68. support::ulittle8_t VersionAndFlags;
  69. support::ulittle8_t PrologSize;
  70. support::ulittle8_t NumCodes;
  71. support::ulittle8_t FrameRegisterAndOffset;
  72. UnwindCode UnwindCodes[1];
  73. uint8_t getVersion() const {
  74. return VersionAndFlags & 0x07;
  75. }
  76. uint8_t getFlags() const {
  77. return (VersionAndFlags >> 3) & 0x1f;
  78. }
  79. uint8_t getFrameRegister() const {
  80. return FrameRegisterAndOffset & 0x0f;
  81. }
  82. uint8_t getFrameOffset() const {
  83. return (FrameRegisterAndOffset >> 4) & 0x0f;
  84. }
  85. // The data after unwindCodes depends on flags.
  86. // If UNW_ExceptionHandler or UNW_TerminateHandler is set then follows
  87. // the address of the language-specific exception handler.
  88. // If UNW_ChainInfo is set then follows a RuntimeFunction which defines
  89. // the chained unwind info.
  90. // For more information please see MSDN at:
  91. // http://msdn.microsoft.com/en-us/library/ddssxxy8.aspx
  92. /// \brief Return pointer to language specific data part of UnwindInfo.
  93. void *getLanguageSpecificData() {
  94. return reinterpret_cast<void *>(&UnwindCodes[(NumCodes+1) & ~1]);
  95. }
  96. /// \brief Return pointer to language specific data part of UnwindInfo.
  97. const void *getLanguageSpecificData() const {
  98. return reinterpret_cast<const void *>(&UnwindCodes[(NumCodes+1) & ~1]);
  99. }
  100. /// \brief Return image-relative offset of language-specific exception handler.
  101. uint32_t getLanguageSpecificHandlerOffset() const {
  102. return *reinterpret_cast<const uint32_t *>(getLanguageSpecificData());
  103. }
  104. /// \brief Set image-relative offset of language-specific exception handler.
  105. void setLanguageSpecificHandlerOffset(uint32_t offset) {
  106. *reinterpret_cast<uint32_t *>(getLanguageSpecificData()) = offset;
  107. }
  108. /// \brief Return pointer to exception-specific data.
  109. void *getExceptionData() {
  110. return reinterpret_cast<void *>(reinterpret_cast<uint32_t *>(
  111. getLanguageSpecificData())+1);
  112. }
  113. /// \brief Return pointer to chained unwind info.
  114. RuntimeFunction *getChainedFunctionEntry() {
  115. return reinterpret_cast<RuntimeFunction *>(getLanguageSpecificData());
  116. }
  117. /// \brief Return pointer to chained unwind info.
  118. const RuntimeFunction *getChainedFunctionEntry() const {
  119. return reinterpret_cast<const RuntimeFunction *>(getLanguageSpecificData());
  120. }
  121. };
  122. } // End of namespace Win64EH
  123. } // End of namespace llvm
  124. #endif