Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Signal handling |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu> |
| 5 | * Copyright (C) 2008-2009 PetaLogix |
| 6 | * Copyright (C) 2003,2004 John Williams <jwilliams@itee.uq.edu.au> |
| 7 | * Copyright (C) 2001 NEC Corporation |
| 8 | * Copyright (C) 2001 Miles Bader <miles@gnu.org> |
| 9 | * Copyright (C) 1999,2000 Niibe Yutaka & Kaz Kojima |
| 10 | * Copyright (C) 1991,1992 Linus Torvalds |
| 11 | * |
| 12 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson |
| 13 | * |
| 14 | * This file was was derived from the sh version, arch/sh/kernel/signal.c |
| 15 | * |
| 16 | * This file is subject to the terms and conditions of the GNU General |
| 17 | * Public License. See the file COPYING in the main directory of this |
| 18 | * archive for more details. |
| 19 | */ |
| 20 | |
| 21 | #include <linux/sched.h> |
| 22 | #include <linux/mm.h> |
| 23 | #include <linux/smp.h> |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 24 | #include <linux/kernel.h> |
| 25 | #include <linux/signal.h> |
| 26 | #include <linux/errno.h> |
| 27 | #include <linux/wait.h> |
| 28 | #include <linux/ptrace.h> |
| 29 | #include <linux/unistd.h> |
| 30 | #include <linux/stddef.h> |
| 31 | #include <linux/personality.h> |
| 32 | #include <linux/percpu.h> |
| 33 | #include <linux/linkage.h> |
Al Viro | 969a961 | 2012-04-24 02:03:06 -0400 | [diff] [blame^] | 34 | #include <linux/tracehook.h> |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 35 | #include <asm/entry.h> |
| 36 | #include <asm/ucontext.h> |
| 37 | #include <linux/uaccess.h> |
| 38 | #include <asm/pgtable.h> |
| 39 | #include <asm/pgalloc.h> |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 40 | #include <linux/syscalls.h> |
| 41 | #include <asm/cacheflush.h> |
| 42 | #include <asm/syscalls.h> |
| 43 | |
| 44 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) |
| 45 | |
Arnd Bergmann | e513588 | 2009-06-18 19:55:30 +0200 | [diff] [blame] | 46 | asmlinkage long |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 47 | sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, |
| 48 | struct pt_regs *regs) |
| 49 | { |
| 50 | return do_sigaltstack(uss, uoss, regs->r1); |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * Do a signal return; undo the signal stack. |
| 55 | */ |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 56 | struct sigframe { |
| 57 | struct sigcontext sc; |
| 58 | unsigned long extramask[_NSIG_WORDS-1]; |
| 59 | unsigned long tramp[2]; /* signal trampoline */ |
| 60 | }; |
| 61 | |
| 62 | struct rt_sigframe { |
| 63 | struct siginfo info; |
| 64 | struct ucontext uc; |
| 65 | unsigned long tramp[2]; /* signal trampoline */ |
| 66 | }; |
| 67 | |
Arnd Bergmann | 353b431 | 2009-05-01 13:37:46 +0000 | [diff] [blame] | 68 | static int restore_sigcontext(struct pt_regs *regs, |
| 69 | struct sigcontext __user *sc, int *rval_p) |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 70 | { |
| 71 | unsigned int err = 0; |
| 72 | |
| 73 | #define COPY(x) {err |= __get_user(regs->x, &sc->regs.x); } |
| 74 | COPY(r0); |
| 75 | COPY(r1); |
| 76 | COPY(r2); COPY(r3); COPY(r4); COPY(r5); |
| 77 | COPY(r6); COPY(r7); COPY(r8); COPY(r9); |
| 78 | COPY(r10); COPY(r11); COPY(r12); COPY(r13); |
| 79 | COPY(r14); COPY(r15); COPY(r16); COPY(r17); |
| 80 | COPY(r18); COPY(r19); COPY(r20); COPY(r21); |
| 81 | COPY(r22); COPY(r23); COPY(r24); COPY(r25); |
| 82 | COPY(r26); COPY(r27); COPY(r28); COPY(r29); |
| 83 | COPY(r30); COPY(r31); |
| 84 | COPY(pc); COPY(ear); COPY(esr); COPY(fsr); |
| 85 | #undef COPY |
| 86 | |
| 87 | *rval_p = regs->r3; |
| 88 | |
| 89 | return err; |
| 90 | } |
| 91 | |
Arnd Bergmann | 3183e06 | 2009-06-18 19:55:29 +0200 | [diff] [blame] | 92 | asmlinkage long sys_rt_sigreturn(struct pt_regs *regs) |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 93 | { |
Arnd Bergmann | 353b431 | 2009-05-01 13:37:46 +0000 | [diff] [blame] | 94 | struct rt_sigframe __user *frame = |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 95 | (struct rt_sigframe __user *)(regs->r1); |
Michal Simek | 2921e2b | 2009-04-21 14:08:47 +0200 | [diff] [blame] | 96 | |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 97 | sigset_t set; |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 98 | int rval; |
| 99 | |
Al Viro | 58e4257 | 2012-04-22 03:32:18 -0400 | [diff] [blame] | 100 | /* Always make any pending restarted system calls return -EINTR */ |
| 101 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
| 102 | |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 103 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 104 | goto badframe; |
| 105 | |
| 106 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) |
| 107 | goto badframe; |
| 108 | |
| 109 | sigdelsetmask(&set, ~_BLOCKABLE); |
Matt Fleming | 60c5975 | 2012-05-11 10:58:05 +1000 | [diff] [blame] | 110 | set_current_blocked(&set); |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 111 | |
| 112 | if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &rval)) |
| 113 | goto badframe; |
| 114 | |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 115 | /* It is more difficult to avoid calling this function than to |
| 116 | call it and ignore errors. */ |
Arnd Bergmann | 353b431 | 2009-05-01 13:37:46 +0000 | [diff] [blame] | 117 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->r1)) |
| 118 | goto badframe; |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 119 | |
| 120 | return rval; |
| 121 | |
| 122 | badframe: |
| 123 | force_sig(SIGSEGV, current); |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Set up a signal frame. |
| 129 | */ |
| 130 | |
| 131 | static int |
Arnd Bergmann | 353b431 | 2009-05-01 13:37:46 +0000 | [diff] [blame] | 132 | setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 133 | unsigned long mask) |
| 134 | { |
| 135 | int err = 0; |
| 136 | |
| 137 | #define COPY(x) {err |= __put_user(regs->x, &sc->regs.x); } |
| 138 | COPY(r0); |
| 139 | COPY(r1); |
| 140 | COPY(r2); COPY(r3); COPY(r4); COPY(r5); |
| 141 | COPY(r6); COPY(r7); COPY(r8); COPY(r9); |
| 142 | COPY(r10); COPY(r11); COPY(r12); COPY(r13); |
| 143 | COPY(r14); COPY(r15); COPY(r16); COPY(r17); |
| 144 | COPY(r18); COPY(r19); COPY(r20); COPY(r21); |
| 145 | COPY(r22); COPY(r23); COPY(r24); COPY(r25); |
| 146 | COPY(r26); COPY(r27); COPY(r28); COPY(r29); |
| 147 | COPY(r30); COPY(r31); |
| 148 | COPY(pc); COPY(ear); COPY(esr); COPY(fsr); |
| 149 | #undef COPY |
| 150 | |
| 151 | err |= __put_user(mask, &sc->oldmask); |
| 152 | |
| 153 | return err; |
| 154 | } |
| 155 | |
| 156 | /* |
| 157 | * Determine which stack to use.. |
| 158 | */ |
Arnd Bergmann | 353b431 | 2009-05-01 13:37:46 +0000 | [diff] [blame] | 159 | static inline void __user * |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 160 | get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size) |
| 161 | { |
| 162 | /* Default to using normal stack */ |
| 163 | unsigned long sp = regs->r1; |
| 164 | |
| 165 | if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && !on_sig_stack(sp)) |
| 166 | sp = current->sas_ss_sp + current->sas_ss_size; |
| 167 | |
Arnd Bergmann | 353b431 | 2009-05-01 13:37:46 +0000 | [diff] [blame] | 168 | return (void __user *)((sp - frame_size) & -8UL); |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 169 | } |
| 170 | |
Matt Fleming | bcb8c8d | 2012-05-11 10:58:04 +1000 | [diff] [blame] | 171 | static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 172 | sigset_t *set, struct pt_regs *regs) |
| 173 | { |
Arnd Bergmann | 353b431 | 2009-05-01 13:37:46 +0000 | [diff] [blame] | 174 | struct rt_sigframe __user *frame; |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 175 | int err = 0; |
| 176 | int signal; |
Michal Simek | 2ee2ff8 | 2009-12-10 11:43:57 +0100 | [diff] [blame] | 177 | unsigned long address = 0; |
| 178 | #ifdef CONFIG_MMU |
| 179 | pmd_t *pmdp; |
| 180 | pte_t *ptep; |
| 181 | #endif |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 182 | |
| 183 | frame = get_sigframe(ka, regs, sizeof(*frame)); |
| 184 | |
| 185 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
| 186 | goto give_sigsegv; |
| 187 | |
| 188 | signal = current_thread_info()->exec_domain |
| 189 | && current_thread_info()->exec_domain->signal_invmap |
| 190 | && sig < 32 |
| 191 | ? current_thread_info()->exec_domain->signal_invmap[sig] |
| 192 | : sig; |
| 193 | |
Michal Simek | a6029d1 | 2009-05-12 12:10:52 +0200 | [diff] [blame] | 194 | if (info) |
| 195 | err |= copy_siginfo_to_user(&frame->info, info); |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 196 | |
| 197 | /* Create the ucontext. */ |
| 198 | err |= __put_user(0, &frame->uc.uc_flags); |
Michal Simek | 2cfedb9 | 2011-02-07 12:25:37 +0100 | [diff] [blame] | 199 | err |= __put_user(NULL, &frame->uc.uc_link); |
| 200 | err |= __put_user((void __user *)current->sas_ss_sp, |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 201 | &frame->uc.uc_stack.ss_sp); |
| 202 | err |= __put_user(sas_ss_flags(regs->r1), |
| 203 | &frame->uc.uc_stack.ss_flags); |
| 204 | err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); |
| 205 | err |= setup_sigcontext(&frame->uc.uc_mcontext, |
| 206 | regs, set->sig[0]); |
| 207 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); |
| 208 | |
| 209 | /* Set up to return from userspace. If provided, use a stub |
| 210 | already in userspace. */ |
| 211 | /* minus 8 is offset to cater for "rtsd r15,8" */ |
Arnd Bergmann | 3183e06 | 2009-06-18 19:55:29 +0200 | [diff] [blame] | 212 | /* addi r12, r0, __NR_sigreturn */ |
| 213 | err |= __put_user(0x31800000 | __NR_rt_sigreturn , |
| 214 | frame->tramp + 0); |
| 215 | /* brki r14, 0x8 */ |
| 216 | err |= __put_user(0xb9cc0008, frame->tramp + 1); |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 217 | |
Arnd Bergmann | 3183e06 | 2009-06-18 19:55:29 +0200 | [diff] [blame] | 218 | /* Return from sighandler will jump to the tramp. |
| 219 | Negative 8 offset because return is rtsd r15, 8 */ |
| 220 | regs->r15 = ((unsigned long)frame->tramp)-8; |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 221 | |
Michal Simek | 2ee2ff8 | 2009-12-10 11:43:57 +0100 | [diff] [blame] | 222 | address = ((unsigned long)frame->tramp); |
| 223 | #ifdef CONFIG_MMU |
| 224 | pmdp = pmd_offset(pud_offset( |
| 225 | pgd_offset(current->mm, address), |
| 226 | address), address); |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 227 | |
Michal Simek | 2ee2ff8 | 2009-12-10 11:43:57 +0100 | [diff] [blame] | 228 | preempt_disable(); |
| 229 | ptep = pte_offset_map(pmdp, address); |
| 230 | if (pte_present(*ptep)) { |
| 231 | address = (unsigned long) page_address(pte_page(*ptep)); |
| 232 | /* MS: I need add offset in page */ |
| 233 | address += ((unsigned long)frame->tramp) & ~PAGE_MASK; |
| 234 | /* MS address is virtual */ |
| 235 | address = virt_to_phys(address); |
| 236 | invalidate_icache_range(address, address + 8); |
| 237 | flush_dcache_range(address, address + 8); |
| 238 | } |
| 239 | pte_unmap(ptep); |
| 240 | preempt_enable(); |
| 241 | #else |
| 242 | flush_icache_range(address, address + 8); |
| 243 | flush_dcache_range(address, address + 8); |
| 244 | #endif |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 245 | if (err) |
| 246 | goto give_sigsegv; |
| 247 | |
| 248 | /* Set up registers for signal handler */ |
Michal Simek | 6e83557 | 2011-01-31 15:10:04 +0100 | [diff] [blame] | 249 | regs->r1 = (unsigned long) frame; |
Michal Simek | 2921e2b | 2009-04-21 14:08:47 +0200 | [diff] [blame] | 250 | |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 251 | /* Signal handler args: */ |
| 252 | regs->r5 = signal; /* arg 0: signum */ |
| 253 | regs->r6 = (unsigned long) &frame->info; /* arg 1: siginfo */ |
| 254 | regs->r7 = (unsigned long) &frame->uc; /* arg2: ucontext */ |
| 255 | /* Offset to handle microblaze rtid r14, 0 */ |
| 256 | regs->pc = (unsigned long)ka->sa.sa_handler; |
| 257 | |
| 258 | set_fs(USER_DS); |
| 259 | |
Michal Simek | a01523c | 2009-10-15 11:32:25 +0200 | [diff] [blame] | 260 | /* the tracer may want to single-step inside the handler */ |
| 261 | if (test_thread_flag(TIF_SINGLESTEP)) |
| 262 | ptrace_notify(SIGTRAP); |
| 263 | |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 264 | #ifdef DEBUG_SIG |
| 265 | printk(KERN_INFO "SIG deliver (%s:%d): sp=%p pc=%08lx\n", |
| 266 | current->comm, current->pid, frame, regs->pc); |
| 267 | #endif |
| 268 | |
Matt Fleming | bcb8c8d | 2012-05-11 10:58:04 +1000 | [diff] [blame] | 269 | return 0; |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 270 | |
| 271 | give_sigsegv: |
Matt Fleming | de8f2dd | 2012-05-11 10:58:03 +1000 | [diff] [blame] | 272 | force_sigsegv(sig, current); |
Matt Fleming | bcb8c8d | 2012-05-11 10:58:04 +1000 | [diff] [blame] | 273 | return -EFAULT; |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | /* Handle restarting system calls */ |
| 277 | static inline void |
| 278 | handle_restart(struct pt_regs *regs, struct k_sigaction *ka, int has_handler) |
| 279 | { |
| 280 | switch (regs->r3) { |
| 281 | case -ERESTART_RESTARTBLOCK: |
| 282 | case -ERESTARTNOHAND: |
| 283 | if (!has_handler) |
| 284 | goto do_restart; |
| 285 | regs->r3 = -EINTR; |
| 286 | break; |
| 287 | case -ERESTARTSYS: |
| 288 | if (has_handler && !(ka->sa.sa_flags & SA_RESTART)) { |
| 289 | regs->r3 = -EINTR; |
| 290 | break; |
| 291 | } |
| 292 | /* fallthrough */ |
| 293 | case -ERESTARTNOINTR: |
| 294 | do_restart: |
| 295 | /* offset of 4 bytes to re-execute trap (brki) instruction */ |
Michal Simek | 8b28626 | 2009-05-26 16:30:28 +0200 | [diff] [blame] | 296 | #ifndef CONFIG_MMU |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 297 | regs->pc -= 4; |
Michal Simek | 8b28626 | 2009-05-26 16:30:28 +0200 | [diff] [blame] | 298 | #else |
| 299 | /* offset of 8 bytes required = 4 for rtbd |
| 300 | offset, plus 4 for size of |
| 301 | "brki r14,8" |
| 302 | instruction. */ |
| 303 | regs->pc -= 8; |
| 304 | #endif |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 305 | break; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | /* |
| 310 | * OK, we're invoking a handler |
| 311 | */ |
| 312 | |
Arnd Bergmann | 3183e06 | 2009-06-18 19:55:29 +0200 | [diff] [blame] | 313 | static int |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 314 | handle_signal(unsigned long sig, struct k_sigaction *ka, |
| 315 | siginfo_t *info, sigset_t *oldset, struct pt_regs *regs) |
| 316 | { |
Matt Fleming | bcb8c8d | 2012-05-11 10:58:04 +1000 | [diff] [blame] | 317 | int ret; |
| 318 | |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 319 | /* Set up the stack frame */ |
| 320 | if (ka->sa.sa_flags & SA_SIGINFO) |
Matt Fleming | bcb8c8d | 2012-05-11 10:58:04 +1000 | [diff] [blame] | 321 | ret = setup_rt_frame(sig, ka, info, oldset, regs); |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 322 | else |
Matt Fleming | bcb8c8d | 2012-05-11 10:58:04 +1000 | [diff] [blame] | 323 | ret = setup_rt_frame(sig, ka, NULL, oldset, regs); |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 324 | |
Matt Fleming | bcb8c8d | 2012-05-11 10:58:04 +1000 | [diff] [blame] | 325 | if (ret) |
| 326 | return ret; |
| 327 | |
Matt Fleming | 60c5975 | 2012-05-11 10:58:05 +1000 | [diff] [blame] | 328 | block_sigmask(ka, sig); |
Matt Fleming | bcb8c8d | 2012-05-11 10:58:04 +1000 | [diff] [blame] | 329 | |
| 330 | return 0; |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | /* |
| 334 | * Note that 'init' is a special process: it doesn't get signals it doesn't |
| 335 | * want to handle. Thus you cannot kill init even with a SIGKILL even by |
| 336 | * mistake. |
| 337 | * |
| 338 | * Note that we go through the signals twice: once to check the signals that |
| 339 | * the kernel can handle, and then we build all the user-level signal handling |
| 340 | * stack-frames in one go after that. |
| 341 | */ |
Al Viro | 969a961 | 2012-04-24 02:03:06 -0400 | [diff] [blame^] | 342 | static int do_signal(struct pt_regs *regs, sigset_t *oldset, int in_syscall) |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 343 | { |
| 344 | siginfo_t info; |
| 345 | int signr; |
| 346 | struct k_sigaction ka; |
| 347 | #ifdef DEBUG_SIG |
| 348 | printk(KERN_INFO "do signal: %p %p %d\n", regs, oldset, in_syscall); |
| 349 | printk(KERN_INFO "do signal2: %lx %lx %ld [%lx]\n", regs->pc, regs->r1, |
| 350 | regs->r12, current_thread_info()->flags); |
| 351 | #endif |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 352 | |
Arnd Bergmann | 3183e06 | 2009-06-18 19:55:29 +0200 | [diff] [blame] | 353 | if (current_thread_info()->status & TS_RESTORE_SIGMASK) |
| 354 | oldset = ¤t->saved_sigmask; |
| 355 | else |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 356 | oldset = ¤t->blocked; |
| 357 | |
| 358 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); |
| 359 | if (signr > 0) { |
| 360 | /* Whee! Actually deliver the signal. */ |
| 361 | if (in_syscall) |
| 362 | handle_restart(regs, &ka, 1); |
Matt Fleming | bcb8c8d | 2012-05-11 10:58:04 +1000 | [diff] [blame] | 363 | if (!handle_signal(signr, &ka, &info, oldset, regs)) { |
Arnd Bergmann | 3183e06 | 2009-06-18 19:55:29 +0200 | [diff] [blame] | 364 | /* |
| 365 | * A signal was successfully delivered; the saved |
| 366 | * sigmask will have been stored in the signal frame, |
| 367 | * and will be restored by sigreturn, so we can simply |
| 368 | * clear the TS_RESTORE_SIGMASK flag. |
| 369 | */ |
| 370 | current_thread_info()->status &= |
| 371 | ~TS_RESTORE_SIGMASK; |
| 372 | } |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 373 | return 1; |
| 374 | } |
| 375 | |
| 376 | if (in_syscall) |
| 377 | handle_restart(regs, NULL, 0); |
| 378 | |
Arnd Bergmann | 3183e06 | 2009-06-18 19:55:29 +0200 | [diff] [blame] | 379 | /* |
| 380 | * If there's no signal to deliver, we just put the saved sigmask |
| 381 | * back. |
| 382 | */ |
| 383 | if (current_thread_info()->status & TS_RESTORE_SIGMASK) { |
| 384 | current_thread_info()->status &= ~TS_RESTORE_SIGMASK; |
| 385 | sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL); |
| 386 | } |
| 387 | |
Michal Simek | 2148daa9 | 2009-03-27 14:25:14 +0100 | [diff] [blame] | 388 | /* Did we come from a system call? */ |
| 389 | return 0; |
| 390 | } |
Al Viro | 969a961 | 2012-04-24 02:03:06 -0400 | [diff] [blame^] | 391 | |
| 392 | void do_notify_resume(struct pt_regs *regs, sigset_t *oldset, int in_syscall) |
| 393 | { |
| 394 | /* |
| 395 | * We want the common case to go fast, which |
| 396 | * is why we may in certain cases get here from |
| 397 | * kernel mode. Just return without doing anything |
| 398 | * if so. |
| 399 | */ |
| 400 | if (kernel_mode(regs)) |
| 401 | return; |
| 402 | |
| 403 | if (test_thread_flag(TIF_SIGPENDING)) |
| 404 | do_signal(regs, oldset, in_syscall); |
| 405 | |
| 406 | if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME)) { |
| 407 | tracehook_notify_resume(regs); |
| 408 | if (current->replacement_session_keyring) |
| 409 | key_replace_session_keyring(); |
| 410 | } |
| 411 | } |