• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
3 
4 This file is part of libunwind.
5 
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13 
14 The above copyright notice and this permission notice shall be
15 included in all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
24 
25 #include "unwind_i.h"
26 
27 /* Disassembly of the Linux VDSO sigreturn functions:
28 
29 00000000 <__kernel_sigreturn>:
30    0:   05 93           mov.w   e <__kernel_sigreturn+0xe>,r3   ! 77
31    2:   10 c3           trapa   #16
32    4:   0b 20           or      r0,r0
33    6:   0b 20           or      r0,r0
34    8:   0b 20           or      r0,r0
35    a:   0b 20           or      r0,r0
36    c:   0b 20           or      r0,r0
37    e:   77 00           .word 0x0077
38   10:   09 00           nop
39   12:   09 00           nop
40   14:   09 00           nop
41   16:   09 00           nop
42   18:   09 00           nop
43   1a:   09 00           nop
44   1c:   09 00           nop
45   1e:   09 00           nop
46 
47 00000020 <__kernel_rt_sigreturn>:
48   20:   05 93           mov.w   2e <__kernel_rt_sigreturn+0xe>,r3       ! ad
49   22:   10 c3           trapa   #16
50   24:   0b 20           or      r0,r0
51   26:   0b 20           or      r0,r0
52   28:   0b 20           or      r0,r0
53   2a:   0b 20           or      r0,r0
54   2c:   0b 20           or      r0,r0
55   2e:   ad 00           mov.w   @(r0,r10),r0
56   30:   09 00           nop
57   32:   09 00           nop
58   34:   09 00           nop
59   36:   09 00           nop
60   38:   09 00           nop
61   3a:   09 00           nop
62   3c:   09 00           nop
63   3e:   09 00           nop
64 */
65 
66 int
unw_is_signal_frame(unw_cursor_t * cursor)67 unw_is_signal_frame (unw_cursor_t *cursor)
68 {
69 #ifdef __linux__
70   struct cursor *c = (struct cursor *) cursor;
71   unw_word_t w0, ip;
72   unw_addr_space_t as;
73   unw_accessors_t *a;
74   void *arg;
75   int ret;
76 
77   as = c->dwarf.as;
78   a = unw_get_accessors_int (as);
79   arg = c->dwarf.as_arg;
80 
81   ip = c->dwarf.ip;
82 
83   ret = (*a->access_mem) (as, ip, &w0, 0, arg);
84   if (ret < 0)
85     return ret;
86 
87   if (w0 != 0xc3109305)
88     return 0;
89 
90   ret = (*a->access_mem) (as, ip+4, &w0, 0, arg);
91   if (ret < 0)
92     return ret;
93 
94   if (w0 != 0x200b200b)
95     return 0;
96 
97   ret = (*a->access_mem) (as, ip+8, &w0, 0, arg);
98   if (ret < 0)
99     return ret;
100 
101   if (w0 != 0x200b200b)
102     return 0;
103 
104   ret = (*a->access_mem) (as, ip+12, &w0, 0, arg);
105   if (ret < 0)
106     return ret;
107 
108   if (w0 == 0x0077200b)
109     return 1; /* non-RT */
110   else if (w0 == 0x00ad200b)
111     return 2; /* RT */
112 
113   /* does not look like a signal frame */
114   return 0;
115 
116 #else
117   return -UNW_ENOINFO;
118 #endif
119 }
120