Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/x86_64/kernel/signal.c |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | * Copyright (C) 2000, 2001, 2002 Andi Kleen SuSE Labs |
| 6 | * |
| 7 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson |
| 8 | * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes |
| 9 | * 2000-2002 x86-64 support by Andi Kleen |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <linux/sched.h> |
| 13 | #include <linux/mm.h> |
| 14 | #include <linux/smp.h> |
| 15 | #include <linux/smp_lock.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/signal.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/wait.h> |
| 20 | #include <linux/ptrace.h> |
| 21 | #include <linux/unistd.h> |
| 22 | #include <linux/stddef.h> |
| 23 | #include <linux/personality.h> |
| 24 | #include <linux/compiler.h> |
| 25 | #include <asm/ucontext.h> |
| 26 | #include <asm/uaccess.h> |
| 27 | #include <asm/i387.h> |
| 28 | #include <asm/proto.h> |
Oliver Korpilla | c5924b7 | 2005-05-27 12:52:55 -0700 | [diff] [blame] | 29 | #include <asm/ia32_unistd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | /* #define DEBUG_SIG 1 */ |
| 32 | |
| 33 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) |
| 34 | |
Roland McGrath | 0928d6e | 2005-06-23 00:08:37 -0700 | [diff] [blame] | 35 | int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | sigset_t *set, struct pt_regs * regs); |
Roland McGrath | 0928d6e | 2005-06-23 00:08:37 -0700 | [diff] [blame] | 37 | int ia32_setup_frame(int sig, struct k_sigaction *ka, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | sigset_t *set, struct pt_regs * regs); |
| 39 | |
| 40 | asmlinkage long |
| 41 | sys_rt_sigsuspend(sigset_t __user *unewset, size_t sigsetsize, struct pt_regs *regs) |
| 42 | { |
| 43 | sigset_t saveset, newset; |
| 44 | |
| 45 | /* XXX: Don't preclude handling different sized sigset_t's. */ |
| 46 | if (sigsetsize != sizeof(sigset_t)) |
| 47 | return -EINVAL; |
| 48 | |
| 49 | if (copy_from_user(&newset, unewset, sizeof(newset))) |
| 50 | return -EFAULT; |
| 51 | sigdelsetmask(&newset, ~_BLOCKABLE); |
| 52 | |
| 53 | spin_lock_irq(¤t->sighand->siglock); |
| 54 | saveset = current->blocked; |
| 55 | current->blocked = newset; |
| 56 | recalc_sigpending(); |
| 57 | spin_unlock_irq(¤t->sighand->siglock); |
| 58 | #ifdef DEBUG_SIG |
| 59 | printk("rt_sigsuspend savset(%lx) newset(%lx) regs(%p) rip(%lx)\n", |
| 60 | saveset, newset, regs, regs->rip); |
| 61 | #endif |
| 62 | regs->rax = -EINTR; |
| 63 | while (1) { |
| 64 | current->state = TASK_INTERRUPTIBLE; |
| 65 | schedule(); |
| 66 | if (do_signal(regs, &saveset)) |
| 67 | return -EINTR; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | asmlinkage long |
| 72 | sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, |
| 73 | struct pt_regs *regs) |
| 74 | { |
| 75 | return do_sigaltstack(uss, uoss, regs->rsp); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | /* |
| 80 | * Do a signal return; undo the signal stack. |
| 81 | */ |
| 82 | |
| 83 | struct rt_sigframe |
| 84 | { |
Al Viro | 993fb38 | 2005-04-26 07:43:42 -0700 | [diff] [blame] | 85 | char __user *pretcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | struct ucontext uc; |
| 87 | struct siginfo info; |
| 88 | }; |
| 89 | |
| 90 | static int |
| 91 | restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, unsigned long *prax) |
| 92 | { |
| 93 | unsigned int err = 0; |
| 94 | |
| 95 | /* Always make any pending restarted system calls return -EINTR */ |
| 96 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
| 97 | |
| 98 | #define COPY(x) err |= __get_user(regs->x, &sc->x) |
| 99 | |
| 100 | COPY(rdi); COPY(rsi); COPY(rbp); COPY(rsp); COPY(rbx); |
| 101 | COPY(rdx); COPY(rcx); COPY(rip); |
| 102 | COPY(r8); |
| 103 | COPY(r9); |
| 104 | COPY(r10); |
| 105 | COPY(r11); |
| 106 | COPY(r12); |
| 107 | COPY(r13); |
| 108 | COPY(r14); |
| 109 | COPY(r15); |
| 110 | |
Bryan Ford | e4e5d32 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 111 | /* Kernel saves and restores only the CS segment register on signals, |
| 112 | * which is the bare minimum needed to allow mixed 32/64-bit code. |
| 113 | * App's signal handler can save/restore other segments if needed. */ |
| 114 | { |
| 115 | unsigned cs; |
| 116 | err |= __get_user(cs, &sc->cs); |
| 117 | regs->cs = cs | 3; /* Force into user mode */ |
| 118 | } |
| 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { |
| 121 | unsigned int tmpflags; |
| 122 | err |= __get_user(tmpflags, &sc->eflags); |
| 123 | regs->eflags = (regs->eflags & ~0x40DD5) | (tmpflags & 0x40DD5); |
| 124 | regs->orig_rax = -1; /* disable syscall checks */ |
| 125 | } |
| 126 | |
| 127 | { |
| 128 | struct _fpstate __user * buf; |
| 129 | err |= __get_user(buf, &sc->fpstate); |
| 130 | |
| 131 | if (buf) { |
| 132 | if (!access_ok(VERIFY_READ, buf, sizeof(*buf))) |
| 133 | goto badframe; |
| 134 | err |= restore_i387(buf); |
| 135 | } else { |
| 136 | struct task_struct *me = current; |
| 137 | if (used_math()) { |
| 138 | clear_fpu(me); |
| 139 | clear_used_math(); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | err |= __get_user(*prax, &sc->rax); |
| 145 | return err; |
| 146 | |
| 147 | badframe: |
| 148 | return 1; |
| 149 | } |
| 150 | |
| 151 | asmlinkage long sys_rt_sigreturn(struct pt_regs *regs) |
| 152 | { |
| 153 | struct rt_sigframe __user *frame; |
| 154 | sigset_t set; |
| 155 | unsigned long eax; |
| 156 | |
| 157 | frame = (struct rt_sigframe __user *)(regs->rsp - 8); |
| 158 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) { |
| 159 | goto badframe; |
| 160 | } |
| 161 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) { |
| 162 | goto badframe; |
| 163 | } |
| 164 | |
| 165 | sigdelsetmask(&set, ~_BLOCKABLE); |
| 166 | spin_lock_irq(¤t->sighand->siglock); |
| 167 | current->blocked = set; |
| 168 | recalc_sigpending(); |
| 169 | spin_unlock_irq(¤t->sighand->siglock); |
| 170 | |
| 171 | if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &eax)) |
| 172 | goto badframe; |
| 173 | |
| 174 | #ifdef DEBUG_SIG |
| 175 | printk("%d sigreturn rip:%lx rsp:%lx frame:%p rax:%lx\n",current->pid,regs.rip,regs.rsp,frame,eax); |
| 176 | #endif |
| 177 | |
| 178 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->rsp) == -EFAULT) |
| 179 | goto badframe; |
| 180 | |
| 181 | return eax; |
| 182 | |
| 183 | badframe: |
| 184 | signal_fault(regs,frame,"sigreturn"); |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | /* |
| 189 | * Set up a signal frame. |
| 190 | */ |
| 191 | |
| 192 | static inline int |
| 193 | setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, unsigned long mask, struct task_struct *me) |
| 194 | { |
| 195 | int err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Bryan Ford | e4e5d32 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 197 | err |= __put_user(regs->cs, &sc->cs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | err |= __put_user(0, &sc->gs); |
| 199 | err |= __put_user(0, &sc->fs); |
| 200 | |
| 201 | err |= __put_user(regs->rdi, &sc->rdi); |
| 202 | err |= __put_user(regs->rsi, &sc->rsi); |
| 203 | err |= __put_user(regs->rbp, &sc->rbp); |
| 204 | err |= __put_user(regs->rsp, &sc->rsp); |
| 205 | err |= __put_user(regs->rbx, &sc->rbx); |
| 206 | err |= __put_user(regs->rdx, &sc->rdx); |
| 207 | err |= __put_user(regs->rcx, &sc->rcx); |
| 208 | err |= __put_user(regs->rax, &sc->rax); |
| 209 | err |= __put_user(regs->r8, &sc->r8); |
| 210 | err |= __put_user(regs->r9, &sc->r9); |
| 211 | err |= __put_user(regs->r10, &sc->r10); |
| 212 | err |= __put_user(regs->r11, &sc->r11); |
| 213 | err |= __put_user(regs->r12, &sc->r12); |
| 214 | err |= __put_user(regs->r13, &sc->r13); |
| 215 | err |= __put_user(regs->r14, &sc->r14); |
| 216 | err |= __put_user(regs->r15, &sc->r15); |
| 217 | err |= __put_user(me->thread.trap_no, &sc->trapno); |
| 218 | err |= __put_user(me->thread.error_code, &sc->err); |
| 219 | err |= __put_user(regs->rip, &sc->rip); |
Andi Kleen | be61bff | 2005-04-16 15:24:57 -0700 | [diff] [blame] | 220 | err |= __put_user(regs->eflags, &sc->eflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | err |= __put_user(mask, &sc->oldmask); |
| 222 | err |= __put_user(me->thread.cr2, &sc->cr2); |
| 223 | |
| 224 | return err; |
| 225 | } |
| 226 | |
| 227 | /* |
| 228 | * Determine which stack to use.. |
| 229 | */ |
| 230 | |
| 231 | static void __user * |
| 232 | get_stack(struct k_sigaction *ka, struct pt_regs *regs, unsigned long size) |
| 233 | { |
| 234 | unsigned long rsp; |
| 235 | |
| 236 | /* Default to using normal stack - redzone*/ |
| 237 | rsp = regs->rsp - 128; |
| 238 | |
| 239 | /* This is the X/Open sanctioned signal stack switching. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | if (ka->sa.sa_flags & SA_ONSTACK) { |
| 241 | if (sas_ss_flags(rsp) == 0) |
| 242 | rsp = current->sas_ss_sp + current->sas_ss_size; |
| 243 | } |
| 244 | |
| 245 | return (void __user *)round_down(rsp - size, 16); |
| 246 | } |
| 247 | |
Roland McGrath | 0928d6e | 2005-06-23 00:08:37 -0700 | [diff] [blame] | 248 | 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] | 249 | sigset_t *set, struct pt_regs * regs) |
| 250 | { |
| 251 | struct rt_sigframe __user *frame; |
| 252 | struct _fpstate __user *fp = NULL; |
| 253 | int err = 0; |
| 254 | struct task_struct *me = current; |
| 255 | |
| 256 | if (used_math()) { |
| 257 | fp = get_stack(ka, regs, sizeof(struct _fpstate)); |
| 258 | frame = (void __user *)round_down( |
| 259 | (unsigned long)fp - sizeof(struct rt_sigframe), 16) - 8; |
| 260 | |
| 261 | if (!access_ok(VERIFY_WRITE, fp, sizeof(struct _fpstate))) |
| 262 | goto give_sigsegv; |
| 263 | |
| 264 | if (save_i387(fp) < 0) |
| 265 | err |= -1; |
| 266 | } else |
| 267 | frame = get_stack(ka, regs, sizeof(struct rt_sigframe)) - 8; |
| 268 | |
| 269 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
| 270 | goto give_sigsegv; |
| 271 | |
| 272 | if (ka->sa.sa_flags & SA_SIGINFO) { |
| 273 | err |= copy_siginfo_to_user(&frame->info, info); |
| 274 | if (err) |
| 275 | goto give_sigsegv; |
| 276 | } |
| 277 | |
| 278 | /* Create the ucontext. */ |
| 279 | err |= __put_user(0, &frame->uc.uc_flags); |
| 280 | err |= __put_user(0, &frame->uc.uc_link); |
| 281 | err |= __put_user(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp); |
| 282 | err |= __put_user(sas_ss_flags(regs->rsp), |
| 283 | &frame->uc.uc_stack.ss_flags); |
| 284 | err |= __put_user(me->sas_ss_size, &frame->uc.uc_stack.ss_size); |
| 285 | err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0], me); |
| 286 | err |= __put_user(fp, &frame->uc.uc_mcontext.fpstate); |
| 287 | if (sizeof(*set) == 16) { |
| 288 | __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]); |
| 289 | __put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]); |
| 290 | } else |
| 291 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); |
| 292 | |
| 293 | /* Set up to return from userspace. If provided, use a stub |
| 294 | already in userspace. */ |
| 295 | /* x86-64 should always use SA_RESTORER. */ |
| 296 | if (ka->sa.sa_flags & SA_RESTORER) { |
| 297 | err |= __put_user(ka->sa.sa_restorer, &frame->pretcode); |
| 298 | } else { |
| 299 | /* could use a vstub here */ |
| 300 | goto give_sigsegv; |
| 301 | } |
| 302 | |
| 303 | if (err) |
| 304 | goto give_sigsegv; |
| 305 | |
| 306 | #ifdef DEBUG_SIG |
| 307 | printk("%d old rip %lx old rsp %lx old rax %lx\n", current->pid,regs->rip,regs->rsp,regs->rax); |
| 308 | #endif |
| 309 | |
| 310 | /* Set up registers for signal handler */ |
| 311 | { |
| 312 | struct exec_domain *ed = current_thread_info()->exec_domain; |
| 313 | if (unlikely(ed && ed->signal_invmap && sig < 32)) |
| 314 | sig = ed->signal_invmap[sig]; |
| 315 | } |
| 316 | regs->rdi = sig; |
| 317 | /* In case the signal handler was declared without prototypes */ |
| 318 | regs->rax = 0; |
| 319 | |
| 320 | /* This also works for non SA_SIGINFO handlers because they expect the |
| 321 | next argument after the signal number on the stack. */ |
| 322 | regs->rsi = (unsigned long)&frame->info; |
| 323 | regs->rdx = (unsigned long)&frame->uc; |
| 324 | regs->rip = (unsigned long) ka->sa.sa_handler; |
| 325 | |
| 326 | regs->rsp = (unsigned long)frame; |
| 327 | |
Bryan Ford | e4e5d32 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 328 | /* Set up the CS register to run signal handlers in 64-bit mode, |
| 329 | even if the handler happens to be interrupting 32-bit code. */ |
| 330 | regs->cs = __USER_CS; |
| 331 | |
| 332 | /* This, by contrast, has nothing to do with segment registers - |
| 333 | see include/asm-x86_64/uaccess.h for details. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | set_fs(USER_DS); |
Bryan Ford | e4e5d32 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 335 | |
Andi Kleen | be61bff | 2005-04-16 15:24:57 -0700 | [diff] [blame] | 336 | regs->eflags &= ~TF_MASK; |
| 337 | if (test_thread_flag(TIF_SINGLESTEP)) |
| 338 | ptrace_notify(SIGTRAP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | #ifdef DEBUG_SIG |
| 340 | printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n", |
| 341 | current->comm, current->pid, frame, regs->rip, frame->pretcode); |
| 342 | #endif |
| 343 | |
Roland McGrath | 0928d6e | 2005-06-23 00:08:37 -0700 | [diff] [blame] | 344 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
| 346 | give_sigsegv: |
| 347 | force_sigsegv(sig, current); |
Roland McGrath | 0928d6e | 2005-06-23 00:08:37 -0700 | [diff] [blame] | 348 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /* |
| 352 | * OK, we're invoking a handler |
| 353 | */ |
| 354 | |
Roland McGrath | 0928d6e | 2005-06-23 00:08:37 -0700 | [diff] [blame] | 355 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, |
| 357 | sigset_t *oldset, struct pt_regs *regs) |
| 358 | { |
Roland McGrath | 0928d6e | 2005-06-23 00:08:37 -0700 | [diff] [blame] | 359 | int ret; |
| 360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | #ifdef DEBUG_SIG |
| 362 | printk("handle_signal pid:%d sig:%lu rip:%lx rsp:%lx regs=%p\n", |
| 363 | current->pid, sig, |
| 364 | regs->rip, regs->rsp, regs); |
| 365 | #endif |
| 366 | |
| 367 | /* Are we from a system call? */ |
| 368 | if ((long)regs->orig_rax >= 0) { |
| 369 | /* If so, check system call restarting.. */ |
| 370 | switch (regs->rax) { |
| 371 | case -ERESTART_RESTARTBLOCK: |
| 372 | case -ERESTARTNOHAND: |
| 373 | regs->rax = -EINTR; |
| 374 | break; |
| 375 | |
| 376 | case -ERESTARTSYS: |
| 377 | if (!(ka->sa.sa_flags & SA_RESTART)) { |
| 378 | regs->rax = -EINTR; |
| 379 | break; |
| 380 | } |
| 381 | /* fallthrough */ |
| 382 | case -ERESTARTNOINTR: |
| 383 | regs->rax = regs->orig_rax; |
| 384 | regs->rip -= 2; |
| 385 | break; |
| 386 | } |
| 387 | } |
| 388 | |
Andi Kleen | d61915d | 2005-04-16 15:25:00 -0700 | [diff] [blame] | 389 | /* |
| 390 | * If TF is set due to a debugger (PT_DTRACE), clear the TF |
| 391 | * flag so that register information in the sigcontext is |
| 392 | * correct. |
| 393 | */ |
| 394 | if (unlikely(regs->eflags & TF_MASK)) { |
| 395 | if (likely(current->ptrace & PT_DTRACE)) { |
| 396 | current->ptrace &= ~PT_DTRACE; |
| 397 | regs->eflags &= ~TF_MASK; |
| 398 | } |
| 399 | } |
| 400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | #ifdef CONFIG_IA32_EMULATION |
| 402 | if (test_thread_flag(TIF_IA32)) { |
| 403 | if (ka->sa.sa_flags & SA_SIGINFO) |
Roland McGrath | 0928d6e | 2005-06-23 00:08:37 -0700 | [diff] [blame] | 404 | ret = ia32_setup_rt_frame(sig, ka, info, oldset, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | else |
Roland McGrath | 0928d6e | 2005-06-23 00:08:37 -0700 | [diff] [blame] | 406 | ret = ia32_setup_frame(sig, ka, oldset, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | } else |
| 408 | #endif |
Roland McGrath | 0928d6e | 2005-06-23 00:08:37 -0700 | [diff] [blame] | 409 | ret = setup_rt_frame(sig, ka, info, oldset, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
Steven Rostedt | 69be8f1 | 2005-08-29 11:44:09 -0400 | [diff] [blame] | 411 | if (ret) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | spin_lock_irq(¤t->sighand->siglock); |
| 413 | sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask); |
Steven Rostedt | 69be8f1 | 2005-08-29 11:44:09 -0400 | [diff] [blame] | 414 | if (!(ka->sa.sa_flags & SA_NODEFER)) |
| 415 | sigaddset(¤t->blocked,sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | recalc_sigpending(); |
| 417 | spin_unlock_irq(¤t->sighand->siglock); |
| 418 | } |
Roland McGrath | 0928d6e | 2005-06-23 00:08:37 -0700 | [diff] [blame] | 419 | |
| 420 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | /* |
| 424 | * Note that 'init' is a special process: it doesn't get signals it doesn't |
| 425 | * want to handle. Thus you cannot kill init even with a SIGKILL even by |
| 426 | * mistake. |
| 427 | */ |
| 428 | int do_signal(struct pt_regs *regs, sigset_t *oldset) |
| 429 | { |
| 430 | struct k_sigaction ka; |
| 431 | siginfo_t info; |
| 432 | int signr; |
| 433 | |
| 434 | /* |
| 435 | * We want the common case to go fast, which |
| 436 | * is why we may in certain cases get here from |
| 437 | * kernel mode. Just return without doing anything |
| 438 | * if so. |
| 439 | */ |
Vincent Hanquez | 76381fe | 2005-06-23 00:08:46 -0700 | [diff] [blame] | 440 | if (!user_mode(regs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | return 1; |
| 442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | if (!oldset) |
| 444 | oldset = ¤t->blocked; |
| 445 | |
| 446 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); |
| 447 | if (signr > 0) { |
| 448 | /* Reenable any watchpoints before delivering the |
| 449 | * signal to user space. The processor register will |
| 450 | * have been cleared if the watchpoint triggered |
| 451 | * inside the kernel. |
| 452 | */ |
| 453 | if (current->thread.debugreg7) |
Vincent Hanquez | e9129e5 | 2005-06-23 00:08:46 -0700 | [diff] [blame] | 454 | set_debugreg(current->thread.debugreg7, 7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
| 456 | /* Whee! Actually deliver the signal. */ |
Roland McGrath | 0928d6e | 2005-06-23 00:08:37 -0700 | [diff] [blame] | 457 | return handle_signal(signr, &info, &ka, oldset, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | /* Did we come from a system call? */ |
| 461 | if ((long)regs->orig_rax >= 0) { |
| 462 | /* Restart the system call - no handlers present */ |
| 463 | long res = regs->rax; |
| 464 | if (res == -ERESTARTNOHAND || |
| 465 | res == -ERESTARTSYS || |
| 466 | res == -ERESTARTNOINTR) { |
| 467 | regs->rax = regs->orig_rax; |
| 468 | regs->rip -= 2; |
| 469 | } |
| 470 | if (regs->rax == (unsigned long)-ERESTART_RESTARTBLOCK) { |
Andi Kleen | 607a168 | 2005-05-20 14:27:58 -0700 | [diff] [blame] | 471 | regs->rax = test_thread_flag(TIF_IA32) ? |
| 472 | __NR_ia32_restart_syscall : |
| 473 | __NR_restart_syscall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | regs->rip -= 2; |
| 475 | } |
| 476 | } |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | void do_notify_resume(struct pt_regs *regs, sigset_t *oldset, __u32 thread_info_flags) |
| 481 | { |
| 482 | #ifdef DEBUG_SIG |
| 483 | printk("do_notify_resume flags:%x rip:%lx rsp:%lx caller:%lx pending:%lx\n", |
| 484 | thread_info_flags, regs->rip, regs->rsp, __builtin_return_address(0),signal_pending(current)); |
| 485 | #endif |
| 486 | |
| 487 | /* Pending single-step? */ |
| 488 | if (thread_info_flags & _TIF_SINGLESTEP) { |
| 489 | regs->eflags |= TF_MASK; |
| 490 | clear_thread_flag(TIF_SINGLESTEP); |
| 491 | } |
| 492 | |
| 493 | /* deal with pending signal delivery */ |
| 494 | if (thread_info_flags & _TIF_SIGPENDING) |
| 495 | do_signal(regs,oldset); |
| 496 | } |
| 497 | |
| 498 | void signal_fault(struct pt_regs *regs, void __user *frame, char *where) |
| 499 | { |
| 500 | struct task_struct *me = current; |
| 501 | if (exception_trace) |
| 502 | printk("%s[%d] bad frame in %s frame:%p rip:%lx rsp:%lx orax:%lx\n", |
| 503 | me->comm,me->pid,where,frame,regs->rip,regs->rsp,regs->orig_rax); |
| 504 | |
| 505 | force_sig(SIGSEGV, me); |
| 506 | } |