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