setjmp_i.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2003-2005 Hewlett-Packard Co
  3. Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
  4. This file is part of libunwind.
  5. Permission is hereby granted, free of charge, to any person obtaining
  6. a copy of this software and associated documentation files (the
  7. "Software"), to deal in the Software without restriction, including
  8. without limitation the rights to use, copy, modify, merge, publish,
  9. distribute, sublicense, and/or sell copies of the Software, and to
  10. permit persons to whom the Software is furnished to do so, subject to
  11. the following conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  18. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  21. #if UNW_TARGET_IA64
  22. #include "libunwind_i.h"
  23. #include "tdep-ia64/rse.h"
  24. static inline int
  25. bsp_match (unw_cursor_t *c, unw_word_t *wp)
  26. {
  27. unw_word_t bsp, pfs, sol;
  28. if (unw_get_reg (c, UNW_IA64_BSP, &bsp) < 0
  29. || unw_get_reg (c, UNW_IA64_AR_PFS, &pfs) < 0)
  30. abort ();
  31. /* simulate the effect of "br.call sigsetjmp" on ar.bsp: */
  32. sol = (pfs >> 7) & 0x7f;
  33. bsp = rse_skip_regs (bsp, sol);
  34. if (bsp != wp[JB_BSP])
  35. return 0;
  36. if (unlikely (sol == 0))
  37. {
  38. unw_word_t sp, prev_sp;
  39. unw_cursor_t tmp = *c;
  40. /* The caller of {sig,}setjmp() cannot have a NULL-frame. If we
  41. see a NULL-frame, we haven't reached the right target yet.
  42. To have a NULL-frame, the number of locals must be zero and
  43. the stack-frame must also be empty. */
  44. if (unw_step (&tmp) < 0)
  45. abort ();
  46. if (unw_get_reg (&tmp, UNW_REG_SP, &sp) < 0
  47. || unw_get_reg (&tmp, UNW_REG_SP, &prev_sp) < 0)
  48. abort ();
  49. if (sp == prev_sp)
  50. /* got a NULL-frame; keep looking... */
  51. return 0;
  52. }
  53. return 1;
  54. }
  55. /* On ia64 we cannot always call sigprocmask() at
  56. _UI_siglongjmp_cont() because the signal may have switched stacks
  57. and the old stack's register-backing store may have overflown,
  58. leaving us no space to allocate the stacked registers needed to
  59. call sigprocmask(). Fortunately, we can just let unw_resume() (via
  60. sigreturn) take care of restoring the signal-mask. That's faster
  61. anyhow. */
  62. static inline int
  63. resume_restores_sigmask (unw_cursor_t *c, unw_word_t *wp)
  64. {
  65. unw_word_t sc_addr = ((struct cursor *) c)->sigcontext_addr;
  66. struct sigcontext *sc = (struct sigcontext *) sc_addr;
  67. sigset_t current_mask;
  68. void *mp;
  69. if (!sc_addr)
  70. return 0;
  71. /* let unw_resume() install the desired signal mask */
  72. if (wp[JB_MASK_SAVED])
  73. mp = &wp[JB_MASK];
  74. else
  75. {
  76. if (sigprocmask (SIG_BLOCK, NULL, &current_mask) < 0)
  77. abort ();
  78. mp = &current_mask;
  79. }
  80. memcpy (&sc->sc_mask, mp, sizeof (sc->sc_mask));
  81. return 1;
  82. }
  83. #else /* !UNW_TARGET_IA64 */
  84. static inline int
  85. bsp_match (unw_cursor_t *c, unw_word_t *wp)
  86. {
  87. return 1;
  88. }
  89. static inline int
  90. resume_restores_sigmask (unw_cursor_t *c, unw_word_t *wp)
  91. {
  92. /* We may want to do this analogously as for ia64... */
  93. return 0;
  94. }
  95. #endif /* !UNW_TARGET_IA64 */