1b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino/* libunwind - a platform-independent unwind library
2b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino   Copyright (C) 2006-2007 IBM
3b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino   Contributed by
4b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino     Corey Ashford <cjashfor@us.ibm.com>
5b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino     Jose Flavio Aguilar Paulino <jflavio@br.ibm.com> <joseflavio@gmail.com>
6b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino
7b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoThis file is part of libunwind.
8b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino
9b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoPermission is hereby granted, free of charge, to any person obtaining
10b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinoa copy of this software and associated documentation files (the
11b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino"Software"), to deal in the Software without restriction, including
12b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinowithout limitation the rights to use, copy, modify, merge, publish,
13b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinodistribute, sublicense, and/or sell copies of the Software, and to
14b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinopermit persons to whom the Software is furnished to do so, subject to
15b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinothe following conditions:
16b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino
17b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoThe above copyright notice and this permission notice shall be
18b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinoincluded in all copies or substantial portions of the Software.
19b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino
20b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
27b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino
284499bb29a6214b5df5b3b21e03c6b4f3c8f26cfdJose Flavio Aguilar Paulino#include <libunwind_i.h>
29b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino
30b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoPROTECTED int
31b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinounw_is_signal_frame (unw_cursor_t * cursor)
32b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino{
33b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino  struct cursor *c = (struct cursor *) cursor;
34b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino  unw_word_t w0, w1, ip;
35b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino  unw_addr_space_t as;
36b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino  unw_accessors_t *a;
37b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino  void *arg;
38b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino  int ret;
39b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino
40b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino  as = c->dwarf.as;
41b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino  as->validate = 1;		/* Don't trust the ip */
42b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino  arg = c->dwarf.as_arg;
43b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino
44b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino  /* Check if return address points at sigreturn sequence.
45b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino     on ppc64 Linux that is (see libc.so):
46b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino     0x38210080  addi r1, r1, 128  // pop the stack
47b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino     0x380000ac  li r0, 172        // invoke system service 172
48b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino     0x44000002  sc
49b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino   */
50b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino
51b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino  ip = c->dwarf.ip;
52b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino  if (ip == 0)
53b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino    return 0;
54b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino
55b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino  /* Read up two 8-byte words at the IP.  We are only looking at 3
56b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino     consecutive 32-bit words, so the second 8-byte word needs to be
57b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino     shifted right by 32 bits (think big-endian) */
58b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino
59b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino  a = unw_get_accessors (as);
60b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino  if ((ret = (*a->access_mem) (as, ip, &w0, 0, arg)) < 0
61b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino      || (ret = (*a->access_mem) (as, ip + 8, &w1, 0, arg)) < 0)
62b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino    return 0;
63b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino  w1 >>= 32;
64b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino  return (w0 == 0x38210080380000ac && w1 == 0x44000002);
65b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino
66b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino}
67