Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/s390/kernel/signal.c |
| 3 | * |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 4 | * Copyright (C) IBM Corp. 1999,2006 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com) |
| 6 | * |
| 7 | * Based on Intel version |
| 8 | * |
| 9 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 10 | * |
| 11 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson |
| 12 | */ |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/sched.h> |
| 15 | #include <linux/mm.h> |
| 16 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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/stddef.h> |
| 24 | #include <linux/tty.h> |
| 25 | #include <linux/personality.h> |
| 26 | #include <linux/binfmts.h> |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 27 | #include <linux/tracehook.h> |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 28 | #include <linux/syscalls.h> |
Heiko Carstens | 7757591 | 2009-06-12 10:26:25 +0200 | [diff] [blame] | 29 | #include <linux/compat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/ucontext.h> |
| 31 | #include <asm/uaccess.h> |
| 32 | #include <asm/lowcore.h> |
David Howells | a0616cd | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 33 | #include <asm/switch_to.h> |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 34 | #include "entry.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) |
| 37 | |
| 38 | |
| 39 | typedef struct |
| 40 | { |
| 41 | __u8 callee_used_stack[__SIGNAL_FRAMESIZE]; |
| 42 | struct sigcontext sc; |
| 43 | _sigregs sregs; |
| 44 | int signo; |
| 45 | __u8 retcode[S390_SYSCALL_SIZE]; |
| 46 | } sigframe; |
| 47 | |
| 48 | typedef struct |
| 49 | { |
| 50 | __u8 callee_used_stack[__SIGNAL_FRAMESIZE]; |
| 51 | __u8 retcode[S390_SYSCALL_SIZE]; |
| 52 | struct siginfo info; |
| 53 | struct ucontext uc; |
| 54 | } rt_sigframe; |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /* |
| 57 | * Atomically swap in the new signal mask, and wait for a signal. |
| 58 | */ |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 59 | SYSCALL_DEFINE3(sigsuspend, int, history0, int, history1, old_sigset_t, mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { |
Heiko Carstens | 391c62f | 2011-08-03 16:44:26 +0200 | [diff] [blame] | 61 | sigset_t blocked; |
Heiko Carstens | 391c62f | 2011-08-03 16:44:26 +0200 | [diff] [blame] | 62 | siginitset(&blocked, mask); |
Al Viro | 68f3f16 | 2012-05-21 21:42:32 -0400 | [diff] [blame] | 63 | return sigsuspend(&blocked); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 66 | SYSCALL_DEFINE3(sigaction, int, sig, const struct old_sigaction __user *, act, |
| 67 | struct old_sigaction __user *, oact) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
| 69 | struct k_sigaction new_ka, old_ka; |
| 70 | int ret; |
| 71 | |
| 72 | if (act) { |
| 73 | old_sigset_t mask; |
| 74 | if (!access_ok(VERIFY_READ, act, sizeof(*act)) || |
| 75 | __get_user(new_ka.sa.sa_handler, &act->sa_handler) || |
Heiko Carstens | 12bae23 | 2006-10-27 12:39:22 +0200 | [diff] [blame] | 76 | __get_user(new_ka.sa.sa_restorer, &act->sa_restorer) || |
| 77 | __get_user(new_ka.sa.sa_flags, &act->sa_flags) || |
| 78 | __get_user(mask, &act->sa_mask)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | siginitset(&new_ka.sa.sa_mask, mask); |
| 81 | } |
| 82 | |
| 83 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
| 84 | |
| 85 | if (!ret && oact) { |
| 86 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || |
| 87 | __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || |
Heiko Carstens | 12bae23 | 2006-10-27 12:39:22 +0200 | [diff] [blame] | 88 | __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer) || |
| 89 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags) || |
| 90 | __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | return ret; |
| 95 | } |
| 96 | |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 97 | SYSCALL_DEFINE2(sigaltstack, const stack_t __user *, uss, |
| 98 | stack_t __user *, uoss) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 100 | struct pt_regs *regs = task_pt_regs(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | return do_sigaltstack(uss, uoss, regs->gprs[15]); |
| 102 | } |
| 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | /* Returns non-zero on fault. */ |
| 105 | static int save_sigregs(struct pt_regs *regs, _sigregs __user *sregs) |
| 106 | { |
Gerald Schaefer | 6837a8c | 2006-09-20 15:59:39 +0200 | [diff] [blame] | 107 | _sigregs user_sregs; |
| 108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | save_access_regs(current->thread.acrs); |
| 110 | |
| 111 | /* Copy a 'clean' PSW mask to the user to avoid leaking |
| 112 | information about whether PER is currently on. */ |
Martin Schwidefsky | d4e81b3 | 2011-10-30 15:16:51 +0100 | [diff] [blame] | 113 | user_sregs.regs.psw.mask = psw_user_bits | |
| 114 | (regs->psw.mask & PSW_MASK_USER); |
Martin Schwidefsky | b05e370 | 2006-10-04 20:01:58 +0200 | [diff] [blame] | 115 | user_sregs.regs.psw.addr = regs->psw.addr; |
| 116 | memcpy(&user_sregs.regs.gprs, ®s->gprs, sizeof(sregs->regs.gprs)); |
Gerald Schaefer | 6837a8c | 2006-09-20 15:59:39 +0200 | [diff] [blame] | 117 | memcpy(&user_sregs.regs.acrs, current->thread.acrs, |
| 118 | sizeof(sregs->regs.acrs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | /* |
| 120 | * We have to store the fp registers to current->thread.fp_regs |
| 121 | * to merge them with the emulated registers. |
| 122 | */ |
| 123 | save_fp_regs(¤t->thread.fp_regs); |
Gerald Schaefer | 6837a8c | 2006-09-20 15:59:39 +0200 | [diff] [blame] | 124 | memcpy(&user_sregs.fpregs, ¤t->thread.fp_regs, |
| 125 | sizeof(s390_fp_regs)); |
| 126 | return __copy_to_user(sregs, &user_sregs, sizeof(_sigregs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /* Returns positive number on error */ |
| 130 | static int restore_sigregs(struct pt_regs *regs, _sigregs __user *sregs) |
| 131 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | int err; |
Gerald Schaefer | 6837a8c | 2006-09-20 15:59:39 +0200 | [diff] [blame] | 133 | _sigregs user_sregs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | /* Alwys make any pending restarted system call return -EINTR */ |
| 136 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
| 137 | |
Gerald Schaefer | 6837a8c | 2006-09-20 15:59:39 +0200 | [diff] [blame] | 138 | err = __copy_from_user(&user_sregs, sregs, sizeof(_sigregs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | if (err) |
| 140 | return err; |
Martin Schwidefsky | d4e81b3 | 2011-10-30 15:16:51 +0100 | [diff] [blame] | 141 | /* Use regs->psw.mask instead of psw_user_bits to preserve PER bit. */ |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 142 | regs->psw.mask = (regs->psw.mask & ~PSW_MASK_USER) | |
Martin Schwidefsky | d4e81b3 | 2011-10-30 15:16:51 +0100 | [diff] [blame] | 143 | (user_sregs.regs.psw.mask & PSW_MASK_USER); |
| 144 | /* Check for invalid amode */ |
| 145 | if (regs->psw.mask & PSW_MASK_EA) |
| 146 | regs->psw.mask |= PSW_MASK_BA; |
| 147 | regs->psw.addr = user_sregs.regs.psw.addr; |
Martin Schwidefsky | b05e370 | 2006-10-04 20:01:58 +0200 | [diff] [blame] | 148 | memcpy(®s->gprs, &user_sregs.regs.gprs, sizeof(sregs->regs.gprs)); |
Gerald Schaefer | 6837a8c | 2006-09-20 15:59:39 +0200 | [diff] [blame] | 149 | memcpy(¤t->thread.acrs, &user_sregs.regs.acrs, |
| 150 | sizeof(sregs->regs.acrs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | restore_access_regs(current->thread.acrs); |
| 152 | |
Gerald Schaefer | 6837a8c | 2006-09-20 15:59:39 +0200 | [diff] [blame] | 153 | memcpy(¤t->thread.fp_regs, &user_sregs.fpregs, |
| 154 | sizeof(s390_fp_regs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | current->thread.fp_regs.fpc &= FPC_VALID_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | restore_fp_regs(¤t->thread.fp_regs); |
Martin Schwidefsky | b6ef5bb | 2011-10-30 15:16:49 +0100 | [diff] [blame] | 158 | clear_thread_flag(TIF_SYSCALL); /* No longer in a system call */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | return 0; |
| 160 | } |
| 161 | |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 162 | SYSCALL_DEFINE0(sigreturn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | { |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 164 | struct pt_regs *regs = task_pt_regs(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | sigframe __user *frame = (sigframe __user *)regs->gprs[15]; |
| 166 | sigset_t set; |
| 167 | |
| 168 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 169 | goto badframe; |
| 170 | if (__copy_from_user(&set.sig, &frame->sc.oldmask, _SIGMASK_COPY_SIZE)) |
| 171 | goto badframe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | sigdelsetmask(&set, ~_BLOCKABLE); |
Heiko Carstens | 391c62f | 2011-08-03 16:44:26 +0200 | [diff] [blame] | 173 | set_current_blocked(&set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | if (restore_sigregs(regs, &frame->sregs)) |
| 175 | goto badframe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | return regs->gprs[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | badframe: |
| 178 | force_sig(SIGSEGV, current); |
| 179 | return 0; |
| 180 | } |
| 181 | |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 182 | SYSCALL_DEFINE0(rt_sigreturn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | { |
Martin Schwidefsky | 03ff9a2 | 2007-04-27 16:01:40 +0200 | [diff] [blame] | 184 | struct pt_regs *regs = task_pt_regs(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | rt_sigframe __user *frame = (rt_sigframe __user *)regs->gprs[15]; |
| 186 | sigset_t set; |
| 187 | |
| 188 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 189 | goto badframe; |
| 190 | if (__copy_from_user(&set.sig, &frame->uc.uc_sigmask, sizeof(set))) |
| 191 | goto badframe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | sigdelsetmask(&set, ~_BLOCKABLE); |
Heiko Carstens | 391c62f | 2011-08-03 16:44:26 +0200 | [diff] [blame] | 193 | set_current_blocked(&set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | if (restore_sigregs(regs, &frame->uc.uc_mcontext)) |
| 195 | goto badframe; |
Cedric Le Goater | 4e3df37 | 2006-01-06 00:19:10 -0800 | [diff] [blame] | 196 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, |
| 197 | regs->gprs[15]) == -EFAULT) |
| 198 | goto badframe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | return regs->gprs[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | badframe: |
| 201 | force_sig(SIGSEGV, current); |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | /* |
| 206 | * Set up a signal frame. |
| 207 | */ |
| 208 | |
| 209 | |
| 210 | /* |
| 211 | * Determine which stack to use.. |
| 212 | */ |
| 213 | static inline void __user * |
| 214 | get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size) |
| 215 | { |
| 216 | unsigned long sp; |
| 217 | |
| 218 | /* Default to using normal stack */ |
| 219 | sp = regs->gprs[15]; |
| 220 | |
Heiko Carstens | de55343 | 2008-04-17 07:45:57 +0200 | [diff] [blame] | 221 | /* Overflow on alternate signal stack gives SIGSEGV. */ |
| 222 | if (on_sig_stack(sp) && !on_sig_stack((sp - frame_size) & -8UL)) |
| 223 | return (void __user *) -1UL; |
| 224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | /* This is the X/Open sanctioned signal stack switching. */ |
| 226 | if (ka->sa.sa_flags & SA_ONSTACK) { |
| 227 | if (! sas_ss_flags(sp)) |
| 228 | sp = current->sas_ss_sp + current->sas_ss_size; |
| 229 | } |
| 230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | return (void __user *)((sp - frame_size) & -8ul); |
| 232 | } |
| 233 | |
| 234 | static inline int map_signal(int sig) |
| 235 | { |
| 236 | if (current_thread_info()->exec_domain |
| 237 | && current_thread_info()->exec_domain->signal_invmap |
| 238 | && sig < 32) |
| 239 | return current_thread_info()->exec_domain->signal_invmap[sig]; |
| 240 | else |
| 241 | return sig; |
| 242 | } |
| 243 | |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 244 | static int setup_frame(int sig, struct k_sigaction *ka, |
| 245 | sigset_t *set, struct pt_regs * regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
| 247 | sigframe __user *frame; |
| 248 | |
| 249 | frame = get_sigframe(ka, regs, sizeof(sigframe)); |
| 250 | if (!access_ok(VERIFY_WRITE, frame, sizeof(sigframe))) |
| 251 | goto give_sigsegv; |
| 252 | |
Heiko Carstens | de55343 | 2008-04-17 07:45:57 +0200 | [diff] [blame] | 253 | if (frame == (void __user *) -1UL) |
| 254 | goto give_sigsegv; |
| 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | if (__copy_to_user(&frame->sc.oldmask, &set->sig, _SIGMASK_COPY_SIZE)) |
| 257 | goto give_sigsegv; |
| 258 | |
| 259 | if (save_sigregs(regs, &frame->sregs)) |
| 260 | goto give_sigsegv; |
| 261 | if (__put_user(&frame->sregs, &frame->sc.sregs)) |
| 262 | goto give_sigsegv; |
| 263 | |
| 264 | /* Set up to return from userspace. If provided, use a stub |
| 265 | already in userspace. */ |
| 266 | if (ka->sa.sa_flags & SA_RESTORER) { |
| 267 | regs->gprs[14] = (unsigned long) |
| 268 | ka->sa.sa_restorer | PSW_ADDR_AMODE; |
| 269 | } else { |
| 270 | regs->gprs[14] = (unsigned long) |
| 271 | frame->retcode | PSW_ADDR_AMODE; |
| 272 | if (__put_user(S390_SYSCALL_OPCODE | __NR_sigreturn, |
| 273 | (u16 __user *)(frame->retcode))) |
| 274 | goto give_sigsegv; |
| 275 | } |
| 276 | |
| 277 | /* Set up backchain. */ |
| 278 | if (__put_user(regs->gprs[15], (addr_t __user *) frame)) |
| 279 | goto give_sigsegv; |
| 280 | |
| 281 | /* Set up registers for signal handler */ |
| 282 | regs->gprs[15] = (unsigned long) frame; |
Martin Schwidefsky | d4e81b3 | 2011-10-30 15:16:51 +0100 | [diff] [blame] | 283 | regs->psw.mask |= PSW_MASK_EA | PSW_MASK_BA; /* 64 bit amode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | regs->psw.addr = (unsigned long) ka->sa.sa_handler | PSW_ADDR_AMODE; |
| 285 | |
| 286 | regs->gprs[2] = map_signal(sig); |
| 287 | regs->gprs[3] = (unsigned long) &frame->sc; |
| 288 | |
| 289 | /* We forgot to include these in the sigcontext. |
| 290 | To avoid breaking binary compatibility, they are passed as args. */ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 291 | if (sig == SIGSEGV || sig == SIGBUS || sig == SIGILL || |
| 292 | sig == SIGTRAP || sig == SIGFPE) { |
| 293 | /* set extra registers only for synchronous signals */ |
| 294 | regs->gprs[4] = regs->int_code & 127; |
| 295 | regs->gprs[5] = regs->int_parm_long; |
| 296 | regs->gprs[6] = task_thread_info(current)->last_break; |
| 297 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | /* Place signal number on stack to allow backtrace from handler. */ |
| 300 | if (__put_user(regs->gprs[2], (int __user *) &frame->signo)) |
| 301 | goto give_sigsegv; |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 302 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
| 304 | give_sigsegv: |
| 305 | force_sigsegv(sig, current); |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 306 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 309 | static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | sigset_t *set, struct pt_regs * regs) |
| 311 | { |
| 312 | int err = 0; |
| 313 | rt_sigframe __user *frame; |
| 314 | |
| 315 | frame = get_sigframe(ka, regs, sizeof(rt_sigframe)); |
| 316 | if (!access_ok(VERIFY_WRITE, frame, sizeof(rt_sigframe))) |
| 317 | goto give_sigsegv; |
| 318 | |
Heiko Carstens | de55343 | 2008-04-17 07:45:57 +0200 | [diff] [blame] | 319 | if (frame == (void __user *) -1UL) |
| 320 | goto give_sigsegv; |
| 321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | if (copy_siginfo_to_user(&frame->info, info)) |
| 323 | goto give_sigsegv; |
| 324 | |
| 325 | /* Create the ucontext. */ |
| 326 | err |= __put_user(0, &frame->uc.uc_flags); |
Al Viro | c281447 | 2005-09-29 00:16:02 +0100 | [diff] [blame] | 327 | err |= __put_user(NULL, &frame->uc.uc_link); |
| 328 | err |= __put_user((void __user *)current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | err |= __put_user(sas_ss_flags(regs->gprs[15]), |
| 330 | &frame->uc.uc_stack.ss_flags); |
| 331 | err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); |
| 332 | err |= save_sigregs(regs, &frame->uc.uc_mcontext); |
| 333 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); |
| 334 | if (err) |
| 335 | goto give_sigsegv; |
| 336 | |
| 337 | /* Set up to return from userspace. If provided, use a stub |
| 338 | already in userspace. */ |
| 339 | if (ka->sa.sa_flags & SA_RESTORER) { |
| 340 | regs->gprs[14] = (unsigned long) |
| 341 | ka->sa.sa_restorer | PSW_ADDR_AMODE; |
| 342 | } else { |
| 343 | regs->gprs[14] = (unsigned long) |
| 344 | frame->retcode | PSW_ADDR_AMODE; |
Heiko Carstens | b44df33 | 2006-05-01 12:16:15 -0700 | [diff] [blame] | 345 | if (__put_user(S390_SYSCALL_OPCODE | __NR_rt_sigreturn, |
| 346 | (u16 __user *)(frame->retcode))) |
| 347 | goto give_sigsegv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | /* Set up backchain. */ |
| 351 | if (__put_user(regs->gprs[15], (addr_t __user *) frame)) |
| 352 | goto give_sigsegv; |
| 353 | |
| 354 | /* Set up registers for signal handler */ |
| 355 | regs->gprs[15] = (unsigned long) frame; |
Martin Schwidefsky | d4e81b3 | 2011-10-30 15:16:51 +0100 | [diff] [blame] | 356 | regs->psw.mask |= PSW_MASK_EA | PSW_MASK_BA; /* 64 bit amode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | regs->psw.addr = (unsigned long) ka->sa.sa_handler | PSW_ADDR_AMODE; |
| 358 | |
| 359 | regs->gprs[2] = map_signal(sig); |
| 360 | regs->gprs[3] = (unsigned long) &frame->info; |
| 361 | regs->gprs[4] = (unsigned long) &frame->uc; |
Martin Schwidefsky | 86f2552 | 2010-05-17 10:00:05 +0200 | [diff] [blame] | 362 | regs->gprs[5] = task_thread_info(current)->last_break; |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 363 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
| 365 | give_sigsegv: |
| 366 | force_sigsegv(sig, current); |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 367 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Heiko Carstens | 391c62f | 2011-08-03 16:44:26 +0200 | [diff] [blame] | 370 | static int handle_signal(unsigned long sig, struct k_sigaction *ka, |
| 371 | siginfo_t *info, sigset_t *oldset, |
| 372 | struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | { |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 374 | int ret; |
| 375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | /* Set up the stack frame */ |
| 377 | if (ka->sa.sa_flags & SA_SIGINFO) |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 378 | ret = setup_rt_frame(sig, ka, info, oldset, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | else |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 380 | ret = setup_frame(sig, ka, oldset, regs); |
Heiko Carstens | 391c62f | 2011-08-03 16:44:26 +0200 | [diff] [blame] | 381 | if (ret) |
| 382 | return ret; |
Matt Fleming | ad252ff | 2012-03-11 11:59:33 -0400 | [diff] [blame] | 383 | block_sigmask(ka, sig); |
Heiko Carstens | 391c62f | 2011-08-03 16:44:26 +0200 | [diff] [blame] | 384 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | /* |
| 388 | * Note that 'init' is a special process: it doesn't get signals it doesn't |
| 389 | * want to handle. Thus you cannot kill init even with a SIGKILL even by |
| 390 | * mistake. |
| 391 | * |
| 392 | * Note that we go through the signals twice: once to check the signals that |
| 393 | * the kernel can handle, and then we build all the user-level signal handling |
| 394 | * stack-frames in one go after that. |
| 395 | */ |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 396 | void do_signal(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | siginfo_t info; |
| 399 | int signr; |
| 400 | struct k_sigaction ka; |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 401 | sigset_t *oldset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 403 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) |
| 404 | oldset = ¤t->saved_sigmask; |
| 405 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | oldset = ¤t->blocked; |
| 407 | |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 408 | /* |
| 409 | * Get signal to deliver. When running under ptrace, at this point |
| 410 | * the debugger may change all our registers, including the system |
| 411 | * call information. |
| 412 | */ |
Martin Schwidefsky | b6ef5bb | 2011-10-30 15:16:49 +0100 | [diff] [blame] | 413 | current_thread_info()->system_call = |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 414 | test_thread_flag(TIF_SYSCALL) ? regs->int_code : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
| 417 | if (signr > 0) { |
| 418 | /* Whee! Actually deliver the signal. */ |
Martin Schwidefsky | b6ef5bb | 2011-10-30 15:16:49 +0100 | [diff] [blame] | 419 | if (current_thread_info()->system_call) { |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 420 | regs->int_code = current_thread_info()->system_call; |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 421 | /* Check for system call restarting. */ |
| 422 | switch (regs->gprs[2]) { |
| 423 | case -ERESTART_RESTARTBLOCK: |
| 424 | case -ERESTARTNOHAND: |
| 425 | regs->gprs[2] = -EINTR; |
| 426 | break; |
| 427 | case -ERESTARTSYS: |
| 428 | if (!(ka.sa.sa_flags & SA_RESTART)) { |
| 429 | regs->gprs[2] = -EINTR; |
| 430 | break; |
| 431 | } |
| 432 | /* fallthrough */ |
| 433 | case -ERESTARTNOINTR: |
| 434 | regs->gprs[2] = regs->orig_gpr2; |
Martin Schwidefsky | ccf45ca | 2011-10-30 15:16:48 +0100 | [diff] [blame] | 435 | regs->psw.addr = |
| 436 | __rewind_psw(regs->psw, |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 437 | regs->int_code >> 16); |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 438 | break; |
| 439 | } |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 440 | } |
Martin Schwidefsky | d9ae677 | 2011-12-01 13:32:15 +0100 | [diff] [blame] | 441 | /* No longer in a system call */ |
| 442 | clear_thread_flag(TIF_SYSCALL); |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 443 | |
| 444 | if ((is_compat_task() ? |
| 445 | handle_signal32(signr, &ka, &info, oldset, regs) : |
| 446 | handle_signal(signr, &ka, &info, oldset, regs)) == 0) { |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 447 | /* |
| 448 | * A signal was successfully delivered; the saved |
| 449 | * sigmask will have been stored in the signal frame, |
| 450 | * and will be restored by sigreturn, so we can simply |
| 451 | * clear the TIF_RESTORE_SIGMASK flag. |
| 452 | */ |
| 453 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) |
| 454 | clear_thread_flag(TIF_RESTORE_SIGMASK); |
Roland McGrath | 0ac30be | 2008-01-26 14:11:22 +0100 | [diff] [blame] | 455 | |
| 456 | /* |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 457 | * Let tracing know that we've done the handler setup. |
| 458 | */ |
| 459 | tracehook_signal_handler(signr, &info, &ka, regs, |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 460 | test_thread_flag(TIF_SINGLE_STEP)); |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 461 | } |
| 462 | return; |
| 463 | } |
| 464 | |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 465 | /* No handlers present - check for system call restart */ |
Martin Schwidefsky | d9ae677 | 2011-12-01 13:32:15 +0100 | [diff] [blame] | 466 | clear_thread_flag(TIF_SYSCALL); |
Martin Schwidefsky | b6ef5bb | 2011-10-30 15:16:49 +0100 | [diff] [blame] | 467 | if (current_thread_info()->system_call) { |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 468 | regs->int_code = current_thread_info()->system_call; |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 469 | switch (regs->gprs[2]) { |
| 470 | case -ERESTART_RESTARTBLOCK: |
| 471 | /* Restart with sys_restart_syscall */ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 472 | regs->int_code = __NR_restart_syscall; |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 473 | /* fallthrough */ |
| 474 | case -ERESTARTNOHAND: |
| 475 | case -ERESTARTSYS: |
| 476 | case -ERESTARTNOINTR: |
| 477 | /* Restart system call with magic TIF bit. */ |
| 478 | regs->gprs[2] = regs->orig_gpr2; |
Martin Schwidefsky | b6ef5bb | 2011-10-30 15:16:49 +0100 | [diff] [blame] | 479 | set_thread_flag(TIF_SYSCALL); |
| 480 | break; |
Martin Schwidefsky | 20b40a7 | 2011-10-30 15:16:47 +0100 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | |
Heiko Carstens | 54dfe5d | 2006-02-01 03:06:38 -0800 | [diff] [blame] | 484 | /* |
| 485 | * If there's no signal to deliver, we just put the saved sigmask back. |
| 486 | */ |
Al Viro | 51a7b44 | 2012-05-21 23:33:55 -0400 | [diff] [blame^] | 487 | restore_saved_sigmask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | } |
Martin Schwidefsky | 753c4dd | 2008-10-10 21:33:20 +0200 | [diff] [blame] | 489 | |
| 490 | void do_notify_resume(struct pt_regs *regs) |
| 491 | { |
| 492 | clear_thread_flag(TIF_NOTIFY_RESUME); |
| 493 | tracehook_notify_resume(regs); |
| 494 | } |