Annotation of coherent/d/286_KERNEL/USRSRC/coh/sig.c, revision 1.1

1.1     ! root        1: /* $Header: /newbits/286_KERNEL/USRSRC/coh/RCS/sig.c,v 1.1 92/01/09 13:29:11 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/01/09  13:29:11  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: #include <sys/uproc.h>
        !            43: 
        !            44: /*
        !            45:  * Send a signal to the process `pp'.
        !            46:  */
        !            47: sendsig(sig, pp)
        !            48: register unsigned sig;
        !            49: register PROC *pp;
        !            50: {
        !            51:        register sig_t f;
        !            52:        register int s;
        !            53: 
        !            54:        f = ((sig_t)1) << (sig-1);
        !            55:        if ((pp->p_isig&f) != 0)
        !            56:                return;
        !            57:        pp->p_ssig |= f;
        !            58:        if (pp->p_state == PSSLEEP) {
        !            59:                s = sphi();
        !            60:                pp->p_lback->p_lforw = pp->p_lforw;
        !            61:                pp->p_lforw->p_lback = pp->p_lback;
        !            62:                addu(pp->p_cval, (utimer-pp->p_lctim)*CVCLOCK);
        !            63:                setrun(pp);
        !            64:                spl(s);
        !            65:        }
        !            66: }
        !            67: 
        !            68: /*
        !            69:  * Return signal number if we have a non ignored signal, else zero.
        !            70:  */
        !            71: nondsig()
        !            72: {
        !            73:        register PROC *pp;
        !            74:        register sig_t mask;
        !            75:        register int signo;
        !            76: 
        !            77:        pp = SELF;
        !            78:        signo = 0;
        !            79:        pp->p_ssig &= ~pp->p_isig;
        !            80:        if (pp->p_ssig != 0) {
        !            81:                mask = (sig_t) 1;
        !            82:                signo += 1;
        !            83:                while ((pp->p_ssig&mask) == 0) {
        !            84:                        mask <<= 1;
        !            85:                        signo += 1;
        !            86:                }
        !            87:        }
        !            88:        return (signo);
        !            89: }
        !            90: 
        !            91: /*
        !            92:  * If we have a signal that isn't ignored, activate it.
        !            93:  */
        !            94: actvsig()
        !            95: {
        !            96:        register int n;
        !            97:        register PROC *pp;
        !            98:        register int (*f)();
        !            99: 
        !           100: #if EBUG_VM > 0
        !           101:        printf("actvsig ");     /** DEBUG **/
        !           102: #endif
        !           103: 
        !           104:        if ((n = nondsig()) == 0)
        !           105:                return;
        !           106:        pp = SELF;
        !           107:        --n;
        !           108:        pp->p_ssig &= ~((sig_t)1<<n);
        !           109:        f = u.u_sfunc[n];
        !           110:        u.u_signo = ++n;
        !           111:        if (f != SIG_DFL) {
        !           112:                msigint(n, f);
        !           113:                return;
        !           114:        }
        !           115:        msysgen(&u.u_sysgen);
        !           116:        if ((pp->p_flags&PFTRAC) != 0) {
        !           117:                pp->p_flags |= PFWAIT;
        !           118:                n = ptret();
        !           119:                pp->p_flags &= ~(PFWAIT|PFSTOP);
        !           120:                if (n == 0)
        !           121:                        return;
        !           122:        }
        !           123:        if (n>SIGKILL || n==SIGQUIT || n==SIGSYS) {
        !           124:                if (sigdump())
        !           125:                        n |= 0200;
        !           126:        }
        !           127:        pexit(n);
        !           128: }
        !           129: 
        !           130: /*
        !           131:  * Create a dump of ourselves onto the file `core'.
        !           132:  */
        !           133: sigdump()
        !           134: {
        !           135:        register INODE *ip;
        !           136:        register SR *srp;
        !           137:        register SEG * sp;
        !           138:        register int n;
        !           139:        register paddr_t ssize;
        !           140: 
        !           141:        if ((SELF->p_flags&PFNDMP) != 0)
        !           142:                return (0);
        !           143:        u.u_io.io_seg  = IOSYS;
        !           144:        u.u_io.io_flag = 0;
        !           145:        /* Make the core with the real owners */
        !           146:        schizo();
        !           147:        if (ftoi("core", 'c') != 0) {
        !           148:                schizo();
        !           149:                return (0);
        !           150:        }
        !           151:        if ((ip=u.u_cdiri) == NULL) {
        !           152:                if ((ip=imake(IFREG|0644, 0)) == NULL) {
        !           153:                        schizo();
        !           154:                        return (0);
        !           155:                }
        !           156:        } else {
        !           157:                if ((ip->i_mode&IFMT)!=IFREG
        !           158:                 || iaccess(ip, IPW)==0
        !           159:                 || getment(ip->i_dev, 1)==NULL) {
        !           160:                        idetach(ip);
        !           161:                        schizo();
        !           162:                        return (0);
        !           163:                }
        !           164:                iclear(ip);
        !           165:        }
        !           166:        schizo();
        !           167:        u.u_error = 0;
        !           168:        u.u_io.io_seek = 0;
        !           169:        for (srp=u.u_segl; u.u_error==0 && srp<&u.u_segl[NUSEG]; srp++) {
        !           170:                if ((sp = srp->sr_segp)==NULL || (srp->sr_flag&SRFDUMP)==0)
        !           171:                        continue;
        !           172:                u.u_io.io_seg = IOPHY;
        !           173:                u.u_io.io_phys = sp->s_paddr;
        !           174:                u.u_io.io_flag = 0;
        !           175:                ssize = sp->s_size;
        !           176:                sp->s_lrefc++;
        !           177:                while (u.u_error == 0 && ssize != 0) {
        !           178:                        n = ssize > SCHUNK ? SCHUNK : ssize;
        !           179:                        u.u_io.io_ioc = n;
        !           180:                        iwrite(ip, &u.u_io);
        !           181:                        u.u_io.io_phys += (paddr_t)n;
        !           182:                        ssize -= (paddr_t)n;
        !           183:                }
        !           184:                sp->s_lrefc--;
        !           185:        }
        !           186:        idetach(ip);
        !           187:        return (u.u_error==0);
        !           188: }
        !           189: 
        !           190: /*
        !           191:  * Send a ptrace command to the child.
        !           192:  */
        !           193: ptset(req, pid, addr, data)
        !           194: unsigned req;
        !           195: int *addr;
        !           196: {
        !           197: #ifdef TINY
        !           198:        sendsig(SELF, SIGSYS);
        !           199:        return (0);
        !           200: #else
        !           201:        register PROC *pp;
        !           202: 
        !           203:        lock(pnxgate);
        !           204:        for (pp=procq.p_nforw; pp!=&procq; pp=pp->p_nforw)
        !           205:                if (pp->p_pid == pid)
        !           206:                        break;
        !           207:        unlock(pnxgate);
        !           208:        if (pp==&procq || (pp->p_flags&PFSTOP)==0 || pp->p_ppid!=SELF->p_pid) {
        !           209:                u.u_error = ESRCH;
        !           210:                return;
        !           211:        }
        !           212:        lock(pts.pt_gate);
        !           213:        pts.pt_req = req;
        !           214:        pts.pt_pid = pid;
        !           215:        pts.pt_addr = addr;
        !           216:        pts.pt_data = data;
        !           217:        pts.pt_errs = 0;
        !           218:        pts.pt_rval = 0;
        !           219:        pts.pt_busy = 1;
        !           220:        wakeup((char *)&pts.pt_req);
        !           221:        while (pts.pt_busy != 0)
        !           222:                sleep((char *)&pts.pt_busy, CVPTSET, IVPTSET, SVPTSET);
        !           223:        u.u_error = pts.pt_errs;
        !           224:        unlock(pts.pt_gate);
        !           225:        return (pts.pt_rval);
        !           226: #endif
        !           227: }
        !           228: 
        !           229: /*
        !           230:  * This routine is called when a child that is being traced receives a signal
        !           231:  * that is not caught or ignored.  It follows up on any requests by the parent
        !           232:  * and returns when done.
        !           233:  */
        !           234: ptret()
        !           235: {
        !           236: #ifdef TINY
        !           237:        return (SIGKILL);
        !           238: #else
        !           239:        register PROC *pp;
        !           240:        register PROC *pp1;
        !           241:        register int sign;
        !           242: 
        !           243:        pp = SELF;
        !           244: next:
        !           245:        u.u_error = 0;
        !           246:        if (pp->p_ppid == 1)
        !           247:                return (SIGKILL);
        !           248:        sign = -1;
        !           249:        lock(pnxgate);
        !           250:        pp1 = &procq;
        !           251:        for (;;) {
        !           252:                if ((pp1=pp1->p_nforw) == &procq) {
        !           253:                        sign = SIGKILL;
        !           254:                        break;
        !           255:                }
        !           256:                if (pp1->p_pid != pp->p_ppid)
        !           257:                        continue;
        !           258:                if (pp1->p_state == PSSLEEP)
        !           259:                        wakeup((char *)pp1);
        !           260:                break;
        !           261:        }
        !           262:        unlock(pnxgate);
        !           263:        while (sign < 0) {
        !           264:                if (pts.pt_busy==0 || pp->p_pid!=pts.pt_pid) {
        !           265:                        sleep((char *)&pts.pt_req, CVPTRET, IVPTRET, SVPTRET);
        !           266:                        goto next;
        !           267:                }
        !           268:                switch (pts.pt_req) {
        !           269:                case 1:
        !           270:                        pts.pt_rval = getuwi(pts.pt_addr);
        !           271:                        break;
        !           272:                case 2:
        !           273:                        pts.pt_rval = getuwd(pts.pt_addr);
        !           274:                        break;
        !           275:                case 3:
        !           276:                        if ((unsigned)pts.pt_addr < UPASIZE)
        !           277:                                pts.pt_rval = *(int *)((char *)&u+pts.pt_addr);
        !           278:                        else
        !           279:                                u.u_error = EINVAL;
        !           280:                        break;
        !           281:                case 4:
        !           282:                        putuwi(pts.pt_addr, pts.pt_data);
        !           283:                        break;
        !           284:                case 5:
        !           285:                        putuwd(pts.pt_addr, pts.pt_data);
        !           286:                        break;
        !           287:                case 6:
        !           288:                        if (msetuof(pts.pt_addr, pts.pt_data) == 0)
        !           289:                                u.u_error = EINVAL;
        !           290:                        break;
        !           291:                case 7:
        !           292:                        goto sig;
        !           293:                case 8:
        !           294:                        sign = SIGKILL;
        !           295:                        break;
        !           296:                case 9:
        !           297:                        msigsin();
        !           298:                sig:
        !           299:                        if (pts.pt_data<0 || pts.pt_data>NSIG) {
        !           300:                                u.u_error = EINVAL;
        !           301:                                break;
        !           302:                        }
        !           303:                        sign = pts.pt_data;
        !           304:                        if (pts.pt_addr != SIG_IGN)
        !           305:                                msetppc((vaddr_t)pts.pt_addr);
        !           306:                        break;
        !           307:                default:
        !           308:                        u.u_error = EINVAL;
        !           309:                }
        !           310:                if ((pts.pt_errs=u.u_error) == EFAULT)
        !           311:                        pts.pt_errs = EINVAL;
        !           312:                pts.pt_busy = 0;
        !           313:                wakeup((char *)&pts.pt_busy);
        !           314:        }
        !           315:        return (sign);
        !           316: #endif
        !           317: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.