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