UnwindInfoManager.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "Backend.h"
  6. #include "ARM64UnwindEncoder.h"
  7. UnwindInfoManager::UnwindInfoManager()
  8. {
  9. for (int which = UnwindInvalid; which < UnwindFunctionOffsetCount; which++)
  10. {
  11. this->m_functionOffsetLabelId[which] = 0;
  12. this->m_functionOffset[which] = 0xffffffff;
  13. }
  14. }
  15. void UnwindInfoManager::Init(Func * func)
  16. {
  17. // necessary? Maybe not, but keeping around for now
  18. }
  19. DWORD UnwindInfoManager::GetPDataCount(DWORD length)
  20. {
  21. // TODO: Support splitting huge functions if needed?
  22. return 1;
  23. }
  24. DWORD UnwindInfoManager::GetFunctionOffset(UnwindFunctionOffsets which)
  25. {
  26. Assert(which < UnwindFunctionOffsetCount);
  27. DWORD result = this->m_functionOffset[which];
  28. Assert(result != 0xffffffff);
  29. Assert(result % 4 == 0);
  30. return result;
  31. }
  32. void UnwindInfoManager::FinalizeUnwindInfo(BYTE *functionStart, DWORD codeSize)
  33. {
  34. // fetch the appropriate offsets and hand off to the generic code
  35. m_xdata.Generate(PULONG(functionStart + this->GetFunctionOffset(UnwindPrologStart)),
  36. PULONG(functionStart + this->GetFunctionOffset(UnwindPrologEnd)),
  37. PULONG(functionStart + this->GetFunctionOffset(UnwindEpilogStart)),
  38. PULONG(functionStart + this->GetFunctionOffset(UnwindEpilogEnd)),
  39. PULONG(functionStart + codeSize));
  40. }
  41. void UnwindInfoManager::SetFunctionOffsetLabel(UnwindFunctionOffsets which, IR::LabelInstr *label)
  42. {
  43. Assert(which < UnwindFunctionOffsetCount);
  44. Assert(this->m_functionOffsetLabelId[which] == 0);
  45. this->m_functionOffsetLabelId[which] = label->m_id;
  46. }
  47. void UnwindInfoManager::SetLabelOffset(DWORD id, DWORD offset)
  48. {
  49. Assert(offset % 4 == 0);
  50. for (int which = UnwindInvalid + 1; which < UnwindFunctionOffsetCount; which++)
  51. {
  52. if (this->m_functionOffsetLabelId[which] == id)
  53. {
  54. Assert(this->m_functionOffset[which] == 0xffffffff);
  55. this->m_functionOffset[which] = offset;
  56. }
  57. }
  58. }