2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1991, 1992 Linus Torvalds
7 * Copyright (C) 1994 - 2000 Ralf Baechle
8 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
10 #include <linux/config.h>
11 #include <linux/cache.h>
12 #include <linux/sched.h>
14 #include <linux/personality.h>
15 #include <linux/smp.h>
16 #include <linux/smp_lock.h>
17 #include <linux/kernel.h>
18 #include <linux/signal.h>
19 #include <linux/errno.h>
20 #include <linux/wait.h>
21 #include <linux/ptrace.h>
22 #include <linux/unistd.h>
23 #include <linux/compiler.h>
27 #include <linux/bitops.h>
28 #include <asm/cacheflush.h>
31 #include <asm/uaccess.h>
32 #include <asm/ucontext.h>
33 #include <asm/cpu-features.h>
36 #include "signal-common.h"
40 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
42 int do_signal(sigset_t *oldset, struct pt_regs *regs);
45 * Atomically swap in the new signal mask, and wait for a signal.
48 #ifdef CONFIG_TRAD_SIGNALS
49 save_static_function(sys_sigsuspend);
50 __attribute_used__ noinline static int
51 _sys_sigsuspend(nabi_no_regargs struct pt_regs regs)
53 sigset_t saveset, newset;
54 sigset_t __user *uset;
56 uset = (sigset_t __user *) regs.regs[4];
57 if (copy_from_user(&newset, uset, sizeof(sigset_t)))
59 sigdelsetmask(&newset, ~_BLOCKABLE);
61 spin_lock_irq(¤t->sighand->siglock);
62 saveset = current->blocked;
63 current->blocked = newset;
65 spin_unlock_irq(¤t->sighand->siglock);
70 current->state = TASK_INTERRUPTIBLE;
72 if (do_signal(&saveset, ®s))
78 save_static_function(sys_rt_sigsuspend);
79 __attribute_used__ noinline static int
80 _sys_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
82 sigset_t saveset, newset;
83 sigset_t __user *unewset;
86 /* XXX Don't preclude handling different sized sigset_t's. */
87 sigsetsize = regs.regs[5];
88 if (sigsetsize != sizeof(sigset_t))
91 unewset = (sigset_t __user *) regs.regs[4];
92 if (copy_from_user(&newset, unewset, sizeof(newset)))
94 sigdelsetmask(&newset, ~_BLOCKABLE);
96 spin_lock_irq(¤t->sighand->siglock);
97 saveset = current->blocked;
98 current->blocked = newset;
100 spin_unlock_irq(¤t->sighand->siglock);
102 regs.regs[2] = EINTR;
105 current->state = TASK_INTERRUPTIBLE;
107 if (do_signal(&saveset, ®s))
112 #ifdef CONFIG_TRAD_SIGNALS
113 asmlinkage int sys_sigaction(int sig, const struct sigaction *act,
114 struct sigaction *oact)
116 struct k_sigaction new_ka, old_ka;
123 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
125 err |= __get_user(new_ka.sa.sa_handler, &act->sa_handler);
126 err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
127 err |= __get_user(mask, &act->sa_mask.sig[0]);
131 siginitset(&new_ka.sa.sa_mask, mask);
134 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
137 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
139 err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
140 err |= __put_user(old_ka.sa.sa_handler, &oact->sa_handler);
141 err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig);
142 err |= __put_user(0, &oact->sa_mask.sig[1]);
143 err |= __put_user(0, &oact->sa_mask.sig[2]);
144 err |= __put_user(0, &oact->sa_mask.sig[3]);
153 asmlinkage int sys_sigaltstack(nabi_no_regargs struct pt_regs regs)
155 const stack_t __user *uss = (const stack_t __user *) regs.regs[4];
156 stack_t __user *uoss = (stack_t __user *) regs.regs[5];
157 unsigned long usp = regs.regs[29];
159 return do_sigaltstack(uss, uoss, usp);
163 * Horribly complicated - with the bloody RM9000 workarounds enabled
164 * the signal trampolines is moving to the end of the structure so we can
165 * increase the alignment without breaking software compatibility.
167 #ifdef CONFIG_TRAD_SIGNALS
169 u32 sf_ass[4]; /* argument save space for o32 */
170 #if ICACHE_REFILLS_WORKAROUND_WAR
173 u32 sf_code[2]; /* signal trampoline */
175 struct sigcontext sf_sc;
177 #if ICACHE_REFILLS_WORKAROUND_WAR
178 u32 sf_code[8] ____cacheline_aligned; /* signal trampoline */
184 u32 rs_ass[4]; /* argument save space for o32 */
185 #if ICACHE_REFILLS_WORKAROUND_WAR
188 u32 rs_code[2]; /* signal trampoline */
190 struct siginfo rs_info;
191 struct ucontext rs_uc;
192 #if ICACHE_REFILLS_WORKAROUND_WAR
193 u32 rs_code[8] ____cacheline_aligned; /* signal trampoline */
197 #ifdef CONFIG_TRAD_SIGNALS
198 save_static_function(sys_sigreturn);
199 __attribute_used__ noinline static void
200 _sys_sigreturn(nabi_no_regargs struct pt_regs regs)
202 struct sigframe *frame;
205 frame = (struct sigframe *) regs.regs[29];
206 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
208 if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked)))
211 sigdelsetmask(&blocked, ~_BLOCKABLE);
212 spin_lock_irq(¤t->sighand->siglock);
213 current->blocked = blocked;
215 spin_unlock_irq(¤t->sighand->siglock);
217 if (restore_sigcontext(®s, &frame->sf_sc))
221 * Don't let your children do this ...
223 if (current_thread_info()->flags & TIF_SYSCALL_TRACE)
224 do_syscall_trace(®s, 1);
225 __asm__ __volatile__(
233 force_sig(SIGSEGV, current);
235 #endif /* CONFIG_TRAD_SIGNALS */
237 save_static_function(sys_rt_sigreturn);
238 __attribute_used__ noinline static void
239 _sys_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
241 struct rt_sigframe *frame;
245 frame = (struct rt_sigframe *) regs.regs[29];
246 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
248 if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set)))
251 sigdelsetmask(&set, ~_BLOCKABLE);
252 spin_lock_irq(¤t->sighand->siglock);
253 current->blocked = set;
255 spin_unlock_irq(¤t->sighand->siglock);
257 if (restore_sigcontext(®s, &frame->rs_uc.uc_mcontext))
260 if (__copy_from_user(&st, &frame->rs_uc.uc_stack, sizeof(st)))
262 /* It is more difficult to avoid calling this function than to
263 call it and ignore errors. */
264 do_sigaltstack(&st, NULL, regs.regs[29]);
267 * Don't let your children do this ...
269 __asm__ __volatile__(
277 force_sig(SIGSEGV, current);
280 #ifdef CONFIG_TRAD_SIGNALS
281 void setup_frame(struct k_sigaction * ka, struct pt_regs *regs,
282 int signr, sigset_t *set)
284 struct sigframe *frame;
287 frame = get_sigframe(ka, regs, sizeof(*frame));
288 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
291 install_sigtramp(frame->sf_code, __NR_sigreturn);
293 err |= setup_sigcontext(regs, &frame->sf_sc);
294 err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set));
299 * Arguments to signal handler:
302 * a1 = 0 (should be cause)
303 * a2 = pointer to struct sigcontext
305 * $25 and c0_epc point to the signal handler, $29 points to the
308 regs->regs[ 4] = signr;
310 regs->regs[ 6] = (unsigned long) &frame->sf_sc;
311 regs->regs[29] = (unsigned long) frame;
312 regs->regs[31] = (unsigned long) frame->sf_code;
313 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
316 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
317 current->comm, current->pid,
318 frame, regs->cp0_epc, frame->regs[31]);
323 force_sigsegv(signr, current);
327 void setup_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
328 int signr, sigset_t *set, siginfo_t *info)
330 struct rt_sigframe *frame;
333 frame = get_sigframe(ka, regs, sizeof(*frame));
334 if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
337 install_sigtramp(frame->rs_code, __NR_rt_sigreturn);
339 /* Create siginfo. */
340 err |= copy_siginfo_to_user(&frame->rs_info, info);
342 /* Create the ucontext. */
343 err |= __put_user(0, &frame->rs_uc.uc_flags);
344 err |= __put_user(0, &frame->rs_uc.uc_link);
345 err |= __put_user((void *)current->sas_ss_sp,
346 &frame->rs_uc.uc_stack.ss_sp);
347 err |= __put_user(sas_ss_flags(regs->regs[29]),
348 &frame->rs_uc.uc_stack.ss_flags);
349 err |= __put_user(current->sas_ss_size,
350 &frame->rs_uc.uc_stack.ss_size);
351 err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext);
352 err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set));
358 * Arguments to signal handler:
361 * a1 = 0 (should be cause)
362 * a2 = pointer to ucontext
364 * $25 and c0_epc point to the signal handler, $29 points to
365 * the struct rt_sigframe.
367 regs->regs[ 4] = signr;
368 regs->regs[ 5] = (unsigned long) &frame->rs_info;
369 regs->regs[ 6] = (unsigned long) &frame->rs_uc;
370 regs->regs[29] = (unsigned long) frame;
371 regs->regs[31] = (unsigned long) frame->rs_code;
372 regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
375 printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
376 current->comm, current->pid,
377 frame, regs->cp0_epc, regs->regs[31]);
382 force_sigsegv(signr, current);
385 extern void setup_rt_frame_n32(struct k_sigaction * ka,
386 struct pt_regs *regs, int signr, sigset_t *set, siginfo_t *info);
388 static inline void handle_signal(unsigned long sig, siginfo_t *info,
389 struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs)
391 switch(regs->regs[0]) {
392 case ERESTART_RESTARTBLOCK:
394 regs->regs[2] = EINTR;
397 if(!(ka->sa.sa_flags & SA_RESTART)) {
398 regs->regs[2] = EINTR;
402 case ERESTARTNOINTR: /* Userland will reload $v0. */
403 regs->regs[7] = regs->regs[26];
407 regs->regs[0] = 0; /* Don't deal with this again. */
409 if (sig_uses_siginfo(ka))
410 current->thread.abi->setup_rt_frame(ka, regs, sig, oldset, info);
412 current->thread.abi->setup_frame(ka, regs, sig, oldset);
414 spin_lock_irq(¤t->sighand->siglock);
415 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask);
416 if (!(ka->sa.sa_flags & SA_NODEFER))
417 sigaddset(¤t->blocked,sig);
419 spin_unlock_irq(¤t->sighand->siglock);
422 int do_signal(sigset_t *oldset, struct pt_regs *regs)
424 struct k_sigaction ka;
429 * We want the common case to go fast, which is why we may in certain
430 * cases get here from kernel mode. Just return without doing anything
433 if (!user_mode(regs))
440 oldset = ¤t->blocked;
442 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
444 handle_signal(signr, &info, &ka, oldset, regs);
450 * Who's code doesn't conform to the restartable syscall convention
451 * dies here!!! The li instruction, a single machine instruction,
452 * must directly be followed by the syscall instruction.
455 if (regs->regs[2] == ERESTARTNOHAND ||
456 regs->regs[2] == ERESTARTSYS ||
457 regs->regs[2] == ERESTARTNOINTR) {
458 regs->regs[7] = regs->regs[26];
461 if (regs->regs[2] == ERESTART_RESTARTBLOCK) {
462 regs->regs[2] = __NR_restart_syscall;
463 regs->regs[7] = regs->regs[26];
471 * notification of userspace execution resumption
472 * - triggered by current->work.notify_resume
474 asmlinkage void do_notify_resume(struct pt_regs *regs, sigset_t *oldset,
475 __u32 thread_info_flags)
477 /* deal with pending signal delivery */
478 if (thread_info_flags & _TIF_SIGPENDING) {
479 current->thread.abi->do_signal(oldset, regs);