OSDN Git Service

struct siginfo vs. siginfo_t
[pf3gnuchains/gcc-fork.git] / libgcc / config / mips / linux-unwind.h
1 /* DWARF2 EH unwinding support for MIPS Linux.
2    Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2012 Free Software
3    Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
20
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24 <http://www.gnu.org/licenses/>.  */
25
26 #ifndef inhibit_libc
27 /* Do code reading to identify a signal frame, and set the frame
28    state data appropriately.  See unwind-dw2.c for the structs.  */
29
30 #include <signal.h>
31 #include <asm/unistd.h>
32
33 /* The third parameter to the signal handler points to something with
34  * this structure defined in asm/ucontext.h, but the name clashes with
35  * struct ucontext from sys/ucontext.h so this private copy is used.  */
36 typedef struct _sig_ucontext {
37     unsigned long         uc_flags;
38     struct _sig_ucontext  *uc_link;
39     stack_t               uc_stack;
40     struct sigcontext uc_mcontext;
41     sigset_t      uc_sigmask;
42 } _sig_ucontext_t;
43
44 #define MD_FALLBACK_FRAME_STATE_FOR mips_fallback_frame_state
45
46 static _Unwind_Reason_Code
47 mips_fallback_frame_state (struct _Unwind_Context *context,
48                            _Unwind_FrameState *fs)
49 {
50   u_int32_t *pc = (u_int32_t *) context->ra;
51   struct sigcontext *sc;
52   _Unwind_Ptr new_cfa, reg_offset;
53   int i;
54
55   /* 24021061 li v0, 0x1061 (rt_sigreturn)*/
56   /* 0000000c syscall    */
57   /*    or */
58   /* 24021017 li v0, 0x1017 (sigreturn) */
59   /* 0000000c syscall  */
60   if (pc[1] != 0x0000000c)
61     return _URC_END_OF_STACK;
62 #if _MIPS_SIM == _ABIO32
63   if (pc[0] == (0x24020000 | __NR_sigreturn))
64     {
65       struct sigframe {
66         u_int32_t ass[4];  /* Argument save space for o32.  */
67         u_int32_t trampoline[2];
68         struct sigcontext sigctx;
69       } *rt_ = context->cfa;
70       sc = &rt_->sigctx;
71     }
72   else
73 #endif
74   if (pc[0] == (0x24020000 | __NR_rt_sigreturn))
75     {
76       struct rt_sigframe {
77         u_int32_t ass[4];  /* Argument save space for o32.  */
78         u_int32_t trampoline[2];
79         siginfo_t info;
80         _sig_ucontext_t uc;
81       } *rt_ = context->cfa;
82       sc = &rt_->uc.uc_mcontext;
83     }
84   else
85     return _URC_END_OF_STACK;
86
87   new_cfa = (_Unwind_Ptr) sc;
88   fs->regs.cfa_how = CFA_REG_OFFSET;
89   fs->regs.cfa_reg = STACK_POINTER_REGNUM;
90   fs->regs.cfa_offset = new_cfa - (_Unwind_Ptr) context->cfa;
91
92   /* On o32 Linux, the register save slots in the sigcontext are
93      eight bytes.  We need the lower half of each register slot,
94      so slide our view of the structure back four bytes.  */
95 #if _MIPS_SIM == _ABIO32 && defined __MIPSEB__
96   reg_offset = 4;
97 #else
98   reg_offset = 0;
99 #endif
100
101   for (i = 0; i < 32; i++) {
102     fs->regs.reg[i].how = REG_SAVED_OFFSET;
103     fs->regs.reg[i].loc.offset
104       = (_Unwind_Ptr)&(sc->sc_regs[i]) + reg_offset - new_cfa;
105   }
106   /* "PC & -2" points to the faulting instruction, but the unwind code
107      searches for "(ADDR & -2) - 1".  (See MASK_RETURN_ADDR for the source
108      of the -2 mask.)  Adding 2 here ensures that "(ADDR & -2) - 1" is the
109      address of the second byte of the faulting instruction.
110
111      Note that setting fs->signal_frame would not work.  As the comment
112      above MASK_RETURN_ADDR explains, MIPS unwinders must earch for an
113      odd-valued address.  */
114   fs->regs.reg[DWARF_ALT_FRAME_RETURN_COLUMN].how = REG_SAVED_VAL_OFFSET;
115   fs->regs.reg[DWARF_ALT_FRAME_RETURN_COLUMN].loc.offset
116     = (_Unwind_Ptr)(sc->sc_pc) + 2 - new_cfa;
117   fs->retaddr_column = DWARF_ALT_FRAME_RETURN_COLUMN;
118
119   return _URC_NO_REASON;
120 }
121 #endif