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 5This file is part of libunwind. 6 7Permission is hereby granted, free of charge, to any person obtaining 8a copy of this software and associated documentation files (the 9"Software"), to deal in the Software without restriction, including 10without limitation the rights to use, copy, modify, merge, publish, 11distribute, sublicense, and/or sell copies of the Software, and to 12permit persons to whom the Software is furnished to do so, subject to 13the following conditions: 14 15The above copyright notice and this permission notice shall be 16included in all copies or substantial portions of the Software. 17 18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 25 26#include "unwind_i.h" 27 28PROTECTED int 29unw_is_signal_frame (unw_cursor_t *cursor) 30{ 31#ifdef __linux__ 32 struct cursor *c = (struct cursor *) cursor; 33 unw_word_t w0, w1, w2, w3, ip; 34 unw_addr_space_t as; 35 unw_accessors_t *a; 36 void *arg; 37 int ret; 38 39 as = c->dwarf.as; 40 a = unw_get_accessors (as); 41 arg = c->dwarf.as_arg; 42 43 /* Check if IP points at sigreturn() sequence. On Linux, this normally is: 44 45 rt_sigreturn: 46 0x34190000 ldi 0, %r25 47 0x3414015a ldi __NR_rt_sigreturn,%r20 48 0xe4008200 be,l 0x100(%sr2,%r0),%sr0,%r31 49 0x08000240 nop 50 51 When a signal interrupts a system call, the first word is instead: 52 53 0x34190002 ldi 1, %r25 54 */ 55 ip = c->dwarf.ip; 56 if (!ip) 57 return 0; 58 if ((ret = (*a->access_mem) (as, ip, &w0, 0, arg)) < 0 59 || (ret = (*a->access_mem) (as, ip + 4, &w1, 0, arg)) < 0 60 || (ret = (*a->access_mem) (as, ip + 8, &w2, 0, arg)) < 0 61 || (ret = (*a->access_mem) (as, ip + 12, &w3, 0, arg)) < 0) 62 { 63 Debug (1, "failed to read sigreturn code (ret=%d)\n", ret); 64 return ret; 65 } 66 ret = ((w0 == 0x34190000 || w0 == 0x34190002) 67 && w1 == 0x3414015a && w2 == 0xe4008200 && w3 == 0x08000240); 68 Debug (1, "(cursor=%p, ip=0x%08lx) -> %d\n", c, (unsigned) ip, ret); 69 return ret; 70#else 71 printf ("%s: implement me\n", __FUNCTION__); 72#endif 73 return -UNW_ENOINFO; 74} 75