]> err.no Git - linux-2.6/blob - arch/um/sys-x86_64/syscalls.c
[netdrvr starfire] Add GPL'd firmware, remove compat code
[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 #include "skas_ptrace.h"
48
49 long sys_modify_ldt_skas(int func, void *ptr, unsigned long bytecount)
50 {
51         struct ptrace_ldt ldt;
52         void *buf;
53         int res, n;
54
55         buf = kmalloc(bytecount, GFP_KERNEL);
56         if(buf == NULL)
57                 return(-ENOMEM);
58
59         res = 0;
60
61         switch(func){
62         case 1:
63         case 0x11:
64                 res = copy_from_user(buf, ptr, bytecount);
65                 break;
66         }
67
68         if(res != 0){
69                 res = -EFAULT;
70                 goto out;
71         }
72
73         ldt = ((struct ptrace_ldt) { .func      = func,
74                                      .ptr       = buf,
75                                      .bytecount = bytecount });
76 #warning Need to look up userspace_pid by cpu
77         res = ptrace(PTRACE_LDT, userspace_pid[0], 0, (unsigned long) &ldt);
78         if(res < 0)
79                 goto out;
80
81         switch(func){
82         case 0:
83         case 2:
84                 n = res;
85                 res = copy_to_user(ptr, buf, n);
86                 if(res != 0)
87                         res = -EFAULT;
88                 else
89                         res = n;
90                 break;
91         }
92
93  out:
94         kfree(buf);
95         return(res);
96 }
97 #endif
98
99 long sys_modify_ldt(int func, void *ptr, unsigned long bytecount)
100 {
101         return(CHOOSE_MODE_PROC(sys_modify_ldt_tt, sys_modify_ldt_skas, func,
102                                 ptr, bytecount));
103 }
104
105 #ifdef CONFIG_MODE_TT
106 extern long arch_prctl(int code, unsigned long addr);
107
108 static long arch_prctl_tt(int code, unsigned long addr)
109 {
110         unsigned long tmp;
111         long ret;
112
113         switch(code){
114         case ARCH_SET_GS:
115         case ARCH_SET_FS:
116                 ret = arch_prctl(code, addr);
117                 break;
118         case ARCH_GET_FS:
119         case ARCH_GET_GS:
120                 ret = arch_prctl(code, (unsigned long) &tmp);
121                 if(!ret)
122                         ret = put_user(tmp, &addr);
123                 break;
124         default:
125                 ret = -EINVAL;
126                 break;
127         }
128
129         return(ret);
130 }
131 #endif
132
133 #ifdef CONFIG_MODE_SKAS
134
135 static long arch_prctl_skas(int code, unsigned long addr)
136 {
137         long ret = 0;
138
139         switch(code){
140         case ARCH_SET_GS:
141                 current->thread.regs.regs.skas.regs[GS_BASE / sizeof(unsigned long)] = addr;
142                 break;
143         case ARCH_SET_FS:
144                 current->thread.regs.regs.skas.regs[FS_BASE / sizeof(unsigned long)] = addr;
145                 break;
146         case ARCH_GET_FS:
147                 ret = put_user(current->thread.regs.regs.skas.regs[GS / sizeof(unsigned long)], &addr);
148                 break;
149         case ARCH_GET_GS:
150                 ret = put_user(current->thread.regs.regs.skas.regs[FS / sizeof(unsigned \
151 long)], &addr);
152                 break;
153         default:
154                 ret = -EINVAL;
155                 break;
156         }
157
158         return(ret);
159 }
160 #endif
161
162 long sys_arch_prctl(int code, unsigned long addr)
163 {
164         return(CHOOSE_MODE_PROC(arch_prctl_tt, arch_prctl_skas, code, addr));
165 }
166
167 long sys_clone(unsigned long clone_flags, unsigned long newsp,
168                void __user *parent_tid, void __user *child_tid)
169 {
170         long ret;
171
172         /* XXX: normal arch do here this pass, and also pass the regs to
173          * do_fork, instead of NULL. Currently the arch-independent code
174          * ignores these values, while the UML code (actually it's
175          * copy_thread) does the right thing. But this should change,
176          probably. */
177         /*if (!newsp)
178                 newsp = UPT_SP(current->thread.regs);*/
179         current->thread.forking = 1;
180         ret = do_fork(clone_flags, newsp, NULL, 0, parent_tid, child_tid);
181         current->thread.forking = 0;
182         return(ret);
183 }
184
185 /*
186  * Overrides for Emacs so that we follow Linus's tabbing style.
187  * Emacs will notice this stuff at the end of the file and automatically
188  * adjust the settings for this buffer only.  This must remain at the end
189  * of the file.
190  * ---------------------------------------------------------------------------
191  * Local variables:
192  * c-file-style: "linux"
193  * End:
194  */