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