This source file includes following definitions.
- read_ldt
- write_ldt
- sys_modify_ldt
1
2
3
4
5
6
7 #include <linux/config.h>
8 #include <linux/errno.h>
9 #include <linux/sched.h>
10 #include <linux/string.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 #ifdef NOTDEF_KLUDGE
62 if (limit < base || limit >= 0xC0000000)
63 return -EINVAL;
64 #endif
65
66 if (!current->ldt) {
67 for (i=1 ; i<NR_TASKS ; i++) {
68 if (task[i] == current) {
69 if (!(current->ldt = (struct desc_struct*) vmalloc(LDT_ENTRIES*LDT_ENTRY_SIZE)))
70 return -ENOMEM;
71 set_ldt_desc(gdt+(i<<1)+FIRST_LDT_ENTRY, current->ldt, LDT_ENTRIES);
72 load_ldt(i);
73 }
74 }
75 }
76
77 lp = (unsigned long *) ¤t->ldt[ldt_info.entry_number];
78
79 if (ldt_info.base_addr == 0 && ldt_info.limit == 0) {
80 *lp = 0;
81 *(lp+1) = 0;
82 return 0;
83 }
84 *lp = ((ldt_info.base_addr & 0x0000ffff) << 16) |
85 (ldt_info.limit & 0x0ffff);
86 *(lp+1) = (ldt_info.base_addr & 0xff000000) |
87 ((ldt_info.base_addr & 0x00ff0000)>>16) |
88 (ldt_info.limit & 0xf0000) |
89 (ldt_info.contents << 10) |
90 ((ldt_info.read_exec_only ^ 1) << 9) |
91 (ldt_info.seg_32bit << 22) |
92 (ldt_info.limit_in_pages << 23) |
93 ((ldt_info.seg_not_present ^1) << 15) |
94 0x7000;
95 return 0;
96 }
97
98 asmlinkage int sys_modify_ldt(int func, void *ptr, unsigned long bytecount)
99 {
100 if (func == 0)
101 return read_ldt(ptr, bytecount);
102 if (func == 1)
103 return write_ldt(ptr, bytecount);
104 return -ENOSYS;
105 }