Gresume.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (c) 2004 Hewlett-Packard Development Company, L.P.
  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. #include <stdlib.h>
  22. #include "unwind_i.h"
  23. #ifndef UNW_REMOTE_ONLY
  24. #if defined(__linux)
  25. # include <sys/syscall.h>
  26. static NORETURN inline long
  27. my_rt_sigreturn (void *new_sp, int in_syscall)
  28. {
  29. register unsigned long r25 __asm__ ("r25") = (in_syscall != 0);
  30. register unsigned long r20 __asm__ ("r20") = SYS_rt_sigreturn;
  31. __asm__ __volatile__ ("copy %0, %%sp\n"
  32. "be,l 0x100(%%sr2,%%r0),%%sr0,%%r31\n"
  33. "nop"
  34. :
  35. : "r"(new_sp), "r"(r20), "r"(r25)
  36. : "memory");
  37. abort ();
  38. }
  39. #endif /* __linux */
  40. HIDDEN inline int
  41. hppa_local_resume (unw_addr_space_t as, unw_cursor_t *cursor, void *arg)
  42. {
  43. #if defined(__linux)
  44. struct cursor *c = (struct cursor *) cursor;
  45. ucontext_t *uc = c->dwarf.as_arg;
  46. /* Ensure c->pi is up-to-date. On PA-RISC, it's relatively common to be
  47. missing DWARF unwind info. We don't want to fail in that case,
  48. because the frame-chain still would let us do a backtrace at
  49. least. */
  50. dwarf_make_proc_info (&c->dwarf);
  51. if (unlikely (c->sigcontext_format != HPPA_SCF_NONE))
  52. {
  53. struct sigcontext *sc = (struct sigcontext *) c->sigcontext_addr;
  54. Debug (8, "resuming at ip=%x via sigreturn(%p)\n", c->dwarf.ip, sc);
  55. my_rt_sigreturn (sc, (sc->sc_flags & PARISC_SC_FLAG_IN_SYSCALL) != 0);
  56. }
  57. else
  58. {
  59. Debug (8, "resuming at ip=%x via setcontext()\n", c->dwarf.ip);
  60. setcontext (uc);
  61. }
  62. #else
  63. # warning Implement me!
  64. #endif
  65. return -UNW_EINVAL;
  66. }
  67. #endif /* !UNW_REMOTE_ONLY */
  68. /* This routine is responsible for copying the register values in
  69. cursor C and establishing them as the current machine state. */
  70. static inline int
  71. establish_machine_state (struct cursor *c)
  72. {
  73. int (*access_reg) (unw_addr_space_t, unw_regnum_t, unw_word_t *,
  74. int write, void *);
  75. int (*access_fpreg) (unw_addr_space_t, unw_regnum_t, unw_fpreg_t *,
  76. int write, void *);
  77. unw_addr_space_t as = c->dwarf.as;
  78. void *arg = c->dwarf.as_arg;
  79. unw_fpreg_t fpval;
  80. unw_word_t val;
  81. int reg;
  82. access_reg = as->acc.access_reg;
  83. access_fpreg = as->acc.access_fpreg;
  84. Debug (8, "copying out cursor state\n");
  85. for (reg = 0; reg <= UNW_REG_LAST; ++reg)
  86. {
  87. Debug (16, "copying %s %d\n", unw_regname (reg), reg);
  88. if (unw_is_fpreg (reg))
  89. {
  90. if (tdep_access_fpreg (c, reg, &fpval, 0) >= 0)
  91. (*access_fpreg) (as, reg, &fpval, 1, arg);
  92. }
  93. else
  94. {
  95. if (tdep_access_reg (c, reg, &val, 0) >= 0)
  96. (*access_reg) (as, reg, &val, 1, arg);
  97. }
  98. }
  99. return 0;
  100. }
  101. PROTECTED int
  102. unw_resume (unw_cursor_t *cursor)
  103. {
  104. struct cursor *c = (struct cursor *) cursor;
  105. int ret;
  106. Debug (1, "(cursor=%p)\n", c);
  107. if (!c->dwarf.ip)
  108. {
  109. /* This can happen easily when the frame-chain gets truncated
  110. due to bad or missing unwind-info. */
  111. Debug (1, "refusing to resume execution at address 0\n");
  112. return -UNW_EINVAL;
  113. }
  114. if ((ret = establish_machine_state (c)) < 0)
  115. return ret;
  116. return (*c->dwarf.as->acc.resume) (c->dwarf.as, (unw_cursor_t *) c,
  117. c->dwarf.as_arg);
  118. }