Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/x86_64/ia32/ia32_signal.c |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | * |
| 6 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson |
| 7 | * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes |
| 8 | * 2000-12-* x86-64 compatibility mode signal handling by Andi Kleen |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/sched.h> |
| 12 | #include <linux/mm.h> |
| 13 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/kernel.h> |
| 15 | #include <linux/signal.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/wait.h> |
| 18 | #include <linux/ptrace.h> |
| 19 | #include <linux/unistd.h> |
| 20 | #include <linux/stddef.h> |
| 21 | #include <linux/personality.h> |
| 22 | #include <linux/compat.h> |
Andi Kleen | 9fbbd4d | 2007-02-13 13:26:26 +0100 | [diff] [blame] | 23 | #include <linux/binfmts.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/ucontext.h> |
| 25 | #include <asm/uaccess.h> |
| 26 | #include <asm/i387.h> |
| 27 | #include <asm/ia32.h> |
| 28 | #include <asm/ptrace.h> |
| 29 | #include <asm/ia32_unistd.h> |
| 30 | #include <asm/user32.h> |
| 31 | #include <asm/sigcontext32.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/proto.h> |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 33 | #include <asm/vdso.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | #define DEBUG_SIG 0 |
| 36 | |
| 37 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) |
| 38 | |
Hiroshi Shimamoto | fbdb7da | 2008-07-14 15:34:09 -0700 | [diff] [blame] | 39 | #define FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \ |
| 40 | X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \ |
| 41 | X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \ |
| 42 | X86_EFLAGS_CF) |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | asmlinkage int do_signal(struct pt_regs *regs, sigset_t *oldset); |
| 45 | void signal_fault(struct pt_regs *regs, void __user *frame, char *where); |
| 46 | |
| 47 | int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from) |
| 48 | { |
| 49 | int err; |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 50 | |
| 51 | if (!access_ok(VERIFY_WRITE, to, sizeof(compat_siginfo_t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | return -EFAULT; |
| 53 | |
| 54 | /* If you change siginfo_t structure, please make sure that |
| 55 | this code is fixed accordingly. |
| 56 | It should never copy any pad contained in the structure |
| 57 | to avoid security leaks, but must copy the generic |
| 58 | 3 ints plus the relevant union member. */ |
| 59 | err = __put_user(from->si_signo, &to->si_signo); |
| 60 | err |= __put_user(from->si_errno, &to->si_errno); |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 61 | err |= __put_user((short)from->si_code, &to->si_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
| 63 | if (from->si_code < 0) { |
| 64 | err |= __put_user(from->si_pid, &to->si_pid); |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 65 | err |= __put_user(from->si_uid, &to->si_uid); |
| 66 | err |= __put_user(ptr_to_compat(from->si_ptr), &to->si_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | } else { |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 68 | /* |
| 69 | * First 32bits of unions are always present: |
| 70 | * si_pid === si_band === si_tid === si_addr(LS half) |
| 71 | */ |
| 72 | err |= __put_user(from->_sifields._pad[0], |
| 73 | &to->_sifields._pad[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | switch (from->si_code >> 16) { |
| 75 | case __SI_FAULT >> 16: |
| 76 | break; |
| 77 | case __SI_CHLD >> 16: |
| 78 | err |= __put_user(from->si_utime, &to->si_utime); |
| 79 | err |= __put_user(from->si_stime, &to->si_stime); |
| 80 | err |= __put_user(from->si_status, &to->si_status); |
| 81 | /* FALL THROUGH */ |
| 82 | default: |
| 83 | case __SI_KILL >> 16: |
| 84 | err |= __put_user(from->si_uid, &to->si_uid); |
| 85 | break; |
| 86 | case __SI_POLL >> 16: |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 87 | err |= __put_user(from->si_fd, &to->si_fd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | break; |
| 89 | case __SI_TIMER >> 16: |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 90 | err |= __put_user(from->si_overrun, &to->si_overrun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | err |= __put_user(ptr_to_compat(from->si_ptr), |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 92 | &to->si_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | break; |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 94 | /* This is not generated by the kernel as of now. */ |
| 95 | case __SI_RT >> 16: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | case __SI_MESGQ >> 16: |
| 97 | err |= __put_user(from->si_uid, &to->si_uid); |
| 98 | err |= __put_user(from->si_int, &to->si_int); |
| 99 | break; |
| 100 | } |
| 101 | } |
| 102 | return err; |
| 103 | } |
| 104 | |
| 105 | int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from) |
| 106 | { |
| 107 | int err; |
| 108 | u32 ptr32; |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 109 | |
| 110 | if (!access_ok(VERIFY_READ, from, sizeof(compat_siginfo_t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | return -EFAULT; |
| 112 | |
| 113 | err = __get_user(to->si_signo, &from->si_signo); |
| 114 | err |= __get_user(to->si_errno, &from->si_errno); |
| 115 | err |= __get_user(to->si_code, &from->si_code); |
| 116 | |
| 117 | err |= __get_user(to->si_pid, &from->si_pid); |
| 118 | err |= __get_user(to->si_uid, &from->si_uid); |
| 119 | err |= __get_user(ptr32, &from->si_ptr); |
| 120 | to->si_ptr = compat_ptr(ptr32); |
| 121 | |
| 122 | return err; |
| 123 | } |
| 124 | |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 125 | asmlinkage long sys32_sigsuspend(int history0, int history1, old_sigset_t mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | mask &= _BLOCKABLE; |
| 128 | spin_lock_irq(¤t->sighand->siglock); |
Andi Kleen | 1d001df | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 129 | current->saved_sigmask = current->blocked; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | siginitset(¤t->blocked, mask); |
| 131 | recalc_sigpending(); |
| 132 | spin_unlock_irq(¤t->sighand->siglock); |
| 133 | |
Andi Kleen | 1d001df | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 134 | current->state = TASK_INTERRUPTIBLE; |
| 135 | schedule(); |
Roland McGrath | 5a8da0e | 2008-04-30 00:53:10 -0700 | [diff] [blame] | 136 | set_restore_sigmask(); |
Andi Kleen | 1d001df | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 137 | return -ERESTARTNOHAND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 140 | asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr, |
| 141 | stack_ia32_t __user *uoss_ptr, |
| 142 | struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | { |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 144 | stack_t uss, uoss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | int ret; |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 146 | mm_segment_t seg; |
| 147 | |
| 148 | if (uss_ptr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | u32 ptr; |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 150 | |
| 151 | memset(&uss, 0, sizeof(stack_t)); |
| 152 | if (!access_ok(VERIFY_READ, uss_ptr, sizeof(stack_ia32_t)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | __get_user(ptr, &uss_ptr->ss_sp) || |
| 154 | __get_user(uss.ss_flags, &uss_ptr->ss_flags) || |
| 155 | __get_user(uss.ss_size, &uss_ptr->ss_size)) |
| 156 | return -EFAULT; |
| 157 | uss.ss_sp = compat_ptr(ptr); |
| 158 | } |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 159 | seg = get_fs(); |
| 160 | set_fs(KERNEL_DS); |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 161 | ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp); |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 162 | set_fs(seg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | if (ret >= 0 && uoss_ptr) { |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 164 | if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | __put_user(ptr_to_compat(uoss.ss_sp), &uoss_ptr->ss_sp) || |
| 166 | __put_user(uoss.ss_flags, &uoss_ptr->ss_flags) || |
| 167 | __put_user(uoss.ss_size, &uoss_ptr->ss_size)) |
| 168 | ret = -EFAULT; |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 169 | } |
| 170 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /* |
| 174 | * Do a signal return; undo the signal stack. |
| 175 | */ |
| 176 | |
| 177 | struct sigframe |
| 178 | { |
| 179 | u32 pretcode; |
| 180 | int sig; |
| 181 | struct sigcontext_ia32 sc; |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 182 | struct _fpstate_ia32 fpstate_unused; /* look at kernel/sigframe.h */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | unsigned int extramask[_COMPAT_NSIG_WORDS-1]; |
| 184 | char retcode[8]; |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 185 | /* fp state follows here */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | }; |
| 187 | |
| 188 | struct rt_sigframe |
| 189 | { |
| 190 | u32 pretcode; |
| 191 | int sig; |
| 192 | u32 pinfo; |
| 193 | u32 puc; |
| 194 | compat_siginfo_t info; |
| 195 | struct ucontext_ia32 uc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | char retcode[8]; |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 197 | /* fp state follows here */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | }; |
| 199 | |
Hiroshi Shimamoto | b78a5b5 | 2008-11-17 15:44:50 -0800 | [diff] [blame] | 200 | #define COPY(x) { \ |
| 201 | err |= __get_user(regs->x, &sc->x); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Hiroshi Shimamoto | d71a68d | 2008-11-17 15:47:06 -0800 | [diff] [blame^] | 204 | #define COPY_SEG_CPL3(seg) { \ |
| 205 | unsigned short tmp; \ |
| 206 | err |= __get_user(tmp, &sc->seg); \ |
| 207 | regs->seg = tmp | 3; \ |
| 208 | } |
| 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | #define RELOAD_SEG(seg,mask) \ |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 211 | { unsigned int cur; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | unsigned short pre; \ |
| 213 | err |= __get_user(pre, &sc->seg); \ |
Jeremy Fitzhardinge | b6edbb1 | 2008-08-19 13:04:19 -0700 | [diff] [blame] | 214 | savesegment(seg, cur); \ |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 215 | pre |= mask; \ |
| 216 | if (pre != cur) loadsegment(seg, pre); } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 218 | static int ia32_restore_sigcontext(struct pt_regs *regs, |
| 219 | struct sigcontext_ia32 __user *sc, |
| 220 | unsigned int *peax) |
| 221 | { |
| 222 | unsigned int tmpflags, gs, oldgs, err = 0; |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 223 | void __user *buf; |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 224 | u32 tmp; |
| 225 | |
| 226 | /* Always make any pending restarted system calls return -EINTR */ |
| 227 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
| 228 | |
| 229 | #if DEBUG_SIG |
| 230 | printk(KERN_DEBUG "SIG restore_sigcontext: " |
| 231 | "sc=%p err(%x) eip(%x) cs(%x) flg(%x)\n", |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 232 | sc, sc->err, sc->ip, sc->cs, sc->flags); |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 233 | #endif |
| 234 | |
| 235 | /* |
| 236 | * Reload fs and gs if they have changed in the signal |
| 237 | * handler. This does not handle long fs/gs base changes in |
| 238 | * the handler, but does not clobber them at least in the |
| 239 | * normal case. |
| 240 | */ |
| 241 | err |= __get_user(gs, &sc->gs); |
| 242 | gs |= 3; |
Jeremy Fitzhardinge | b6edbb1 | 2008-08-19 13:04:19 -0700 | [diff] [blame] | 243 | savesegment(gs, oldgs); |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 244 | if (gs != oldgs) |
| 245 | load_gs_index(gs); |
| 246 | |
| 247 | RELOAD_SEG(fs, 3); |
| 248 | RELOAD_SEG(ds, 3); |
| 249 | RELOAD_SEG(es, 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx); |
| 252 | COPY(dx); COPY(cx); COPY(ip); |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 253 | /* Don't touch extended registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Hiroshi Shimamoto | d71a68d | 2008-11-17 15:47:06 -0800 | [diff] [blame^] | 255 | COPY_SEG_CPL3(cs); |
| 256 | COPY_SEG_CPL3(ss); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
H. Peter Anvin | 742fa54 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 258 | err |= __get_user(tmpflags, &sc->flags); |
Hiroshi Shimamoto | fbdb7da | 2008-07-14 15:34:09 -0700 | [diff] [blame] | 259 | regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS); |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 260 | /* disable syscall checks */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 261 | regs->orig_ax = -1; |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 262 | |
| 263 | err |= __get_user(tmp, &sc->fpstate); |
| 264 | buf = compat_ptr(tmp); |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 265 | err |= restore_i387_xstate_ia32(buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
H. Peter Anvin | 742fa54 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 267 | err |= __get_user(tmp, &sc->ax); |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 268 | *peax = tmp; |
| 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | asmlinkage long sys32_sigreturn(struct pt_regs *regs) |
| 274 | { |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 275 | struct sigframe __user *frame = (struct sigframe __user *)(regs->sp-8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | sigset_t set; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 277 | unsigned int ax; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
| 279 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 280 | goto badframe; |
| 281 | if (__get_user(set.sig[0], &frame->sc.oldmask) |
| 282 | || (_COMPAT_NSIG_WORDS > 1 |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 283 | && __copy_from_user((((char *) &set.sig) + 4), |
| 284 | &frame->extramask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | sizeof(frame->extramask)))) |
| 286 | goto badframe; |
| 287 | |
| 288 | sigdelsetmask(&set, ~_BLOCKABLE); |
| 289 | spin_lock_irq(¤t->sighand->siglock); |
| 290 | current->blocked = set; |
| 291 | recalc_sigpending(); |
| 292 | spin_unlock_irq(¤t->sighand->siglock); |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 293 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 294 | if (ia32_restore_sigcontext(regs, &frame->sc, &ax)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | goto badframe; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 296 | return ax; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
| 298 | badframe: |
| 299 | signal_fault(regs, frame, "32bit sigreturn"); |
| 300 | return 0; |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 301 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
| 303 | asmlinkage long sys32_rt_sigreturn(struct pt_regs *regs) |
| 304 | { |
| 305 | struct rt_sigframe __user *frame; |
| 306 | sigset_t set; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 307 | unsigned int ax; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | struct pt_regs tregs; |
| 309 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 310 | frame = (struct rt_sigframe __user *)(regs->sp - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
| 312 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 313 | goto badframe; |
| 314 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) |
| 315 | goto badframe; |
| 316 | |
| 317 | sigdelsetmask(&set, ~_BLOCKABLE); |
| 318 | spin_lock_irq(¤t->sighand->siglock); |
| 319 | current->blocked = set; |
| 320 | recalc_sigpending(); |
| 321 | spin_unlock_irq(¤t->sighand->siglock); |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 322 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 323 | if (ia32_restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | goto badframe; |
| 325 | |
| 326 | tregs = *regs; |
| 327 | if (sys32_sigaltstack(&frame->uc.uc_stack, NULL, &tregs) == -EFAULT) |
| 328 | goto badframe; |
| 329 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 330 | return ax; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
| 332 | badframe: |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 333 | signal_fault(regs, frame, "32bit rt sigreturn"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | return 0; |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 335 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
| 337 | /* |
| 338 | * Set up a signal frame. |
| 339 | */ |
| 340 | |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 341 | static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc, |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 342 | void __user *fpstate, |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 343 | struct pt_regs *regs, unsigned int mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | { |
| 345 | int tmp, err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Jeremy Fitzhardinge | b6edbb1 | 2008-08-19 13:04:19 -0700 | [diff] [blame] | 347 | savesegment(gs, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | err |= __put_user(tmp, (unsigned int __user *)&sc->gs); |
Jeremy Fitzhardinge | b6edbb1 | 2008-08-19 13:04:19 -0700 | [diff] [blame] | 349 | savesegment(fs, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | err |= __put_user(tmp, (unsigned int __user *)&sc->fs); |
Jeremy Fitzhardinge | b6edbb1 | 2008-08-19 13:04:19 -0700 | [diff] [blame] | 351 | savesegment(ds, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | err |= __put_user(tmp, (unsigned int __user *)&sc->ds); |
Jeremy Fitzhardinge | b6edbb1 | 2008-08-19 13:04:19 -0700 | [diff] [blame] | 353 | savesegment(es, tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | err |= __put_user(tmp, (unsigned int __user *)&sc->es); |
| 355 | |
Hiroshi Shimamoto | bff0aa4 | 2008-09-30 20:28:20 -0700 | [diff] [blame] | 356 | err |= __put_user(regs->di, &sc->di); |
| 357 | err |= __put_user(regs->si, &sc->si); |
| 358 | err |= __put_user(regs->bp, &sc->bp); |
| 359 | err |= __put_user(regs->sp, &sc->sp); |
| 360 | err |= __put_user(regs->bx, &sc->bx); |
| 361 | err |= __put_user(regs->dx, &sc->dx); |
| 362 | err |= __put_user(regs->cx, &sc->cx); |
| 363 | err |= __put_user(regs->ax, &sc->ax); |
| 364 | err |= __put_user(regs->cs, &sc->cs); |
| 365 | err |= __put_user(regs->ss, &sc->ss); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | err |= __put_user(current->thread.trap_no, &sc->trapno); |
| 367 | err |= __put_user(current->thread.error_code, &sc->err); |
Hiroshi Shimamoto | bff0aa4 | 2008-09-30 20:28:20 -0700 | [diff] [blame] | 368 | err |= __put_user(regs->ip, &sc->ip); |
| 369 | err |= __put_user(regs->flags, &sc->flags); |
| 370 | err |= __put_user(regs->sp, &sc->sp_at_signal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Hiroshi Shimamoto | 99ea1b93 | 2008-11-05 18:32:54 -0800 | [diff] [blame] | 372 | err |= __put_user(ptr_to_compat(fpstate), &sc->fpstate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
| 374 | /* non-iBCS2 extensions.. */ |
| 375 | err |= __put_user(mask, &sc->oldmask); |
| 376 | err |= __put_user(current->thread.cr2, &sc->cr2); |
| 377 | |
| 378 | return err; |
| 379 | } |
| 380 | |
| 381 | /* |
| 382 | * Determine which stack to use.. |
| 383 | */ |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 384 | static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 385 | size_t frame_size, |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 386 | void **fpstate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | { |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 388 | unsigned long sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
| 390 | /* Default to using normal stack */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 391 | sp = regs->sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
| 393 | /* This is the X/Open sanctioned signal stack switching. */ |
| 394 | if (ka->sa.sa_flags & SA_ONSTACK) { |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 395 | if (sas_ss_flags(sp) == 0) |
| 396 | sp = current->sas_ss_sp + current->sas_ss_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | /* This is the legacy signal stack switching. */ |
| 400 | else if ((regs->ss & 0xffff) != __USER_DS && |
| 401 | !(ka->sa.sa_flags & SA_RESTORER) && |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 402 | ka->sa.sa_restorer) |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 403 | sp = (unsigned long) ka->sa.sa_restorer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 405 | if (used_math()) { |
| 406 | sp = sp - sig_xstate_ia32_size; |
| 407 | *fpstate = (struct _fpstate_ia32 *) sp; |
Hiroshi Shimamoto | 99ea1b93 | 2008-11-05 18:32:54 -0800 | [diff] [blame] | 408 | if (save_i387_xstate_ia32(*fpstate) < 0) |
| 409 | return (void __user *) -1L; |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 410 | } |
| 411 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 412 | sp -= frame_size; |
Markus F.X.J. Oberhumer | d347f37 | 2005-10-09 18:54:23 +0200 | [diff] [blame] | 413 | /* Align the stack pointer according to the i386 ABI, |
| 414 | * i.e. so that on function entry ((sp + 4) & 15) == 0. */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 415 | sp = ((sp + 4) & -16ul) - 4; |
| 416 | return (void __user *) sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Roland McGrath | 0928d6e | 2005-06-23 00:08:37 -0700 | [diff] [blame] | 419 | int ia32_setup_frame(int sig, struct k_sigaction *ka, |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 420 | compat_sigset_t *set, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | { |
| 422 | struct sigframe __user *frame; |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 423 | void __user *restorer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | int err = 0; |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 425 | void __user *fpstate = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 427 | /* copy_to_user optimizes that into a single 8 byte store */ |
| 428 | static const struct { |
| 429 | u16 poplmovl; |
| 430 | u32 val; |
| 431 | u16 int80; |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 432 | } __attribute__((packed)) code = { |
| 433 | 0xb858, /* popl %eax ; movl $...,%eax */ |
| 434 | __NR_ia32_sigreturn, |
| 435 | 0x80cd, /* int $0x80 */ |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 436 | }; |
| 437 | |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 438 | frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
| 440 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 441 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
Hiroshi Shimamoto | 2ba48e1 | 2008-09-12 17:02:53 -0700 | [diff] [blame] | 443 | if (__put_user(sig, &frame->sig)) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 444 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Hiroshi Shimamoto | 2ba48e1 | 2008-09-12 17:02:53 -0700 | [diff] [blame] | 446 | if (ia32_setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0])) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 447 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
| 449 | if (_COMPAT_NSIG_WORDS > 1) { |
Hiroshi Shimamoto | 2ba48e1 | 2008-09-12 17:02:53 -0700 | [diff] [blame] | 450 | if (__copy_to_user(frame->extramask, &set->sig[1], |
| 451 | sizeof(frame->extramask))) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 452 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 455 | if (ka->sa.sa_flags & SA_RESTORER) { |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 456 | restorer = ka->sa.sa_restorer; |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 457 | } else { |
| 458 | /* Return stub is in 32bit vsyscall page */ |
Roland McGrath | 1a3e4ca | 2008-04-09 01:29:27 -0700 | [diff] [blame] | 459 | if (current->mm->context.vdso) |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 460 | restorer = VDSO32_SYMBOL(current->mm->context.vdso, |
| 461 | sigreturn); |
| 462 | else |
Jan Engelhardt | ade1af7 | 2008-01-30 13:33:23 +0100 | [diff] [blame] | 463 | restorer = &frame->retcode; |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 464 | } |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 465 | err |= __put_user(ptr_to_compat(restorer), &frame->pretcode); |
| 466 | |
| 467 | /* |
| 468 | * These are actually not used anymore, but left because some |
| 469 | * gdb versions depend on them as a marker. |
| 470 | */ |
| 471 | err |= __copy_to_user(frame->retcode, &code, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | if (err) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 473 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
| 475 | /* Set up registers for signal handler */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 476 | regs->sp = (unsigned long) frame; |
| 477 | regs->ip = (unsigned long) ka->sa.sa_handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Andi Kleen | 536e3ee | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 479 | /* Make -mregparm=3 work */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 480 | regs->ax = sig; |
| 481 | regs->dx = 0; |
| 482 | regs->cx = 0; |
Andi Kleen | 536e3ee | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 483 | |
Jeremy Fitzhardinge | b6edbb1 | 2008-08-19 13:04:19 -0700 | [diff] [blame] | 484 | loadsegment(ds, __USER32_DS); |
| 485 | loadsegment(es, __USER32_DS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 487 | regs->cs = __USER32_CS; |
| 488 | regs->ss = __USER32_DS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | #if DEBUG_SIG |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 491 | printk(KERN_DEBUG "SIG deliver (%s:%d): sp=%p pc=%lx ra=%u\n", |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 492 | current->comm, current->pid, frame, regs->ip, frame->pretcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | #endif |
| 494 | |
Andi Kleen | 1d001df | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 495 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Roland McGrath | 0928d6e | 2005-06-23 00:08:37 -0700 | [diff] [blame] | 498 | int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 499 | compat_sigset_t *set, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | { |
| 501 | struct rt_sigframe __user *frame; |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 502 | void __user *restorer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | int err = 0; |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 504 | void __user *fpstate = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 506 | /* __copy_to_user optimizes that into a single 8 byte store */ |
| 507 | static const struct { |
| 508 | u8 movl; |
| 509 | u32 val; |
| 510 | u16 int80; |
Hiroshi Shimamoto | 9cc3c49 | 2008-11-11 19:11:39 -0800 | [diff] [blame] | 511 | u8 pad; |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 512 | } __attribute__((packed)) code = { |
| 513 | 0xb8, |
| 514 | __NR_ia32_rt_sigreturn, |
| 515 | 0x80cd, |
| 516 | 0, |
| 517 | }; |
| 518 | |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 519 | frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
| 521 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 522 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | |
Hiroshi Shimamoto | 812b121 | 2008-07-16 19:21:31 -0700 | [diff] [blame] | 524 | err |= __put_user(sig, &frame->sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | err |= __put_user(ptr_to_compat(&frame->info), &frame->pinfo); |
| 526 | err |= __put_user(ptr_to_compat(&frame->uc), &frame->puc); |
| 527 | err |= copy_siginfo_to_user32(&frame->info, info); |
| 528 | if (err) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 529 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
| 531 | /* Create the ucontext. */ |
Suresh Siddha | c37b5ef | 2008-07-29 10:29:25 -0700 | [diff] [blame] | 532 | if (cpu_has_xsave) |
| 533 | err |= __put_user(UC_FP_XSTATE, &frame->uc.uc_flags); |
| 534 | else |
| 535 | err |= __put_user(0, &frame->uc.uc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | err |= __put_user(0, &frame->uc.uc_link); |
| 537 | err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 538 | err |= __put_user(sas_ss_flags(regs->sp), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | &frame->uc.uc_stack.ss_flags); |
| 540 | err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 541 | err |= ia32_setup_sigcontext(&frame->uc.uc_mcontext, fpstate, |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 542 | regs, set->sig[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); |
| 544 | if (err) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 545 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 547 | if (ka->sa.sa_flags & SA_RESTORER) |
| 548 | restorer = ka->sa.sa_restorer; |
Roland McGrath | af65d64 | 2008-01-30 13:30:43 +0100 | [diff] [blame] | 549 | else |
| 550 | restorer = VDSO32_SYMBOL(current->mm->context.vdso, |
| 551 | rt_sigreturn); |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 552 | err |= __put_user(ptr_to_compat(restorer), &frame->pretcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 554 | /* |
| 555 | * Not actually used anymore, but left because some gdb |
| 556 | * versions need it. |
| 557 | */ |
| 558 | err |= __copy_to_user(frame->retcode, &code, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | if (err) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 560 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
| 562 | /* Set up registers for signal handler */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 563 | regs->sp = (unsigned long) frame; |
| 564 | regs->ip = (unsigned long) ka->sa.sa_handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
Albert Cahalan | a7aacdf | 2006-10-29 22:26:17 -0500 | [diff] [blame] | 566 | /* Make -mregparm=3 work */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 567 | regs->ax = sig; |
| 568 | regs->dx = (unsigned long) &frame->info; |
| 569 | regs->cx = (unsigned long) &frame->uc; |
Albert Cahalan | a7aacdf | 2006-10-29 22:26:17 -0500 | [diff] [blame] | 570 | |
Albert Cahalan | 8e3de53 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 571 | /* Make -mregparm=3 work */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 572 | regs->ax = sig; |
| 573 | regs->dx = (unsigned long) &frame->info; |
| 574 | regs->cx = (unsigned long) &frame->uc; |
Albert Cahalan | 8e3de53 | 2006-12-07 02:14:06 +0100 | [diff] [blame] | 575 | |
Jeremy Fitzhardinge | b6edbb1 | 2008-08-19 13:04:19 -0700 | [diff] [blame] | 576 | loadsegment(ds, __USER32_DS); |
| 577 | loadsegment(es, __USER32_DS); |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 578 | |
| 579 | regs->cs = __USER32_CS; |
| 580 | regs->ss = __USER32_DS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | #if DEBUG_SIG |
Thomas Gleixner | 99b9cdf | 2008-01-30 13:30:07 +0100 | [diff] [blame] | 583 | printk(KERN_DEBUG "SIG deliver (%s:%d): sp=%p pc=%lx ra=%u\n", |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 584 | current->comm, current->pid, frame, regs->ip, frame->pretcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | #endif |
| 586 | |
Andi Kleen | 1d001df | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 587 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | } |