linux-unwind.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* DWARF2 EH unwinding support for S/390 Linux.
  2. Copyright (C) 2004-2022 Free Software Foundation, Inc.
  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. /* Do code reading to identify a signal frame, and set the frame
  20. state data appropriately. See unwind-dw2.c for the structs. */
  21. #define MD_FALLBACK_FRAME_STATE_FOR s390_fallback_frame_state
  22. static _Unwind_Reason_Code
  23. s390_fallback_frame_state (struct _Unwind_Context *context,
  24. _Unwind_FrameState *fs)
  25. {
  26. static const unsigned char dwarf_to_fpr_map[16] =
  27. { 0, 2, 4, 6, 1, 3, 5, 7, 8, 10, 12, 14, 9, 11, 13, 15 };
  28. unsigned char *pc = context->ra;
  29. long new_cfa;
  30. int i;
  31. typedef struct
  32. {
  33. unsigned long psw_mask;
  34. unsigned long psw_addr;
  35. unsigned long gprs[16];
  36. unsigned int acrs[16];
  37. unsigned int fpc;
  38. unsigned int __pad;
  39. double fprs[16];
  40. } __attribute__ ((__aligned__ (8))) sigregs_;
  41. sigregs_ *regs;
  42. int *signo;
  43. /* svc $__NR_sigreturn or svc $__NR_rt_sigreturn */
  44. if (pc[0] != 0x0a || (pc[1] != 119 && pc[1] != 173))
  45. return _URC_END_OF_STACK;
  46. /* Legacy frames:
  47. old signal mask (8 bytes)
  48. pointer to sigregs (8 bytes) - points always to next location
  49. sigregs
  50. retcode
  51. This frame layout was used on kernels < 2.6.9 for non-RT frames,
  52. and on kernels < 2.4.13 for RT frames as well. Note that we need
  53. to look at RA to detect this layout -- this means that if you use
  54. sa_restorer to install a different signal restorer on a legacy
  55. kernel, unwinding from signal frames will not work. */
  56. if (context->ra == context->cfa + 16 + sizeof (sigregs_))
  57. {
  58. regs = (sigregs_ *)(context->cfa + 16);
  59. signo = NULL;
  60. }
  61. /* New-style RT frame:
  62. retcode + alignment (8 bytes)
  63. siginfo (128 bytes)
  64. ucontext (contains sigregs) */
  65. else if (pc[1] == 173 /* __NR_rt_sigreturn */)
  66. {
  67. struct ucontext_
  68. {
  69. unsigned long uc_flags;
  70. struct ucontext_ *uc_link;
  71. unsigned long uc_stack[3];
  72. sigregs_ uc_mcontext;
  73. } *uc = context->cfa + 8 + 128;
  74. regs = &uc->uc_mcontext;
  75. signo = context->cfa + sizeof(long);
  76. }
  77. /* New-style non-RT frame:
  78. old signal mask (8 bytes)
  79. pointer to sigregs (followed by signal number) */
  80. else
  81. {
  82. regs = *(sigregs_ **)(context->cfa + 8);
  83. signo = (int *)(regs + 1);
  84. }
  85. new_cfa = regs->gprs[15] + 16*sizeof(long) + 32;
  86. fs->regs.cfa_how = CFA_REG_OFFSET;
  87. fs->regs.cfa_reg = 15;
  88. fs->regs.cfa_offset =
  89. new_cfa - (long) context->cfa + 16*sizeof(long) + 32;
  90. for (i = 0; i < 16; i++)
  91. {
  92. fs->regs.reg[i].how = REG_SAVED_OFFSET;
  93. fs->regs.reg[i].loc.offset =
  94. (long)&regs->gprs[i] - new_cfa;
  95. }
  96. for (i = 0; i < 16; i++)
  97. {
  98. fs->regs.reg[16+i].how = REG_SAVED_OFFSET;
  99. fs->regs.reg[16+i].loc.offset =
  100. (long)&regs->fprs[dwarf_to_fpr_map[i]] - new_cfa;
  101. }
  102. /* Load return addr from PSW into dummy register 32. */
  103. fs->regs.reg[32].how = REG_SAVED_OFFSET;
  104. fs->regs.reg[32].loc.offset = (long)&regs->psw_addr - new_cfa;
  105. fs->retaddr_column = 32;
  106. /* SIGILL, SIGFPE and SIGTRAP are delivered with psw_addr
  107. after the faulting instruction rather than before it.
  108. Don't set FS->signal_frame in that case. */
  109. if (!signo || (*signo != 4 && *signo != 5 && *signo != 8))
  110. fs->signal_frame = 1;
  111. return _URC_NO_REASON;
  112. }