root/arch/mips/kernel/signal.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sys_sigsuspend
  2. sys_sigreturn
  3. setup_frame
  4. do_signal

   1 /*
   2  *  linux/arch/mips/kernel/signal.c
   3  *
   4  *  Copyright (C) 1991, 1992  Linus Torvalds
   5  */
   6 
   7 #include <linux/sched.h>
   8 #include <linux/kernel.h>
   9 #include <linux/signal.h>
  10 #include <linux/errno.h>
  11 #include <linux/wait.h>
  12 #include <linux/ptrace.h>
  13 #include <linux/unistd.h>
  14 
  15 #include <asm/segment.h>
  16 #include <asm/cachectl.h>
  17 
  18 #define _S(nr) (1<<((nr)-1))
  19 
  20 #define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
  21 
  22 asmlinkage int sys_waitpid(pid_t pid,unsigned long * stat_addr, int options);
  23 
  24 /*
  25  * atomically swap in the new signal mask, and wait for a signal.
  26  */
  27 asmlinkage int sys_sigsuspend(int restart, unsigned long oldmask, unsigned long set)
     /* [previous][next][first][last][top][bottom][index][help] */
  28 {
  29         unsigned long mask;
  30         struct pt_regs * regs = (struct pt_regs *) &restart;
  31 
  32         mask = current->blocked;
  33         current->blocked = set & _BLOCKABLE;
  34         regs->reg2 = -EINTR;
  35         while (1) {
  36                 current->state = TASK_INTERRUPTIBLE;
  37                 schedule();
  38                 if (do_signal(mask,regs))
  39                         return -EINTR;
  40         }
  41 }
  42 
  43 /*
  44  * This sets regs->reg29 even though we don't actually use sigstacks yet..
  45  */
  46 asmlinkage int sys_sigreturn(unsigned long __unused)
     /* [previous][next][first][last][top][bottom][index][help] */
  47 {
  48         struct sigcontext_struct context;
  49         struct pt_regs * regs;
  50 
  51         regs = (struct pt_regs *) &__unused;
  52         if (verify_area(VERIFY_READ, (void *) regs->reg29, sizeof(context)))
  53                 goto badframe;
  54         memcpy_fromfs(&context,(void *) regs->reg29, sizeof(context));
  55         current->blocked = context.oldmask & _BLOCKABLE;
  56         regs->reg1  = context.sc_at;
  57         regs->reg2  = context.sc_v0;
  58         regs->reg3  = context.sc_v1;
  59         regs->reg4  = context.sc_a0;
  60         regs->reg5  = context.sc_a1;
  61         regs->reg6  = context.sc_a2;
  62         regs->reg7  = context.sc_a3;
  63         regs->reg8  = context.sc_t0;
  64         regs->reg9  = context.sc_t1;
  65         regs->reg10 = context.sc_t2;
  66         regs->reg11 = context.sc_t3;
  67         regs->reg12 = context.sc_t4;
  68         regs->reg13 = context.sc_t5;
  69         regs->reg14 = context.sc_t6;
  70         regs->reg15 = context.sc_t7;
  71         regs->reg16 = context.sc_s0;
  72         regs->reg17 = context.sc_s1;
  73         regs->reg18 = context.sc_s2;
  74         regs->reg19 = context.sc_s3;
  75         regs->reg20 = context.sc_s4;
  76         regs->reg21 = context.sc_s5;
  77         regs->reg22 = context.sc_s6;
  78         regs->reg23 = context.sc_s7;
  79         regs->reg24 = context.sc_t8;
  80         regs->reg25 = context.sc_t9;
  81         /*
  82          * Skip k0/k1
  83          */
  84         regs->reg28 = context.sc_gp;
  85         regs->reg29 = context.sc_sp;
  86         regs->reg30 = context.sc_fp;
  87         regs->reg31 = context.sc_ra;
  88         regs->cp0_epc = context.sc_epc;
  89         regs->cp0_cause = context.sc_cause;
  90 
  91         /*
  92          * disable syscall checks
  93          */
  94         regs->orig_reg2 = -1;
  95         return regs->orig_reg2;
  96 badframe:
  97         do_exit(SIGSEGV);
  98 }
  99 
 100 /*
 101  * Set up a signal frame...
 102  */
 103 static void setup_frame(struct sigaction * sa, unsigned long ** fp,
     /* [previous][next][first][last][top][bottom][index][help] */
 104                         unsigned long pc, struct pt_regs *regs,
 105                         int signr, unsigned long oldmask)
 106 {
 107         unsigned long * frame;
 108 
 109         frame = *fp;
 110         frame -= 32;
 111         if (verify_area(VERIFY_WRITE,frame,21*4))
 112                 do_exit(SIGSEGV);
 113         /*
 114          * set up the "normal" stack seen by the signal handler
 115          */
 116         put_fs_long(regs->reg1 , frame   );
 117         put_fs_long(regs->reg2 , frame+ 1);
 118         put_fs_long(regs->reg3 , frame+ 2);
 119         put_fs_long(regs->reg4 , frame+ 3);
 120         put_fs_long(regs->reg5 , frame+ 4);
 121         put_fs_long(regs->reg6 , frame+ 5);
 122         put_fs_long(regs->reg7 , frame+ 6);
 123         put_fs_long(regs->reg8 , frame+ 7);
 124         put_fs_long(regs->reg9 , frame+ 8);
 125         put_fs_long(regs->reg10, frame+ 9);
 126         put_fs_long(regs->reg11, frame+10);
 127         put_fs_long(regs->reg12, frame+11);
 128         put_fs_long(regs->reg13, frame+12);
 129         put_fs_long(regs->reg14, frame+13);
 130         put_fs_long(regs->reg15, frame+14);
 131         put_fs_long(regs->reg16, frame+15);
 132         put_fs_long(regs->reg17, frame+16);
 133         put_fs_long(regs->reg18, frame+17);
 134         put_fs_long(regs->reg19, frame+18);
 135         put_fs_long(regs->reg20, frame+19);
 136         put_fs_long(regs->reg21, frame+20);
 137         put_fs_long(regs->reg22, frame+21);
 138         put_fs_long(regs->reg23, frame+22);
 139         put_fs_long(regs->reg24, frame+23);
 140         put_fs_long(regs->reg25, frame+24);
 141         /*
 142          * Don't copy k0/k1
 143          */
 144         put_fs_long(regs->reg28, frame+25);
 145         put_fs_long(regs->reg29, frame+26);
 146         put_fs_long(regs->reg30, frame+27);
 147         put_fs_long(regs->reg31, frame+28);
 148         put_fs_long(pc         , frame+29);
 149         put_fs_long(oldmask    , frame+30);
 150         /*
 151          * set up the return code...
 152          *
 153          *         .set    noreorder
 154          *         .set    noat
 155          *         syscall
 156          *         li      $1,__NR_sigreturn
 157          *         .set    at
 158          *         .set    reorder
 159          */
 160         put_fs_long(0x24010077, frame+31);              /* li   $1,119 */
 161         put_fs_long(0x000000c0, frame+32);              /* syscall     */
 162         *fp = frame;
 163         /*
 164          * Flush caches so the instructions will be correctly executed.
 165          */
 166         sys_cacheflush(frame, 32*4, BCACHE);
 167 }
 168 
 169 /*
 170  * Note that 'init' is a special process: it doesn't get signals it doesn't
 171  * want to handle. Thus you cannot kill init even with a SIGKILL even by
 172  * mistake.
 173  *
 174  * Note that we go through the signals twice: once to check the signals that
 175  * the kernel can handle, and then we build all the user-level signal handling
 176  * stack-frames in one go after that.
 177  */
 178 asmlinkage int do_signal(unsigned long oldmask, struct pt_regs * regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 179 {
 180         unsigned long mask = ~current->blocked;
 181         unsigned long handler_signal = 0;
 182         unsigned long *frame = NULL;
 183         unsigned long pc = 0;
 184         unsigned long signr;
 185         struct sigaction * sa;
 186 
 187         while ((signr = current->signal & mask)) {
 188                 __asm__(".set\tnoreorder\n\t"
 189                         ".set\tnoat\n\t"
 190                         "li\t%0,31\n"
 191                         "1:\tsllv\t$1,%1,%0\n\t"
 192                         "bgezl\t$1,1b\n\t"
 193                         "subu\t$8,1\n\t"
 194                         "subu\t%0,31\n\t"
 195                         "subu\t%0,$0,%0\n\t"
 196                         "li\t$1,1\n\t"
 197                         "sllv\t$1,$1,%0\n\t"
 198                         "nor\t$1,$0\n\t"
 199                         "xor\t%1,$1\n\t"
 200                         ".set\tat\n\t"
 201                         ".set\treorder"
 202                         :"=r" (signr),"=r" (current->signal)
 203                         :"0"  (signr),"1"  (current->signal)
 204                         :"$1");
 205                 sa = current->sigaction + signr;
 206                 signr++;
 207                 if ((current->flags & PF_PTRACED) && signr != SIGKILL) {
 208                         current->exit_code = signr;
 209                         current->state = TASK_STOPPED;
 210                         notify_parent(current);
 211                         schedule();
 212                         if (!(signr = current->exit_code))
 213                                 continue;
 214                         current->exit_code = 0;
 215                         if (signr == SIGSTOP)
 216                                 continue;
 217                         if (_S(signr) & current->blocked) {
 218                                 current->signal |= _S(signr);
 219                                 continue;
 220                         }
 221                         sa = current->sigaction + signr - 1;
 222                 }
 223                 if (sa->sa_handler == SIG_IGN) {
 224                         if (signr != SIGCHLD)
 225                                 continue;
 226                         /* check for SIGCHLD: it's special */
 227                         while (sys_waitpid(-1,NULL,WNOHANG) > 0)
 228                                 /* nothing */;
 229                         continue;
 230                 }
 231                 if (sa->sa_handler == SIG_DFL) {
 232                         if (current->pid == 1)
 233                                 continue;
 234                         switch (signr) {
 235                         case SIGCONT: case SIGCHLD: case SIGWINCH:
 236                                 continue;
 237 
 238                         case SIGSTOP: case SIGTSTP: case SIGTTIN: case SIGTTOU:
 239                                 if (current->flags & PF_PTRACED)
 240                                         continue;
 241                                 current->state = TASK_STOPPED;
 242                                 current->exit_code = signr;
 243                                 if (!(current->p_pptr->sigaction[SIGCHLD-1].sa_flags & 
 244                                                 SA_NOCLDSTOP))
 245                                         notify_parent(current);
 246                                 schedule();
 247                                 continue;
 248 
 249                         case SIGQUIT: case SIGILL: case SIGTRAP:
 250                         case SIGIOT: case SIGFPE: case SIGSEGV:
 251                                 if (current->binfmt && current->binfmt->core_dump) {
 252                                         if (current->binfmt->core_dump(signr, regs))
 253                                                 signr |= 0x80;
 254                                 }
 255                                 /* fall through */
 256                         default:
 257                                 current->signal |= _S(signr & 0x7f);
 258                                 do_exit(signr);
 259                         }
 260                 }
 261                 /*
 262                  * OK, we're invoking a handler
 263                  */
 264                 if (regs->orig_reg2 >= 0) {
 265                         if (regs->reg2 == -ERESTARTNOHAND ||
 266                            (regs->reg2 == -ERESTARTSYS &&
 267                             !(sa->sa_flags & SA_RESTART)))
 268                                 regs->reg2 = -EINTR;
 269                 }
 270                 handler_signal |= 1 << (signr-1);
 271                 mask &= ~sa->sa_mask;
 272         }
 273         if (regs->orig_reg2 >= 0 &&
 274             (regs->reg2 == -ERESTARTNOHAND ||
 275              regs->reg2 == -ERESTARTSYS ||
 276              regs->reg2 == -ERESTARTNOINTR)) {
 277                 regs->reg2 = regs->orig_reg2;
 278                 regs->cp0_epc -= 4;
 279         }
 280         if (!handler_signal)            /* no handler will be called - return 0 */
 281                 return 0;
 282         pc = regs->cp0_epc;
 283         frame = (unsigned long *) regs->reg29;
 284         signr = 1;
 285         sa = current->sigaction;
 286         for (mask = 1 ; mask ; sa++,signr++,mask += mask) {
 287                 if (mask > handler_signal)
 288                         break;
 289                 if (!(mask & handler_signal))
 290                         continue;
 291                 setup_frame(sa,&frame,pc,regs,signr,oldmask);
 292                 pc = (unsigned long) sa->sa_handler;
 293                 if (sa->sa_flags & SA_ONESHOT)
 294                         sa->sa_handler = NULL;
 295                 /*
 296                  * force a kernel-mode page-in of the signal
 297                  * handler to reduce races
 298                  */
 299                 __asm__(".set\tnoat\n\t"
 300                         "lwu\t$1,(%0)\n\t"
 301                         ".set\tat\n\t"
 302                         :
 303                         :"r" ((char *) pc)
 304                         :"$1");
 305                 current->blocked |= sa->sa_mask;
 306                 oldmask |= sa->sa_mask;
 307         }
 308         regs->reg29 = (unsigned long) frame;
 309         regs->cp0_epc = pc;             /* "return" to the first handler */
 310         return 1;
 311 }

/* [previous][next][first][last][top][bottom][index][help] */