diff options
Diffstat (limited to 'arch/um/sys-i386/ldt.c')
-rw-r--r-- | arch/um/sys-i386/ldt.c | 217 |
1 files changed, 105 insertions, 112 deletions
diff --git a/arch/um/sys-i386/ldt.c b/arch/um/sys-i386/ldt.c index 906c2a4e7279..0bf7572a80a3 100644 --- a/arch/um/sys-i386/ldt.c +++ b/arch/um/sys-i386/ldt.c | |||
@@ -1,34 +1,26 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com) | 2 | * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include "linux/sched.h" | 6 | #include "linux/mm.h" |
7 | #include "linux/slab.h" | ||
8 | #include "linux/types.h" | ||
9 | #include "linux/errno.h" | ||
10 | #include "linux/spinlock.h" | ||
11 | #include "asm/uaccess.h" | ||
12 | #include "asm/smp.h" | ||
13 | #include "asm/ldt.h" | ||
14 | #include "asm/unistd.h" | 7 | #include "asm/unistd.h" |
15 | #include "kern.h" | ||
16 | #include "os.h" | 8 | #include "os.h" |
17 | 9 | #include "proc_mm.h" | |
18 | extern int modify_ldt(int func, void *ptr, unsigned long bytecount); | ||
19 | |||
20 | #include "skas.h" | 10 | #include "skas.h" |
21 | #include "skas_ptrace.h" | 11 | #include "skas_ptrace.h" |
22 | #include "asm/mmu_context.h" | 12 | #include "sysdep/tls.h" |
23 | #include "proc_mm.h" | 13 | |
14 | extern int modify_ldt(int func, void *ptr, unsigned long bytecount); | ||
24 | 15 | ||
25 | long write_ldt_entry(struct mm_id * mm_idp, int func, struct user_desc * desc, | 16 | long write_ldt_entry(struct mm_id * mm_idp, int func, struct user_desc * desc, |
26 | void **addr, int done) | 17 | void **addr, int done) |
27 | { | 18 | { |
28 | long res; | 19 | long res; |
29 | 20 | ||
30 | if(proc_mm){ | 21 | if (proc_mm) { |
31 | /* This is a special handling for the case, that the mm to | 22 | /* |
23 | * This is a special handling for the case, that the mm to | ||
32 | * modify isn't current->active_mm. | 24 | * modify isn't current->active_mm. |
33 | * If this is called directly by modify_ldt, | 25 | * If this is called directly by modify_ldt, |
34 | * (current->active_mm->context.skas.u == mm_idp) | 26 | * (current->active_mm->context.skas.u == mm_idp) |
@@ -40,12 +32,12 @@ long write_ldt_entry(struct mm_id * mm_idp, int func, struct user_desc * desc, | |||
40 | * | 32 | * |
41 | * Note: I'm unsure: should interrupts be disabled here? | 33 | * Note: I'm unsure: should interrupts be disabled here? |
42 | */ | 34 | */ |
43 | if(!current->active_mm || current->active_mm == &init_mm || | 35 | if (!current->active_mm || current->active_mm == &init_mm || |
44 | mm_idp != ¤t->active_mm->context.skas.id) | 36 | mm_idp != ¤t->active_mm->context.skas.id) |
45 | __switch_mm(mm_idp); | 37 | __switch_mm(mm_idp); |
46 | } | 38 | } |
47 | 39 | ||
48 | if(ptrace_ldt) { | 40 | if (ptrace_ldt) { |
49 | struct ptrace_ldt ldt_op = (struct ptrace_ldt) { | 41 | struct ptrace_ldt ldt_op = (struct ptrace_ldt) { |
50 | .func = func, | 42 | .func = func, |
51 | .ptr = desc, | 43 | .ptr = desc, |
@@ -53,7 +45,7 @@ long write_ldt_entry(struct mm_id * mm_idp, int func, struct user_desc * desc, | |||
53 | u32 cpu; | 45 | u32 cpu; |
54 | int pid; | 46 | int pid; |
55 | 47 | ||
56 | if(!proc_mm) | 48 | if (!proc_mm) |
57 | pid = mm_idp->u.pid; | 49 | pid = mm_idp->u.pid; |
58 | else { | 50 | else { |
59 | cpu = get_cpu(); | 51 | cpu = get_cpu(); |
@@ -62,7 +54,7 @@ long write_ldt_entry(struct mm_id * mm_idp, int func, struct user_desc * desc, | |||
62 | 54 | ||
63 | res = os_ptrace_ldt(pid, 0, (unsigned long) &ldt_op); | 55 | res = os_ptrace_ldt(pid, 0, (unsigned long) &ldt_op); |
64 | 56 | ||
65 | if(proc_mm) | 57 | if (proc_mm) |
66 | put_cpu(); | 58 | put_cpu(); |
67 | } | 59 | } |
68 | else { | 60 | else { |
@@ -71,7 +63,7 @@ long write_ldt_entry(struct mm_id * mm_idp, int func, struct user_desc * desc, | |||
71 | (sizeof(*desc) + sizeof(long) - 1) & | 63 | (sizeof(*desc) + sizeof(long) - 1) & |
72 | ~(sizeof(long) - 1), | 64 | ~(sizeof(long) - 1), |
73 | addr, &stub_addr); | 65 | addr, &stub_addr); |
74 | if(!res){ | 66 | if (!res) { |
75 | unsigned long args[] = { func, | 67 | unsigned long args[] = { func, |
76 | (unsigned long)stub_addr, | 68 | (unsigned long)stub_addr, |
77 | sizeof(*desc), | 69 | sizeof(*desc), |
@@ -81,12 +73,13 @@ long write_ldt_entry(struct mm_id * mm_idp, int func, struct user_desc * desc, | |||
81 | } | 73 | } |
82 | } | 74 | } |
83 | 75 | ||
84 | if(proc_mm){ | 76 | if (proc_mm) { |
85 | /* This is the second part of special handling, that makes | 77 | /* |
78 | * This is the second part of special handling, that makes | ||
86 | * PTRACE_LDT possible to implement. | 79 | * PTRACE_LDT possible to implement. |
87 | */ | 80 | */ |
88 | if(current->active_mm && current->active_mm != &init_mm && | 81 | if (current->active_mm && current->active_mm != &init_mm && |
89 | mm_idp != ¤t->active_mm->context.skas.id) | 82 | mm_idp != ¤t->active_mm->context.skas.id) |
90 | __switch_mm(¤t->active_mm->context.skas.id); | 83 | __switch_mm(¤t->active_mm->context.skas.id); |
91 | } | 84 | } |
92 | 85 | ||
@@ -102,21 +95,22 @@ static long read_ldt_from_host(void __user * ptr, unsigned long bytecount) | |||
102 | .ptr = kmalloc(bytecount, GFP_KERNEL)}; | 95 | .ptr = kmalloc(bytecount, GFP_KERNEL)}; |
103 | u32 cpu; | 96 | u32 cpu; |
104 | 97 | ||
105 | if(ptrace_ldt.ptr == NULL) | 98 | if (ptrace_ldt.ptr == NULL) |
106 | return -ENOMEM; | 99 | return -ENOMEM; |
107 | 100 | ||
108 | /* This is called from sys_modify_ldt only, so userspace_pid gives | 101 | /* |
102 | * This is called from sys_modify_ldt only, so userspace_pid gives | ||
109 | * us the right number | 103 | * us the right number |
110 | */ | 104 | */ |
111 | 105 | ||
112 | cpu = get_cpu(); | 106 | cpu = get_cpu(); |
113 | res = os_ptrace_ldt(userspace_pid[cpu], 0, (unsigned long) &ptrace_ldt); | 107 | res = os_ptrace_ldt(userspace_pid[cpu], 0, (unsigned long) &ptrace_ldt); |
114 | put_cpu(); | 108 | put_cpu(); |
115 | if(res < 0) | 109 | if (res < 0) |
116 | goto out; | 110 | goto out; |
117 | 111 | ||
118 | n = copy_to_user(ptr, ptrace_ldt.ptr, res); | 112 | n = copy_to_user(ptr, ptrace_ldt.ptr, res); |
119 | if(n != 0) | 113 | if (n != 0) |
120 | res = -EFAULT; | 114 | res = -EFAULT; |
121 | 115 | ||
122 | out: | 116 | out: |
@@ -143,33 +137,32 @@ static int read_ldt(void __user * ptr, unsigned long bytecount) | |||
143 | unsigned long size; | 137 | unsigned long size; |
144 | uml_ldt_t * ldt = ¤t->mm->context.skas.ldt; | 138 | uml_ldt_t * ldt = ¤t->mm->context.skas.ldt; |
145 | 139 | ||
146 | if(!ldt->entry_count) | 140 | if (!ldt->entry_count) |
147 | goto out; | 141 | goto out; |
148 | if(bytecount > LDT_ENTRY_SIZE*LDT_ENTRIES) | 142 | if (bytecount > LDT_ENTRY_SIZE*LDT_ENTRIES) |
149 | bytecount = LDT_ENTRY_SIZE*LDT_ENTRIES; | 143 | bytecount = LDT_ENTRY_SIZE*LDT_ENTRIES; |
150 | err = bytecount; | 144 | err = bytecount; |
151 | 145 | ||
152 | if(ptrace_ldt){ | 146 | if (ptrace_ldt) |
153 | return read_ldt_from_host(ptr, bytecount); | 147 | return read_ldt_from_host(ptr, bytecount); |
154 | } | ||
155 | 148 | ||
156 | down(&ldt->semaphore); | 149 | down(&ldt->semaphore); |
157 | if(ldt->entry_count <= LDT_DIRECT_ENTRIES){ | 150 | if (ldt->entry_count <= LDT_DIRECT_ENTRIES) { |
158 | size = LDT_ENTRY_SIZE*LDT_DIRECT_ENTRIES; | 151 | size = LDT_ENTRY_SIZE*LDT_DIRECT_ENTRIES; |
159 | if(size > bytecount) | 152 | if (size > bytecount) |
160 | size = bytecount; | 153 | size = bytecount; |
161 | if(copy_to_user(ptr, ldt->u.entries, size)) | 154 | if (copy_to_user(ptr, ldt->u.entries, size)) |
162 | err = -EFAULT; | 155 | err = -EFAULT; |
163 | bytecount -= size; | 156 | bytecount -= size; |
164 | ptr += size; | 157 | ptr += size; |
165 | } | 158 | } |
166 | else { | 159 | else { |
167 | for(i=0; i<ldt->entry_count/LDT_ENTRIES_PER_PAGE && bytecount; | 160 | for (i=0; i<ldt->entry_count/LDT_ENTRIES_PER_PAGE && bytecount; |
168 | i++){ | 161 | i++) { |
169 | size = PAGE_SIZE; | 162 | size = PAGE_SIZE; |
170 | if(size > bytecount) | 163 | if (size > bytecount) |
171 | size = bytecount; | 164 | size = bytecount; |
172 | if(copy_to_user(ptr, ldt->u.pages[i], size)){ | 165 | if (copy_to_user(ptr, ldt->u.pages[i], size)) { |
173 | err = -EFAULT; | 166 | err = -EFAULT; |
174 | break; | 167 | break; |
175 | } | 168 | } |
@@ -179,10 +172,10 @@ static int read_ldt(void __user * ptr, unsigned long bytecount) | |||
179 | } | 172 | } |
180 | up(&ldt->semaphore); | 173 | up(&ldt->semaphore); |
181 | 174 | ||
182 | if(bytecount == 0 || err == -EFAULT) | 175 | if (bytecount == 0 || err == -EFAULT) |
183 | goto out; | 176 | goto out; |
184 | 177 | ||
185 | if(clear_user(ptr, bytecount)) | 178 | if (clear_user(ptr, bytecount)) |
186 | err = -EFAULT; | 179 | err = -EFAULT; |
187 | 180 | ||
188 | out: | 181 | out: |
@@ -193,15 +186,16 @@ static int read_default_ldt(void __user * ptr, unsigned long bytecount) | |||
193 | { | 186 | { |
194 | int err; | 187 | int err; |
195 | 188 | ||
196 | if(bytecount > 5*LDT_ENTRY_SIZE) | 189 | if (bytecount > 5*LDT_ENTRY_SIZE) |
197 | bytecount = 5*LDT_ENTRY_SIZE; | 190 | bytecount = 5*LDT_ENTRY_SIZE; |
198 | 191 | ||
199 | err = bytecount; | 192 | err = bytecount; |
200 | /* UML doesn't support lcall7 and lcall27. | 193 | /* |
194 | * UML doesn't support lcall7 and lcall27. | ||
201 | * So, we don't really have a default ldt, but emulate | 195 | * So, we don't really have a default ldt, but emulate |
202 | * an empty ldt of common host default ldt size. | 196 | * an empty ldt of common host default ldt size. |
203 | */ | 197 | */ |
204 | if(clear_user(ptr, bytecount)) | 198 | if (clear_user(ptr, bytecount)) |
205 | err = -EFAULT; | 199 | err = -EFAULT; |
206 | 200 | ||
207 | return err; | 201 | return err; |
@@ -217,52 +211,52 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int func) | |||
217 | void *addr = NULL; | 211 | void *addr = NULL; |
218 | 212 | ||
219 | err = -EINVAL; | 213 | err = -EINVAL; |
220 | if(bytecount != sizeof(ldt_info)) | 214 | if (bytecount != sizeof(ldt_info)) |
221 | goto out; | 215 | goto out; |
222 | err = -EFAULT; | 216 | err = -EFAULT; |
223 | if(copy_from_user(&ldt_info, ptr, sizeof(ldt_info))) | 217 | if (copy_from_user(&ldt_info, ptr, sizeof(ldt_info))) |
224 | goto out; | 218 | goto out; |
225 | 219 | ||
226 | err = -EINVAL; | 220 | err = -EINVAL; |
227 | if(ldt_info.entry_number >= LDT_ENTRIES) | 221 | if (ldt_info.entry_number >= LDT_ENTRIES) |
228 | goto out; | 222 | goto out; |
229 | if(ldt_info.contents == 3){ | 223 | if (ldt_info.contents == 3) { |
230 | if (func == 1) | 224 | if (func == 1) |
231 | goto out; | 225 | goto out; |
232 | if (ldt_info.seg_not_present == 0) | 226 | if (ldt_info.seg_not_present == 0) |
233 | goto out; | 227 | goto out; |
234 | } | 228 | } |
235 | 229 | ||
236 | if(!ptrace_ldt) | 230 | if (!ptrace_ldt) |
237 | down(&ldt->semaphore); | 231 | down(&ldt->semaphore); |
238 | 232 | ||
239 | err = write_ldt_entry(mm_idp, func, &ldt_info, &addr, 1); | 233 | err = write_ldt_entry(mm_idp, func, &ldt_info, &addr, 1); |
240 | if(err) | 234 | if (err) |
241 | goto out_unlock; | 235 | goto out_unlock; |
242 | else if(ptrace_ldt) { | 236 | else if (ptrace_ldt) { |
243 | /* With PTRACE_LDT available, this is used as a flag only */ | 237 | /* With PTRACE_LDT available, this is used as a flag only */ |
244 | ldt->entry_count = 1; | 238 | ldt->entry_count = 1; |
245 | goto out; | 239 | goto out; |
246 | } | 240 | } |
247 | 241 | ||
248 | if(ldt_info.entry_number >= ldt->entry_count && | 242 | if (ldt_info.entry_number >= ldt->entry_count && |
249 | ldt_info.entry_number >= LDT_DIRECT_ENTRIES){ | 243 | ldt_info.entry_number >= LDT_DIRECT_ENTRIES) { |
250 | for(i=ldt->entry_count/LDT_ENTRIES_PER_PAGE; | 244 | for (i=ldt->entry_count/LDT_ENTRIES_PER_PAGE; |
251 | i*LDT_ENTRIES_PER_PAGE <= ldt_info.entry_number; | 245 | i*LDT_ENTRIES_PER_PAGE <= ldt_info.entry_number; |
252 | i++){ | 246 | i++) { |
253 | if(i == 0) | 247 | if (i == 0) |
254 | memcpy(&entry0, ldt->u.entries, | 248 | memcpy(&entry0, ldt->u.entries, |
255 | sizeof(entry0)); | 249 | sizeof(entry0)); |
256 | ldt->u.pages[i] = (struct ldt_entry *) | 250 | ldt->u.pages[i] = (struct ldt_entry *) |
257 | __get_free_page(GFP_KERNEL|__GFP_ZERO); | 251 | __get_free_page(GFP_KERNEL|__GFP_ZERO); |
258 | if(!ldt->u.pages[i]){ | 252 | if (!ldt->u.pages[i]) { |
259 | err = -ENOMEM; | 253 | err = -ENOMEM; |
260 | /* Undo the change in host */ | 254 | /* Undo the change in host */ |
261 | memset(&ldt_info, 0, sizeof(ldt_info)); | 255 | memset(&ldt_info, 0, sizeof(ldt_info)); |
262 | write_ldt_entry(mm_idp, 1, &ldt_info, &addr, 1); | 256 | write_ldt_entry(mm_idp, 1, &ldt_info, &addr, 1); |
263 | goto out_unlock; | 257 | goto out_unlock; |
264 | } | 258 | } |
265 | if(i == 0) { | 259 | if (i == 0) { |
266 | memcpy(ldt->u.pages[0], &entry0, | 260 | memcpy(ldt->u.pages[0], &entry0, |
267 | sizeof(entry0)); | 261 | sizeof(entry0)); |
268 | memcpy(ldt->u.pages[0]+1, ldt->u.entries+1, | 262 | memcpy(ldt->u.pages[0]+1, ldt->u.entries+1, |
@@ -271,17 +265,17 @@ static int write_ldt(void __user * ptr, unsigned long bytecount, int func) | |||
271 | ldt->entry_count = (i + 1) * LDT_ENTRIES_PER_PAGE; | 265 | ldt->entry_count = (i + 1) * LDT_ENTRIES_PER_PAGE; |
272 | } | 266 | } |
273 | } | 267 | } |
274 | if(ldt->entry_count <= ldt_info.entry_number) | 268 | if (ldt->entry_count <= ldt_info.entry_number) |
275 | ldt->entry_count = ldt_info.entry_number + 1; | 269 | ldt->entry_count = ldt_info.entry_number + 1; |
276 | 270 | ||
277 | if(ldt->entry_count <= LDT_DIRECT_ENTRIES) | 271 | if (ldt->entry_count <= LDT_DIRECT_ENTRIES) |
278 | ldt_p = ldt->u.entries + ldt_info.entry_number; | 272 | ldt_p = ldt->u.entries + ldt_info.entry_number; |
279 | else | 273 | else |
280 | ldt_p = ldt->u.pages[ldt_info.entry_number/LDT_ENTRIES_PER_PAGE] + | 274 | ldt_p = ldt->u.pages[ldt_info.entry_number/LDT_ENTRIES_PER_PAGE] + |
281 | ldt_info.entry_number%LDT_ENTRIES_PER_PAGE; | 275 | ldt_info.entry_number%LDT_ENTRIES_PER_PAGE; |
282 | 276 | ||
283 | if(ldt_info.base_addr == 0 && ldt_info.limit == 0 && | 277 | if (ldt_info.base_addr == 0 && ldt_info.limit == 0 && |
284 | (func == 1 || LDT_empty(&ldt_info))){ | 278 | (func == 1 || LDT_empty(&ldt_info))) { |
285 | ldt_p->a = 0; | 279 | ldt_p->a = 0; |
286 | ldt_p->b = 0; | 280 | ldt_p->b = 0; |
287 | } | 281 | } |
@@ -332,7 +326,7 @@ static void ldt_get_host_info(void) | |||
332 | 326 | ||
333 | spin_lock(&host_ldt_lock); | 327 | spin_lock(&host_ldt_lock); |
334 | 328 | ||
335 | if(host_ldt_entries != NULL){ | 329 | if (host_ldt_entries != NULL) { |
336 | spin_unlock(&host_ldt_lock); | 330 | spin_unlock(&host_ldt_lock); |
337 | return; | 331 | return; |
338 | } | 332 | } |
@@ -340,49 +334,49 @@ static void ldt_get_host_info(void) | |||
340 | 334 | ||
341 | spin_unlock(&host_ldt_lock); | 335 | spin_unlock(&host_ldt_lock); |
342 | 336 | ||
343 | for(i = LDT_PAGES_MAX-1, order=0; i; i>>=1, order++); | 337 | for (i = LDT_PAGES_MAX-1, order=0; i; i>>=1, order++) |
338 | ; | ||
344 | 339 | ||
345 | ldt = (struct ldt_entry *) | 340 | ldt = (struct ldt_entry *) |
346 | __get_free_pages(GFP_KERNEL|__GFP_ZERO, order); | 341 | __get_free_pages(GFP_KERNEL|__GFP_ZERO, order); |
347 | if(ldt == NULL) { | 342 | if (ldt == NULL) { |
348 | printk("ldt_get_host_info: couldn't allocate buffer for host " | 343 | printk(KERN_ERR "ldt_get_host_info: couldn't allocate buffer " |
349 | "ldt\n"); | 344 | "for host ldt\n"); |
350 | return; | 345 | return; |
351 | } | 346 | } |
352 | 347 | ||
353 | ret = modify_ldt(0, ldt, (1<<order)*PAGE_SIZE); | 348 | ret = modify_ldt(0, ldt, (1<<order)*PAGE_SIZE); |
354 | if(ret < 0) { | 349 | if (ret < 0) { |
355 | printk("ldt_get_host_info: couldn't read host ldt\n"); | 350 | printk(KERN_ERR "ldt_get_host_info: couldn't read host ldt\n"); |
356 | goto out_free; | 351 | goto out_free; |
357 | } | 352 | } |
358 | if(ret == 0) { | 353 | if (ret == 0) { |
359 | /* default_ldt is active, simply write an empty entry 0 */ | 354 | /* default_ldt is active, simply write an empty entry 0 */ |
360 | host_ldt_entries = dummy_list; | 355 | host_ldt_entries = dummy_list; |
361 | goto out_free; | 356 | goto out_free; |
362 | } | 357 | } |
363 | 358 | ||
364 | for(i=0, size=0; i<ret/LDT_ENTRY_SIZE; i++){ | 359 | for (i=0, size=0; i<ret/LDT_ENTRY_SIZE; i++) { |
365 | if(ldt[i].a != 0 || ldt[i].b != 0) | 360 | if (ldt[i].a != 0 || ldt[i].b != 0) |
366 | size++; | 361 | size++; |
367 | } | 362 | } |
368 | 363 | ||
369 | if(size < ARRAY_SIZE(dummy_list)) | 364 | if (size < ARRAY_SIZE(dummy_list)) |
370 | host_ldt_entries = dummy_list; | 365 | host_ldt_entries = dummy_list; |
371 | else { | 366 | else { |
372 | size = (size + 1) * sizeof(dummy_list[0]); | 367 | size = (size + 1) * sizeof(dummy_list[0]); |
373 | tmp = kmalloc(size, GFP_KERNEL); | 368 | tmp = kmalloc(size, GFP_KERNEL); |
374 | if(tmp == NULL) { | 369 | if (tmp == NULL) { |
375 | printk("ldt_get_host_info: couldn't allocate host ldt " | 370 | printk(KERN_ERR "ldt_get_host_info: couldn't allocate " |
376 | "list\n"); | 371 | "host ldt list\n"); |
377 | goto out_free; | 372 | goto out_free; |
378 | } | 373 | } |
379 | host_ldt_entries = tmp; | 374 | host_ldt_entries = tmp; |
380 | } | 375 | } |
381 | 376 | ||
382 | for(i=0, k=0; i<ret/LDT_ENTRY_SIZE; i++){ | 377 | for (i=0, k=0; i<ret/LDT_ENTRY_SIZE; i++) { |
383 | if(ldt[i].a != 0 || ldt[i].b != 0) { | 378 | if (ldt[i].a != 0 || ldt[i].b != 0) |
384 | host_ldt_entries[k++] = i; | 379 | host_ldt_entries[k++] = i; |
385 | } | ||
386 | } | 380 | } |
387 | host_ldt_entries[k] = -1; | 381 | host_ldt_entries[k] = -1; |
388 | 382 | ||
@@ -401,15 +395,15 @@ long init_new_ldt(struct mmu_context_skas * new_mm, | |||
401 | struct proc_mm_op copy; | 395 | struct proc_mm_op copy; |
402 | 396 | ||
403 | 397 | ||
404 | if(!ptrace_ldt) | 398 | if (!ptrace_ldt) |
405 | init_MUTEX(&new_mm->ldt.semaphore); | 399 | init_MUTEX(&new_mm->ldt.semaphore); |
406 | 400 | ||
407 | if(!from_mm){ | 401 | if (!from_mm) { |
408 | memset(&desc, 0, sizeof(desc)); | 402 | memset(&desc, 0, sizeof(desc)); |
409 | /* | 403 | /* |
410 | * We have to initialize a clean ldt. | 404 | * We have to initialize a clean ldt. |
411 | */ | 405 | */ |
412 | if(proc_mm) { | 406 | if (proc_mm) { |
413 | /* | 407 | /* |
414 | * If the new mm was created using proc_mm, host's | 408 | * If the new mm was created using proc_mm, host's |
415 | * default-ldt currently is assigned, which normally | 409 | * default-ldt currently is assigned, which normally |
@@ -417,8 +411,7 @@ long init_new_ldt(struct mmu_context_skas * new_mm, | |||
417 | * To remove these gates, we simply write an empty | 411 | * To remove these gates, we simply write an empty |
418 | * entry as number 0 to the host. | 412 | * entry as number 0 to the host. |
419 | */ | 413 | */ |
420 | err = write_ldt_entry(&new_mm->id, 1, &desc, | 414 | err = write_ldt_entry(&new_mm->id, 1, &desc, &addr, 1); |
421 | &addr, 1); | ||
422 | } | 415 | } |
423 | else{ | 416 | else{ |
424 | /* | 417 | /* |
@@ -427,11 +420,11 @@ long init_new_ldt(struct mmu_context_skas * new_mm, | |||
427 | * will be reset in the following loop | 420 | * will be reset in the following loop |
428 | */ | 421 | */ |
429 | ldt_get_host_info(); | 422 | ldt_get_host_info(); |
430 | for(num_p=host_ldt_entries; *num_p != -1; num_p++){ | 423 | for (num_p=host_ldt_entries; *num_p != -1; num_p++) { |
431 | desc.entry_number = *num_p; | 424 | desc.entry_number = *num_p; |
432 | err = write_ldt_entry(&new_mm->id, 1, &desc, | 425 | err = write_ldt_entry(&new_mm->id, 1, &desc, |
433 | &addr, *(num_p + 1) == -1); | 426 | &addr, *(num_p + 1) == -1); |
434 | if(err) | 427 | if (err) |
435 | break; | 428 | break; |
436 | } | 429 | } |
437 | } | 430 | } |
@@ -440,8 +433,9 @@ long init_new_ldt(struct mmu_context_skas * new_mm, | |||
440 | goto out; | 433 | goto out; |
441 | } | 434 | } |
442 | 435 | ||
443 | if(proc_mm){ | 436 | if (proc_mm) { |
444 | /* We have a valid from_mm, so we now have to copy the LDT of | 437 | /* |
438 | * We have a valid from_mm, so we now have to copy the LDT of | ||
445 | * from_mm to new_mm, because using proc_mm an new mm with | 439 | * from_mm to new_mm, because using proc_mm an new mm with |
446 | * an empty/default LDT was created in new_mm() | 440 | * an empty/default LDT was created in new_mm() |
447 | */ | 441 | */ |
@@ -450,27 +444,27 @@ long init_new_ldt(struct mmu_context_skas * new_mm, | |||
450 | { .copy_segments = | 444 | { .copy_segments = |
451 | from_mm->id.u.mm_fd } } ); | 445 | from_mm->id.u.mm_fd } } ); |
452 | i = os_write_file(new_mm->id.u.mm_fd, ©, sizeof(copy)); | 446 | i = os_write_file(new_mm->id.u.mm_fd, ©, sizeof(copy)); |
453 | if(i != sizeof(copy)) | 447 | if (i != sizeof(copy)) |
454 | printk("new_mm : /proc/mm copy_segments failed, " | 448 | printk(KERN_ERR "new_mm : /proc/mm copy_segments " |
455 | "err = %d\n", -i); | 449 | "failed, err = %d\n", -i); |
456 | } | 450 | } |
457 | 451 | ||
458 | if(!ptrace_ldt) { | 452 | if (!ptrace_ldt) { |
459 | /* Our local LDT is used to supply the data for | 453 | /* |
454 | * Our local LDT is used to supply the data for | ||
460 | * modify_ldt(READLDT), if PTRACE_LDT isn't available, | 455 | * modify_ldt(READLDT), if PTRACE_LDT isn't available, |
461 | * i.e., we have to use the stub for modify_ldt, which | 456 | * i.e., we have to use the stub for modify_ldt, which |
462 | * can't handle the big read buffer of up to 64kB. | 457 | * can't handle the big read buffer of up to 64kB. |
463 | */ | 458 | */ |
464 | down(&from_mm->ldt.semaphore); | 459 | down(&from_mm->ldt.semaphore); |
465 | if(from_mm->ldt.entry_count <= LDT_DIRECT_ENTRIES){ | 460 | if (from_mm->ldt.entry_count <= LDT_DIRECT_ENTRIES) |
466 | memcpy(new_mm->ldt.u.entries, from_mm->ldt.u.entries, | 461 | memcpy(new_mm->ldt.u.entries, from_mm->ldt.u.entries, |
467 | sizeof(new_mm->ldt.u.entries)); | 462 | sizeof(new_mm->ldt.u.entries)); |
468 | } | 463 | else { |
469 | else{ | ||
470 | i = from_mm->ldt.entry_count / LDT_ENTRIES_PER_PAGE; | 464 | i = from_mm->ldt.entry_count / LDT_ENTRIES_PER_PAGE; |
471 | while(i-->0){ | 465 | while (i-->0) { |
472 | page = __get_free_page(GFP_KERNEL|__GFP_ZERO); | 466 | page = __get_free_page(GFP_KERNEL|__GFP_ZERO); |
473 | if (!page){ | 467 | if (!page) { |
474 | err = -ENOMEM; | 468 | err = -ENOMEM; |
475 | break; | 469 | break; |
476 | } | 470 | } |
@@ -493,11 +487,10 @@ void free_ldt(struct mmu_context_skas * mm) | |||
493 | { | 487 | { |
494 | int i; | 488 | int i; |
495 | 489 | ||
496 | if(!ptrace_ldt && mm->ldt.entry_count > LDT_DIRECT_ENTRIES){ | 490 | if (!ptrace_ldt && mm->ldt.entry_count > LDT_DIRECT_ENTRIES) { |
497 | i = mm->ldt.entry_count / LDT_ENTRIES_PER_PAGE; | 491 | i = mm->ldt.entry_count / LDT_ENTRIES_PER_PAGE; |
498 | while(i-- > 0){ | 492 | while (i-- > 0) |
499 | free_page((long )mm->ldt.u.pages[i]); | 493 | free_page((long) mm->ldt.u.pages[i]); |
500 | } | ||
501 | } | 494 | } |
502 | mm->ldt.entry_count = 0; | 495 | mm->ldt.entry_count = 0; |
503 | } | 496 | } |