Annotation of linux/kernel/ioport.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *     linux/kernel/ioport.c
                      3:  *
                      4:  * This contains the io-permission bitmap code - written by obz, with changes
                      5:  * by Linus.
                      6:  */
                      7: 
                      8: #include <linux/sched.h>
                      9: #include <linux/kernel.h>
                     10: 
                     11: #include <sys/types.h>
                     12: #include <errno.h>
                     13: 
                     14: #define _IODEBUG
                     15: 
                     16: #ifdef IODEBUG
                     17: static char * ios(unsigned long l)
                     18: {
                     19:        static char str[33] = { '\0' };
                     20:        int i;
                     21:        unsigned long mask;
                     22: 
                     23:        for (i = 0, mask = 0x80000000; i < 32; ++i, mask >>= 1)
                     24:                str[i] = (l & mask) ? '1' : '0';
                     25:        return str;
                     26: }
                     27: 
                     28: static void dump_io_bitmap(void)
                     29: {
                     30:        int i, j;
                     31:        int numl = sizeof(current->tss.io_bitmap) >> 2;
                     32: 
                     33:        for (i = j = 0; j < numl; ++i)
                     34:        {
                     35:                printk("%4d [%3x]: ", 64*i, 64*i);
                     36:                printk("%s ", ios(current->tss.io_bitmap[j++]));
                     37:                if (j < numl)
                     38:                        printk("%s", ios(current->tss.io_bitmap[j++]));
                     39:                printk("\n");
                     40:        }
                     41: }
                     42: #endif
                     43: 
                     44: /*
                     45:  * this changes the io permissions bitmap in the current task.
                     46:  */
                     47: int sys_ioperm(unsigned long from, unsigned long num, int turn_on)
                     48: {
                     49:        unsigned long froml, lindex, tnum, numl, rindex, mask;
                     50:        unsigned long *iop;
                     51: 
                     52:        froml = from >> 5;
                     53:        lindex = from & 0x1f;
                     54:        tnum = lindex + num;
                     55:        numl = (tnum + 0x1f) >> 5;
                     56:        rindex = tnum & 0x1f;
                     57: 
                     58:        if (!suser())
                     59:                return -EPERM;
                     60:        if (froml * 32 + tnum > sizeof(current->tss.io_bitmap) * 8 - 8)
                     61:                return -EINVAL;
                     62: 
                     63: #ifdef IODEBUG
                     64:        printk("io: from=%d num=%d %s\n", from, num, (turn_on ? "on" : "off"));
                     65: #endif
                     66: 
                     67:        if (numl) {
                     68:                iop = (unsigned long *)current->tss.io_bitmap + froml;
                     69:                if (lindex != 0) {
                     70:                        mask = (~0 << lindex);
                     71:                        if (--numl == 0 && rindex)
                     72:                                mask &= ~(~0 << rindex);
                     73:                        if (turn_on)
                     74:                                *iop++ &= ~mask;
                     75:                        else
                     76:                                *iop++ |= mask;
                     77:                }
                     78:                if (numl) {
                     79:                        if (rindex)
                     80:                                --numl;
                     81:                        mask = (turn_on ? 0 : ~0);
                     82:                        while (numl--)
                     83:                                *iop++ = mask;
                     84:                        if (numl && rindex) {
                     85:                                mask = ~(~0 << rindex);
                     86:                                if (turn_on)
                     87:                                        *iop++ &= ~mask;
                     88:                                else
                     89:                                        *iop++ |= mask;
                     90:                        }
                     91:                }
                     92:        }
                     93:        return 0;
                     94: }

unix.superglobalmegacorp.com

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