|
|
1.1 root 1: /* $Header: /kernel/kersrc/coh.286/RCS/sig.c,v 1.1 92/07/17 15:18:46 bin Exp Locker: bin $ */
2: /* (lgl-
3: * The information contained herein is a trade secret of Mark Williams
4: * Company, and is confidential information. It is provided under a
5: * license agreement, and may be copied or disclosed only under the
6: * terms of that agreement. Any reproduction or disclosure of this
7: * material without the express written authorization of Mark Williams
8: * Company or persuant to the license agreement is unlawful.
9: *
10: * COHERENT Version 2.3.37
11: * Copyright (c) 1982, 1983, 1984.
12: * An unpublished work by Mark Williams Company, Chicago.
13: * All rights reserved.
14: -lgl) */
15: /*
16: * Coherent.
17: * Signal handling.
18: *
19: * $Log: sig.c,v $
20: * Revision 1.1 92/07/17 15:18:46 bin
21: * Initial revision
22: *
23: * Revision 1.1 88/03/24 16:14:24 src
24: * Initial revision
25: *
26: * 87/11/05 Allan Cornish /usr/src/sys/coh/sig.c
27: * New seg struct now used to allow extended addressing.
28: *
29: * 86/11/19 Allan Cornish /usr/src/sys/coh/sig.c
30: * sigdump() initializes the (new) (IO).io_flag field to 0.
31: */
32: #include <sys/coherent.h>
33: #include <errno.h>
34: #include <sys/ino.h>
35: #include <sys/inode.h>
36: #include <sys/io.h>
37: #include <sys/proc.h>
38: #include <sys/ptrace.h>
39: #include <sys/sched.h>
40: #include <sys/seg.h>
41: #include <signal.h>
42:
43: /*
44: * Send a signal to the process `pp'.
45: */
46: sendsig(sig, pp)
47: register unsigned sig;
48: register PROC *pp;
49: {
50: register sig_t f;
51: register int s;
52:
53: f = ((sig_t)1) << (sig-1);
54: if ((pp->p_isig&f) != 0)
55: return;
56: pp->p_ssig |= f;
57: if (pp->p_state == PSSLEEP) {
58: s = sphi();
59: pp->p_lback->p_lforw = pp->p_lforw;
60: pp->p_lforw->p_lback = pp->p_lback;
61: addu(pp->p_cval, (utimer-pp->p_lctim)*CVCLOCK);
62: setrun(pp);
63: spl(s);
64: }
65: }
66:
67: /*
68: * Return signal number if we have a non ignored signal, else zero.
69: */
70: nondsig()
71: {
72: register PROC *pp;
73: register sig_t mask;
74: register int signo;
75:
76: pp = SELF;
77: signo = 0;
78: pp->p_ssig &= ~pp->p_isig;
79: if (pp->p_ssig != 0) {
80: mask = (sig_t) 1;
81: signo += 1;
82: while ((pp->p_ssig&mask) == 0) {
83: mask <<= 1;
84: signo += 1;
85: }
86: }
87: return (signo);
88: }
89:
90: /*
91: * If we have a signal that isn't ignored, activate it.
92: */
93: actvsig()
94: {
95: register int n;
96: register PROC *pp;
97: register int (*f)();
98:
99: #if EBUG_VM > 0
100: printf("actvsig "); /** DEBUG **/
101: #endif
102:
103: if ((n = nondsig()) == 0)
104: return;
105: pp = SELF;
106: --n;
107: pp->p_ssig &= ~((sig_t)1<<n);
108: f = u.u_sfunc[n];
109: u.u_signo = ++n;
110: if (f != SIG_DFL) {
111: msigint(n, f);
112: return;
113: }
114: msysgen(&u.u_sysgen);
115: if ((pp->p_flags&PFTRAC) != 0) {
116: pp->p_flags |= PFWAIT;
117: n = ptret();
118: pp->p_flags &= ~(PFWAIT|PFSTOP);
119: if (n == 0)
120: return;
121: }
122: if (n>SIGKILL || n==SIGQUIT || n==SIGSYS) {
123: if (sigdump())
124: n |= 0200;
125: }
126: pexit(n);
127: }
128:
129: /*
130: * Create a dump of ourselves onto the file `core'.
131: */
132: sigdump()
133: {
134: register INODE *ip;
135: register SR *srp;
136: register SEG * sp;
137: register int n;
138: register paddr_t ssize;
139:
140: if ((SELF->p_flags&PFNDMP) != 0)
141: return (0);
142: u.u_io.io_seg = IOSYS;
143: u.u_io.io_flag = 0;
144: /* Make the core with the real owners */
145: schizo();
146: if (ftoi("core", 'c') != 0) {
147: schizo();
148: return (0);
149: }
150: if ((ip=u.u_cdiri) == NULL) {
151: if ((ip=imake(IFREG|0644, 0)) == NULL) {
152: schizo();
153: return (0);
154: }
155: } else {
156: if ((ip->i_mode&IFMT)!=IFREG
157: || iaccess(ip, IPW)==0
158: || getment(ip->i_dev, 1)==NULL) {
159: idetach(ip);
160: schizo();
161: return (0);
162: }
163: iclear(ip);
164: }
165: schizo();
166: u.u_error = 0;
167: u.u_io.io_seek = 0;
168: for (srp=u.u_segl; u.u_error==0 && srp<&u.u_segl[NUSEG]; srp++) {
169: if ((sp = srp->sr_segp)==NULL || (srp->sr_flag&SRFDUMP)==0)
170: continue;
171: u.u_io.io_seg = IOPHY;
172: u.u_io.io_phys = sp->s_paddr;
173: u.u_io.io_flag = 0;
174: ssize = sp->s_size;
175: sp->s_lrefc++;
176: while (u.u_error == 0 && ssize != 0) {
177: n = ssize > SCHUNK ? SCHUNK : ssize;
178: u.u_io.io_ioc = n;
179: iwrite(ip, &u.u_io);
180: u.u_io.io_phys += (paddr_t)n;
181: ssize -= (paddr_t)n;
182: }
183: sp->s_lrefc--;
184: }
185: idetach(ip);
186: return (u.u_error==0);
187: }
188:
189: /*
190: * Send a ptrace command to the child.
191: */
192: ptset(req, pid, addr, data)
193: unsigned req;
194: int *addr;
195: {
196: #ifdef TINY
197: sendsig(SELF, SIGSYS);
198: return (0);
199: #else
200: register PROC *pp;
201:
202: lock(pnxgate);
203: for (pp=procq.p_nforw; pp!=&procq; pp=pp->p_nforw)
204: if (pp->p_pid == pid)
205: break;
206: unlock(pnxgate);
207: if (pp==&procq || (pp->p_flags&PFSTOP)==0 || pp->p_ppid!=SELF->p_pid) {
208: u.u_error = ESRCH;
209: return;
210: }
211: lock(pts.pt_gate);
212: pts.pt_req = req;
213: pts.pt_pid = pid;
214: pts.pt_addr = addr;
215: pts.pt_data = data;
216: pts.pt_errs = 0;
217: pts.pt_rval = 0;
218: pts.pt_busy = 1;
219: wakeup((char *)&pts.pt_req);
220: while (pts.pt_busy != 0)
221: sleep((char *)&pts.pt_busy, CVPTSET, IVPTSET, SVPTSET);
222: u.u_error = pts.pt_errs;
223: unlock(pts.pt_gate);
224: return (pts.pt_rval);
225: #endif
226: }
227:
228: /*
229: * This routine is called when a child that is being traced receives a signal
230: * that is not caught or ignored. It follows up on any requests by the parent
231: * and returns when done.
232: */
233: ptret()
234: {
235: #ifdef TINY
236: return (SIGKILL);
237: #else
238: register PROC *pp;
239: register PROC *pp1;
240: register int sign;
241:
242: pp = SELF;
243: next:
244: u.u_error = 0;
245: if (pp->p_ppid == 1)
246: return (SIGKILL);
247: sign = -1;
248: lock(pnxgate);
249: pp1 = &procq;
250: for (;;) {
251: if ((pp1=pp1->p_nforw) == &procq) {
252: sign = SIGKILL;
253: break;
254: }
255: if (pp1->p_pid != pp->p_ppid)
256: continue;
257: if (pp1->p_state == PSSLEEP)
258: wakeup((char *)pp1);
259: break;
260: }
261: unlock(pnxgate);
262: while (sign < 0) {
263: if (pts.pt_busy==0 || pp->p_pid!=pts.pt_pid) {
264: sleep((char *)&pts.pt_req, CVPTRET, IVPTRET, SVPTRET);
265: goto next;
266: }
267: switch (pts.pt_req) {
268: case 1:
269: pts.pt_rval = getuwi(pts.pt_addr);
270: break;
271: case 2:
272: pts.pt_rval = getuwd(pts.pt_addr);
273: break;
274: case 3:
275: if ((unsigned)pts.pt_addr < UPASIZE)
276: pts.pt_rval = *(int *)((char *)&u+pts.pt_addr);
277: else
278: u.u_error = EINVAL;
279: break;
280: case 4:
281: putuwi(pts.pt_addr, pts.pt_data);
282: break;
283: case 5:
284: putuwd(pts.pt_addr, pts.pt_data);
285: break;
286: case 6:
287: if (msetuof(pts.pt_addr, pts.pt_data) == 0)
288: u.u_error = EINVAL;
289: break;
290: case 7:
291: goto sig;
292: case 8:
293: sign = SIGKILL;
294: break;
295: case 9:
296: msigsin();
297: sig:
298: if (pts.pt_data<0 || pts.pt_data>NSIG) {
299: u.u_error = EINVAL;
300: break;
301: }
302: sign = pts.pt_data;
303: if (pts.pt_addr != SIG_IGN)
304: msetppc((vaddr_t)pts.pt_addr);
305: break;
306: default:
307: u.u_error = EINVAL;
308: }
309: if ((pts.pt_errs=u.u_error) == EFAULT)
310: pts.pt_errs = EINVAL;
311: pts.pt_busy = 0;
312: wakeup((char *)&pts.pt_busy);
313: }
314: return (sign);
315: #endif
316: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.