This source file includes following definitions.
- read_ldt
- write_ldt
- sys_modify_ldt
1
2
3
4
5
6
7 #include <linux/errno.h>
8 #include <linux/sched.h>
9 #include <linux/string.h>
10 #include <linux/mm.h>
11 #include <asm/segment.h>
12 #include <asm/system.h>
13 #include <linux/ldt.h>
14
15 static int read_ldt(void * ptr, unsigned long bytecount)
16 {
17 int error;
18 void * address = current->ldt;
19 unsigned long size;
20
21 if (!ptr)
22 return -EINVAL;
23 size = LDT_ENTRIES*LDT_ENTRY_SIZE;
24 if (!address) {
25 address = &default_ldt;
26 size = sizeof(default_ldt);
27 }
28 if (size > bytecount)
29 size = bytecount;
30 error = verify_area(VERIFY_WRITE, ptr, size);
31 if (error)
32 return error;
33 memcpy_tofs(ptr, address, size);
34 return size;
35 }
36
37 static int write_ldt(void * ptr, unsigned long bytecount)
38 {
39 struct modify_ldt_ldt_s ldt_info;
40 unsigned long *lp;
41 unsigned long base, limit;
42 int error, i;
43
44 if (bytecount != sizeof(ldt_info))
45 return -EINVAL;
46 error = verify_area(VERIFY_READ, ptr, sizeof(ldt_info));
47 if (error)
48 return error;
49
50 memcpy_fromfs(&ldt_info, ptr, sizeof(ldt_info));
51
52 if (ldt_info.contents == 3 || ldt_info.entry_number >= LDT_ENTRIES)
53 return -EINVAL;
54
55 limit = ldt_info.limit;
56 base = ldt_info.base_addr;
57 if (ldt_info.limit_in_pages)
58 limit *= PAGE_SIZE;
59
60 limit += base;
61 if (limit < base || limit >= 0xC0000000)
62 return -EINVAL;
63
64 if (!current->ldt) {
65 for (i=1 ; i<NR_TASKS ; i++) {
66 if (task[i] == current) {
67 if (!(current->ldt = (struct desc_struct*) vmalloc(LDT_ENTRIES*LDT_ENTRY_SIZE)))
68 return -ENOMEM;
69 memset(current->ldt, 0, LDT_ENTRIES*LDT_ENTRY_SIZE);
70 set_ldt_desc(gdt+(i<<1)+FIRST_LDT_ENTRY, current->ldt, LDT_ENTRIES);
71 load_ldt(i);
72 }
73 }
74 }
75
76 lp = (unsigned long *) ¤t->ldt[ldt_info.entry_number];
77
78 if (ldt_info.base_addr == 0 && ldt_info.limit == 0) {
79 *lp = 0;
80 *(lp+1) = 0;
81 return 0;
82 }
83 *lp = ((ldt_info.base_addr & 0x0000ffff) << 16) |
84 (ldt_info.limit & 0x0ffff);
85 *(lp+1) = (ldt_info.base_addr & 0xff000000) |
86 ((ldt_info.base_addr & 0x00ff0000)>>16) |
87 (ldt_info.limit & 0xf0000) |
88 (ldt_info.contents << 10) |
89 ((ldt_info.read_exec_only ^ 1) << 9) |
90 (ldt_info.seg_32bit << 22) |
91 (ldt_info.limit_in_pages << 23) |
92 ((ldt_info.seg_not_present ^1) << 15) |
93 0x7000;
94 return 0;
95 }
96
97 asmlinkage int sys_modify_ldt(int func, void *ptr, unsigned long bytecount)
98 {
99 if (func == 0)
100 return read_ldt(ptr, bytecount);
101 if (func == 1)
102 return write_ldt(ptr, bytecount);
103 return -ENOSYS;
104 }