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>
33 #include <asm/uaccess.h>
34 #include <asm/ucontext.h>
35 #include <asm/system.h>
39 * Including <asm/unistd.h would give use the 64-bit syscall numbers ...
41 #define __NR_N32_rt_sigreturn 6211
42 #define __NR_N32_restart_syscall 6214
44 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
46 /* IRIX compatible stack_t */
47 typedef struct sigaltstack32 {
49 compat_size_t ss_size;
57 struct sigcontext uc_mcontext;
58 sigset_t uc_sigmask; /* mask last for extensibility */
61 struct rt_sigframe_n32 {
62 u32 rs_ass[4]; /* argument save space for o32 */
63 u32 rs_code[2]; /* signal trampoline */
64 struct siginfo rs_info;
65 struct ucontextn32 rs_uc;
68 extern asmlinkage int restore_sigcontext(struct pt_regs *regs, struct sigcontext *sc);
69 extern int inline setup_sigcontext(struct pt_regs *regs, struct sigcontext *sc);
71 asmlinkage void sysn32_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
73 struct rt_sigframe_n32 *frame;
78 frame = (struct rt_sigframe_n32 *) regs.regs[29];
79 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
81 if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set)))
84 sigdelsetmask(&set, ~_BLOCKABLE);
85 spin_lock_irq(¤t->sighand->siglock);
86 current->blocked = set;
88 spin_unlock_irq(¤t->sighand->siglock);
90 if (restore_sigcontext(®s, &frame->rs_uc.uc_mcontext))
93 /* The ucontext contains a stack32_t, so we must convert! */
94 if (__get_user(sp, &frame->rs_uc.uc_stack.ss_sp))
96 st.ss_size = (long) sp;
97 if (__get_user(st.ss_size, &frame->rs_uc.uc_stack.ss_size))
99 if (__get_user(st.ss_flags, &frame->rs_uc.uc_stack.ss_flags))
102 /* It is more difficult to avoid calling this function than to
103 call it and ignore errors. */
104 do_sigaltstack(&st, NULL, regs.regs[29]);
107 * Don't let your children do this ...
109 __asm__ __volatile__(
117 force_sig(SIGSEGV, current);
121 * Determine which stack to use..
123 static inline void *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
128 /* Default to using normal stack */
132 * FPU emulator may have it's own trampoline active just
133 * above the user stack, 16-bytes before the next lowest
134 * 16 byte boundary. Try to avoid trashing it.
138 /* This is the X/Open sanctioned signal stack switching. */
139 if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0))
140 sp = current->sas_ss_sp + current->sas_ss_size;
142 return (void *)((sp - frame_size) & ALMASK);
145 void setup_rt_frame_n32(struct k_sigaction * ka,
146 struct pt_regs *regs, int signr, sigset_t *set, siginfo_t *info)
148 struct rt_sigframe_n32 *frame;
152 frame = get_sigframe(ka, regs, sizeof(*frame));
153 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
157 * Set up the return code ...
159 * li v0, __NR_rt_sigreturn
162 err |= __put_user(0x24020000 + __NR_N32_rt_sigreturn, frame->rs_code + 0);
163 err |= __put_user(0x0000000c , frame->rs_code + 1);
164 flush_cache_sigtramp((unsigned long) frame->rs_code);
166 /* Create siginfo. */
167 err |= copy_siginfo_to_user(&frame->rs_info, info);
169 /* Create the ucontext. */
170 err |= __put_user(0, &frame->rs_uc.uc_flags);
171 err |= __put_user(0, &frame->rs_uc.uc_link);
172 sp = (int) (long) current->sas_ss_sp;
173 err |= __put_user(sp,
174 &frame->rs_uc.uc_stack.ss_sp);
175 err |= __put_user(sas_ss_flags(regs->regs[29]),
176 &frame->rs_uc.uc_stack.ss_flags);
177 err |= __put_user(current->sas_ss_size,
178 &frame->rs_uc.uc_stack.ss_size);
179 err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext);
180 err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set));
186 * Arguments to signal handler:
189 * a1 = 0 (should be cause)
190 * a2 = pointer to ucontext
192 * $25 and c0_epc point to the signal handler, $29 points to
193 * the struct rt_sigframe.
195 regs->regs[ 4] = signr;
196 regs->regs[ 5] = (unsigned long) &frame->rs_info;
197 regs->regs[ 6] = (unsigned long) &frame->rs_uc;
198 regs->regs[29] = (unsigned long) frame;
199 regs->regs[31] = (unsigned long) frame->rs_code;
200 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
203 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
204 current->comm, current->pid,
205 frame, regs->cp0_epc, regs->regs[31]);
210 if (signr == SIGSEGV)
211 ka->sa.sa_handler = SIG_DFL;
212 force_sig(SIGSEGV, current);