Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 2 | * Copyright (C) 2004 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include "linux/ptrace.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include "asm/unistd.h" |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 8 | #include "asm/uaccess.h" |
| 9 | #include "asm/ucontext.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include "frame_kern.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include "skas.h" |
| 12 | |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 13 | void copy_sc(struct uml_pt_regs *regs, void *from) |
Jeff Dike | 377fad3 | 2007-05-06 14:51:25 -0700 | [diff] [blame] | 14 | { |
| 15 | struct sigcontext *sc = from; |
| 16 | |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 17 | REGS_GS(regs->regs) = sc->gs; |
| 18 | REGS_FS(regs->regs) = sc->fs; |
| 19 | REGS_ES(regs->regs) = sc->es; |
| 20 | REGS_DS(regs->regs) = sc->ds; |
| 21 | REGS_EDI(regs->regs) = sc->edi; |
| 22 | REGS_ESI(regs->regs) = sc->esi; |
| 23 | REGS_EBP(regs->regs) = sc->ebp; |
| 24 | REGS_SP(regs->regs) = sc->esp; |
| 25 | REGS_EBX(regs->regs) = sc->ebx; |
| 26 | REGS_EDX(regs->regs) = sc->edx; |
| 27 | REGS_ECX(regs->regs) = sc->ecx; |
| 28 | REGS_EAX(regs->regs) = sc->eax; |
| 29 | REGS_IP(regs->regs) = sc->eip; |
| 30 | REGS_CS(regs->regs) = sc->cs; |
| 31 | REGS_EFLAGS(regs->regs) = sc->eflags; |
| 32 | REGS_SS(regs->regs) = sc->ss; |
Jeff Dike | 377fad3 | 2007-05-06 14:51:25 -0700 | [diff] [blame] | 33 | } |
| 34 | |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 35 | static int copy_sc_from_user(struct pt_regs *regs, |
| 36 | struct sigcontext __user *from) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 38 | struct sigcontext sc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | unsigned long fpregs[HOST_FP_SIZE]; |
| 40 | int err; |
| 41 | |
| 42 | err = copy_from_user(&sc, from, sizeof(sc)); |
| 43 | err |= copy_from_user(fpregs, sc.fpstate, sizeof(fpregs)); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 44 | if (err) |
Jeff Dike | 5d86456 | 2007-05-06 14:51:24 -0700 | [diff] [blame] | 45 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Jeff Dike | 377fad3 | 2007-05-06 14:51:25 -0700 | [diff] [blame] | 47 | copy_sc(®s->regs, &sc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | err = restore_fp_registers(userspace_pid[0], fpregs); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 50 | if (err < 0) { |
| 51 | printk(KERN_ERR "copy_sc_from_user_skas - PTRACE_SETFPREGS " |
| 52 | "failed, errno = %d\n", -err); |
Jeff Dike | 5d86456 | 2007-05-06 14:51:24 -0700 | [diff] [blame] | 53 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Jeff Dike | 5d86456 | 2007-05-06 14:51:24 -0700 | [diff] [blame] | 56 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 59 | static int copy_sc_to_user(struct sigcontext __user *to, |
| 60 | struct _fpstate __user *to_fp, struct pt_regs *regs, |
| 61 | unsigned long sp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 63 | struct sigcontext sc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | unsigned long fpregs[HOST_FP_SIZE]; |
Bodo Stroesser | c578455 | 2005-05-05 16:15:31 -0700 | [diff] [blame] | 65 | struct faultinfo * fi = ¤t->thread.arch.faultinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | int err; |
| 67 | |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 68 | sc.gs = REGS_GS(regs->regs.regs); |
| 69 | sc.fs = REGS_FS(regs->regs.regs); |
| 70 | sc.es = REGS_ES(regs->regs.regs); |
| 71 | sc.ds = REGS_DS(regs->regs.regs); |
| 72 | sc.edi = REGS_EDI(regs->regs.regs); |
| 73 | sc.esi = REGS_ESI(regs->regs.regs); |
| 74 | sc.ebp = REGS_EBP(regs->regs.regs); |
Jeff Dike | 98c1823 | 2006-03-27 01:14:38 -0800 | [diff] [blame] | 75 | sc.esp = sp; |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 76 | sc.ebx = REGS_EBX(regs->regs.regs); |
| 77 | sc.edx = REGS_EDX(regs->regs.regs); |
| 78 | sc.ecx = REGS_ECX(regs->regs.regs); |
| 79 | sc.eax = REGS_EAX(regs->regs.regs); |
| 80 | sc.eip = REGS_IP(regs->regs.regs); |
| 81 | sc.cs = REGS_CS(regs->regs.regs); |
| 82 | sc.eflags = REGS_EFLAGS(regs->regs.regs); |
| 83 | sc.esp_at_signal = regs->regs.regs[UESP]; |
| 84 | sc.ss = regs->regs.regs[SS]; |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 85 | sc.cr2 = fi->cr2; |
| 86 | sc.err = fi->error_code; |
| 87 | sc.trapno = fi->trap_no; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | err = save_fp_registers(userspace_pid[0], fpregs); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 90 | if (err < 0) { |
| 91 | printk(KERN_ERR "copy_sc_to_user_skas - PTRACE_GETFPREGS " |
| 92 | "failed, errno = %d\n", err); |
Jeff Dike | 5d86456 | 2007-05-06 14:51:24 -0700 | [diff] [blame] | 93 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 95 | to_fp = (to_fp ? to_fp : (struct _fpstate __user *) (to + 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | sc.fpstate = to_fp; |
| 97 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 98 | if (err) |
Jeff Dike | 5d86456 | 2007-05-06 14:51:24 -0700 | [diff] [blame] | 99 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Jeff Dike | 5d86456 | 2007-05-06 14:51:24 -0700 | [diff] [blame] | 101 | return copy_to_user(to, &sc, sizeof(sc)) || |
| 102 | copy_to_user(to_fp, fpregs, sizeof(fpregs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 105 | static int copy_ucontext_to_user(struct ucontext __user *uc, |
| 106 | struct _fpstate __user *fp, sigset_t *set, |
| 107 | unsigned long sp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { |
| 109 | int err = 0; |
| 110 | |
| 111 | err |= put_user(current->sas_ss_sp, &uc->uc_stack.ss_sp); |
| 112 | err |= put_user(sas_ss_flags(sp), &uc->uc_stack.ss_flags); |
| 113 | err |= put_user(current->sas_ss_size, &uc->uc_stack.ss_size); |
Jeff Dike | 98c1823 | 2006-03-27 01:14:38 -0800 | [diff] [blame] | 114 | err |= copy_sc_to_user(&uc->uc_mcontext, fp, ¤t->thread.regs, sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | err |= copy_to_user(&uc->uc_sigmask, set, sizeof(*set)); |
Jeff Dike | 5d86456 | 2007-05-06 14:51:24 -0700 | [diff] [blame] | 116 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | struct sigframe |
| 120 | { |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 121 | char __user *pretcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | int sig; |
| 123 | struct sigcontext sc; |
| 124 | struct _fpstate fpstate; |
| 125 | unsigned long extramask[_NSIG_WORDS-1]; |
| 126 | char retcode[8]; |
| 127 | }; |
| 128 | |
| 129 | struct rt_sigframe |
| 130 | { |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 131 | char __user *pretcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | int sig; |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 133 | struct siginfo __user *pinfo; |
| 134 | void __user *puc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | struct siginfo info; |
| 136 | struct ucontext uc; |
| 137 | struct _fpstate fpstate; |
| 138 | char retcode[8]; |
| 139 | }; |
| 140 | |
| 141 | int setup_signal_stack_sc(unsigned long stack_top, int sig, |
| 142 | struct k_sigaction *ka, struct pt_regs *regs, |
| 143 | sigset_t *mask) |
| 144 | { |
| 145 | struct sigframe __user *frame; |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 146 | void __user *restorer; |
Jeff Dike | 98c1823 | 2006-03-27 01:14:38 -0800 | [diff] [blame] | 147 | unsigned long save_sp = PT_REGS_SP(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | int err = 0; |
| 149 | |
Jeff Dike | 3896625 | 2007-01-30 14:36:17 -0800 | [diff] [blame] | 150 | /* This is the same calculation as i386 - ((sp + 4) & 15) == 0 */ |
| 151 | stack_top = ((stack_top + 4) & -16UL) - 4; |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 152 | frame = (struct sigframe __user *) stack_top - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
| 154 | return 1; |
| 155 | |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 156 | restorer = frame->retcode; |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 157 | if (ka->sa.sa_flags & SA_RESTORER) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | restorer = ka->sa.sa_restorer; |
| 159 | |
Jeff Dike | 98c1823 | 2006-03-27 01:14:38 -0800 | [diff] [blame] | 160 | /* Update SP now because the page fault handler refuses to extend |
| 161 | * the stack if the faulting address is too far below the current |
| 162 | * SP, which frame now certainly is. If there's an error, the original |
| 163 | * value is restored on the way out. |
| 164 | * When writing the sigcontext to the stack, we have to write the |
| 165 | * original value, so that's passed to copy_sc_to_user, which does |
| 166 | * the right thing with it. |
| 167 | */ |
| 168 | PT_REGS_SP(regs) = (unsigned long) frame; |
| 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | err |= __put_user(restorer, &frame->pretcode); |
| 171 | err |= __put_user(sig, &frame->sig); |
Jeff Dike | 98c1823 | 2006-03-27 01:14:38 -0800 | [diff] [blame] | 172 | err |= copy_sc_to_user(&frame->sc, NULL, regs, save_sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | err |= __put_user(mask->sig[0], &frame->sc.oldmask); |
| 174 | if (_NSIG_WORDS > 1) |
| 175 | err |= __copy_to_user(&frame->extramask, &mask->sig[1], |
| 176 | sizeof(frame->extramask)); |
| 177 | |
| 178 | /* |
| 179 | * This is popl %eax ; movl $,%eax ; int $0x80 |
| 180 | * |
| 181 | * WE DO NOT USE IT ANY MORE! It's only left here for historical |
| 182 | * reasons and because gdb uses it as a signature to notice |
| 183 | * signal handler stack frames. |
| 184 | */ |
| 185 | err |= __put_user(0xb858, (short __user *)(frame->retcode+0)); |
| 186 | err |= __put_user(__NR_sigreturn, (int __user *)(frame->retcode+2)); |
| 187 | err |= __put_user(0x80cd, (short __user *)(frame->retcode+6)); |
| 188 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 189 | if (err) |
Jeff Dike | 98c1823 | 2006-03-27 01:14:38 -0800 | [diff] [blame] | 190 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
| 192 | PT_REGS_SP(regs) = (unsigned long) frame; |
| 193 | PT_REGS_IP(regs) = (unsigned long) ka->sa.sa_handler; |
| 194 | PT_REGS_EAX(regs) = (unsigned long) sig; |
| 195 | PT_REGS_EDX(regs) = (unsigned long) 0; |
| 196 | PT_REGS_ECX(regs) = (unsigned long) 0; |
| 197 | |
| 198 | if ((current->ptrace & PT_DTRACE) && (current->ptrace & PT_PTRACED)) |
| 199 | ptrace_notify(SIGTRAP); |
Jeff Dike | 98c1823 | 2006-03-27 01:14:38 -0800 | [diff] [blame] | 200 | return 0; |
| 201 | |
| 202 | err: |
| 203 | PT_REGS_SP(regs) = save_sp; |
| 204 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | int setup_signal_stack_si(unsigned long stack_top, int sig, |
| 208 | struct k_sigaction *ka, struct pt_regs *regs, |
| 209 | siginfo_t *info, sigset_t *mask) |
| 210 | { |
| 211 | struct rt_sigframe __user *frame; |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 212 | void __user *restorer; |
Jeff Dike | 98c1823 | 2006-03-27 01:14:38 -0800 | [diff] [blame] | 213 | unsigned long save_sp = PT_REGS_SP(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | int err = 0; |
| 215 | |
| 216 | stack_top &= -8UL; |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 217 | frame = (struct rt_sigframe __user *) stack_top - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
| 219 | return 1; |
| 220 | |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 221 | restorer = frame->retcode; |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 222 | if (ka->sa.sa_flags & SA_RESTORER) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | restorer = ka->sa.sa_restorer; |
| 224 | |
Jeff Dike | 98c1823 | 2006-03-27 01:14:38 -0800 | [diff] [blame] | 225 | /* See comment above about why this is here */ |
| 226 | PT_REGS_SP(regs) = (unsigned long) frame; |
| 227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | err |= __put_user(restorer, &frame->pretcode); |
| 229 | err |= __put_user(sig, &frame->sig); |
| 230 | err |= __put_user(&frame->info, &frame->pinfo); |
| 231 | err |= __put_user(&frame->uc, &frame->puc); |
| 232 | err |= copy_siginfo_to_user(&frame->info, info); |
| 233 | err |= copy_ucontext_to_user(&frame->uc, &frame->fpstate, mask, |
Jeff Dike | 98c1823 | 2006-03-27 01:14:38 -0800 | [diff] [blame] | 234 | save_sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
| 236 | /* |
| 237 | * This is movl $,%eax ; int $0x80 |
| 238 | * |
| 239 | * WE DO NOT USE IT ANY MORE! It's only left here for historical |
| 240 | * reasons and because gdb uses it as a signature to notice |
| 241 | * signal handler stack frames. |
| 242 | */ |
| 243 | err |= __put_user(0xb8, (char __user *)(frame->retcode+0)); |
| 244 | err |= __put_user(__NR_rt_sigreturn, (int __user *)(frame->retcode+1)); |
| 245 | err |= __put_user(0x80cd, (short __user *)(frame->retcode+5)); |
| 246 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 247 | if (err) |
Jeff Dike | 98c1823 | 2006-03-27 01:14:38 -0800 | [diff] [blame] | 248 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | PT_REGS_IP(regs) = (unsigned long) ka->sa.sa_handler; |
| 251 | PT_REGS_EAX(regs) = (unsigned long) sig; |
| 252 | PT_REGS_EDX(regs) = (unsigned long) &frame->info; |
| 253 | PT_REGS_ECX(regs) = (unsigned long) &frame->uc; |
| 254 | |
| 255 | if ((current->ptrace & PT_DTRACE) && (current->ptrace & PT_PTRACED)) |
| 256 | ptrace_notify(SIGTRAP); |
Jeff Dike | 98c1823 | 2006-03-27 01:14:38 -0800 | [diff] [blame] | 257 | return 0; |
| 258 | |
| 259 | err: |
| 260 | PT_REGS_SP(regs) = save_sp; |
| 261 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | long sys_sigreturn(struct pt_regs regs) |
| 265 | { |
| 266 | unsigned long sp = PT_REGS_SP(¤t->thread.regs); |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 267 | struct sigframe __user *frame = (struct sigframe __user *)(sp - 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | sigset_t set; |
| 269 | struct sigcontext __user *sc = &frame->sc; |
| 270 | unsigned long __user *oldmask = &sc->oldmask; |
| 271 | unsigned long __user *extramask = frame->extramask; |
| 272 | int sig_size = (_NSIG_WORDS - 1) * sizeof(unsigned long); |
| 273 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 274 | if (copy_from_user(&set.sig[0], oldmask, sizeof(set.sig[0])) || |
| 275 | copy_from_user(&set.sig[1], extramask, sig_size)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | goto segfault; |
| 277 | |
| 278 | sigdelsetmask(&set, ~_BLOCKABLE); |
| 279 | |
| 280 | spin_lock_irq(¤t->sighand->siglock); |
| 281 | current->blocked = set; |
| 282 | recalc_sigpending(); |
| 283 | spin_unlock_irq(¤t->sighand->siglock); |
| 284 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 285 | if (copy_sc_from_user(¤t->thread.regs, sc)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | goto segfault; |
| 287 | |
| 288 | /* Avoid ERESTART handling */ |
| 289 | PT_REGS_SYSCALL_NR(¤t->thread.regs) = -1; |
Jeff Dike | 5d86456 | 2007-05-06 14:51:24 -0700 | [diff] [blame] | 290 | return PT_REGS_SYSCALL_RET(¤t->thread.regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
| 292 | segfault: |
| 293 | force_sig(SIGSEGV, current); |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | long sys_rt_sigreturn(struct pt_regs regs) |
| 298 | { |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 299 | unsigned long sp = PT_REGS_SP(¤t->thread.regs); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 300 | struct rt_sigframe __user *frame = |
| 301 | (struct rt_sigframe __user *) (sp - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | sigset_t set; |
| 303 | struct ucontext __user *uc = &frame->uc; |
| 304 | int sig_size = _NSIG_WORDS * sizeof(unsigned long); |
| 305 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 306 | if (copy_from_user(&set, &uc->uc_sigmask, sig_size)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | goto segfault; |
| 308 | |
| 309 | sigdelsetmask(&set, ~_BLOCKABLE); |
| 310 | |
| 311 | spin_lock_irq(¤t->sighand->siglock); |
| 312 | current->blocked = set; |
| 313 | recalc_sigpending(); |
| 314 | spin_unlock_irq(¤t->sighand->siglock); |
| 315 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame^] | 316 | if (copy_sc_from_user(¤t->thread.regs, &uc->uc_mcontext)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | goto segfault; |
| 318 | |
| 319 | /* Avoid ERESTART handling */ |
| 320 | PT_REGS_SYSCALL_NR(¤t->thread.regs) = -1; |
Jeff Dike | 5d86456 | 2007-05-06 14:51:24 -0700 | [diff] [blame] | 321 | return PT_REGS_SYSCALL_RET(¤t->thread.regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
| 323 | segfault: |
| 324 | force_sig(SIGSEGV, current); |
| 325 | return 0; |
| 326 | } |