Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Based on arch/arm/kernel/signal.c |
| 3 | * |
| 4 | * Copyright (C) 1995-2009 Russell King |
| 5 | * Copyright (C) 2012 ARM Ltd. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
AKASHI Takahiro | fd92d4a | 2014-04-30 10:51:32 +0100 | [diff] [blame] | 20 | #include <linux/compat.h> |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 21 | #include <linux/errno.h> |
| 22 | #include <linux/signal.h> |
| 23 | #include <linux/personality.h> |
| 24 | #include <linux/freezer.h> |
| 25 | #include <linux/uaccess.h> |
| 26 | #include <linux/tracehook.h> |
| 27 | #include <linux/ratelimit.h> |
| 28 | |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 29 | #include <asm/debug-monitors.h> |
| 30 | #include <asm/elf.h> |
| 31 | #include <asm/cacheflush.h> |
| 32 | #include <asm/ucontext.h> |
| 33 | #include <asm/unistd.h> |
| 34 | #include <asm/fpsimd.h> |
| 35 | #include <asm/signal32.h> |
| 36 | #include <asm/vdso.h> |
| 37 | |
| 38 | /* |
| 39 | * Do a signal return; undo the signal stack. These are aligned to 128-bit. |
| 40 | */ |
| 41 | struct rt_sigframe { |
| 42 | struct siginfo info; |
| 43 | struct ucontext uc; |
Will Deacon | 304ef4e | 2012-11-23 12:34:13 +0000 | [diff] [blame] | 44 | u64 fp; |
| 45 | u64 lr; |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | static int preserve_fpsimd_context(struct fpsimd_context __user *ctx) |
| 49 | { |
| 50 | struct fpsimd_state *fpsimd = ¤t->thread.fpsimd_state; |
| 51 | int err; |
| 52 | |
| 53 | /* dump the hardware registers to the fpsimd_state structure */ |
Ard Biesheuvel | c51f926 | 2014-02-24 15:26:27 +0100 | [diff] [blame] | 54 | fpsimd_preserve_current_state(); |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 55 | |
| 56 | /* copy the FP and status/control registers */ |
| 57 | err = __copy_to_user(ctx->vregs, fpsimd->vregs, sizeof(fpsimd->vregs)); |
| 58 | __put_user_error(fpsimd->fpsr, &ctx->fpsr, err); |
| 59 | __put_user_error(fpsimd->fpcr, &ctx->fpcr, err); |
| 60 | |
| 61 | /* copy the magic/size information */ |
| 62 | __put_user_error(FPSIMD_MAGIC, &ctx->head.magic, err); |
| 63 | __put_user_error(sizeof(struct fpsimd_context), &ctx->head.size, err); |
| 64 | |
| 65 | return err ? -EFAULT : 0; |
| 66 | } |
| 67 | |
| 68 | static int restore_fpsimd_context(struct fpsimd_context __user *ctx) |
| 69 | { |
| 70 | struct fpsimd_state fpsimd; |
| 71 | __u32 magic, size; |
| 72 | int err = 0; |
| 73 | |
| 74 | /* check the magic/size information */ |
| 75 | __get_user_error(magic, &ctx->head.magic, err); |
| 76 | __get_user_error(size, &ctx->head.size, err); |
| 77 | if (err) |
| 78 | return -EFAULT; |
| 79 | if (magic != FPSIMD_MAGIC || size != sizeof(struct fpsimd_context)) |
| 80 | return -EINVAL; |
| 81 | |
| 82 | /* copy the FP and status/control registers */ |
| 83 | err = __copy_from_user(fpsimd.vregs, ctx->vregs, |
| 84 | sizeof(fpsimd.vregs)); |
| 85 | __get_user_error(fpsimd.fpsr, &ctx->fpsr, err); |
| 86 | __get_user_error(fpsimd.fpcr, &ctx->fpcr, err); |
| 87 | |
| 88 | /* load the hardware registers from the fpsimd_state structure */ |
Ard Biesheuvel | c51f926 | 2014-02-24 15:26:27 +0100 | [diff] [blame] | 89 | if (!err) |
| 90 | fpsimd_update_current_state(&fpsimd); |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 91 | |
| 92 | return err ? -EFAULT : 0; |
| 93 | } |
| 94 | |
| 95 | static int restore_sigframe(struct pt_regs *regs, |
| 96 | struct rt_sigframe __user *sf) |
| 97 | { |
| 98 | sigset_t set; |
| 99 | int i, err; |
Catalin Marinas | 0e0276d | 2014-04-04 15:42:16 +0100 | [diff] [blame] | 100 | void *aux = sf->uc.uc_mcontext.__reserved; |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 101 | |
| 102 | err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set)); |
| 103 | if (err == 0) |
| 104 | set_current_blocked(&set); |
| 105 | |
| 106 | for (i = 0; i < 31; i++) |
| 107 | __get_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i], |
| 108 | err); |
| 109 | __get_user_error(regs->sp, &sf->uc.uc_mcontext.sp, err); |
| 110 | __get_user_error(regs->pc, &sf->uc.uc_mcontext.pc, err); |
| 111 | __get_user_error(regs->pstate, &sf->uc.uc_mcontext.pstate, err); |
| 112 | |
| 113 | /* |
| 114 | * Avoid sys_rt_sigreturn() restarting. |
| 115 | */ |
| 116 | regs->syscallno = ~0UL; |
| 117 | |
| 118 | err |= !valid_user_regs(®s->user_regs); |
| 119 | |
Catalin Marinas | 0e0276d | 2014-04-04 15:42:16 +0100 | [diff] [blame] | 120 | if (err == 0) { |
| 121 | struct fpsimd_context *fpsimd_ctx = |
| 122 | container_of(aux, struct fpsimd_context, head); |
| 123 | err |= restore_fpsimd_context(fpsimd_ctx); |
| 124 | } |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 125 | |
| 126 | return err; |
| 127 | } |
| 128 | |
| 129 | asmlinkage long sys_rt_sigreturn(struct pt_regs *regs) |
| 130 | { |
| 131 | struct rt_sigframe __user *frame; |
| 132 | |
| 133 | /* Always make any pending restarted system calls return -EINTR */ |
| 134 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
| 135 | |
| 136 | /* |
| 137 | * Since we stacked the signal on a 128-bit boundary, then 'sp' should |
| 138 | * be word aligned here. |
| 139 | */ |
| 140 | if (regs->sp & 15) |
| 141 | goto badframe; |
| 142 | |
| 143 | frame = (struct rt_sigframe __user *)regs->sp; |
| 144 | |
| 145 | if (!access_ok(VERIFY_READ, frame, sizeof (*frame))) |
| 146 | goto badframe; |
| 147 | |
| 148 | if (restore_sigframe(regs, frame)) |
| 149 | goto badframe; |
| 150 | |
Al Viro | 207bdae | 2012-12-23 01:56:45 -0500 | [diff] [blame] | 151 | if (restore_altstack(&frame->uc.uc_stack)) |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 152 | goto badframe; |
| 153 | |
| 154 | return regs->regs[0]; |
| 155 | |
| 156 | badframe: |
| 157 | if (show_unhandled_signals) |
| 158 | pr_info_ratelimited("%s[%d]: bad frame in %s: pc=%08llx sp=%08llx\n", |
| 159 | current->comm, task_pid_nr(current), __func__, |
| 160 | regs->pc, regs->sp); |
| 161 | force_sig(SIGSEGV, current); |
| 162 | return 0; |
| 163 | } |
| 164 | |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 165 | static int setup_sigframe(struct rt_sigframe __user *sf, |
| 166 | struct pt_regs *regs, sigset_t *set) |
| 167 | { |
| 168 | int i, err = 0; |
Catalin Marinas | 0e0276d | 2014-04-04 15:42:16 +0100 | [diff] [blame] | 169 | void *aux = sf->uc.uc_mcontext.__reserved; |
| 170 | struct _aarch64_ctx *end; |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 171 | |
Will Deacon | 304ef4e | 2012-11-23 12:34:13 +0000 | [diff] [blame] | 172 | /* set up the stack frame for unwinding */ |
| 173 | __put_user_error(regs->regs[29], &sf->fp, err); |
| 174 | __put_user_error(regs->regs[30], &sf->lr, err); |
| 175 | |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 176 | for (i = 0; i < 31; i++) |
| 177 | __put_user_error(regs->regs[i], &sf->uc.uc_mcontext.regs[i], |
| 178 | err); |
| 179 | __put_user_error(regs->sp, &sf->uc.uc_mcontext.sp, err); |
| 180 | __put_user_error(regs->pc, &sf->uc.uc_mcontext.pc, err); |
| 181 | __put_user_error(regs->pstate, &sf->uc.uc_mcontext.pstate, err); |
| 182 | |
| 183 | __put_user_error(current->thread.fault_address, &sf->uc.uc_mcontext.fault_address, err); |
| 184 | |
| 185 | err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(*set)); |
| 186 | |
Catalin Marinas | 0e0276d | 2014-04-04 15:42:16 +0100 | [diff] [blame] | 187 | if (err == 0) { |
| 188 | struct fpsimd_context *fpsimd_ctx = |
| 189 | container_of(aux, struct fpsimd_context, head); |
| 190 | err |= preserve_fpsimd_context(fpsimd_ctx); |
| 191 | aux += sizeof(*fpsimd_ctx); |
| 192 | } |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 193 | |
Catalin Marinas | 15af194 | 2013-09-16 15:19:27 +0100 | [diff] [blame] | 194 | /* fault information, if valid */ |
| 195 | if (current->thread.fault_code) { |
| 196 | struct esr_context *esr_ctx = |
| 197 | container_of(aux, struct esr_context, head); |
| 198 | __put_user_error(ESR_MAGIC, &esr_ctx->head.magic, err); |
| 199 | __put_user_error(sizeof(*esr_ctx), &esr_ctx->head.size, err); |
| 200 | __put_user_error(current->thread.fault_code, &esr_ctx->esr, err); |
| 201 | aux += sizeof(*esr_ctx); |
| 202 | } |
| 203 | |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 204 | /* set the "end" magic */ |
Catalin Marinas | 0e0276d | 2014-04-04 15:42:16 +0100 | [diff] [blame] | 205 | end = aux; |
| 206 | __put_user_error(0, &end->magic, err); |
| 207 | __put_user_error(0, &end->size, err); |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 208 | |
| 209 | return err; |
| 210 | } |
| 211 | |
Richard Weinberger | 38a7be3 | 2014-03-05 13:31:20 +0100 | [diff] [blame] | 212 | static struct rt_sigframe __user *get_sigframe(struct ksignal *ksig, |
Will Deacon | b64e1c6 | 2012-11-23 11:01:04 +0000 | [diff] [blame] | 213 | struct pt_regs *regs) |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 214 | { |
| 215 | unsigned long sp, sp_top; |
Will Deacon | b64e1c6 | 2012-11-23 11:01:04 +0000 | [diff] [blame] | 216 | struct rt_sigframe __user *frame; |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 217 | |
Richard Weinberger | 38a7be3 | 2014-03-05 13:31:20 +0100 | [diff] [blame] | 218 | sp = sp_top = sigsp(regs->sp, ksig); |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 219 | |
Will Deacon | b64e1c6 | 2012-11-23 11:01:04 +0000 | [diff] [blame] | 220 | sp = (sp - sizeof(struct rt_sigframe)) & ~15; |
| 221 | frame = (struct rt_sigframe __user *)sp; |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 222 | |
| 223 | /* |
| 224 | * Check that we can actually write to the signal frame. |
| 225 | */ |
| 226 | if (!access_ok(VERIFY_WRITE, frame, sp_top - sp)) |
| 227 | frame = NULL; |
| 228 | |
| 229 | return frame; |
| 230 | } |
| 231 | |
Will Deacon | 304ef4e | 2012-11-23 12:34:13 +0000 | [diff] [blame] | 232 | static void setup_return(struct pt_regs *regs, struct k_sigaction *ka, |
| 233 | void __user *frame, int usig) |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 234 | { |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 235 | __sigrestore_t sigtramp; |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 236 | |
| 237 | regs->regs[0] = usig; |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 238 | regs->sp = (unsigned long)frame; |
Will Deacon | 304ef4e | 2012-11-23 12:34:13 +0000 | [diff] [blame] | 239 | regs->regs[29] = regs->sp + offsetof(struct rt_sigframe, fp); |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 240 | regs->pc = (unsigned long)ka->sa.sa_handler; |
| 241 | |
| 242 | if (ka->sa.sa_flags & SA_RESTORER) |
| 243 | sigtramp = ka->sa.sa_restorer; |
| 244 | else |
| 245 | sigtramp = VDSO_SYMBOL(current->mm->context.vdso, sigtramp); |
| 246 | |
| 247 | regs->regs[30] = (unsigned long)sigtramp; |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Richard Weinberger | 00554fa | 2013-10-06 22:52:44 +0200 | [diff] [blame] | 250 | static int setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set, |
| 251 | struct pt_regs *regs) |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 252 | { |
| 253 | struct rt_sigframe __user *frame; |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 254 | int err = 0; |
| 255 | |
Richard Weinberger | 38a7be3 | 2014-03-05 13:31:20 +0100 | [diff] [blame] | 256 | frame = get_sigframe(ksig, regs); |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 257 | if (!frame) |
| 258 | return 1; |
| 259 | |
| 260 | __put_user_error(0, &frame->uc.uc_flags, err); |
| 261 | __put_user_error(NULL, &frame->uc.uc_link, err); |
| 262 | |
Al Viro | 207bdae | 2012-12-23 01:56:45 -0500 | [diff] [blame] | 263 | err |= __save_altstack(&frame->uc.uc_stack, regs->sp); |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 264 | err |= setup_sigframe(frame, regs, set); |
Will Deacon | 304ef4e | 2012-11-23 12:34:13 +0000 | [diff] [blame] | 265 | if (err == 0) { |
Richard Weinberger | 00554fa | 2013-10-06 22:52:44 +0200 | [diff] [blame] | 266 | setup_return(regs, &ksig->ka, frame, usig); |
| 267 | if (ksig->ka.sa.sa_flags & SA_SIGINFO) { |
| 268 | err |= copy_siginfo_to_user(&frame->info, &ksig->info); |
Will Deacon | 304ef4e | 2012-11-23 12:34:13 +0000 | [diff] [blame] | 269 | regs->regs[1] = (unsigned long)&frame->info; |
| 270 | regs->regs[2] = (unsigned long)&frame->uc; |
| 271 | } |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | return err; |
| 275 | } |
| 276 | |
| 277 | static void setup_restart_syscall(struct pt_regs *regs) |
| 278 | { |
| 279 | if (is_compat_task()) |
| 280 | compat_setup_restart_syscall(regs); |
| 281 | else |
| 282 | regs->regs[8] = __NR_restart_syscall; |
| 283 | } |
| 284 | |
| 285 | /* |
| 286 | * OK, we're invoking a handler |
| 287 | */ |
Richard Weinberger | 00554fa | 2013-10-06 22:52:44 +0200 | [diff] [blame] | 288 | static void handle_signal(struct ksignal *ksig, struct pt_regs *regs) |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 289 | { |
| 290 | struct thread_info *thread = current_thread_info(); |
| 291 | struct task_struct *tsk = current; |
| 292 | sigset_t *oldset = sigmask_to_save(); |
Richard Weinberger | 00554fa | 2013-10-06 22:52:44 +0200 | [diff] [blame] | 293 | int usig = ksig->sig; |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 294 | int ret; |
| 295 | |
| 296 | /* |
| 297 | * translate the signal |
| 298 | */ |
| 299 | if (usig < 32 && thread->exec_domain && thread->exec_domain->signal_invmap) |
| 300 | usig = thread->exec_domain->signal_invmap[usig]; |
| 301 | |
| 302 | /* |
| 303 | * Set up the stack frame |
| 304 | */ |
| 305 | if (is_compat_task()) { |
Richard Weinberger | 00554fa | 2013-10-06 22:52:44 +0200 | [diff] [blame] | 306 | if (ksig->ka.sa.sa_flags & SA_SIGINFO) |
| 307 | ret = compat_setup_rt_frame(usig, ksig, oldset, regs); |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 308 | else |
Richard Weinberger | 00554fa | 2013-10-06 22:52:44 +0200 | [diff] [blame] | 309 | ret = compat_setup_frame(usig, ksig, oldset, regs); |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 310 | } else { |
Richard Weinberger | 00554fa | 2013-10-06 22:52:44 +0200 | [diff] [blame] | 311 | ret = setup_rt_frame(usig, ksig, oldset, regs); |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /* |
| 315 | * Check that the resulting registers are actually sane. |
| 316 | */ |
| 317 | ret |= !valid_user_regs(®s->user_regs); |
| 318 | |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 319 | /* |
| 320 | * Fast forward the stepping logic so we step into the signal |
| 321 | * handler. |
| 322 | */ |
Richard Weinberger | 00554fa | 2013-10-06 22:52:44 +0200 | [diff] [blame] | 323 | if (!ret) |
| 324 | user_fastforward_single_step(tsk); |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 325 | |
Richard Weinberger | 00554fa | 2013-10-06 22:52:44 +0200 | [diff] [blame] | 326 | signal_setup_done(ret, ksig, 0); |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /* |
| 330 | * Note that 'init' is a special process: it doesn't get signals it doesn't |
| 331 | * want to handle. Thus you cannot kill init even with a SIGKILL even by |
| 332 | * mistake. |
| 333 | * |
| 334 | * Note that we go through the signals twice: once to check the signals that |
| 335 | * the kernel can handle, and then we build all the user-level signal handling |
| 336 | * stack-frames in one go after that. |
| 337 | */ |
| 338 | static void do_signal(struct pt_regs *regs) |
| 339 | { |
| 340 | unsigned long continue_addr = 0, restart_addr = 0; |
Richard Weinberger | 00554fa | 2013-10-06 22:52:44 +0200 | [diff] [blame] | 341 | int retval = 0; |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 342 | int syscall = (int)regs->syscallno; |
Richard Weinberger | 00554fa | 2013-10-06 22:52:44 +0200 | [diff] [blame] | 343 | struct ksignal ksig; |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 344 | |
| 345 | /* |
| 346 | * If we were from a system call, check for system call restarting... |
| 347 | */ |
| 348 | if (syscall >= 0) { |
| 349 | continue_addr = regs->pc; |
| 350 | restart_addr = continue_addr - (compat_thumb_mode(regs) ? 2 : 4); |
| 351 | retval = regs->regs[0]; |
| 352 | |
| 353 | /* |
| 354 | * Avoid additional syscall restarting via ret_to_user. |
| 355 | */ |
| 356 | regs->syscallno = ~0UL; |
| 357 | |
| 358 | /* |
| 359 | * Prepare for system call restart. We do this here so that a |
| 360 | * debugger will see the already changed PC. |
| 361 | */ |
| 362 | switch (retval) { |
| 363 | case -ERESTARTNOHAND: |
| 364 | case -ERESTARTSYS: |
| 365 | case -ERESTARTNOINTR: |
| 366 | case -ERESTART_RESTARTBLOCK: |
| 367 | regs->regs[0] = regs->orig_x0; |
| 368 | regs->pc = restart_addr; |
| 369 | break; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | /* |
| 374 | * Get the signal to deliver. When running under ptrace, at this point |
| 375 | * the debugger may change all of our registers. |
| 376 | */ |
Richard Weinberger | 00554fa | 2013-10-06 22:52:44 +0200 | [diff] [blame] | 377 | if (get_signal(&ksig)) { |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 378 | /* |
| 379 | * Depending on the signal settings, we may need to revert the |
| 380 | * decision to restart the system call, but skip this if a |
| 381 | * debugger has chosen to restart at a different PC. |
| 382 | */ |
| 383 | if (regs->pc == restart_addr && |
| 384 | (retval == -ERESTARTNOHAND || |
| 385 | retval == -ERESTART_RESTARTBLOCK || |
| 386 | (retval == -ERESTARTSYS && |
Richard Weinberger | 00554fa | 2013-10-06 22:52:44 +0200 | [diff] [blame] | 387 | !(ksig.ka.sa.sa_flags & SA_RESTART)))) { |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 388 | regs->regs[0] = -EINTR; |
| 389 | regs->pc = continue_addr; |
| 390 | } |
| 391 | |
Richard Weinberger | 00554fa | 2013-10-06 22:52:44 +0200 | [diff] [blame] | 392 | handle_signal(&ksig, regs); |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 393 | return; |
| 394 | } |
| 395 | |
| 396 | /* |
| 397 | * Handle restarting a different system call. As above, if a debugger |
| 398 | * has chosen to restart at a different PC, ignore the restart. |
| 399 | */ |
| 400 | if (syscall >= 0 && regs->pc == restart_addr) { |
| 401 | if (retval == -ERESTART_RESTARTBLOCK) |
| 402 | setup_restart_syscall(regs); |
| 403 | user_rewind_single_step(current); |
| 404 | } |
| 405 | |
| 406 | restore_saved_sigmask(); |
| 407 | } |
| 408 | |
| 409 | asmlinkage void do_notify_resume(struct pt_regs *regs, |
| 410 | unsigned int thread_flags) |
| 411 | { |
| 412 | if (thread_flags & _TIF_SIGPENDING) |
| 413 | do_signal(regs); |
| 414 | |
| 415 | if (thread_flags & _TIF_NOTIFY_RESUME) { |
| 416 | clear_thread_flag(TIF_NOTIFY_RESUME); |
| 417 | tracehook_notify_resume(regs); |
| 418 | } |
Ard Biesheuvel | 005f78c | 2014-05-08 11:20:23 +0200 | [diff] [blame] | 419 | |
| 420 | if (thread_flags & _TIF_FOREIGN_FPSTATE) |
| 421 | fpsimd_restore_current_state(); |
| 422 | |
Catalin Marinas | 2c020ed | 2012-03-05 11:49:31 +0000 | [diff] [blame] | 423 | } |