Gis_signal_frame.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2004 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. #include "unwind_i.h"
  22. PROTECTED int
  23. unw_is_signal_frame (unw_cursor_t *cursor)
  24. {
  25. #ifdef __linux__
  26. struct cursor *c = (struct cursor *) cursor;
  27. unw_word_t w0, w1, w2, w3, ip;
  28. unw_addr_space_t as;
  29. unw_accessors_t *a;
  30. void *arg;
  31. int ret;
  32. as = c->dwarf.as;
  33. a = unw_get_accessors (as);
  34. arg = c->dwarf.as_arg;
  35. /* Check if IP points at sigreturn() sequence. On Linux, this normally is:
  36. rt_sigreturn:
  37. 0x34190000 ldi 0, %r25
  38. 0x3414015a ldi __NR_rt_sigreturn,%r20
  39. 0xe4008200 be,l 0x100(%sr2,%r0),%sr0,%r31
  40. 0x08000240 nop
  41. When a signal interrupts a system call, the first word is instead:
  42. 0x34190002 ldi 1, %r25
  43. */
  44. ip = c->dwarf.ip;
  45. if (!ip)
  46. return 0;
  47. if ((ret = (*a->access_mem) (as, ip, &w0, 0, arg)) < 0
  48. || (ret = (*a->access_mem) (as, ip + 4, &w1, 0, arg)) < 0
  49. || (ret = (*a->access_mem) (as, ip + 8, &w2, 0, arg)) < 0
  50. || (ret = (*a->access_mem) (as, ip + 12, &w3, 0, arg)) < 0)
  51. {
  52. Debug (1, "failed to read sigreturn code (ret=%d)\n", ret);
  53. return ret;
  54. }
  55. ret = ((w0 == 0x34190000 || w0 == 0x34190002)
  56. && w1 == 0x3414015a && w2 == 0xe4008200 && w3 == 0x08000240);
  57. Debug (1, "(cursor=%p, ip=0x%08lx) -> %d\n", c, (unsigned) ip, ret);
  58. return ret;
  59. #else
  60. printf ("%s: implement me\n", __FUNCTION__);
  61. #endif
  62. return -UNW_ENOINFO;
  63. }