[PATCH] uml: obvious compile fixes for x86-64 Subarch and x86 regression fixes
[safe/jmp/linux-2.6] / arch / um / sys-x86_64 / syscalls.c
1 /*
2  * Copyright 2003 PathScale, Inc.
3  *
4  * Licensed under the GPL
5  */
6
7 #include "linux/linkage.h"
8 #include "linux/slab.h"
9 #include "linux/shm.h"
10 #include "linux/utsname.h"
11 #include "linux/personality.h"
12 #include "asm/uaccess.h"
13 #define __FRAME_OFFSETS
14 #include "asm/ptrace.h"
15 #include "asm/unistd.h"
16 #include "asm/prctl.h" /* XXX This should get the constants from libc */
17 #include "choose-mode.h"
18
19 asmlinkage long sys_uname64(struct new_utsname __user * name)
20 {
21         int err;
22         down_read(&uts_sem);
23         err = copy_to_user(name, &system_utsname, sizeof (*name));
24         up_read(&uts_sem);
25         if (personality(current->personality) == PER_LINUX32)
26                 err |= copy_to_user(&name->machine, "i686", 5);
27         return err ? -EFAULT : 0;
28 }
29
30 #ifdef CONFIG_MODE_TT
31 extern int modify_ldt(int func, void *ptr, unsigned long bytecount);
32
33 long sys_modify_ldt_tt(int func, void *ptr, unsigned long bytecount)
34 {
35         /* XXX This should check VERIFY_WRITE depending on func, check this
36          * in i386 as well.
37          */
38         if (!access_ok(VERIFY_READ, ptr, bytecount))
39                 return -EFAULT;
40         return(modify_ldt(func, ptr, bytecount));
41 }
42 #endif
43
44 #ifdef CONFIG_MODE_SKAS
45 extern int userspace_pid[];
46
47 long sys_modify_ldt_skas(int func, void *ptr, unsigned long bytecount)
48 {
49         struct ptrace_ldt ldt;
50         void *buf;
51         int res, n;
52
53         buf = kmalloc(bytecount, GFP_KERNEL);
54         if(buf == NULL)
55                 return(-ENOMEM);
56
57         res = 0;
58
59         switch(func){
60         case 1:
61         case 0x11:
62                 res = copy_from_user(buf, ptr, bytecount);
63                 break;
64         }
65
66         if(res != 0){
67                 res = -EFAULT;
68                 goto out;
69         }
70
71         ldt = ((struct ptrace_ldt) { .func      = func,
72                                      .ptr       = buf,
73                                      .bytecount = bytecount });
74 #warning Need to look up userspace_pid by cpu
75         res = ptrace(PTRACE_LDT, userspace_pid[0], 0, (unsigned long) &ldt);
76         if(res < 0)
77                 goto out;
78
79         switch(func){
80         case 0:
81         case 2:
82                 n = res;
83                 res = copy_to_user(ptr, buf, n);
84                 if(res != 0)
85                         res = -EFAULT;
86                 else
87                         res = n;
88                 break;
89         }
90
91  out:
92         kfree(buf);
93         return(res);
94 }
95 #endif
96
97 long sys_modify_ldt(int func, void *ptr, unsigned long bytecount)
98 {
99         return(CHOOSE_MODE_PROC(sys_modify_ldt_tt, sys_modify_ldt_skas, func,
100                                 ptr, bytecount));
101 }
102
103 #ifdef CONFIG_MODE_TT
104 extern long arch_prctl(int code, unsigned long addr);
105
106 static long arch_prctl_tt(int code, unsigned long addr)
107 {
108         unsigned long tmp;
109         long ret;
110
111         switch(code){
112         case ARCH_SET_GS:
113         case ARCH_SET_FS:
114                 ret = arch_prctl(code, addr);
115                 break;
116         case ARCH_GET_FS:
117         case ARCH_GET_GS:
118                 ret = arch_prctl(code, (unsigned long) &tmp);
119                 if(!ret)
120                         ret = put_user(tmp, &addr);
121                 break;
122         default:
123                 ret = -EINVAL;
124                 break;
125         }
126
127         return(ret);
128 }
129 #endif
130
131 #ifdef CONFIG_MODE_SKAS
132
133 static long arch_prctl_skas(int code, unsigned long addr)
134 {
135         long ret = 0;
136
137         switch(code){
138         case ARCH_SET_GS:
139                 current->thread.regs.regs.skas.regs[GS_BASE / sizeof(unsigned long)] = addr;
140                 break;
141         case ARCH_SET_FS:
142                 current->thread.regs.regs.skas.regs[FS_BASE / sizeof(unsigned long)] = addr;
143                 break;
144         case ARCH_GET_FS:
145                 ret = put_user(current->thread.regs.regs.skas.regs[GS / sizeof(unsigned long)], &addr);
146                 break;
147         case ARCH_GET_GS:
148                 ret = put_user(current->thread.regs.regs.skas.regs[FS / sizeof(unsigned \
149 long)], &addr);
150                 break;
151         default:
152                 ret = -EINVAL;
153                 break;
154         }
155
156         return(ret);
157 }
158 #endif
159
160 long sys_arch_prctl(int code, unsigned long addr)
161 {
162         return(CHOOSE_MODE_PROC(arch_prctl_tt, arch_prctl_skas, code, addr));
163 }
164
165 long sys_clone(unsigned long clone_flags, unsigned long newsp,
166                void __user *parent_tid, void __user *child_tid)
167 {
168         long ret;
169
170         /* XXX: normal arch do here this pass, and also pass the regs to
171          * do_fork, instead of NULL. Currently the arch-independent code
172          * ignores these values, while the UML code (actually it's
173          * copy_thread) does the right thing. But this should change,
174          probably. */
175         /*if (!newsp)
176                 newsp = UPT_SP(current->thread.regs);*/
177         current->thread.forking = 1;
178         ret = do_fork(clone_flags, newsp, NULL, 0, parent_tid, child_tid);
179         current->thread.forking = 0;
180         return(ret);
181 }
182
183 /*
184  * Overrides for Emacs so that we follow Linus's tabbing style.
185  * Emacs will notice this stuff at the end of the file and automatically
186  * adjust the settings for this buffer only.  This must remain at the end
187  * of the file.
188  * ---------------------------------------------------------------------------
189  * Local variables:
190  * c-file-style: "linux"
191  * End:
192  */