aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/ia32
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/ia32')
-rw-r--r--arch/x86/ia32/ia32_signal.c371
1 files changed, 183 insertions, 188 deletions
diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
index 6ea19c25f90d..0fc5d8563e19 100644
--- a/arch/x86/ia32/ia32_signal.c
+++ b/arch/x86/ia32/ia32_signal.c
@@ -43,7 +43,8 @@ void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
43int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from) 43int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from)
44{ 44{
45 int err; 45 int err;
46 if (!access_ok (VERIFY_WRITE, to, sizeof(compat_siginfo_t))) 46
47 if (!access_ok(VERIFY_WRITE, to, sizeof(compat_siginfo_t)))
47 return -EFAULT; 48 return -EFAULT;
48 49
49 /* If you change siginfo_t structure, please make sure that 50 /* If you change siginfo_t structure, please make sure that
@@ -53,16 +54,19 @@ int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from)
53 3 ints plus the relevant union member. */ 54 3 ints plus the relevant union member. */
54 err = __put_user(from->si_signo, &to->si_signo); 55 err = __put_user(from->si_signo, &to->si_signo);
55 err |= __put_user(from->si_errno, &to->si_errno); 56 err |= __put_user(from->si_errno, &to->si_errno);
56 err |= __put_user((short)from->si_code, &to->si_code); 57 err |= __put_user((short)from->si_code, &to->si_code);
57 58
58 if (from->si_code < 0) { 59 if (from->si_code < 0) {
59 err |= __put_user(from->si_pid, &to->si_pid); 60 err |= __put_user(from->si_pid, &to->si_pid);
60 err |= __put_user(from->si_uid, &to->si_uid); 61 err |= __put_user(from->si_uid, &to->si_uid);
61 err |= __put_user(ptr_to_compat(from->si_ptr), &to->si_ptr); 62 err |= __put_user(ptr_to_compat(from->si_ptr), &to->si_ptr);
62 } else { 63 } else {
63 /* First 32bits of unions are always present: 64 /*
64 * si_pid === si_band === si_tid === si_addr(LS half) */ 65 * First 32bits of unions are always present:
65 err |= __put_user(from->_sifields._pad[0], &to->_sifields._pad[0]); 66 * si_pid === si_band === si_tid === si_addr(LS half)
67 */
68 err |= __put_user(from->_sifields._pad[0],
69 &to->_sifields._pad[0]);
66 switch (from->si_code >> 16) { 70 switch (from->si_code >> 16) {
67 case __SI_FAULT >> 16: 71 case __SI_FAULT >> 16:
68 break; 72 break;
@@ -76,14 +80,15 @@ int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from)
76 err |= __put_user(from->si_uid, &to->si_uid); 80 err |= __put_user(from->si_uid, &to->si_uid);
77 break; 81 break;
78 case __SI_POLL >> 16: 82 case __SI_POLL >> 16:
79 err |= __put_user(from->si_fd, &to->si_fd); 83 err |= __put_user(from->si_fd, &to->si_fd);
80 break; 84 break;
81 case __SI_TIMER >> 16: 85 case __SI_TIMER >> 16:
82 err |= __put_user(from->si_overrun, &to->si_overrun); 86 err |= __put_user(from->si_overrun, &to->si_overrun);
83 err |= __put_user(ptr_to_compat(from->si_ptr), 87 err |= __put_user(ptr_to_compat(from->si_ptr),
84 &to->si_ptr); 88 &to->si_ptr);
85 break; 89 break;
86 case __SI_RT >> 16: /* This is not generated by the kernel as of now. */ 90 /* This is not generated by the kernel as of now. */
91 case __SI_RT >> 16:
87 case __SI_MESGQ >> 16: 92 case __SI_MESGQ >> 16:
88 err |= __put_user(from->si_uid, &to->si_uid); 93 err |= __put_user(from->si_uid, &to->si_uid);
89 err |= __put_user(from->si_int, &to->si_int); 94 err |= __put_user(from->si_int, &to->si_int);
@@ -97,7 +102,8 @@ int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
97{ 102{
98 int err; 103 int err;
99 u32 ptr32; 104 u32 ptr32;
100 if (!access_ok (VERIFY_READ, from, sizeof(compat_siginfo_t))) 105
106 if (!access_ok(VERIFY_READ, from, sizeof(compat_siginfo_t)))
101 return -EFAULT; 107 return -EFAULT;
102 108
103 err = __get_user(to->si_signo, &from->si_signo); 109 err = __get_user(to->si_signo, &from->si_signo);
@@ -112,8 +118,7 @@ int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
112 return err; 118 return err;
113} 119}
114 120
115asmlinkage long 121asmlinkage long sys32_sigsuspend(int history0, int history1, old_sigset_t mask)
116sys32_sigsuspend(int history0, int history1, old_sigset_t mask)
117{ 122{
118 mask &= _BLOCKABLE; 123 mask &= _BLOCKABLE;
119 spin_lock_irq(&current->sighand->siglock); 124 spin_lock_irq(&current->sighand->siglock);
@@ -128,36 +133,37 @@ sys32_sigsuspend(int history0, int history1, old_sigset_t mask)
128 return -ERESTARTNOHAND; 133 return -ERESTARTNOHAND;
129} 134}
130 135
131asmlinkage long 136asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
132sys32_sigaltstack(const stack_ia32_t __user *uss_ptr, 137 stack_ia32_t __user *uoss_ptr,
133 stack_ia32_t __user *uoss_ptr, 138 struct pt_regs *regs)
134 struct pt_regs *regs)
135{ 139{
136 stack_t uss,uoss; 140 stack_t uss, uoss;
137 int ret; 141 int ret;
138 mm_segment_t seg; 142 mm_segment_t seg;
139 if (uss_ptr) { 143
144 if (uss_ptr) {
140 u32 ptr; 145 u32 ptr;
141 memset(&uss,0,sizeof(stack_t)); 146
142 if (!access_ok(VERIFY_READ,uss_ptr,sizeof(stack_ia32_t)) || 147 memset(&uss, 0, sizeof(stack_t));
148 if (!access_ok(VERIFY_READ, uss_ptr, sizeof(stack_ia32_t)) ||
143 __get_user(ptr, &uss_ptr->ss_sp) || 149 __get_user(ptr, &uss_ptr->ss_sp) ||
144 __get_user(uss.ss_flags, &uss_ptr->ss_flags) || 150 __get_user(uss.ss_flags, &uss_ptr->ss_flags) ||
145 __get_user(uss.ss_size, &uss_ptr->ss_size)) 151 __get_user(uss.ss_size, &uss_ptr->ss_size))
146 return -EFAULT; 152 return -EFAULT;
147 uss.ss_sp = compat_ptr(ptr); 153 uss.ss_sp = compat_ptr(ptr);
148 } 154 }
149 seg = get_fs(); 155 seg = get_fs();
150 set_fs(KERNEL_DS); 156 set_fs(KERNEL_DS);
151 ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->rsp); 157 ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->rsp);
152 set_fs(seg); 158 set_fs(seg);
153 if (ret >= 0 && uoss_ptr) { 159 if (ret >= 0 && uoss_ptr) {
154 if (!access_ok(VERIFY_WRITE,uoss_ptr,sizeof(stack_ia32_t)) || 160 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)) ||
155 __put_user(ptr_to_compat(uoss.ss_sp), &uoss_ptr->ss_sp) || 161 __put_user(ptr_to_compat(uoss.ss_sp), &uoss_ptr->ss_sp) ||
156 __put_user(uoss.ss_flags, &uoss_ptr->ss_flags) || 162 __put_user(uoss.ss_flags, &uoss_ptr->ss_flags) ||
157 __put_user(uoss.ss_size, &uoss_ptr->ss_size)) 163 __put_user(uoss.ss_size, &uoss_ptr->ss_size))
158 ret = -EFAULT; 164 ret = -EFAULT;
159 } 165 }
160 return ret; 166 return ret;
161} 167}
162 168
163/* 169/*
@@ -186,18 +192,6 @@ struct rt_sigframe
186 char retcode[8]; 192 char retcode[8];
187}; 193};
188 194
189static int
190ia32_restore_sigcontext(struct pt_regs *regs, struct sigcontext_ia32 __user *sc, unsigned int *peax)
191{
192 unsigned int err = 0;
193
194 /* Always make any pending restarted system calls return -EINTR */
195 current_thread_info()->restart_block.fn = do_no_restart_syscall;
196
197#if DEBUG_SIG
198 printk("SIG restore_sigcontext: sc=%p err(%x) eip(%x) cs(%x) flg(%x)\n",
199 sc, sc->err, sc->eip, sc->cs, sc->eflags);
200#endif
201#define COPY(x) { \ 195#define COPY(x) { \
202 unsigned int reg; \ 196 unsigned int reg; \
203 err |= __get_user(reg, &sc->e ##x); \ 197 err |= __get_user(reg, &sc->e ##x); \
@@ -205,68 +199,78 @@ ia32_restore_sigcontext(struct pt_regs *regs, struct sigcontext_ia32 __user *sc,
205} 199}
206 200
207#define RELOAD_SEG(seg,mask) \ 201#define RELOAD_SEG(seg,mask) \
208 { unsigned int cur; \ 202 { unsigned int cur; \
209 unsigned short pre; \ 203 unsigned short pre; \
210 err |= __get_user(pre, &sc->seg); \ 204 err |= __get_user(pre, &sc->seg); \
211 asm volatile("movl %%" #seg ",%0" : "=r" (cur)); \ 205 asm volatile("movl %%" #seg ",%0" : "=r" (cur)); \
212 pre |= mask; \ 206 pre |= mask; \
213 if (pre != cur) loadsegment(seg,pre); } 207 if (pre != cur) loadsegment(seg, pre); }
214 208
215 /* Reload fs and gs if they have changed in the signal handler. 209static int ia32_restore_sigcontext(struct pt_regs *regs,
216 This does not handle long fs/gs base changes in the handler, but 210 struct sigcontext_ia32 __user *sc,
217 does not clobber them at least in the normal case. */ 211 unsigned int *peax)
218 212{
219 { 213 unsigned int tmpflags, gs, oldgs, err = 0;
220 unsigned gs, oldgs; 214 struct _fpstate_ia32 __user *buf;
221 err |= __get_user(gs, &sc->gs); 215 u32 tmp;
222 gs |= 3; 216
223 asm("movl %%gs,%0" : "=r" (oldgs)); 217 /* Always make any pending restarted system calls return -EINTR */
224 if (gs != oldgs) 218 current_thread_info()->restart_block.fn = do_no_restart_syscall;
225 load_gs_index(gs); 219
226 } 220#if DEBUG_SIG
227 RELOAD_SEG(fs,3); 221 printk(KERN_DEBUG "SIG restore_sigcontext: "
228 RELOAD_SEG(ds,3); 222 "sc=%p err(%x) eip(%x) cs(%x) flg(%x)\n",
229 RELOAD_SEG(es,3); 223 sc, sc->err, sc->eip, sc->cs, sc->eflags);
224#endif
225
226 /*
227 * Reload fs and gs if they have changed in the signal
228 * handler. This does not handle long fs/gs base changes in
229 * the handler, but does not clobber them at least in the
230 * normal case.
231 */
232 err |= __get_user(gs, &sc->gs);
233 gs |= 3;
234 asm("movl %%gs,%0" : "=r" (oldgs));
235 if (gs != oldgs)
236 load_gs_index(gs);
237
238 RELOAD_SEG(fs, 3);
239 RELOAD_SEG(ds, 3);
240 RELOAD_SEG(es, 3);
230 241
231 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx); 242 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
232 COPY(dx); COPY(cx); COPY(ip); 243 COPY(dx); COPY(cx); COPY(ip);
233 /* Don't touch extended registers */ 244 /* Don't touch extended registers */
234 245
235 err |= __get_user(regs->cs, &sc->cs); 246 err |= __get_user(regs->cs, &sc->cs);
236 regs->cs |= 3; 247 regs->cs |= 3;
237 err |= __get_user(regs->ss, &sc->ss); 248 err |= __get_user(regs->ss, &sc->ss);
238 regs->ss |= 3; 249 regs->ss |= 3;
239 250
240 { 251 err |= __get_user(tmpflags, &sc->eflags);
241 unsigned int tmpflags; 252 regs->eflags = (regs->eflags & ~0x40DD5) | (tmpflags & 0x40DD5);
242 err |= __get_user(tmpflags, &sc->eflags); 253 /* disable syscall checks */
243 regs->eflags = (regs->eflags & ~0x40DD5) | (tmpflags & 0x40DD5); 254 regs->orig_rax = -1;
244 regs->orig_rax = -1; /* disable syscall checks */ 255
245 } 256 err |= __get_user(tmp, &sc->fpstate);
257 buf = compat_ptr(tmp);
258 if (buf) {
259 if (!access_ok(VERIFY_READ, buf, sizeof(*buf)))
260 goto badframe;
261 err |= restore_i387_ia32(current, buf, 0);
262 } else {
263 struct task_struct *me = current;
246 264
247 { 265 if (used_math()) {
248 u32 tmp; 266 clear_fpu(me);
249 struct _fpstate_ia32 __user * buf; 267 clear_used_math();
250 err |= __get_user(tmp, &sc->fpstate);
251 buf = compat_ptr(tmp);
252 if (buf) {
253 if (!access_ok(VERIFY_READ, buf, sizeof(*buf)))
254 goto badframe;
255 err |= restore_i387_ia32(current, buf, 0);
256 } else {
257 struct task_struct *me = current;
258 if (used_math()) {
259 clear_fpu(me);
260 clear_used_math();
261 }
262 } 268 }
263 } 269 }
264 270
265 { 271 err |= __get_user(tmp, &sc->eax);
266 u32 tmp; 272 *peax = tmp;
267 err |= __get_user(tmp, &sc->eax); 273
268 *peax = tmp;
269 }
270 return err; 274 return err;
271 275
272badframe: 276badframe:
@@ -283,7 +287,8 @@ asmlinkage long sys32_sigreturn(struct pt_regs *regs)
283 goto badframe; 287 goto badframe;
284 if (__get_user(set.sig[0], &frame->sc.oldmask) 288 if (__get_user(set.sig[0], &frame->sc.oldmask)
285 || (_COMPAT_NSIG_WORDS > 1 289 || (_COMPAT_NSIG_WORDS > 1
286 && __copy_from_user((((char *) &set.sig) + 4), &frame->extramask, 290 && __copy_from_user((((char *) &set.sig) + 4),
291 &frame->extramask,
287 sizeof(frame->extramask)))) 292 sizeof(frame->extramask))))
288 goto badframe; 293 goto badframe;
289 294
@@ -292,7 +297,7 @@ asmlinkage long sys32_sigreturn(struct pt_regs *regs)
292 current->blocked = set; 297 current->blocked = set;
293 recalc_sigpending(); 298 recalc_sigpending();
294 spin_unlock_irq(&current->sighand->siglock); 299 spin_unlock_irq(&current->sighand->siglock);
295 300
296 if (ia32_restore_sigcontext(regs, &frame->sc, &eax)) 301 if (ia32_restore_sigcontext(regs, &frame->sc, &eax))
297 goto badframe; 302 goto badframe;
298 return eax; 303 return eax;
@@ -300,7 +305,7 @@ asmlinkage long sys32_sigreturn(struct pt_regs *regs)
300badframe: 305badframe:
301 signal_fault(regs, frame, "32bit sigreturn"); 306 signal_fault(regs, frame, "32bit sigreturn");
302 return 0; 307 return 0;
303} 308}
304 309
305asmlinkage long sys32_rt_sigreturn(struct pt_regs *regs) 310asmlinkage long sys32_rt_sigreturn(struct pt_regs *regs)
306{ 311{
@@ -321,7 +326,7 @@ asmlinkage long sys32_rt_sigreturn(struct pt_regs *regs)
321 current->blocked = set; 326 current->blocked = set;
322 recalc_sigpending(); 327 recalc_sigpending();
323 spin_unlock_irq(&current->sighand->siglock); 328 spin_unlock_irq(&current->sighand->siglock);
324 329
325 if (ia32_restore_sigcontext(regs, &frame->uc.uc_mcontext, &eax)) 330 if (ia32_restore_sigcontext(regs, &frame->uc.uc_mcontext, &eax))
326 goto badframe; 331 goto badframe;
327 332
@@ -332,17 +337,17 @@ asmlinkage long sys32_rt_sigreturn(struct pt_regs *regs)
332 return eax; 337 return eax;
333 338
334badframe: 339badframe:
335 signal_fault(regs,frame,"32bit rt sigreturn"); 340 signal_fault(regs, frame, "32bit rt sigreturn");
336 return 0; 341 return 0;
337} 342}
338 343
339/* 344/*
340 * Set up a signal frame. 345 * Set up a signal frame.
341 */ 346 */
342 347
343static int 348static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
344ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc, struct _fpstate_ia32 __user *fpstate, 349 struct _fpstate_ia32 __user *fpstate,
345 struct pt_regs *regs, unsigned int mask) 350 struct pt_regs *regs, unsigned int mask)
346{ 351{
347 int tmp, err = 0; 352 int tmp, err = 0;
348 353
@@ -375,7 +380,7 @@ ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc, struct _fpstate_ia32 __
375 tmp = save_i387_ia32(current, fpstate, regs, 0); 380 tmp = save_i387_ia32(current, fpstate, regs, 0);
376 if (tmp < 0) 381 if (tmp < 0)
377 err = -EFAULT; 382 err = -EFAULT;
378 else { 383 else {
379 clear_used_math(); 384 clear_used_math();
380 stts(); 385 stts();
381 err |= __put_user(ptr_to_compat(tmp ? fpstate : NULL), 386 err |= __put_user(ptr_to_compat(tmp ? fpstate : NULL),
@@ -392,8 +397,8 @@ ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc, struct _fpstate_ia32 __
392/* 397/*
393 * Determine which stack to use.. 398 * Determine which stack to use..
394 */ 399 */
395static void __user * 400static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
396get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size) 401 size_t frame_size)
397{ 402{
398 unsigned long rsp; 403 unsigned long rsp;
399 404
@@ -409,9 +414,8 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size)
409 /* This is the legacy signal stack switching. */ 414 /* This is the legacy signal stack switching. */
410 else if ((regs->ss & 0xffff) != __USER_DS && 415 else if ((regs->ss & 0xffff) != __USER_DS &&
411 !(ka->sa.sa_flags & SA_RESTORER) && 416 !(ka->sa.sa_flags & SA_RESTORER) &&
412 ka->sa.sa_restorer) { 417 ka->sa.sa_restorer)
413 rsp = (unsigned long) ka->sa.sa_restorer; 418 rsp = (unsigned long) ka->sa.sa_restorer;
414 }
415 419
416 rsp -= frame_size; 420 rsp -= frame_size;
417 /* Align the stack pointer according to the i386 ABI, 421 /* Align the stack pointer according to the i386 ABI,
@@ -421,11 +425,25 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size)
421} 425}
422 426
423int ia32_setup_frame(int sig, struct k_sigaction *ka, 427int ia32_setup_frame(int sig, struct k_sigaction *ka,
424 compat_sigset_t *set, struct pt_regs * regs) 428 compat_sigset_t *set, struct pt_regs *regs)
425{ 429{
426 struct sigframe __user *frame; 430 struct sigframe __user *frame;
431 void __user *restorer;
427 int err = 0; 432 int err = 0;
428 433
434 /* copy_to_user optimizes that into a single 8 byte store */
435 static const struct {
436 u16 poplmovl;
437 u32 val;
438 u16 int80;
439 u16 pad;
440 } __attribute__((packed)) code = {
441 0xb858, /* popl %eax ; movl $...,%eax */
442 __NR_ia32_sigreturn,
443 0x80cd, /* int $0x80 */
444 0,
445 };
446
429 frame = get_sigframe(ka, regs, sizeof(*frame)); 447 frame = get_sigframe(ka, regs, sizeof(*frame));
430 448
431 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) 449 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
@@ -443,38 +461,24 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
443 if (_COMPAT_NSIG_WORDS > 1) { 461 if (_COMPAT_NSIG_WORDS > 1) {
444 err |= __copy_to_user(frame->extramask, &set->sig[1], 462 err |= __copy_to_user(frame->extramask, &set->sig[1],
445 sizeof(frame->extramask)); 463 sizeof(frame->extramask));
464 if (err)
465 goto give_sigsegv;
446 } 466 }
447 if (err)
448 goto give_sigsegv;
449 467
450 /* Return stub is in 32bit vsyscall page */ 468 /* Return stub is in 32bit vsyscall page */
451 { 469 if (current->binfmt->hasvdso)
452 void __user *restorer; 470 restorer = VSYSCALL32_SIGRETURN;
453 if (current->binfmt->hasvdso) 471 else
454 restorer = VSYSCALL32_SIGRETURN; 472 restorer = (void *)&frame->retcode;
455 else 473 if (ka->sa.sa_flags & SA_RESTORER)
456 restorer = (void *)&frame->retcode; 474 restorer = ka->sa.sa_restorer;
457 if (ka->sa.sa_flags & SA_RESTORER) 475 err |= __put_user(ptr_to_compat(restorer), &frame->pretcode);
458 restorer = ka->sa.sa_restorer; 476
459 err |= __put_user(ptr_to_compat(restorer), &frame->pretcode); 477 /*
460 } 478 * These are actually not used anymore, but left because some
461 /* These are actually not used anymore, but left because some 479 * gdb versions depend on them as a marker.
462 gdb versions depend on them as a marker. */ 480 */
463 { 481 err |= __copy_to_user(frame->retcode, &code, 8);
464 /* copy_to_user optimizes that into a single 8 byte store */
465 static const struct {
466 u16 poplmovl;
467 u32 val;
468 u16 int80;
469 u16 pad;
470 } __attribute__((packed)) code = {
471 0xb858, /* popl %eax ; movl $...,%eax */
472 __NR_ia32_sigreturn,
473 0x80cd, /* int $0x80 */
474 0,
475 };
476 err |= __copy_to_user(frame->retcode, &code, 8);
477 }
478 if (err) 482 if (err)
479 goto give_sigsegv; 483 goto give_sigsegv;
480 484
@@ -487,11 +491,11 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
487 regs->rdx = 0; 491 regs->rdx = 0;
488 regs->rcx = 0; 492 regs->rcx = 0;
489 493
490 asm volatile("movl %0,%%ds" :: "r" (__USER32_DS)); 494 asm volatile("movl %0,%%ds" :: "r" (__USER32_DS));
491 asm volatile("movl %0,%%es" :: "r" (__USER32_DS)); 495 asm volatile("movl %0,%%es" :: "r" (__USER32_DS));
492 496
493 regs->cs = __USER32_CS; 497 regs->cs = __USER32_CS;
494 regs->ss = __USER32_DS; 498 regs->ss = __USER32_DS;
495 499
496 set_fs(USER_DS); 500 set_fs(USER_DS);
497 regs->eflags &= ~TF_MASK; 501 regs->eflags &= ~TF_MASK;
@@ -499,8 +503,8 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
499 ptrace_notify(SIGTRAP); 503 ptrace_notify(SIGTRAP);
500 504
501#if DEBUG_SIG 505#if DEBUG_SIG
502 printk("SIG deliver (%s:%d): sp=%p pc=%lx ra=%u\n", 506 printk(KERN_DEBUG "SIG deliver (%s:%d): sp=%p pc=%lx ra=%u\n",
503 current->comm, current->pid, frame, regs->rip, frame->pretcode); 507 current->comm, current->pid, frame, regs->rip, frame->pretcode);
504#endif 508#endif
505 509
506 return 0; 510 return 0;
@@ -511,25 +515,34 @@ give_sigsegv:
511} 515}
512 516
513int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, 517int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
514 compat_sigset_t *set, struct pt_regs * regs) 518 compat_sigset_t *set, struct pt_regs *regs)
515{ 519{
516 struct rt_sigframe __user *frame; 520 struct rt_sigframe __user *frame;
521 struct exec_domain *ed = current_thread_info()->exec_domain;
522 void __user *restorer = VSYSCALL32_RTSIGRETURN;
517 int err = 0; 523 int err = 0;
518 524
525 /* __copy_to_user optimizes that into a single 8 byte store */
526 static const struct {
527 u8 movl;
528 u32 val;
529 u16 int80;
530 u16 pad;
531 u8 pad2;
532 } __attribute__((packed)) code = {
533 0xb8,
534 __NR_ia32_rt_sigreturn,
535 0x80cd,
536 0,
537 };
538
519 frame = get_sigframe(ka, regs, sizeof(*frame)); 539 frame = get_sigframe(ka, regs, sizeof(*frame));
520 540
521 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) 541 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
522 goto give_sigsegv; 542 goto give_sigsegv;
523 543
524 { 544 err |= __put_user((ed && ed->signal_invmap && sig < 32
525 struct exec_domain *ed = current_thread_info()->exec_domain; 545 ? ed->signal_invmap[sig] : sig), &frame->sig);
526 err |= __put_user((ed
527 && ed->signal_invmap
528 && sig < 32
529 ? ed->signal_invmap[sig]
530 : sig),
531 &frame->sig);
532 }
533 err |= __put_user(ptr_to_compat(&frame->info), &frame->pinfo); 546 err |= __put_user(ptr_to_compat(&frame->info), &frame->pinfo);
534 err |= __put_user(ptr_to_compat(&frame->uc), &frame->puc); 547 err |= __put_user(ptr_to_compat(&frame->uc), &frame->puc);
535 err |= copy_siginfo_to_user32(&frame->info, info); 548 err |= copy_siginfo_to_user32(&frame->info, info);
@@ -544,38 +557,20 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
544 &frame->uc.uc_stack.ss_flags); 557 &frame->uc.uc_stack.ss_flags);
545 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); 558 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
546 err |= ia32_setup_sigcontext(&frame->uc.uc_mcontext, &frame->fpstate, 559 err |= ia32_setup_sigcontext(&frame->uc.uc_mcontext, &frame->fpstate,
547 regs, set->sig[0]); 560 regs, set->sig[0]);
548 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); 561 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
549 if (err) 562 if (err)
550 goto give_sigsegv; 563 goto give_sigsegv;
551 564
552 565 if (ka->sa.sa_flags & SA_RESTORER)
553 { 566 restorer = ka->sa.sa_restorer;
554 void __user *restorer = VSYSCALL32_RTSIGRETURN; 567 err |= __put_user(ptr_to_compat(restorer), &frame->pretcode);
555 if (ka->sa.sa_flags & SA_RESTORER)
556 restorer = ka->sa.sa_restorer;
557 err |= __put_user(ptr_to_compat(restorer), &frame->pretcode);
558 }
559 568
560 /* This is movl $,%eax ; int $0x80 */ 569 /*
561 /* Not actually used anymore, but left because some gdb versions 570 * Not actually used anymore, but left because some gdb
562 need it. */ 571 * versions need it.
563 { 572 */
564 /* __copy_to_user optimizes that into a single 8 byte store */ 573 err |= __copy_to_user(frame->retcode, &code, 8);
565 static const struct {
566 u8 movl;
567 u32 val;
568 u16 int80;
569 u16 pad;
570 u8 pad2;
571 } __attribute__((packed)) code = {
572 0xb8,
573 __NR_ia32_rt_sigreturn,
574 0x80cd,
575 0,
576 };
577 err |= __copy_to_user(frame->retcode, &code, 8);
578 }
579 if (err) 574 if (err)
580 goto give_sigsegv; 575 goto give_sigsegv;
581 576
@@ -593,11 +588,11 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
593 regs->rdx = (unsigned long) &frame->info; 588 regs->rdx = (unsigned long) &frame->info;
594 regs->rcx = (unsigned long) &frame->uc; 589 regs->rcx = (unsigned long) &frame->uc;
595 590
596 asm volatile("movl %0,%%ds" :: "r" (__USER32_DS)); 591 asm volatile("movl %0,%%ds" :: "r" (__USER32_DS));
597 asm volatile("movl %0,%%es" :: "r" (__USER32_DS)); 592 asm volatile("movl %0,%%es" :: "r" (__USER32_DS));
598 593
599 regs->cs = __USER32_CS; 594 regs->cs = __USER32_CS;
600 regs->ss = __USER32_DS; 595 regs->ss = __USER32_DS;
601 596
602 set_fs(USER_DS); 597 set_fs(USER_DS);
603 regs->eflags &= ~TF_MASK; 598 regs->eflags &= ~TF_MASK;
@@ -605,8 +600,8 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
605 ptrace_notify(SIGTRAP); 600 ptrace_notify(SIGTRAP);
606 601
607#if DEBUG_SIG 602#if DEBUG_SIG
608 printk("SIG deliver (%s:%d): sp=%p pc=%lx ra=%u\n", 603 printk(KERN_DEBUG "SIG deliver (%s:%d): sp=%p pc=%lx ra=%u\n",
609 current->comm, current->pid, frame, regs->rip, frame->pretcode); 604 current->comm, current->pid, frame, regs->rip, frame->pretcode);
610#endif 605#endif
611 606
612 return 0; 607 return 0;