linux/arch/arm/kernel/signal.c
<<
>>
Prefs
   1/*
   2 *  linux/arch/arm/kernel/signal.c
   3 *
   4 *  Copyright (C) 1995-2009 Russell King
   5 *
   6 * This program is free software; you can redistribute it and/or modify
   7 * it under the terms of the GNU General Public License version 2 as
   8 * published by the Free Software Foundation.
   9 */
  10#include <linux/errno.h>
  11#include <linux/random.h>
  12#include <linux/signal.h>
  13#include <linux/personality.h>
  14#include <linux/uaccess.h>
  15#include <linux/tracehook.h>
  16#include <linux/uprobes.h>
  17
  18#include <asm/elf.h>
  19#include <asm/cacheflush.h>
  20#include <asm/traps.h>
  21#include <asm/ucontext.h>
  22#include <asm/unistd.h>
  23#include <asm/vfp.h>
  24
  25extern const unsigned long sigreturn_codes[7];
  26
  27static unsigned long signal_return_offset;
  28
  29#ifdef CONFIG_CRUNCH
  30static int preserve_crunch_context(struct crunch_sigframe __user *frame)
  31{
  32        char kbuf[sizeof(*frame) + 8];
  33        struct crunch_sigframe *kframe;
  34
  35        /* the crunch context must be 64 bit aligned */
  36        kframe = (struct crunch_sigframe *)((unsigned long)(kbuf + 8) & ~7);
  37        kframe->magic = CRUNCH_MAGIC;
  38        kframe->size = CRUNCH_STORAGE_SIZE;
  39        crunch_task_copy(current_thread_info(), &kframe->storage);
  40        return __copy_to_user(frame, kframe, sizeof(*frame));
  41}
  42
  43static int restore_crunch_context(char __user **auxp)
  44{
  45        struct crunch_sigframe __user *frame =
  46                (struct crunch_sigframe __user *)*auxp;
  47        char kbuf[sizeof(*frame) + 8];
  48        struct crunch_sigframe *kframe;
  49
  50        /* the crunch context must be 64 bit aligned */
  51        kframe = (struct crunch_sigframe *)((unsigned long)(kbuf + 8) & ~7);
  52        if (__copy_from_user(kframe, frame, sizeof(*frame)))
  53                return -1;
  54        if (kframe->magic != CRUNCH_MAGIC ||
  55            kframe->size != CRUNCH_STORAGE_SIZE)
  56                return -1;
  57        *auxp += CRUNCH_STORAGE_SIZE;
  58        crunch_task_restore(current_thread_info(), &kframe->storage);
  59        return 0;
  60}
  61#endif
  62
  63#ifdef CONFIG_IWMMXT
  64
  65static int preserve_iwmmxt_context(struct iwmmxt_sigframe __user *frame)
  66{
  67        char kbuf[sizeof(*frame) + 8];
  68        struct iwmmxt_sigframe *kframe;
  69        int err = 0;
  70
  71        /* the iWMMXt context must be 64 bit aligned */
  72        kframe = (struct iwmmxt_sigframe *)((unsigned long)(kbuf + 8) & ~7);
  73
  74        if (test_thread_flag(TIF_USING_IWMMXT)) {
  75                kframe->magic = IWMMXT_MAGIC;
  76                kframe->size = IWMMXT_STORAGE_SIZE;
  77                iwmmxt_task_copy(current_thread_info(), &kframe->storage);
  78
  79                err = __copy_to_user(frame, kframe, sizeof(*frame));
  80        } else {
  81                /*
  82                 * For bug-compatibility with older kernels, some space
  83                 * has to be reserved for iWMMXt even if it's not used.
  84                 * Set the magic and size appropriately so that properly
  85                 * written userspace can skip it reliably:
  86                 */
  87                __put_user_error(DUMMY_MAGIC, &frame->magic, err);
  88                __put_user_error(IWMMXT_STORAGE_SIZE, &frame->size, err);
  89        }
  90
  91        return err;
  92}
  93
  94static int restore_iwmmxt_context(char __user **auxp)
  95{
  96        struct iwmmxt_sigframe __user *frame =
  97                (struct iwmmxt_sigframe __user *)*auxp;
  98        char kbuf[sizeof(*frame) + 8];
  99        struct iwmmxt_sigframe *kframe;
 100
 101        /* the iWMMXt context must be 64 bit aligned */
 102        kframe = (struct iwmmxt_sigframe *)((unsigned long)(kbuf + 8) & ~7);
 103        if (__copy_from_user(kframe, frame, sizeof(*frame)))
 104                return -1;
 105
 106        /*
 107         * For non-iWMMXt threads: a single iwmmxt_sigframe-sized dummy
 108         * block is discarded for compatibility with setup_sigframe() if
 109         * present, but we don't mandate its presence.  If some other
 110         * magic is here, it's not for us:
 111         */
 112        if (!test_thread_flag(TIF_USING_IWMMXT) &&
 113            kframe->magic != DUMMY_MAGIC)
 114                return 0;
 115
 116        if (kframe->size != IWMMXT_STORAGE_SIZE)
 117                return -1;
 118
 119        if (test_thread_flag(TIF_USING_IWMMXT)) {
 120                if (kframe->magic != IWMMXT_MAGIC)
 121                        return -1;
 122
 123                iwmmxt_task_restore(current_thread_info(), &kframe->storage);
 124        }
 125
 126        *auxp += IWMMXT_STORAGE_SIZE;
 127        return 0;
 128}
 129
 130#endif
 131
 132#ifdef CONFIG_VFP
 133
 134static int preserve_vfp_context(struct vfp_sigframe __user *frame)
 135{
 136        const unsigned long magic = VFP_MAGIC;
 137        const unsigned long size = VFP_STORAGE_SIZE;
 138        int err = 0;
 139
 140        __put_user_error(magic, &frame->magic, err);
 141        __put_user_error(size, &frame->size, err);
 142
 143        if (err)
 144                return -EFAULT;
 145
 146        return vfp_preserve_user_clear_hwstate(&frame->ufp, &frame->ufp_exc);
 147}
 148
 149static int restore_vfp_context(char __user **auxp)
 150{
 151        struct vfp_sigframe __user *frame =
 152                (struct vfp_sigframe __user *)*auxp;
 153        unsigned long magic;
 154        unsigned long size;
 155        int err = 0;
 156
 157        __get_user_error(magic, &frame->magic, err);
 158        __get_user_error(size, &frame->size, err);
 159
 160        if (err)
 161                return -EFAULT;
 162        if (magic != VFP_MAGIC || size != VFP_STORAGE_SIZE)
 163                return -EINVAL;
 164
 165        *auxp += size;
 166        return vfp_restore_user_hwstate(&frame->ufp, &frame->ufp_exc);
 167}
 168
 169#endif
 170
 171/*
 172 * Do a signal return; undo the signal stack.  These are aligned to 64-bit.
 173 */
 174struct sigframe {
 175        struct ucontext uc;
 176        unsigned long retcode[2];
 177};
 178
 179struct rt_sigframe {
 180        struct siginfo info;
 181        struct sigframe sig;
 182};
 183
 184static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf)
 185{
 186        char __user *aux;
 187        sigset_t set;
 188        int err;
 189
 190        err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set));
 191        if (err == 0)
 192                set_current_blocked(&set);
 193
 194        __get_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err);
 195        __get_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err);
 196        __get_user_error(regs->ARM_r2, &sf->uc.uc_mcontext.arm_r2, err);
 197        __get_user_error(regs->ARM_r3, &sf->uc.uc_mcontext.arm_r3, err);
 198        __get_user_error(regs->ARM_r4, &sf->uc.uc_mcontext.arm_r4, err);
 199        __get_user_error(regs->ARM_r5, &sf->uc.uc_mcontext.arm_r5, err);
 200        __get_user_error(regs->ARM_r6, &sf->uc.uc_mcontext.arm_r6, err);
 201        __get_user_error(regs->ARM_r7, &sf->uc.uc_mcontext.arm_r7, err);
 202        __get_user_error(regs->ARM_r8, &sf->uc.uc_mcontext.arm_r8, err);
 203        __get_user_error(regs->ARM_r9, &sf->uc.uc_mcontext.arm_r9, err);
 204        __get_user_error(regs->ARM_r10, &sf->uc.uc_mcontext.arm_r10, err);
 205        __get_user_error(regs->ARM_fp, &sf->uc.uc_mcontext.arm_fp, err);
 206        __get_user_error(regs->ARM_ip, &sf->uc.uc_mcontext.arm_ip, err);
 207        __get_user_error(regs->ARM_sp, &sf->uc.uc_mcontext.arm_sp, err);
 208        __get_user_error(regs->ARM_lr, &sf->uc.uc_mcontext.arm_lr, err);
 209        __get_user_error(regs->ARM_pc, &sf->uc.uc_mcontext.arm_pc, err);
 210        __get_user_error(regs->ARM_cpsr, &sf->uc.uc_mcontext.arm_cpsr, err);
 211
 212        err |= !valid_user_regs(regs);
 213
 214        aux = (char __user *) sf->uc.uc_regspace;
 215#ifdef CONFIG_CRUNCH
 216        if (err == 0)
 217                err |= restore_crunch_context(&aux);
 218#endif
 219#ifdef CONFIG_IWMMXT
 220        if (err == 0)
 221                err |= restore_iwmmxt_context(&aux);
 222#endif
 223#ifdef CONFIG_VFP
 224        if (err == 0)
 225                err |= restore_vfp_context(&aux);
 226#endif
 227
 228        return err;
 229}
 230
 231asmlinkage int sys_sigreturn(struct pt_regs *regs)
 232{
 233        struct sigframe __user *frame;
 234
 235        /* Always make any pending restarted system calls return -EINTR */
 236        current->restart_block.fn = do_no_restart_syscall;
 237
 238        /*
 239         * Since we stacked the signal on a 64-bit boundary,
 240         * then 'sp' should be word aligned here.  If it's
 241         * not, then the user is trying to mess with us.
 242         */
 243        if (regs->ARM_sp & 7)
 244                goto badframe;
 245
 246        frame = (struct sigframe __user *)regs->ARM_sp;
 247
 248        if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
 249                goto badframe;
 250
 251        if (restore_sigframe(regs, frame))
 252                goto badframe;
 253
 254        return regs->ARM_r0;
 255
 256badframe:
 257        force_sig(SIGSEGV, current);
 258        return 0;
 259}
 260
 261asmlinkage int sys_rt_sigreturn(struct pt_regs *regs)
 262{
 263        struct rt_sigframe __user *frame;
 264
 265        /* Always make any pending restarted system calls return -EINTR */
 266        current->restart_block.fn = do_no_restart_syscall;
 267
 268        /*
 269         * Since we stacked the signal on a 64-bit boundary,
 270         * then 'sp' should be word aligned here.  If it's
 271         * not, then the user is trying to mess with us.
 272         */
 273        if (regs->ARM_sp & 7)
 274                goto badframe;
 275
 276        frame = (struct rt_sigframe __user *)regs->ARM_sp;
 277
 278        if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
 279                goto badframe;
 280
 281        if (restore_sigframe(regs, &frame->sig))
 282                goto badframe;
 283
 284        if (restore_altstack(&frame->sig.uc.uc_stack))
 285                goto badframe;
 286
 287        return regs->ARM_r0;
 288
 289badframe:
 290        force_sig(SIGSEGV, current);
 291        return 0;
 292}
 293
 294static int
 295setup_sigframe(struct sigframe __user *sf, struct pt_regs *regs, sigset_t *set)
 296{
 297        struct aux_sigframe __user *aux;
 298        int err = 0;
 299
 300        __put_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err);
 301        __put_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err);
 302        __put_user_error(regs->ARM_r2, &sf->uc.uc_mcontext.arm_r2, err);
 303        __put_user_error(regs->ARM_r3, &sf->uc.uc_mcontext.arm_r3, err);
 304        __put_user_error(regs->ARM_r4, &sf->uc.uc_mcontext.arm_r4, err);
 305        __put_user_error(regs->ARM_r5, &sf->uc.uc_mcontext.arm_r5, err);
 306        __put_user_error(regs->ARM_r6, &sf->uc.uc_mcontext.arm_r6, err);
 307        __put_user_error(regs->ARM_r7, &sf->uc.uc_mcontext.arm_r7, err);
 308        __put_user_error(regs->ARM_r8, &sf->uc.uc_mcontext.arm_r8, err);
 309        __put_user_error(regs->ARM_r9, &sf->uc.uc_mcontext.arm_r9, err);
 310        __put_user_error(regs->ARM_r10, &sf->uc.uc_mcontext.arm_r10, err);
 311        __put_user_error(regs->ARM_fp, &sf->uc.uc_mcontext.arm_fp, err);
 312        __put_user_error(regs->ARM_ip, &sf->uc.uc_mcontext.arm_ip, err);
 313        __put_user_error(regs->ARM_sp, &sf->uc.uc_mcontext.arm_sp, err);
 314        __put_user_error(regs->ARM_lr, &sf->uc.uc_mcontext.arm_lr, err);
 315        __put_user_error(regs->ARM_pc, &sf->uc.uc_mcontext.arm_pc, err);
 316        __put_user_error(regs->ARM_cpsr, &sf->uc.uc_mcontext.arm_cpsr, err);
 317
 318        __put_user_error(current->thread.trap_no, &sf->uc.uc_mcontext.trap_no, err);
 319        __put_user_error(current->thread.error_code, &sf->uc.uc_mcontext.error_code, err);
 320        __put_user_error(current->thread.address, &sf->uc.uc_mcontext.fault_address, err);
 321        __put_user_error(set->sig[0], &sf->uc.uc_mcontext.oldmask, err);
 322
 323        err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(*set));
 324
 325        aux = (struct aux_sigframe __user *) sf->uc.uc_regspace;
 326#ifdef CONFIG_CRUNCH
 327        if (err == 0)
 328                err |= preserve_crunch_context(&aux->crunch);
 329#endif
 330#ifdef CONFIG_IWMMXT
 331        if (err == 0)
 332                err |= preserve_iwmmxt_context(&aux->iwmmxt);
 333#endif
 334#ifdef CONFIG_VFP
 335        if (err == 0)
 336                err |= preserve_vfp_context(&aux->vfp);
 337#endif
 338        __put_user_error(0, &aux->end_magic, err);
 339
 340        return err;
 341}
 342
 343static inline void __user *
 344get_sigframe(struct ksignal *ksig, struct pt_regs *regs, int framesize)
 345{
 346        unsigned long sp = sigsp(regs->ARM_sp, ksig);
 347        void __user *frame;
 348
 349        /*
 350         * ATPCS B01 mandates 8-byte alignment
 351         */
 352        frame = (void __user *)((sp - framesize) & ~7);
 353
 354        /*
 355         * Check that we can actually write to the signal frame.
 356         */
 357        if (!access_ok(VERIFY_WRITE, frame, framesize))
 358                frame = NULL;
 359
 360        return frame;
 361}
 362
 363static int
 364setup_return(struct pt_regs *regs, struct ksignal *ksig,
 365             unsigned long __user *rc, void __user *frame)
 366{
 367        unsigned long handler = (unsigned long)ksig->ka.sa.sa_handler;
 368        unsigned long retcode;
 369        int thumb = 0;
 370        unsigned long cpsr = regs->ARM_cpsr & ~(PSR_f | PSR_E_BIT);
 371
 372        cpsr |= PSR_ENDSTATE;
 373
 374        /*
 375         * Maybe we need to deliver a 32-bit signal to a 26-bit task.
 376         */
 377        if (ksig->ka.sa.sa_flags & SA_THIRTYTWO)
 378                cpsr = (cpsr & ~MODE_MASK) | USR_MODE;
 379
 380#ifdef CONFIG_ARM_THUMB
 381        if (elf_hwcap & HWCAP_THUMB) {
 382                /*
 383                 * The LSB of the handler determines if we're going to
 384                 * be using THUMB or ARM mode for this signal handler.
 385                 */
 386                thumb = handler & 1;
 387
 388                /*
 389                 * Clear the If-Then Thumb-2 execution state.  ARM spec
 390                 * requires this to be all 000s in ARM mode.  Snapdragon
 391                 * S4/Krait misbehaves on a Thumb=>ARM signal transition
 392                 * without this.
 393                 *
 394                 * We must do this whenever we are running on a Thumb-2
 395                 * capable CPU, which includes ARMv6T2.  However, we elect
 396                 * to always do this to simplify the code; this field is
 397                 * marked UNK/SBZP for older architectures.
 398                 */
 399                cpsr &= ~PSR_IT_MASK;
 400
 401                if (thumb) {
 402                        cpsr |= PSR_T_BIT;
 403                } else
 404                        cpsr &= ~PSR_T_BIT;
 405        }
 406#endif
 407
 408        if (ksig->ka.sa.sa_flags & SA_RESTORER) {
 409                retcode = (unsigned long)ksig->ka.sa.sa_restorer;
 410        } else {
 411                unsigned int idx = thumb << 1;
 412
 413                if (ksig->ka.sa.sa_flags & SA_SIGINFO)
 414                        idx += 3;
 415
 416                /*
 417                 * Put the sigreturn code on the stack no matter which return
 418                 * mechanism we use in order to remain ABI compliant
 419                 */
 420                if (__put_user(sigreturn_codes[idx],   rc) ||
 421                    __put_user(sigreturn_codes[idx+1], rc+1))
 422                        return 1;
 423
 424#ifdef CONFIG_MMU
 425                if (cpsr & MODE32_BIT) {
 426                        struct mm_struct *mm = current->mm;
 427
 428                        /*
 429                         * 32-bit code can use the signal return page
 430                         * except when the MPU has protected the vectors
 431                         * page from PL0
 432                         */
 433                        retcode = mm->context.sigpage + signal_return_offset +
 434                                  (idx << 2) + thumb;
 435                } else
 436#endif
 437                {
 438                        /*
 439                         * Ensure that the instruction cache sees
 440                         * the return code written onto the stack.
 441                         */
 442                        flush_icache_range((unsigned long)rc,
 443                                           (unsigned long)(rc + 2));
 444
 445                        retcode = ((unsigned long)rc) + thumb;
 446                }
 447        }
 448
 449        regs->ARM_r0 = ksig->sig;
 450        regs->ARM_sp = (unsigned long)frame;
 451        regs->ARM_lr = retcode;
 452        regs->ARM_pc = handler;
 453        regs->ARM_cpsr = cpsr;
 454
 455        return 0;
 456}
 457
 458static int
 459setup_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs)
 460{
 461        struct sigframe __user *frame = get_sigframe(ksig, regs, sizeof(*frame));
 462        int err = 0;
 463
 464        if (!frame)
 465                return 1;
 466
 467        /*
 468         * Set uc.uc_flags to a value which sc.trap_no would never have.
 469         */
 470        __put_user_error(0x5ac3c35a, &frame->uc.uc_flags, err);
 471
 472        err |= setup_sigframe(frame, regs, set);
 473        if (err == 0)
 474                err = setup_return(regs, ksig, frame->retcode, frame);
 475
 476        return err;
 477}
 478
 479static int
 480setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs)
 481{
 482        struct rt_sigframe __user *frame = get_sigframe(ksig, regs, sizeof(*frame));
 483        int err = 0;
 484
 485        if (!frame)
 486                return 1;
 487
 488        err |= copy_siginfo_to_user(&frame->info, &ksig->info);
 489
 490        __put_user_error(0, &frame->sig.uc.uc_flags, err);
 491        __put_user_error(NULL, &frame->sig.uc.uc_link, err);
 492
 493        err |= __save_altstack(&frame->sig.uc.uc_stack, regs->ARM_sp);
 494        err |= setup_sigframe(&frame->sig, regs, set);
 495        if (err == 0)
 496                err = setup_return(regs, ksig, frame->sig.retcode, frame);
 497
 498        if (err == 0) {
 499                /*
 500                 * For realtime signals we must also set the second and third
 501                 * arguments for the signal handler.
 502                 *   -- Peter Maydell <pmaydell@chiark.greenend.org.uk> 2000-12-06
 503                 */
 504                regs->ARM_r1 = (unsigned long)&frame->info;
 505                regs->ARM_r2 = (unsigned long)&frame->sig.uc;
 506        }
 507
 508        return err;
 509}
 510
 511/*
 512 * OK, we're invoking a handler
 513 */     
 514static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
 515{
 516        sigset_t *oldset = sigmask_to_save();
 517        int ret;
 518
 519        /*
 520         * Set up the stack frame
 521         */
 522        if (ksig->ka.sa.sa_flags & SA_SIGINFO)
 523                ret = setup_rt_frame(ksig, oldset, regs);
 524        else
 525                ret = setup_frame(ksig, oldset, regs);
 526
 527        /*
 528         * Check that the resulting registers are actually sane.
 529         */
 530        ret |= !valid_user_regs(regs);
 531
 532        signal_setup_done(ret, ksig, 0);
 533}
 534
 535/*
 536 * Note that 'init' is a special process: it doesn't get signals it doesn't
 537 * want to handle. Thus you cannot kill init even with a SIGKILL even by
 538 * mistake.
 539 *
 540 * Note that we go through the signals twice: once to check the signals that
 541 * the kernel can handle, and then we build all the user-level signal handling
 542 * stack-frames in one go after that.
 543 */
 544static int do_signal(struct pt_regs *regs, int syscall)
 545{
 546        unsigned int retval = 0, continue_addr = 0, restart_addr = 0;
 547        struct ksignal ksig;
 548        int restart = 0;
 549
 550        /*
 551         * If we were from a system call, check for system call restarting...
 552         */
 553        if (syscall) {
 554                continue_addr = regs->ARM_pc;
 555                restart_addr = continue_addr - (thumb_mode(regs) ? 2 : 4);
 556                retval = regs->ARM_r0;
 557
 558                /*
 559                 * Prepare for system call restart.  We do this here so that a
 560                 * debugger will see the already changed PSW.
 561                 */
 562                switch (retval) {
 563                case -ERESTART_RESTARTBLOCK:
 564                        restart -= 2;
 565                case -ERESTARTNOHAND:
 566                case -ERESTARTSYS:
 567                case -ERESTARTNOINTR:
 568                        restart++;
 569                        regs->ARM_r0 = regs->ARM_ORIG_r0;
 570                        regs->ARM_pc = restart_addr;
 571                        break;
 572                }
 573        }
 574
 575        /*
 576         * Get the signal to deliver.  When running under ptrace, at this
 577         * point the debugger may change all our registers ...
 578         */
 579        /*
 580         * Depending on the signal settings we may need to revert the
 581         * decision to restart the system call.  But skip this if a
 582         * debugger has chosen to restart at a different PC.
 583         */
 584        if (get_signal(&ksig)) {
 585                /* handler */
 586                if (unlikely(restart) && regs->ARM_pc == restart_addr) {
 587                        if (retval == -ERESTARTNOHAND ||
 588                            retval == -ERESTART_RESTARTBLOCK
 589                            || (retval == -ERESTARTSYS
 590                                && !(ksig.ka.sa.sa_flags & SA_RESTART))) {
 591                                regs->ARM_r0 = -EINTR;
 592                                regs->ARM_pc = continue_addr;
 593                        }
 594                }
 595                handle_signal(&ksig, regs);
 596        } else {
 597                /* no handler */
 598                restore_saved_sigmask();
 599                if (unlikely(restart) && regs->ARM_pc == restart_addr) {
 600                        regs->ARM_pc = continue_addr;
 601                        return restart;
 602                }
 603        }
 604        return 0;
 605}
 606
 607asmlinkage int
 608do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
 609{
 610        /*
 611         * The assembly code enters us with IRQs off, but it hasn't
 612         * informed the tracing code of that for efficiency reasons.
 613         * Update the trace code with the current status.
 614         */
 615        trace_hardirqs_off();
 616        do {
 617                if (likely(thread_flags & _TIF_NEED_RESCHED)) {
 618                        schedule();
 619                } else {
 620                        if (unlikely(!user_mode(regs)))
 621                                return 0;
 622                        local_irq_enable();
 623                        if (thread_flags & _TIF_SIGPENDING) {
 624                                int restart = do_signal(regs, syscall);
 625                                if (unlikely(restart)) {
 626                                        /*
 627                                         * Restart without handlers.
 628                                         * Deal with it without leaving
 629                                         * the kernel space.
 630                                         */
 631                                        return restart;
 632                                }
 633                                syscall = 0;
 634                        } else if (thread_flags & _TIF_UPROBE) {
 635                                uprobe_notify_resume(regs);
 636                        } else {
 637                                clear_thread_flag(TIF_NOTIFY_RESUME);
 638                                tracehook_notify_resume(regs);
 639                        }
 640                }
 641                local_irq_disable();
 642                thread_flags = current_thread_info()->flags;
 643        } while (thread_flags & _TIF_WORK_MASK);
 644        return 0;
 645}
 646
 647struct page *get_signal_page(void)
 648{
 649        unsigned long ptr;
 650        unsigned offset;
 651        struct page *page;
 652        void *addr;
 653
 654        page = alloc_pages(GFP_KERNEL, 0);
 655
 656        if (!page)
 657                return NULL;
 658
 659        addr = page_address(page);
 660
 661        /* Give the signal return code some randomness */
 662        offset = 0x200 + (get_random_int() & 0x7fc);
 663        signal_return_offset = offset;
 664
 665        /*
 666         * Copy signal return handlers into the vector page, and
 667         * set sigreturn to be a pointer to these.
 668         */
 669        memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
 670
 671        ptr = (unsigned long)addr + offset;
 672        flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
 673
 674        return page;
 675}
 676