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