ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / um / sys-i386 / ldt.c
1 /*
2  * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #include "linux/config.h"
7 #include "linux/slab.h"
8 #include "asm/uaccess.h"
9 #include "asm/ptrace.h"
10 #include "choose-mode.h"
11 #include "kern.h"
12
13 #ifdef CONFIG_MODE_TT
14 extern int modify_ldt(int func, void *ptr, unsigned long bytecount);
15
16 int sys_modify_ldt_tt(int func, void *ptr, unsigned long bytecount)
17 {
18         if(verify_area(VERIFY_READ, ptr, bytecount)) return(-EFAULT);
19         return(modify_ldt(func, ptr, bytecount));
20 }
21 #endif
22
23 #ifdef CONFIG_MODE_SKAS
24 extern int userspace_pid;
25
26 int sys_modify_ldt_skas(int func, void *ptr, unsigned long bytecount)
27 {
28         struct ptrace_ldt ldt;
29         void *buf;
30         int res, n;
31
32         buf = kmalloc(bytecount, GFP_KERNEL);
33         if(buf == NULL)
34                 return(-ENOMEM);
35
36         res = 0;
37
38         switch(func){
39         case 1:
40         case 0x11:
41                 res = copy_from_user(buf, ptr, bytecount);
42                 break;
43         }
44
45         if(res != 0){
46                 res = -EFAULT;
47                 goto out;
48         }
49
50         ldt = ((struct ptrace_ldt) { .func      = func,
51                                      .ptr       = buf,
52                                      .bytecount = bytecount });
53         res = ptrace(PTRACE_LDT, userspace_pid, 0, (unsigned long) &ldt);
54         if(res < 0)
55                 goto out;
56
57         switch(func){
58         case 0:
59         case 2:
60                 n = res;
61                 res = copy_to_user(ptr, buf, n);
62                 if(res != 0)
63                         res = -EFAULT;
64                 else 
65                         res = n;
66                 break;
67         }
68
69  out:
70         kfree(buf);
71         return(res);
72 }
73 #endif
74
75 int sys_modify_ldt(int func, void *ptr, unsigned long bytecount)
76 {
77         return(CHOOSE_MODE_PROC(sys_modify_ldt_tt, sys_modify_ldt_skas, func, 
78                                 ptr, bytecount));
79 }
80
81
82
83 /*
84  * Overrides for Emacs so that we follow Linus's tabbing style.
85  * Emacs will notice this stuff at the end of the file and automatically
86  * adjust the settings for this buffer only.  This must remain at the end
87  * of the file.
88  * ---------------------------------------------------------------------------
89  * Local variables:
90  * c-file-style: "linux"
91  * End:
92  */