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