1
2
3
4
5
6
7
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>
13#include <linux/mm.h>
14#include <linux/slab.h>
15#include <linux/smp.h>
16#include <linux/smp_lock.h>
17#include <linux/stddef.h>
18
19
20static void set_bitmap(unsigned long *bitmap, short base, short extent, int new_value)
21{
22 int i;
23 if (new_value)
24 for (i = base; i < base + extent; i++)
25 __set_bit(i, bitmap);
26 else
27 for (i = base; i < base + extent; i++)
28 clear_bit(i, bitmap);
29}
30
31
32
33
34asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
35{
36 struct thread_struct * t = ¤t->thread;
37 struct tss_struct * tss = init_tss + smp_processor_id();
38
39 if ((from + num <= from) || (from + num > IO_BITMAP_SIZE*32))
40 return -EINVAL;
41 if (turn_on && !capable(CAP_SYS_RAWIO))
42 return -EPERM;
43
44
45
46
47
48 if (!t->io_bitmap_ptr) {
49 t->io_bitmap_ptr = kmalloc((IO_BITMAP_SIZE+1)*4, GFP_KERNEL);
50 if (!t->io_bitmap_ptr)
51 return -ENOMEM;
52
53 memset(t->io_bitmap_ptr,0xff,(IO_BITMAP_SIZE+1)*4);
54
55
56
57 }
58
59
60
61
62 set_bitmap((unsigned long *) t->io_bitmap_ptr, from, num, !turn_on);
63 if (tss->io_map_base != IO_BITMAP_OFFSET) {
64 memcpy(tss->io_bitmap, t->io_bitmap_ptr, sizeof(tss->io_bitmap));
65 tss->io_map_base = IO_BITMAP_OFFSET;
66 } else {
67 set_bitmap((unsigned long *) tss->io_bitmap, from, num, !turn_on);
68 }
69
70 return 0;
71}
72
73
74
75
76
77
78
79
80
81
82
83
84asmlinkage long sys_iopl(unsigned int level, struct pt_regs regs)
85{
86 unsigned int old = (regs.eflags >> 12) & 3;
87
88 if (level > 3)
89 return -EINVAL;
90
91 if (level > old) {
92 if (!capable(CAP_SYS_RAWIO))
93 return -EPERM;
94 }
95 regs.eflags = (regs.eflags & 0xffffffffffffcfff) | (level << 12);
96 return 0;
97}
98