2 * linux/arch/i386/kernel/ioport.c
4 * This contains the io-permission bitmap code - written by obz, with changes
8 #include <linux/sched.h>
9 #include <linux/kernel.h>
10 #include <linux/errno.h>
11 #include <linux/types.h>
12 #include <linux/ioport.h>
14 #include <linux/smp.h>
15 #include <linux/smp_lock.h>
16 #include <linux/stddef.h>
18 /* Set EXTENT bits starting at BASE in BITMAP to value TURN_ON. */
19 static void set_bitmap(unsigned long *bitmap
, short base
, short extent
, int new_value
)
22 unsigned long *bitmap_base
= bitmap
+ (base
>> 5);
23 unsigned short low_index
= base
& 0x1f;
24 int length
= low_index
+ extent
;
27 mask
= (~0 << low_index
);
29 mask
&= ~(~0 << length
);
31 *bitmap_base
++ |= mask
;
33 *bitmap_base
++ &= ~mask
;
37 mask
= (new_value
? ~0 : 0);
38 while (length
>= 32) {
39 *bitmap_base
++ = mask
;
44 mask
= ~(~0 << length
);
46 *bitmap_base
++ |= mask
;
48 *bitmap_base
++ &= ~mask
;
53 * this changes the io permissions bitmap in the current task.
55 asmlinkage
int sys_ioperm(unsigned long from
, unsigned long num
, int turn_on
)
57 struct thread_struct
* t
= ¤t
->thread
;
58 struct tss_struct
* tss
= init_tss
+ smp_processor_id();
60 if ((from
+ num
<= from
) || (from
+ num
> IO_BITMAP_SIZE
*32))
62 if (turn_on
&& !capable(CAP_SYS_RAWIO
))
65 * If it's the first ioperm() call in this thread's lifetime, set the
66 * IO bitmap up. ioperm() is much less timing critical than clone(),
67 * this is why we delay this operation until now:
73 memset(t
->io_bitmap
,0xff,(IO_BITMAP_SIZE
+1)*4);
76 * this activates it in the TSS
78 tss
->bitmap
= IO_BITMAP_OFFSET
;
82 * do it in the per-thread copy and in the TSS ...
84 set_bitmap(t
->io_bitmap
, from
, num
, !turn_on
);
85 set_bitmap(tss
->io_bitmap
, from
, num
, !turn_on
);
91 * sys_iopl has to be used when you want to access the IO ports
92 * beyond the 0x3ff range: to get the full 65536 ports bitmapped
93 * you'd need 8kB of bitmaps/process, which is a bit excessive.
95 * Here we just change the eflags value on the stack: we allow
96 * only the super-user to do it. This depends on the stack-layout
97 * on system-call entry - see also fork() and the signal handling
101 asmlinkage
int sys_iopl(unsigned long unused
)
103 struct pt_regs
* regs
= (struct pt_regs
*) &unused
;
104 unsigned int level
= regs
->ebx
;
105 unsigned int old
= (regs
->eflags
>> 12) & 3;
109 /* Trying to gain more privileges? */
111 if (!capable(CAP_SYS_RAWIO
))
114 regs
->eflags
= (regs
->eflags
& 0xffffcfff) | (level
<< 12);