1/* libunwind - a platform-independent unwind library
2   Copyright (C) 2008 CodeSourcery
3   Copyright 2011 Linaro Limited
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 <stdio.h>
27#include "unwind_i.h"
28
29#ifdef __linux__
30#define ARM_NR_sigreturn 119
31#define ARM_NR_rt_sigreturn 173
32#define ARM_NR_OABI_SYSCALL_BASE 0x900000
33
34/* ARM EABI sigreturn (the syscall number is loaded into r7) */
35#define MOV_R7_SIGRETURN (0xe3a07000UL | ARM_NR_sigreturn)
36#define MOV_R7_RT_SIGRETURN (0xe3a07000UL | ARM_NR_rt_sigreturn)
37
38/* ARM OABI sigreturn (using SWI) */
39#define ARM_SIGRETURN \
40  (0xef000000UL | ARM_NR_sigreturn | ARM_NR_OABI_SYSCALL_BASE)
41#define ARM_RT_SIGRETURN \
42  (0xef000000UL | ARM_NR_rt_sigreturn | ARM_NR_OABI_SYSCALL_BASE)
43
44/* Thumb sigreturn (two insns, syscall number is loaded into r7) */
45#define THUMB_SIGRETURN (0xdf00UL << 16 | 0x2700 | ARM_NR_sigreturn)
46#define THUMB_RT_SIGRETURN (0xdf00UL << 16 | 0x2700 | ARM_NR_rt_sigreturn)
47#endif /* __linux__ */
48
49/* Returns 1 in case of a non-RT signal frame and 2 in case of a RT signal
50   frame. */
51PROTECTED int
52unw_is_signal_frame (unw_cursor_t *cursor)
53{
54#ifdef __linux__
55  struct cursor *c = (struct cursor *) cursor;
56  unw_word_t w0, ip;
57  unw_addr_space_t as;
58  unw_accessors_t *a;
59  void *arg;
60  int ret;
61
62  as = c->dwarf.as;
63  a = unw_get_accessors (as);
64  arg = c->dwarf.as_arg;
65
66  ip = c->dwarf.ip;
67
68  if ((ret = (*a->access_mem) (as, ip, &w0, 0, arg)) < 0)
69  /* ANDROID support update. */
70    return 0;
71  /* End ANDROID update. */
72
73  /* Return 1 if the IP points to a non-RT sigreturn sequence.  */
74  if (w0 == MOV_R7_SIGRETURN || w0 == ARM_SIGRETURN || w0 == THUMB_SIGRETURN)
75    return 1;
76  /* Return 2 if the IP points to a RT sigreturn sequence.  */
77  else if (w0 == MOV_R7_RT_SIGRETURN || w0 == ARM_RT_SIGRETURN
78           || w0 == THUMB_RT_SIGRETURN)
79    return 2;
80
81  return 0;
82#elif defined(__QNX__)
83  /* Not supported yet */
84  return 0;
85#else
86  printf ("%s: implement me\n", __FUNCTION__);
87  return -UNW_ENOINFO;
88#endif
89}
90