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