Annotation of cci/usr/src/bin/adb/access.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *
        !             3:  *     UNIX debugger
        !             4:  *
        !             5:  */
        !             6: 
        !             7: #include "defs.h"
        !             8: 
        !             9: MSG            BADDAT;
        !            10: MSG            BADTXT;
        !            11: MSG            ADDOOS;
        !            12: MSG            BADBR;
        !            13: MSG            BADPT;
        !            14: MSG            BADPAGE;
        !            15: MAP            txtmap;
        !            16: MAP            datmap;
        !            17: INT            wtflag;
        !            18: STRING         errflg;
        !            19: INT            errno;
        !            20: 
        !            21: L_INT          pid;
        !            22: 
        !            23: /* file handling and access routines */
        !            24: 
        !            25: put(adr,space,value)
        !            26: #ifndef EDDT
        !            27: L_INT  adr;
        !            28: {
        !            29:        access(WT,adr,space,value);
        !            30: }
        !            31: #else
        !            32:        L_INT *adr; {*adr=value;}
        !            33: #endif
        !            34: 
        !            35: POS    get(adr, space)
        !            36: #ifndef EDDT
        !            37: L_INT          adr;
        !            38: {
        !            39:        return(access(RD,adr,space,0));
        !            40: }
        !            41: #else
        !            42:        L_INT *adr; {return(*adr);}
        !            43: #endif
        !            44: 
        !            45: POS    chkget(n, space)
        !            46: L_INT          n;
        !            47: {
        !            48:        REG w;
        !            49: 
        !            50:        w = get(n, space);
        !            51:        chkerr();
        !            52:        return(w);
        !            53: }
        !            54: 
        !            55: POS bchkget(n, space) 
        !            56: L_INT  n;
        !            57: {
        !            58:        return(byte(chkget(n, space)));
        !            59: }
        !            60: 
        !            61: /*
        !            62:  * When the kernel is being debugged with the -k flag we interpret
        !            63:  * the system page tables for data space, mapping p0 and p2 addresses
        !            64:  * relative to the 'current' process (as specified by its p_addr in <p)
        !            65:  * and mapping system space addresses through the system page tables.
        !            66:  */
        !            67: #ifndef EDDT
        !            68: access(mode,adr,space,value)
        !            69: L_INT  adr;
        !            70: ADDR   value;
        !            71: {
        !            72:        REG     pmode,rd,file;
        !            73:        ADDR    w;
        !            74:        rd = mode==RD;
        !            75: 
        !            76:        IF space == NSP THEN return(0); FI
        !            77: 
        !            78:        IF pid          /* tracing on? */
        !            79:        THEN
        !            80:             pmode = (space&DSP?(rd?RDUSER:WDUSER):(rd?RIUSER:WIUSER));
        !            81:             w = ptrace(pmode, pid, adr, value);
        !            82:             IF errno
        !            83:             THEN errflg = (space&DSP ? BADDAT : BADTXT);
        !            84:             FI
        !            85:             return(w);
        !            86:        FI
        !            87:        w = 0;
        !            88:        IF mode==WT ANDF wtflag==0
        !            89:        THEN    error("not in write mode");
        !            90:        FI
        !            91:        IF !chkmap(&adr,space)
        !            92:        THEN return(0);
        !            93:        FI
        !            94:        file=(space&DSP?datmap.ufd:txtmap.ufd);
        !            95:        IF kernel ANDF space == DSP
        !            96:        THEN
        !            97:                adr = vtophys(adr);
        !            98:                IF (adr < 0)
        !            99:                THEN return(0);
        !           100:                FI
        !           101:        FI
        !           102:        IF physrw(file,adr,rd ? &w : &value,rd) < 0
        !           103:        THEN    errflg=(space&DSP?BADDAT:BADTXT);
        !           104:        FI
        !           105:        return(w);
        !           106: }
        !           107: #endif
        !           108: 
        !           109: /*
        !           110:  * When looking at kernel data space through /dev/mem or
        !           111:  * with a core file, do virtual memory mapping.
        !           112:  */
        !           113: vtophys(addr)
        !           114:        off_t addr;
        !           115: {
        !           116:        REG     v, oldaddr = addr;
        !           117:        STRUCT  pte pte;
        !           118: 
        !           119:        addr &= ~0xc0000000;
        !           120:        v = btop(addr);
        !           121:        switch (oldaddr&0xc0000000) {
        !           122: 
        !           123:        case 0xc0000000:
        !           124:                /*
        !           125:                 * In system space get system pte.  If
        !           126:                 * valid or reclaimable then physical address
        !           127:                 * is combination of its page number and the page
        !           128:                 * offset of the original address.
        !           129:                 */
        !           130:                IF v > slr
        !           131:                THEN goto oor;
        !           132:                FI
        !           133:                addr = ((long)(sbr + v)) & ~0xc0000000;
        !           134:                goto simple;
        !           135: 
        !           136:        default:
        !           137:                return(-1);
        !           138:        oor:
        !           139:                errflg = ADDOOS;
        !           140:                return(-1);
        !           141:        }
        !           142: simple:
        !           143:        /*
        !           144:         * Addr is now address of the pte of the page we
        !           145:         * are interested in; get the pte and paste up the
        !           146:         * physical address.
        !           147:         */
        !           148:        IF physrw(fcor, addr, (int *)&pte, 1) < 0
        !           149:        THEN
        !           150:                errflg = BADPT;
        !           151:                return(-1);
        !           152:        FI
        !           153:        IF pte.pg_v == 0 ANDF (pte.pg_fod ORF pte.pg_pfnum == 0)
        !           154:        THEN
        !           155:                errflg = BADPAGE;
        !           156:                return(-1);
        !           157:        FI
        !           158:        return((ADDR)ptob(pte.pg_pfnum) + (oldaddr & PGOFSET));
        !           159: }
        !           160: 
        !           161: physrw(file,addr,aw,rd)
        !           162:        off_t addr;
        !           163:        REG *aw, rd;
        !           164: {
        !           165: 
        !           166:        IF longseek(file,addr)==0 ORF
        !           167:           (rd ? read(file,aw,sizeof(int)) : write(file,aw,sizeof(int))) < 1
        !           168:        THEN    return(-1);
        !           169:        FI
        !           170:        return(0);
        !           171: }
        !           172: 
        !           173: chkmap(adr,space)
        !           174:        REG POS *adr;
        !           175:        REG space;
        !           176: {
        !           177:        REG MAPPTR amap;
        !           178:        amap=((space&DSP?&datmap:&txtmap));
        !           179:        IF space&STAR ORF !within(*adr,amap->b1,amap->e1)
        !           180:        THEN IF within(*adr,amap->b2,amap->e2)
        !           181:             THEN *adr += (amap->f2)-(amap->b2);
        !           182:             ELSE errflg=(space&DSP?BADDAT:BADTXT); return(0);
        !           183:             FI
        !           184:        ELSE *adr += (amap->f1)-(amap->b1);
        !           185:        FI
        !           186:        return(1);
        !           187: }
        !           188: 
        !           189: within(adr,lbd,ubd)
        !           190: POS    adr, lbd, ubd;
        !           191: {
        !           192:        return(adr>=lbd && adr<ubd);
        !           193: }
        !           194: 
        !           195: longseek(f, a)
        !           196: L_INT a;
        !           197: {
        !           198:        return(lseek(f,a,0) != -1);
        !           199: }

unix.superglobalmegacorp.com

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