aarch64-unwind.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* Copyright (C) 2017-2022 Free Software Foundation, Inc.
  2. Contributed by ARM Ltd.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. #if !defined (AARCH64_UNWIND_H) && !defined (__ILP32__)
  20. #define AARCH64_UNWIND_H
  21. #define DWARF_REGNUM_AARCH64_RA_STATE 34
  22. #define MD_DEMANGLE_RETURN_ADDR(context, fs, addr) \
  23. aarch64_demangle_return_addr (context, fs, addr)
  24. #define MD_FROB_UPDATE_CONTEXT(context, fs) \
  25. aarch64_frob_update_context (context, fs)
  26. static inline int
  27. aarch64_cie_signed_with_b_key (struct _Unwind_Context *context)
  28. {
  29. const struct dwarf_fde *fde = _Unwind_Find_FDE (context->bases.func,
  30. &context->bases);
  31. if (fde != NULL)
  32. {
  33. const struct dwarf_cie *cie = get_cie (fde);
  34. if (cie != NULL)
  35. {
  36. char *aug_str = cie->augmentation;
  37. return strchr (aug_str, 'B') == NULL ? 0 : 1;
  38. }
  39. }
  40. return 0;
  41. }
  42. /* Do AArch64 private extraction on ADDR_WORD based on context info CONTEXT and
  43. unwind frame info FS. If ADDR_WORD is signed, we do address authentication
  44. on it using CFA of current frame. */
  45. static inline void *
  46. aarch64_demangle_return_addr (struct _Unwind_Context *context,
  47. _Unwind_FrameState *fs ATTRIBUTE_UNUSED,
  48. _Unwind_Word addr_word)
  49. {
  50. void *addr = (void *)addr_word;
  51. if (context->flags & RA_SIGNED_BIT)
  52. {
  53. _Unwind_Word salt = (_Unwind_Word) context->cfa;
  54. if (aarch64_cie_signed_with_b_key (context) != 0)
  55. return __builtin_aarch64_autib1716 (addr, salt);
  56. return __builtin_aarch64_autia1716 (addr, salt);
  57. }
  58. else
  59. return addr;
  60. }
  61. /* Do AArch64 private initialization on CONTEXT based on frame info FS. Mark
  62. CONTEXT as return address signed if bit 0 of DWARF_REGNUM_AARCH64_RA_STATE is
  63. set. */
  64. static inline void
  65. aarch64_frob_update_context (struct _Unwind_Context *context,
  66. _Unwind_FrameState *fs)
  67. {
  68. if (fs->regs.reg[DWARF_REGNUM_AARCH64_RA_STATE].loc.offset & 0x1)
  69. /* The flag is used for re-authenticating EH handler's address. */
  70. context->flags |= RA_SIGNED_BIT;
  71. else
  72. context->flags &= ~RA_SIGNED_BIT;
  73. return;
  74. }
  75. #endif /* defined AARCH64_UNWIND_H && defined __ILP32__ */