2 * This contains the io-permission bitmap code - written by obz, with changes
3 * by Linus. 32/64 bits code unification by Miguel Botón.
6 #include <linux/sched.h>
7 #include <linux/kernel.h>
8 #include <linux/capability.h>
9 #include <linux/errno.h>
10 #include <linux/types.h>
11 #include <linux/ioport.h>
12 #include <linux/smp.h>
13 #include <linux/stddef.h>
14 #include <linux/slab.h>
15 #include <linux/thread_info.h>
16 #include <linux/syscalls.h>
17 #include <linux/bitmap.h>
18 #include <asm/syscalls.h>
19 #include <xen/interface/physdev.h>
22 * this changes the io permissions bitmap in the current task.
24 asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
26 struct thread_struct *t = ¤t->thread;
27 struct physdev_set_iobitmap set_iobitmap;
29 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
31 if (turn_on && !capable(CAP_SYS_RAWIO))
35 * If it's the first ioperm() call in this thread's lifetime, set the
36 * IO bitmap up. ioperm() is much less timing critical than clone(),
37 * this is why we delay this operation until now:
39 if (!t->io_bitmap_ptr) {
40 unsigned long *bitmap = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
45 memset(bitmap, 0xff, IO_BITMAP_BYTES);
46 t->io_bitmap_ptr = bitmap;
47 set_thread_flag(TIF_IO_BITMAP);
49 set_xen_guest_handle(set_iobitmap.bitmap, (char *)bitmap);
50 set_iobitmap.nr_ports = IO_BITMAP_BITS;
51 WARN_ON(HYPERVISOR_physdev_op(PHYSDEVOP_set_iobitmap,
56 bitmap_clear(t->io_bitmap_ptr, from, num);
58 bitmap_set(t->io_bitmap_ptr, from, num);
64 * sys_iopl has to be used when you want to access the IO ports
65 * beyond the 0x3ff range: to get the full 65536 ports bitmapped
66 * you'd need 8kB of bitmaps/process, which is a bit excessive.
68 long sys_iopl(unsigned int level, struct pt_regs *regs)
70 struct thread_struct *t = ¤t->thread;
71 unsigned int old = t->iopl >> 12;
75 /* Trying to gain more privileges? */
77 if (!capable(CAP_SYS_RAWIO))
80 t->iopl = level << 12;
81 set_iopl_mask(t->iopl);