Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 | /* $Id: signal.c,v 1.77 1997/12/22 03:06:32 ecd Exp $ * linux/arch/sparc/kernel/signal.c * * Copyright (C) 1991, 1992 Linus Torvalds * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx) * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be) */ #include <linux/sched.h> #include <linux/kernel.h> #include <linux/signal.h> #include <linux/errno.h> #include <linux/wait.h> #include <linux/ptrace.h> #include <linux/unistd.h> #include <linux/mm.h> #include <linux/smp.h> #include <linux/smp_lock.h> #include <asm/uaccess.h> #include <asm/bitops.h> #include <asm/ptrace.h> #include <asm/svr4.h> #include <asm/pgtable.h> #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) asmlinkage int sys_wait4(pid_t pid, unsigned long *stat_addr, int options, unsigned long *ru); extern void fpsave(unsigned long *fpregs, unsigned long *fsr, void *fpqueue, unsigned long *fpqdepth); extern void fpload(unsigned long *fpregs, unsigned long *fsr); asmlinkage int do_signal(sigset_t *oldset, struct pt_regs * regs, unsigned long orig_o0, int ret_from_syscall); /* This turned off for production... */ /* #define DEBUG_SIGNALS 1 */ /* Signal frames: the original one (compatible with SunOS): * * Set up a signal frame... Make the stack look the way SunOS * expects it to look which is basically: * * ---------------------------------- <-- %sp at signal time * Struct sigcontext * Signal address * Ptr to sigcontext area above * Signal code * The signal number itself * One register window * ---------------------------------- <-- New %sp */ struct signal_sframe { struct reg_window sig_window; int sig_num; int sig_code; struct sigcontext *sig_scptr; int sig_address; struct sigcontext sig_context; unsigned int extramask[_NSIG_WORDS - 1]; }; /* * And the new one, intended to be used for Linux applications only * (we have enough in there to work with clone). * All the interesting bits are in the info field. */ struct new_signal_frame { struct sparc_stackf ss; __siginfo_t info; __siginfo_fpu_t *fpu_save; unsigned long insns [2] __attribute__ ((aligned (8))); unsigned int extramask[_NSIG_WORDS - 1]; __siginfo_fpu_t fpu_state; }; /* Align macros */ #define SF_ALIGNEDSZ (((sizeof(struct signal_sframe) + 7) & (~7))) #define NF_ALIGNEDSZ (((sizeof(struct new_signal_frame) + 7) & (~7))) /* * atomically swap in the new signal mask, and wait for a signal. * This is really tricky on the Sparc, watch out... */ asmlinkage void _sigpause_common(old_sigset_t set, struct pt_regs *regs) { sigset_t saveset; set &= _BLOCKABLE; spin_lock_irq(¤t->sigmask_lock); saveset = current->blocked; siginitset(¤t->blocked, set); recalc_sigpending(current); spin_unlock_irq(¤t->sigmask_lock); regs->pc = regs->npc; regs->npc += 4; /* Condition codes and return value where set here for sigpause, * and so got used by setup_frame, which again causes sigreturn() * to return -EINTR. */ while (1) { current->state = TASK_INTERRUPTIBLE; schedule(); /* * Return -EINTR and set condition code here, * so the interrupted system call actually returns * these. */ regs->psr |= PSR_C; regs->u_regs[UREG_I0] = EINTR; if (do_signal(&saveset, regs, 0, 0)) return; } } asmlinkage void do_sigpause(unsigned int set, struct pt_regs *regs) { _sigpause_common(set, regs); } asmlinkage void do_sigsuspend (struct pt_regs *regs) { _sigpause_common(regs->u_regs[UREG_I0], regs); } asmlinkage void do_rt_sigsuspend(sigset_t *uset, size_t sigsetsize, struct pt_regs *regs) { sigset_t oldset, set; /* XXX: Don't preclude handling different sized sigset_t's. */ if (sigsetsize != sizeof(sigset_t)) { regs->psr |= PSR_C; regs->u_regs[UREG_I0] = EINVAL; return; } if (copy_from_user(&set, uset, sizeof(set))) { regs->psr |= PSR_C; regs->u_regs[UREG_I0] = EFAULT; return; } sigdelsetmask(&set, ~_BLOCKABLE); spin_lock_irq(¤t->sigmask_lock); oldset = current->blocked; current->blocked = set; recalc_sigpending(current); spin_unlock_irq(¤t->sigmask_lock); regs->pc = regs->npc; regs->npc += 4; /* Condition codes and return value where set here for sigpause, * and so got used by setup_frame, which again causes sigreturn() * to return -EINTR. */ while (1) { current->state = TASK_INTERRUPTIBLE; schedule(); /* * Return -EINTR and set condition code here, * so the interrupted system call actually returns * these. */ regs->psr |= PSR_C; regs->u_regs[UREG_I0] = EINTR; if (do_signal(&oldset, regs, 0, 0)) return; } } static inline void restore_fpu_state(struct pt_regs *regs, __siginfo_fpu_t *fpu) { #ifdef __SMP__ if (current->flags & PF_USEDFPU) regs->psr &= ~PSR_EF; #else if (current == last_task_used_math) { last_task_used_math = 0; regs->psr &= ~PSR_EF; } #endif current->used_math = 1; current->flags &= ~PF_USEDFPU; copy_from_user(¤t->tss.float_regs[0], &fpu->si_float_regs[0], (sizeof(unsigned long) * 32)); __get_user(current->tss.fsr, &fpu->si_fsr); __get_user(current->tss.fpqdepth, &fpu->si_fpqdepth); if (current->tss.fpqdepth != 0) copy_from_user(¤t->tss.fpqueue[0], &fpu->si_fpqueue[0], ((sizeof(unsigned long) + (sizeof(unsigned long *)))*16)); } static inline void do_new_sigreturn (struct pt_regs *regs) { struct new_signal_frame *sf; unsigned long up_psr, pc, npc; sigset_t set; sf = (struct new_signal_frame *) regs->u_regs [UREG_FP]; /* 1. Make sure we are not getting garbage from the user */ if (verify_area (VERIFY_READ, sf, sizeof (*sf))) goto segv_and_exit; if (((uint) sf) & 3) goto segv_and_exit; __get_user(pc, &sf->info.si_regs.pc); __get_user(npc, &sf->info.si_regs.npc); if ((pc | npc) & 3) goto segv_and_exit; /* 2. Restore the state */ up_psr = regs->psr; copy_from_user(regs, &sf->info.si_regs, sizeof (struct pt_regs)); /* User can only change condition codes and FPU enabling in %psr. */ regs->psr = (up_psr & ~(PSR_ICC | PSR_EF)) | (regs->psr & (PSR_ICC | PSR_EF)); if (sf->fpu_save) restore_fpu_state(regs, sf->fpu_save); /* This is pretty much atomic, no amount locking would prevent * the races which exist anyways. */ if (__get_user(set.sig[0], &sf->info.si_mask) || copy_from_user(&set.sig[1], &sf->extramask, (_NSIG_WORDS-1) * sizeof(unsigned int))) goto segv_and_exit; sigdelsetmask(&set, ~_BLOCKABLE); spin_lock_irq(¤t->sigmask_lock); current->blocked = set; recalc_sigpending(current); spin_unlock_irq(¤t->sigmask_lock); return; segv_and_exit: /* Ugh, we need to grab master lock in these rare cases ;-( */ lock_kernel(); do_exit(SIGSEGV); } asmlinkage void do_sigreturn(struct pt_regs *regs) { struct sigcontext *scptr; unsigned long pc, npc, psr; sigset_t set; synchronize_user_stack(); if (current->tss.new_signal) return do_new_sigreturn (regs); scptr = (struct sigcontext *) regs->u_regs[UREG_I0]; /* Check sanity of the user arg. */ if(verify_area(VERIFY_READ, scptr, sizeof(struct sigcontext)) || (((unsigned long) scptr) & 3)) goto segv_and_exit; __get_user(pc, &scptr->sigc_pc); __get_user(npc, &scptr->sigc_npc); if((pc | npc) & 3) goto segv_and_exit; /* This is pretty much atomic, no amount locking would prevent * the races which exist anyways. */ if (__get_user(set.sig[0], &scptr->sigc_mask) || /* Note that scptr + 1 points to extramask */ copy_from_user(&set.sig[1], scptr + 1, (_NSIG_WORDS - 1) * sizeof(unsigned int))) goto segv_and_exit; sigdelsetmask(&set, ~_BLOCKABLE); spin_lock_irq(¤t->sigmask_lock); current->blocked = set; recalc_sigpending(current); spin_unlock_irq(¤t->sigmask_lock); __get_user(current->tss.sstk_info.cur_status, &scptr->sigc_onstack); current->tss.sstk_info.cur_status &= 1; regs->pc = pc; regs->npc = npc; __get_user(regs->u_regs[UREG_FP], &scptr->sigc_sp); __get_user(regs->u_regs[UREG_I0], &scptr->sigc_o0); __get_user(regs->u_regs[UREG_G1], &scptr->sigc_g1); /* User can only change condition codes in %psr. */ __get_user(psr, &scptr->sigc_psr); regs->psr &= ~(PSR_ICC); regs->psr |= (psr & PSR_ICC); return; segv_and_exit: /* Ugh, we need to grab master lock in these rare cases ;-( */ lock_kernel(); do_exit(SIGSEGV); } asmlinkage void do_rt_sigreturn(struct pt_regs *regs) { printk("XXX: FIXME: write do_rt_sigreturn\n"); } /* Checks if the fp is valid */ static inline int invalid_frame_pointer (void *fp, int fplen) { if ((((unsigned long) fp) & 7) || !__access_ok((unsigned long)fp, fplen) || ((sparc_cpu_model == sun4 || sparc_cpu_model == sun4c) && ((unsigned long) fp < 0xe0000000 && (unsigned long) fp >= 0x20000000))) return 1; return 0; } static inline void setup_frame(struct sigaction *sa, unsigned long pc, unsigned long npc, struct pt_regs *regs, int signr, sigset_t *oldset) { struct signal_sframe *sframep; struct sigcontext *sc; int window = 0; int old_status = current->tss.sstk_info.cur_status; synchronize_user_stack(); sframep = (struct signal_sframe *) regs->u_regs[UREG_FP]; sframep = (struct signal_sframe *) (((unsigned long) sframep)-SF_ALIGNEDSZ); if (invalid_frame_pointer (sframep, sizeof(*sframep))){ #ifdef DEBUG_SIGNALS /* fills up the console logs during crashme runs, yuck... */ printk("%s [%d]: User has trashed signal stack\n", current->comm, current->pid); printk("Sigstack ptr %p handler at pc<%08lx> for sig<%d>\n", sframep, pc, signr); #endif /* Don't change signal code and address, so that * post mortem debuggers can have a look. */ goto sigill_and_return; } sc = &sframep->sig_context; /* We've already made sure frame pointer isn't in kernel space... */ __put_user(old_status, &sc->sigc_onstack); __put_user(oldset->sig[0], &sc->sigc_mask); __copy_to_user(sframep->extramask, &oldset->sig[1], (_NSIG_WORDS - 1) * sizeof(unsigned int)); __put_user(regs->u_regs[UREG_FP], &sc->sigc_sp); __put_user(pc, &sc->sigc_pc); __put_user(npc, &sc->sigc_npc); __put_user(regs->psr, &sc->sigc_psr); __put_user(regs->u_regs[UREG_G1], &sc->sigc_g1); __put_user(regs->u_regs[UREG_I0], &sc->sigc_o0); __put_user(current->tss.w_saved, &sc->sigc_oswins); if(current->tss.w_saved) for(window = 0; window < current->tss.w_saved; window++) { sc->sigc_spbuf[window] = (char *)current->tss.rwbuf_stkptrs[window]; copy_to_user(&sc->sigc_wbuf[window], ¤t->tss.reg_window[window], sizeof(struct reg_window)); } else copy_to_user(sframep, (char *)regs->u_regs[UREG_FP], sizeof(struct reg_window)); current->tss.w_saved = 0; /* So process is allowed to execute. */ __put_user(signr, &sframep->sig_num); if(signr == SIGSEGV || signr == SIGILL || signr == SIGFPE || signr == SIGBUS || signr == SIGEMT) { __put_user(current->tss.sig_desc, &sframep->sig_code); __put_user(current->tss.sig_address, &sframep->sig_address); } else { __put_user(0, &sframep->sig_code); __put_user(0, &sframep->sig_address); } __put_user(sc, &sframep->sig_scptr); regs->u_regs[UREG_FP] = (unsigned long) sframep; regs->pc = (unsigned long) sa->sa_handler; regs->npc = (regs->pc + 4); return; sigill_and_return: /* Ugh, we need to grab master lock in these rare cases ;-( */ lock_kernel(); do_exit(SIGILL); } static inline void save_fpu_state(struct pt_regs *regs, __siginfo_fpu_t *fpu) { #ifdef __SMP__ if (current->flags & PF_USEDFPU) { put_psr(get_psr() | PSR_EF); fpsave(¤t->tss.float_regs[0], ¤t->tss.fsr, ¤t->tss.fpqueue[0], ¤t->tss.fpqdepth); regs->psr &= ~(PSR_EF); current->flags &= ~(PF_USEDFPU); } #else if (current == last_task_used_math) { put_psr(get_psr() | PSR_EF); fpsave(¤t->tss.float_regs[0], ¤t->tss.fsr, ¤t->tss.fpqueue[0], ¤t->tss.fpqdepth); last_task_used_math = 0; regs->psr &= ~(PSR_EF); } #endif copy_to_user(&fpu->si_float_regs[0], ¤t->tss.float_regs[0], (sizeof(unsigned long) * 32)); __put_user(current->tss.fsr, &fpu->si_fsr); __put_user(current->tss.fpqdepth, &fpu->si_fpqdepth); if (current->tss.fpqdepth != 0) copy_to_user(&fpu->si_fpqueue[0], ¤t->tss.fpqueue[0], ((sizeof(unsigned long) + (sizeof(unsigned long *)))*16)); current->used_math = 0; } static inline void new_setup_frame(struct k_sigaction *ka, struct pt_regs *regs, int signo, sigset_t *oldset) { struct new_signal_frame *sf; int sigframe_size; /* 1. Make sure everything is clean */ synchronize_user_stack(); sigframe_size = NF_ALIGNEDSZ; if (!current->used_math) sigframe_size -= sizeof(__siginfo_fpu_t); sf = (struct new_signal_frame *)(regs->u_regs[UREG_FP] - sigframe_size); if (invalid_frame_pointer (sf, sigframe_size)) goto sigill_and_return; if (current->tss.w_saved != 0) { printk ("%s [%d]: Invalid user stack frame for " "signal delivery.\n", current->comm, current->pid); goto sigill_and_return; } /* 2. Save the current process state */ copy_to_user(&sf->info.si_regs, regs, sizeof (struct pt_regs)); if (current->used_math) { save_fpu_state(regs, &sf->fpu_state); sf->fpu_save = &sf->fpu_state; } else { sf->fpu_save = NULL; } __put_user(oldset->sig[0], &sf->info.si_mask); __copy_to_user(sf->extramask, &oldset->sig[1], (_NSIG_WORDS - 1) * sizeof(unsigned int)); copy_to_user(sf, (char *) regs->u_regs [UREG_FP], sizeof (struct reg_window)); /* 3. signal handler back-trampoline and parameters */ regs->u_regs[UREG_FP] = (unsigned long) sf; regs->u_regs[UREG_I0] = signo; regs->u_regs[UREG_I1] = (unsigned long) &sf->info; /* 4. signal handler */ regs->pc = (unsigned long) ka->sa.sa_handler; regs->npc = (regs->pc + 4); /* 5. return to kernel instructions */ if (ka->ka_restorer) regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer; else { regs->u_regs[UREG_I7] = (unsigned long)(&(sf->insns[0]) - 2); __put_user(0x821020d8, &sf->insns[0]); /* mov __NR_sigreturn, %g1 */ __put_user(0x91d02010, &sf->insns[1]); /* t 0x10 */ /* Flush instruction space. */ flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0])); } return; sigill_and_return: lock_kernel(); do_exit(SIGILL); } static inline void new_setup_rt_frame(struct k_sigaction *ka, struct pt_regs *regs, int signo, sigset_t *oldset, siginfo_t *info) { printk("XXX: FIXME: new_setup_rt_frame unimplemented\n"); } /* Setup a Solaris stack frame */ static inline void setup_svr4_frame(struct sigaction *sa, unsigned long pc, unsigned long npc, struct pt_regs *regs, int signr, sigset_t *oldset) { svr4_signal_frame_t *sfp; svr4_gregset_t *gr; svr4_siginfo_t *si; svr4_mcontext_t *mc; svr4_gwindows_t *gw; svr4_ucontext_t *uc; svr4_sigset_t setv; int window = 0; synchronize_user_stack(); sfp = (svr4_signal_frame_t *) regs->u_regs[UREG_FP] - REGWIN_SZ; sfp = (svr4_signal_frame_t *) (((unsigned long) sfp)-SVR4_SF_ALIGNED); if (invalid_frame_pointer (sfp, sizeof (*sfp))){ #ifdef DEBUG_SIGNALS printk ("Invalid stack frame\n"); #endif goto sigill_and_return; } /* Start with a clean frame pointer and fill it */ clear_user(sfp, sizeof (*sfp)); /* Setup convenience variables */ si = &sfp->si; uc = &sfp->uc; gw = &sfp->gw; mc = &uc->mcontext; gr = &mc->greg; /* FIXME: where am I supposed to put this? * sc->sigc_onstack = old_status; * anyways, it does not look like it is used for anything at all. */ setv.sigbits[0] = oldset->sig[0]; setv.sigbits[1] = oldset->sig[1]; if (_NSIG_WORDS >= 4) { setv.sigbits[2] = oldset->sig[2]; setv.sigbits[3] = oldset->sig[3]; __copy_to_user(&uc->sigmask, &setv, sizeof(svr4_sigset_t)); } else __copy_to_user(&uc->sigmask, &setv, 2 * sizeof(unsigned int)); /* Store registers */ __put_user(regs->pc, &((*gr) [SVR4_PC])); __put_user(regs->npc, &((*gr) [SVR4_NPC])); __put_user(regs->psr, &((*gr) [SVR4_PSR])); __put_user(regs->y, &((*gr) [SVR4_Y])); /* Copy g [1..7] and o [0..7] registers */ copy_to_user(&(*gr)[SVR4_G1], ®s->u_regs [UREG_G1], sizeof (long) * 7); copy_to_user(&(*gr)[SVR4_O0], ®s->u_regs [UREG_I0], sizeof (long) * 8); /* Setup sigaltstack, FIXME */ __put_user(0xdeadbeef, &uc->stack.sp); __put_user(0, &uc->stack.size); __put_user(0, &uc->stack.flags); /* Possible: ONSTACK, DISABLE */ /* Save the currently window file: */ /* 1. Link sfp->uc->gwins to our windows */ __put_user(gw, &mc->gwin); /* 2. Number of windows to restore at setcontext (): */ __put_user(current->tss.w_saved, &gw->count); /* 3. Save each valid window * Currently, it makes a copy of the windows from the kernel copy. * David's code for SunOS, makes the copy but keeps the pointer to * the kernel. My version makes the pointer point to a userland * copy of those. Mhm, I wonder if I shouldn't just ignore those * on setcontext and use those that are on the kernel, the signal * handler should not be modyfing those, mhm. * * These windows are just used in case synchronize_user_stack failed * to flush the user windows. */ for(window = 0; window < current->tss.w_saved; window++) { __put_user((int *) &(gw->win [window]), &gw->winptr [window]); copy_to_user(&gw->win [window], ¤t->tss.reg_window [window], sizeof (svr4_rwindow_t)); __put_user(0, gw->winptr [window]); } /* 4. We just pay attention to the gw->count field on setcontext */ current->tss.w_saved = 0; /* So process is allowed to execute. */ /* Setup the signal information. Solaris expects a bunch of * information to be passed to the signal handler, we don't provide * that much currently, should use those that David already * is providing with tss.sig_desc */ __put_user(signr, &si->siginfo.signo); __put_user(SVR4_SINOINFO, &si->siginfo.code); regs->u_regs[UREG_FP] = (unsigned long) sfp; regs->pc = (unsigned long) sa->sa_handler; regs->npc = (regs->pc + 4); #ifdef DEBUG_SIGNALS printk ("Solaris-frame: %x %x\n", (int) regs->pc, (int) regs->npc); #endif /* Arguments passed to signal handler */ if (regs->u_regs [14]){ struct reg_window *rw = (struct reg_window *) regs->u_regs [14]; __put_user(signr, &rw->ins [0]); __put_user(si, &rw->ins [1]); __put_user(uc, &rw->ins [2]); __put_user(sfp, &rw->ins [6]); /* frame pointer */ regs->u_regs[UREG_I0] = signr; regs->u_regs[UREG_I1] = (uint) si; regs->u_regs[UREG_I2] = (uint) uc; } return; sigill_and_return: lock_kernel(); do_exit(SIGILL); } asmlinkage int svr4_getcontext (svr4_ucontext_t *uc, struct pt_regs *regs) { svr4_gregset_t *gr; svr4_mcontext_t *mc; svr4_sigset_t setv; synchronize_user_stack(); if (current->tss.w_saved) goto sigsegv_and_return; if(clear_user(uc, sizeof (*uc))) return -EFAULT; /* Setup convenience variables */ mc = &uc->mcontext; gr = &mc->greg; setv.sigbits[0] = current->blocked.sig[0]; setv.sigbits[1] = current->blocked.sig[1]; if (_NSIG_WORDS >= 4) { setv.sigbits[2] = current->blocked.sig[2]; setv.sigbits[3] = current->blocked.sig[3]; __copy_to_user(&uc->sigmask, &setv, sizeof(svr4_sigset_t)); } else __copy_to_user(&uc->sigmask, &setv, 2 * sizeof(unsigned int)); /* Store registers */ __put_user(regs->pc, &uc->mcontext.greg [SVR4_PC]); __put_user(regs->npc, &uc->mcontext.greg [SVR4_NPC]); __put_user(regs->psr, &uc->mcontext.greg [SVR4_PSR]); __put_user(regs->y, &uc->mcontext.greg [SVR4_Y]); /* Copy g [1..7] and o [0..7] registers */ copy_to_user(&(*gr)[SVR4_G1], ®s->u_regs [UREG_G1], sizeof (uint) * 7); copy_to_user(&(*gr)[SVR4_O0], ®s->u_regs [UREG_I0], sizeof (uint) * 8); /* Setup sigaltstack, FIXME */ __put_user(0xdeadbeef, &uc->stack.sp); __put_user(0, &uc->stack.size); __put_user(0, &uc->stack.flags); /* Possible: ONSTACK, DISABLE */ /* The register file is not saved * we have already stuffed all of it with sync_user_stack */ return 0; sigsegv_and_return: lock_kernel(); do_exit(SIGSEGV); } /* Set the context for a svr4 application, this is Solaris way to sigreturn */ asmlinkage int svr4_setcontext (svr4_ucontext_t *c, struct pt_regs *regs) { struct thread_struct *tp = ¤t->tss; svr4_gregset_t *gr; unsigned long pc, npc, psr; sigset_t set; svr4_sigset_t setv; /* Fixme: restore windows, or is this already taken care of in * svr4_setup_frame when sync_user_windows is done? */ flush_user_windows(); if (tp->w_saved) goto sigsegv_and_return; if (((uint) c) & 3) goto sigsegv_and_return; if(!__access_ok((unsigned long)c, sizeof(*c))) goto sigsegv_and_return; /* Check for valid PC and nPC */ gr = &c->mcontext.greg; __get_user(pc, &((*gr)[SVR4_PC])); __get_user(npc, &((*gr)[SVR4_NPC])); if((pc | npc) & 3) goto sigsegv_and_return; /* Retrieve information from passed ucontext */ /* note that nPC is ored a 1, this is used to inform entry.S */ /* that we don't want it to mess with our PC and nPC */ /* This is pretty much atomic, no amount locking would prevent * the races which exist anyways. */ if (__copy_from_user(&setv, &c->sigmask, sizeof(svr4_sigset_t))) goto sigsegv_and_return; set.sig[0] = setv.sigbits[0]; set.sig[1] = setv.sigbits[1]; if (_NSIG_WORDS >= 4) { set.sig[2] = setv.sigbits[2]; set.sig[3] = setv.sigbits[3]; } sigdelsetmask(&set, ~_BLOCKABLE); spin_lock_irq(¤t->sigmask_lock); current->blocked = set; recalc_sigpending(current); spin_unlock_irq(¤t->sigmask_lock); regs->pc = pc; regs->npc = npc | 1; __get_user(regs->y, &((*gr) [SVR4_Y])); __get_user(psr, &((*gr) [SVR4_PSR])); regs->psr &= ~(PSR_ICC); regs->psr |= (psr & PSR_ICC); /* Restore g[1..7] and o[0..7] registers */ copy_from_user(®s->u_regs [UREG_G1], &(*gr)[SVR4_G1], sizeof (long) * 7); copy_from_user(®s->u_regs [UREG_I0], &(*gr)[SVR4_O0], sizeof (long) * 8); return 0; sigsegv_and_return: lock_kernel(); do_exit(SIGSEGV); } static inline void handle_signal(unsigned long signr, struct k_sigaction *ka, siginfo_t *info, sigset_t *oldset, struct pt_regs *regs, int svr4_signal) { if (svr4_signal) setup_svr4_frame(&ka->sa, regs->pc, regs->npc, regs, signr, oldset); else { if (ka->sa.sa_flags & SA_SIGINFO) new_setup_rt_frame(ka, regs, signr, oldset, info); else if (current->tss.new_signal) new_setup_frame (ka, regs, signr, oldset); else setup_frame(&ka->sa, regs->pc, regs->npc, regs, signr, oldset); } if(ka->sa.sa_flags & SA_ONESHOT) ka->sa.sa_handler = SIG_DFL; if(!(ka->sa.sa_flags & SA_NOMASK)) { spin_lock_irq(¤t->sigmask_lock); sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask); sigaddset(¤t->blocked, signr); spin_unlock_irq(¤t->sigmask_lock); } } static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs, struct sigaction *sa) { switch(regs->u_regs[UREG_I0]) { case ERESTARTNOHAND: no_system_call_restart: regs->u_regs[UREG_I0] = EINTR; regs->psr |= PSR_C; break; case ERESTARTSYS: if(!(sa->sa_flags & SA_RESTART)) goto no_system_call_restart; /* fallthrough */ case ERESTARTNOINTR: regs->u_regs[UREG_I0] = orig_i0; regs->pc -= 4; regs->npc -= 4; } } /* Note that 'init' is a special process: it doesn't get signals it doesn't * want to handle. Thus you cannot kill init even with a SIGKILL even by * mistake. */ asmlinkage int do_signal(sigset_t *oldset, struct pt_regs * regs, unsigned long orig_i0, int restart_syscall) { unsigned long signr; struct k_sigaction *ka; siginfo_t info; int svr4_signal = current->personality == PER_SVR4; if (!oldset) oldset = ¤t->blocked; for (;;) { spin_lock_irq(¤t->sigmask_lock); signr = dequeue_signal(¤t->blocked, &info); spin_unlock_irq(¤t->sigmask_lock); if (!signr) break; if ((current->flags & PF_PTRACED) && signr != SIGKILL) { current->exit_code = signr; current->state = TASK_STOPPED; /* This happens to be SMP safe so no need to * grab master kernel lock even in this case. */ notify_parent(current, SIGCHLD); schedule(); if (!(signr = current->exit_code)) continue; current->exit_code = 0; if (signr == SIGSTOP) continue; /* Update the siginfo structure. Is this good? */ if (signr != info.si_signo) { info.si_signo = signr; info.si_errno = 0; info.si_code = SI_USER; info.si_pid = current->p_pptr->pid; info.si_uid = current->p_pptr->uid; } /* If the (new) signal is now blocked, requeue it. */ if (sigismember(¤t->blocked, signr)) { send_sig_info(signr, &info, current); continue; } } ka = ¤t->sig->action[signr-1]; if(ka->sa.sa_handler == SIG_IGN) { if(signr != SIGCHLD) continue; /* sys_wait4() grabs the master kernel lock, so * we need not do so, that sucker should be * threaded and would not be that difficult to * do anyways. */ while(sys_wait4(-1, NULL, WNOHANG, NULL) > 0) ; continue; } if(ka->sa.sa_handler == SIG_DFL) { unsigned long exit_code = signr; if(current->pid == 1) continue; switch(signr) { case SIGCONT: case SIGCHLD: case SIGWINCH: continue; case SIGTSTP: case SIGTTIN: case SIGTTOU: /* The operations performed by * is_orphaned_pgrp() are protected by * the tasklist_lock. */ if (is_orphaned_pgrp(current->pgrp)) continue; case SIGSTOP: if (current->flags & PF_PTRACED) continue; current->state = TASK_STOPPED; current->exit_code = signr; /* notify_parent() is SMP safe */ if(!(current->p_pptr->sig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDSTOP)) notify_parent(current, SIGCHLD); schedule(); continue; case SIGQUIT: case SIGILL: case SIGTRAP: case SIGABRT: case SIGFPE: case SIGSEGV: case SIGBUS: if(current->binfmt && current->binfmt->core_dump) { lock_kernel(); if(current->binfmt->core_dump(signr, regs)) exit_code |= 0x80; unlock_kernel(); } #ifdef DEBUG_SIGNALS /* Very useful to debug dynamic linker problems */ printk ("Sig ILL going...\n"); show_regs (regs); #endif /* fall through */ default: lock_kernel(); sigaddset(¤t->signal, signr); current->flags |= PF_SIGNALED; do_exit(exit_code); /* NOT REACHED */ } } if(restart_syscall) syscall_restart(orig_i0, regs, &ka->sa); handle_signal(signr, ka, &info, oldset, regs, svr4_signal); return 1; } if(restart_syscall && (regs->u_regs[UREG_I0] == ERESTARTNOHAND || regs->u_regs[UREG_I0] == ERESTARTSYS || regs->u_regs[UREG_I0] == ERESTARTNOINTR)) { /* replay the system call when we are done */ regs->u_regs[UREG_I0] = orig_i0; regs->pc -= 4; regs->npc -= 4; } return 0; } asmlinkage int sys_sigstack(struct sigstack *ssptr, struct sigstack *ossptr) { int ret = -EFAULT; lock_kernel(); /* First see if old state is wanted. */ if(ossptr) { if(copy_to_user(ossptr, ¤t->tss.sstk_info, sizeof(struct sigstack))) goto out; } /* Now see if we want to update the new state. */ if(ssptr) { if(copy_from_user(¤t->tss.sstk_info, ssptr, sizeof(struct sigstack))) goto out; } ret = 0; out: unlock_kernel(); return ret; } |