linux/arch/sparc/kernel/signal_32.c
<<
>>
Prefs
   1/*  linux/arch/sparc/kernel/signal.c
   2 *
   3 *  Copyright (C) 1991, 1992  Linus Torvalds
   4 *  Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
   5 *  Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
   6 *  Copyright (C) 1997 Eddie C. Dost   (ecd@skynet.be)
   7 */
   8
   9#include <linux/sched.h>
  10#include <linux/kernel.h>
  11#include <linux/signal.h>
  12#include <linux/errno.h>
  13#include <linux/wait.h>
  14#include <linux/ptrace.h>
  15#include <linux/unistd.h>
  16#include <linux/mm.h>
  17#include <linux/tty.h>
  18#include <linux/smp.h>
  19#include <linux/binfmts.h>      /* do_coredum */
  20#include <linux/bitops.h>
  21#include <linux/tracehook.h>
  22
  23#include <asm/uaccess.h>
  24#include <asm/ptrace.h>
  25#include <asm/pgalloc.h>
  26#include <asm/pgtable.h>
  27#include <asm/cacheflush.h>     /* flush_sig_insns */
  28#include <asm/switch_to.h>
  29
  30#include "sigutil.h"
  31
  32#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
  33
  34extern void fpsave(unsigned long *fpregs, unsigned long *fsr,
  35                   void *fpqueue, unsigned long *fpqdepth);
  36extern void fpload(unsigned long *fpregs, unsigned long *fsr);
  37
  38struct signal_frame {
  39        struct sparc_stackf     ss;
  40        __siginfo32_t           info;
  41        __siginfo_fpu_t __user  *fpu_save;
  42        unsigned long           insns[2] __attribute__ ((aligned (8)));
  43        unsigned int            extramask[_NSIG_WORDS - 1];
  44        unsigned int            extra_size; /* Should be 0 */
  45        __siginfo_rwin_t __user *rwin_save;
  46} __attribute__((aligned(8)));
  47
  48struct rt_signal_frame {
  49        struct sparc_stackf     ss;
  50        siginfo_t               info;
  51        struct pt_regs          regs;
  52        sigset_t                mask;
  53        __siginfo_fpu_t __user  *fpu_save;
  54        unsigned int            insns[2];
  55        stack_t                 stack;
  56        unsigned int            extra_size; /* Should be 0 */
  57        __siginfo_rwin_t __user *rwin_save;
  58} __attribute__((aligned(8)));
  59
  60/* Align macros */
  61#define SF_ALIGNEDSZ  (((sizeof(struct signal_frame) + 7) & (~7)))
  62#define RT_ALIGNEDSZ  (((sizeof(struct rt_signal_frame) + 7) & (~7)))
  63
  64static int _sigpause_common(old_sigset_t set)
  65{
  66        sigset_t blocked;
  67
  68        current->saved_sigmask = current->blocked;
  69
  70        set &= _BLOCKABLE;
  71        siginitset(&blocked, set);
  72        set_current_blocked(&blocked);
  73
  74        current->state = TASK_INTERRUPTIBLE;
  75        schedule();
  76        set_thread_flag(TIF_RESTORE_SIGMASK);
  77
  78        return -ERESTARTNOHAND;
  79}
  80
  81asmlinkage int sys_sigsuspend(old_sigset_t set)
  82{
  83        return _sigpause_common(set);
  84}
  85
  86asmlinkage void do_sigreturn(struct pt_regs *regs)
  87{
  88        struct signal_frame __user *sf;
  89        unsigned long up_psr, pc, npc;
  90        sigset_t set;
  91        __siginfo_fpu_t __user *fpu_save;
  92        __siginfo_rwin_t __user *rwin_save;
  93        int err;
  94
  95        /* Always make any pending restarted system calls return -EINTR */
  96        current_thread_info()->restart_block.fn = do_no_restart_syscall;
  97
  98        synchronize_user_stack();
  99
 100        sf = (struct signal_frame __user *) regs->u_regs[UREG_FP];
 101
 102        /* 1. Make sure we are not getting garbage from the user */
 103        if (!access_ok(VERIFY_READ, sf, sizeof(*sf)))
 104                goto segv_and_exit;
 105
 106        if (((unsigned long) sf) & 3)
 107                goto segv_and_exit;
 108
 109        err = __get_user(pc,  &sf->info.si_regs.pc);
 110        err |= __get_user(npc, &sf->info.si_regs.npc);
 111
 112        if ((pc | npc) & 3)
 113                goto segv_and_exit;
 114
 115        /* 2. Restore the state */
 116        up_psr = regs->psr;
 117        err |= __copy_from_user(regs, &sf->info.si_regs, sizeof(struct pt_regs));
 118
 119        /* User can only change condition codes and FPU enabling in %psr. */
 120        regs->psr = (up_psr & ~(PSR_ICC | PSR_EF))
 121                  | (regs->psr & (PSR_ICC | PSR_EF));
 122
 123        /* Prevent syscall restart.  */
 124        pt_regs_clear_syscall(regs);
 125
 126        err |= __get_user(fpu_save, &sf->fpu_save);
 127        if (fpu_save)
 128                err |= restore_fpu_state(regs, fpu_save);
 129        err |= __get_user(rwin_save, &sf->rwin_save);
 130        if (rwin_save)
 131                err |= restore_rwin_state(rwin_save);
 132
 133        /* This is pretty much atomic, no amount locking would prevent
 134         * the races which exist anyways.
 135         */
 136        err |= __get_user(set.sig[0], &sf->info.si_mask);
 137        err |= __copy_from_user(&set.sig[1], &sf->extramask,
 138                                (_NSIG_WORDS-1) * sizeof(unsigned int));
 139                           
 140        if (err)
 141                goto segv_and_exit;
 142
 143        sigdelsetmask(&set, ~_BLOCKABLE);
 144        set_current_blocked(&set);
 145        return;
 146
 147segv_and_exit:
 148        force_sig(SIGSEGV, current);
 149}
 150
 151asmlinkage void do_rt_sigreturn(struct pt_regs *regs)
 152{
 153        struct rt_signal_frame __user *sf;
 154        unsigned int psr, pc, npc;
 155        __siginfo_fpu_t __user *fpu_save;
 156        __siginfo_rwin_t __user *rwin_save;
 157        mm_segment_t old_fs;
 158        sigset_t set;
 159        stack_t st;
 160        int err;
 161
 162        synchronize_user_stack();
 163        sf = (struct rt_signal_frame __user *) regs->u_regs[UREG_FP];
 164        if (!access_ok(VERIFY_READ, sf, sizeof(*sf)) ||
 165            (((unsigned long) sf) & 0x03))
 166                goto segv;
 167
 168        err = __get_user(pc, &sf->regs.pc);
 169        err |= __get_user(npc, &sf->regs.npc);
 170        err |= ((pc | npc) & 0x03);
 171
 172        err |= __get_user(regs->y, &sf->regs.y);
 173        err |= __get_user(psr, &sf->regs.psr);
 174
 175        err |= __copy_from_user(&regs->u_regs[UREG_G1],
 176                                &sf->regs.u_regs[UREG_G1], 15 * sizeof(u32));
 177
 178        regs->psr = (regs->psr & ~PSR_ICC) | (psr & PSR_ICC);
 179
 180        /* Prevent syscall restart.  */
 181        pt_regs_clear_syscall(regs);
 182
 183        err |= __get_user(fpu_save, &sf->fpu_save);
 184        if (!err && fpu_save)
 185                err |= restore_fpu_state(regs, fpu_save);
 186        err |= __copy_from_user(&set, &sf->mask, sizeof(sigset_t));
 187        
 188        err |= __copy_from_user(&st, &sf->stack, sizeof(stack_t));
 189        
 190        if (err)
 191                goto segv;
 192                
 193        regs->pc = pc;
 194        regs->npc = npc;
 195        
 196        /* It is more difficult to avoid calling this function than to
 197         * call it and ignore errors.
 198         */
 199        old_fs = get_fs();
 200        set_fs(KERNEL_DS);
 201        do_sigaltstack((const stack_t __user *) &st, NULL, (unsigned long)sf);
 202        set_fs(old_fs);
 203
 204        err |= __get_user(rwin_save, &sf->rwin_save);
 205        if (!err && rwin_save) {
 206                if (restore_rwin_state(rwin_save))
 207                        goto segv;
 208        }
 209
 210        sigdelsetmask(&set, ~_BLOCKABLE);
 211        set_current_blocked(&set);
 212        return;
 213segv:
 214        force_sig(SIGSEGV, current);
 215}
 216
 217/* Checks if the fp is valid */
 218static inline int invalid_frame_pointer(void __user *fp, int fplen)
 219{
 220        if ((((unsigned long) fp) & 7) ||
 221            !__access_ok((unsigned long)fp, fplen) ||
 222            ((sparc_cpu_model == sun4 || sparc_cpu_model == sun4c) &&
 223             ((unsigned long) fp < 0xe0000000 && (unsigned long) fp >= 0x20000000)))
 224                return 1;
 225        
 226        return 0;
 227}
 228
 229static inline void __user *get_sigframe(struct sigaction *sa, struct pt_regs *regs, unsigned long framesize)
 230{
 231        unsigned long sp = regs->u_regs[UREG_FP];
 232
 233        /*
 234         * If we are on the alternate signal stack and would overflow it, don't.
 235         * Return an always-bogus address instead so we will die with SIGSEGV.
 236         */
 237        if (on_sig_stack(sp) && !likely(on_sig_stack(sp - framesize)))
 238                return (void __user *) -1L;
 239
 240        /* This is the X/Open sanctioned signal stack switching.  */
 241        if (sa->sa_flags & SA_ONSTACK) {
 242                if (sas_ss_flags(sp) == 0)
 243                        sp = current->sas_ss_sp + current->sas_ss_size;
 244        }
 245
 246        sp -= framesize;
 247
 248        /* Always align the stack frame.  This handles two cases.  First,
 249         * sigaltstack need not be mindful of platform specific stack
 250         * alignment.  Second, if we took this signal because the stack
 251         * is not aligned properly, we'd like to take the signal cleanly
 252         * and report that.
 253         */
 254        sp &= ~15UL;
 255
 256        return (void __user *) sp;
 257}
 258
 259static int setup_frame(struct k_sigaction *ka, struct pt_regs *regs,
 260                       int signo, sigset_t *oldset)
 261{
 262        struct signal_frame __user *sf;
 263        int sigframe_size, err, wsaved;
 264        void __user *tail;
 265
 266        /* 1. Make sure everything is clean */
 267        synchronize_user_stack();
 268
 269        wsaved = current_thread_info()->w_saved;
 270
 271        sigframe_size = sizeof(*sf);
 272        if (used_math())
 273                sigframe_size += sizeof(__siginfo_fpu_t);
 274        if (wsaved)
 275                sigframe_size += sizeof(__siginfo_rwin_t);
 276
 277        sf = (struct signal_frame __user *)
 278                get_sigframe(&ka->sa, regs, sigframe_size);
 279
 280        if (invalid_frame_pointer(sf, sigframe_size))
 281                goto sigill_and_return;
 282
 283        tail = sf + 1;
 284
 285        /* 2. Save the current process state */
 286        err = __copy_to_user(&sf->info.si_regs, regs, sizeof(struct pt_regs));
 287        
 288        err |= __put_user(0, &sf->extra_size);
 289
 290        if (used_math()) {
 291                __siginfo_fpu_t __user *fp = tail;
 292                tail += sizeof(*fp);
 293                err |= save_fpu_state(regs, fp);
 294                err |= __put_user(fp, &sf->fpu_save);
 295        } else {
 296                err |= __put_user(0, &sf->fpu_save);
 297        }
 298        if (wsaved) {
 299                __siginfo_rwin_t __user *rwp = tail;
 300                tail += sizeof(*rwp);
 301                err |= save_rwin_state(wsaved, rwp);
 302                err |= __put_user(rwp, &sf->rwin_save);
 303        } else {
 304                err |= __put_user(0, &sf->rwin_save);
 305        }
 306
 307        err |= __put_user(oldset->sig[0], &sf->info.si_mask);
 308        err |= __copy_to_user(sf->extramask, &oldset->sig[1],
 309                              (_NSIG_WORDS - 1) * sizeof(unsigned int));
 310        if (!wsaved) {
 311                err |= __copy_to_user(sf, (char *) regs->u_regs[UREG_FP],
 312                                      sizeof(struct reg_window32));
 313        } else {
 314                struct reg_window32 *rp;
 315
 316                rp = &current_thread_info()->reg_window[wsaved - 1];
 317                err |= __copy_to_user(sf, rp, sizeof(struct reg_window32));
 318        }
 319        if (err)
 320                goto sigsegv;
 321        
 322        /* 3. signal handler back-trampoline and parameters */
 323        regs->u_regs[UREG_FP] = (unsigned long) sf;
 324        regs->u_regs[UREG_I0] = signo;
 325        regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
 326        regs->u_regs[UREG_I2] = (unsigned long) &sf->info;
 327
 328        /* 4. signal handler */
 329        regs->pc = (unsigned long) ka->sa.sa_handler;
 330        regs->npc = (regs->pc + 4);
 331
 332        /* 5. return to kernel instructions */
 333        if (ka->ka_restorer)
 334                regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
 335        else {
 336                regs->u_regs[UREG_I7] = (unsigned long)(&(sf->insns[0]) - 2);
 337
 338                /* mov __NR_sigreturn, %g1 */
 339                err |= __put_user(0x821020d8, &sf->insns[0]);
 340
 341                /* t 0x10 */
 342                err |= __put_user(0x91d02010, &sf->insns[1]);
 343                if (err)
 344                        goto sigsegv;
 345
 346                /* Flush instruction space. */
 347                flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
 348        }
 349        return 0;
 350
 351sigill_and_return:
 352        do_exit(SIGILL);
 353        return -EINVAL;
 354
 355sigsegv:
 356        force_sigsegv(signo, current);
 357        return -EFAULT;
 358}
 359
 360static int setup_rt_frame(struct k_sigaction *ka, struct pt_regs *regs,
 361                          int signo, sigset_t *oldset, siginfo_t *info)
 362{
 363        struct rt_signal_frame __user *sf;
 364        int sigframe_size, wsaved;
 365        void __user *tail;
 366        unsigned int psr;
 367        int err;
 368
 369        synchronize_user_stack();
 370        wsaved = current_thread_info()->w_saved;
 371        sigframe_size = sizeof(*sf);
 372        if (used_math())
 373                sigframe_size += sizeof(__siginfo_fpu_t);
 374        if (wsaved)
 375                sigframe_size += sizeof(__siginfo_rwin_t);
 376        sf = (struct rt_signal_frame __user *)
 377                get_sigframe(&ka->sa, regs, sigframe_size);
 378        if (invalid_frame_pointer(sf, sigframe_size))
 379                goto sigill;
 380
 381        tail = sf + 1;
 382        err  = __put_user(regs->pc, &sf->regs.pc);
 383        err |= __put_user(regs->npc, &sf->regs.npc);
 384        err |= __put_user(regs->y, &sf->regs.y);
 385        psr = regs->psr;
 386        if (used_math())
 387                psr |= PSR_EF;
 388        err |= __put_user(psr, &sf->regs.psr);
 389        err |= __copy_to_user(&sf->regs.u_regs, regs->u_regs, sizeof(regs->u_regs));
 390        err |= __put_user(0, &sf->extra_size);
 391
 392        if (psr & PSR_EF) {
 393                __siginfo_fpu_t *fp = tail;
 394                tail += sizeof(*fp);
 395                err |= save_fpu_state(regs, fp);
 396                err |= __put_user(fp, &sf->fpu_save);
 397        } else {
 398                err |= __put_user(0, &sf->fpu_save);
 399        }
 400        if (wsaved) {
 401                __siginfo_rwin_t *rwp = tail;
 402                tail += sizeof(*rwp);
 403                err |= save_rwin_state(wsaved, rwp);
 404                err |= __put_user(rwp, &sf->rwin_save);
 405        } else {
 406                err |= __put_user(0, &sf->rwin_save);
 407        }
 408        err |= __copy_to_user(&sf->mask, &oldset->sig[0], sizeof(sigset_t));
 409        
 410        /* Setup sigaltstack */
 411        err |= __put_user(current->sas_ss_sp, &sf->stack.ss_sp);
 412        err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &sf->stack.ss_flags);
 413        err |= __put_user(current->sas_ss_size, &sf->stack.ss_size);
 414        
 415        if (!wsaved) {
 416                err |= __copy_to_user(sf, (char *) regs->u_regs[UREG_FP],
 417                                      sizeof(struct reg_window32));
 418        } else {
 419                struct reg_window32 *rp;
 420
 421                rp = &current_thread_info()->reg_window[wsaved - 1];
 422                err |= __copy_to_user(sf, rp, sizeof(struct reg_window32));
 423        }
 424
 425        err |= copy_siginfo_to_user(&sf->info, info);
 426
 427        if (err)
 428                goto sigsegv;
 429
 430        regs->u_regs[UREG_FP] = (unsigned long) sf;
 431        regs->u_regs[UREG_I0] = signo;
 432        regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
 433        regs->u_regs[UREG_I2] = (unsigned long) &sf->regs;
 434
 435        regs->pc = (unsigned long) ka->sa.sa_handler;
 436        regs->npc = (regs->pc + 4);
 437
 438        if (ka->ka_restorer)
 439                regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
 440        else {
 441                regs->u_regs[UREG_I7] = (unsigned long)(&(sf->insns[0]) - 2);
 442
 443                /* mov __NR_sigreturn, %g1 */
 444                err |= __put_user(0x821020d8, &sf->insns[0]);
 445
 446                /* t 0x10 */
 447                err |= __put_user(0x91d02010, &sf->insns[1]);
 448                if (err)
 449                        goto sigsegv;
 450
 451                /* Flush instruction space. */
 452                flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
 453        }
 454        return 0;
 455
 456sigill:
 457        do_exit(SIGILL);
 458        return -EINVAL;
 459
 460sigsegv:
 461        force_sigsegv(signo, current);
 462        return -EFAULT;
 463}
 464
 465static inline int
 466handle_signal(unsigned long signr, struct k_sigaction *ka,
 467              siginfo_t *info, sigset_t *oldset, struct pt_regs *regs)
 468{
 469        int err;
 470
 471        if (ka->sa.sa_flags & SA_SIGINFO)
 472                err = setup_rt_frame(ka, regs, signr, oldset, info);
 473        else
 474                err = setup_frame(ka, regs, signr, oldset);
 475
 476        if (err)
 477                return err;
 478
 479        block_sigmask(ka, signr);
 480        tracehook_signal_handler(signr, info, ka, regs, 0);
 481
 482        return 0;
 483}
 484
 485static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs,
 486                                   struct sigaction *sa)
 487{
 488        switch(regs->u_regs[UREG_I0]) {
 489        case ERESTART_RESTARTBLOCK:
 490        case ERESTARTNOHAND:
 491        no_system_call_restart:
 492                regs->u_regs[UREG_I0] = EINTR;
 493                regs->psr |= PSR_C;
 494                break;
 495        case ERESTARTSYS:
 496                if (!(sa->sa_flags & SA_RESTART))
 497                        goto no_system_call_restart;
 498                /* fallthrough */
 499        case ERESTARTNOINTR:
 500                regs->u_regs[UREG_I0] = orig_i0;
 501                regs->pc -= 4;
 502                regs->npc -= 4;
 503        }
 504}
 505
 506/* Note that 'init' is a special process: it doesn't get signals it doesn't
 507 * want to handle. Thus you cannot kill init even with a SIGKILL even by
 508 * mistake.
 509 */
 510static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
 511{
 512        struct k_sigaction ka;
 513        int restart_syscall;
 514        sigset_t *oldset;
 515        siginfo_t info;
 516        int signr;
 517
 518        /* It's a lot of work and synchronization to add a new ptrace
 519         * register for GDB to save and restore in order to get
 520         * orig_i0 correct for syscall restarts when debugging.
 521         *
 522         * Although it should be the case that most of the global
 523         * registers are volatile across a system call, glibc already
 524         * depends upon that fact that we preserve them.  So we can't
 525         * just use any global register to save away the orig_i0 value.
 526         *
 527         * In particular %g2, %g3, %g4, and %g5 are all assumed to be
 528         * preserved across a system call trap by various pieces of
 529         * code in glibc.
 530         *
 531         * %g7 is used as the "thread register".   %g6 is not used in
 532         * any fixed manner.  %g6 is used as a scratch register and
 533         * a compiler temporary, but it's value is never used across
 534         * a system call.  Therefore %g6 is usable for orig_i0 storage.
 535         */
 536        if (pt_regs_is_syscall(regs) && (regs->psr & PSR_C))
 537                regs->u_regs[UREG_G6] = orig_i0;
 538
 539        if (test_thread_flag(TIF_RESTORE_SIGMASK))
 540                oldset = &current->saved_sigmask;
 541        else
 542                oldset = &current->blocked;
 543
 544        signr = get_signal_to_deliver(&info, &ka, regs, NULL);
 545
 546        /* If the debugger messes with the program counter, it clears
 547         * the software "in syscall" bit, directing us to not perform
 548         * a syscall restart.
 549         */
 550        restart_syscall = 0;
 551        if (pt_regs_is_syscall(regs) && (regs->psr & PSR_C)) {
 552                restart_syscall = 1;
 553                orig_i0 = regs->u_regs[UREG_G6];
 554        }
 555
 556
 557        if (signr > 0) {
 558                if (restart_syscall)
 559                        syscall_restart(orig_i0, regs, &ka.sa);
 560                if (handle_signal(signr, &ka, &info, oldset, regs) == 0) {
 561                        /* a signal was successfully delivered; the saved
 562                         * sigmask will have been stored in the signal frame,
 563                         * and will be restored by sigreturn, so we can simply
 564                         * clear the TIF_RESTORE_SIGMASK flag.
 565                         */
 566                        if (test_thread_flag(TIF_RESTORE_SIGMASK))
 567                                clear_thread_flag(TIF_RESTORE_SIGMASK);
 568                }
 569                return;
 570        }
 571        if (restart_syscall &&
 572            (regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
 573             regs->u_regs[UREG_I0] == ERESTARTSYS ||
 574             regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
 575                /* replay the system call when we are done */
 576                regs->u_regs[UREG_I0] = orig_i0;
 577                regs->pc -= 4;
 578                regs->npc -= 4;
 579                pt_regs_clear_syscall(regs);
 580        }
 581        if (restart_syscall &&
 582            regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
 583                regs->u_regs[UREG_G1] = __NR_restart_syscall;
 584                regs->pc -= 4;
 585                regs->npc -= 4;
 586                pt_regs_clear_syscall(regs);
 587        }
 588
 589        /* if there's no signal to deliver, we just put the saved sigmask
 590         * back
 591         */
 592        if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
 593                clear_thread_flag(TIF_RESTORE_SIGMASK);
 594                set_current_blocked(&current->saved_sigmask);
 595        }
 596}
 597
 598void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0,
 599                      unsigned long thread_info_flags)
 600{
 601        if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
 602                do_signal(regs, orig_i0);
 603        if (thread_info_flags & _TIF_NOTIFY_RESUME) {
 604                clear_thread_flag(TIF_NOTIFY_RESUME);
 605                tracehook_notify_resume(regs);
 606                if (current->replacement_session_keyring)
 607                        key_replace_session_keyring();
 608        }
 609}
 610
 611asmlinkage int
 612do_sys_sigstack(struct sigstack __user *ssptr, struct sigstack __user *ossptr,
 613                unsigned long sp)
 614{
 615        int ret = -EFAULT;
 616
 617        /* First see if old state is wanted. */
 618        if (ossptr) {
 619                if (put_user(current->sas_ss_sp + current->sas_ss_size,
 620                             &ossptr->the_stack) ||
 621                    __put_user(on_sig_stack(sp), &ossptr->cur_status))
 622                        goto out;
 623        }
 624
 625        /* Now see if we want to update the new state. */
 626        if (ssptr) {
 627                char *ss_sp;
 628
 629                if (get_user(ss_sp, &ssptr->the_stack))
 630                        goto out;
 631                /* If the current stack was set with sigaltstack, don't
 632                   swap stacks while we are on it.  */
 633                ret = -EPERM;
 634                if (current->sas_ss_sp && on_sig_stack(sp))
 635                        goto out;
 636
 637                /* Since we don't know the extent of the stack, and we don't
 638                   track onstack-ness, but rather calculate it, we must
 639                   presume a size.  Ho hum this interface is lossy.  */
 640                current->sas_ss_sp = (unsigned long)ss_sp - SIGSTKSZ;
 641                current->sas_ss_size = SIGSTKSZ;
 642        }
 643        ret = 0;
 644out:
 645        return ret;
 646}
 647