diff options
Diffstat (limited to 'arch/sparc/kernel/signal_64.c')
-rw-r--r-- | arch/sparc/kernel/signal_64.c | 108 |
1 files changed, 47 insertions, 61 deletions
diff --git a/arch/sparc/kernel/signal_64.c b/arch/sparc/kernel/signal_64.c index 006fe4515886..47509df3b893 100644 --- a/arch/sparc/kernel/signal_64.c +++ b/arch/sparc/kernel/signal_64.c | |||
@@ -34,6 +34,7 @@ | |||
34 | 34 | ||
35 | #include "entry.h" | 35 | #include "entry.h" |
36 | #include "systbls.h" | 36 | #include "systbls.h" |
37 | #include "sigutil.h" | ||
37 | 38 | ||
38 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) | 39 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) |
39 | 40 | ||
@@ -236,7 +237,7 @@ struct rt_signal_frame { | |||
236 | __siginfo_fpu_t __user *fpu_save; | 237 | __siginfo_fpu_t __user *fpu_save; |
237 | stack_t stack; | 238 | stack_t stack; |
238 | sigset_t mask; | 239 | sigset_t mask; |
239 | __siginfo_fpu_t fpu_state; | 240 | __siginfo_rwin_t *rwin_save; |
240 | }; | 241 | }; |
241 | 242 | ||
242 | static long _sigpause_common(old_sigset_t set) | 243 | static long _sigpause_common(old_sigset_t set) |
@@ -266,33 +267,12 @@ asmlinkage long sys_sigsuspend(old_sigset_t set) | |||
266 | return _sigpause_common(set); | 267 | return _sigpause_common(set); |
267 | } | 268 | } |
268 | 269 | ||
269 | static inline int | ||
270 | restore_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu) | ||
271 | { | ||
272 | unsigned long *fpregs = current_thread_info()->fpregs; | ||
273 | unsigned long fprs; | ||
274 | int err; | ||
275 | |||
276 | err = __get_user(fprs, &fpu->si_fprs); | ||
277 | fprs_write(0); | ||
278 | regs->tstate &= ~TSTATE_PEF; | ||
279 | if (fprs & FPRS_DL) | ||
280 | err |= copy_from_user(fpregs, &fpu->si_float_regs[0], | ||
281 | (sizeof(unsigned int) * 32)); | ||
282 | if (fprs & FPRS_DU) | ||
283 | err |= copy_from_user(fpregs+16, &fpu->si_float_regs[32], | ||
284 | (sizeof(unsigned int) * 32)); | ||
285 | err |= __get_user(current_thread_info()->xfsr[0], &fpu->si_fsr); | ||
286 | err |= __get_user(current_thread_info()->gsr[0], &fpu->si_gsr); | ||
287 | current_thread_info()->fpsaved[0] |= fprs; | ||
288 | return err; | ||
289 | } | ||
290 | |||
291 | void do_rt_sigreturn(struct pt_regs *regs) | 270 | void do_rt_sigreturn(struct pt_regs *regs) |
292 | { | 271 | { |
293 | struct rt_signal_frame __user *sf; | 272 | struct rt_signal_frame __user *sf; |
294 | unsigned long tpc, tnpc, tstate; | 273 | unsigned long tpc, tnpc, tstate; |
295 | __siginfo_fpu_t __user *fpu_save; | 274 | __siginfo_fpu_t __user *fpu_save; |
275 | __siginfo_rwin_t __user *rwin_save; | ||
296 | sigset_t set; | 276 | sigset_t set; |
297 | int err; | 277 | int err; |
298 | 278 | ||
@@ -325,8 +305,8 @@ void do_rt_sigreturn(struct pt_regs *regs) | |||
325 | regs->tstate |= (tstate & (TSTATE_ASI | TSTATE_ICC | TSTATE_XCC)); | 305 | regs->tstate |= (tstate & (TSTATE_ASI | TSTATE_ICC | TSTATE_XCC)); |
326 | 306 | ||
327 | err |= __get_user(fpu_save, &sf->fpu_save); | 307 | err |= __get_user(fpu_save, &sf->fpu_save); |
328 | if (fpu_save) | 308 | if (!err && fpu_save) |
329 | err |= restore_fpu_state(regs, &sf->fpu_state); | 309 | err |= restore_fpu_state(regs, fpu_save); |
330 | 310 | ||
331 | err |= __copy_from_user(&set, &sf->mask, sizeof(sigset_t)); | 311 | err |= __copy_from_user(&set, &sf->mask, sizeof(sigset_t)); |
332 | err |= do_sigaltstack(&sf->stack, NULL, (unsigned long)sf); | 312 | err |= do_sigaltstack(&sf->stack, NULL, (unsigned long)sf); |
@@ -334,6 +314,12 @@ void do_rt_sigreturn(struct pt_regs *regs) | |||
334 | if (err) | 314 | if (err) |
335 | goto segv; | 315 | goto segv; |
336 | 316 | ||
317 | err |= __get_user(rwin_save, &sf->rwin_save); | ||
318 | if (!err && rwin_save) { | ||
319 | if (restore_rwin_state(rwin_save)) | ||
320 | goto segv; | ||
321 | } | ||
322 | |||
337 | regs->tpc = tpc; | 323 | regs->tpc = tpc; |
338 | regs->tnpc = tnpc; | 324 | regs->tnpc = tnpc; |
339 | 325 | ||
@@ -351,34 +337,13 @@ segv: | |||
351 | } | 337 | } |
352 | 338 | ||
353 | /* Checks if the fp is valid */ | 339 | /* Checks if the fp is valid */ |
354 | static int invalid_frame_pointer(void __user *fp, int fplen) | 340 | static int invalid_frame_pointer(void __user *fp) |
355 | { | 341 | { |
356 | if (((unsigned long) fp) & 15) | 342 | if (((unsigned long) fp) & 15) |
357 | return 1; | 343 | return 1; |
358 | return 0; | 344 | return 0; |
359 | } | 345 | } |
360 | 346 | ||
361 | static inline int | ||
362 | save_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu) | ||
363 | { | ||
364 | unsigned long *fpregs = current_thread_info()->fpregs; | ||
365 | unsigned long fprs; | ||
366 | int err = 0; | ||
367 | |||
368 | fprs = current_thread_info()->fpsaved[0]; | ||
369 | if (fprs & FPRS_DL) | ||
370 | err |= copy_to_user(&fpu->si_float_regs[0], fpregs, | ||
371 | (sizeof(unsigned int) * 32)); | ||
372 | if (fprs & FPRS_DU) | ||
373 | err |= copy_to_user(&fpu->si_float_regs[32], fpregs+16, | ||
374 | (sizeof(unsigned int) * 32)); | ||
375 | err |= __put_user(current_thread_info()->xfsr[0], &fpu->si_fsr); | ||
376 | err |= __put_user(current_thread_info()->gsr[0], &fpu->si_gsr); | ||
377 | err |= __put_user(fprs, &fpu->si_fprs); | ||
378 | |||
379 | return err; | ||
380 | } | ||
381 | |||
382 | static inline void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, unsigned long framesize) | 347 | static inline void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, unsigned long framesize) |
383 | { | 348 | { |
384 | unsigned long sp = regs->u_regs[UREG_FP] + STACK_BIAS; | 349 | unsigned long sp = regs->u_regs[UREG_FP] + STACK_BIAS; |
@@ -414,34 +379,48 @@ setup_rt_frame(struct k_sigaction *ka, struct pt_regs *regs, | |||
414 | int signo, sigset_t *oldset, siginfo_t *info) | 379 | int signo, sigset_t *oldset, siginfo_t *info) |
415 | { | 380 | { |
416 | struct rt_signal_frame __user *sf; | 381 | struct rt_signal_frame __user *sf; |
417 | int sigframe_size, err; | 382 | int wsaved, err, sf_size; |
383 | void __user *tail; | ||
418 | 384 | ||
419 | /* 1. Make sure everything is clean */ | 385 | /* 1. Make sure everything is clean */ |
420 | synchronize_user_stack(); | 386 | synchronize_user_stack(); |
421 | save_and_clear_fpu(); | 387 | save_and_clear_fpu(); |
422 | 388 | ||
423 | sigframe_size = sizeof(struct rt_signal_frame); | 389 | wsaved = get_thread_wsaved(); |
424 | if (!(current_thread_info()->fpsaved[0] & FPRS_FEF)) | ||
425 | sigframe_size -= sizeof(__siginfo_fpu_t); | ||
426 | 390 | ||
391 | sf_size = sizeof(struct rt_signal_frame); | ||
392 | if (current_thread_info()->fpsaved[0] & FPRS_FEF) | ||
393 | sf_size += sizeof(__siginfo_fpu_t); | ||
394 | if (wsaved) | ||
395 | sf_size += sizeof(__siginfo_rwin_t); | ||
427 | sf = (struct rt_signal_frame __user *) | 396 | sf = (struct rt_signal_frame __user *) |
428 | get_sigframe(ka, regs, sigframe_size); | 397 | get_sigframe(ka, regs, sf_size); |
429 | |||
430 | if (invalid_frame_pointer (sf, sigframe_size)) | ||
431 | goto sigill; | ||
432 | 398 | ||
433 | if (get_thread_wsaved() != 0) | 399 | if (invalid_frame_pointer (sf)) |
434 | goto sigill; | 400 | goto sigill; |
435 | 401 | ||
402 | tail = (sf + 1); | ||
403 | |||
436 | /* 2. Save the current process state */ | 404 | /* 2. Save the current process state */ |
437 | err = copy_to_user(&sf->regs, regs, sizeof (*regs)); | 405 | err = copy_to_user(&sf->regs, regs, sizeof (*regs)); |
438 | 406 | ||
439 | if (current_thread_info()->fpsaved[0] & FPRS_FEF) { | 407 | if (current_thread_info()->fpsaved[0] & FPRS_FEF) { |
440 | err |= save_fpu_state(regs, &sf->fpu_state); | 408 | __siginfo_fpu_t __user *fpu_save = tail; |
441 | err |= __put_user((u64)&sf->fpu_state, &sf->fpu_save); | 409 | tail += sizeof(__siginfo_fpu_t); |
410 | err |= save_fpu_state(regs, fpu_save); | ||
411 | err |= __put_user((u64)fpu_save, &sf->fpu_save); | ||
442 | } else { | 412 | } else { |
443 | err |= __put_user(0, &sf->fpu_save); | 413 | err |= __put_user(0, &sf->fpu_save); |
444 | } | 414 | } |
415 | if (wsaved) { | ||
416 | __siginfo_rwin_t __user *rwin_save = tail; | ||
417 | tail += sizeof(__siginfo_rwin_t); | ||
418 | err |= save_rwin_state(wsaved, rwin_save); | ||
419 | err |= __put_user((u64)rwin_save, &sf->rwin_save); | ||
420 | set_thread_wsaved(0); | ||
421 | } else { | ||
422 | err |= __put_user(0, &sf->rwin_save); | ||
423 | } | ||
445 | 424 | ||
446 | /* Setup sigaltstack */ | 425 | /* Setup sigaltstack */ |
447 | err |= __put_user(current->sas_ss_sp, &sf->stack.ss_sp); | 426 | err |= __put_user(current->sas_ss_sp, &sf->stack.ss_sp); |
@@ -450,10 +429,17 @@ setup_rt_frame(struct k_sigaction *ka, struct pt_regs *regs, | |||
450 | 429 | ||
451 | err |= copy_to_user(&sf->mask, oldset, sizeof(sigset_t)); | 430 | err |= copy_to_user(&sf->mask, oldset, sizeof(sigset_t)); |
452 | 431 | ||
453 | err |= copy_in_user((u64 __user *)sf, | 432 | if (!wsaved) { |
454 | (u64 __user *)(regs->u_regs[UREG_FP]+STACK_BIAS), | 433 | err |= copy_in_user((u64 __user *)sf, |
455 | sizeof(struct reg_window)); | 434 | (u64 __user *)(regs->u_regs[UREG_FP] + |
435 | STACK_BIAS), | ||
436 | sizeof(struct reg_window)); | ||
437 | } else { | ||
438 | struct reg_window *rp; | ||
456 | 439 | ||
440 | rp = ¤t_thread_info()->reg_window[wsaved - 1]; | ||
441 | err |= copy_to_user(sf, rp, sizeof(struct reg_window)); | ||
442 | } | ||
457 | if (info) | 443 | if (info) |
458 | err |= copy_siginfo_to_user(&sf->info, info); | 444 | err |= copy_siginfo_to_user(&sf->info, info); |
459 | else { | 445 | else { |