1*8644Sroot /* kern_sig.c 5.9 82/10/17 */ 27421Sroot 37421Sroot #include "../h/param.h" 47421Sroot #include "../h/systm.h" 57421Sroot #include "../h/dir.h" 67421Sroot #include "../h/user.h" 77421Sroot #include "../h/reg.h" 87421Sroot #include "../h/inode.h" 97421Sroot #include "../h/proc.h" 107421Sroot #include "../h/timeb.h" 117421Sroot #include "../h/times.h" 127421Sroot #include "../h/conf.h" 137421Sroot #include "../h/buf.h" 147421Sroot #include "../h/mount.h" 157421Sroot #include "../h/text.h" 167421Sroot #include "../h/seg.h" 177421Sroot #include "../h/pte.h" 187421Sroot #include "../h/psl.h" 197421Sroot #include "../h/vm.h" 207421Sroot #include "../h/acct.h" 217818Sroot #include "../h/uio.h" 228117Sroot #include "../h/kernel.h" 237421Sroot 247499Sroot /* KILL CODE SHOULDNT KNOW ABOUT PROCESS INTERNALS !?! */ 257499Sroot 267499Sroot sigvec() 277421Sroot { 287421Sroot 297421Sroot } 307421Sroot 317499Sroot sigblock() 327421Sroot { 337499Sroot 347499Sroot } 357499Sroot 367499Sroot sigsetmask() 377499Sroot { 387499Sroot 397499Sroot } 407499Sroot 417499Sroot sigpause() 427499Sroot { 437499Sroot 447499Sroot } 457499Sroot 467499Sroot sigstack() 477499Sroot { 487499Sroot 497499Sroot } 507499Sroot 518032Sroot kill() 528032Sroot { 538032Sroot 548032Sroot } 558032Sroot 568032Sroot killpg() 578032Sroot { 588032Sroot 598032Sroot } 608032Sroot 617499Sroot /* BEGIN DEFUNCT */ 627499Sroot okill() 637499Sroot { 647421Sroot register struct proc *p; 657421Sroot register a, sig; 667421Sroot register struct a { 677421Sroot int pid; 687421Sroot int signo; 697421Sroot } *uap; 707421Sroot int f, priv; 717421Sroot 727421Sroot uap = (struct a *)u.u_ap; 737421Sroot f = 0; 747421Sroot a = uap->pid; 757421Sroot priv = 0; 767421Sroot sig = uap->signo; 777421Sroot if (sig < 0) 787421Sroot /* 797421Sroot * A negative signal means send to process group. 807421Sroot */ 817421Sroot uap->signo = -uap->signo; 827421Sroot if (uap->signo == 0 || uap->signo > NSIG) { 837421Sroot u.u_error = EINVAL; 847421Sroot return; 857421Sroot } 867421Sroot if (a > 0 && sig > 0) { 877421Sroot p = pfind(a); 887421Sroot if (p == 0 || u.u_uid && u.u_uid != p->p_uid) { 897421Sroot u.u_error = ESRCH; 907421Sroot return; 917421Sroot } 927421Sroot psignal(p, uap->signo); 937421Sroot return; 947421Sroot } 957421Sroot if (a==-1 && u.u_uid==0) { 967421Sroot priv++; 977421Sroot a = 0; 987421Sroot sig = -1; /* like sending to pgrp */ 997421Sroot } else if (a==0) { 1007421Sroot /* 1017421Sroot * Zero process id means send to my process group. 1027421Sroot */ 1037421Sroot sig = -1; 1047421Sroot a = u.u_procp->p_pgrp; 1057421Sroot if (a == 0) { 1067421Sroot u.u_error = EINVAL; 1077421Sroot return; 1087421Sroot } 1097421Sroot } 1107421Sroot for(p = proc; p < procNPROC; p++) { 1117421Sroot if (p->p_stat == NULL) 1127421Sroot continue; 1137421Sroot if (sig > 0) { 1147421Sroot if (p->p_pid != a) 1157421Sroot continue; 1167421Sroot } else if (p->p_pgrp!=a && priv==0 || p->p_ppid==0 || 1177421Sroot (p->p_flag&SSYS) || (priv && p==u.u_procp)) 1187421Sroot continue; 1197421Sroot if (u.u_uid != 0 && u.u_uid != p->p_uid && 1207421Sroot (uap->signo != SIGCONT || !inferior(p))) 1217421Sroot continue; 1227421Sroot f++; 1237421Sroot psignal(p, uap->signo); 1247421Sroot } 1257421Sroot if (f == 0) 1267421Sroot u.u_error = ESRCH; 1277421Sroot } 1287421Sroot 1297499Sroot ossig() 1307499Sroot { 1317499Sroot register int (*f)(); 1327499Sroot struct a { 1337499Sroot int signo; 1347499Sroot int (*fun)(); 1357499Sroot } *uap; 1367499Sroot register struct proc *p = u.u_procp; 1377499Sroot register a; 1387499Sroot long sigmask; 1397421Sroot 1407499Sroot uap = (struct a *)u.u_ap; 1417499Sroot a = uap->signo & SIGNUMMASK; 1427499Sroot f = uap->fun; 1437499Sroot if (a<=0 || a>=NSIG || a==SIGKILL || a==SIGSTOP || 1447499Sroot a==SIGCONT && (f == SIG_IGN || f == SIG_HOLD)) { 1457499Sroot u.u_error = EINVAL; 1467499Sroot return; 1477499Sroot } 1487499Sroot if ((uap->signo &~ SIGNUMMASK) || (f != SIG_DFL && f != SIG_IGN && 1497499Sroot SIGISDEFER(f))) 1507499Sroot u.u_procp->p_flag |= SNUSIG; 1517499Sroot /* 1527499Sroot * Don't clobber registers if we are to simulate 1537499Sroot * a ret+rti. 1547499Sroot */ 1557499Sroot if ((uap->signo&SIGDORTI) == 0) 1567499Sroot u.u_r.r_val1 = (int)u.u_signal[a]; 1577499Sroot /* 1587499Sroot * Change setting atomically. 1597499Sroot */ 1607499Sroot (void) spl6(); 1617499Sroot sigmask = 1L << (a-1); 1627499Sroot if (u.u_signal[a] == SIG_IGN) 1637499Sroot p->p_sig &= ~sigmask; /* never to be seen again */ 1647499Sroot u.u_signal[a] = f; 1657499Sroot if (f != SIG_DFL && f != SIG_IGN && f != SIG_HOLD) 1667499Sroot f = SIG_CATCH; 1677499Sroot if ((int)f & 1) 1687499Sroot p->p_siga0 |= sigmask; 1697499Sroot else 1707499Sroot p->p_siga0 &= ~sigmask; 1717499Sroot if ((int)f & 2) 1727499Sroot p->p_siga1 |= sigmask; 1737499Sroot else 1747499Sroot p->p_siga1 &= ~sigmask; 1757499Sroot (void) spl0(); 1767499Sroot /* 1777499Sroot * Now handle options. 1787499Sroot */ 1797499Sroot if (uap->signo & SIGDOPAUSE) { 1807499Sroot /* 1817499Sroot * Simulate a PDP11 style wait instrution which 1827499Sroot * atomically lowers priority, enables interrupts 1837499Sroot * and hangs. 1847499Sroot */ 1857499Sroot opause(); 1867499Sroot /*NOTREACHED*/ 1877499Sroot } 1887499Sroot if (uap->signo & SIGDORTI) 1897499Sroot u.u_eosys = SIMULATERTI; 1907499Sroot } 1917421Sroot 1927421Sroot /* 1937421Sroot * Send the specified signal to 1947421Sroot * all processes with 'pgrp' as 1957421Sroot * process group. 1967421Sroot * Called by tty.c for quits and 1977421Sroot * interrupts. 1987421Sroot */ 1997421Sroot gsignal(pgrp, sig) 2007421Sroot register int pgrp; 2017421Sroot { 2027421Sroot register struct proc *p; 2037421Sroot 2047421Sroot if (pgrp == 0) 2057421Sroot return; 2067421Sroot for(p = proc; p < procNPROC; p++) 2077421Sroot if (p->p_pgrp == pgrp) 2087421Sroot psignal(p, sig); 2097421Sroot } 2107421Sroot 2117421Sroot /* 2127421Sroot * Send the specified signal to 2137421Sroot * the specified process. 2147421Sroot */ 2157421Sroot psignal(p, sig) 2167421Sroot register struct proc *p; 2177421Sroot register int sig; 2187421Sroot { 2197421Sroot register int s; 2207421Sroot register int (*action)(); 2217421Sroot long sigmask; 2227421Sroot 2237421Sroot if ((unsigned)sig >= NSIG) 2247421Sroot return; 2257421Sroot sigmask = (1L << (sig-1)); 2267421Sroot 2277421Sroot /* 2287421Sroot * If proc is traced, always give parent a chance. 2297421Sroot * Otherwise get the signal action from the bits in the proc table. 2307421Sroot */ 2317421Sroot if (p->p_flag & STRC) 2327421Sroot action = SIG_DFL; 2337421Sroot else { 2347421Sroot s = (p->p_siga1&sigmask) != 0; 2357421Sroot s <<= 1; 2367421Sroot s |= (p->p_siga0&sigmask) != 0; 2377421Sroot action = (int(*)())s; 2387421Sroot /* 2397421Sroot * If the signal is ignored, we forget about it immediately. 2407421Sroot */ 2417421Sroot if (action == SIG_IGN) 2427421Sroot return; 2437421Sroot } 2447421Sroot #define mask(sig) (1<<(sig-1)) 2457421Sroot #define stops (mask(SIGSTOP)|mask(SIGTSTP)|mask(SIGTTIN)|mask(SIGTTOU)) 2467421Sroot if (sig) { 2477421Sroot p->p_sig |= sigmask; 2487421Sroot switch (sig) { 2497421Sroot 2507421Sroot case SIGTERM: 2517421Sroot if ((p->p_flag&STRC) != 0 || action != SIG_DFL) 2527421Sroot break; 2537421Sroot /* fall into ... */ 2547421Sroot 2557421Sroot case SIGKILL: 2567421Sroot if (p->p_nice > NZERO) 2577421Sroot p->p_nice = NZERO; 2587421Sroot break; 2597421Sroot 2607421Sroot case SIGCONT: 2617421Sroot p->p_sig &= ~stops; 2627421Sroot break; 2637421Sroot 2647421Sroot case SIGSTOP: 2657421Sroot case SIGTSTP: 2667421Sroot case SIGTTIN: 2677421Sroot case SIGTTOU: 2687421Sroot p->p_sig &= ~mask(SIGCONT); 2697421Sroot break; 2707421Sroot } 2717421Sroot } 2727421Sroot #undef mask 2737421Sroot #undef stops 2747421Sroot /* 2757421Sroot * Defer further processing for signals which are held. 2767421Sroot */ 2777421Sroot if (action == SIG_HOLD) 2787421Sroot return; 2797421Sroot s = spl6(); 2807421Sroot switch (p->p_stat) { 2817421Sroot 2827421Sroot case SSLEEP: 2837421Sroot /* 2847421Sroot * If process is sleeping at negative priority 2857421Sroot * we can't interrupt the sleep... the signal will 2867421Sroot * be noticed when the process returns through 2877421Sroot * trap() or syscall(). 2887421Sroot */ 2897421Sroot if (p->p_pri <= PZERO) 2907421Sroot goto out; 2917421Sroot /* 2927421Sroot * Process is sleeping and traced... make it runnable 2937421Sroot * so it can discover the signal in issig() and stop 2947421Sroot * for the parent. 2957421Sroot */ 2967421Sroot if (p->p_flag&STRC) 2977421Sroot goto run; 2987421Sroot switch (sig) { 2997421Sroot 3007421Sroot case SIGSTOP: 3017421Sroot case SIGTSTP: 3027421Sroot case SIGTTIN: 3037421Sroot case SIGTTOU: 3047421Sroot /* 3057421Sroot * These are the signals which by default 3067421Sroot * stop a process. 3077421Sroot */ 3087421Sroot if (action != SIG_DFL) 3097421Sroot goto run; 3107421Sroot /* 3117421Sroot * Don't clog system with children of init 3127421Sroot * stopped from the keyboard. 3137421Sroot */ 3147421Sroot if (sig != SIGSTOP && p->p_pptr == &proc[1]) { 3157421Sroot psignal(p, SIGKILL); 3167421Sroot p->p_sig &= ~sigmask; 3177421Sroot splx(s); 3187421Sroot return; 3197421Sroot } 3207421Sroot /* 3217421Sroot * If a child in vfork(), stopping could 3227421Sroot * cause deadlock. 3237421Sroot */ 3247421Sroot if (p->p_flag&SVFORK) 3257421Sroot goto out; 3267421Sroot p->p_sig &= ~sigmask; 3277421Sroot p->p_cursig = sig; 3287421Sroot stop(p); 3297421Sroot goto out; 3307421Sroot 3317421Sroot case SIGIO: 3327421Sroot case SIGURG: 3337421Sroot case SIGCHLD: 3347421Sroot /* 3357421Sroot * These signals are special in that they 3367421Sroot * don't get propogated... if the process 3377421Sroot * isn't interested, forget it. 3387421Sroot */ 3397421Sroot if (action != SIG_DFL) 3407421Sroot goto run; 3417421Sroot p->p_sig &= ~sigmask; /* take it away */ 3427421Sroot goto out; 3437421Sroot 3447421Sroot default: 3457421Sroot /* 3467421Sroot * All other signals cause the process to run 3477421Sroot */ 3487421Sroot goto run; 3497421Sroot } 3507421Sroot /*NOTREACHED*/ 3517421Sroot 3527421Sroot case SSTOP: 3537421Sroot /* 3547421Sroot * If traced process is already stopped, 3557421Sroot * then no further action is necessary. 3567421Sroot */ 3577421Sroot if (p->p_flag&STRC) 3587421Sroot goto out; 3597421Sroot switch (sig) { 3607421Sroot 3617421Sroot case SIGKILL: 3627421Sroot /* 3637421Sroot * Kill signal always sets processes running. 3647421Sroot */ 3657421Sroot goto run; 3667421Sroot 3677421Sroot case SIGCONT: 3687421Sroot /* 3697421Sroot * If the process catches SIGCONT, let it handle 3707421Sroot * the signal itself. If it isn't waiting on 3717421Sroot * an event, then it goes back to run state. 3727421Sroot * Otherwise, process goes back to sleep state. 3737421Sroot */ 3747421Sroot if (action != SIG_DFL || p->p_wchan == 0) 3757421Sroot goto run; 3767421Sroot p->p_stat = SSLEEP; 3777421Sroot goto out; 3787421Sroot 3797421Sroot case SIGSTOP: 3807421Sroot case SIGTSTP: 3817421Sroot case SIGTTIN: 3827421Sroot case SIGTTOU: 3837421Sroot /* 3847421Sroot * Already stopped, don't need to stop again. 3857421Sroot * (If we did the shell could get confused.) 3867421Sroot */ 3877421Sroot p->p_sig &= ~sigmask; /* take it away */ 3887421Sroot goto out; 3897421Sroot 3907421Sroot default: 3917421Sroot /* 3927421Sroot * If process is sleeping interruptibly, then 3937421Sroot * unstick it so that when it is continued 3947421Sroot * it can look at the signal. 3957421Sroot * But don't setrun the process as its not to 3967421Sroot * be unstopped by the signal alone. 3977421Sroot */ 3987421Sroot if (p->p_wchan && p->p_pri > PZERO) 3997421Sroot unsleep(p); 4007421Sroot goto out; 4017421Sroot } 4027421Sroot /*NOTREACHED*/ 4037421Sroot 4047421Sroot default: 4057421Sroot /* 4067421Sroot * SRUN, SIDL, SZOMB do nothing with the signal, 4077421Sroot * other than kicking ourselves if we are running. 4087421Sroot * It will either never be noticed, or noticed very soon. 4097421Sroot */ 4107421Sroot if (p == u.u_procp && !noproc) 4118444Sroot #include "../vax/mtpr.h" 4127421Sroot aston(); 4137421Sroot goto out; 4147421Sroot } 4157421Sroot /*NOTREACHED*/ 4167421Sroot run: 4177421Sroot /* 4187421Sroot * Raise priority to at least PUSER. 4197421Sroot */ 4207421Sroot if (p->p_pri > PUSER) 4217421Sroot if ((p != u.u_procp || noproc) && p->p_stat == SRUN && 4227421Sroot (p->p_flag & SLOAD)) { 4237421Sroot remrq(p); 4247421Sroot p->p_pri = PUSER; 4257421Sroot setrq(p); 4267421Sroot } else 4277421Sroot p->p_pri = PUSER; 4287421Sroot setrun(p); 4297421Sroot out: 4307421Sroot splx(s); 4317421Sroot } 4327421Sroot 4337421Sroot /* 4347421Sroot * Returns true if the current 4357421Sroot * process has a signal to process. 4367421Sroot * The signal to process is put in p_cursig. 4377421Sroot * This is asked at least once each time a process enters the 4387421Sroot * system (though this can usually be done without actually 4397421Sroot * calling issig by checking the pending signal masks.) 4407421Sroot * A signal does not do anything 4417421Sroot * directly to a process; it sets 4427421Sroot * a flag that asks the process to 4437421Sroot * do something to itself. 4447421Sroot */ 4457421Sroot issig() 4467421Sroot { 4477421Sroot register struct proc *p; 4487421Sroot register int sig; 4497421Sroot long sigbits; 4507421Sroot long sigmask; 4517421Sroot 4527421Sroot p = u.u_procp; 4537421Sroot for (;;) { 4547421Sroot sigbits = p->p_sig; 4557421Sroot if ((p->p_flag&STRC) == 0) 4567421Sroot sigbits &= ~p->p_ignsig; 4577421Sroot if (p->p_flag&SVFORK) 4587421Sroot #define bit(a) (1<<(a-1)) 4597421Sroot sigbits &= ~(bit(SIGSTOP)|bit(SIGTSTP)|bit(SIGTTIN)|bit(SIGTTOU)); 4607421Sroot if (sigbits == 0) 4617421Sroot break; 4627421Sroot sig = ffs((int)sigbits); 4637421Sroot sigmask = 1L << (sig-1); 4647421Sroot p->p_sig &= ~sigmask; /* take the signal! */ 4657421Sroot p->p_cursig = sig; 4667421Sroot if (p->p_flag&STRC && (p->p_flag&SVFORK)==0) { 4677421Sroot /* 4687421Sroot * If traced, always stop, and stay 4697421Sroot * stopped until released by the parent. 4707421Sroot */ 4717421Sroot do { 4727421Sroot stop(p); 4737421Sroot swtch(); 4747421Sroot } while (!procxmt() && p->p_flag&STRC); 4757421Sroot 4767421Sroot /* 4777421Sroot * If the traced bit got turned off, 4787421Sroot * then put the signal taken above back into p_sig 4797421Sroot * and go back up to the top to rescan signals. 4807421Sroot * This ensures that siga0 and u_signal are consistent. 4817421Sroot */ 4827421Sroot if ((p->p_flag&STRC) == 0) { 4837421Sroot p->p_sig |= sigmask; 4847421Sroot continue; 4857421Sroot } 4867421Sroot 4877421Sroot /* 4887421Sroot * If parent wants us to take the signal, 4897421Sroot * then it will leave it in p->p_cursig; 4907421Sroot * otherwise we just look for signals again. 4917421Sroot */ 4927421Sroot sig = p->p_cursig; 4937421Sroot if (sig == 0) 4947421Sroot continue; 4957421Sroot } 4967421Sroot switch (u.u_signal[sig]) { 4977421Sroot 4987421Sroot case SIG_DFL: 4997421Sroot /* 5007421Sroot * Don't take default actions on system processes. 5017421Sroot */ 5027421Sroot if (p->p_ppid == 0) 5037421Sroot break; 5047421Sroot switch (sig) { 5057421Sroot 5067421Sroot case SIGTSTP: 5077421Sroot case SIGTTIN: 5087421Sroot case SIGTTOU: 5097421Sroot /* 5107421Sroot * Children of init aren't allowed to stop 5117421Sroot * on signals from the keyboard. 5127421Sroot */ 5137421Sroot if (p->p_pptr == &proc[1]) { 5147421Sroot psignal(p, SIGKILL); 5157421Sroot continue; 5167421Sroot } 5177421Sroot /* fall into ... */ 5187421Sroot 5197421Sroot case SIGSTOP: 5207421Sroot if (p->p_flag&STRC) 5217421Sroot continue; 5227421Sroot stop(p); 5237421Sroot swtch(); 5247421Sroot continue; 5257421Sroot 5267421Sroot case SIGCONT: 5277421Sroot case SIGCHLD: 5287421Sroot /* 5297421Sroot * These signals are normally not 5307421Sroot * sent if the action is the default. 5317421Sroot */ 5327421Sroot continue; /* == ignore */ 5337421Sroot 5347421Sroot default: 5357421Sroot goto send; 5367421Sroot } 5377421Sroot /*NOTREACHED*/ 5387421Sroot 5397421Sroot case SIG_HOLD: 5407421Sroot case SIG_IGN: 5417421Sroot /* 5427421Sroot * Masking above should prevent us 5437421Sroot * ever trying to take action on a held 5447421Sroot * or ignored signal, unless process is traced. 5457421Sroot */ 5467421Sroot if ((p->p_flag&STRC) == 0) 5477421Sroot printf("issig\n"); 5487421Sroot continue; 5497421Sroot 5507421Sroot default: 5517421Sroot /* 5527421Sroot * This signal has an action, let 5537421Sroot * psig process it. 5547421Sroot */ 5557421Sroot goto send; 5567421Sroot } 5577421Sroot /*NOTREACHED*/ 5587421Sroot } 5597421Sroot /* 5607421Sroot * Didn't find a signal to send. 5617421Sroot */ 5627421Sroot p->p_cursig = 0; 5637421Sroot return (0); 5647421Sroot 5657421Sroot send: 5667421Sroot /* 5677421Sroot * Let psig process the signal. 5687421Sroot */ 5697421Sroot return (sig); 5707421Sroot } 5717421Sroot 5727421Sroot /* 5737421Sroot * Put the argument process into the stopped 5747421Sroot * state and notify the parent via wakeup and/or signal. 5757421Sroot */ 5767421Sroot stop(p) 5777421Sroot register struct proc *p; 5787421Sroot { 5797421Sroot 5807421Sroot p->p_stat = SSTOP; 5817421Sroot p->p_flag &= ~SWTED; 5827421Sroot wakeup((caddr_t)p->p_pptr); 5837421Sroot /* 5847421Sroot * Avoid sending signal to parent if process is traced 5857421Sroot */ 5867421Sroot if (p->p_flag&STRC) 5877421Sroot return; 5887421Sroot psignal(p->p_pptr, SIGCHLD); 5897421Sroot } 5907421Sroot 5917421Sroot /* 5927421Sroot * Perform the action specified by 5937421Sroot * the current signal. 5947421Sroot * The usual sequence is: 5957421Sroot * if (issig()) 5967421Sroot * psig(); 5977421Sroot * The signal bit has already been cleared by issig, 5987421Sroot * and the current signal number stored in p->p_cursig. 5997421Sroot */ 6007421Sroot psig() 6017421Sroot { 6027421Sroot register struct proc *rp = u.u_procp; 6037421Sroot register int n = rp->p_cursig; 6047421Sroot long sigmask = 1L << (n-1); 6057421Sroot register int (*action)(); 6067421Sroot 6077421Sroot if (rp->p_cursig == 0) 6087421Sroot panic("psig"); 6097421Sroot action = u.u_signal[n]; 6107421Sroot if (action != SIG_DFL) { 6117421Sroot if (action == SIG_IGN || action == SIG_HOLD) 6127421Sroot panic("psig action"); 6137421Sroot u.u_error = 0; 6147421Sroot if (n != SIGILL && n != SIGTRAP) 6157421Sroot u.u_signal[n] = 0; 6167421Sroot /* 6177421Sroot * If this catch value indicates automatic holding of 6187421Sroot * subsequent signals, set the hold value. 6197421Sroot */ 6207421Sroot if (SIGISDEFER(action)) { 6217421Sroot (void) spl6(); 6227421Sroot if ((int)SIG_HOLD & 1) 6237421Sroot rp->p_siga0 |= sigmask; 6247421Sroot else 6257421Sroot rp->p_siga0 &= ~sigmask; 6267421Sroot if ((int)SIG_HOLD & 2) 6277421Sroot rp->p_siga1 |= sigmask; 6287421Sroot else 6297421Sroot rp->p_siga1 &= ~sigmask; 6307421Sroot u.u_signal[n] = SIG_HOLD; 6317421Sroot (void) spl0(); 6327421Sroot action = SIGUNDEFER(action); 6337421Sroot } 6348032Sroot u.u_ru.ru_nsignals++; 6357421Sroot sendsig(action, n); 6367421Sroot rp->p_cursig = 0; 6377421Sroot return; 6387421Sroot } 6397421Sroot u.u_acflag |= AXSIG; 6407421Sroot switch (n) { 6417421Sroot 6427421Sroot case SIGILL: 6437421Sroot case SIGIOT: 6447421Sroot case SIGBUS: 6457421Sroot case SIGQUIT: 6467421Sroot case SIGTRAP: 6477421Sroot case SIGEMT: 6487421Sroot case SIGFPE: 6497421Sroot case SIGSEGV: 6507421Sroot case SIGSYS: 6517421Sroot u.u_arg[0] = n; 6527421Sroot if (core()) 6537421Sroot n += 0200; 6547421Sroot } 6557421Sroot exit(n); 6567421Sroot } 6577421Sroot 6587421Sroot #ifdef unneeded 6597421Sroot int corestop = 0; 6607421Sroot #endif 6617421Sroot /* 6627421Sroot * Create a core image on the file "core" 6637421Sroot * If you are looking for protection glitches, 6647421Sroot * there are probably a wealth of them here 6657421Sroot * when this occurs to a suid command. 6667421Sroot * 6677421Sroot * It writes UPAGES block of the 6687421Sroot * user.h area followed by the entire 6697421Sroot * data+stack segments. 6707421Sroot */ 6717421Sroot core() 6727421Sroot { 6737421Sroot register struct inode *ip; 6747421Sroot extern schar(); 6757421Sroot 6767421Sroot #ifdef unneeded 6777421Sroot if (corestop) { 6787421Sroot int i; 6797421Sroot for (i = 0; i < 10; i++) 6807421Sroot if (u.u_comm[i]) 6817421Sroot putchar(u.u_comm[i], 0); 6827421Sroot printf(", uid %d\n", u.u_uid); 6837421Sroot if (corestop&2) 6847421Sroot asm("halt"); 6857421Sroot } 6867421Sroot #endif 6877421Sroot if (u.u_uid != u.u_ruid) 6887818Sroot return (0); 6898032Sroot if (ctob(UPAGES+u.u_dsize+u.u_ssize) >= 6908032Sroot u.u_rlimit[RLIMIT_CORE].rlim_cur) 6917421Sroot return (0); 6927421Sroot u.u_error = 0; 6937421Sroot u.u_dirp = "core"; 6947421Sroot ip = namei(schar, 1, 1); 6957421Sroot if (ip == NULL) { 6967421Sroot if (u.u_error) 6977421Sroot return (0); 6987421Sroot ip = maknode(0666); 6997421Sroot if (ip==NULL) 7007421Sroot return (0); 7017421Sroot } 7027818Sroot if (access(ip, IWRITE) || 7037818Sroot (ip->i_mode&IFMT) != IFREG || 7047818Sroot ip->i_nlink != 1) { 7057421Sroot u.u_error = EFAULT; 7067818Sroot goto out; 7077818Sroot } 7087818Sroot itrunc(ip, 0); 7097818Sroot u.u_acflag |= ACORE; 710*8644Sroot u.u_error = rdwri(UIO_WRITE, ip, 7117818Sroot (caddr_t)&u, ctob(UPAGES), 7127818Sroot 0, 1, (int *)0); 7138101Sroot if (u.u_error == 0) 714*8644Sroot u.u_error = rdwri(UIO_WRITE, ip, 715*8644Sroot (caddr_t)ctob(u.u_tsize), ctob(u.u_dsize), 716*8644Sroot ctob(UPAGES), 0, (int *)0); 7178101Sroot if (u.u_error == 0) 718*8644Sroot u.u_error = rdwri(UIO_WRITE, ip, 719*8644Sroot (caddr_t)(USRSTACK-ctob(u.u_ssize)), ctob(u.u_ssize), 720*8644Sroot ctob(UPAGES)+ctob(u.u_dsize), 0, (int *)0); 7217818Sroot out: 7227421Sroot iput(ip); 7237818Sroot return (u.u_error == 0); 7247421Sroot } 725