2 * Copyright (C) 2003 Broadcom Corporation
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #include <linux/sched.h>
20 #include <linux/smp.h>
21 #include <linux/smp_lock.h>
22 #include <linux/kernel.h>
23 #include <linux/signal.h>
24 #include <linux/errno.h>
25 #include <linux/wait.h>
26 #include <linux/ptrace.h>
27 #include <linux/unistd.h>
28 #include <linux/compat.h>
31 #include <asm/bitops.h>
32 #include <asm/cacheflush.h>
34 #include <asm/uaccess.h>
35 #include <asm/ucontext.h>
36 #include <asm/system.h>
40 * Including <asm/unistd.h would give use the 64-bit syscall numbers ...
42 #define __NR_N32_rt_sigreturn 6211
43 #define __NR_N32_restart_syscall 6214
45 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
47 /* IRIX compatible stack_t */
48 typedef struct sigaltstack32
{
50 compat_size_t ss_size
;
58 struct sigcontext uc_mcontext
;
59 sigset_t uc_sigmask
; /* mask last for extensibility */
62 struct rt_sigframe_n32
{
63 u32 rs_ass
[4]; /* argument save space for o32 */
64 u32 rs_code
[2]; /* signal trampoline */
65 struct siginfo rs_info
;
66 struct ucontextn32 rs_uc
;
69 extern asmlinkage
int restore_sigcontext(struct pt_regs
*regs
, struct sigcontext
*sc
);
70 extern int inline setup_sigcontext(struct pt_regs
*regs
, struct sigcontext
*sc
);
72 asmlinkage
void sysn32_rt_sigreturn(nabi_no_regargs
struct pt_regs regs
)
74 struct rt_sigframe_n32
*frame
;
79 frame
= (struct rt_sigframe_n32
*) regs
.regs
[29];
80 if (!access_ok(VERIFY_READ
, frame
, sizeof(*frame
)))
82 if (__copy_from_user(&set
, &frame
->rs_uc
.uc_sigmask
, sizeof(set
)))
85 sigdelsetmask(&set
, ~_BLOCKABLE
);
86 spin_lock_irq(¤t
->sighand
->siglock
);
87 current
->blocked
= set
;
89 spin_unlock_irq(¤t
->sighand
->siglock
);
91 if (restore_sigcontext(®s
, &frame
->rs_uc
.uc_mcontext
))
94 /* The ucontext contains a stack32_t, so we must convert! */
95 if (__get_user(sp
, &frame
->rs_uc
.uc_stack
.ss_sp
))
97 st
.ss_size
= (long) sp
;
98 if (__get_user(st
.ss_size
, &frame
->rs_uc
.uc_stack
.ss_size
))
100 if (__get_user(st
.ss_flags
, &frame
->rs_uc
.uc_stack
.ss_flags
))
103 /* It is more difficult to avoid calling this function than to
104 call it and ignore errors. */
105 do_sigaltstack(&st
, NULL
, regs
.regs
[29]);
108 * Don't let your children do this ...
110 __asm__
__volatile__(
118 force_sig(SIGSEGV
, current
);
122 * Determine which stack to use..
124 static inline void *get_sigframe(struct k_sigaction
*ka
, struct pt_regs
*regs
,
129 /* Default to using normal stack */
133 * FPU emulator may have it's own trampoline active just
134 * above the user stack, 16-bytes before the next lowest
135 * 16 byte boundary. Try to avoid trashing it.
139 /* This is the X/Open sanctioned signal stack switching. */
140 if ((ka
->sa
.sa_flags
& SA_ONSTACK
) && (sas_ss_flags (sp
) == 0))
141 sp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
143 return (void *)((sp
- frame_size
) & ALMASK
);
146 void setup_rt_frame_n32(struct k_sigaction
* ka
,
147 struct pt_regs
*regs
, int signr
, sigset_t
*set
, siginfo_t
*info
)
149 struct rt_sigframe_n32
*frame
;
153 frame
= get_sigframe(ka
, regs
, sizeof(*frame
));
154 if (!access_ok(VERIFY_WRITE
, frame
, sizeof (*frame
)))
158 * Set up the return code ...
160 * li v0, __NR_rt_sigreturn
163 err
|= __put_user(0x24020000 + __NR_N32_rt_sigreturn
, frame
->rs_code
+ 0);
164 err
|= __put_user(0x0000000c , frame
->rs_code
+ 1);
165 flush_cache_sigtramp((unsigned long) frame
->rs_code
);
167 /* Create siginfo. */
168 err
|= copy_siginfo_to_user(&frame
->rs_info
, info
);
170 /* Create the ucontext. */
171 err
|= __put_user(0, &frame
->rs_uc
.uc_flags
);
172 err
|= __put_user(0, &frame
->rs_uc
.uc_link
);
173 sp
= (int) (long) current
->sas_ss_sp
;
174 err
|= __put_user(sp
,
175 &frame
->rs_uc
.uc_stack
.ss_sp
);
176 err
|= __put_user(sas_ss_flags(regs
->regs
[29]),
177 &frame
->rs_uc
.uc_stack
.ss_flags
);
178 err
|= __put_user(current
->sas_ss_size
,
179 &frame
->rs_uc
.uc_stack
.ss_size
);
180 err
|= setup_sigcontext(regs
, &frame
->rs_uc
.uc_mcontext
);
181 err
|= __copy_to_user(&frame
->rs_uc
.uc_sigmask
, set
, sizeof(*set
));
187 * Arguments to signal handler:
190 * a1 = 0 (should be cause)
191 * a2 = pointer to ucontext
193 * $25 and c0_epc point to the signal handler, $29 points to
194 * the struct rt_sigframe.
196 regs
->regs
[ 4] = signr
;
197 regs
->regs
[ 5] = (unsigned long) &frame
->rs_info
;
198 regs
->regs
[ 6] = (unsigned long) &frame
->rs_uc
;
199 regs
->regs
[29] = (unsigned long) frame
;
200 regs
->regs
[31] = (unsigned long) frame
->rs_code
;
201 regs
->cp0_epc
= regs
->regs
[25] = (unsigned long) ka
->sa
.sa_handler
;
204 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
205 current
->comm
, current
->pid
,
206 frame
, regs
->cp0_epc
, regs
->regs
[31]);
211 force_sigsegv(signr
, current
);