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