root / linux-user / syscall.c @ ea785922
History | View | Annotate | Download (121.2 kB)
1 | 31e31b8a | bellard | /*
|
---|---|---|---|
2 | 31e31b8a | bellard | * Linux syscalls
|
3 | 31e31b8a | bellard | *
|
4 | 31e31b8a | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | 31e31b8a | bellard | *
|
6 | 31e31b8a | bellard | * This program is free software; you can redistribute it and/or modify
|
7 | 31e31b8a | bellard | * it under the terms of the GNU General Public License as published by
|
8 | 31e31b8a | bellard | * the Free Software Foundation; either version 2 of the License, or
|
9 | 31e31b8a | bellard | * (at your option) any later version.
|
10 | 31e31b8a | bellard | *
|
11 | 31e31b8a | bellard | * This program is distributed in the hope that it will be useful,
|
12 | 31e31b8a | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 31e31b8a | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 31e31b8a | bellard | * GNU General Public License for more details.
|
15 | 31e31b8a | bellard | *
|
16 | 31e31b8a | bellard | * You should have received a copy of the GNU General Public License
|
17 | 31e31b8a | bellard | * along with this program; if not, write to the Free Software
|
18 | 31e31b8a | bellard | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
19 | 31e31b8a | bellard | */
|
20 | 31e31b8a | bellard | #include <stdlib.h> |
21 | 31e31b8a | bellard | #include <stdio.h> |
22 | 31e31b8a | bellard | #include <stdarg.h> |
23 | 04369ff2 | bellard | #include <string.h> |
24 | 31e31b8a | bellard | #include <elf.h> |
25 | 31e31b8a | bellard | #include <endian.h> |
26 | 31e31b8a | bellard | #include <errno.h> |
27 | 31e31b8a | bellard | #include <unistd.h> |
28 | 31e31b8a | bellard | #include <fcntl.h> |
29 | 7854b056 | bellard | #include <time.h> |
30 | 31e31b8a | bellard | #include <sys/types.h> |
31 | 31e31b8a | bellard | #include <sys/wait.h> |
32 | 31e31b8a | bellard | #include <sys/time.h> |
33 | 31e31b8a | bellard | #include <sys/stat.h> |
34 | 31e31b8a | bellard | #include <sys/mount.h> |
35 | 31e31b8a | bellard | #include <sys/resource.h> |
36 | 31e31b8a | bellard | #include <sys/mman.h> |
37 | 31e31b8a | bellard | #include <sys/swap.h> |
38 | 31e31b8a | bellard | #include <signal.h> |
39 | 31e31b8a | bellard | #include <sched.h> |
40 | 31e31b8a | bellard | #include <sys/socket.h> |
41 | 31e31b8a | bellard | #include <sys/uio.h> |
42 | 9de5e440 | bellard | #include <sys/poll.h> |
43 | 32f36bce | bellard | #include <sys/times.h> |
44 | 8853f86e | bellard | #include <sys/shm.h> |
45 | fa294816 | ths | #include <sys/sem.h> |
46 | 56c8f68f | bellard | #include <sys/statfs.h> |
47 | ebc05488 | bellard | #include <utime.h> |
48 | a5448a7d | bellard | #include <sys/sysinfo.h> |
49 | 72f03900 | bellard | //#include <sys/user.h>
|
50 | 8853f86e | bellard | #include <netinet/ip.h> |
51 | 7854b056 | bellard | #include <netinet/tcp.h> |
52 | 31e31b8a | bellard | |
53 | 31e31b8a | bellard | #define termios host_termios
|
54 | 31e31b8a | bellard | #define winsize host_winsize
|
55 | 31e31b8a | bellard | #define termio host_termio
|
56 | 04369ff2 | bellard | #define sgttyb host_sgttyb /* same as target */ |
57 | 04369ff2 | bellard | #define tchars host_tchars /* same as target */ |
58 | 04369ff2 | bellard | #define ltchars host_ltchars /* same as target */ |
59 | 31e31b8a | bellard | |
60 | 31e31b8a | bellard | #include <linux/termios.h> |
61 | 31e31b8a | bellard | #include <linux/unistd.h> |
62 | 31e31b8a | bellard | #include <linux/utsname.h> |
63 | 31e31b8a | bellard | #include <linux/cdrom.h> |
64 | 31e31b8a | bellard | #include <linux/hdreg.h> |
65 | 31e31b8a | bellard | #include <linux/soundcard.h> |
66 | dab2ed99 | bellard | #include <linux/dirent.h> |
67 | 19b84f3c | bellard | #include <linux/kd.h> |
68 | 31e31b8a | bellard | |
69 | 3ef693a0 | bellard | #include "qemu.h" |
70 | 31e31b8a | bellard | |
71 | 72f03900 | bellard | //#define DEBUG
|
72 | 31e31b8a | bellard | |
73 | e6e5906b | pbrook | #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC) \
|
74 | e6e5906b | pbrook | || defined(TARGET_M68K) |
75 | 67867308 | bellard | /* 16 bit uid wrappers emulation */
|
76 | 67867308 | bellard | #define USE_UID16
|
77 | 67867308 | bellard | #endif
|
78 | 67867308 | bellard | |
79 | 1a9353d2 | bellard | //#include <linux/msdos_fs.h>
|
80 | 1a9353d2 | bellard | #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2]) |
81 | 1a9353d2 | bellard | #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2]) |
82 | 1a9353d2 | bellard | |
83 | 70a194b9 | bellard | |
84 | 70a194b9 | bellard | #undef _syscall0
|
85 | 70a194b9 | bellard | #undef _syscall1
|
86 | 70a194b9 | bellard | #undef _syscall2
|
87 | 70a194b9 | bellard | #undef _syscall3
|
88 | 70a194b9 | bellard | #undef _syscall4
|
89 | 70a194b9 | bellard | #undef _syscall5
|
90 | 83fcb515 | bellard | #undef _syscall6
|
91 | 70a194b9 | bellard | |
92 | 83fcb515 | bellard | #define _syscall0(type,name) \
|
93 | 83fcb515 | bellard | type name (void) \
|
94 | 83fcb515 | bellard | { \ |
95 | 83fcb515 | bellard | return syscall(__NR_##name); \ |
96 | 83fcb515 | bellard | } |
97 | 70a194b9 | bellard | |
98 | 83fcb515 | bellard | #define _syscall1(type,name,type1,arg1) \
|
99 | 83fcb515 | bellard | type name (type1 arg1) \ |
100 | 83fcb515 | bellard | { \ |
101 | 83fcb515 | bellard | return syscall(__NR_##name, arg1); \ |
102 | 70a194b9 | bellard | } |
103 | 70a194b9 | bellard | |
104 | 83fcb515 | bellard | #define _syscall2(type,name,type1,arg1,type2,arg2) \
|
105 | 83fcb515 | bellard | type name (type1 arg1,type2 arg2) \ |
106 | 83fcb515 | bellard | { \ |
107 | 83fcb515 | bellard | return syscall(__NR_##name, arg1, arg2); \ |
108 | 70a194b9 | bellard | } |
109 | 70a194b9 | bellard | |
110 | 83fcb515 | bellard | #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
|
111 | 83fcb515 | bellard | type name (type1 arg1,type2 arg2,type3 arg3) \ |
112 | 83fcb515 | bellard | { \ |
113 | 83fcb515 | bellard | return syscall(__NR_##name, arg1, arg2, arg3); \ |
114 | 70a194b9 | bellard | } |
115 | 70a194b9 | bellard | |
116 | 83fcb515 | bellard | #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
|
117 | 83fcb515 | bellard | type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4) \ |
118 | 83fcb515 | bellard | { \ |
119 | 83fcb515 | bellard | return syscall(__NR_##name, arg1, arg2, arg3, arg4); \ |
120 | 70a194b9 | bellard | } |
121 | 70a194b9 | bellard | |
122 | 83fcb515 | bellard | #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
|
123 | 83fcb515 | bellard | type5,arg5) \ |
124 | 83fcb515 | bellard | type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ |
125 | 83fcb515 | bellard | { \ |
126 | 83fcb515 | bellard | return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5); \ |
127 | 70a194b9 | bellard | } |
128 | 70a194b9 | bellard | |
129 | 83fcb515 | bellard | |
130 | 83fcb515 | bellard | #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \
|
131 | 83fcb515 | bellard | type5,arg5,type6,arg6) \ |
132 | 83fcb515 | bellard | type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \ |
133 | 83fcb515 | bellard | { \ |
134 | 83fcb515 | bellard | return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5, arg6); \ |
135 | 70a194b9 | bellard | } |
136 | 83fcb515 | bellard | |
137 | 70a194b9 | bellard | |
138 | 31e31b8a | bellard | #define __NR_sys_uname __NR_uname
|
139 | 72f03900 | bellard | #define __NR_sys_getcwd1 __NR_getcwd
|
140 | 72f03900 | bellard | #define __NR_sys_getdents __NR_getdents
|
141 | dab2ed99 | bellard | #define __NR_sys_getdents64 __NR_getdents64
|
142 | 66fb9763 | bellard | #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
|
143 | 31e31b8a | bellard | |
144 | bc51c5c9 | bellard | #if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__)
|
145 | 9af9eaaa | bellard | #define __NR__llseek __NR_lseek
|
146 | 9af9eaaa | bellard | #endif
|
147 | 9af9eaaa | bellard | |
148 | 72f03900 | bellard | #ifdef __NR_gettid
|
149 | 31e31b8a | bellard | _syscall0(int, gettid)
|
150 | 72f03900 | bellard | #else
|
151 | 72f03900 | bellard | static int gettid(void) { |
152 | 72f03900 | bellard | return -ENOSYS;
|
153 | 72f03900 | bellard | } |
154 | 72f03900 | bellard | #endif
|
155 | 31e31b8a | bellard | _syscall1(int,sys_uname,struct new_utsname *,buf) |
156 | 72f03900 | bellard | _syscall2(int,sys_getcwd1,char *,buf,size_t,size) |
157 | 72f03900 | bellard | _syscall3(int, sys_getdents, uint, fd, struct dirent *, dirp, uint, count); |
158 | dab2ed99 | bellard | _syscall3(int, sys_getdents64, uint, fd, struct dirent64 *, dirp, uint, count); |
159 | 31e31b8a | bellard | _syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo,
|
160 | 31e31b8a | bellard | loff_t *, res, uint, wh); |
161 | 66fb9763 | bellard | _syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo) |
162 | ec86b0fb | bellard | #ifdef __NR_exit_group
|
163 | ec86b0fb | bellard | _syscall1(int,exit_group,int,error_code) |
164 | ec86b0fb | bellard | #endif
|
165 | 66fb9763 | bellard | |
166 | 66fb9763 | bellard | extern int personality(int); |
167 | 9de5e440 | bellard | extern int flock(int, int); |
168 | 9de5e440 | bellard | extern int setfsuid(int); |
169 | 9de5e440 | bellard | extern int setfsgid(int); |
170 | 5cd4393b | bellard | extern int setresuid(uid_t, uid_t, uid_t); |
171 | 5cd4393b | bellard | extern int getresuid(uid_t *, uid_t *, uid_t *); |
172 | 5cd4393b | bellard | extern int setresgid(gid_t, gid_t, gid_t); |
173 | 5cd4393b | bellard | extern int getresgid(gid_t *, gid_t *, gid_t *); |
174 | 19b84f3c | bellard | extern int setgroups(int, gid_t *); |
175 | 31e31b8a | bellard | |
176 | 31e31b8a | bellard | static inline long get_errno(long ret) |
177 | 31e31b8a | bellard | { |
178 | 31e31b8a | bellard | if (ret == -1) |
179 | 31e31b8a | bellard | return -errno;
|
180 | 31e31b8a | bellard | else
|
181 | 31e31b8a | bellard | return ret;
|
182 | 31e31b8a | bellard | } |
183 | 31e31b8a | bellard | |
184 | 31e31b8a | bellard | static inline int is_error(long ret) |
185 | 31e31b8a | bellard | { |
186 | 31e31b8a | bellard | return (unsigned long)ret >= (unsigned long)(-4096); |
187 | 31e31b8a | bellard | } |
188 | 31e31b8a | bellard | |
189 | 53a5960a | pbrook | static target_ulong target_brk;
|
190 | 53a5960a | pbrook | static target_ulong target_original_brk;
|
191 | 31e31b8a | bellard | |
192 | 53a5960a | pbrook | void target_set_brk(target_ulong new_brk)
|
193 | 31e31b8a | bellard | { |
194 | 53a5960a | pbrook | target_original_brk = target_brk = new_brk; |
195 | 31e31b8a | bellard | } |
196 | 31e31b8a | bellard | |
197 | 53a5960a | pbrook | long do_brk(target_ulong new_brk)
|
198 | 31e31b8a | bellard | { |
199 | 53a5960a | pbrook | target_ulong brk_page; |
200 | 31e31b8a | bellard | long mapped_addr;
|
201 | 31e31b8a | bellard | int new_alloc_size;
|
202 | 31e31b8a | bellard | |
203 | 31e31b8a | bellard | if (!new_brk)
|
204 | 53a5960a | pbrook | return target_brk;
|
205 | 31e31b8a | bellard | if (new_brk < target_original_brk)
|
206 | 31e31b8a | bellard | return -ENOMEM;
|
207 | 31e31b8a | bellard | |
208 | 53a5960a | pbrook | brk_page = HOST_PAGE_ALIGN(target_brk); |
209 | 31e31b8a | bellard | |
210 | 31e31b8a | bellard | /* If the new brk is less than this, set it and we're done... */
|
211 | 31e31b8a | bellard | if (new_brk < brk_page) {
|
212 | 31e31b8a | bellard | target_brk = new_brk; |
213 | 53a5960a | pbrook | return target_brk;
|
214 | 31e31b8a | bellard | } |
215 | 31e31b8a | bellard | |
216 | 31e31b8a | bellard | /* We need to allocate more memory after the brk... */
|
217 | 54936004 | bellard | new_alloc_size = HOST_PAGE_ALIGN(new_brk - brk_page + 1);
|
218 | 53a5960a | pbrook | mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size, |
219 | 54936004 | bellard | PROT_READ|PROT_WRITE, |
220 | 54936004 | bellard | MAP_ANON|MAP_FIXED|MAP_PRIVATE, 0, 0)); |
221 | 31e31b8a | bellard | if (is_error(mapped_addr)) {
|
222 | 31e31b8a | bellard | return mapped_addr;
|
223 | 31e31b8a | bellard | } else {
|
224 | 31e31b8a | bellard | target_brk = new_brk; |
225 | 53a5960a | pbrook | return target_brk;
|
226 | 31e31b8a | bellard | } |
227 | 31e31b8a | bellard | } |
228 | 31e31b8a | bellard | |
229 | 31e31b8a | bellard | static inline fd_set *target_to_host_fds(fd_set *fds, |
230 | 31e31b8a | bellard | target_long *target_fds, int n)
|
231 | 31e31b8a | bellard | { |
232 | 7854b056 | bellard | #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
|
233 | 31e31b8a | bellard | return (fd_set *)target_fds;
|
234 | 31e31b8a | bellard | #else
|
235 | 31e31b8a | bellard | int i, b;
|
236 | 31e31b8a | bellard | if (target_fds) {
|
237 | 31e31b8a | bellard | FD_ZERO(fds); |
238 | 31e31b8a | bellard | for(i = 0;i < n; i++) { |
239 | 31e31b8a | bellard | b = (tswapl(target_fds[i / TARGET_LONG_BITS]) >> |
240 | 31e31b8a | bellard | (i & (TARGET_LONG_BITS - 1))) & 1; |
241 | 31e31b8a | bellard | if (b)
|
242 | 31e31b8a | bellard | FD_SET(i, fds); |
243 | 31e31b8a | bellard | } |
244 | 31e31b8a | bellard | return fds;
|
245 | 31e31b8a | bellard | } else {
|
246 | 31e31b8a | bellard | return NULL; |
247 | 31e31b8a | bellard | } |
248 | 31e31b8a | bellard | #endif
|
249 | 31e31b8a | bellard | } |
250 | 31e31b8a | bellard | |
251 | 31e31b8a | bellard | static inline void host_to_target_fds(target_long *target_fds, |
252 | 31e31b8a | bellard | fd_set *fds, int n)
|
253 | 31e31b8a | bellard | { |
254 | 7854b056 | bellard | #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
|
255 | 31e31b8a | bellard | /* nothing to do */
|
256 | 31e31b8a | bellard | #else
|
257 | 31e31b8a | bellard | int i, nw, j, k;
|
258 | 31e31b8a | bellard | target_long v; |
259 | 31e31b8a | bellard | |
260 | 31e31b8a | bellard | if (target_fds) {
|
261 | 8853f86e | bellard | nw = (n + TARGET_LONG_BITS - 1) / TARGET_LONG_BITS;
|
262 | 31e31b8a | bellard | k = 0;
|
263 | 31e31b8a | bellard | for(i = 0;i < nw; i++) { |
264 | 31e31b8a | bellard | v = 0;
|
265 | 31e31b8a | bellard | for(j = 0; j < TARGET_LONG_BITS; j++) { |
266 | 31e31b8a | bellard | v |= ((FD_ISSET(k, fds) != 0) << j);
|
267 | 31e31b8a | bellard | k++; |
268 | 31e31b8a | bellard | } |
269 | 31e31b8a | bellard | target_fds[i] = tswapl(v); |
270 | 31e31b8a | bellard | } |
271 | 31e31b8a | bellard | } |
272 | 31e31b8a | bellard | #endif
|
273 | 31e31b8a | bellard | } |
274 | 31e31b8a | bellard | |
275 | c596ed17 | bellard | #if defined(__alpha__)
|
276 | c596ed17 | bellard | #define HOST_HZ 1024 |
277 | c596ed17 | bellard | #else
|
278 | c596ed17 | bellard | #define HOST_HZ 100 |
279 | c596ed17 | bellard | #endif
|
280 | c596ed17 | bellard | |
281 | c596ed17 | bellard | static inline long host_to_target_clock_t(long ticks) |
282 | c596ed17 | bellard | { |
283 | c596ed17 | bellard | #if HOST_HZ == TARGET_HZ
|
284 | c596ed17 | bellard | return ticks;
|
285 | c596ed17 | bellard | #else
|
286 | c596ed17 | bellard | return ((int64_t)ticks * TARGET_HZ) / HOST_HZ;
|
287 | c596ed17 | bellard | #endif
|
288 | c596ed17 | bellard | } |
289 | c596ed17 | bellard | |
290 | 53a5960a | pbrook | static inline void host_to_target_rusage(target_ulong target_addr, |
291 | b409186b | bellard | const struct rusage *rusage) |
292 | b409186b | bellard | { |
293 | 53a5960a | pbrook | struct target_rusage *target_rusage;
|
294 | 53a5960a | pbrook | |
295 | 53a5960a | pbrook | lock_user_struct(target_rusage, target_addr, 0);
|
296 | b409186b | bellard | target_rusage->ru_utime.tv_sec = tswapl(rusage->ru_utime.tv_sec); |
297 | b409186b | bellard | target_rusage->ru_utime.tv_usec = tswapl(rusage->ru_utime.tv_usec); |
298 | b409186b | bellard | target_rusage->ru_stime.tv_sec = tswapl(rusage->ru_stime.tv_sec); |
299 | b409186b | bellard | target_rusage->ru_stime.tv_usec = tswapl(rusage->ru_stime.tv_usec); |
300 | b409186b | bellard | target_rusage->ru_maxrss = tswapl(rusage->ru_maxrss); |
301 | b409186b | bellard | target_rusage->ru_ixrss = tswapl(rusage->ru_ixrss); |
302 | b409186b | bellard | target_rusage->ru_idrss = tswapl(rusage->ru_idrss); |
303 | b409186b | bellard | target_rusage->ru_isrss = tswapl(rusage->ru_isrss); |
304 | b409186b | bellard | target_rusage->ru_minflt = tswapl(rusage->ru_minflt); |
305 | b409186b | bellard | target_rusage->ru_majflt = tswapl(rusage->ru_majflt); |
306 | b409186b | bellard | target_rusage->ru_nswap = tswapl(rusage->ru_nswap); |
307 | b409186b | bellard | target_rusage->ru_inblock = tswapl(rusage->ru_inblock); |
308 | b409186b | bellard | target_rusage->ru_oublock = tswapl(rusage->ru_oublock); |
309 | b409186b | bellard | target_rusage->ru_msgsnd = tswapl(rusage->ru_msgsnd); |
310 | b409186b | bellard | target_rusage->ru_msgrcv = tswapl(rusage->ru_msgrcv); |
311 | b409186b | bellard | target_rusage->ru_nsignals = tswapl(rusage->ru_nsignals); |
312 | b409186b | bellard | target_rusage->ru_nvcsw = tswapl(rusage->ru_nvcsw); |
313 | b409186b | bellard | target_rusage->ru_nivcsw = tswapl(rusage->ru_nivcsw); |
314 | 53a5960a | pbrook | unlock_user_struct(target_rusage, target_addr, 1);
|
315 | b409186b | bellard | } |
316 | b409186b | bellard | |
317 | 53a5960a | pbrook | static inline void target_to_host_timeval(struct timeval *tv, |
318 | 53a5960a | pbrook | target_ulong target_addr) |
319 | 31e31b8a | bellard | { |
320 | 53a5960a | pbrook | struct target_timeval *target_tv;
|
321 | 53a5960a | pbrook | |
322 | 53a5960a | pbrook | lock_user_struct(target_tv, target_addr, 1);
|
323 | 66fb9763 | bellard | tv->tv_sec = tswapl(target_tv->tv_sec); |
324 | 66fb9763 | bellard | tv->tv_usec = tswapl(target_tv->tv_usec); |
325 | 53a5960a | pbrook | unlock_user_struct(target_tv, target_addr, 0);
|
326 | 31e31b8a | bellard | } |
327 | 31e31b8a | bellard | |
328 | 53a5960a | pbrook | static inline void host_to_target_timeval(target_ulong target_addr, |
329 | 5cd4393b | bellard | const struct timeval *tv) |
330 | 31e31b8a | bellard | { |
331 | 53a5960a | pbrook | struct target_timeval *target_tv;
|
332 | 53a5960a | pbrook | |
333 | 53a5960a | pbrook | lock_user_struct(target_tv, target_addr, 0);
|
334 | 66fb9763 | bellard | target_tv->tv_sec = tswapl(tv->tv_sec); |
335 | 66fb9763 | bellard | target_tv->tv_usec = tswapl(tv->tv_usec); |
336 | 53a5960a | pbrook | unlock_user_struct(target_tv, target_addr, 1);
|
337 | 31e31b8a | bellard | } |
338 | 31e31b8a | bellard | |
339 | 31e31b8a | bellard | |
340 | 31e31b8a | bellard | static long do_select(long n, |
341 | 53a5960a | pbrook | target_ulong rfd_p, target_ulong wfd_p, |
342 | 53a5960a | pbrook | target_ulong efd_p, target_ulong target_tv) |
343 | 31e31b8a | bellard | { |
344 | 31e31b8a | bellard | fd_set rfds, wfds, efds; |
345 | 31e31b8a | bellard | fd_set *rfds_ptr, *wfds_ptr, *efds_ptr; |
346 | 53a5960a | pbrook | target_long *target_rfds, *target_wfds, *target_efds; |
347 | 31e31b8a | bellard | struct timeval tv, *tv_ptr;
|
348 | 31e31b8a | bellard | long ret;
|
349 | 53a5960a | pbrook | int ok;
|
350 | 31e31b8a | bellard | |
351 | 53a5960a | pbrook | if (rfd_p) {
|
352 | 53a5960a | pbrook | target_rfds = lock_user(rfd_p, sizeof(target_long) * n, 1); |
353 | 53a5960a | pbrook | rfds_ptr = target_to_host_fds(&rfds, target_rfds, n); |
354 | 53a5960a | pbrook | } else {
|
355 | 53a5960a | pbrook | target_rfds = NULL;
|
356 | 53a5960a | pbrook | rfds_ptr = NULL;
|
357 | 53a5960a | pbrook | } |
358 | 53a5960a | pbrook | if (wfd_p) {
|
359 | 53a5960a | pbrook | target_wfds = lock_user(wfd_p, sizeof(target_long) * n, 1); |
360 | 53a5960a | pbrook | wfds_ptr = target_to_host_fds(&wfds, target_wfds, n); |
361 | 53a5960a | pbrook | } else {
|
362 | 53a5960a | pbrook | target_wfds = NULL;
|
363 | 53a5960a | pbrook | wfds_ptr = NULL;
|
364 | 53a5960a | pbrook | } |
365 | 53a5960a | pbrook | if (efd_p) {
|
366 | 53a5960a | pbrook | target_efds = lock_user(efd_p, sizeof(target_long) * n, 1); |
367 | 53a5960a | pbrook | efds_ptr = target_to_host_fds(&efds, target_efds, n); |
368 | 53a5960a | pbrook | } else {
|
369 | 53a5960a | pbrook | target_efds = NULL;
|
370 | 53a5960a | pbrook | efds_ptr = NULL;
|
371 | 53a5960a | pbrook | } |
372 | 31e31b8a | bellard | |
373 | 31e31b8a | bellard | if (target_tv) {
|
374 | 5cd4393b | bellard | target_to_host_timeval(&tv, target_tv); |
375 | 31e31b8a | bellard | tv_ptr = &tv; |
376 | 31e31b8a | bellard | } else {
|
377 | 31e31b8a | bellard | tv_ptr = NULL;
|
378 | 31e31b8a | bellard | } |
379 | 31e31b8a | bellard | ret = get_errno(select(n, rfds_ptr, wfds_ptr, efds_ptr, tv_ptr)); |
380 | 53a5960a | pbrook | ok = !is_error(ret); |
381 | 53a5960a | pbrook | |
382 | 53a5960a | pbrook | if (ok) {
|
383 | 31e31b8a | bellard | host_to_target_fds(target_rfds, rfds_ptr, n); |
384 | 31e31b8a | bellard | host_to_target_fds(target_wfds, wfds_ptr, n); |
385 | 31e31b8a | bellard | host_to_target_fds(target_efds, efds_ptr, n); |
386 | 31e31b8a | bellard | |
387 | 31e31b8a | bellard | if (target_tv) {
|
388 | 5cd4393b | bellard | host_to_target_timeval(target_tv, &tv); |
389 | 31e31b8a | bellard | } |
390 | 31e31b8a | bellard | } |
391 | 53a5960a | pbrook | if (target_rfds)
|
392 | 53a5960a | pbrook | unlock_user(target_rfds, rfd_p, ok ? sizeof(target_long) * n : 0); |
393 | 53a5960a | pbrook | if (target_wfds)
|
394 | 53a5960a | pbrook | unlock_user(target_wfds, wfd_p, ok ? sizeof(target_long) * n : 0); |
395 | 53a5960a | pbrook | if (target_efds)
|
396 | 53a5960a | pbrook | unlock_user(target_efds, efd_p, ok ? sizeof(target_long) * n : 0); |
397 | 53a5960a | pbrook | |
398 | 31e31b8a | bellard | return ret;
|
399 | 31e31b8a | bellard | } |
400 | 31e31b8a | bellard | |
401 | 7854b056 | bellard | static inline void target_to_host_sockaddr(struct sockaddr *addr, |
402 | 53a5960a | pbrook | target_ulong target_addr, |
403 | 7854b056 | bellard | socklen_t len) |
404 | 7854b056 | bellard | { |
405 | 53a5960a | pbrook | struct target_sockaddr *target_saddr;
|
406 | 53a5960a | pbrook | |
407 | 53a5960a | pbrook | target_saddr = lock_user(target_addr, len, 1);
|
408 | 53a5960a | pbrook | memcpy(addr, target_saddr, len); |
409 | 53a5960a | pbrook | addr->sa_family = tswap16(target_saddr->sa_family); |
410 | 53a5960a | pbrook | unlock_user(target_saddr, target_addr, 0);
|
411 | 7854b056 | bellard | } |
412 | 7854b056 | bellard | |
413 | 53a5960a | pbrook | static inline void host_to_target_sockaddr(target_ulong target_addr, |
414 | 7854b056 | bellard | struct sockaddr *addr,
|
415 | 7854b056 | bellard | socklen_t len) |
416 | 7854b056 | bellard | { |
417 | 53a5960a | pbrook | struct target_sockaddr *target_saddr;
|
418 | 53a5960a | pbrook | |
419 | 53a5960a | pbrook | target_saddr = lock_user(target_addr, len, 0);
|
420 | 53a5960a | pbrook | memcpy(target_saddr, addr, len); |
421 | 53a5960a | pbrook | target_saddr->sa_family = tswap16(addr->sa_family); |
422 | 53a5960a | pbrook | unlock_user(target_saddr, target_addr, len); |
423 | 7854b056 | bellard | } |
424 | 7854b056 | bellard | |
425 | 53a5960a | pbrook | /* ??? Should this also swap msgh->name? */
|
426 | 7854b056 | bellard | static inline void target_to_host_cmsg(struct msghdr *msgh, |
427 | 7854b056 | bellard | struct target_msghdr *target_msgh)
|
428 | 7854b056 | bellard | { |
429 | 7854b056 | bellard | struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh);
|
430 | 7854b056 | bellard | struct target_cmsghdr *target_cmsg = TARGET_CMSG_FIRSTHDR(target_msgh);
|
431 | 7854b056 | bellard | socklen_t space = 0;
|
432 | 7854b056 | bellard | |
433 | 7854b056 | bellard | while (cmsg && target_cmsg) {
|
434 | 7854b056 | bellard | void *data = CMSG_DATA(cmsg);
|
435 | 7854b056 | bellard | void *target_data = TARGET_CMSG_DATA(target_cmsg);
|
436 | 7854b056 | bellard | |
437 | 7854b056 | bellard | int len = tswapl(target_cmsg->cmsg_len)
|
438 | 7854b056 | bellard | - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr)); |
439 | 7854b056 | bellard | |
440 | 7854b056 | bellard | space += CMSG_SPACE(len); |
441 | 7854b056 | bellard | if (space > msgh->msg_controllen) {
|
442 | 7854b056 | bellard | space -= CMSG_SPACE(len); |
443 | 31febb71 | bellard | gemu_log("Host cmsg overflow\n");
|
444 | 7854b056 | bellard | break;
|
445 | 7854b056 | bellard | } |
446 | 7854b056 | bellard | |
447 | 7854b056 | bellard | cmsg->cmsg_level = tswap32(target_cmsg->cmsg_level); |
448 | 7854b056 | bellard | cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type); |
449 | 7854b056 | bellard | cmsg->cmsg_len = CMSG_LEN(len); |
450 | 7854b056 | bellard | |
451 | 3532fa74 | bellard | if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
|
452 | 7854b056 | bellard | gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
|
453 | 7854b056 | bellard | memcpy(data, target_data, len); |
454 | 7854b056 | bellard | } else {
|
455 | 7854b056 | bellard | int *fd = (int *)data; |
456 | 7854b056 | bellard | int *target_fd = (int *)target_data; |
457 | 7854b056 | bellard | int i, numfds = len / sizeof(int); |
458 | 7854b056 | bellard | |
459 | 7854b056 | bellard | for (i = 0; i < numfds; i++) |
460 | 7854b056 | bellard | fd[i] = tswap32(target_fd[i]); |
461 | 7854b056 | bellard | } |
462 | 7854b056 | bellard | |
463 | 7854b056 | bellard | cmsg = CMSG_NXTHDR(msgh, cmsg); |
464 | 7854b056 | bellard | target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg); |
465 | 7854b056 | bellard | } |
466 | 7854b056 | bellard | |
467 | 7854b056 | bellard | msgh->msg_controllen = space; |
468 | 7854b056 | bellard | } |
469 | 7854b056 | bellard | |
470 | 53a5960a | pbrook | /* ??? Should this also swap msgh->name? */
|
471 | 7854b056 | bellard | static inline void host_to_target_cmsg(struct target_msghdr *target_msgh, |
472 | 7854b056 | bellard | struct msghdr *msgh)
|
473 | 7854b056 | bellard | { |
474 | 7854b056 | bellard | struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh);
|
475 | 7854b056 | bellard | struct target_cmsghdr *target_cmsg = TARGET_CMSG_FIRSTHDR(target_msgh);
|
476 | 7854b056 | bellard | socklen_t space = 0;
|
477 | 7854b056 | bellard | |
478 | 7854b056 | bellard | while (cmsg && target_cmsg) {
|
479 | 7854b056 | bellard | void *data = CMSG_DATA(cmsg);
|
480 | 7854b056 | bellard | void *target_data = TARGET_CMSG_DATA(target_cmsg);
|
481 | 7854b056 | bellard | |
482 | 7854b056 | bellard | int len = cmsg->cmsg_len - CMSG_ALIGN(sizeof (struct cmsghdr)); |
483 | 7854b056 | bellard | |
484 | 7854b056 | bellard | space += TARGET_CMSG_SPACE(len); |
485 | 7854b056 | bellard | if (space > tswapl(target_msgh->msg_controllen)) {
|
486 | 7854b056 | bellard | space -= TARGET_CMSG_SPACE(len); |
487 | 31febb71 | bellard | gemu_log("Target cmsg overflow\n");
|
488 | 7854b056 | bellard | break;
|
489 | 7854b056 | bellard | } |
490 | 7854b056 | bellard | |
491 | 7854b056 | bellard | target_cmsg->cmsg_level = tswap32(cmsg->cmsg_level); |
492 | 7854b056 | bellard | target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type); |
493 | 7854b056 | bellard | target_cmsg->cmsg_len = tswapl(TARGET_CMSG_LEN(len)); |
494 | 7854b056 | bellard | |
495 | 3532fa74 | bellard | if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
|
496 | 7854b056 | bellard | gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
|
497 | 7854b056 | bellard | memcpy(target_data, data, len); |
498 | 7854b056 | bellard | } else {
|
499 | 7854b056 | bellard | int *fd = (int *)data; |
500 | 7854b056 | bellard | int *target_fd = (int *)target_data; |
501 | 7854b056 | bellard | int i, numfds = len / sizeof(int); |
502 | 7854b056 | bellard | |
503 | 7854b056 | bellard | for (i = 0; i < numfds; i++) |
504 | 7854b056 | bellard | target_fd[i] = tswap32(fd[i]); |
505 | 7854b056 | bellard | } |
506 | 7854b056 | bellard | |
507 | 7854b056 | bellard | cmsg = CMSG_NXTHDR(msgh, cmsg); |
508 | 7854b056 | bellard | target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg); |
509 | 7854b056 | bellard | } |
510 | 7854b056 | bellard | |
511 | 7854b056 | bellard | msgh->msg_controllen = tswapl(space); |
512 | 7854b056 | bellard | } |
513 | 7854b056 | bellard | |
514 | 7854b056 | bellard | static long do_setsockopt(int sockfd, int level, int optname, |
515 | 53a5960a | pbrook | target_ulong optval, socklen_t optlen) |
516 | 7854b056 | bellard | { |
517 | 8853f86e | bellard | int val, ret;
|
518 | 8853f86e | bellard | |
519 | 8853f86e | bellard | switch(level) {
|
520 | 8853f86e | bellard | case SOL_TCP:
|
521 | 7854b056 | bellard | /* TCP options all take an 'int' value. */
|
522 | 7854b056 | bellard | if (optlen < sizeof(uint32_t)) |
523 | 7854b056 | bellard | return -EINVAL;
|
524 | 8853f86e | bellard | |
525 | 53a5960a | pbrook | val = tget32(optval); |
526 | 8853f86e | bellard | ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
|
527 | 8853f86e | bellard | break;
|
528 | 8853f86e | bellard | case SOL_IP:
|
529 | 8853f86e | bellard | switch(optname) {
|
530 | 2efbe911 | bellard | case IP_TOS:
|
531 | 2efbe911 | bellard | case IP_TTL:
|
532 | 8853f86e | bellard | case IP_HDRINCL:
|
533 | 2efbe911 | bellard | case IP_ROUTER_ALERT:
|
534 | 2efbe911 | bellard | case IP_RECVOPTS:
|
535 | 2efbe911 | bellard | case IP_RETOPTS:
|
536 | 2efbe911 | bellard | case IP_PKTINFO:
|
537 | 2efbe911 | bellard | case IP_MTU_DISCOVER:
|
538 | 2efbe911 | bellard | case IP_RECVERR:
|
539 | 2efbe911 | bellard | case IP_RECVTOS:
|
540 | 2efbe911 | bellard | #ifdef IP_FREEBIND
|
541 | 2efbe911 | bellard | case IP_FREEBIND:
|
542 | 2efbe911 | bellard | #endif
|
543 | 2efbe911 | bellard | case IP_MULTICAST_TTL:
|
544 | 2efbe911 | bellard | case IP_MULTICAST_LOOP:
|
545 | 8853f86e | bellard | val = 0;
|
546 | 8853f86e | bellard | if (optlen >= sizeof(uint32_t)) { |
547 | 53a5960a | pbrook | val = tget32(optval); |
548 | 8853f86e | bellard | } else if (optlen >= 1) { |
549 | 53a5960a | pbrook | val = tget8(optval); |
550 | 8853f86e | bellard | } |
551 | 8853f86e | bellard | ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
|
552 | 8853f86e | bellard | break;
|
553 | 8853f86e | bellard | default:
|
554 | 8853f86e | bellard | goto unimplemented;
|
555 | 8853f86e | bellard | } |
556 | 8853f86e | bellard | break;
|
557 | 3532fa74 | bellard | case TARGET_SOL_SOCKET:
|
558 | 8853f86e | bellard | switch (optname) {
|
559 | 8853f86e | bellard | /* Options with 'int' argument. */
|
560 | 3532fa74 | bellard | case TARGET_SO_DEBUG:
|
561 | 3532fa74 | bellard | optname = SO_DEBUG; |
562 | 3532fa74 | bellard | break;
|
563 | 3532fa74 | bellard | case TARGET_SO_REUSEADDR:
|
564 | 3532fa74 | bellard | optname = SO_REUSEADDR; |
565 | 3532fa74 | bellard | break;
|
566 | 3532fa74 | bellard | case TARGET_SO_TYPE:
|
567 | 3532fa74 | bellard | optname = SO_TYPE; |
568 | 3532fa74 | bellard | break;
|
569 | 3532fa74 | bellard | case TARGET_SO_ERROR:
|
570 | 3532fa74 | bellard | optname = SO_ERROR; |
571 | 3532fa74 | bellard | break;
|
572 | 3532fa74 | bellard | case TARGET_SO_DONTROUTE:
|
573 | 3532fa74 | bellard | optname = SO_DONTROUTE; |
574 | 3532fa74 | bellard | break;
|
575 | 3532fa74 | bellard | case TARGET_SO_BROADCAST:
|
576 | 3532fa74 | bellard | optname = SO_BROADCAST; |
577 | 3532fa74 | bellard | break;
|
578 | 3532fa74 | bellard | case TARGET_SO_SNDBUF:
|
579 | 3532fa74 | bellard | optname = SO_SNDBUF; |
580 | 3532fa74 | bellard | break;
|
581 | 3532fa74 | bellard | case TARGET_SO_RCVBUF:
|
582 | 3532fa74 | bellard | optname = SO_RCVBUF; |
583 | 3532fa74 | bellard | break;
|
584 | 3532fa74 | bellard | case TARGET_SO_KEEPALIVE:
|
585 | 3532fa74 | bellard | optname = SO_KEEPALIVE; |
586 | 3532fa74 | bellard | break;
|
587 | 3532fa74 | bellard | case TARGET_SO_OOBINLINE:
|
588 | 3532fa74 | bellard | optname = SO_OOBINLINE; |
589 | 3532fa74 | bellard | break;
|
590 | 3532fa74 | bellard | case TARGET_SO_NO_CHECK:
|
591 | 3532fa74 | bellard | optname = SO_NO_CHECK; |
592 | 3532fa74 | bellard | break;
|
593 | 3532fa74 | bellard | case TARGET_SO_PRIORITY:
|
594 | 3532fa74 | bellard | optname = SO_PRIORITY; |
595 | 3532fa74 | bellard | break;
|
596 | 5e83e8e3 | bellard | #ifdef SO_BSDCOMPAT
|
597 | 3532fa74 | bellard | case TARGET_SO_BSDCOMPAT:
|
598 | 3532fa74 | bellard | optname = SO_BSDCOMPAT; |
599 | 3532fa74 | bellard | break;
|
600 | 5e83e8e3 | bellard | #endif
|
601 | 3532fa74 | bellard | case TARGET_SO_PASSCRED:
|
602 | 3532fa74 | bellard | optname = SO_PASSCRED; |
603 | 3532fa74 | bellard | break;
|
604 | 3532fa74 | bellard | case TARGET_SO_TIMESTAMP:
|
605 | 3532fa74 | bellard | optname = SO_TIMESTAMP; |
606 | 3532fa74 | bellard | break;
|
607 | 3532fa74 | bellard | case TARGET_SO_RCVLOWAT:
|
608 | 3532fa74 | bellard | optname = SO_RCVLOWAT; |
609 | 3532fa74 | bellard | break;
|
610 | 3532fa74 | bellard | case TARGET_SO_RCVTIMEO:
|
611 | 3532fa74 | bellard | optname = SO_RCVTIMEO; |
612 | 3532fa74 | bellard | break;
|
613 | 3532fa74 | bellard | case TARGET_SO_SNDTIMEO:
|
614 | 3532fa74 | bellard | optname = SO_SNDTIMEO; |
615 | 3532fa74 | bellard | break;
|
616 | 8853f86e | bellard | break;
|
617 | 8853f86e | bellard | default:
|
618 | 8853f86e | bellard | goto unimplemented;
|
619 | 8853f86e | bellard | } |
620 | 3532fa74 | bellard | if (optlen < sizeof(uint32_t)) |
621 | 3532fa74 | bellard | return -EINVAL;
|
622 | 3532fa74 | bellard | |
623 | 3532fa74 | bellard | val = tget32(optval); |
624 | 3532fa74 | bellard | ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname, &val, sizeof(val)));
|
625 | 8853f86e | bellard | break;
|
626 | 7854b056 | bellard | default:
|
627 | 8853f86e | bellard | unimplemented:
|
628 | 8853f86e | bellard | gemu_log("Unsupported setsockopt level=%d optname=%d \n", level, optname);
|
629 | 8853f86e | bellard | ret = -ENOSYS; |
630 | 7854b056 | bellard | } |
631 | 8853f86e | bellard | return ret;
|
632 | 7854b056 | bellard | } |
633 | 7854b056 | bellard | |
634 | 7854b056 | bellard | static long do_getsockopt(int sockfd, int level, int optname, |
635 | 53a5960a | pbrook | target_ulong optval, target_ulong optlen) |
636 | 7854b056 | bellard | { |
637 | 8853f86e | bellard | int len, lv, val, ret;
|
638 | 8853f86e | bellard | |
639 | 8853f86e | bellard | switch(level) {
|
640 | 3532fa74 | bellard | case TARGET_SOL_SOCKET:
|
641 | 3532fa74 | bellard | level = SOL_SOCKET; |
642 | 8853f86e | bellard | switch (optname) {
|
643 | 3532fa74 | bellard | case TARGET_SO_LINGER:
|
644 | 3532fa74 | bellard | case TARGET_SO_RCVTIMEO:
|
645 | 3532fa74 | bellard | case TARGET_SO_SNDTIMEO:
|
646 | 3532fa74 | bellard | case TARGET_SO_PEERCRED:
|
647 | 3532fa74 | bellard | case TARGET_SO_PEERNAME:
|
648 | 8853f86e | bellard | /* These don't just return a single integer */
|
649 | 8853f86e | bellard | goto unimplemented;
|
650 | 8853f86e | bellard | default:
|
651 | 2efbe911 | bellard | goto int_case;
|
652 | 2efbe911 | bellard | } |
653 | 2efbe911 | bellard | break;
|
654 | 2efbe911 | bellard | case SOL_TCP:
|
655 | 2efbe911 | bellard | /* TCP options all take an 'int' value. */
|
656 | 2efbe911 | bellard | int_case:
|
657 | 53a5960a | pbrook | len = tget32(optlen); |
658 | 2efbe911 | bellard | if (len < 0) |
659 | 2efbe911 | bellard | return -EINVAL;
|
660 | 2efbe911 | bellard | lv = sizeof(int); |
661 | 2efbe911 | bellard | ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv)); |
662 | 2efbe911 | bellard | if (ret < 0) |
663 | 2efbe911 | bellard | return ret;
|
664 | 2efbe911 | bellard | val = tswap32(val); |
665 | 2efbe911 | bellard | if (len > lv)
|
666 | 2efbe911 | bellard | len = lv; |
667 | 53a5960a | pbrook | if (len == 4) |
668 | 53a5960a | pbrook | tput32(optval, val); |
669 | 53a5960a | pbrook | else
|
670 | 53a5960a | pbrook | tput8(optval, val); |
671 | 53a5960a | pbrook | tput32(optlen, len); |
672 | 2efbe911 | bellard | break;
|
673 | 2efbe911 | bellard | case SOL_IP:
|
674 | 2efbe911 | bellard | switch(optname) {
|
675 | 2efbe911 | bellard | case IP_TOS:
|
676 | 2efbe911 | bellard | case IP_TTL:
|
677 | 2efbe911 | bellard | case IP_HDRINCL:
|
678 | 2efbe911 | bellard | case IP_ROUTER_ALERT:
|
679 | 2efbe911 | bellard | case IP_RECVOPTS:
|
680 | 2efbe911 | bellard | case IP_RETOPTS:
|
681 | 2efbe911 | bellard | case IP_PKTINFO:
|
682 | 2efbe911 | bellard | case IP_MTU_DISCOVER:
|
683 | 2efbe911 | bellard | case IP_RECVERR:
|
684 | 2efbe911 | bellard | case IP_RECVTOS:
|
685 | 2efbe911 | bellard | #ifdef IP_FREEBIND
|
686 | 2efbe911 | bellard | case IP_FREEBIND:
|
687 | 2efbe911 | bellard | #endif
|
688 | 2efbe911 | bellard | case IP_MULTICAST_TTL:
|
689 | 2efbe911 | bellard | case IP_MULTICAST_LOOP:
|
690 | 53a5960a | pbrook | len = tget32(optlen); |
691 | 8853f86e | bellard | if (len < 0) |
692 | 8853f86e | bellard | return -EINVAL;
|
693 | 8853f86e | bellard | lv = sizeof(int); |
694 | 8853f86e | bellard | ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv)); |
695 | 8853f86e | bellard | if (ret < 0) |
696 | 8853f86e | bellard | return ret;
|
697 | 2efbe911 | bellard | if (len < sizeof(int) && len > 0 && val >= 0 && val < 255) { |
698 | 2efbe911 | bellard | len = 1;
|
699 | 53a5960a | pbrook | tput32(optlen, len); |
700 | 53a5960a | pbrook | tput8(optval, val); |
701 | 2efbe911 | bellard | } else {
|
702 | 2efbe911 | bellard | if (len > sizeof(int)) |
703 | 2efbe911 | bellard | len = sizeof(int); |
704 | 53a5960a | pbrook | tput32(optlen, len); |
705 | 53a5960a | pbrook | tput32(optval, val); |
706 | 2efbe911 | bellard | } |
707 | 8853f86e | bellard | break;
|
708 | 2efbe911 | bellard | default:
|
709 | 2efbe911 | bellard | goto unimplemented;
|
710 | 8853f86e | bellard | } |
711 | 8853f86e | bellard | break;
|
712 | 8853f86e | bellard | default:
|
713 | 8853f86e | bellard | unimplemented:
|
714 | 8853f86e | bellard | gemu_log("getsockopt level=%d optname=%d not yet supported\n",
|
715 | 8853f86e | bellard | level, optname); |
716 | 8853f86e | bellard | ret = -ENOSYS; |
717 | 8853f86e | bellard | break;
|
718 | 8853f86e | bellard | } |
719 | 8853f86e | bellard | return ret;
|
720 | 7854b056 | bellard | } |
721 | 7854b056 | bellard | |
722 | 53a5960a | pbrook | static void lock_iovec(struct iovec *vec, target_ulong target_addr, |
723 | 53a5960a | pbrook | int count, int copy) |
724 | 53a5960a | pbrook | { |
725 | 53a5960a | pbrook | struct target_iovec *target_vec;
|
726 | 53a5960a | pbrook | target_ulong base; |
727 | 53a5960a | pbrook | int i;
|
728 | 53a5960a | pbrook | |
729 | 53a5960a | pbrook | target_vec = lock_user(target_addr, count * sizeof(struct target_iovec), 1); |
730 | 53a5960a | pbrook | for(i = 0;i < count; i++) { |
731 | 53a5960a | pbrook | base = tswapl(target_vec[i].iov_base); |
732 | 53a5960a | pbrook | vec[i].iov_len = tswapl(target_vec[i].iov_len); |
733 | 53a5960a | pbrook | vec[i].iov_base = lock_user(base, vec[i].iov_len, copy); |
734 | 53a5960a | pbrook | } |
735 | 53a5960a | pbrook | unlock_user (target_vec, target_addr, 0);
|
736 | 53a5960a | pbrook | } |
737 | 53a5960a | pbrook | |
738 | 53a5960a | pbrook | static void unlock_iovec(struct iovec *vec, target_ulong target_addr, |
739 | 53a5960a | pbrook | int count, int copy) |
740 | 53a5960a | pbrook | { |
741 | 53a5960a | pbrook | struct target_iovec *target_vec;
|
742 | 53a5960a | pbrook | target_ulong base; |
743 | 53a5960a | pbrook | int i;
|
744 | 53a5960a | pbrook | |
745 | 53a5960a | pbrook | target_vec = lock_user(target_addr, count * sizeof(struct target_iovec), 1); |
746 | 53a5960a | pbrook | for(i = 0;i < count; i++) { |
747 | 53a5960a | pbrook | base = tswapl(target_vec[i].iov_base); |
748 | 53a5960a | pbrook | unlock_user(vec[i].iov_base, base, copy ? vec[i].iov_len : 0);
|
749 | 53a5960a | pbrook | } |
750 | 53a5960a | pbrook | unlock_user (target_vec, target_addr, 0);
|
751 | 53a5960a | pbrook | } |
752 | 53a5960a | pbrook | |
753 | 3532fa74 | bellard | static long do_socket(int domain, int type, int protocol) |
754 | 3532fa74 | bellard | { |
755 | 3532fa74 | bellard | #if defined(TARGET_MIPS)
|
756 | 3532fa74 | bellard | switch(type) {
|
757 | 3532fa74 | bellard | case TARGET_SOCK_DGRAM:
|
758 | 3532fa74 | bellard | type = SOCK_DGRAM; |
759 | 3532fa74 | bellard | break;
|
760 | 3532fa74 | bellard | case TARGET_SOCK_STREAM:
|
761 | 3532fa74 | bellard | type = SOCK_STREAM; |
762 | 3532fa74 | bellard | break;
|
763 | 3532fa74 | bellard | case TARGET_SOCK_RAW:
|
764 | 3532fa74 | bellard | type = SOCK_RAW; |
765 | 3532fa74 | bellard | break;
|
766 | 3532fa74 | bellard | case TARGET_SOCK_RDM:
|
767 | 3532fa74 | bellard | type = SOCK_RDM; |
768 | 3532fa74 | bellard | break;
|
769 | 3532fa74 | bellard | case TARGET_SOCK_SEQPACKET:
|
770 | 3532fa74 | bellard | type = SOCK_SEQPACKET; |
771 | 3532fa74 | bellard | break;
|
772 | 3532fa74 | bellard | case TARGET_SOCK_PACKET:
|
773 | 3532fa74 | bellard | type = SOCK_PACKET; |
774 | 3532fa74 | bellard | break;
|
775 | 3532fa74 | bellard | } |
776 | 3532fa74 | bellard | #endif
|
777 | 3532fa74 | bellard | return get_errno(socket(domain, type, protocol));
|
778 | 3532fa74 | bellard | } |
779 | 3532fa74 | bellard | |
780 | 3532fa74 | bellard | static long do_bind(int sockfd, target_ulong target_addr, |
781 | 3532fa74 | bellard | socklen_t addrlen) |
782 | 3532fa74 | bellard | { |
783 | 3532fa74 | bellard | void *addr = alloca(addrlen);
|
784 | 3532fa74 | bellard | |
785 | 3532fa74 | bellard | target_to_host_sockaddr(addr, target_addr, addrlen); |
786 | 3532fa74 | bellard | return get_errno(bind(sockfd, addr, addrlen));
|
787 | 3532fa74 | bellard | } |
788 | 3532fa74 | bellard | |
789 | 3532fa74 | bellard | static long do_connect(int sockfd, target_ulong target_addr, |
790 | 3532fa74 | bellard | socklen_t addrlen) |
791 | 3532fa74 | bellard | { |
792 | 3532fa74 | bellard | void *addr = alloca(addrlen);
|
793 | 3532fa74 | bellard | |
794 | 3532fa74 | bellard | target_to_host_sockaddr(addr, target_addr, addrlen); |
795 | 3532fa74 | bellard | return get_errno(connect(sockfd, addr, addrlen));
|
796 | 3532fa74 | bellard | } |
797 | 3532fa74 | bellard | |
798 | 3532fa74 | bellard | static long do_sendrecvmsg(int fd, target_ulong target_msg, |
799 | 3532fa74 | bellard | int flags, int send) |
800 | 3532fa74 | bellard | { |
801 | 3532fa74 | bellard | long ret;
|
802 | 3532fa74 | bellard | struct target_msghdr *msgp;
|
803 | 3532fa74 | bellard | struct msghdr msg;
|
804 | 3532fa74 | bellard | int count;
|
805 | 3532fa74 | bellard | struct iovec *vec;
|
806 | 3532fa74 | bellard | target_ulong target_vec; |
807 | 3532fa74 | bellard | |
808 | 3532fa74 | bellard | lock_user_struct(msgp, target_msg, 1);
|
809 | 3532fa74 | bellard | if (msgp->msg_name) {
|
810 | 3532fa74 | bellard | msg.msg_namelen = tswap32(msgp->msg_namelen); |
811 | 3532fa74 | bellard | msg.msg_name = alloca(msg.msg_namelen); |
812 | 3532fa74 | bellard | target_to_host_sockaddr(msg.msg_name, tswapl(msgp->msg_name), |
813 | 3532fa74 | bellard | msg.msg_namelen); |
814 | 3532fa74 | bellard | } else {
|
815 | 3532fa74 | bellard | msg.msg_name = NULL;
|
816 | 3532fa74 | bellard | msg.msg_namelen = 0;
|
817 | 3532fa74 | bellard | } |
818 | 3532fa74 | bellard | msg.msg_controllen = 2 * tswapl(msgp->msg_controllen);
|
819 | 3532fa74 | bellard | msg.msg_control = alloca(msg.msg_controllen); |
820 | 3532fa74 | bellard | msg.msg_flags = tswap32(msgp->msg_flags); |
821 | 3532fa74 | bellard | |
822 | 3532fa74 | bellard | count = tswapl(msgp->msg_iovlen); |
823 | 3532fa74 | bellard | vec = alloca(count * sizeof(struct iovec)); |
824 | 3532fa74 | bellard | target_vec = tswapl(msgp->msg_iov); |
825 | 3532fa74 | bellard | lock_iovec(vec, target_vec, count, send); |
826 | 3532fa74 | bellard | msg.msg_iovlen = count; |
827 | 3532fa74 | bellard | msg.msg_iov = vec; |
828 | 3532fa74 | bellard | |
829 | 3532fa74 | bellard | if (send) {
|
830 | 3532fa74 | bellard | target_to_host_cmsg(&msg, msgp); |
831 | 3532fa74 | bellard | ret = get_errno(sendmsg(fd, &msg, flags)); |
832 | 3532fa74 | bellard | } else {
|
833 | 3532fa74 | bellard | ret = get_errno(recvmsg(fd, &msg, flags)); |
834 | 3532fa74 | bellard | if (!is_error(ret))
|
835 | 3532fa74 | bellard | host_to_target_cmsg(msgp, &msg); |
836 | 3532fa74 | bellard | } |
837 | 3532fa74 | bellard | unlock_iovec(vec, target_vec, count, !send); |
838 | 3532fa74 | bellard | return ret;
|
839 | 3532fa74 | bellard | } |
840 | 3532fa74 | bellard | |
841 | 1be9e1dc | pbrook | static long do_accept(int fd, target_ulong target_addr, |
842 | 1be9e1dc | pbrook | target_ulong target_addrlen) |
843 | 1be9e1dc | pbrook | { |
844 | 1be9e1dc | pbrook | socklen_t addrlen = tget32(target_addrlen); |
845 | 197ea35a | ths | void *addr = alloca(addrlen);
|
846 | 1be9e1dc | pbrook | long ret;
|
847 | 1be9e1dc | pbrook | |
848 | 1be9e1dc | pbrook | ret = get_errno(accept(fd, addr, &addrlen)); |
849 | 1be9e1dc | pbrook | if (!is_error(ret)) {
|
850 | 1be9e1dc | pbrook | host_to_target_sockaddr(target_addr, addr, addrlen); |
851 | 1be9e1dc | pbrook | tput32(target_addrlen, addrlen); |
852 | 1be9e1dc | pbrook | } |
853 | 1be9e1dc | pbrook | return ret;
|
854 | 1be9e1dc | pbrook | } |
855 | 1be9e1dc | pbrook | |
856 | 1be9e1dc | pbrook | static long do_getpeername(int fd, target_ulong target_addr, |
857 | 1be9e1dc | pbrook | target_ulong target_addrlen) |
858 | 1be9e1dc | pbrook | { |
859 | 1be9e1dc | pbrook | socklen_t addrlen = tget32(target_addrlen); |
860 | 1be9e1dc | pbrook | void *addr = alloca(target_addrlen);
|
861 | 1be9e1dc | pbrook | long ret;
|
862 | 1be9e1dc | pbrook | |
863 | 1be9e1dc | pbrook | ret = get_errno(getpeername(fd, addr, &addrlen)); |
864 | 1be9e1dc | pbrook | if (!is_error(ret)) {
|
865 | 1be9e1dc | pbrook | host_to_target_sockaddr(target_addr, addr, addrlen); |
866 | 1be9e1dc | pbrook | tput32(target_addrlen, addrlen); |
867 | 1be9e1dc | pbrook | } |
868 | 1be9e1dc | pbrook | return ret;
|
869 | 1be9e1dc | pbrook | } |
870 | 1be9e1dc | pbrook | |
871 | 1be9e1dc | pbrook | static long do_getsockname(int fd, target_ulong target_addr, |
872 | 1be9e1dc | pbrook | target_ulong target_addrlen) |
873 | 1be9e1dc | pbrook | { |
874 | 1be9e1dc | pbrook | socklen_t addrlen = tget32(target_addrlen); |
875 | 1be9e1dc | pbrook | void *addr = alloca(target_addrlen);
|
876 | 1be9e1dc | pbrook | long ret;
|
877 | 1be9e1dc | pbrook | |
878 | 1be9e1dc | pbrook | ret = get_errno(getsockname(fd, addr, &addrlen)); |
879 | 1be9e1dc | pbrook | if (!is_error(ret)) {
|
880 | 1be9e1dc | pbrook | host_to_target_sockaddr(target_addr, addr, addrlen); |
881 | 1be9e1dc | pbrook | tput32(target_addrlen, addrlen); |
882 | 1be9e1dc | pbrook | } |
883 | 1be9e1dc | pbrook | return ret;
|
884 | 1be9e1dc | pbrook | } |
885 | 1be9e1dc | pbrook | |
886 | 1be9e1dc | pbrook | static long do_socketpair(int domain, int type, int protocol, |
887 | 1be9e1dc | pbrook | target_ulong target_tab) |
888 | 1be9e1dc | pbrook | { |
889 | 1be9e1dc | pbrook | int tab[2]; |
890 | 1be9e1dc | pbrook | long ret;
|
891 | 1be9e1dc | pbrook | |
892 | 1be9e1dc | pbrook | ret = get_errno(socketpair(domain, type, protocol, tab)); |
893 | 1be9e1dc | pbrook | if (!is_error(ret)) {
|
894 | 1be9e1dc | pbrook | tput32(target_tab, tab[0]);
|
895 | 1be9e1dc | pbrook | tput32(target_tab + 4, tab[1]); |
896 | 1be9e1dc | pbrook | } |
897 | 1be9e1dc | pbrook | return ret;
|
898 | 1be9e1dc | pbrook | } |
899 | 1be9e1dc | pbrook | |
900 | 1be9e1dc | pbrook | static long do_sendto(int fd, target_ulong msg, size_t len, int flags, |
901 | 1be9e1dc | pbrook | target_ulong target_addr, socklen_t addrlen) |
902 | 1be9e1dc | pbrook | { |
903 | 1be9e1dc | pbrook | void *addr;
|
904 | 1be9e1dc | pbrook | void *host_msg;
|
905 | 1be9e1dc | pbrook | long ret;
|
906 | 1be9e1dc | pbrook | |
907 | 1be9e1dc | pbrook | host_msg = lock_user(msg, len, 1);
|
908 | 1be9e1dc | pbrook | if (target_addr) {
|
909 | 1be9e1dc | pbrook | addr = alloca(addrlen); |
910 | 1be9e1dc | pbrook | target_to_host_sockaddr(addr, target_addr, addrlen); |
911 | 1be9e1dc | pbrook | ret = get_errno(sendto(fd, host_msg, len, flags, addr, addrlen)); |
912 | 1be9e1dc | pbrook | } else {
|
913 | 1be9e1dc | pbrook | ret = get_errno(send(fd, host_msg, len, flags)); |
914 | 1be9e1dc | pbrook | } |
915 | 1be9e1dc | pbrook | unlock_user(host_msg, msg, 0);
|
916 | 1be9e1dc | pbrook | return ret;
|
917 | 1be9e1dc | pbrook | } |
918 | 1be9e1dc | pbrook | |
919 | 1be9e1dc | pbrook | static long do_recvfrom(int fd, target_ulong msg, size_t len, int flags, |
920 | 1be9e1dc | pbrook | target_ulong target_addr, target_ulong target_addrlen) |
921 | 1be9e1dc | pbrook | { |
922 | 1be9e1dc | pbrook | socklen_t addrlen; |
923 | 1be9e1dc | pbrook | void *addr;
|
924 | 1be9e1dc | pbrook | void *host_msg;
|
925 | 1be9e1dc | pbrook | long ret;
|
926 | 1be9e1dc | pbrook | |
927 | 1be9e1dc | pbrook | host_msg = lock_user(msg, len, 0);
|
928 | 1be9e1dc | pbrook | if (target_addr) {
|
929 | 1be9e1dc | pbrook | addrlen = tget32(target_addrlen); |
930 | 1be9e1dc | pbrook | addr = alloca(addrlen); |
931 | 1be9e1dc | pbrook | ret = get_errno(recvfrom(fd, host_msg, len, flags, addr, &addrlen)); |
932 | 1be9e1dc | pbrook | } else {
|
933 | 1be9e1dc | pbrook | addr = NULL; /* To keep compiler quiet. */ |
934 | 1be9e1dc | pbrook | ret = get_errno(recv(fd, host_msg, len, flags)); |
935 | 1be9e1dc | pbrook | } |
936 | 1be9e1dc | pbrook | if (!is_error(ret)) {
|
937 | 1be9e1dc | pbrook | if (target_addr) {
|
938 | 1be9e1dc | pbrook | host_to_target_sockaddr(target_addr, addr, addrlen); |
939 | 1be9e1dc | pbrook | tput32(target_addrlen, addrlen); |
940 | 1be9e1dc | pbrook | } |
941 | 1be9e1dc | pbrook | unlock_user(host_msg, msg, len); |
942 | 1be9e1dc | pbrook | } else {
|
943 | 1be9e1dc | pbrook | unlock_user(host_msg, msg, 0);
|
944 | 1be9e1dc | pbrook | } |
945 | 1be9e1dc | pbrook | return ret;
|
946 | 1be9e1dc | pbrook | } |
947 | 1be9e1dc | pbrook | |
948 | 53a5960a | pbrook | static long do_socketcall(int num, target_ulong vptr) |
949 | 31e31b8a | bellard | { |
950 | 31e31b8a | bellard | long ret;
|
951 | 53a5960a | pbrook | const int n = sizeof(target_ulong); |
952 | 31e31b8a | bellard | |
953 | 31e31b8a | bellard | switch(num) {
|
954 | 31e31b8a | bellard | case SOCKOP_socket:
|
955 | 7854b056 | bellard | { |
956 | 53a5960a | pbrook | int domain = tgetl(vptr);
|
957 | 53a5960a | pbrook | int type = tgetl(vptr + n);
|
958 | 53a5960a | pbrook | int protocol = tgetl(vptr + 2 * n); |
959 | 3532fa74 | bellard | ret = do_socket(domain, type, protocol); |
960 | 7854b056 | bellard | } |
961 | 31e31b8a | bellard | break;
|
962 | 31e31b8a | bellard | case SOCKOP_bind:
|
963 | 7854b056 | bellard | { |
964 | 53a5960a | pbrook | int sockfd = tgetl(vptr);
|
965 | 53a5960a | pbrook | target_ulong target_addr = tgetl(vptr + n); |
966 | 53a5960a | pbrook | socklen_t addrlen = tgetl(vptr + 2 * n);
|
967 | 3532fa74 | bellard | ret = do_bind(sockfd, target_addr, addrlen); |
968 | 7854b056 | bellard | } |
969 | 31e31b8a | bellard | break;
|
970 | 31e31b8a | bellard | case SOCKOP_connect:
|
971 | 7854b056 | bellard | { |
972 | 53a5960a | pbrook | int sockfd = tgetl(vptr);
|
973 | 53a5960a | pbrook | target_ulong target_addr = tgetl(vptr + n); |
974 | 53a5960a | pbrook | socklen_t addrlen = tgetl(vptr + 2 * n);
|
975 | 3532fa74 | bellard | ret = do_connect(sockfd, target_addr, addrlen); |
976 | 7854b056 | bellard | } |
977 | 31e31b8a | bellard | break;
|
978 | 31e31b8a | bellard | case SOCKOP_listen:
|
979 | 7854b056 | bellard | { |
980 | 53a5960a | pbrook | int sockfd = tgetl(vptr);
|
981 | 53a5960a | pbrook | int backlog = tgetl(vptr + n);
|
982 | 7854b056 | bellard | ret = get_errno(listen(sockfd, backlog)); |
983 | 7854b056 | bellard | } |
984 | 31e31b8a | bellard | break;
|
985 | 31e31b8a | bellard | case SOCKOP_accept:
|
986 | 31e31b8a | bellard | { |
987 | 53a5960a | pbrook | int sockfd = tgetl(vptr);
|
988 | 53a5960a | pbrook | target_ulong target_addr = tgetl(vptr + n); |
989 | 53a5960a | pbrook | target_ulong target_addrlen = tgetl(vptr + 2 * n);
|
990 | 1be9e1dc | pbrook | ret = do_accept(sockfd, target_addr, target_addrlen); |
991 | 31e31b8a | bellard | } |
992 | 31e31b8a | bellard | break;
|
993 | 31e31b8a | bellard | case SOCKOP_getsockname:
|
994 | 31e31b8a | bellard | { |
995 | 53a5960a | pbrook | int sockfd = tgetl(vptr);
|
996 | 53a5960a | pbrook | target_ulong target_addr = tgetl(vptr + n); |
997 | 53a5960a | pbrook | target_ulong target_addrlen = tgetl(vptr + 2 * n);
|
998 | 1be9e1dc | pbrook | ret = do_getsockname(sockfd, target_addr, target_addrlen); |
999 | 31e31b8a | bellard | } |
1000 | 31e31b8a | bellard | break;
|
1001 | 31e31b8a | bellard | case SOCKOP_getpeername:
|
1002 | 31e31b8a | bellard | { |
1003 | 53a5960a | pbrook | int sockfd = tgetl(vptr);
|
1004 | 53a5960a | pbrook | target_ulong target_addr = tgetl(vptr + n); |
1005 | 53a5960a | pbrook | target_ulong target_addrlen = tgetl(vptr + 2 * n);
|
1006 | 1be9e1dc | pbrook | ret = do_getpeername(sockfd, target_addr, target_addrlen); |
1007 | 31e31b8a | bellard | } |
1008 | 31e31b8a | bellard | break;
|
1009 | 31e31b8a | bellard | case SOCKOP_socketpair:
|
1010 | 31e31b8a | bellard | { |
1011 | 53a5960a | pbrook | int domain = tgetl(vptr);
|
1012 | 53a5960a | pbrook | int type = tgetl(vptr + n);
|
1013 | 53a5960a | pbrook | int protocol = tgetl(vptr + 2 * n); |
1014 | 1be9e1dc | pbrook | target_ulong tab = tgetl(vptr + 3 * n);
|
1015 | 1be9e1dc | pbrook | ret = do_socketpair(domain, type, protocol, tab); |
1016 | 31e31b8a | bellard | } |
1017 | 31e31b8a | bellard | break;
|
1018 | 31e31b8a | bellard | case SOCKOP_send:
|
1019 | 7854b056 | bellard | { |
1020 | 53a5960a | pbrook | int sockfd = tgetl(vptr);
|
1021 | 53a5960a | pbrook | target_ulong msg = tgetl(vptr + n); |
1022 | 53a5960a | pbrook | size_t len = tgetl(vptr + 2 * n);
|
1023 | 53a5960a | pbrook | int flags = tgetl(vptr + 3 * n); |
1024 | 1be9e1dc | pbrook | ret = do_sendto(sockfd, msg, len, flags, 0, 0); |
1025 | 7854b056 | bellard | } |
1026 | 31e31b8a | bellard | break;
|
1027 | 31e31b8a | bellard | case SOCKOP_recv:
|
1028 | 7854b056 | bellard | { |
1029 | 53a5960a | pbrook | int sockfd = tgetl(vptr);
|
1030 | 53a5960a | pbrook | target_ulong msg = tgetl(vptr + n); |
1031 | 53a5960a | pbrook | size_t len = tgetl(vptr + 2 * n);
|
1032 | 53a5960a | pbrook | int flags = tgetl(vptr + 3 * n); |
1033 | 1be9e1dc | pbrook | ret = do_recvfrom(sockfd, msg, len, flags, 0, 0); |
1034 | 7854b056 | bellard | } |
1035 | 31e31b8a | bellard | break;
|
1036 | 31e31b8a | bellard | case SOCKOP_sendto:
|
1037 | 7854b056 | bellard | { |
1038 | 53a5960a | pbrook | int sockfd = tgetl(vptr);
|
1039 | 53a5960a | pbrook | target_ulong msg = tgetl(vptr + n); |
1040 | 53a5960a | pbrook | size_t len = tgetl(vptr + 2 * n);
|
1041 | 53a5960a | pbrook | int flags = tgetl(vptr + 3 * n); |
1042 | 1be9e1dc | pbrook | target_ulong addr = tgetl(vptr + 4 * n);
|
1043 | 53a5960a | pbrook | socklen_t addrlen = tgetl(vptr + 5 * n);
|
1044 | 1be9e1dc | pbrook | ret = do_sendto(sockfd, msg, len, flags, addr, addrlen); |
1045 | 7854b056 | bellard | } |
1046 | 31e31b8a | bellard | break;
|
1047 | 31e31b8a | bellard | case SOCKOP_recvfrom:
|
1048 | 31e31b8a | bellard | { |
1049 | 53a5960a | pbrook | int sockfd = tgetl(vptr);
|
1050 | 53a5960a | pbrook | target_ulong msg = tgetl(vptr + n); |
1051 | 53a5960a | pbrook | size_t len = tgetl(vptr + 2 * n);
|
1052 | 53a5960a | pbrook | int flags = tgetl(vptr + 3 * n); |
1053 | 1be9e1dc | pbrook | target_ulong addr = tgetl(vptr + 4 * n);
|
1054 | 1be9e1dc | pbrook | target_ulong addrlen = tgetl(vptr + 5 * n);
|
1055 | 1be9e1dc | pbrook | ret = do_recvfrom(sockfd, msg, len, flags, addr, addrlen); |
1056 | 31e31b8a | bellard | } |
1057 | 31e31b8a | bellard | break;
|
1058 | 31e31b8a | bellard | case SOCKOP_shutdown:
|
1059 | 7854b056 | bellard | { |
1060 | 53a5960a | pbrook | int sockfd = tgetl(vptr);
|
1061 | 53a5960a | pbrook | int how = tgetl(vptr + n);
|
1062 | 7854b056 | bellard | |
1063 | 7854b056 | bellard | ret = get_errno(shutdown(sockfd, how)); |
1064 | 7854b056 | bellard | } |
1065 | 31e31b8a | bellard | break;
|
1066 | 31e31b8a | bellard | case SOCKOP_sendmsg:
|
1067 | 31e31b8a | bellard | case SOCKOP_recvmsg:
|
1068 | 1a9353d2 | bellard | { |
1069 | 1a9353d2 | bellard | int fd;
|
1070 | 53a5960a | pbrook | target_ulong target_msg; |
1071 | 3532fa74 | bellard | int flags;
|
1072 | 1a9353d2 | bellard | |
1073 | 53a5960a | pbrook | fd = tgetl(vptr); |
1074 | 3532fa74 | bellard | target_msg = tgetl(vptr + n); |
1075 | 53a5960a | pbrook | flags = tgetl(vptr + 2 * n);
|
1076 | 3532fa74 | bellard | |
1077 | 3532fa74 | bellard | ret = do_sendrecvmsg(fd, target_msg, flags, |
1078 | 3532fa74 | bellard | (num == SOCKOP_sendmsg)); |
1079 | 1a9353d2 | bellard | } |
1080 | 1a9353d2 | bellard | break;
|
1081 | 31e31b8a | bellard | case SOCKOP_setsockopt:
|
1082 | 7854b056 | bellard | { |
1083 | 53a5960a | pbrook | int sockfd = tgetl(vptr);
|
1084 | 53a5960a | pbrook | int level = tgetl(vptr + n);
|
1085 | 53a5960a | pbrook | int optname = tgetl(vptr + 2 * n); |
1086 | 53a5960a | pbrook | target_ulong optval = tgetl(vptr + 3 * n);
|
1087 | 53a5960a | pbrook | socklen_t optlen = tgetl(vptr + 4 * n);
|
1088 | 7854b056 | bellard | |
1089 | 7854b056 | bellard | ret = do_setsockopt(sockfd, level, optname, optval, optlen); |
1090 | 7854b056 | bellard | } |
1091 | 7854b056 | bellard | break;
|
1092 | 31e31b8a | bellard | case SOCKOP_getsockopt:
|
1093 | 7854b056 | bellard | { |
1094 | 53a5960a | pbrook | int sockfd = tgetl(vptr);
|
1095 | 53a5960a | pbrook | int level = tgetl(vptr + n);
|
1096 | 53a5960a | pbrook | int optname = tgetl(vptr + 2 * n); |
1097 | 53a5960a | pbrook | target_ulong optval = tgetl(vptr + 3 * n);
|
1098 | 53a5960a | pbrook | target_ulong poptlen = tgetl(vptr + 4 * n);
|
1099 | 7854b056 | bellard | |
1100 | 8853f86e | bellard | ret = do_getsockopt(sockfd, level, optname, optval, poptlen); |
1101 | 7854b056 | bellard | } |
1102 | 7854b056 | bellard | break;
|
1103 | 31e31b8a | bellard | default:
|
1104 | 31e31b8a | bellard | gemu_log("Unsupported socketcall: %d\n", num);
|
1105 | 31e31b8a | bellard | ret = -ENOSYS; |
1106 | 31e31b8a | bellard | break;
|
1107 | 31e31b8a | bellard | } |
1108 | 31e31b8a | bellard | return ret;
|
1109 | 31e31b8a | bellard | } |
1110 | 31e31b8a | bellard | |
1111 | 8853f86e | bellard | #define N_SHM_REGIONS 32 |
1112 | 8853f86e | bellard | |
1113 | 8853f86e | bellard | static struct shm_region { |
1114 | 8853f86e | bellard | uint32_t start; |
1115 | 8853f86e | bellard | uint32_t size; |
1116 | 8853f86e | bellard | } shm_regions[N_SHM_REGIONS]; |
1117 | 8853f86e | bellard | |
1118 | fa294816 | ths | union semun {
|
1119 | fa294816 | ths | int val;
|
1120 | fa294816 | ths | struct senid_ds *buf;
|
1121 | fa294816 | ths | unsigned short *array; |
1122 | fa294816 | ths | }; |
1123 | fa294816 | ths | |
1124 | 53a5960a | pbrook | /* ??? This only works with linear mappings. */
|
1125 | 8853f86e | bellard | static long do_ipc(long call, long first, long second, long third, |
1126 | 8853f86e | bellard | long ptr, long fifth) |
1127 | 8853f86e | bellard | { |
1128 | 8853f86e | bellard | int version;
|
1129 | 8853f86e | bellard | long ret = 0; |
1130 | 8853f86e | bellard | unsigned long raddr; |
1131 | 8853f86e | bellard | struct shmid_ds shm_info;
|
1132 | 8853f86e | bellard | int i;
|
1133 | 8853f86e | bellard | |
1134 | 8853f86e | bellard | version = call >> 16;
|
1135 | 8853f86e | bellard | call &= 0xffff;
|
1136 | 8853f86e | bellard | |
1137 | 8853f86e | bellard | switch (call) {
|
1138 | fa294816 | ths | case IPCOP_semop:
|
1139 | fa294816 | ths | ret = get_errno(semop(first,(struct sembuf *) ptr, second));
|
1140 | fa294816 | ths | break;
|
1141 | fa294816 | ths | |
1142 | fa294816 | ths | case IPCOP_semget:
|
1143 | fa294816 | ths | ret = get_errno(semget(first, second, third)); |
1144 | fa294816 | ths | break;
|
1145 | fa294816 | ths | |
1146 | fa294816 | ths | case IPCOP_semctl:
|
1147 | fa294816 | ths | ret = get_errno(semctl(first, second, third, ((union semun*)ptr)->val));
|
1148 | fa294816 | ths | |
1149 | fa294816 | ths | break;
|
1150 | fa294816 | ths | |
1151 | fa294816 | ths | case IPCOP_semtimedop:
|
1152 | fa294816 | ths | gemu_log("Unsupported ipc call: %ld (version %d)\n", call, version);
|
1153 | fa294816 | ths | ret = -ENOSYS; |
1154 | fa294816 | ths | break;
|
1155 | d96372ef | ths | |
1156 | d96372ef | ths | case IPCOP_msgget:
|
1157 | d96372ef | ths | ret = get_errno(msgget(first, second)); |
1158 | d96372ef | ths | break;
|
1159 | d96372ef | ths | |
1160 | d96372ef | ths | case IPCOP_msgsnd:
|
1161 | d96372ef | ths | ret = get_errno(msgsnd(first, (struct msgbuf *) ptr, second, third));
|
1162 | d96372ef | ths | break;
|
1163 | d96372ef | ths | |
1164 | d96372ef | ths | case IPCOP_msgctl:
|
1165 | d96372ef | ths | ret = get_errno(msgctl(first, second, (struct msqid_ds *) ptr));
|
1166 | d96372ef | ths | break;
|
1167 | d96372ef | ths | |
1168 | d96372ef | ths | case IPCOP_msgrcv:
|
1169 | d96372ef | ths | { |
1170 | d96372ef | ths | struct ipc_kludge
|
1171 | d96372ef | ths | { |
1172 | d96372ef | ths | void *__unbounded msgp;
|
1173 | d96372ef | ths | long int msgtyp; |
1174 | d96372ef | ths | }; |
1175 | d96372ef | ths | |
1176 | d96372ef | ths | struct ipc_kludge *foo = (struct ipc_kludge *) ptr; |
1177 | d96372ef | ths | struct msgbuf *msgp = (struct msgbuf *) foo->msgp; |
1178 | d96372ef | ths | |
1179 | d96372ef | ths | ret = get_errno(msgrcv(first, msgp, second, 0, third));
|
1180 | d96372ef | ths | |
1181 | d96372ef | ths | } |
1182 | d96372ef | ths | break;
|
1183 | d96372ef | ths | |
1184 | 8853f86e | bellard | case IPCOP_shmat:
|
1185 | 8853f86e | bellard | /* SHM_* flags are the same on all linux platforms */
|
1186 | 8853f86e | bellard | ret = get_errno((long) shmat(first, (void *) ptr, second)); |
1187 | 8853f86e | bellard | if (is_error(ret))
|
1188 | 8853f86e | bellard | break;
|
1189 | 8853f86e | bellard | raddr = ret; |
1190 | 8853f86e | bellard | /* find out the length of the shared memory segment */
|
1191 | 8853f86e | bellard | |
1192 | 8853f86e | bellard | ret = get_errno(shmctl(first, IPC_STAT, &shm_info)); |
1193 | 8853f86e | bellard | if (is_error(ret)) {
|
1194 | 8853f86e | bellard | /* can't get length, bail out */
|
1195 | 8853f86e | bellard | shmdt((void *) raddr);
|
1196 | 8853f86e | bellard | break;
|
1197 | 8853f86e | bellard | } |
1198 | 8853f86e | bellard | page_set_flags(raddr, raddr + shm_info.shm_segsz, |
1199 | 8853f86e | bellard | PAGE_VALID | PAGE_READ | |
1200 | 8853f86e | bellard | ((second & SHM_RDONLY)? 0: PAGE_WRITE));
|
1201 | 8853f86e | bellard | for (i = 0; i < N_SHM_REGIONS; ++i) { |
1202 | 8853f86e | bellard | if (shm_regions[i].start == 0) { |
1203 | 8853f86e | bellard | shm_regions[i].start = raddr; |
1204 | 8853f86e | bellard | shm_regions[i].size = shm_info.shm_segsz; |
1205 | 8853f86e | bellard | break;
|
1206 | 8853f86e | bellard | } |
1207 | 8853f86e | bellard | } |
1208 | 8853f86e | bellard | if (put_user(raddr, (uint32_t *)third))
|
1209 | 8853f86e | bellard | return -EFAULT;
|
1210 | 8853f86e | bellard | ret = 0;
|
1211 | 8853f86e | bellard | break;
|
1212 | 8853f86e | bellard | case IPCOP_shmdt:
|
1213 | 8853f86e | bellard | for (i = 0; i < N_SHM_REGIONS; ++i) { |
1214 | 8853f86e | bellard | if (shm_regions[i].start == ptr) {
|
1215 | 8853f86e | bellard | shm_regions[i].start = 0;
|
1216 | 8853f86e | bellard | page_set_flags(ptr, shm_regions[i].size, 0);
|
1217 | 8853f86e | bellard | break;
|
1218 | 8853f86e | bellard | } |
1219 | 8853f86e | bellard | } |
1220 | 8853f86e | bellard | ret = get_errno(shmdt((void *) ptr));
|
1221 | 8853f86e | bellard | break;
|
1222 | 8853f86e | bellard | |
1223 | 8853f86e | bellard | case IPCOP_shmget:
|
1224 | 8853f86e | bellard | /* IPC_* flag values are the same on all linux platforms */
|
1225 | 8853f86e | bellard | ret = get_errno(shmget(first, second, third)); |
1226 | 8853f86e | bellard | break;
|
1227 | 8853f86e | bellard | |
1228 | 8853f86e | bellard | /* IPC_* and SHM_* command values are the same on all linux platforms */
|
1229 | 8853f86e | bellard | case IPCOP_shmctl:
|
1230 | 8853f86e | bellard | switch(second) {
|
1231 | 8853f86e | bellard | case IPC_RMID:
|
1232 | 8853f86e | bellard | case SHM_LOCK:
|
1233 | 8853f86e | bellard | case SHM_UNLOCK:
|
1234 | 8853f86e | bellard | ret = get_errno(shmctl(first, second, NULL));
|
1235 | 8853f86e | bellard | break;
|
1236 | 8853f86e | bellard | default:
|
1237 | 8853f86e | bellard | goto unimplemented;
|
1238 | 8853f86e | bellard | } |
1239 | 8853f86e | bellard | break;
|
1240 | 8853f86e | bellard | default:
|
1241 | 8853f86e | bellard | unimplemented:
|
1242 | 8853f86e | bellard | gemu_log("Unsupported ipc call: %ld (version %d)\n", call, version);
|
1243 | 8853f86e | bellard | ret = -ENOSYS; |
1244 | 8853f86e | bellard | break;
|
1245 | 8853f86e | bellard | } |
1246 | 8853f86e | bellard | return ret;
|
1247 | 8853f86e | bellard | } |
1248 | 8853f86e | bellard | |
1249 | 31e31b8a | bellard | /* kernel structure types definitions */
|
1250 | 31e31b8a | bellard | #define IFNAMSIZ 16 |
1251 | 31e31b8a | bellard | |
1252 | 31e31b8a | bellard | #define STRUCT(name, list...) STRUCT_ ## name, |
1253 | 31e31b8a | bellard | #define STRUCT_SPECIAL(name) STRUCT_ ## name, |
1254 | 31e31b8a | bellard | enum {
|
1255 | 31e31b8a | bellard | #include "syscall_types.h" |
1256 | 31e31b8a | bellard | }; |
1257 | 31e31b8a | bellard | #undef STRUCT
|
1258 | 31e31b8a | bellard | #undef STRUCT_SPECIAL
|
1259 | 31e31b8a | bellard | |
1260 | 31e31b8a | bellard | #define STRUCT(name, list...) const argtype struct_ ## name ## _def[] = { list, TYPE_NULL }; |
1261 | 31e31b8a | bellard | #define STRUCT_SPECIAL(name)
|
1262 | 31e31b8a | bellard | #include "syscall_types.h" |
1263 | 31e31b8a | bellard | #undef STRUCT
|
1264 | 31e31b8a | bellard | #undef STRUCT_SPECIAL
|
1265 | 31e31b8a | bellard | |
1266 | 31e31b8a | bellard | typedef struct IOCTLEntry { |
1267 | 2ab83ea7 | bellard | unsigned int target_cmd; |
1268 | 2ab83ea7 | bellard | unsigned int host_cmd; |
1269 | 31e31b8a | bellard | const char *name; |
1270 | 31e31b8a | bellard | int access;
|
1271 | 1a9353d2 | bellard | const argtype arg_type[5]; |
1272 | 31e31b8a | bellard | } IOCTLEntry; |
1273 | 31e31b8a | bellard | |
1274 | 31e31b8a | bellard | #define IOC_R 0x0001 |
1275 | 31e31b8a | bellard | #define IOC_W 0x0002 |
1276 | 31e31b8a | bellard | #define IOC_RW (IOC_R | IOC_W)
|
1277 | 31e31b8a | bellard | |
1278 | 31e31b8a | bellard | #define MAX_STRUCT_SIZE 4096 |
1279 | 31e31b8a | bellard | |
1280 | 2ab83ea7 | bellard | IOCTLEntry ioctl_entries[] = { |
1281 | 31e31b8a | bellard | #define IOCTL(cmd, access, types...) \
|
1282 | 31e31b8a | bellard | { TARGET_ ## cmd, cmd, #cmd, access, { types } }, |
1283 | 31e31b8a | bellard | #include "ioctls.h" |
1284 | 31e31b8a | bellard | { 0, 0, }, |
1285 | 31e31b8a | bellard | }; |
1286 | 31e31b8a | bellard | |
1287 | 53a5960a | pbrook | /* ??? Implement proper locking for ioctls. */
|
1288 | 31e31b8a | bellard | static long do_ioctl(long fd, long cmd, long arg) |
1289 | 31e31b8a | bellard | { |
1290 | 31e31b8a | bellard | const IOCTLEntry *ie;
|
1291 | 31e31b8a | bellard | const argtype *arg_type;
|
1292 | 31e31b8a | bellard | long ret;
|
1293 | 31e31b8a | bellard | uint8_t buf_temp[MAX_STRUCT_SIZE]; |
1294 | 53a5960a | pbrook | int target_size;
|
1295 | 53a5960a | pbrook | void *argptr;
|
1296 | 31e31b8a | bellard | |
1297 | 31e31b8a | bellard | ie = ioctl_entries; |
1298 | 31e31b8a | bellard | for(;;) {
|
1299 | 31e31b8a | bellard | if (ie->target_cmd == 0) { |
1300 | 31e31b8a | bellard | gemu_log("Unsupported ioctl: cmd=0x%04lx\n", cmd);
|
1301 | 31e31b8a | bellard | return -ENOSYS;
|
1302 | 31e31b8a | bellard | } |
1303 | 31e31b8a | bellard | if (ie->target_cmd == cmd)
|
1304 | 31e31b8a | bellard | break;
|
1305 | 31e31b8a | bellard | ie++; |
1306 | 31e31b8a | bellard | } |
1307 | 31e31b8a | bellard | arg_type = ie->arg_type; |
1308 | 9de5e440 | bellard | #if defined(DEBUG)
|
1309 | 72f03900 | bellard | gemu_log("ioctl: cmd=0x%04lx (%s)\n", cmd, ie->name);
|
1310 | 72f03900 | bellard | #endif
|
1311 | 31e31b8a | bellard | switch(arg_type[0]) { |
1312 | 31e31b8a | bellard | case TYPE_NULL:
|
1313 | 31e31b8a | bellard | /* no argument */
|
1314 | 31e31b8a | bellard | ret = get_errno(ioctl(fd, ie->host_cmd)); |
1315 | 31e31b8a | bellard | break;
|
1316 | 31e31b8a | bellard | case TYPE_PTRVOID:
|
1317 | 31e31b8a | bellard | case TYPE_INT:
|
1318 | 31e31b8a | bellard | /* int argment */
|
1319 | 31e31b8a | bellard | ret = get_errno(ioctl(fd, ie->host_cmd, arg)); |
1320 | 31e31b8a | bellard | break;
|
1321 | 31e31b8a | bellard | case TYPE_PTR:
|
1322 | 31e31b8a | bellard | arg_type++; |
1323 | 53a5960a | pbrook | target_size = thunk_type_size(arg_type, 0);
|
1324 | 31e31b8a | bellard | switch(ie->access) {
|
1325 | 31e31b8a | bellard | case IOC_R:
|
1326 | 31e31b8a | bellard | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
1327 | 31e31b8a | bellard | if (!is_error(ret)) {
|
1328 | 53a5960a | pbrook | argptr = lock_user(arg, target_size, 0);
|
1329 | 53a5960a | pbrook | thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); |
1330 | 53a5960a | pbrook | unlock_user(argptr, arg, target_size); |
1331 | 31e31b8a | bellard | } |
1332 | 31e31b8a | bellard | break;
|
1333 | 31e31b8a | bellard | case IOC_W:
|
1334 | 53a5960a | pbrook | argptr = lock_user(arg, target_size, 1);
|
1335 | 53a5960a | pbrook | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
1336 | 53a5960a | pbrook | unlock_user(argptr, arg, 0);
|
1337 | 31e31b8a | bellard | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
1338 | 31e31b8a | bellard | break;
|
1339 | 31e31b8a | bellard | default:
|
1340 | 31e31b8a | bellard | case IOC_RW:
|
1341 | 53a5960a | pbrook | argptr = lock_user(arg, target_size, 1);
|
1342 | 53a5960a | pbrook | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
1343 | 53a5960a | pbrook | unlock_user(argptr, arg, 0);
|
1344 | 31e31b8a | bellard | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
1345 | 31e31b8a | bellard | if (!is_error(ret)) {
|
1346 | 53a5960a | pbrook | argptr = lock_user(arg, target_size, 0);
|
1347 | 53a5960a | pbrook | thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); |
1348 | 53a5960a | pbrook | unlock_user(argptr, arg, target_size); |
1349 | 31e31b8a | bellard | } |
1350 | 31e31b8a | bellard | break;
|
1351 | 31e31b8a | bellard | } |
1352 | 31e31b8a | bellard | break;
|
1353 | 31e31b8a | bellard | default:
|
1354 | 31e31b8a | bellard | gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", cmd, arg_type[0]); |
1355 | 31e31b8a | bellard | ret = -ENOSYS; |
1356 | 31e31b8a | bellard | break;
|
1357 | 31e31b8a | bellard | } |
1358 | 31e31b8a | bellard | return ret;
|
1359 | 31e31b8a | bellard | } |
1360 | 31e31b8a | bellard | |
1361 | 31e31b8a | bellard | bitmask_transtbl iflag_tbl[] = { |
1362 | 31e31b8a | bellard | { TARGET_IGNBRK, TARGET_IGNBRK, IGNBRK, IGNBRK }, |
1363 | 31e31b8a | bellard | { TARGET_BRKINT, TARGET_BRKINT, BRKINT, BRKINT }, |
1364 | 31e31b8a | bellard | { TARGET_IGNPAR, TARGET_IGNPAR, IGNPAR, IGNPAR }, |
1365 | 31e31b8a | bellard | { TARGET_PARMRK, TARGET_PARMRK, PARMRK, PARMRK }, |
1366 | 31e31b8a | bellard | { TARGET_INPCK, TARGET_INPCK, INPCK, INPCK }, |
1367 | 31e31b8a | bellard | { TARGET_ISTRIP, TARGET_ISTRIP, ISTRIP, ISTRIP }, |
1368 | 31e31b8a | bellard | { TARGET_INLCR, TARGET_INLCR, INLCR, INLCR }, |
1369 | 31e31b8a | bellard | { TARGET_IGNCR, TARGET_IGNCR, IGNCR, IGNCR }, |
1370 | 31e31b8a | bellard | { TARGET_ICRNL, TARGET_ICRNL, ICRNL, ICRNL }, |
1371 | 31e31b8a | bellard | { TARGET_IUCLC, TARGET_IUCLC, IUCLC, IUCLC }, |
1372 | 31e31b8a | bellard | { TARGET_IXON, TARGET_IXON, IXON, IXON }, |
1373 | 31e31b8a | bellard | { TARGET_IXANY, TARGET_IXANY, IXANY, IXANY }, |
1374 | 31e31b8a | bellard | { TARGET_IXOFF, TARGET_IXOFF, IXOFF, IXOFF }, |
1375 | 31e31b8a | bellard | { TARGET_IMAXBEL, TARGET_IMAXBEL, IMAXBEL, IMAXBEL }, |
1376 | 31e31b8a | bellard | { 0, 0, 0, 0 } |
1377 | 31e31b8a | bellard | }; |
1378 | 31e31b8a | bellard | |
1379 | 31e31b8a | bellard | bitmask_transtbl oflag_tbl[] = { |
1380 | 31e31b8a | bellard | { TARGET_OPOST, TARGET_OPOST, OPOST, OPOST }, |
1381 | 31e31b8a | bellard | { TARGET_OLCUC, TARGET_OLCUC, OLCUC, OLCUC }, |
1382 | 31e31b8a | bellard | { TARGET_ONLCR, TARGET_ONLCR, ONLCR, ONLCR }, |
1383 | 31e31b8a | bellard | { TARGET_OCRNL, TARGET_OCRNL, OCRNL, OCRNL }, |
1384 | 31e31b8a | bellard | { TARGET_ONOCR, TARGET_ONOCR, ONOCR, ONOCR }, |
1385 | 31e31b8a | bellard | { TARGET_ONLRET, TARGET_ONLRET, ONLRET, ONLRET }, |
1386 | 31e31b8a | bellard | { TARGET_OFILL, TARGET_OFILL, OFILL, OFILL }, |
1387 | 31e31b8a | bellard | { TARGET_OFDEL, TARGET_OFDEL, OFDEL, OFDEL }, |
1388 | 31e31b8a | bellard | { TARGET_NLDLY, TARGET_NL0, NLDLY, NL0 }, |
1389 | 31e31b8a | bellard | { TARGET_NLDLY, TARGET_NL1, NLDLY, NL1 }, |
1390 | 31e31b8a | bellard | { TARGET_CRDLY, TARGET_CR0, CRDLY, CR0 }, |
1391 | 31e31b8a | bellard | { TARGET_CRDLY, TARGET_CR1, CRDLY, CR1 }, |
1392 | 31e31b8a | bellard | { TARGET_CRDLY, TARGET_CR2, CRDLY, CR2 }, |
1393 | 31e31b8a | bellard | { TARGET_CRDLY, TARGET_CR3, CRDLY, CR3 }, |
1394 | 31e31b8a | bellard | { TARGET_TABDLY, TARGET_TAB0, TABDLY, TAB0 }, |
1395 | 31e31b8a | bellard | { TARGET_TABDLY, TARGET_TAB1, TABDLY, TAB1 }, |
1396 | 31e31b8a | bellard | { TARGET_TABDLY, TARGET_TAB2, TABDLY, TAB2 }, |
1397 | 31e31b8a | bellard | { TARGET_TABDLY, TARGET_TAB3, TABDLY, TAB3 }, |
1398 | 31e31b8a | bellard | { TARGET_BSDLY, TARGET_BS0, BSDLY, BS0 }, |
1399 | 31e31b8a | bellard | { TARGET_BSDLY, TARGET_BS1, BSDLY, BS1 }, |
1400 | 31e31b8a | bellard | { TARGET_VTDLY, TARGET_VT0, VTDLY, VT0 }, |
1401 | 31e31b8a | bellard | { TARGET_VTDLY, TARGET_VT1, VTDLY, VT1 }, |
1402 | 31e31b8a | bellard | { TARGET_FFDLY, TARGET_FF0, FFDLY, FF0 }, |
1403 | 31e31b8a | bellard | { TARGET_FFDLY, TARGET_FF1, FFDLY, FF1 }, |
1404 | 31e31b8a | bellard | { 0, 0, 0, 0 } |
1405 | 31e31b8a | bellard | }; |
1406 | 31e31b8a | bellard | |
1407 | 31e31b8a | bellard | bitmask_transtbl cflag_tbl[] = { |
1408 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B0, CBAUD, B0 }, |
1409 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B50, CBAUD, B50 }, |
1410 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B75, CBAUD, B75 }, |
1411 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B110, CBAUD, B110 }, |
1412 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B134, CBAUD, B134 }, |
1413 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B150, CBAUD, B150 }, |
1414 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B200, CBAUD, B200 }, |
1415 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B300, CBAUD, B300 }, |
1416 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B600, CBAUD, B600 }, |
1417 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B1200, CBAUD, B1200 }, |
1418 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B1800, CBAUD, B1800 }, |
1419 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B2400, CBAUD, B2400 }, |
1420 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B4800, CBAUD, B4800 }, |
1421 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B9600, CBAUD, B9600 }, |
1422 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B19200, CBAUD, B19200 }, |
1423 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B38400, CBAUD, B38400 }, |
1424 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B57600, CBAUD, B57600 }, |
1425 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B115200, CBAUD, B115200 }, |
1426 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B230400, CBAUD, B230400 }, |
1427 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B460800, CBAUD, B460800 }, |
1428 | 31e31b8a | bellard | { TARGET_CSIZE, TARGET_CS5, CSIZE, CS5 }, |
1429 | 31e31b8a | bellard | { TARGET_CSIZE, TARGET_CS6, CSIZE, CS6 }, |
1430 | 31e31b8a | bellard | { TARGET_CSIZE, TARGET_CS7, CSIZE, CS7 }, |
1431 | 31e31b8a | bellard | { TARGET_CSIZE, TARGET_CS8, CSIZE, CS8 }, |
1432 | 31e31b8a | bellard | { TARGET_CSTOPB, TARGET_CSTOPB, CSTOPB, CSTOPB }, |
1433 | 31e31b8a | bellard | { TARGET_CREAD, TARGET_CREAD, CREAD, CREAD }, |
1434 | 31e31b8a | bellard | { TARGET_PARENB, TARGET_PARENB, PARENB, PARENB }, |
1435 | 31e31b8a | bellard | { TARGET_PARODD, TARGET_PARODD, PARODD, PARODD }, |
1436 | 31e31b8a | bellard | { TARGET_HUPCL, TARGET_HUPCL, HUPCL, HUPCL }, |
1437 | 31e31b8a | bellard | { TARGET_CLOCAL, TARGET_CLOCAL, CLOCAL, CLOCAL }, |
1438 | 31e31b8a | bellard | { TARGET_CRTSCTS, TARGET_CRTSCTS, CRTSCTS, CRTSCTS }, |
1439 | 31e31b8a | bellard | { 0, 0, 0, 0 } |
1440 | 31e31b8a | bellard | }; |
1441 | 31e31b8a | bellard | |
1442 | 31e31b8a | bellard | bitmask_transtbl lflag_tbl[] = { |
1443 | 31e31b8a | bellard | { TARGET_ISIG, TARGET_ISIG, ISIG, ISIG }, |
1444 | 31e31b8a | bellard | { TARGET_ICANON, TARGET_ICANON, ICANON, ICANON }, |
1445 | 31e31b8a | bellard | { TARGET_XCASE, TARGET_XCASE, XCASE, XCASE }, |
1446 | 31e31b8a | bellard | { TARGET_ECHO, TARGET_ECHO, ECHO, ECHO }, |
1447 | 31e31b8a | bellard | { TARGET_ECHOE, TARGET_ECHOE, ECHOE, ECHOE }, |
1448 | 31e31b8a | bellard | { TARGET_ECHOK, TARGET_ECHOK, ECHOK, ECHOK }, |
1449 | 31e31b8a | bellard | { TARGET_ECHONL, TARGET_ECHONL, ECHONL, ECHONL }, |
1450 | 31e31b8a | bellard | { TARGET_NOFLSH, TARGET_NOFLSH, NOFLSH, NOFLSH }, |
1451 | 31e31b8a | bellard | { TARGET_TOSTOP, TARGET_TOSTOP, TOSTOP, TOSTOP }, |
1452 | 31e31b8a | bellard | { TARGET_ECHOCTL, TARGET_ECHOCTL, ECHOCTL, ECHOCTL }, |
1453 | 31e31b8a | bellard | { TARGET_ECHOPRT, TARGET_ECHOPRT, ECHOPRT, ECHOPRT }, |
1454 | 31e31b8a | bellard | { TARGET_ECHOKE, TARGET_ECHOKE, ECHOKE, ECHOKE }, |
1455 | 31e31b8a | bellard | { TARGET_FLUSHO, TARGET_FLUSHO, FLUSHO, FLUSHO }, |
1456 | 31e31b8a | bellard | { TARGET_PENDIN, TARGET_PENDIN, PENDIN, PENDIN }, |
1457 | 31e31b8a | bellard | { TARGET_IEXTEN, TARGET_IEXTEN, IEXTEN, IEXTEN }, |
1458 | 31e31b8a | bellard | { 0, 0, 0, 0 } |
1459 | 31e31b8a | bellard | }; |
1460 | 31e31b8a | bellard | |
1461 | 31e31b8a | bellard | static void target_to_host_termios (void *dst, const void *src) |
1462 | 31e31b8a | bellard | { |
1463 | 31e31b8a | bellard | struct host_termios *host = dst;
|
1464 | 31e31b8a | bellard | const struct target_termios *target = src; |
1465 | 31e31b8a | bellard | |
1466 | 31e31b8a | bellard | host->c_iflag = |
1467 | 31e31b8a | bellard | target_to_host_bitmask(tswap32(target->c_iflag), iflag_tbl); |
1468 | 31e31b8a | bellard | host->c_oflag = |
1469 | 31e31b8a | bellard | target_to_host_bitmask(tswap32(target->c_oflag), oflag_tbl); |
1470 | 31e31b8a | bellard | host->c_cflag = |
1471 | 31e31b8a | bellard | target_to_host_bitmask(tswap32(target->c_cflag), cflag_tbl); |
1472 | 31e31b8a | bellard | host->c_lflag = |
1473 | 31e31b8a | bellard | target_to_host_bitmask(tswap32(target->c_lflag), lflag_tbl); |
1474 | 31e31b8a | bellard | host->c_line = target->c_line; |
1475 | 31e31b8a | bellard | |
1476 | 31e31b8a | bellard | host->c_cc[VINTR] = target->c_cc[TARGET_VINTR]; |
1477 | 31e31b8a | bellard | host->c_cc[VQUIT] = target->c_cc[TARGET_VQUIT]; |
1478 | 31e31b8a | bellard | host->c_cc[VERASE] = target->c_cc[TARGET_VERASE]; |
1479 | 31e31b8a | bellard | host->c_cc[VKILL] = target->c_cc[TARGET_VKILL]; |
1480 | 31e31b8a | bellard | host->c_cc[VEOF] = target->c_cc[TARGET_VEOF]; |
1481 | 31e31b8a | bellard | host->c_cc[VTIME] = target->c_cc[TARGET_VTIME]; |
1482 | 31e31b8a | bellard | host->c_cc[VMIN] = target->c_cc[TARGET_VMIN]; |
1483 | 31e31b8a | bellard | host->c_cc[VSWTC] = target->c_cc[TARGET_VSWTC]; |
1484 | 31e31b8a | bellard | host->c_cc[VSTART] = target->c_cc[TARGET_VSTART]; |
1485 | 31e31b8a | bellard | host->c_cc[VSTOP] = target->c_cc[TARGET_VSTOP]; |
1486 | 31e31b8a | bellard | host->c_cc[VSUSP] = target->c_cc[TARGET_VSUSP]; |
1487 | 31e31b8a | bellard | host->c_cc[VEOL] = target->c_cc[TARGET_VEOL]; |
1488 | 31e31b8a | bellard | host->c_cc[VREPRINT] = target->c_cc[TARGET_VREPRINT]; |
1489 | 31e31b8a | bellard | host->c_cc[VDISCARD] = target->c_cc[TARGET_VDISCARD]; |
1490 | 31e31b8a | bellard | host->c_cc[VWERASE] = target->c_cc[TARGET_VWERASE]; |
1491 | 31e31b8a | bellard | host->c_cc[VLNEXT] = target->c_cc[TARGET_VLNEXT]; |
1492 | 31e31b8a | bellard | host->c_cc[VEOL2] = target->c_cc[TARGET_VEOL2]; |
1493 | 31e31b8a | bellard | } |
1494 | 31e31b8a | bellard | |
1495 | 31e31b8a | bellard | static void host_to_target_termios (void *dst, const void *src) |
1496 | 31e31b8a | bellard | { |
1497 | 31e31b8a | bellard | struct target_termios *target = dst;
|
1498 | 31e31b8a | bellard | const struct host_termios *host = src; |
1499 | 31e31b8a | bellard | |
1500 | 31e31b8a | bellard | target->c_iflag = |
1501 | 31e31b8a | bellard | tswap32(host_to_target_bitmask(host->c_iflag, iflag_tbl)); |
1502 | 31e31b8a | bellard | target->c_oflag = |
1503 | 31e31b8a | bellard | tswap32(host_to_target_bitmask(host->c_oflag, oflag_tbl)); |
1504 | 31e31b8a | bellard | target->c_cflag = |
1505 | 31e31b8a | bellard | tswap32(host_to_target_bitmask(host->c_cflag, cflag_tbl)); |
1506 | 31e31b8a | bellard | target->c_lflag = |
1507 | 31e31b8a | bellard | tswap32(host_to_target_bitmask(host->c_lflag, lflag_tbl)); |
1508 | 31e31b8a | bellard | target->c_line = host->c_line; |
1509 | 31e31b8a | bellard | |
1510 | 31e31b8a | bellard | target->c_cc[TARGET_VINTR] = host->c_cc[VINTR]; |
1511 | 31e31b8a | bellard | target->c_cc[TARGET_VQUIT] = host->c_cc[VQUIT]; |
1512 | 31e31b8a | bellard | target->c_cc[TARGET_VERASE] = host->c_cc[VERASE]; |
1513 | 31e31b8a | bellard | target->c_cc[TARGET_VKILL] = host->c_cc[VKILL]; |
1514 | 31e31b8a | bellard | target->c_cc[TARGET_VEOF] = host->c_cc[VEOF]; |
1515 | 31e31b8a | bellard | target->c_cc[TARGET_VTIME] = host->c_cc[VTIME]; |
1516 | 31e31b8a | bellard | target->c_cc[TARGET_VMIN] = host->c_cc[VMIN]; |
1517 | 31e31b8a | bellard | target->c_cc[TARGET_VSWTC] = host->c_cc[VSWTC]; |
1518 | 31e31b8a | bellard | target->c_cc[TARGET_VSTART] = host->c_cc[VSTART]; |
1519 | 31e31b8a | bellard | target->c_cc[TARGET_VSTOP] = host->c_cc[VSTOP]; |
1520 | 31e31b8a | bellard | target->c_cc[TARGET_VSUSP] = host->c_cc[VSUSP]; |
1521 | 31e31b8a | bellard | target->c_cc[TARGET_VEOL] = host->c_cc[VEOL]; |
1522 | 31e31b8a | bellard | target->c_cc[TARGET_VREPRINT] = host->c_cc[VREPRINT]; |
1523 | 31e31b8a | bellard | target->c_cc[TARGET_VDISCARD] = host->c_cc[VDISCARD]; |
1524 | 31e31b8a | bellard | target->c_cc[TARGET_VWERASE] = host->c_cc[VWERASE]; |
1525 | 31e31b8a | bellard | target->c_cc[TARGET_VLNEXT] = host->c_cc[VLNEXT]; |
1526 | 31e31b8a | bellard | target->c_cc[TARGET_VEOL2] = host->c_cc[VEOL2]; |
1527 | 31e31b8a | bellard | } |
1528 | 31e31b8a | bellard | |
1529 | 31e31b8a | bellard | StructEntry struct_termios_def = { |
1530 | 31e31b8a | bellard | .convert = { host_to_target_termios, target_to_host_termios }, |
1531 | 31e31b8a | bellard | .size = { sizeof(struct target_termios), sizeof(struct host_termios) }, |
1532 | 31e31b8a | bellard | .align = { __alignof__(struct target_termios), __alignof__(struct host_termios) }, |
1533 | 31e31b8a | bellard | }; |
1534 | 31e31b8a | bellard | |
1535 | 5286db75 | bellard | static bitmask_transtbl mmap_flags_tbl[] = {
|
1536 | 5286db75 | bellard | { TARGET_MAP_SHARED, TARGET_MAP_SHARED, MAP_SHARED, MAP_SHARED }, |
1537 | 5286db75 | bellard | { TARGET_MAP_PRIVATE, TARGET_MAP_PRIVATE, MAP_PRIVATE, MAP_PRIVATE }, |
1538 | 5286db75 | bellard | { TARGET_MAP_FIXED, TARGET_MAP_FIXED, MAP_FIXED, MAP_FIXED }, |
1539 | 5286db75 | bellard | { TARGET_MAP_ANONYMOUS, TARGET_MAP_ANONYMOUS, MAP_ANONYMOUS, MAP_ANONYMOUS }, |
1540 | 5286db75 | bellard | { TARGET_MAP_GROWSDOWN, TARGET_MAP_GROWSDOWN, MAP_GROWSDOWN, MAP_GROWSDOWN }, |
1541 | 5286db75 | bellard | { TARGET_MAP_DENYWRITE, TARGET_MAP_DENYWRITE, MAP_DENYWRITE, MAP_DENYWRITE }, |
1542 | 5286db75 | bellard | { TARGET_MAP_EXECUTABLE, TARGET_MAP_EXECUTABLE, MAP_EXECUTABLE, MAP_EXECUTABLE }, |
1543 | 5286db75 | bellard | { TARGET_MAP_LOCKED, TARGET_MAP_LOCKED, MAP_LOCKED, MAP_LOCKED }, |
1544 | 5286db75 | bellard | { 0, 0, 0, 0 } |
1545 | 5286db75 | bellard | }; |
1546 | 5286db75 | bellard | |
1547 | ffa65c3b | bellard | static bitmask_transtbl fcntl_flags_tbl[] = {
|
1548 | ffa65c3b | bellard | { TARGET_O_ACCMODE, TARGET_O_WRONLY, O_ACCMODE, O_WRONLY, }, |
1549 | ffa65c3b | bellard | { TARGET_O_ACCMODE, TARGET_O_RDWR, O_ACCMODE, O_RDWR, }, |
1550 | ffa65c3b | bellard | { TARGET_O_CREAT, TARGET_O_CREAT, O_CREAT, O_CREAT, }, |
1551 | ffa65c3b | bellard | { TARGET_O_EXCL, TARGET_O_EXCL, O_EXCL, O_EXCL, }, |
1552 | ffa65c3b | bellard | { TARGET_O_NOCTTY, TARGET_O_NOCTTY, O_NOCTTY, O_NOCTTY, }, |
1553 | ffa65c3b | bellard | { TARGET_O_TRUNC, TARGET_O_TRUNC, O_TRUNC, O_TRUNC, }, |
1554 | ffa65c3b | bellard | { TARGET_O_APPEND, TARGET_O_APPEND, O_APPEND, O_APPEND, }, |
1555 | ffa65c3b | bellard | { TARGET_O_NONBLOCK, TARGET_O_NONBLOCK, O_NONBLOCK, O_NONBLOCK, }, |
1556 | ffa65c3b | bellard | { TARGET_O_SYNC, TARGET_O_SYNC, O_SYNC, O_SYNC, }, |
1557 | ffa65c3b | bellard | { TARGET_FASYNC, TARGET_FASYNC, FASYNC, FASYNC, }, |
1558 | ffa65c3b | bellard | { TARGET_O_DIRECTORY, TARGET_O_DIRECTORY, O_DIRECTORY, O_DIRECTORY, }, |
1559 | ffa65c3b | bellard | { TARGET_O_NOFOLLOW, TARGET_O_NOFOLLOW, O_NOFOLLOW, O_NOFOLLOW, }, |
1560 | ffa65c3b | bellard | { TARGET_O_LARGEFILE, TARGET_O_LARGEFILE, O_LARGEFILE, O_LARGEFILE, }, |
1561 | 121061dc | bellard | #if defined(O_DIRECT)
|
1562 | ffa65c3b | bellard | { TARGET_O_DIRECT, TARGET_O_DIRECT, O_DIRECT, O_DIRECT, }, |
1563 | 121061dc | bellard | #endif
|
1564 | ffa65c3b | bellard | { 0, 0, 0, 0 } |
1565 | ffa65c3b | bellard | }; |
1566 | ffa65c3b | bellard | |
1567 | 2ab83ea7 | bellard | #if defined(TARGET_I386)
|
1568 | 6dbad63e | bellard | |
1569 | 6dbad63e | bellard | /* NOTE: there is really one LDT for all the threads */
|
1570 | 6dbad63e | bellard | uint8_t *ldt_table; |
1571 | 6dbad63e | bellard | |
1572 | 53a5960a | pbrook | static int read_ldt(target_ulong ptr, unsigned long bytecount) |
1573 | 6dbad63e | bellard | { |
1574 | 6dbad63e | bellard | int size;
|
1575 | 53a5960a | pbrook | void *p;
|
1576 | 6dbad63e | bellard | |
1577 | 6dbad63e | bellard | if (!ldt_table)
|
1578 | 6dbad63e | bellard | return 0; |
1579 | 6dbad63e | bellard | size = TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE; |
1580 | 6dbad63e | bellard | if (size > bytecount)
|
1581 | 6dbad63e | bellard | size = bytecount; |
1582 | 53a5960a | pbrook | p = lock_user(ptr, size, 0);
|
1583 | 53a5960a | pbrook | /* ??? Shoudl this by byteswapped? */
|
1584 | 53a5960a | pbrook | memcpy(p, ldt_table, size); |
1585 | 53a5960a | pbrook | unlock_user(p, ptr, size); |
1586 | 6dbad63e | bellard | return size;
|
1587 | 6dbad63e | bellard | } |
1588 | 6dbad63e | bellard | |
1589 | 6dbad63e | bellard | /* XXX: add locking support */
|
1590 | 6dbad63e | bellard | static int write_ldt(CPUX86State *env, |
1591 | 53a5960a | pbrook | target_ulong ptr, unsigned long bytecount, int oldmode) |
1592 | 6dbad63e | bellard | { |
1593 | 6dbad63e | bellard | struct target_modify_ldt_ldt_s ldt_info;
|
1594 | 53a5960a | pbrook | struct target_modify_ldt_ldt_s *target_ldt_info;
|
1595 | 6dbad63e | bellard | int seg_32bit, contents, read_exec_only, limit_in_pages;
|
1596 | 6dbad63e | bellard | int seg_not_present, useable;
|
1597 | 6dbad63e | bellard | uint32_t *lp, entry_1, entry_2; |
1598 | 6dbad63e | bellard | |
1599 | 6dbad63e | bellard | if (bytecount != sizeof(ldt_info)) |
1600 | 6dbad63e | bellard | return -EINVAL;
|
1601 | 53a5960a | pbrook | lock_user_struct(target_ldt_info, ptr, 1);
|
1602 | 53a5960a | pbrook | ldt_info.entry_number = tswap32(target_ldt_info->entry_number); |
1603 | 53a5960a | pbrook | ldt_info.base_addr = tswapl(target_ldt_info->base_addr); |
1604 | 53a5960a | pbrook | ldt_info.limit = tswap32(target_ldt_info->limit); |
1605 | 53a5960a | pbrook | ldt_info.flags = tswap32(target_ldt_info->flags); |
1606 | 53a5960a | pbrook | unlock_user_struct(target_ldt_info, ptr, 0);
|
1607 | 6dbad63e | bellard | |
1608 | 6dbad63e | bellard | if (ldt_info.entry_number >= TARGET_LDT_ENTRIES)
|
1609 | 6dbad63e | bellard | return -EINVAL;
|
1610 | 6dbad63e | bellard | seg_32bit = ldt_info.flags & 1;
|
1611 | 6dbad63e | bellard | contents = (ldt_info.flags >> 1) & 3; |
1612 | 6dbad63e | bellard | read_exec_only = (ldt_info.flags >> 3) & 1; |
1613 | 6dbad63e | bellard | limit_in_pages = (ldt_info.flags >> 4) & 1; |
1614 | 6dbad63e | bellard | seg_not_present = (ldt_info.flags >> 5) & 1; |
1615 | 6dbad63e | bellard | useable = (ldt_info.flags >> 6) & 1; |
1616 | 6dbad63e | bellard | |
1617 | 6dbad63e | bellard | if (contents == 3) { |
1618 | 6dbad63e | bellard | if (oldmode)
|
1619 | 6dbad63e | bellard | return -EINVAL;
|
1620 | 6dbad63e | bellard | if (seg_not_present == 0) |
1621 | 6dbad63e | bellard | return -EINVAL;
|
1622 | 6dbad63e | bellard | } |
1623 | 6dbad63e | bellard | /* allocate the LDT */
|
1624 | 6dbad63e | bellard | if (!ldt_table) {
|
1625 | 6dbad63e | bellard | ldt_table = malloc(TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE); |
1626 | 6dbad63e | bellard | if (!ldt_table)
|
1627 | 6dbad63e | bellard | return -ENOMEM;
|
1628 | 6dbad63e | bellard | memset(ldt_table, 0, TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE);
|
1629 | 53a5960a | pbrook | env->ldt.base = h2g(ldt_table); |
1630 | 6dbad63e | bellard | env->ldt.limit = 0xffff;
|
1631 | 6dbad63e | bellard | } |
1632 | 6dbad63e | bellard | |
1633 | 6dbad63e | bellard | /* NOTE: same code as Linux kernel */
|
1634 | 6dbad63e | bellard | /* Allow LDTs to be cleared by the user. */
|
1635 | 6dbad63e | bellard | if (ldt_info.base_addr == 0 && ldt_info.limit == 0) { |
1636 | 6dbad63e | bellard | if (oldmode ||
|
1637 | 6dbad63e | bellard | (contents == 0 &&
|
1638 | 6dbad63e | bellard | read_exec_only == 1 &&
|
1639 | 6dbad63e | bellard | seg_32bit == 0 &&
|
1640 | 6dbad63e | bellard | limit_in_pages == 0 &&
|
1641 | 6dbad63e | bellard | seg_not_present == 1 &&
|
1642 | 6dbad63e | bellard | useable == 0 )) {
|
1643 | 6dbad63e | bellard | entry_1 = 0;
|
1644 | 6dbad63e | bellard | entry_2 = 0;
|
1645 | 6dbad63e | bellard | goto install;
|
1646 | 6dbad63e | bellard | } |
1647 | 6dbad63e | bellard | } |
1648 | 6dbad63e | bellard | |
1649 | 6dbad63e | bellard | entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) | |
1650 | 6dbad63e | bellard | (ldt_info.limit & 0x0ffff);
|
1651 | 6dbad63e | bellard | entry_2 = (ldt_info.base_addr & 0xff000000) |
|
1652 | 6dbad63e | bellard | ((ldt_info.base_addr & 0x00ff0000) >> 16) | |
1653 | 6dbad63e | bellard | (ldt_info.limit & 0xf0000) |
|
1654 | 6dbad63e | bellard | ((read_exec_only ^ 1) << 9) | |
1655 | 6dbad63e | bellard | (contents << 10) |
|
1656 | 6dbad63e | bellard | ((seg_not_present ^ 1) << 15) | |
1657 | 6dbad63e | bellard | (seg_32bit << 22) |
|
1658 | 6dbad63e | bellard | (limit_in_pages << 23) |
|
1659 | 6dbad63e | bellard | 0x7000;
|
1660 | 6dbad63e | bellard | if (!oldmode)
|
1661 | 6dbad63e | bellard | entry_2 |= (useable << 20);
|
1662 | 14ae3ba7 | bellard | |
1663 | 6dbad63e | bellard | /* Install the new entry ... */
|
1664 | 6dbad63e | bellard | install:
|
1665 | 6dbad63e | bellard | lp = (uint32_t *)(ldt_table + (ldt_info.entry_number << 3));
|
1666 | 6dbad63e | bellard | lp[0] = tswap32(entry_1);
|
1667 | 6dbad63e | bellard | lp[1] = tswap32(entry_2);
|
1668 | 6dbad63e | bellard | return 0; |
1669 | 6dbad63e | bellard | } |
1670 | 6dbad63e | bellard | |
1671 | 6dbad63e | bellard | /* specific and weird i386 syscalls */
|
1672 | 53a5960a | pbrook | int do_modify_ldt(CPUX86State *env, int func, target_ulong ptr, unsigned long bytecount) |
1673 | 6dbad63e | bellard | { |
1674 | 6dbad63e | bellard | int ret = -ENOSYS;
|
1675 | 6dbad63e | bellard | |
1676 | 6dbad63e | bellard | switch (func) {
|
1677 | 6dbad63e | bellard | case 0: |
1678 | 6dbad63e | bellard | ret = read_ldt(ptr, bytecount); |
1679 | 6dbad63e | bellard | break;
|
1680 | 6dbad63e | bellard | case 1: |
1681 | 6dbad63e | bellard | ret = write_ldt(env, ptr, bytecount, 1);
|
1682 | 6dbad63e | bellard | break;
|
1683 | 6dbad63e | bellard | case 0x11: |
1684 | 6dbad63e | bellard | ret = write_ldt(env, ptr, bytecount, 0);
|
1685 | 6dbad63e | bellard | break;
|
1686 | 6dbad63e | bellard | } |
1687 | 6dbad63e | bellard | return ret;
|
1688 | 6dbad63e | bellard | } |
1689 | 1b6b029e | bellard | |
1690 | 2ab83ea7 | bellard | #endif /* defined(TARGET_I386) */ |
1691 | 2ab83ea7 | bellard | |
1692 | 1b6b029e | bellard | /* this stack is the equivalent of the kernel stack associated with a
|
1693 | 1b6b029e | bellard | thread/process */
|
1694 | 1b6b029e | bellard | #define NEW_STACK_SIZE 8192 |
1695 | 1b6b029e | bellard | |
1696 | 1b6b029e | bellard | static int clone_func(void *arg) |
1697 | 1b6b029e | bellard | { |
1698 | 2ab83ea7 | bellard | CPUState *env = arg; |
1699 | 1b6b029e | bellard | cpu_loop(env); |
1700 | 1b6b029e | bellard | /* never exits */
|
1701 | 1b6b029e | bellard | return 0; |
1702 | 1b6b029e | bellard | } |
1703 | 1b6b029e | bellard | |
1704 | 2ab83ea7 | bellard | int do_fork(CPUState *env, unsigned int flags, unsigned long newsp) |
1705 | 1b6b029e | bellard | { |
1706 | 1b6b029e | bellard | int ret;
|
1707 | 5cd4393b | bellard | TaskState *ts; |
1708 | 1b6b029e | bellard | uint8_t *new_stack; |
1709 | 2ab83ea7 | bellard | CPUState *new_env; |
1710 | 1b6b029e | bellard | |
1711 | 1b6b029e | bellard | if (flags & CLONE_VM) {
|
1712 | 5cd4393b | bellard | ts = malloc(sizeof(TaskState) + NEW_STACK_SIZE);
|
1713 | 5cd4393b | bellard | memset(ts, 0, sizeof(TaskState)); |
1714 | 5cd4393b | bellard | new_stack = ts->stack; |
1715 | 5cd4393b | bellard | ts->used = 1;
|
1716 | 5cd4393b | bellard | /* add in task state list */
|
1717 | 5cd4393b | bellard | ts->next = first_task_state; |
1718 | 5cd4393b | bellard | first_task_state = ts; |
1719 | 1b6b029e | bellard | /* we create a new CPU instance. */
|
1720 | 2ab83ea7 | bellard | new_env = cpu_init(); |
1721 | 2ab83ea7 | bellard | memcpy(new_env, env, sizeof(CPUState));
|
1722 | 2ab83ea7 | bellard | #if defined(TARGET_I386)
|
1723 | 2ab83ea7 | bellard | if (!newsp)
|
1724 | 2ab83ea7 | bellard | newsp = env->regs[R_ESP]; |
1725 | 1b6b029e | bellard | new_env->regs[R_ESP] = newsp; |
1726 | 1b6b029e | bellard | new_env->regs[R_EAX] = 0;
|
1727 | 2ab83ea7 | bellard | #elif defined(TARGET_ARM)
|
1728 | 2ab83ea7 | bellard | if (!newsp)
|
1729 | 2ab83ea7 | bellard | newsp = env->regs[13];
|
1730 | 2ab83ea7 | bellard | new_env->regs[13] = newsp;
|
1731 | 2ab83ea7 | bellard | new_env->regs[0] = 0; |
1732 | ebc05488 | bellard | #elif defined(TARGET_SPARC)
|
1733 | 48dc41eb | bellard | if (!newsp)
|
1734 | 48dc41eb | bellard | newsp = env->regwptr[22];
|
1735 | 48dc41eb | bellard | new_env->regwptr[22] = newsp;
|
1736 | 48dc41eb | bellard | new_env->regwptr[0] = 0; |
1737 | 48dc41eb | bellard | /* XXXXX */
|
1738 | 67867308 | bellard | printf ("HELPME: %s:%d\n", __FILE__, __LINE__);
|
1739 | e6e5906b | pbrook | #elif defined(TARGET_M68K)
|
1740 | e6e5906b | pbrook | if (!newsp)
|
1741 | e6e5906b | pbrook | newsp = env->aregs[7];
|
1742 | e6e5906b | pbrook | new_env->aregs[7] = newsp;
|
1743 | e6e5906b | pbrook | new_env->dregs[0] = 0; |
1744 | e6e5906b | pbrook | /* ??? is this sufficient? */
|
1745 | 048f6b4d | bellard | #elif defined(TARGET_MIPS)
|
1746 | 048f6b4d | bellard | printf ("HELPME: %s:%d\n", __FILE__, __LINE__);
|
1747 | 67867308 | bellard | #elif defined(TARGET_PPC)
|
1748 | 67867308 | bellard | if (!newsp)
|
1749 | 67867308 | bellard | newsp = env->gpr[1];
|
1750 | 67867308 | bellard | new_env->gpr[1] = newsp;
|
1751 | 67867308 | bellard | { |
1752 | 67867308 | bellard | int i;
|
1753 | 67867308 | bellard | for (i = 7; i < 32; i++) |
1754 | 67867308 | bellard | new_env->gpr[i] = 0;
|
1755 | 67867308 | bellard | } |
1756 | fdf9b3e8 | bellard | #elif defined(TARGET_SH4)
|
1757 | fdf9b3e8 | bellard | if (!newsp)
|
1758 | fdf9b3e8 | bellard | newsp = env->gregs[15];
|
1759 | fdf9b3e8 | bellard | new_env->gregs[15] = newsp;
|
1760 | fdf9b3e8 | bellard | /* XXXXX */
|
1761 | 2ab83ea7 | bellard | #else
|
1762 | 2ab83ea7 | bellard | #error unsupported target CPU
|
1763 | 2ab83ea7 | bellard | #endif
|
1764 | 5cd4393b | bellard | new_env->opaque = ts; |
1765 | 27725c1d | bellard | #ifdef __ia64__
|
1766 | fd4a43e4 | bellard | ret = __clone2(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env); |
1767 | 27725c1d | bellard | #else
|
1768 | 27725c1d | bellard | ret = clone(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env); |
1769 | 27725c1d | bellard | #endif
|
1770 | 1b6b029e | bellard | } else {
|
1771 | 1b6b029e | bellard | /* if no CLONE_VM, we consider it is a fork */
|
1772 | 1b6b029e | bellard | if ((flags & ~CSIGNAL) != 0) |
1773 | 1b6b029e | bellard | return -EINVAL;
|
1774 | 1b6b029e | bellard | ret = fork(); |
1775 | 1b6b029e | bellard | } |
1776 | 1b6b029e | bellard | return ret;
|
1777 | 1b6b029e | bellard | } |
1778 | 1b6b029e | bellard | |
1779 | 53a5960a | pbrook | static long do_fcntl(int fd, int cmd, target_ulong arg) |
1780 | 7775e9ec | bellard | { |
1781 | 7775e9ec | bellard | struct flock fl;
|
1782 | 53a5960a | pbrook | struct target_flock *target_fl;
|
1783 | 43f238d7 | ths | struct flock64 fl64;
|
1784 | 43f238d7 | ths | struct target_flock64 *target_fl64;
|
1785 | 7775e9ec | bellard | long ret;
|
1786 | 53a5960a | pbrook | |
1787 | 7775e9ec | bellard | switch(cmd) {
|
1788 | 7775e9ec | bellard | case TARGET_F_GETLK:
|
1789 | 7775e9ec | bellard | ret = fcntl(fd, cmd, &fl); |
1790 | 7775e9ec | bellard | if (ret == 0) { |
1791 | 53a5960a | pbrook | lock_user_struct(target_fl, arg, 0);
|
1792 | 7775e9ec | bellard | target_fl->l_type = tswap16(fl.l_type); |
1793 | 7775e9ec | bellard | target_fl->l_whence = tswap16(fl.l_whence); |
1794 | 7775e9ec | bellard | target_fl->l_start = tswapl(fl.l_start); |
1795 | 7775e9ec | bellard | target_fl->l_len = tswapl(fl.l_len); |
1796 | 7775e9ec | bellard | target_fl->l_pid = tswapl(fl.l_pid); |
1797 | 53a5960a | pbrook | unlock_user_struct(target_fl, arg, 1);
|
1798 | 7775e9ec | bellard | } |
1799 | 7775e9ec | bellard | break;
|
1800 | 7775e9ec | bellard | |
1801 | 7775e9ec | bellard | case TARGET_F_SETLK:
|
1802 | 7775e9ec | bellard | case TARGET_F_SETLKW:
|
1803 | 53a5960a | pbrook | lock_user_struct(target_fl, arg, 1);
|
1804 | 7775e9ec | bellard | fl.l_type = tswap16(target_fl->l_type); |
1805 | 7775e9ec | bellard | fl.l_whence = tswap16(target_fl->l_whence); |
1806 | 7775e9ec | bellard | fl.l_start = tswapl(target_fl->l_start); |
1807 | 7775e9ec | bellard | fl.l_len = tswapl(target_fl->l_len); |
1808 | 7775e9ec | bellard | fl.l_pid = tswapl(target_fl->l_pid); |
1809 | 53a5960a | pbrook | unlock_user_struct(target_fl, arg, 0);
|
1810 | 7775e9ec | bellard | ret = fcntl(fd, cmd, &fl); |
1811 | 7775e9ec | bellard | break;
|
1812 | 7775e9ec | bellard | |
1813 | 7775e9ec | bellard | case TARGET_F_GETLK64:
|
1814 | 43f238d7 | ths | ret = fcntl(fd, cmd >> 1, &fl64);
|
1815 | 43f238d7 | ths | if (ret == 0) { |
1816 | 43f238d7 | ths | lock_user_struct(target_fl64, arg, 0);
|
1817 | 43f238d7 | ths | target_fl64->l_type = tswap16(fl64.l_type) >> 1;
|
1818 | 43f238d7 | ths | target_fl64->l_whence = tswap16(fl64.l_whence); |
1819 | 43f238d7 | ths | target_fl64->l_start = tswapl(fl64.l_start); |
1820 | 43f238d7 | ths | target_fl64->l_len = tswapl(fl64.l_len); |
1821 | 43f238d7 | ths | target_fl64->l_pid = tswapl(fl64.l_pid); |
1822 | 43f238d7 | ths | unlock_user_struct(target_fl64, arg, 1);
|
1823 | 43f238d7 | ths | } |
1824 | 43f238d7 | ths | break;
|
1825 | 7775e9ec | bellard | case TARGET_F_SETLK64:
|
1826 | 7775e9ec | bellard | case TARGET_F_SETLKW64:
|
1827 | 43f238d7 | ths | lock_user_struct(target_fl64, arg, 1);
|
1828 | 43f238d7 | ths | fl64.l_type = tswap16(target_fl64->l_type) >> 1;
|
1829 | 43f238d7 | ths | fl64.l_whence = tswap16(target_fl64->l_whence); |
1830 | 43f238d7 | ths | fl64.l_start = tswapl(target_fl64->l_start); |
1831 | 43f238d7 | ths | fl64.l_len = tswapl(target_fl64->l_len); |
1832 | 43f238d7 | ths | fl64.l_pid = tswap16(target_fl64->l_pid); |
1833 | 43f238d7 | ths | unlock_user_struct(target_fl64, arg, 0);
|
1834 | 43f238d7 | ths | ret = fcntl(fd, cmd >> 1, &fl64);
|
1835 | 7775e9ec | bellard | break;
|
1836 | 7775e9ec | bellard | |
1837 | ffa65c3b | bellard | case F_GETFL:
|
1838 | ffa65c3b | bellard | ret = fcntl(fd, cmd, arg); |
1839 | ffa65c3b | bellard | ret = host_to_target_bitmask(ret, fcntl_flags_tbl); |
1840 | ffa65c3b | bellard | break;
|
1841 | ffa65c3b | bellard | |
1842 | ffa65c3b | bellard | case F_SETFL:
|
1843 | ffa65c3b | bellard | ret = fcntl(fd, cmd, target_to_host_bitmask(arg, fcntl_flags_tbl)); |
1844 | ffa65c3b | bellard | break;
|
1845 | ffa65c3b | bellard | |
1846 | 7775e9ec | bellard | default:
|
1847 | 7775e9ec | bellard | ret = fcntl(fd, cmd, arg); |
1848 | 7775e9ec | bellard | break;
|
1849 | 7775e9ec | bellard | } |
1850 | 7775e9ec | bellard | return ret;
|
1851 | 7775e9ec | bellard | } |
1852 | 7775e9ec | bellard | |
1853 | 67867308 | bellard | #ifdef USE_UID16
|
1854 | 7775e9ec | bellard | |
1855 | 67867308 | bellard | static inline int high2lowuid(int uid) |
1856 | 67867308 | bellard | { |
1857 | 67867308 | bellard | if (uid > 65535) |
1858 | 67867308 | bellard | return 65534; |
1859 | 67867308 | bellard | else
|
1860 | 67867308 | bellard | return uid;
|
1861 | 67867308 | bellard | } |
1862 | 67867308 | bellard | |
1863 | 67867308 | bellard | static inline int high2lowgid(int gid) |
1864 | 67867308 | bellard | { |
1865 | 67867308 | bellard | if (gid > 65535) |
1866 | 67867308 | bellard | return 65534; |
1867 | 67867308 | bellard | else
|
1868 | 67867308 | bellard | return gid;
|
1869 | 67867308 | bellard | } |
1870 | 67867308 | bellard | |
1871 | 67867308 | bellard | static inline int low2highuid(int uid) |
1872 | 67867308 | bellard | { |
1873 | 67867308 | bellard | if ((int16_t)uid == -1) |
1874 | 67867308 | bellard | return -1; |
1875 | 67867308 | bellard | else
|
1876 | 67867308 | bellard | return uid;
|
1877 | 67867308 | bellard | } |
1878 | 67867308 | bellard | |
1879 | 67867308 | bellard | static inline int low2highgid(int gid) |
1880 | 67867308 | bellard | { |
1881 | 67867308 | bellard | if ((int16_t)gid == -1) |
1882 | 67867308 | bellard | return -1; |
1883 | 67867308 | bellard | else
|
1884 | 67867308 | bellard | return gid;
|
1885 | 67867308 | bellard | } |
1886 | 67867308 | bellard | |
1887 | 67867308 | bellard | #endif /* USE_UID16 */ |
1888 | 1b6b029e | bellard | |
1889 | 31e31b8a | bellard | void syscall_init(void) |
1890 | 31e31b8a | bellard | { |
1891 | 2ab83ea7 | bellard | IOCTLEntry *ie; |
1892 | 2ab83ea7 | bellard | const argtype *arg_type;
|
1893 | 2ab83ea7 | bellard | int size;
|
1894 | 2ab83ea7 | bellard | |
1895 | 31e31b8a | bellard | #define STRUCT(name, list...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def); |
1896 | 31e31b8a | bellard | #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def); |
1897 | 31e31b8a | bellard | #include "syscall_types.h" |
1898 | 31e31b8a | bellard | #undef STRUCT
|
1899 | 31e31b8a | bellard | #undef STRUCT_SPECIAL
|
1900 | 2ab83ea7 | bellard | |
1901 | 2ab83ea7 | bellard | /* we patch the ioctl size if necessary. We rely on the fact that
|
1902 | 2ab83ea7 | bellard | no ioctl has all the bits at '1' in the size field */
|
1903 | 2ab83ea7 | bellard | ie = ioctl_entries; |
1904 | 2ab83ea7 | bellard | while (ie->target_cmd != 0) { |
1905 | 2ab83ea7 | bellard | if (((ie->target_cmd >> TARGET_IOC_SIZESHIFT) & TARGET_IOC_SIZEMASK) ==
|
1906 | 2ab83ea7 | bellard | TARGET_IOC_SIZEMASK) { |
1907 | 2ab83ea7 | bellard | arg_type = ie->arg_type; |
1908 | 2ab83ea7 | bellard | if (arg_type[0] != TYPE_PTR) { |
1909 | 2ab83ea7 | bellard | fprintf(stderr, "cannot patch size for ioctl 0x%x\n",
|
1910 | 2ab83ea7 | bellard | ie->target_cmd); |
1911 | 2ab83ea7 | bellard | exit(1);
|
1912 | 2ab83ea7 | bellard | } |
1913 | 2ab83ea7 | bellard | arg_type++; |
1914 | 2ab83ea7 | bellard | size = thunk_type_size(arg_type, 0);
|
1915 | 2ab83ea7 | bellard | ie->target_cmd = (ie->target_cmd & |
1916 | 2ab83ea7 | bellard | ~(TARGET_IOC_SIZEMASK << TARGET_IOC_SIZESHIFT)) | |
1917 | 2ab83ea7 | bellard | (size << TARGET_IOC_SIZESHIFT); |
1918 | 2ab83ea7 | bellard | } |
1919 | 2ab83ea7 | bellard | /* automatic consistency check if same arch */
|
1920 | 2ab83ea7 | bellard | #if defined(__i386__) && defined(TARGET_I386)
|
1921 | 2ab83ea7 | bellard | if (ie->target_cmd != ie->host_cmd) {
|
1922 | 2ab83ea7 | bellard | fprintf(stderr, "ERROR: ioctl: target=0x%x host=0x%x\n",
|
1923 | 2ab83ea7 | bellard | ie->target_cmd, ie->host_cmd); |
1924 | 2ab83ea7 | bellard | } |
1925 | 2ab83ea7 | bellard | #endif
|
1926 | 2ab83ea7 | bellard | ie++; |
1927 | 2ab83ea7 | bellard | } |
1928 | 31e31b8a | bellard | } |
1929 | c573ff67 | bellard | |
1930 | ce4defa0 | pbrook | static inline uint64_t target_offset64(uint32_t word0, uint32_t word1) |
1931 | ce4defa0 | pbrook | { |
1932 | ce4defa0 | pbrook | #ifdef TARGET_WORDS_BIG_ENDIAN
|
1933 | ce4defa0 | pbrook | return ((uint64_t)word0 << 32) | word1; |
1934 | ce4defa0 | pbrook | #else
|
1935 | ce4defa0 | pbrook | return ((uint64_t)word1 << 32) | word0; |
1936 | ce4defa0 | pbrook | #endif
|
1937 | ce4defa0 | pbrook | } |
1938 | ce4defa0 | pbrook | |
1939 | ce4defa0 | pbrook | #ifdef TARGET_NR_truncate64
|
1940 | ce4defa0 | pbrook | static inline long target_truncate64(void *cpu_env, const char *arg1, |
1941 | ce4defa0 | pbrook | long arg2, long arg3, long arg4) |
1942 | ce4defa0 | pbrook | { |
1943 | ce4defa0 | pbrook | #ifdef TARGET_ARM
|
1944 | ce4defa0 | pbrook | if (((CPUARMState *)cpu_env)->eabi)
|
1945 | ce4defa0 | pbrook | { |
1946 | ce4defa0 | pbrook | arg2 = arg3; |
1947 | ce4defa0 | pbrook | arg3 = arg4; |
1948 | ce4defa0 | pbrook | } |
1949 | ce4defa0 | pbrook | #endif
|
1950 | ce4defa0 | pbrook | return get_errno(truncate64(arg1, target_offset64(arg2, arg3)));
|
1951 | ce4defa0 | pbrook | } |
1952 | ce4defa0 | pbrook | #endif
|
1953 | ce4defa0 | pbrook | |
1954 | ce4defa0 | pbrook | #ifdef TARGET_NR_ftruncate64
|
1955 | ce4defa0 | pbrook | static inline long target_ftruncate64(void *cpu_env, long arg1, long arg2, |
1956 | ce4defa0 | pbrook | long arg3, long arg4) |
1957 | ce4defa0 | pbrook | { |
1958 | ce4defa0 | pbrook | #ifdef TARGET_ARM
|
1959 | ce4defa0 | pbrook | if (((CPUARMState *)cpu_env)->eabi)
|
1960 | ce4defa0 | pbrook | { |
1961 | ce4defa0 | pbrook | arg2 = arg3; |
1962 | ce4defa0 | pbrook | arg3 = arg4; |
1963 | ce4defa0 | pbrook | } |
1964 | ce4defa0 | pbrook | #endif
|
1965 | ce4defa0 | pbrook | return get_errno(ftruncate64(arg1, target_offset64(arg2, arg3)));
|
1966 | ce4defa0 | pbrook | } |
1967 | ce4defa0 | pbrook | #endif
|
1968 | ce4defa0 | pbrook | |
1969 | 53a5960a | pbrook | static inline void target_to_host_timespec(struct timespec *host_ts, |
1970 | 53a5960a | pbrook | target_ulong target_addr) |
1971 | 53a5960a | pbrook | { |
1972 | 53a5960a | pbrook | struct target_timespec *target_ts;
|
1973 | 53a5960a | pbrook | |
1974 | 53a5960a | pbrook | lock_user_struct(target_ts, target_addr, 1);
|
1975 | 53a5960a | pbrook | host_ts->tv_sec = tswapl(target_ts->tv_sec); |
1976 | 53a5960a | pbrook | host_ts->tv_nsec = tswapl(target_ts->tv_nsec); |
1977 | 53a5960a | pbrook | unlock_user_struct(target_ts, target_addr, 0);
|
1978 | 53a5960a | pbrook | } |
1979 | 53a5960a | pbrook | |
1980 | 53a5960a | pbrook | static inline void host_to_target_timespec(target_ulong target_addr, |
1981 | 53a5960a | pbrook | struct timespec *host_ts)
|
1982 | 53a5960a | pbrook | { |
1983 | 53a5960a | pbrook | struct target_timespec *target_ts;
|
1984 | 53a5960a | pbrook | |
1985 | 53a5960a | pbrook | lock_user_struct(target_ts, target_addr, 0);
|
1986 | 53a5960a | pbrook | target_ts->tv_sec = tswapl(host_ts->tv_sec); |
1987 | 53a5960a | pbrook | target_ts->tv_nsec = tswapl(host_ts->tv_nsec); |
1988 | 53a5960a | pbrook | unlock_user_struct(target_ts, target_addr, 1);
|
1989 | 53a5960a | pbrook | } |
1990 | 53a5960a | pbrook | |
1991 | 6dbad63e | bellard | long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3, |
1992 | 31e31b8a | bellard | long arg4, long arg5, long arg6) |
1993 | 31e31b8a | bellard | { |
1994 | 31e31b8a | bellard | long ret;
|
1995 | 31e31b8a | bellard | struct stat st;
|
1996 | 56c8f68f | bellard | struct statfs stfs;
|
1997 | 53a5960a | pbrook | void *p;
|
1998 | 31e31b8a | bellard | |
1999 | 72f03900 | bellard | #ifdef DEBUG
|
2000 | c573ff67 | bellard | gemu_log("syscall %d", num);
|
2001 | 72f03900 | bellard | #endif
|
2002 | 31e31b8a | bellard | switch(num) {
|
2003 | 31e31b8a | bellard | case TARGET_NR_exit:
|
2004 | 7d13299d | bellard | #ifdef HAVE_GPROF
|
2005 | 7d13299d | bellard | _mcleanup(); |
2006 | 7d13299d | bellard | #endif
|
2007 | e9009676 | bellard | gdb_exit(cpu_env, arg1); |
2008 | 1b6b029e | bellard | /* XXX: should free thread stack and CPU env */
|
2009 | 31e31b8a | bellard | _exit(arg1); |
2010 | 31e31b8a | bellard | ret = 0; /* avoid warning */ |
2011 | 31e31b8a | bellard | break;
|
2012 | 31e31b8a | bellard | case TARGET_NR_read:
|
2013 | 53a5960a | pbrook | page_unprotect_range(arg2, arg3); |
2014 | 53a5960a | pbrook | p = lock_user(arg2, arg3, 0);
|
2015 | 53a5960a | pbrook | ret = get_errno(read(arg1, p, arg3)); |
2016 | 53a5960a | pbrook | unlock_user(p, arg2, ret); |
2017 | 31e31b8a | bellard | break;
|
2018 | 31e31b8a | bellard | case TARGET_NR_write:
|
2019 | 53a5960a | pbrook | p = lock_user(arg2, arg3, 1);
|
2020 | 53a5960a | pbrook | ret = get_errno(write(arg1, p, arg3)); |
2021 | 53a5960a | pbrook | unlock_user(p, arg2, 0);
|
2022 | 31e31b8a | bellard | break;
|
2023 | 31e31b8a | bellard | case TARGET_NR_open:
|
2024 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2025 | 53a5960a | pbrook | ret = get_errno(open(path(p), |
2026 | ffa65c3b | bellard | target_to_host_bitmask(arg2, fcntl_flags_tbl), |
2027 | ffa65c3b | bellard | arg3)); |
2028 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2029 | 31e31b8a | bellard | break;
|
2030 | 31e31b8a | bellard | case TARGET_NR_close:
|
2031 | 31e31b8a | bellard | ret = get_errno(close(arg1)); |
2032 | 31e31b8a | bellard | break;
|
2033 | 31e31b8a | bellard | case TARGET_NR_brk:
|
2034 | 53a5960a | pbrook | ret = do_brk(arg1); |
2035 | 31e31b8a | bellard | break;
|
2036 | 31e31b8a | bellard | case TARGET_NR_fork:
|
2037 | 1b6b029e | bellard | ret = get_errno(do_fork(cpu_env, SIGCHLD, 0));
|
2038 | 31e31b8a | bellard | break;
|
2039 | 31e31b8a | bellard | case TARGET_NR_waitpid:
|
2040 | 31e31b8a | bellard | { |
2041 | 53a5960a | pbrook | int status;
|
2042 | 53a5960a | pbrook | ret = get_errno(waitpid(arg1, &status, arg3)); |
2043 | 53a5960a | pbrook | if (!is_error(ret) && arg2)
|
2044 | 53a5960a | pbrook | tput32(arg2, status); |
2045 | 31e31b8a | bellard | } |
2046 | 31e31b8a | bellard | break;
|
2047 | 31e31b8a | bellard | case TARGET_NR_creat:
|
2048 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2049 | 53a5960a | pbrook | ret = get_errno(creat(p, arg2)); |
2050 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2051 | 31e31b8a | bellard | break;
|
2052 | 31e31b8a | bellard | case TARGET_NR_link:
|
2053 | 53a5960a | pbrook | { |
2054 | 53a5960a | pbrook | void * p2;
|
2055 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2056 | 53a5960a | pbrook | p2 = lock_user_string(arg2); |
2057 | 53a5960a | pbrook | ret = get_errno(link(p, p2)); |
2058 | 53a5960a | pbrook | unlock_user(p2, arg2, 0);
|
2059 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2060 | 53a5960a | pbrook | } |
2061 | 31e31b8a | bellard | break;
|
2062 | 31e31b8a | bellard | case TARGET_NR_unlink:
|
2063 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2064 | 53a5960a | pbrook | ret = get_errno(unlink(p)); |
2065 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2066 | 31e31b8a | bellard | break;
|
2067 | 31e31b8a | bellard | case TARGET_NR_execve:
|
2068 | 7854b056 | bellard | { |
2069 | 7854b056 | bellard | char **argp, **envp;
|
2070 | f7341ff4 | bellard | int argc, envc;
|
2071 | 53a5960a | pbrook | target_ulong gp; |
2072 | 53a5960a | pbrook | target_ulong guest_argp; |
2073 | 53a5960a | pbrook | target_ulong guest_envp; |
2074 | 53a5960a | pbrook | target_ulong addr; |
2075 | 7854b056 | bellard | char **q;
|
2076 | 7854b056 | bellard | |
2077 | f7341ff4 | bellard | argc = 0;
|
2078 | 53a5960a | pbrook | guest_argp = arg2; |
2079 | 53a5960a | pbrook | for (gp = guest_argp; tgetl(gp); gp++)
|
2080 | 7854b056 | bellard | argc++; |
2081 | f7341ff4 | bellard | envc = 0;
|
2082 | 53a5960a | pbrook | guest_envp = arg3; |
2083 | 53a5960a | pbrook | for (gp = guest_envp; tgetl(gp); gp++)
|
2084 | 7854b056 | bellard | envc++; |
2085 | 7854b056 | bellard | |
2086 | f7341ff4 | bellard | argp = alloca((argc + 1) * sizeof(void *)); |
2087 | f7341ff4 | bellard | envp = alloca((envc + 1) * sizeof(void *)); |
2088 | 7854b056 | bellard | |
2089 | 53a5960a | pbrook | for (gp = guest_argp, q = argp; ;
|
2090 | 53a5960a | pbrook | gp += sizeof(target_ulong), q++) {
|
2091 | 53a5960a | pbrook | addr = tgetl(gp); |
2092 | 53a5960a | pbrook | if (!addr)
|
2093 | 53a5960a | pbrook | break;
|
2094 | 53a5960a | pbrook | *q = lock_user_string(addr); |
2095 | 53a5960a | pbrook | } |
2096 | f7341ff4 | bellard | *q = NULL;
|
2097 | f7341ff4 | bellard | |
2098 | 53a5960a | pbrook | for (gp = guest_envp, q = envp; ;
|
2099 | 53a5960a | pbrook | gp += sizeof(target_ulong), q++) {
|
2100 | 53a5960a | pbrook | addr = tgetl(gp); |
2101 | 53a5960a | pbrook | if (!addr)
|
2102 | 53a5960a | pbrook | break;
|
2103 | 53a5960a | pbrook | *q = lock_user_string(addr); |
2104 | 53a5960a | pbrook | } |
2105 | f7341ff4 | bellard | *q = NULL;
|
2106 | 7854b056 | bellard | |
2107 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2108 | 53a5960a | pbrook | ret = get_errno(execve(p, argp, envp)); |
2109 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2110 | 53a5960a | pbrook | |
2111 | 53a5960a | pbrook | for (gp = guest_argp, q = argp; *q;
|
2112 | 53a5960a | pbrook | gp += sizeof(target_ulong), q++) {
|
2113 | 53a5960a | pbrook | addr = tgetl(gp); |
2114 | 53a5960a | pbrook | unlock_user(*q, addr, 0);
|
2115 | 53a5960a | pbrook | } |
2116 | 53a5960a | pbrook | for (gp = guest_envp, q = envp; *q;
|
2117 | 53a5960a | pbrook | gp += sizeof(target_ulong), q++) {
|
2118 | 53a5960a | pbrook | addr = tgetl(gp); |
2119 | 53a5960a | pbrook | unlock_user(*q, addr, 0);
|
2120 | 53a5960a | pbrook | } |
2121 | 7854b056 | bellard | } |
2122 | 31e31b8a | bellard | break;
|
2123 | 31e31b8a | bellard | case TARGET_NR_chdir:
|
2124 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2125 | 53a5960a | pbrook | ret = get_errno(chdir(p)); |
2126 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2127 | 31e31b8a | bellard | break;
|
2128 | a315a145 | bellard | #ifdef TARGET_NR_time
|
2129 | 31e31b8a | bellard | case TARGET_NR_time:
|
2130 | 31e31b8a | bellard | { |
2131 | 53a5960a | pbrook | time_t host_time; |
2132 | 53a5960a | pbrook | ret = get_errno(time(&host_time)); |
2133 | 53a5960a | pbrook | if (!is_error(ret) && arg1)
|
2134 | 53a5960a | pbrook | tputl(arg1, host_time); |
2135 | 31e31b8a | bellard | } |
2136 | 31e31b8a | bellard | break;
|
2137 | a315a145 | bellard | #endif
|
2138 | 31e31b8a | bellard | case TARGET_NR_mknod:
|
2139 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2140 | 53a5960a | pbrook | ret = get_errno(mknod(p, arg2, arg3)); |
2141 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2142 | 31e31b8a | bellard | break;
|
2143 | 31e31b8a | bellard | case TARGET_NR_chmod:
|
2144 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2145 | 53a5960a | pbrook | ret = get_errno(chmod(p, arg2)); |
2146 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2147 | 31e31b8a | bellard | break;
|
2148 | ebc05488 | bellard | #ifdef TARGET_NR_break
|
2149 | 31e31b8a | bellard | case TARGET_NR_break:
|
2150 | 31e31b8a | bellard | goto unimplemented;
|
2151 | ebc05488 | bellard | #endif
|
2152 | ebc05488 | bellard | #ifdef TARGET_NR_oldstat
|
2153 | 31e31b8a | bellard | case TARGET_NR_oldstat:
|
2154 | 31e31b8a | bellard | goto unimplemented;
|
2155 | ebc05488 | bellard | #endif
|
2156 | 31e31b8a | bellard | case TARGET_NR_lseek:
|
2157 | 31e31b8a | bellard | ret = get_errno(lseek(arg1, arg2, arg3)); |
2158 | 31e31b8a | bellard | break;
|
2159 | 31e31b8a | bellard | case TARGET_NR_getpid:
|
2160 | 31e31b8a | bellard | ret = get_errno(getpid()); |
2161 | 31e31b8a | bellard | break;
|
2162 | 31e31b8a | bellard | case TARGET_NR_mount:
|
2163 | 31e31b8a | bellard | /* need to look at the data field */
|
2164 | 31e31b8a | bellard | goto unimplemented;
|
2165 | 31e31b8a | bellard | case TARGET_NR_umount:
|
2166 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2167 | 53a5960a | pbrook | ret = get_errno(umount(p)); |
2168 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2169 | 31e31b8a | bellard | break;
|
2170 | 31e31b8a | bellard | case TARGET_NR_stime:
|
2171 | 31e31b8a | bellard | { |
2172 | 53a5960a | pbrook | time_t host_time; |
2173 | 53a5960a | pbrook | host_time = tgetl(arg1); |
2174 | 53a5960a | pbrook | ret = get_errno(stime(&host_time)); |
2175 | 31e31b8a | bellard | } |
2176 | 31e31b8a | bellard | break;
|
2177 | 31e31b8a | bellard | case TARGET_NR_ptrace:
|
2178 | 31e31b8a | bellard | goto unimplemented;
|
2179 | 31e31b8a | bellard | case TARGET_NR_alarm:
|
2180 | 31e31b8a | bellard | ret = alarm(arg1); |
2181 | 31e31b8a | bellard | break;
|
2182 | ebc05488 | bellard | #ifdef TARGET_NR_oldfstat
|
2183 | 31e31b8a | bellard | case TARGET_NR_oldfstat:
|
2184 | 31e31b8a | bellard | goto unimplemented;
|
2185 | ebc05488 | bellard | #endif
|
2186 | 31e31b8a | bellard | case TARGET_NR_pause:
|
2187 | 31e31b8a | bellard | ret = get_errno(pause()); |
2188 | 31e31b8a | bellard | break;
|
2189 | 31e31b8a | bellard | case TARGET_NR_utime:
|
2190 | ebc05488 | bellard | { |
2191 | 53a5960a | pbrook | struct utimbuf tbuf, *host_tbuf;
|
2192 | 53a5960a | pbrook | struct target_utimbuf *target_tbuf;
|
2193 | 53a5960a | pbrook | if (arg2) {
|
2194 | 53a5960a | pbrook | lock_user_struct(target_tbuf, arg2, 1);
|
2195 | 53a5960a | pbrook | tbuf.actime = tswapl(target_tbuf->actime); |
2196 | 53a5960a | pbrook | tbuf.modtime = tswapl(target_tbuf->modtime); |
2197 | 53a5960a | pbrook | unlock_user_struct(target_tbuf, arg2, 0);
|
2198 | 53a5960a | pbrook | host_tbuf = &tbuf; |
2199 | f72e8ff4 | bellard | } else {
|
2200 | 53a5960a | pbrook | host_tbuf = NULL;
|
2201 | f72e8ff4 | bellard | } |
2202 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2203 | 53a5960a | pbrook | ret = get_errno(utime(p, host_tbuf)); |
2204 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2205 | ebc05488 | bellard | } |
2206 | ebc05488 | bellard | break;
|
2207 | 978a66ff | bellard | case TARGET_NR_utimes:
|
2208 | 978a66ff | bellard | { |
2209 | 978a66ff | bellard | struct timeval *tvp, tv[2]; |
2210 | 53a5960a | pbrook | if (arg2) {
|
2211 | 53a5960a | pbrook | target_to_host_timeval(&tv[0], arg2);
|
2212 | 53a5960a | pbrook | target_to_host_timeval(&tv[1],
|
2213 | 53a5960a | pbrook | arg2 + sizeof (struct target_timeval)); |
2214 | 978a66ff | bellard | tvp = tv; |
2215 | 978a66ff | bellard | } else {
|
2216 | 978a66ff | bellard | tvp = NULL;
|
2217 | 978a66ff | bellard | } |
2218 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2219 | 53a5960a | pbrook | ret = get_errno(utimes(p, tvp)); |
2220 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2221 | 978a66ff | bellard | } |
2222 | 978a66ff | bellard | break;
|
2223 | ebc05488 | bellard | #ifdef TARGET_NR_stty
|
2224 | 31e31b8a | bellard | case TARGET_NR_stty:
|
2225 | 31e31b8a | bellard | goto unimplemented;
|
2226 | ebc05488 | bellard | #endif
|
2227 | ebc05488 | bellard | #ifdef TARGET_NR_gtty
|
2228 | 31e31b8a | bellard | case TARGET_NR_gtty:
|
2229 | 31e31b8a | bellard | goto unimplemented;
|
2230 | ebc05488 | bellard | #endif
|
2231 | 31e31b8a | bellard | case TARGET_NR_access:
|
2232 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2233 | 53a5960a | pbrook | ret = get_errno(access(p, arg2)); |
2234 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2235 | 31e31b8a | bellard | break;
|
2236 | 31e31b8a | bellard | case TARGET_NR_nice:
|
2237 | 31e31b8a | bellard | ret = get_errno(nice(arg1)); |
2238 | 31e31b8a | bellard | break;
|
2239 | ebc05488 | bellard | #ifdef TARGET_NR_ftime
|
2240 | 31e31b8a | bellard | case TARGET_NR_ftime:
|
2241 | 31e31b8a | bellard | goto unimplemented;
|
2242 | ebc05488 | bellard | #endif
|
2243 | 31e31b8a | bellard | case TARGET_NR_sync:
|
2244 | 04369ff2 | bellard | sync(); |
2245 | 04369ff2 | bellard | ret = 0;
|
2246 | 31e31b8a | bellard | break;
|
2247 | 31e31b8a | bellard | case TARGET_NR_kill:
|
2248 | 31e31b8a | bellard | ret = get_errno(kill(arg1, arg2)); |
2249 | 31e31b8a | bellard | break;
|
2250 | 31e31b8a | bellard | case TARGET_NR_rename:
|
2251 | 53a5960a | pbrook | { |
2252 | 53a5960a | pbrook | void *p2;
|
2253 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2254 | 53a5960a | pbrook | p2 = lock_user_string(arg2); |
2255 | 53a5960a | pbrook | ret = get_errno(rename(p, p2)); |
2256 | 53a5960a | pbrook | unlock_user(p2, arg2, 0);
|
2257 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2258 | 53a5960a | pbrook | } |
2259 | 31e31b8a | bellard | break;
|
2260 | 31e31b8a | bellard | case TARGET_NR_mkdir:
|
2261 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2262 | 53a5960a | pbrook | ret = get_errno(mkdir(p, arg2)); |
2263 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2264 | 31e31b8a | bellard | break;
|
2265 | 31e31b8a | bellard | case TARGET_NR_rmdir:
|
2266 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2267 | 53a5960a | pbrook | ret = get_errno(rmdir(p)); |
2268 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2269 | 31e31b8a | bellard | break;
|
2270 | 31e31b8a | bellard | case TARGET_NR_dup:
|
2271 | 31e31b8a | bellard | ret = get_errno(dup(arg1)); |
2272 | 31e31b8a | bellard | break;
|
2273 | 31e31b8a | bellard | case TARGET_NR_pipe:
|
2274 | 31e31b8a | bellard | { |
2275 | 53a5960a | pbrook | int host_pipe[2]; |
2276 | 53a5960a | pbrook | ret = get_errno(pipe(host_pipe)); |
2277 | 31e31b8a | bellard | if (!is_error(ret)) {
|
2278 | 53a5960a | pbrook | tput32(arg1, host_pipe[0]);
|
2279 | 53a5960a | pbrook | tput32(arg1 + 4, host_pipe[1]); |
2280 | 31e31b8a | bellard | } |
2281 | 31e31b8a | bellard | } |
2282 | 31e31b8a | bellard | break;
|
2283 | 31e31b8a | bellard | case TARGET_NR_times:
|
2284 | 32f36bce | bellard | { |
2285 | 53a5960a | pbrook | struct target_tms *tmsp;
|
2286 | 32f36bce | bellard | struct tms tms;
|
2287 | 32f36bce | bellard | ret = get_errno(times(&tms)); |
2288 | 53a5960a | pbrook | if (arg1) {
|
2289 | 53a5960a | pbrook | tmsp = lock_user(arg1, sizeof(struct target_tms), 0); |
2290 | c596ed17 | bellard | tmsp->tms_utime = tswapl(host_to_target_clock_t(tms.tms_utime)); |
2291 | c596ed17 | bellard | tmsp->tms_stime = tswapl(host_to_target_clock_t(tms.tms_stime)); |
2292 | c596ed17 | bellard | tmsp->tms_cutime = tswapl(host_to_target_clock_t(tms.tms_cutime)); |
2293 | c596ed17 | bellard | tmsp->tms_cstime = tswapl(host_to_target_clock_t(tms.tms_cstime)); |
2294 | 32f36bce | bellard | } |
2295 | c596ed17 | bellard | if (!is_error(ret))
|
2296 | c596ed17 | bellard | ret = host_to_target_clock_t(ret); |
2297 | 32f36bce | bellard | } |
2298 | 32f36bce | bellard | break;
|
2299 | ebc05488 | bellard | #ifdef TARGET_NR_prof
|
2300 | 31e31b8a | bellard | case TARGET_NR_prof:
|
2301 | 31e31b8a | bellard | goto unimplemented;
|
2302 | ebc05488 | bellard | #endif
|
2303 | 31e31b8a | bellard | case TARGET_NR_signal:
|
2304 | 31e31b8a | bellard | goto unimplemented;
|
2305 | 67867308 | bellard | |
2306 | 31e31b8a | bellard | case TARGET_NR_acct:
|
2307 | 24836689 | pbrook | p = lock_user_string(arg1); |
2308 | 24836689 | pbrook | ret = get_errno(acct(path(p))); |
2309 | 24836689 | pbrook | unlock_user(p, arg1, 0);
|
2310 | 24836689 | pbrook | break;
|
2311 | 31e31b8a | bellard | case TARGET_NR_umount2:
|
2312 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2313 | 53a5960a | pbrook | ret = get_errno(umount2(p, arg2)); |
2314 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2315 | 31e31b8a | bellard | break;
|
2316 | ebc05488 | bellard | #ifdef TARGET_NR_lock
|
2317 | 31e31b8a | bellard | case TARGET_NR_lock:
|
2318 | 31e31b8a | bellard | goto unimplemented;
|
2319 | ebc05488 | bellard | #endif
|
2320 | 31e31b8a | bellard | case TARGET_NR_ioctl:
|
2321 | 31e31b8a | bellard | ret = do_ioctl(arg1, arg2, arg3); |
2322 | 31e31b8a | bellard | break;
|
2323 | 31e31b8a | bellard | case TARGET_NR_fcntl:
|
2324 | 7775e9ec | bellard | ret = get_errno(do_fcntl(arg1, arg2, arg3)); |
2325 | 31e31b8a | bellard | break;
|
2326 | ebc05488 | bellard | #ifdef TARGET_NR_mpx
|
2327 | 31e31b8a | bellard | case TARGET_NR_mpx:
|
2328 | 31e31b8a | bellard | goto unimplemented;
|
2329 | ebc05488 | bellard | #endif
|
2330 | 31e31b8a | bellard | case TARGET_NR_setpgid:
|
2331 | 31e31b8a | bellard | ret = get_errno(setpgid(arg1, arg2)); |
2332 | 31e31b8a | bellard | break;
|
2333 | ebc05488 | bellard | #ifdef TARGET_NR_ulimit
|
2334 | 31e31b8a | bellard | case TARGET_NR_ulimit:
|
2335 | 31e31b8a | bellard | goto unimplemented;
|
2336 | ebc05488 | bellard | #endif
|
2337 | ebc05488 | bellard | #ifdef TARGET_NR_oldolduname
|
2338 | 31e31b8a | bellard | case TARGET_NR_oldolduname:
|
2339 | 31e31b8a | bellard | goto unimplemented;
|
2340 | ebc05488 | bellard | #endif
|
2341 | 31e31b8a | bellard | case TARGET_NR_umask:
|
2342 | 31e31b8a | bellard | ret = get_errno(umask(arg1)); |
2343 | 31e31b8a | bellard | break;
|
2344 | 31e31b8a | bellard | case TARGET_NR_chroot:
|
2345 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2346 | 53a5960a | pbrook | ret = get_errno(chroot(p)); |
2347 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2348 | 31e31b8a | bellard | break;
|
2349 | 31e31b8a | bellard | case TARGET_NR_ustat:
|
2350 | 31e31b8a | bellard | goto unimplemented;
|
2351 | 31e31b8a | bellard | case TARGET_NR_dup2:
|
2352 | 31e31b8a | bellard | ret = get_errno(dup2(arg1, arg2)); |
2353 | 31e31b8a | bellard | break;
|
2354 | 31e31b8a | bellard | case TARGET_NR_getppid:
|
2355 | 31e31b8a | bellard | ret = get_errno(getppid()); |
2356 | 31e31b8a | bellard | break;
|
2357 | 31e31b8a | bellard | case TARGET_NR_getpgrp:
|
2358 | 31e31b8a | bellard | ret = get_errno(getpgrp()); |
2359 | 31e31b8a | bellard | break;
|
2360 | 31e31b8a | bellard | case TARGET_NR_setsid:
|
2361 | 31e31b8a | bellard | ret = get_errno(setsid()); |
2362 | 31e31b8a | bellard | break;
|
2363 | 31e31b8a | bellard | case TARGET_NR_sigaction:
|
2364 | 31e31b8a | bellard | { |
2365 | 106ec879 | bellard | #if !defined(TARGET_MIPS)
|
2366 | 53a5960a | pbrook | struct target_old_sigaction *old_act;
|
2367 | 66fb9763 | bellard | struct target_sigaction act, oact, *pact;
|
2368 | 53a5960a | pbrook | if (arg2) {
|
2369 | 53a5960a | pbrook | lock_user_struct(old_act, arg2, 1);
|
2370 | 66fb9763 | bellard | act._sa_handler = old_act->_sa_handler; |
2371 | 66fb9763 | bellard | target_siginitset(&act.sa_mask, old_act->sa_mask); |
2372 | 66fb9763 | bellard | act.sa_flags = old_act->sa_flags; |
2373 | 66fb9763 | bellard | act.sa_restorer = old_act->sa_restorer; |
2374 | 53a5960a | pbrook | unlock_user_struct(old_act, arg2, 0);
|
2375 | 66fb9763 | bellard | pact = &act; |
2376 | 66fb9763 | bellard | } else {
|
2377 | 66fb9763 | bellard | pact = NULL;
|
2378 | 66fb9763 | bellard | } |
2379 | 66fb9763 | bellard | ret = get_errno(do_sigaction(arg1, pact, &oact)); |
2380 | 53a5960a | pbrook | if (!is_error(ret) && arg3) {
|
2381 | 53a5960a | pbrook | lock_user_struct(old_act, arg3, 0);
|
2382 | 53a5960a | pbrook | old_act->_sa_handler = oact._sa_handler; |
2383 | 53a5960a | pbrook | old_act->sa_mask = oact.sa_mask.sig[0];
|
2384 | 53a5960a | pbrook | old_act->sa_flags = oact.sa_flags; |
2385 | 53a5960a | pbrook | old_act->sa_restorer = oact.sa_restorer; |
2386 | 53a5960a | pbrook | unlock_user_struct(old_act, arg3, 1);
|
2387 | 66fb9763 | bellard | } |
2388 | 106ec879 | bellard | #else
|
2389 | 106ec879 | bellard | struct target_sigaction act, oact, *pact, *old_act;
|
2390 | 106ec879 | bellard | |
2391 | 106ec879 | bellard | if (arg2) {
|
2392 | 106ec879 | bellard | lock_user_struct(old_act, arg2, 1);
|
2393 | 106ec879 | bellard | act._sa_handler = old_act->_sa_handler; |
2394 | 106ec879 | bellard | target_siginitset(&act.sa_mask, old_act->sa_mask.sig[0]);
|
2395 | 106ec879 | bellard | act.sa_flags = old_act->sa_flags; |
2396 | 106ec879 | bellard | unlock_user_struct(old_act, arg2, 0);
|
2397 | 106ec879 | bellard | pact = &act; |
2398 | 106ec879 | bellard | } else {
|
2399 | 106ec879 | bellard | pact = NULL;
|
2400 | 106ec879 | bellard | } |
2401 | 106ec879 | bellard | |
2402 | 106ec879 | bellard | ret = get_errno(do_sigaction(arg1, pact, &oact)); |
2403 | 106ec879 | bellard | |
2404 | 106ec879 | bellard | if (!is_error(ret) && arg3) {
|
2405 | 106ec879 | bellard | lock_user_struct(old_act, arg3, 0);
|
2406 | 106ec879 | bellard | old_act->_sa_handler = oact._sa_handler; |
2407 | 106ec879 | bellard | old_act->sa_flags = oact.sa_flags; |
2408 | 106ec879 | bellard | old_act->sa_mask.sig[0] = oact.sa_mask.sig[0]; |
2409 | 106ec879 | bellard | old_act->sa_mask.sig[1] = 0; |
2410 | 106ec879 | bellard | old_act->sa_mask.sig[2] = 0; |
2411 | 106ec879 | bellard | old_act->sa_mask.sig[3] = 0; |
2412 | 106ec879 | bellard | unlock_user_struct(old_act, arg3, 1);
|
2413 | 106ec879 | bellard | } |
2414 | 106ec879 | bellard | #endif
|
2415 | 31e31b8a | bellard | } |
2416 | 31e31b8a | bellard | break;
|
2417 | 66fb9763 | bellard | case TARGET_NR_rt_sigaction:
|
2418 | 53a5960a | pbrook | { |
2419 | 53a5960a | pbrook | struct target_sigaction *act;
|
2420 | 53a5960a | pbrook | struct target_sigaction *oact;
|
2421 | 53a5960a | pbrook | |
2422 | 53a5960a | pbrook | if (arg2)
|
2423 | 53a5960a | pbrook | lock_user_struct(act, arg2, 1);
|
2424 | 53a5960a | pbrook | else
|
2425 | 53a5960a | pbrook | act = NULL;
|
2426 | 53a5960a | pbrook | if (arg3)
|
2427 | 53a5960a | pbrook | lock_user_struct(oact, arg3, 0);
|
2428 | 53a5960a | pbrook | else
|
2429 | 53a5960a | pbrook | oact = NULL;
|
2430 | 53a5960a | pbrook | ret = get_errno(do_sigaction(arg1, act, oact)); |
2431 | 53a5960a | pbrook | if (arg2)
|
2432 | 53a5960a | pbrook | unlock_user_struct(act, arg2, 0);
|
2433 | 53a5960a | pbrook | if (arg3)
|
2434 | 53a5960a | pbrook | unlock_user_struct(oact, arg3, 1);
|
2435 | 53a5960a | pbrook | } |
2436 | 66fb9763 | bellard | break;
|
2437 | 31e31b8a | bellard | case TARGET_NR_sgetmask:
|
2438 | 66fb9763 | bellard | { |
2439 | 66fb9763 | bellard | sigset_t cur_set; |
2440 | 66fb9763 | bellard | target_ulong target_set; |
2441 | 66fb9763 | bellard | sigprocmask(0, NULL, &cur_set); |
2442 | 66fb9763 | bellard | host_to_target_old_sigset(&target_set, &cur_set); |
2443 | 66fb9763 | bellard | ret = target_set; |
2444 | 66fb9763 | bellard | } |
2445 | 66fb9763 | bellard | break;
|
2446 | 31e31b8a | bellard | case TARGET_NR_ssetmask:
|
2447 | 66fb9763 | bellard | { |
2448 | 66fb9763 | bellard | sigset_t set, oset, cur_set; |
2449 | 66fb9763 | bellard | target_ulong target_set = arg1; |
2450 | 66fb9763 | bellard | sigprocmask(0, NULL, &cur_set); |
2451 | 66fb9763 | bellard | target_to_host_old_sigset(&set, &target_set); |
2452 | 66fb9763 | bellard | sigorset(&set, &set, &cur_set); |
2453 | 66fb9763 | bellard | sigprocmask(SIG_SETMASK, &set, &oset); |
2454 | 66fb9763 | bellard | host_to_target_old_sigset(&target_set, &oset); |
2455 | 66fb9763 | bellard | ret = target_set; |
2456 | 66fb9763 | bellard | } |
2457 | 66fb9763 | bellard | break;
|
2458 | 66fb9763 | bellard | case TARGET_NR_sigprocmask:
|
2459 | 66fb9763 | bellard | { |
2460 | 66fb9763 | bellard | int how = arg1;
|
2461 | 66fb9763 | bellard | sigset_t set, oldset, *set_ptr; |
2462 | 66fb9763 | bellard | |
2463 | 53a5960a | pbrook | if (arg2) {
|
2464 | 66fb9763 | bellard | switch(how) {
|
2465 | 66fb9763 | bellard | case TARGET_SIG_BLOCK:
|
2466 | 66fb9763 | bellard | how = SIG_BLOCK; |
2467 | 66fb9763 | bellard | break;
|
2468 | 66fb9763 | bellard | case TARGET_SIG_UNBLOCK:
|
2469 | 66fb9763 | bellard | how = SIG_UNBLOCK; |
2470 | 66fb9763 | bellard | break;
|
2471 | 66fb9763 | bellard | case TARGET_SIG_SETMASK:
|
2472 | 66fb9763 | bellard | how = SIG_SETMASK; |
2473 | 66fb9763 | bellard | break;
|
2474 | 66fb9763 | bellard | default:
|
2475 | 66fb9763 | bellard | ret = -EINVAL; |
2476 | 66fb9763 | bellard | goto fail;
|
2477 | 66fb9763 | bellard | } |
2478 | 53a5960a | pbrook | p = lock_user(arg2, sizeof(target_sigset_t), 1); |
2479 | 53a5960a | pbrook | target_to_host_old_sigset(&set, p); |
2480 | 53a5960a | pbrook | unlock_user(p, arg2, 0);
|
2481 | 66fb9763 | bellard | set_ptr = &set; |
2482 | 66fb9763 | bellard | } else {
|
2483 | 66fb9763 | bellard | how = 0;
|
2484 | 66fb9763 | bellard | set_ptr = NULL;
|
2485 | 66fb9763 | bellard | } |
2486 | 66fb9763 | bellard | ret = get_errno(sigprocmask(arg1, set_ptr, &oldset)); |
2487 | 53a5960a | pbrook | if (!is_error(ret) && arg3) {
|
2488 | 53a5960a | pbrook | p = lock_user(arg3, sizeof(target_sigset_t), 0); |
2489 | 53a5960a | pbrook | host_to_target_old_sigset(p, &oldset); |
2490 | 53a5960a | pbrook | unlock_user(p, arg3, sizeof(target_sigset_t));
|
2491 | 66fb9763 | bellard | } |
2492 | 66fb9763 | bellard | } |
2493 | 66fb9763 | bellard | break;
|
2494 | 66fb9763 | bellard | case TARGET_NR_rt_sigprocmask:
|
2495 | 66fb9763 | bellard | { |
2496 | 66fb9763 | bellard | int how = arg1;
|
2497 | 66fb9763 | bellard | sigset_t set, oldset, *set_ptr; |
2498 | 66fb9763 | bellard | |
2499 | 53a5960a | pbrook | if (arg2) {
|
2500 | 66fb9763 | bellard | switch(how) {
|
2501 | 66fb9763 | bellard | case TARGET_SIG_BLOCK:
|
2502 | 66fb9763 | bellard | how = SIG_BLOCK; |
2503 | 66fb9763 | bellard | break;
|
2504 | 66fb9763 | bellard | case TARGET_SIG_UNBLOCK:
|
2505 | 66fb9763 | bellard | how = SIG_UNBLOCK; |
2506 | 66fb9763 | bellard | break;
|
2507 | 66fb9763 | bellard | case TARGET_SIG_SETMASK:
|
2508 | 66fb9763 | bellard | how = SIG_SETMASK; |
2509 | 66fb9763 | bellard | break;
|
2510 | 66fb9763 | bellard | default:
|
2511 | 66fb9763 | bellard | ret = -EINVAL; |
2512 | 66fb9763 | bellard | goto fail;
|
2513 | 66fb9763 | bellard | } |
2514 | 53a5960a | pbrook | p = lock_user(arg2, sizeof(target_sigset_t), 1); |
2515 | 53a5960a | pbrook | target_to_host_sigset(&set, p); |
2516 | 53a5960a | pbrook | unlock_user(p, arg2, 0);
|
2517 | 66fb9763 | bellard | set_ptr = &set; |
2518 | 66fb9763 | bellard | } else {
|
2519 | 66fb9763 | bellard | how = 0;
|
2520 | 66fb9763 | bellard | set_ptr = NULL;
|
2521 | 66fb9763 | bellard | } |
2522 | 66fb9763 | bellard | ret = get_errno(sigprocmask(how, set_ptr, &oldset)); |
2523 | 53a5960a | pbrook | if (!is_error(ret) && arg3) {
|
2524 | 53a5960a | pbrook | p = lock_user(arg3, sizeof(target_sigset_t), 0); |
2525 | 53a5960a | pbrook | host_to_target_sigset(p, &oldset); |
2526 | 53a5960a | pbrook | unlock_user(p, arg3, sizeof(target_sigset_t));
|
2527 | 66fb9763 | bellard | } |
2528 | 66fb9763 | bellard | } |
2529 | 66fb9763 | bellard | break;
|
2530 | 66fb9763 | bellard | case TARGET_NR_sigpending:
|
2531 | 66fb9763 | bellard | { |
2532 | 66fb9763 | bellard | sigset_t set; |
2533 | 66fb9763 | bellard | ret = get_errno(sigpending(&set)); |
2534 | 66fb9763 | bellard | if (!is_error(ret)) {
|
2535 | 53a5960a | pbrook | p = lock_user(arg1, sizeof(target_sigset_t), 0); |
2536 | 53a5960a | pbrook | host_to_target_old_sigset(p, &set); |
2537 | 53a5960a | pbrook | unlock_user(p, arg1, sizeof(target_sigset_t));
|
2538 | 66fb9763 | bellard | } |
2539 | 66fb9763 | bellard | } |
2540 | 66fb9763 | bellard | break;
|
2541 | 66fb9763 | bellard | case TARGET_NR_rt_sigpending:
|
2542 | 66fb9763 | bellard | { |
2543 | 66fb9763 | bellard | sigset_t set; |
2544 | 66fb9763 | bellard | ret = get_errno(sigpending(&set)); |
2545 | 66fb9763 | bellard | if (!is_error(ret)) {
|
2546 | 53a5960a | pbrook | p = lock_user(arg1, sizeof(target_sigset_t), 0); |
2547 | 53a5960a | pbrook | host_to_target_sigset(p, &set); |
2548 | 53a5960a | pbrook | unlock_user(p, arg1, sizeof(target_sigset_t));
|
2549 | 66fb9763 | bellard | } |
2550 | 66fb9763 | bellard | } |
2551 | 66fb9763 | bellard | break;
|
2552 | 66fb9763 | bellard | case TARGET_NR_sigsuspend:
|
2553 | 66fb9763 | bellard | { |
2554 | 66fb9763 | bellard | sigset_t set; |
2555 | 53a5960a | pbrook | p = lock_user(arg1, sizeof(target_sigset_t), 1); |
2556 | 53a5960a | pbrook | target_to_host_old_sigset(&set, p); |
2557 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2558 | 66fb9763 | bellard | ret = get_errno(sigsuspend(&set)); |
2559 | 66fb9763 | bellard | } |
2560 | 66fb9763 | bellard | break;
|
2561 | 66fb9763 | bellard | case TARGET_NR_rt_sigsuspend:
|
2562 | 66fb9763 | bellard | { |
2563 | 66fb9763 | bellard | sigset_t set; |
2564 | 53a5960a | pbrook | p = lock_user(arg1, sizeof(target_sigset_t), 1); |
2565 | 53a5960a | pbrook | target_to_host_sigset(&set, p); |
2566 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2567 | 66fb9763 | bellard | ret = get_errno(sigsuspend(&set)); |
2568 | 66fb9763 | bellard | } |
2569 | 66fb9763 | bellard | break;
|
2570 | 66fb9763 | bellard | case TARGET_NR_rt_sigtimedwait:
|
2571 | 66fb9763 | bellard | { |
2572 | 66fb9763 | bellard | sigset_t set; |
2573 | 66fb9763 | bellard | struct timespec uts, *puts;
|
2574 | 66fb9763 | bellard | siginfo_t uinfo; |
2575 | 66fb9763 | bellard | |
2576 | 53a5960a | pbrook | p = lock_user(arg1, sizeof(target_sigset_t), 1); |
2577 | 53a5960a | pbrook | target_to_host_sigset(&set, p); |
2578 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2579 | 53a5960a | pbrook | if (arg3) {
|
2580 | 66fb9763 | bellard | puts = &uts; |
2581 | 53a5960a | pbrook | target_to_host_timespec(puts, arg3); |
2582 | 66fb9763 | bellard | } else {
|
2583 | 66fb9763 | bellard | puts = NULL;
|
2584 | 66fb9763 | bellard | } |
2585 | 66fb9763 | bellard | ret = get_errno(sigtimedwait(&set, &uinfo, puts)); |
2586 | 53a5960a | pbrook | if (!is_error(ret) && arg2) {
|
2587 | 53a5960a | pbrook | p = lock_user(arg2, sizeof(target_sigset_t), 0); |
2588 | 53a5960a | pbrook | host_to_target_siginfo(p, &uinfo); |
2589 | 53a5960a | pbrook | unlock_user(p, arg2, sizeof(target_sigset_t));
|
2590 | 66fb9763 | bellard | } |
2591 | 66fb9763 | bellard | } |
2592 | 66fb9763 | bellard | break;
|
2593 | 66fb9763 | bellard | case TARGET_NR_rt_sigqueueinfo:
|
2594 | 66fb9763 | bellard | { |
2595 | 66fb9763 | bellard | siginfo_t uinfo; |
2596 | 53a5960a | pbrook | p = lock_user(arg3, sizeof(target_sigset_t), 1); |
2597 | 53a5960a | pbrook | target_to_host_siginfo(&uinfo, p); |
2598 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2599 | 66fb9763 | bellard | ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, &uinfo)); |
2600 | 66fb9763 | bellard | } |
2601 | 66fb9763 | bellard | break;
|
2602 | 66fb9763 | bellard | case TARGET_NR_sigreturn:
|
2603 | 66fb9763 | bellard | /* NOTE: ret is eax, so not transcoding must be done */
|
2604 | 66fb9763 | bellard | ret = do_sigreturn(cpu_env); |
2605 | 66fb9763 | bellard | break;
|
2606 | 66fb9763 | bellard | case TARGET_NR_rt_sigreturn:
|
2607 | 66fb9763 | bellard | /* NOTE: ret is eax, so not transcoding must be done */
|
2608 | 66fb9763 | bellard | ret = do_rt_sigreturn(cpu_env); |
2609 | 66fb9763 | bellard | break;
|
2610 | 31e31b8a | bellard | case TARGET_NR_sethostname:
|
2611 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2612 | 53a5960a | pbrook | ret = get_errno(sethostname(p, arg2)); |
2613 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2614 | 31e31b8a | bellard | break;
|
2615 | 31e31b8a | bellard | case TARGET_NR_setrlimit:
|
2616 | 9de5e440 | bellard | { |
2617 | 9de5e440 | bellard | /* XXX: convert resource ? */
|
2618 | 9de5e440 | bellard | int resource = arg1;
|
2619 | 53a5960a | pbrook | struct target_rlimit *target_rlim;
|
2620 | 9de5e440 | bellard | struct rlimit rlim;
|
2621 | 53a5960a | pbrook | lock_user_struct(target_rlim, arg2, 1);
|
2622 | 9de5e440 | bellard | rlim.rlim_cur = tswapl(target_rlim->rlim_cur); |
2623 | 9de5e440 | bellard | rlim.rlim_max = tswapl(target_rlim->rlim_max); |
2624 | 53a5960a | pbrook | unlock_user_struct(target_rlim, arg2, 0);
|
2625 | 9de5e440 | bellard | ret = get_errno(setrlimit(resource, &rlim)); |
2626 | 9de5e440 | bellard | } |
2627 | 9de5e440 | bellard | break;
|
2628 | 31e31b8a | bellard | case TARGET_NR_getrlimit:
|
2629 | 9de5e440 | bellard | { |
2630 | 9de5e440 | bellard | /* XXX: convert resource ? */
|
2631 | 9de5e440 | bellard | int resource = arg1;
|
2632 | 53a5960a | pbrook | struct target_rlimit *target_rlim;
|
2633 | 9de5e440 | bellard | struct rlimit rlim;
|
2634 | 9de5e440 | bellard | |
2635 | 9de5e440 | bellard | ret = get_errno(getrlimit(resource, &rlim)); |
2636 | 9de5e440 | bellard | if (!is_error(ret)) {
|
2637 | 53a5960a | pbrook | lock_user_struct(target_rlim, arg2, 0);
|
2638 | 53a5960a | pbrook | rlim.rlim_cur = tswapl(target_rlim->rlim_cur); |
2639 | 53a5960a | pbrook | rlim.rlim_max = tswapl(target_rlim->rlim_max); |
2640 | 53a5960a | pbrook | unlock_user_struct(target_rlim, arg2, 1);
|
2641 | 9de5e440 | bellard | } |
2642 | 9de5e440 | bellard | } |
2643 | 9de5e440 | bellard | break;
|
2644 | 31e31b8a | bellard | case TARGET_NR_getrusage:
|
2645 | b409186b | bellard | { |
2646 | b409186b | bellard | struct rusage rusage;
|
2647 | b409186b | bellard | ret = get_errno(getrusage(arg1, &rusage)); |
2648 | b409186b | bellard | if (!is_error(ret)) {
|
2649 | 53a5960a | pbrook | host_to_target_rusage(arg2, &rusage); |
2650 | b409186b | bellard | } |
2651 | b409186b | bellard | } |
2652 | b409186b | bellard | break;
|
2653 | 31e31b8a | bellard | case TARGET_NR_gettimeofday:
|
2654 | 31e31b8a | bellard | { |
2655 | 31e31b8a | bellard | struct timeval tv;
|
2656 | 31e31b8a | bellard | ret = get_errno(gettimeofday(&tv, NULL));
|
2657 | 31e31b8a | bellard | if (!is_error(ret)) {
|
2658 | 53a5960a | pbrook | host_to_target_timeval(arg1, &tv); |
2659 | 31e31b8a | bellard | } |
2660 | 31e31b8a | bellard | } |
2661 | 31e31b8a | bellard | break;
|
2662 | 31e31b8a | bellard | case TARGET_NR_settimeofday:
|
2663 | 31e31b8a | bellard | { |
2664 | 31e31b8a | bellard | struct timeval tv;
|
2665 | 53a5960a | pbrook | target_to_host_timeval(&tv, arg1); |
2666 | 31e31b8a | bellard | ret = get_errno(settimeofday(&tv, NULL));
|
2667 | 31e31b8a | bellard | } |
2668 | 31e31b8a | bellard | break;
|
2669 | 048f6b4d | bellard | #ifdef TARGET_NR_select
|
2670 | 31e31b8a | bellard | case TARGET_NR_select:
|
2671 | f2674e31 | bellard | { |
2672 | 53a5960a | pbrook | struct target_sel_arg_struct *sel;
|
2673 | 53a5960a | pbrook | target_ulong inp, outp, exp, tvp; |
2674 | 53a5960a | pbrook | long nsel;
|
2675 | 53a5960a | pbrook | |
2676 | 53a5960a | pbrook | lock_user_struct(sel, arg1, 1);
|
2677 | 53a5960a | pbrook | nsel = tswapl(sel->n); |
2678 | 53a5960a | pbrook | inp = tswapl(sel->inp); |
2679 | 53a5960a | pbrook | outp = tswapl(sel->outp); |
2680 | 53a5960a | pbrook | exp = tswapl(sel->exp); |
2681 | 53a5960a | pbrook | tvp = tswapl(sel->tvp); |
2682 | 53a5960a | pbrook | unlock_user_struct(sel, arg1, 0);
|
2683 | 53a5960a | pbrook | ret = do_select(nsel, inp, outp, exp, tvp); |
2684 | f2674e31 | bellard | } |
2685 | f2674e31 | bellard | break;
|
2686 | 048f6b4d | bellard | #endif
|
2687 | 31e31b8a | bellard | case TARGET_NR_symlink:
|
2688 | 53a5960a | pbrook | { |
2689 | 53a5960a | pbrook | void *p2;
|
2690 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2691 | 53a5960a | pbrook | p2 = lock_user_string(arg2); |
2692 | 53a5960a | pbrook | ret = get_errno(symlink(p, p2)); |
2693 | 53a5960a | pbrook | unlock_user(p2, arg2, 0);
|
2694 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2695 | 53a5960a | pbrook | } |
2696 | 31e31b8a | bellard | break;
|
2697 | ebc05488 | bellard | #ifdef TARGET_NR_oldlstat
|
2698 | 31e31b8a | bellard | case TARGET_NR_oldlstat:
|
2699 | 31e31b8a | bellard | goto unimplemented;
|
2700 | ebc05488 | bellard | #endif
|
2701 | 31e31b8a | bellard | case TARGET_NR_readlink:
|
2702 | 53a5960a | pbrook | { |
2703 | 53a5960a | pbrook | void *p2;
|
2704 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2705 | 53a5960a | pbrook | p2 = lock_user(arg2, arg3, 0);
|
2706 | 53a5960a | pbrook | ret = get_errno(readlink(path(p), p2, arg3)); |
2707 | 53a5960a | pbrook | unlock_user(p2, arg2, ret); |
2708 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2709 | 53a5960a | pbrook | } |
2710 | 31e31b8a | bellard | break;
|
2711 | 31e31b8a | bellard | case TARGET_NR_uselib:
|
2712 | 31e31b8a | bellard | goto unimplemented;
|
2713 | 31e31b8a | bellard | case TARGET_NR_swapon:
|
2714 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2715 | 53a5960a | pbrook | ret = get_errno(swapon(p, arg2)); |
2716 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2717 | 31e31b8a | bellard | break;
|
2718 | 31e31b8a | bellard | case TARGET_NR_reboot:
|
2719 | 31e31b8a | bellard | goto unimplemented;
|
2720 | 31e31b8a | bellard | case TARGET_NR_readdir:
|
2721 | 31e31b8a | bellard | goto unimplemented;
|
2722 | 31e31b8a | bellard | case TARGET_NR_mmap:
|
2723 | e6e5906b | pbrook | #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_M68K)
|
2724 | 31e31b8a | bellard | { |
2725 | 53a5960a | pbrook | target_ulong *v; |
2726 | 53a5960a | pbrook | target_ulong v1, v2, v3, v4, v5, v6; |
2727 | 53a5960a | pbrook | v = lock_user(arg1, 6 * sizeof(target_ulong), 1); |
2728 | 53a5960a | pbrook | v1 = tswapl(v[0]);
|
2729 | 53a5960a | pbrook | v2 = tswapl(v[1]);
|
2730 | 53a5960a | pbrook | v3 = tswapl(v[2]);
|
2731 | 53a5960a | pbrook | v4 = tswapl(v[3]);
|
2732 | 53a5960a | pbrook | v5 = tswapl(v[4]);
|
2733 | 53a5960a | pbrook | v6 = tswapl(v[5]);
|
2734 | 53a5960a | pbrook | unlock_user(v, arg1, 0);
|
2735 | 5286db75 | bellard | ret = get_errno(target_mmap(v1, v2, v3, |
2736 | 5286db75 | bellard | target_to_host_bitmask(v4, mmap_flags_tbl), |
2737 | 5286db75 | bellard | v5, v6)); |
2738 | 31e31b8a | bellard | } |
2739 | 31e31b8a | bellard | #else
|
2740 | 6fb883e8 | bellard | ret = get_errno(target_mmap(arg1, arg2, arg3, |
2741 | 6fb883e8 | bellard | target_to_host_bitmask(arg4, mmap_flags_tbl), |
2742 | 6fb883e8 | bellard | arg5, |
2743 | 6fb883e8 | bellard | arg6)); |
2744 | 31e31b8a | bellard | #endif
|
2745 | 6fb883e8 | bellard | break;
|
2746 | a315a145 | bellard | #ifdef TARGET_NR_mmap2
|
2747 | 6fb883e8 | bellard | case TARGET_NR_mmap2:
|
2748 | 0d3267a7 | ths | #if defined(TARGET_SPARC) || defined(TARGET_MIPS)
|
2749 | c573ff67 | bellard | #define MMAP_SHIFT 12 |
2750 | c573ff67 | bellard | #else
|
2751 | c573ff67 | bellard | #define MMAP_SHIFT TARGET_PAGE_BITS
|
2752 | c573ff67 | bellard | #endif
|
2753 | 5286db75 | bellard | ret = get_errno(target_mmap(arg1, arg2, arg3, |
2754 | 5286db75 | bellard | target_to_host_bitmask(arg4, mmap_flags_tbl), |
2755 | 5286db75 | bellard | arg5, |
2756 | c573ff67 | bellard | arg6 << MMAP_SHIFT)); |
2757 | 31e31b8a | bellard | break;
|
2758 | a315a145 | bellard | #endif
|
2759 | 31e31b8a | bellard | case TARGET_NR_munmap:
|
2760 | 54936004 | bellard | ret = get_errno(target_munmap(arg1, arg2)); |
2761 | 31e31b8a | bellard | break;
|
2762 | 9de5e440 | bellard | case TARGET_NR_mprotect:
|
2763 | 54936004 | bellard | ret = get_errno(target_mprotect(arg1, arg2, arg3)); |
2764 | 9de5e440 | bellard | break;
|
2765 | 9de5e440 | bellard | case TARGET_NR_mremap:
|
2766 | 54936004 | bellard | ret = get_errno(target_mremap(arg1, arg2, arg3, arg4, arg5)); |
2767 | 9de5e440 | bellard | break;
|
2768 | 53a5960a | pbrook | /* ??? msync/mlock/munlock are broken for softmmu. */
|
2769 | 9de5e440 | bellard | case TARGET_NR_msync:
|
2770 | 53a5960a | pbrook | ret = get_errno(msync(g2h(arg1), arg2, arg3)); |
2771 | 9de5e440 | bellard | break;
|
2772 | 9de5e440 | bellard | case TARGET_NR_mlock:
|
2773 | 53a5960a | pbrook | ret = get_errno(mlock(g2h(arg1), arg2)); |
2774 | 9de5e440 | bellard | break;
|
2775 | 9de5e440 | bellard | case TARGET_NR_munlock:
|
2776 | 53a5960a | pbrook | ret = get_errno(munlock(g2h(arg1), arg2)); |
2777 | 9de5e440 | bellard | break;
|
2778 | 9de5e440 | bellard | case TARGET_NR_mlockall:
|
2779 | 9de5e440 | bellard | ret = get_errno(mlockall(arg1)); |
2780 | 9de5e440 | bellard | break;
|
2781 | 9de5e440 | bellard | case TARGET_NR_munlockall:
|
2782 | 9de5e440 | bellard | ret = get_errno(munlockall()); |
2783 | 9de5e440 | bellard | break;
|
2784 | 31e31b8a | bellard | case TARGET_NR_truncate:
|
2785 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2786 | 53a5960a | pbrook | ret = get_errno(truncate(p, arg2)); |
2787 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2788 | 31e31b8a | bellard | break;
|
2789 | 31e31b8a | bellard | case TARGET_NR_ftruncate:
|
2790 | 31e31b8a | bellard | ret = get_errno(ftruncate(arg1, arg2)); |
2791 | 31e31b8a | bellard | break;
|
2792 | 31e31b8a | bellard | case TARGET_NR_fchmod:
|
2793 | 31e31b8a | bellard | ret = get_errno(fchmod(arg1, arg2)); |
2794 | 31e31b8a | bellard | break;
|
2795 | 31e31b8a | bellard | case TARGET_NR_getpriority:
|
2796 | 31e31b8a | bellard | ret = get_errno(getpriority(arg1, arg2)); |
2797 | 31e31b8a | bellard | break;
|
2798 | 31e31b8a | bellard | case TARGET_NR_setpriority:
|
2799 | 31e31b8a | bellard | ret = get_errno(setpriority(arg1, arg2, arg3)); |
2800 | 31e31b8a | bellard | break;
|
2801 | ebc05488 | bellard | #ifdef TARGET_NR_profil
|
2802 | 31e31b8a | bellard | case TARGET_NR_profil:
|
2803 | 31e31b8a | bellard | goto unimplemented;
|
2804 | ebc05488 | bellard | #endif
|
2805 | 31e31b8a | bellard | case TARGET_NR_statfs:
|
2806 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2807 | 53a5960a | pbrook | ret = get_errno(statfs(path(p), &stfs)); |
2808 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2809 | 31e31b8a | bellard | convert_statfs:
|
2810 | 31e31b8a | bellard | if (!is_error(ret)) {
|
2811 | 53a5960a | pbrook | struct target_statfs *target_stfs;
|
2812 | 56c8f68f | bellard | |
2813 | 53a5960a | pbrook | lock_user_struct(target_stfs, arg2, 0);
|
2814 | 53a5960a | pbrook | /* ??? put_user is probably wrong. */
|
2815 | 56c8f68f | bellard | put_user(stfs.f_type, &target_stfs->f_type); |
2816 | 56c8f68f | bellard | put_user(stfs.f_bsize, &target_stfs->f_bsize); |
2817 | 56c8f68f | bellard | put_user(stfs.f_blocks, &target_stfs->f_blocks); |
2818 | 56c8f68f | bellard | put_user(stfs.f_bfree, &target_stfs->f_bfree); |
2819 | 56c8f68f | bellard | put_user(stfs.f_bavail, &target_stfs->f_bavail); |
2820 | 56c8f68f | bellard | put_user(stfs.f_files, &target_stfs->f_files); |
2821 | 56c8f68f | bellard | put_user(stfs.f_ffree, &target_stfs->f_ffree); |
2822 | 56c8f68f | bellard | put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid);
|
2823 | 56c8f68f | bellard | put_user(stfs.f_namelen, &target_stfs->f_namelen); |
2824 | 53a5960a | pbrook | unlock_user_struct(target_stfs, arg2, 1);
|
2825 | 31e31b8a | bellard | } |
2826 | 31e31b8a | bellard | break;
|
2827 | 31e31b8a | bellard | case TARGET_NR_fstatfs:
|
2828 | 56c8f68f | bellard | ret = get_errno(fstatfs(arg1, &stfs)); |
2829 | 31e31b8a | bellard | goto convert_statfs;
|
2830 | 56c8f68f | bellard | #ifdef TARGET_NR_statfs64
|
2831 | 56c8f68f | bellard | case TARGET_NR_statfs64:
|
2832 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2833 | 53a5960a | pbrook | ret = get_errno(statfs(path(p), &stfs)); |
2834 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2835 | 56c8f68f | bellard | convert_statfs64:
|
2836 | 56c8f68f | bellard | if (!is_error(ret)) {
|
2837 | 53a5960a | pbrook | struct target_statfs64 *target_stfs;
|
2838 | 53a5960a | pbrook | |
2839 | 53a5960a | pbrook | lock_user_struct(target_stfs, arg3, 0);
|
2840 | 53a5960a | pbrook | /* ??? put_user is probably wrong. */
|
2841 | 56c8f68f | bellard | put_user(stfs.f_type, &target_stfs->f_type); |
2842 | 56c8f68f | bellard | put_user(stfs.f_bsize, &target_stfs->f_bsize); |
2843 | 56c8f68f | bellard | put_user(stfs.f_blocks, &target_stfs->f_blocks); |
2844 | 56c8f68f | bellard | put_user(stfs.f_bfree, &target_stfs->f_bfree); |
2845 | 56c8f68f | bellard | put_user(stfs.f_bavail, &target_stfs->f_bavail); |
2846 | 56c8f68f | bellard | put_user(stfs.f_files, &target_stfs->f_files); |
2847 | 56c8f68f | bellard | put_user(stfs.f_ffree, &target_stfs->f_ffree); |
2848 | 56c8f68f | bellard | put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid);
|
2849 | 56c8f68f | bellard | put_user(stfs.f_namelen, &target_stfs->f_namelen); |
2850 | 53a5960a | pbrook | unlock_user_struct(target_stfs, arg3, 0);
|
2851 | 56c8f68f | bellard | } |
2852 | 56c8f68f | bellard | break;
|
2853 | 56c8f68f | bellard | case TARGET_NR_fstatfs64:
|
2854 | 56c8f68f | bellard | ret = get_errno(fstatfs(arg1, &stfs)); |
2855 | 56c8f68f | bellard | goto convert_statfs64;
|
2856 | 56c8f68f | bellard | #endif
|
2857 | ebc05488 | bellard | #ifdef TARGET_NR_ioperm
|
2858 | 31e31b8a | bellard | case TARGET_NR_ioperm:
|
2859 | 31e31b8a | bellard | goto unimplemented;
|
2860 | ebc05488 | bellard | #endif
|
2861 | 31e31b8a | bellard | case TARGET_NR_socketcall:
|
2862 | 53a5960a | pbrook | ret = do_socketcall(arg1, arg2); |
2863 | 31e31b8a | bellard | break;
|
2864 | 3532fa74 | bellard | |
2865 | 3532fa74 | bellard | #ifdef TARGET_NR_accept
|
2866 | 3532fa74 | bellard | case TARGET_NR_accept:
|
2867 | 1be9e1dc | pbrook | ret = do_accept(arg1, arg2, arg3); |
2868 | 3532fa74 | bellard | break;
|
2869 | 3532fa74 | bellard | #endif
|
2870 | 3532fa74 | bellard | #ifdef TARGET_NR_bind
|
2871 | 3532fa74 | bellard | case TARGET_NR_bind:
|
2872 | 3532fa74 | bellard | ret = do_bind(arg1, arg2, arg3); |
2873 | 3532fa74 | bellard | break;
|
2874 | 3532fa74 | bellard | #endif
|
2875 | 3532fa74 | bellard | #ifdef TARGET_NR_connect
|
2876 | 3532fa74 | bellard | case TARGET_NR_connect:
|
2877 | 3532fa74 | bellard | ret = do_connect(arg1, arg2, arg3); |
2878 | 3532fa74 | bellard | break;
|
2879 | 3532fa74 | bellard | #endif
|
2880 | 3532fa74 | bellard | #ifdef TARGET_NR_getpeername
|
2881 | 3532fa74 | bellard | case TARGET_NR_getpeername:
|
2882 | 1be9e1dc | pbrook | ret = do_getpeername(arg1, arg2, arg3); |
2883 | 3532fa74 | bellard | break;
|
2884 | 3532fa74 | bellard | #endif
|
2885 | 3532fa74 | bellard | #ifdef TARGET_NR_getsockname
|
2886 | 3532fa74 | bellard | case TARGET_NR_getsockname:
|
2887 | 1be9e1dc | pbrook | ret = do_getsockname(arg1, arg2, arg3); |
2888 | 3532fa74 | bellard | break;
|
2889 | 3532fa74 | bellard | #endif
|
2890 | 3532fa74 | bellard | #ifdef TARGET_NR_getsockopt
|
2891 | 3532fa74 | bellard | case TARGET_NR_getsockopt:
|
2892 | 3532fa74 | bellard | ret = do_getsockopt(arg1, arg2, arg3, arg4, arg5); |
2893 | 3532fa74 | bellard | break;
|
2894 | 3532fa74 | bellard | #endif
|
2895 | 3532fa74 | bellard | #ifdef TARGET_NR_listen
|
2896 | 3532fa74 | bellard | case TARGET_NR_listen:
|
2897 | 1be9e1dc | pbrook | ret = get_errno(listen(arg1, arg2)); |
2898 | 3532fa74 | bellard | break;
|
2899 | 3532fa74 | bellard | #endif
|
2900 | 3532fa74 | bellard | #ifdef TARGET_NR_recv
|
2901 | 3532fa74 | bellard | case TARGET_NR_recv:
|
2902 | 1be9e1dc | pbrook | ret = do_recvfrom(arg1, arg1, arg3, arg4, 0, 0); |
2903 | 3532fa74 | bellard | break;
|
2904 | 3532fa74 | bellard | #endif
|
2905 | 3532fa74 | bellard | #ifdef TARGET_NR_recvfrom
|
2906 | 3532fa74 | bellard | case TARGET_NR_recvfrom:
|
2907 | 1be9e1dc | pbrook | ret = do_recvfrom(arg1, arg1, arg3, arg4, arg5, arg6); |
2908 | 3532fa74 | bellard | break;
|
2909 | 3532fa74 | bellard | #endif
|
2910 | 3532fa74 | bellard | #ifdef TARGET_NR_recvmsg
|
2911 | 3532fa74 | bellard | case TARGET_NR_recvmsg:
|
2912 | 3532fa74 | bellard | ret = do_sendrecvmsg(arg1, arg2, arg3, 0);
|
2913 | 3532fa74 | bellard | break;
|
2914 | 3532fa74 | bellard | #endif
|
2915 | 3532fa74 | bellard | #ifdef TARGET_NR_send
|
2916 | 3532fa74 | bellard | case TARGET_NR_send:
|
2917 | 1be9e1dc | pbrook | ret = do_sendto(arg1, arg2, arg3, arg4, 0, 0); |
2918 | 3532fa74 | bellard | break;
|
2919 | 3532fa74 | bellard | #endif
|
2920 | 3532fa74 | bellard | #ifdef TARGET_NR_sendmsg
|
2921 | 3532fa74 | bellard | case TARGET_NR_sendmsg:
|
2922 | 3532fa74 | bellard | ret = do_sendrecvmsg(arg1, arg2, arg3, 1);
|
2923 | 3532fa74 | bellard | break;
|
2924 | 3532fa74 | bellard | #endif
|
2925 | 3532fa74 | bellard | #ifdef TARGET_NR_sendto
|
2926 | 3532fa74 | bellard | case TARGET_NR_sendto:
|
2927 | 1be9e1dc | pbrook | ret = do_sendto(arg1, arg2, arg3, arg4, arg5, arg6); |
2928 | 3532fa74 | bellard | break;
|
2929 | 3532fa74 | bellard | #endif
|
2930 | 3532fa74 | bellard | #ifdef TARGET_NR_shutdown
|
2931 | 3532fa74 | bellard | case TARGET_NR_shutdown:
|
2932 | 1be9e1dc | pbrook | ret = get_errno(shutdown(arg1, arg2)); |
2933 | 3532fa74 | bellard | break;
|
2934 | 3532fa74 | bellard | #endif
|
2935 | 3532fa74 | bellard | #ifdef TARGET_NR_socket
|
2936 | 3532fa74 | bellard | case TARGET_NR_socket:
|
2937 | 3532fa74 | bellard | ret = do_socket(arg1, arg2, arg3); |
2938 | 3532fa74 | bellard | break;
|
2939 | 3532fa74 | bellard | #endif
|
2940 | 3532fa74 | bellard | #ifdef TARGET_NR_socketpair
|
2941 | 3532fa74 | bellard | case TARGET_NR_socketpair:
|
2942 | 1be9e1dc | pbrook | ret = do_socketpair(arg1, arg2, arg3, arg4); |
2943 | 3532fa74 | bellard | break;
|
2944 | 3532fa74 | bellard | #endif
|
2945 | 3532fa74 | bellard | #ifdef TARGET_NR_setsockopt
|
2946 | 3532fa74 | bellard | case TARGET_NR_setsockopt:
|
2947 | 3532fa74 | bellard | ret = do_setsockopt(arg1, arg2, arg3, arg4, (socklen_t) arg5); |
2948 | 3532fa74 | bellard | break;
|
2949 | 3532fa74 | bellard | #endif
|
2950 | 3532fa74 | bellard | |
2951 | 31e31b8a | bellard | case TARGET_NR_syslog:
|
2952 | 31e31b8a | bellard | goto unimplemented;
|
2953 | 31e31b8a | bellard | case TARGET_NR_setitimer:
|
2954 | 66fb9763 | bellard | { |
2955 | 66fb9763 | bellard | struct itimerval value, ovalue, *pvalue;
|
2956 | 66fb9763 | bellard | |
2957 | 53a5960a | pbrook | if (arg2) {
|
2958 | 66fb9763 | bellard | pvalue = &value; |
2959 | 66fb9763 | bellard | target_to_host_timeval(&pvalue->it_interval, |
2960 | 53a5960a | pbrook | arg2); |
2961 | 66fb9763 | bellard | target_to_host_timeval(&pvalue->it_value, |
2962 | 53a5960a | pbrook | arg2 + sizeof(struct target_timeval)); |
2963 | 66fb9763 | bellard | } else {
|
2964 | 66fb9763 | bellard | pvalue = NULL;
|
2965 | 66fb9763 | bellard | } |
2966 | 66fb9763 | bellard | ret = get_errno(setitimer(arg1, pvalue, &ovalue)); |
2967 | 53a5960a | pbrook | if (!is_error(ret) && arg3) {
|
2968 | 53a5960a | pbrook | host_to_target_timeval(arg3, |
2969 | 66fb9763 | bellard | &ovalue.it_interval); |
2970 | 53a5960a | pbrook | host_to_target_timeval(arg3 + sizeof(struct target_timeval), |
2971 | 66fb9763 | bellard | &ovalue.it_value); |
2972 | 66fb9763 | bellard | } |
2973 | 66fb9763 | bellard | } |
2974 | 66fb9763 | bellard | break;
|
2975 | 31e31b8a | bellard | case TARGET_NR_getitimer:
|
2976 | 66fb9763 | bellard | { |
2977 | 66fb9763 | bellard | struct itimerval value;
|
2978 | 66fb9763 | bellard | |
2979 | 66fb9763 | bellard | ret = get_errno(getitimer(arg1, &value)); |
2980 | 53a5960a | pbrook | if (!is_error(ret) && arg2) {
|
2981 | 53a5960a | pbrook | host_to_target_timeval(arg2, |
2982 | 66fb9763 | bellard | &value.it_interval); |
2983 | 53a5960a | pbrook | host_to_target_timeval(arg2 + sizeof(struct target_timeval), |
2984 | 66fb9763 | bellard | &value.it_value); |
2985 | 66fb9763 | bellard | } |
2986 | 66fb9763 | bellard | } |
2987 | 66fb9763 | bellard | break;
|
2988 | 31e31b8a | bellard | case TARGET_NR_stat:
|
2989 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2990 | 53a5960a | pbrook | ret = get_errno(stat(path(p), &st)); |
2991 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2992 | 31e31b8a | bellard | goto do_stat;
|
2993 | 31e31b8a | bellard | case TARGET_NR_lstat:
|
2994 | 53a5960a | pbrook | p = lock_user_string(arg1); |
2995 | 53a5960a | pbrook | ret = get_errno(lstat(path(p), &st)); |
2996 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
2997 | 31e31b8a | bellard | goto do_stat;
|
2998 | 31e31b8a | bellard | case TARGET_NR_fstat:
|
2999 | 31e31b8a | bellard | { |
3000 | 31e31b8a | bellard | ret = get_errno(fstat(arg1, &st)); |
3001 | 31e31b8a | bellard | do_stat:
|
3002 | 31e31b8a | bellard | if (!is_error(ret)) {
|
3003 | 53a5960a | pbrook | struct target_stat *target_st;
|
3004 | 53a5960a | pbrook | |
3005 | 53a5960a | pbrook | lock_user_struct(target_st, arg2, 0);
|
3006 | 31e31b8a | bellard | target_st->st_dev = tswap16(st.st_dev); |
3007 | 31e31b8a | bellard | target_st->st_ino = tswapl(st.st_ino); |
3008 | 7d600c80 | ths | #if defined(TARGET_PPC) || defined(TARGET_MIPS)
|
3009 | 67867308 | bellard | target_st->st_mode = tswapl(st.st_mode); /* XXX: check this */
|
3010 | 67867308 | bellard | target_st->st_uid = tswap32(st.st_uid); |
3011 | 67867308 | bellard | target_st->st_gid = tswap32(st.st_gid); |
3012 | 67867308 | bellard | #else
|
3013 | ec86b0fb | bellard | target_st->st_mode = tswap16(st.st_mode); |
3014 | 31e31b8a | bellard | target_st->st_uid = tswap16(st.st_uid); |
3015 | 31e31b8a | bellard | target_st->st_gid = tswap16(st.st_gid); |
3016 | 67867308 | bellard | #endif
|
3017 | 67867308 | bellard | target_st->st_nlink = tswap16(st.st_nlink); |
3018 | 31e31b8a | bellard | target_st->st_rdev = tswap16(st.st_rdev); |
3019 | 31e31b8a | bellard | target_st->st_size = tswapl(st.st_size); |
3020 | 31e31b8a | bellard | target_st->st_blksize = tswapl(st.st_blksize); |
3021 | 31e31b8a | bellard | target_st->st_blocks = tswapl(st.st_blocks); |
3022 | 7854b056 | bellard | target_st->target_st_atime = tswapl(st.st_atime); |
3023 | 7854b056 | bellard | target_st->target_st_mtime = tswapl(st.st_mtime); |
3024 | 7854b056 | bellard | target_st->target_st_ctime = tswapl(st.st_ctime); |
3025 | 53a5960a | pbrook | unlock_user_struct(target_st, arg2, 1);
|
3026 | 31e31b8a | bellard | } |
3027 | 31e31b8a | bellard | } |
3028 | 31e31b8a | bellard | break;
|
3029 | ebc05488 | bellard | #ifdef TARGET_NR_olduname
|
3030 | 31e31b8a | bellard | case TARGET_NR_olduname:
|
3031 | 31e31b8a | bellard | goto unimplemented;
|
3032 | ebc05488 | bellard | #endif
|
3033 | ebc05488 | bellard | #ifdef TARGET_NR_iopl
|
3034 | 31e31b8a | bellard | case TARGET_NR_iopl:
|
3035 | 31e31b8a | bellard | goto unimplemented;
|
3036 | ebc05488 | bellard | #endif
|
3037 | 31e31b8a | bellard | case TARGET_NR_vhangup:
|
3038 | 31e31b8a | bellard | ret = get_errno(vhangup()); |
3039 | 31e31b8a | bellard | break;
|
3040 | ebc05488 | bellard | #ifdef TARGET_NR_idle
|
3041 | 31e31b8a | bellard | case TARGET_NR_idle:
|
3042 | 31e31b8a | bellard | goto unimplemented;
|
3043 | ebc05488 | bellard | #endif
|
3044 | 42ad6ae9 | bellard | #ifdef TARGET_NR_syscall
|
3045 | 42ad6ae9 | bellard | case TARGET_NR_syscall:
|
3046 | 42ad6ae9 | bellard | ret = do_syscall(cpu_env,arg1 & 0xffff,arg2,arg3,arg4,arg5,arg6,0); |
3047 | 42ad6ae9 | bellard | break;
|
3048 | 42ad6ae9 | bellard | #endif
|
3049 | 31e31b8a | bellard | case TARGET_NR_wait4:
|
3050 | 31e31b8a | bellard | { |
3051 | 31e31b8a | bellard | int status;
|
3052 | 53a5960a | pbrook | target_long status_ptr = arg2; |
3053 | 31e31b8a | bellard | struct rusage rusage, *rusage_ptr;
|
3054 | 53a5960a | pbrook | target_ulong target_rusage = arg4; |
3055 | 31e31b8a | bellard | if (target_rusage)
|
3056 | 31e31b8a | bellard | rusage_ptr = &rusage; |
3057 | 31e31b8a | bellard | else
|
3058 | 31e31b8a | bellard | rusage_ptr = NULL;
|
3059 | 31e31b8a | bellard | ret = get_errno(wait4(arg1, &status, arg3, rusage_ptr)); |
3060 | 31e31b8a | bellard | if (!is_error(ret)) {
|
3061 | 31e31b8a | bellard | if (status_ptr)
|
3062 | 53a5960a | pbrook | tputl(status_ptr, status); |
3063 | 31e31b8a | bellard | if (target_rusage) {
|
3064 | b409186b | bellard | host_to_target_rusage(target_rusage, &rusage); |
3065 | 31e31b8a | bellard | } |
3066 | 31e31b8a | bellard | } |
3067 | 31e31b8a | bellard | } |
3068 | 31e31b8a | bellard | break;
|
3069 | 31e31b8a | bellard | case TARGET_NR_swapoff:
|
3070 | 53a5960a | pbrook | p = lock_user_string(arg1); |
3071 | 53a5960a | pbrook | ret = get_errno(swapoff(p)); |
3072 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
3073 | 31e31b8a | bellard | break;
|
3074 | 31e31b8a | bellard | case TARGET_NR_sysinfo:
|
3075 | a5448a7d | bellard | { |
3076 | 53a5960a | pbrook | struct target_sysinfo *target_value;
|
3077 | a5448a7d | bellard | struct sysinfo value;
|
3078 | a5448a7d | bellard | ret = get_errno(sysinfo(&value)); |
3079 | 53a5960a | pbrook | if (!is_error(ret) && arg1)
|
3080 | a5448a7d | bellard | { |
3081 | 53a5960a | pbrook | /* ??? __put_user is probably wrong. */
|
3082 | 53a5960a | pbrook | lock_user_struct(target_value, arg1, 0);
|
3083 | a5448a7d | bellard | __put_user(value.uptime, &target_value->uptime); |
3084 | a5448a7d | bellard | __put_user(value.loads[0], &target_value->loads[0]); |
3085 | a5448a7d | bellard | __put_user(value.loads[1], &target_value->loads[1]); |
3086 | a5448a7d | bellard | __put_user(value.loads[2], &target_value->loads[2]); |
3087 | a5448a7d | bellard | __put_user(value.totalram, &target_value->totalram); |
3088 | a5448a7d | bellard | __put_user(value.freeram, &target_value->freeram); |
3089 | a5448a7d | bellard | __put_user(value.sharedram, &target_value->sharedram); |
3090 | a5448a7d | bellard | __put_user(value.bufferram, &target_value->bufferram); |
3091 | a5448a7d | bellard | __put_user(value.totalswap, &target_value->totalswap); |
3092 | a5448a7d | bellard | __put_user(value.freeswap, &target_value->freeswap); |
3093 | a5448a7d | bellard | __put_user(value.procs, &target_value->procs); |
3094 | a5448a7d | bellard | __put_user(value.totalhigh, &target_value->totalhigh); |
3095 | a5448a7d | bellard | __put_user(value.freehigh, &target_value->freehigh); |
3096 | a5448a7d | bellard | __put_user(value.mem_unit, &target_value->mem_unit); |
3097 | 53a5960a | pbrook | unlock_user_struct(target_value, arg1, 1);
|
3098 | a5448a7d | bellard | } |
3099 | a5448a7d | bellard | } |
3100 | a5448a7d | bellard | break;
|
3101 | 31e31b8a | bellard | case TARGET_NR_ipc:
|
3102 | 8853f86e | bellard | ret = do_ipc(arg1, arg2, arg3, arg4, arg5, arg6); |
3103 | 8853f86e | bellard | break;
|
3104 | 31e31b8a | bellard | case TARGET_NR_fsync:
|
3105 | 31e31b8a | bellard | ret = get_errno(fsync(arg1)); |
3106 | 31e31b8a | bellard | break;
|
3107 | 31e31b8a | bellard | case TARGET_NR_clone:
|
3108 | 1b6b029e | bellard | ret = get_errno(do_fork(cpu_env, arg1, arg2)); |
3109 | 1b6b029e | bellard | break;
|
3110 | ec86b0fb | bellard | #ifdef __NR_exit_group
|
3111 | ec86b0fb | bellard | /* new thread calls */
|
3112 | ec86b0fb | bellard | case TARGET_NR_exit_group:
|
3113 | e9009676 | bellard | gdb_exit(cpu_env, arg1); |
3114 | ec86b0fb | bellard | ret = get_errno(exit_group(arg1)); |
3115 | ec86b0fb | bellard | break;
|
3116 | ec86b0fb | bellard | #endif
|
3117 | 31e31b8a | bellard | case TARGET_NR_setdomainname:
|
3118 | 53a5960a | pbrook | p = lock_user_string(arg1); |
3119 | 53a5960a | pbrook | ret = get_errno(setdomainname(p, arg2)); |
3120 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
3121 | 31e31b8a | bellard | break;
|
3122 | 31e31b8a | bellard | case TARGET_NR_uname:
|
3123 | 31e31b8a | bellard | /* no need to transcode because we use the linux syscall */
|
3124 | 29e619b1 | bellard | { |
3125 | 29e619b1 | bellard | struct new_utsname * buf;
|
3126 | 29e619b1 | bellard | |
3127 | 53a5960a | pbrook | lock_user_struct(buf, arg1, 0);
|
3128 | 29e619b1 | bellard | ret = get_errno(sys_uname(buf)); |
3129 | 29e619b1 | bellard | if (!is_error(ret)) {
|
3130 | 29e619b1 | bellard | /* Overrite the native machine name with whatever is being
|
3131 | 29e619b1 | bellard | emulated. */
|
3132 | 29e619b1 | bellard | strcpy (buf->machine, UNAME_MACHINE); |
3133 | c5937220 | pbrook | /* Allow the user to override the reported release. */
|
3134 | c5937220 | pbrook | if (qemu_uname_release && *qemu_uname_release)
|
3135 | c5937220 | pbrook | strcpy (buf->release, qemu_uname_release); |
3136 | 29e619b1 | bellard | } |
3137 | 53a5960a | pbrook | unlock_user_struct(buf, arg1, 1);
|
3138 | 29e619b1 | bellard | } |
3139 | 31e31b8a | bellard | break;
|
3140 | 6dbad63e | bellard | #ifdef TARGET_I386
|
3141 | 31e31b8a | bellard | case TARGET_NR_modify_ldt:
|
3142 | 53a5960a | pbrook | ret = get_errno(do_modify_ldt(cpu_env, arg1, arg2, arg3)); |
3143 | 5cd4393b | bellard | break;
|
3144 | 5cd4393b | bellard | case TARGET_NR_vm86old:
|
3145 | 5cd4393b | bellard | goto unimplemented;
|
3146 | 5cd4393b | bellard | case TARGET_NR_vm86:
|
3147 | 53a5960a | pbrook | ret = do_vm86(cpu_env, arg1, arg2); |
3148 | 6dbad63e | bellard | break;
|
3149 | 6dbad63e | bellard | #endif
|
3150 | 31e31b8a | bellard | case TARGET_NR_adjtimex:
|
3151 | 31e31b8a | bellard | goto unimplemented;
|
3152 | 31e31b8a | bellard | case TARGET_NR_create_module:
|
3153 | 31e31b8a | bellard | case TARGET_NR_init_module:
|
3154 | 31e31b8a | bellard | case TARGET_NR_delete_module:
|
3155 | 31e31b8a | bellard | case TARGET_NR_get_kernel_syms:
|
3156 | 31e31b8a | bellard | goto unimplemented;
|
3157 | 31e31b8a | bellard | case TARGET_NR_quotactl:
|
3158 | 31e31b8a | bellard | goto unimplemented;
|
3159 | 31e31b8a | bellard | case TARGET_NR_getpgid:
|
3160 | 31e31b8a | bellard | ret = get_errno(getpgid(arg1)); |
3161 | 31e31b8a | bellard | break;
|
3162 | 31e31b8a | bellard | case TARGET_NR_fchdir:
|
3163 | 31e31b8a | bellard | ret = get_errno(fchdir(arg1)); |
3164 | 31e31b8a | bellard | break;
|
3165 | 31e31b8a | bellard | case TARGET_NR_bdflush:
|
3166 | 31e31b8a | bellard | goto unimplemented;
|
3167 | 31e31b8a | bellard | case TARGET_NR_sysfs:
|
3168 | 31e31b8a | bellard | goto unimplemented;
|
3169 | 31e31b8a | bellard | case TARGET_NR_personality:
|
3170 | 1b6b029e | bellard | ret = get_errno(personality(arg1)); |
3171 | 31e31b8a | bellard | break;
|
3172 | 31e31b8a | bellard | case TARGET_NR_afs_syscall:
|
3173 | 31e31b8a | bellard | goto unimplemented;
|
3174 | 31e31b8a | bellard | case TARGET_NR__llseek:
|
3175 | 31e31b8a | bellard | { |
3176 | 4f2ac237 | bellard | #if defined (__x86_64__)
|
3177 | 4f2ac237 | bellard | ret = get_errno(lseek(arg1, ((uint64_t )arg2 << 32) | arg3, arg5));
|
3178 | 53a5960a | pbrook | tput64(arg4, ret); |
3179 | 4f2ac237 | bellard | #else
|
3180 | 31e31b8a | bellard | int64_t res; |
3181 | 31e31b8a | bellard | ret = get_errno(_llseek(arg1, arg2, arg3, &res, arg5)); |
3182 | 53a5960a | pbrook | tput64(arg4, res); |
3183 | 4f2ac237 | bellard | #endif
|
3184 | 31e31b8a | bellard | } |
3185 | 31e31b8a | bellard | break;
|
3186 | 31e31b8a | bellard | case TARGET_NR_getdents:
|
3187 | 31e31b8a | bellard | #if TARGET_LONG_SIZE != 4 |
3188 | 53a5960a | pbrook | goto unimplemented;
|
3189 | a315a145 | bellard | #warning not supported
|
3190 | 4add45b4 | bellard | #elif TARGET_LONG_SIZE == 4 && HOST_LONG_SIZE == 8 |
3191 | 4add45b4 | bellard | { |
3192 | 53a5960a | pbrook | struct target_dirent *target_dirp;
|
3193 | 4add45b4 | bellard | struct dirent *dirp;
|
3194 | 4add45b4 | bellard | long count = arg3;
|
3195 | 4add45b4 | bellard | |
3196 | 4add45b4 | bellard | dirp = malloc(count); |
3197 | 4add45b4 | bellard | if (!dirp)
|
3198 | 4add45b4 | bellard | return -ENOMEM;
|
3199 | 4add45b4 | bellard | |
3200 | 4add45b4 | bellard | ret = get_errno(sys_getdents(arg1, dirp, count)); |
3201 | 4add45b4 | bellard | if (!is_error(ret)) {
|
3202 | 4add45b4 | bellard | struct dirent *de;
|
3203 | 4add45b4 | bellard | struct target_dirent *tde;
|
3204 | 4add45b4 | bellard | int len = ret;
|
3205 | 4add45b4 | bellard | int reclen, treclen;
|
3206 | 4add45b4 | bellard | int count1, tnamelen;
|
3207 | 4add45b4 | bellard | |
3208 | 4add45b4 | bellard | count1 = 0;
|
3209 | 4add45b4 | bellard | de = dirp; |
3210 | 53a5960a | pbrook | target_dirp = lock_user(arg2, count, 0);
|
3211 | 4add45b4 | bellard | tde = target_dirp; |
3212 | 4add45b4 | bellard | while (len > 0) { |
3213 | 4add45b4 | bellard | reclen = de->d_reclen; |
3214 | 4add45b4 | bellard | treclen = reclen - (2 * (sizeof(long) - sizeof(target_long))); |
3215 | 4add45b4 | bellard | tde->d_reclen = tswap16(treclen); |
3216 | 4add45b4 | bellard | tde->d_ino = tswapl(de->d_ino); |
3217 | 4add45b4 | bellard | tde->d_off = tswapl(de->d_off); |
3218 | 4add45b4 | bellard | tnamelen = treclen - (2 * sizeof(target_long) + 2); |
3219 | 4add45b4 | bellard | if (tnamelen > 256) |
3220 | 4add45b4 | bellard | tnamelen = 256;
|
3221 | 80a9d035 | bellard | /* XXX: may not be correct */
|
3222 | 4add45b4 | bellard | strncpy(tde->d_name, de->d_name, tnamelen); |
3223 | 4add45b4 | bellard | de = (struct dirent *)((char *)de + reclen); |
3224 | 4add45b4 | bellard | len -= reclen; |
3225 | 4add45b4 | bellard | tde = (struct dirent *)((char *)tde + treclen); |
3226 | 4add45b4 | bellard | count1 += treclen; |
3227 | 4add45b4 | bellard | } |
3228 | 4add45b4 | bellard | ret = count1; |
3229 | 4add45b4 | bellard | } |
3230 | 53a5960a | pbrook | unlock_user(target_dirp, arg2, ret); |
3231 | 4add45b4 | bellard | free(dirp); |
3232 | 4add45b4 | bellard | } |
3233 | 4add45b4 | bellard | #else
|
3234 | 31e31b8a | bellard | { |
3235 | 53a5960a | pbrook | struct dirent *dirp;
|
3236 | 31e31b8a | bellard | long count = arg3;
|
3237 | dab2ed99 | bellard | |
3238 | 53a5960a | pbrook | dirp = lock_user(arg2, count, 0);
|
3239 | 72f03900 | bellard | ret = get_errno(sys_getdents(arg1, dirp, count)); |
3240 | 31e31b8a | bellard | if (!is_error(ret)) {
|
3241 | 31e31b8a | bellard | struct dirent *de;
|
3242 | 31e31b8a | bellard | int len = ret;
|
3243 | 31e31b8a | bellard | int reclen;
|
3244 | 31e31b8a | bellard | de = dirp; |
3245 | 31e31b8a | bellard | while (len > 0) { |
3246 | 8083a3e5 | bellard | reclen = de->d_reclen; |
3247 | 31e31b8a | bellard | if (reclen > len)
|
3248 | 31e31b8a | bellard | break;
|
3249 | 8083a3e5 | bellard | de->d_reclen = tswap16(reclen); |
3250 | 31e31b8a | bellard | tswapls(&de->d_ino); |
3251 | 31e31b8a | bellard | tswapls(&de->d_off); |
3252 | 31e31b8a | bellard | de = (struct dirent *)((char *)de + reclen); |
3253 | 31e31b8a | bellard | len -= reclen; |
3254 | 31e31b8a | bellard | } |
3255 | 31e31b8a | bellard | } |
3256 | 53a5960a | pbrook | unlock_user(dirp, arg2, ret); |
3257 | 31e31b8a | bellard | } |
3258 | 4add45b4 | bellard | #endif
|
3259 | 31e31b8a | bellard | break;
|
3260 | a541f297 | bellard | #ifdef TARGET_NR_getdents64
|
3261 | dab2ed99 | bellard | case TARGET_NR_getdents64:
|
3262 | dab2ed99 | bellard | { |
3263 | 53a5960a | pbrook | struct dirent64 *dirp;
|
3264 | dab2ed99 | bellard | long count = arg3;
|
3265 | 53a5960a | pbrook | dirp = lock_user(arg2, count, 0);
|
3266 | dab2ed99 | bellard | ret = get_errno(sys_getdents64(arg1, dirp, count)); |
3267 | dab2ed99 | bellard | if (!is_error(ret)) {
|
3268 | dab2ed99 | bellard | struct dirent64 *de;
|
3269 | dab2ed99 | bellard | int len = ret;
|
3270 | dab2ed99 | bellard | int reclen;
|
3271 | dab2ed99 | bellard | de = dirp; |
3272 | dab2ed99 | bellard | while (len > 0) { |
3273 | 8083a3e5 | bellard | reclen = de->d_reclen; |
3274 | dab2ed99 | bellard | if (reclen > len)
|
3275 | dab2ed99 | bellard | break;
|
3276 | 8083a3e5 | bellard | de->d_reclen = tswap16(reclen); |
3277 | dab2ed99 | bellard | tswap64s(&de->d_ino); |
3278 | dab2ed99 | bellard | tswap64s(&de->d_off); |
3279 | dab2ed99 | bellard | de = (struct dirent64 *)((char *)de + reclen); |
3280 | dab2ed99 | bellard | len -= reclen; |
3281 | dab2ed99 | bellard | } |
3282 | dab2ed99 | bellard | } |
3283 | 53a5960a | pbrook | unlock_user(dirp, arg2, ret); |
3284 | dab2ed99 | bellard | } |
3285 | dab2ed99 | bellard | break;
|
3286 | a541f297 | bellard | #endif /* TARGET_NR_getdents64 */ |
3287 | 31e31b8a | bellard | case TARGET_NR__newselect:
|
3288 | 53a5960a | pbrook | ret = do_select(arg1, arg2, arg3, arg4, arg5); |
3289 | 31e31b8a | bellard | break;
|
3290 | 9de5e440 | bellard | case TARGET_NR_poll:
|
3291 | 9de5e440 | bellard | { |
3292 | 53a5960a | pbrook | struct target_pollfd *target_pfd;
|
3293 | 9de5e440 | bellard | unsigned int nfds = arg2; |
3294 | 9de5e440 | bellard | int timeout = arg3;
|
3295 | 9de5e440 | bellard | struct pollfd *pfd;
|
3296 | 7854b056 | bellard | unsigned int i; |
3297 | 9de5e440 | bellard | |
3298 | 53a5960a | pbrook | target_pfd = lock_user(arg1, sizeof(struct target_pollfd) * nfds, 1); |
3299 | 9de5e440 | bellard | pfd = alloca(sizeof(struct pollfd) * nfds); |
3300 | 9de5e440 | bellard | for(i = 0; i < nfds; i++) { |
3301 | 5cd4393b | bellard | pfd[i].fd = tswap32(target_pfd[i].fd); |
3302 | 5cd4393b | bellard | pfd[i].events = tswap16(target_pfd[i].events); |
3303 | 9de5e440 | bellard | } |
3304 | 9de5e440 | bellard | ret = get_errno(poll(pfd, nfds, timeout)); |
3305 | 9de5e440 | bellard | if (!is_error(ret)) {
|
3306 | 9de5e440 | bellard | for(i = 0; i < nfds; i++) { |
3307 | 5cd4393b | bellard | target_pfd[i].revents = tswap16(pfd[i].revents); |
3308 | 9de5e440 | bellard | } |
3309 | 53a5960a | pbrook | ret += nfds * (sizeof(struct target_pollfd) |
3310 | 53a5960a | pbrook | - sizeof(struct pollfd)); |
3311 | 9de5e440 | bellard | } |
3312 | 53a5960a | pbrook | unlock_user(target_pfd, arg1, ret); |
3313 | 9de5e440 | bellard | } |
3314 | 9de5e440 | bellard | break;
|
3315 | 31e31b8a | bellard | case TARGET_NR_flock:
|
3316 | 9de5e440 | bellard | /* NOTE: the flock constant seems to be the same for every
|
3317 | 9de5e440 | bellard | Linux platform */
|
3318 | 9de5e440 | bellard | ret = get_errno(flock(arg1, arg2)); |
3319 | 31e31b8a | bellard | break;
|
3320 | 31e31b8a | bellard | case TARGET_NR_readv:
|
3321 | 31e31b8a | bellard | { |
3322 | 31e31b8a | bellard | int count = arg3;
|
3323 | 31e31b8a | bellard | struct iovec *vec;
|
3324 | 31e31b8a | bellard | |
3325 | 31e31b8a | bellard | vec = alloca(count * sizeof(struct iovec)); |
3326 | 53a5960a | pbrook | lock_iovec(vec, arg2, count, 0);
|
3327 | 31e31b8a | bellard | ret = get_errno(readv(arg1, vec, count)); |
3328 | 53a5960a | pbrook | unlock_iovec(vec, arg2, count, 1);
|
3329 | 31e31b8a | bellard | } |
3330 | 31e31b8a | bellard | break;
|
3331 | 31e31b8a | bellard | case TARGET_NR_writev:
|
3332 | 31e31b8a | bellard | { |
3333 | 31e31b8a | bellard | int count = arg3;
|
3334 | 31e31b8a | bellard | struct iovec *vec;
|
3335 | 31e31b8a | bellard | |
3336 | 31e31b8a | bellard | vec = alloca(count * sizeof(struct iovec)); |
3337 | 53a5960a | pbrook | lock_iovec(vec, arg2, count, 1);
|
3338 | 31e31b8a | bellard | ret = get_errno(writev(arg1, vec, count)); |
3339 | 53a5960a | pbrook | unlock_iovec(vec, arg2, count, 0);
|
3340 | 31e31b8a | bellard | } |
3341 | 31e31b8a | bellard | break;
|
3342 | 31e31b8a | bellard | case TARGET_NR_getsid:
|
3343 | 31e31b8a | bellard | ret = get_errno(getsid(arg1)); |
3344 | 31e31b8a | bellard | break;
|
3345 | 31e31b8a | bellard | case TARGET_NR_fdatasync:
|
3346 | 5cd4393b | bellard | ret = get_errno(fdatasync(arg1)); |
3347 | 5cd4393b | bellard | break;
|
3348 | 31e31b8a | bellard | case TARGET_NR__sysctl:
|
3349 | 29e619b1 | bellard | /* We don't implement this, but ENODIR is always a safe
|
3350 | 29e619b1 | bellard | return value. */
|
3351 | 29e619b1 | bellard | return -ENOTDIR;
|
3352 | 31e31b8a | bellard | case TARGET_NR_sched_setparam:
|
3353 | 5cd4393b | bellard | { |
3354 | 53a5960a | pbrook | struct sched_param *target_schp;
|
3355 | 5cd4393b | bellard | struct sched_param schp;
|
3356 | 53a5960a | pbrook | |
3357 | 53a5960a | pbrook | lock_user_struct(target_schp, arg2, 1);
|
3358 | 5cd4393b | bellard | schp.sched_priority = tswap32(target_schp->sched_priority); |
3359 | 53a5960a | pbrook | unlock_user_struct(target_schp, arg2, 0);
|
3360 | 5cd4393b | bellard | ret = get_errno(sched_setparam(arg1, &schp)); |
3361 | 5cd4393b | bellard | } |
3362 | 5cd4393b | bellard | break;
|
3363 | 31e31b8a | bellard | case TARGET_NR_sched_getparam:
|
3364 | 5cd4393b | bellard | { |
3365 | 53a5960a | pbrook | struct sched_param *target_schp;
|
3366 | 5cd4393b | bellard | struct sched_param schp;
|
3367 | 5cd4393b | bellard | ret = get_errno(sched_getparam(arg1, &schp)); |
3368 | 5cd4393b | bellard | if (!is_error(ret)) {
|
3369 | 53a5960a | pbrook | lock_user_struct(target_schp, arg2, 0);
|
3370 | 5cd4393b | bellard | target_schp->sched_priority = tswap32(schp.sched_priority); |
3371 | 53a5960a | pbrook | unlock_user_struct(target_schp, arg2, 1);
|
3372 | 5cd4393b | bellard | } |
3373 | 5cd4393b | bellard | } |
3374 | 5cd4393b | bellard | break;
|
3375 | 31e31b8a | bellard | case TARGET_NR_sched_setscheduler:
|
3376 | 5cd4393b | bellard | { |
3377 | 53a5960a | pbrook | struct sched_param *target_schp;
|
3378 | 5cd4393b | bellard | struct sched_param schp;
|
3379 | 53a5960a | pbrook | lock_user_struct(target_schp, arg3, 1);
|
3380 | 5cd4393b | bellard | schp.sched_priority = tswap32(target_schp->sched_priority); |
3381 | 53a5960a | pbrook | unlock_user_struct(target_schp, arg3, 0);
|
3382 | 5cd4393b | bellard | ret = get_errno(sched_setscheduler(arg1, arg2, &schp)); |
3383 | 5cd4393b | bellard | } |
3384 | 5cd4393b | bellard | break;
|
3385 | 31e31b8a | bellard | case TARGET_NR_sched_getscheduler:
|
3386 | 5cd4393b | bellard | ret = get_errno(sched_getscheduler(arg1)); |
3387 | 5cd4393b | bellard | break;
|
3388 | 31e31b8a | bellard | case TARGET_NR_sched_yield:
|
3389 | 31e31b8a | bellard | ret = get_errno(sched_yield()); |
3390 | 31e31b8a | bellard | break;
|
3391 | 31e31b8a | bellard | case TARGET_NR_sched_get_priority_max:
|
3392 | 5cd4393b | bellard | ret = get_errno(sched_get_priority_max(arg1)); |
3393 | 5cd4393b | bellard | break;
|
3394 | 31e31b8a | bellard | case TARGET_NR_sched_get_priority_min:
|
3395 | 5cd4393b | bellard | ret = get_errno(sched_get_priority_min(arg1)); |
3396 | 5cd4393b | bellard | break;
|
3397 | 31e31b8a | bellard | case TARGET_NR_sched_rr_get_interval:
|
3398 | 5cd4393b | bellard | { |
3399 | 5cd4393b | bellard | struct timespec ts;
|
3400 | 5cd4393b | bellard | ret = get_errno(sched_rr_get_interval(arg1, &ts)); |
3401 | 5cd4393b | bellard | if (!is_error(ret)) {
|
3402 | 53a5960a | pbrook | host_to_target_timespec(arg2, &ts); |
3403 | 5cd4393b | bellard | } |
3404 | 5cd4393b | bellard | } |
3405 | 5cd4393b | bellard | break;
|
3406 | 31e31b8a | bellard | case TARGET_NR_nanosleep:
|
3407 | 1b6b029e | bellard | { |
3408 | 1b6b029e | bellard | struct timespec req, rem;
|
3409 | 53a5960a | pbrook | target_to_host_timespec(&req, arg1); |
3410 | 1b6b029e | bellard | ret = get_errno(nanosleep(&req, &rem)); |
3411 | 53a5960a | pbrook | if (is_error(ret) && arg2) {
|
3412 | 53a5960a | pbrook | host_to_target_timespec(arg2, &rem); |
3413 | 1b6b029e | bellard | } |
3414 | 1b6b029e | bellard | } |
3415 | 1b6b029e | bellard | break;
|
3416 | 31e31b8a | bellard | case TARGET_NR_query_module:
|
3417 | 5cd4393b | bellard | goto unimplemented;
|
3418 | 31e31b8a | bellard | case TARGET_NR_nfsservctl:
|
3419 | 5cd4393b | bellard | goto unimplemented;
|
3420 | 31e31b8a | bellard | case TARGET_NR_prctl:
|
3421 | 5cd4393b | bellard | goto unimplemented;
|
3422 | 67867308 | bellard | #ifdef TARGET_NR_pread
|
3423 | 31e31b8a | bellard | case TARGET_NR_pread:
|
3424 | 53a5960a | pbrook | page_unprotect_range(arg2, arg3); |
3425 | 53a5960a | pbrook | p = lock_user(arg2, arg3, 0);
|
3426 | 53a5960a | pbrook | ret = get_errno(pread(arg1, p, arg3, arg4)); |
3427 | 53a5960a | pbrook | unlock_user(p, arg2, ret); |
3428 | 206f0fa7 | bellard | break;
|
3429 | 31e31b8a | bellard | case TARGET_NR_pwrite:
|
3430 | 53a5960a | pbrook | p = lock_user(arg2, arg3, 1);
|
3431 | 53a5960a | pbrook | ret = get_errno(pwrite(arg1, p, arg3, arg4)); |
3432 | 53a5960a | pbrook | unlock_user(p, arg2, 0);
|
3433 | 206f0fa7 | bellard | break;
|
3434 | 67867308 | bellard | #endif
|
3435 | 31e31b8a | bellard | case TARGET_NR_getcwd:
|
3436 | 53a5960a | pbrook | p = lock_user(arg1, arg2, 0);
|
3437 | 53a5960a | pbrook | ret = get_errno(sys_getcwd1(p, arg2)); |
3438 | 53a5960a | pbrook | unlock_user(p, arg1, ret); |
3439 | 31e31b8a | bellard | break;
|
3440 | 31e31b8a | bellard | case TARGET_NR_capget:
|
3441 | 5cd4393b | bellard | goto unimplemented;
|
3442 | 31e31b8a | bellard | case TARGET_NR_capset:
|
3443 | 5cd4393b | bellard | goto unimplemented;
|
3444 | 31e31b8a | bellard | case TARGET_NR_sigaltstack:
|
3445 | 5cd4393b | bellard | goto unimplemented;
|
3446 | 31e31b8a | bellard | case TARGET_NR_sendfile:
|
3447 | 5cd4393b | bellard | goto unimplemented;
|
3448 | ebc05488 | bellard | #ifdef TARGET_NR_getpmsg
|
3449 | 31e31b8a | bellard | case TARGET_NR_getpmsg:
|
3450 | 5cd4393b | bellard | goto unimplemented;
|
3451 | ebc05488 | bellard | #endif
|
3452 | ebc05488 | bellard | #ifdef TARGET_NR_putpmsg
|
3453 | 31e31b8a | bellard | case TARGET_NR_putpmsg:
|
3454 | 5cd4393b | bellard | goto unimplemented;
|
3455 | ebc05488 | bellard | #endif
|
3456 | 048f6b4d | bellard | #ifdef TARGET_NR_vfork
|
3457 | 31e31b8a | bellard | case TARGET_NR_vfork:
|
3458 | 1b6b029e | bellard | ret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD, 0));
|
3459 | 31e31b8a | bellard | break;
|
3460 | 048f6b4d | bellard | #endif
|
3461 | ebc05488 | bellard | #ifdef TARGET_NR_ugetrlimit
|
3462 | 31e31b8a | bellard | case TARGET_NR_ugetrlimit:
|
3463 | 728584be | bellard | { |
3464 | 728584be | bellard | struct rlimit rlim;
|
3465 | 728584be | bellard | ret = get_errno(getrlimit(arg1, &rlim)); |
3466 | 728584be | bellard | if (!is_error(ret)) {
|
3467 | 53a5960a | pbrook | struct target_rlimit *target_rlim;
|
3468 | 53a5960a | pbrook | lock_user_struct(target_rlim, arg2, 0);
|
3469 | 728584be | bellard | target_rlim->rlim_cur = tswapl(rlim.rlim_cur); |
3470 | 728584be | bellard | target_rlim->rlim_max = tswapl(rlim.rlim_max); |
3471 | 53a5960a | pbrook | unlock_user_struct(target_rlim, arg2, 1);
|
3472 | 728584be | bellard | } |
3473 | 728584be | bellard | break;
|
3474 | 728584be | bellard | } |
3475 | ebc05488 | bellard | #endif
|
3476 | a315a145 | bellard | #ifdef TARGET_NR_truncate64
|
3477 | 31e31b8a | bellard | case TARGET_NR_truncate64:
|
3478 | 53a5960a | pbrook | p = lock_user_string(arg1); |
3479 | 53a5960a | pbrook | ret = target_truncate64(cpu_env, p, arg2, arg3, arg4); |
3480 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
3481 | 667f38b1 | bellard | break;
|
3482 | a315a145 | bellard | #endif
|
3483 | a315a145 | bellard | #ifdef TARGET_NR_ftruncate64
|
3484 | 31e31b8a | bellard | case TARGET_NR_ftruncate64:
|
3485 | ce4defa0 | pbrook | ret = target_ftruncate64(cpu_env, arg1, arg2, arg3, arg4); |
3486 | 667f38b1 | bellard | break;
|
3487 | a315a145 | bellard | #endif
|
3488 | a315a145 | bellard | #ifdef TARGET_NR_stat64
|
3489 | 31e31b8a | bellard | case TARGET_NR_stat64:
|
3490 | 53a5960a | pbrook | p = lock_user_string(arg1); |
3491 | 53a5960a | pbrook | ret = get_errno(stat(path(p), &st)); |
3492 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
3493 | 60cd49d5 | bellard | goto do_stat64;
|
3494 | a315a145 | bellard | #endif
|
3495 | a315a145 | bellard | #ifdef TARGET_NR_lstat64
|
3496 | 31e31b8a | bellard | case TARGET_NR_lstat64:
|
3497 | 53a5960a | pbrook | p = lock_user_string(arg1); |
3498 | 53a5960a | pbrook | ret = get_errno(lstat(path(p), &st)); |
3499 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
3500 | 60cd49d5 | bellard | goto do_stat64;
|
3501 | a315a145 | bellard | #endif
|
3502 | a315a145 | bellard | #ifdef TARGET_NR_fstat64
|
3503 | 31e31b8a | bellard | case TARGET_NR_fstat64:
|
3504 | 60cd49d5 | bellard | { |
3505 | 60cd49d5 | bellard | ret = get_errno(fstat(arg1, &st)); |
3506 | 60cd49d5 | bellard | do_stat64:
|
3507 | 60cd49d5 | bellard | if (!is_error(ret)) {
|
3508 | ce4defa0 | pbrook | #ifdef TARGET_ARM
|
3509 | ce4defa0 | pbrook | if (((CPUARMState *)cpu_env)->eabi) {
|
3510 | 53a5960a | pbrook | struct target_eabi_stat64 *target_st;
|
3511 | 53a5960a | pbrook | lock_user_struct(target_st, arg2, 1);
|
3512 | ce4defa0 | pbrook | memset(target_st, 0, sizeof(struct target_eabi_stat64)); |
3513 | 53a5960a | pbrook | /* put_user is probably wrong. */
|
3514 | ce4defa0 | pbrook | put_user(st.st_dev, &target_st->st_dev); |
3515 | ce4defa0 | pbrook | put_user(st.st_ino, &target_st->st_ino); |
3516 | ce4defa0 | pbrook | #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
|
3517 | ce4defa0 | pbrook | put_user(st.st_ino, &target_st->__st_ino); |
3518 | ce4defa0 | pbrook | #endif
|
3519 | ce4defa0 | pbrook | put_user(st.st_mode, &target_st->st_mode); |
3520 | ce4defa0 | pbrook | put_user(st.st_nlink, &target_st->st_nlink); |
3521 | ce4defa0 | pbrook | put_user(st.st_uid, &target_st->st_uid); |
3522 | ce4defa0 | pbrook | put_user(st.st_gid, &target_st->st_gid); |
3523 | ce4defa0 | pbrook | put_user(st.st_rdev, &target_st->st_rdev); |
3524 | ce4defa0 | pbrook | /* XXX: better use of kernel struct */
|
3525 | ce4defa0 | pbrook | put_user(st.st_size, &target_st->st_size); |
3526 | ce4defa0 | pbrook | put_user(st.st_blksize, &target_st->st_blksize); |
3527 | ce4defa0 | pbrook | put_user(st.st_blocks, &target_st->st_blocks); |
3528 | ce4defa0 | pbrook | put_user(st.st_atime, &target_st->target_st_atime); |
3529 | ce4defa0 | pbrook | put_user(st.st_mtime, &target_st->target_st_mtime); |
3530 | ce4defa0 | pbrook | put_user(st.st_ctime, &target_st->target_st_ctime); |
3531 | 53a5960a | pbrook | unlock_user_struct(target_st, arg2, 0);
|
3532 | ce4defa0 | pbrook | } else
|
3533 | ce4defa0 | pbrook | #endif
|
3534 | ce4defa0 | pbrook | { |
3535 | 53a5960a | pbrook | struct target_stat64 *target_st;
|
3536 | 53a5960a | pbrook | lock_user_struct(target_st, arg2, 1);
|
3537 | ce4defa0 | pbrook | memset(target_st, 0, sizeof(struct target_stat64)); |
3538 | 53a5960a | pbrook | /* ??? put_user is probably wrong. */
|
3539 | ce4defa0 | pbrook | put_user(st.st_dev, &target_st->st_dev); |
3540 | ce4defa0 | pbrook | put_user(st.st_ino, &target_st->st_ino); |
3541 | ec86b0fb | bellard | #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
|
3542 | ce4defa0 | pbrook | put_user(st.st_ino, &target_st->__st_ino); |
3543 | ce4defa0 | pbrook | #endif
|
3544 | ce4defa0 | pbrook | put_user(st.st_mode, &target_st->st_mode); |
3545 | ce4defa0 | pbrook | put_user(st.st_nlink, &target_st->st_nlink); |
3546 | ce4defa0 | pbrook | put_user(st.st_uid, &target_st->st_uid); |
3547 | ce4defa0 | pbrook | put_user(st.st_gid, &target_st->st_gid); |
3548 | ce4defa0 | pbrook | put_user(st.st_rdev, &target_st->st_rdev); |
3549 | ce4defa0 | pbrook | /* XXX: better use of kernel struct */
|
3550 | ce4defa0 | pbrook | put_user(st.st_size, &target_st->st_size); |
3551 | ce4defa0 | pbrook | put_user(st.st_blksize, &target_st->st_blksize); |
3552 | ce4defa0 | pbrook | put_user(st.st_blocks, &target_st->st_blocks); |
3553 | ce4defa0 | pbrook | put_user(st.st_atime, &target_st->target_st_atime); |
3554 | ce4defa0 | pbrook | put_user(st.st_mtime, &target_st->target_st_mtime); |
3555 | ce4defa0 | pbrook | put_user(st.st_ctime, &target_st->target_st_ctime); |
3556 | 53a5960a | pbrook | unlock_user_struct(target_st, arg2, 0);
|
3557 | ce4defa0 | pbrook | } |
3558 | 60cd49d5 | bellard | } |
3559 | 60cd49d5 | bellard | } |
3560 | 60cd49d5 | bellard | break;
|
3561 | a315a145 | bellard | #endif
|
3562 | 67867308 | bellard | #ifdef USE_UID16
|
3563 | 67867308 | bellard | case TARGET_NR_lchown:
|
3564 | 53a5960a | pbrook | p = lock_user_string(arg1); |
3565 | 53a5960a | pbrook | ret = get_errno(lchown(p, low2highuid(arg2), low2highgid(arg3))); |
3566 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
3567 | 67867308 | bellard | break;
|
3568 | 67867308 | bellard | case TARGET_NR_getuid:
|
3569 | 67867308 | bellard | ret = get_errno(high2lowuid(getuid())); |
3570 | 67867308 | bellard | break;
|
3571 | 67867308 | bellard | case TARGET_NR_getgid:
|
3572 | 67867308 | bellard | ret = get_errno(high2lowgid(getgid())); |
3573 | 67867308 | bellard | break;
|
3574 | 67867308 | bellard | case TARGET_NR_geteuid:
|
3575 | 67867308 | bellard | ret = get_errno(high2lowuid(geteuid())); |
3576 | 67867308 | bellard | break;
|
3577 | 67867308 | bellard | case TARGET_NR_getegid:
|
3578 | 67867308 | bellard | ret = get_errno(high2lowgid(getegid())); |
3579 | 67867308 | bellard | break;
|
3580 | 67867308 | bellard | case TARGET_NR_setreuid:
|
3581 | 67867308 | bellard | ret = get_errno(setreuid(low2highuid(arg1), low2highuid(arg2))); |
3582 | 67867308 | bellard | break;
|
3583 | 67867308 | bellard | case TARGET_NR_setregid:
|
3584 | 67867308 | bellard | ret = get_errno(setregid(low2highgid(arg1), low2highgid(arg2))); |
3585 | 67867308 | bellard | break;
|
3586 | 67867308 | bellard | case TARGET_NR_getgroups:
|
3587 | 67867308 | bellard | { |
3588 | 67867308 | bellard | int gidsetsize = arg1;
|
3589 | 53a5960a | pbrook | uint16_t *target_grouplist; |
3590 | 67867308 | bellard | gid_t *grouplist; |
3591 | 67867308 | bellard | int i;
|
3592 | 67867308 | bellard | |
3593 | 67867308 | bellard | grouplist = alloca(gidsetsize * sizeof(gid_t));
|
3594 | 67867308 | bellard | ret = get_errno(getgroups(gidsetsize, grouplist)); |
3595 | 67867308 | bellard | if (!is_error(ret)) {
|
3596 | 53a5960a | pbrook | target_grouplist = lock_user(arg2, gidsetsize * 2, 0); |
3597 | 67867308 | bellard | for(i = 0;i < gidsetsize; i++) |
3598 | 67867308 | bellard | target_grouplist[i] = tswap16(grouplist[i]); |
3599 | 53a5960a | pbrook | unlock_user(target_grouplist, arg2, gidsetsize * 2);
|
3600 | 67867308 | bellard | } |
3601 | 67867308 | bellard | } |
3602 | 67867308 | bellard | break;
|
3603 | 67867308 | bellard | case TARGET_NR_setgroups:
|
3604 | 67867308 | bellard | { |
3605 | 67867308 | bellard | int gidsetsize = arg1;
|
3606 | 53a5960a | pbrook | uint16_t *target_grouplist; |
3607 | 67867308 | bellard | gid_t *grouplist; |
3608 | 67867308 | bellard | int i;
|
3609 | 67867308 | bellard | |
3610 | 67867308 | bellard | grouplist = alloca(gidsetsize * sizeof(gid_t));
|
3611 | 53a5960a | pbrook | target_grouplist = lock_user(arg2, gidsetsize * 2, 1); |
3612 | 67867308 | bellard | for(i = 0;i < gidsetsize; i++) |
3613 | 67867308 | bellard | grouplist[i] = tswap16(target_grouplist[i]); |
3614 | 53a5960a | pbrook | unlock_user(target_grouplist, arg2, 0);
|
3615 | 67867308 | bellard | ret = get_errno(setgroups(gidsetsize, grouplist)); |
3616 | 67867308 | bellard | } |
3617 | 67867308 | bellard | break;
|
3618 | 67867308 | bellard | case TARGET_NR_fchown:
|
3619 | 67867308 | bellard | ret = get_errno(fchown(arg1, low2highuid(arg2), low2highgid(arg3))); |
3620 | 67867308 | bellard | break;
|
3621 | 67867308 | bellard | #ifdef TARGET_NR_setresuid
|
3622 | 67867308 | bellard | case TARGET_NR_setresuid:
|
3623 | 67867308 | bellard | ret = get_errno(setresuid(low2highuid(arg1), |
3624 | 67867308 | bellard | low2highuid(arg2), |
3625 | 67867308 | bellard | low2highuid(arg3))); |
3626 | 67867308 | bellard | break;
|
3627 | 67867308 | bellard | #endif
|
3628 | 67867308 | bellard | #ifdef TARGET_NR_getresuid
|
3629 | 67867308 | bellard | case TARGET_NR_getresuid:
|
3630 | 67867308 | bellard | { |
3631 | 53a5960a | pbrook | uid_t ruid, euid, suid; |
3632 | 67867308 | bellard | ret = get_errno(getresuid(&ruid, &euid, &suid)); |
3633 | 67867308 | bellard | if (!is_error(ret)) {
|
3634 | 53a5960a | pbrook | tput16(arg1, tswap16(high2lowuid(ruid))); |
3635 | 53a5960a | pbrook | tput16(arg2, tswap16(high2lowuid(euid))); |
3636 | 53a5960a | pbrook | tput16(arg3, tswap16(high2lowuid(suid))); |
3637 | 67867308 | bellard | } |
3638 | 67867308 | bellard | } |
3639 | 67867308 | bellard | break;
|
3640 | 67867308 | bellard | #endif
|
3641 | 67867308 | bellard | #ifdef TARGET_NR_getresgid
|
3642 | 67867308 | bellard | case TARGET_NR_setresgid:
|
3643 | 67867308 | bellard | ret = get_errno(setresgid(low2highgid(arg1), |
3644 | 67867308 | bellard | low2highgid(arg2), |
3645 | 67867308 | bellard | low2highgid(arg3))); |
3646 | 67867308 | bellard | break;
|
3647 | 67867308 | bellard | #endif
|
3648 | 67867308 | bellard | #ifdef TARGET_NR_getresgid
|
3649 | 67867308 | bellard | case TARGET_NR_getresgid:
|
3650 | 67867308 | bellard | { |
3651 | 53a5960a | pbrook | gid_t rgid, egid, sgid; |
3652 | 67867308 | bellard | ret = get_errno(getresgid(&rgid, &egid, &sgid)); |
3653 | 67867308 | bellard | if (!is_error(ret)) {
|
3654 | 53a5960a | pbrook | tput16(arg1, tswap16(high2lowgid(rgid))); |
3655 | 53a5960a | pbrook | tput16(arg2, tswap16(high2lowgid(egid))); |
3656 | 53a5960a | pbrook | tput16(arg3, tswap16(high2lowgid(sgid))); |
3657 | 67867308 | bellard | } |
3658 | 67867308 | bellard | } |
3659 | 67867308 | bellard | break;
|
3660 | 67867308 | bellard | #endif
|
3661 | 67867308 | bellard | case TARGET_NR_chown:
|
3662 | 53a5960a | pbrook | p = lock_user_string(arg1); |
3663 | 53a5960a | pbrook | ret = get_errno(chown(p, low2highuid(arg2), low2highgid(arg3))); |
3664 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
3665 | 67867308 | bellard | break;
|
3666 | 67867308 | bellard | case TARGET_NR_setuid:
|
3667 | 67867308 | bellard | ret = get_errno(setuid(low2highuid(arg1))); |
3668 | 67867308 | bellard | break;
|
3669 | 67867308 | bellard | case TARGET_NR_setgid:
|
3670 | 67867308 | bellard | ret = get_errno(setgid(low2highgid(arg1))); |
3671 | 67867308 | bellard | break;
|
3672 | 67867308 | bellard | case TARGET_NR_setfsuid:
|
3673 | 67867308 | bellard | ret = get_errno(setfsuid(arg1)); |
3674 | 67867308 | bellard | break;
|
3675 | 67867308 | bellard | case TARGET_NR_setfsgid:
|
3676 | 67867308 | bellard | ret = get_errno(setfsgid(arg1)); |
3677 | 67867308 | bellard | break;
|
3678 | 67867308 | bellard | #endif /* USE_UID16 */ |
3679 | 67867308 | bellard | |
3680 | a315a145 | bellard | #ifdef TARGET_NR_lchown32
|
3681 | 31e31b8a | bellard | case TARGET_NR_lchown32:
|
3682 | 53a5960a | pbrook | p = lock_user_string(arg1); |
3683 | 53a5960a | pbrook | ret = get_errno(lchown(p, arg2, arg3)); |
3684 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
3685 | b03c60f3 | bellard | break;
|
3686 | a315a145 | bellard | #endif
|
3687 | a315a145 | bellard | #ifdef TARGET_NR_getuid32
|
3688 | 31e31b8a | bellard | case TARGET_NR_getuid32:
|
3689 | b03c60f3 | bellard | ret = get_errno(getuid()); |
3690 | b03c60f3 | bellard | break;
|
3691 | a315a145 | bellard | #endif
|
3692 | a315a145 | bellard | #ifdef TARGET_NR_getgid32
|
3693 | 31e31b8a | bellard | case TARGET_NR_getgid32:
|
3694 | b03c60f3 | bellard | ret = get_errno(getgid()); |
3695 | b03c60f3 | bellard | break;
|
3696 | a315a145 | bellard | #endif
|
3697 | a315a145 | bellard | #ifdef TARGET_NR_geteuid32
|
3698 | 31e31b8a | bellard | case TARGET_NR_geteuid32:
|
3699 | b03c60f3 | bellard | ret = get_errno(geteuid()); |
3700 | b03c60f3 | bellard | break;
|
3701 | a315a145 | bellard | #endif
|
3702 | a315a145 | bellard | #ifdef TARGET_NR_getegid32
|
3703 | 31e31b8a | bellard | case TARGET_NR_getegid32:
|
3704 | b03c60f3 | bellard | ret = get_errno(getegid()); |
3705 | b03c60f3 | bellard | break;
|
3706 | a315a145 | bellard | #endif
|
3707 | a315a145 | bellard | #ifdef TARGET_NR_setreuid32
|
3708 | 31e31b8a | bellard | case TARGET_NR_setreuid32:
|
3709 | b03c60f3 | bellard | ret = get_errno(setreuid(arg1, arg2)); |
3710 | b03c60f3 | bellard | break;
|
3711 | a315a145 | bellard | #endif
|
3712 | a315a145 | bellard | #ifdef TARGET_NR_setregid32
|
3713 | 31e31b8a | bellard | case TARGET_NR_setregid32:
|
3714 | b03c60f3 | bellard | ret = get_errno(setregid(arg1, arg2)); |
3715 | b03c60f3 | bellard | break;
|
3716 | a315a145 | bellard | #endif
|
3717 | a315a145 | bellard | #ifdef TARGET_NR_getgroups32
|
3718 | 31e31b8a | bellard | case TARGET_NR_getgroups32:
|
3719 | 99c475ab | bellard | { |
3720 | 99c475ab | bellard | int gidsetsize = arg1;
|
3721 | 53a5960a | pbrook | uint32_t *target_grouplist; |
3722 | 99c475ab | bellard | gid_t *grouplist; |
3723 | 99c475ab | bellard | int i;
|
3724 | 99c475ab | bellard | |
3725 | 99c475ab | bellard | grouplist = alloca(gidsetsize * sizeof(gid_t));
|
3726 | 99c475ab | bellard | ret = get_errno(getgroups(gidsetsize, grouplist)); |
3727 | 99c475ab | bellard | if (!is_error(ret)) {
|
3728 | 53a5960a | pbrook | target_grouplist = lock_user(arg2, gidsetsize * 4, 0); |
3729 | 99c475ab | bellard | for(i = 0;i < gidsetsize; i++) |
3730 | 53a5960a | pbrook | target_grouplist[i] = tswap32(grouplist[i]); |
3731 | 53a5960a | pbrook | unlock_user(target_grouplist, arg2, gidsetsize * 4);
|
3732 | 99c475ab | bellard | } |
3733 | 99c475ab | bellard | } |
3734 | 99c475ab | bellard | break;
|
3735 | a315a145 | bellard | #endif
|
3736 | a315a145 | bellard | #ifdef TARGET_NR_setgroups32
|
3737 | 31e31b8a | bellard | case TARGET_NR_setgroups32:
|
3738 | 99c475ab | bellard | { |
3739 | 99c475ab | bellard | int gidsetsize = arg1;
|
3740 | 53a5960a | pbrook | uint32_t *target_grouplist; |
3741 | 99c475ab | bellard | gid_t *grouplist; |
3742 | 99c475ab | bellard | int i;
|
3743 | 99c475ab | bellard | |
3744 | 99c475ab | bellard | grouplist = alloca(gidsetsize * sizeof(gid_t));
|
3745 | 53a5960a | pbrook | target_grouplist = lock_user(arg2, gidsetsize * 4, 1); |
3746 | 99c475ab | bellard | for(i = 0;i < gidsetsize; i++) |
3747 | 53a5960a | pbrook | grouplist[i] = tswap32(target_grouplist[i]); |
3748 | 53a5960a | pbrook | unlock_user(target_grouplist, arg2, 0);
|
3749 | 99c475ab | bellard | ret = get_errno(setgroups(gidsetsize, grouplist)); |
3750 | 99c475ab | bellard | } |
3751 | 99c475ab | bellard | break;
|
3752 | a315a145 | bellard | #endif
|
3753 | a315a145 | bellard | #ifdef TARGET_NR_fchown32
|
3754 | 31e31b8a | bellard | case TARGET_NR_fchown32:
|
3755 | b03c60f3 | bellard | ret = get_errno(fchown(arg1, arg2, arg3)); |
3756 | b03c60f3 | bellard | break;
|
3757 | a315a145 | bellard | #endif
|
3758 | a315a145 | bellard | #ifdef TARGET_NR_setresuid32
|
3759 | 31e31b8a | bellard | case TARGET_NR_setresuid32:
|
3760 | b03c60f3 | bellard | ret = get_errno(setresuid(arg1, arg2, arg3)); |
3761 | b03c60f3 | bellard | break;
|
3762 | a315a145 | bellard | #endif
|
3763 | a315a145 | bellard | #ifdef TARGET_NR_getresuid32
|
3764 | 31e31b8a | bellard | case TARGET_NR_getresuid32:
|
3765 | b03c60f3 | bellard | { |
3766 | 53a5960a | pbrook | uid_t ruid, euid, suid; |
3767 | b03c60f3 | bellard | ret = get_errno(getresuid(&ruid, &euid, &suid)); |
3768 | b03c60f3 | bellard | if (!is_error(ret)) {
|
3769 | 53a5960a | pbrook | tput32(arg1, tswap32(ruid)); |
3770 | 53a5960a | pbrook | tput32(arg2, tswap32(euid)); |
3771 | 53a5960a | pbrook | tput32(arg3, tswap32(suid)); |
3772 | b03c60f3 | bellard | } |
3773 | b03c60f3 | bellard | } |
3774 | b03c60f3 | bellard | break;
|
3775 | a315a145 | bellard | #endif
|
3776 | a315a145 | bellard | #ifdef TARGET_NR_setresgid32
|
3777 | 31e31b8a | bellard | case TARGET_NR_setresgid32:
|
3778 | b03c60f3 | bellard | ret = get_errno(setresgid(arg1, arg2, arg3)); |
3779 | b03c60f3 | bellard | break;
|
3780 | a315a145 | bellard | #endif
|
3781 | a315a145 | bellard | #ifdef TARGET_NR_getresgid32
|
3782 | 31e31b8a | bellard | case TARGET_NR_getresgid32:
|
3783 | b03c60f3 | bellard | { |
3784 | 53a5960a | pbrook | gid_t rgid, egid, sgid; |
3785 | b03c60f3 | bellard | ret = get_errno(getresgid(&rgid, &egid, &sgid)); |
3786 | b03c60f3 | bellard | if (!is_error(ret)) {
|
3787 | 53a5960a | pbrook | tput32(arg1, tswap32(rgid)); |
3788 | 53a5960a | pbrook | tput32(arg2, tswap32(egid)); |
3789 | 53a5960a | pbrook | tput32(arg3, tswap32(sgid)); |
3790 | b03c60f3 | bellard | } |
3791 | b03c60f3 | bellard | } |
3792 | b03c60f3 | bellard | break;
|
3793 | a315a145 | bellard | #endif
|
3794 | a315a145 | bellard | #ifdef TARGET_NR_chown32
|
3795 | 31e31b8a | bellard | case TARGET_NR_chown32:
|
3796 | 53a5960a | pbrook | p = lock_user_string(arg1); |
3797 | 53a5960a | pbrook | ret = get_errno(chown(p, arg2, arg3)); |
3798 | 53a5960a | pbrook | unlock_user(p, arg1, 0);
|
3799 | b03c60f3 | bellard | break;
|
3800 | a315a145 | bellard | #endif
|
3801 | a315a145 | bellard | #ifdef TARGET_NR_setuid32
|
3802 | 31e31b8a | bellard | case TARGET_NR_setuid32:
|
3803 | b03c60f3 | bellard | ret = get_errno(setuid(arg1)); |
3804 | b03c60f3 | bellard | break;
|
3805 | a315a145 | bellard | #endif
|
3806 | a315a145 | bellard | #ifdef TARGET_NR_setgid32
|
3807 | 31e31b8a | bellard | case TARGET_NR_setgid32:
|
3808 | b03c60f3 | bellard | ret = get_errno(setgid(arg1)); |
3809 | b03c60f3 | bellard | break;
|
3810 | a315a145 | bellard | #endif
|
3811 | a315a145 | bellard | #ifdef TARGET_NR_setfsuid32
|
3812 | 31e31b8a | bellard | case TARGET_NR_setfsuid32:
|
3813 | b03c60f3 | bellard | ret = get_errno(setfsuid(arg1)); |
3814 | b03c60f3 | bellard | break;
|
3815 | a315a145 | bellard | #endif
|
3816 | a315a145 | bellard | #ifdef TARGET_NR_setfsgid32
|
3817 | 31e31b8a | bellard | case TARGET_NR_setfsgid32:
|
3818 | b03c60f3 | bellard | ret = get_errno(setfsgid(arg1)); |
3819 | b03c60f3 | bellard | break;
|
3820 | a315a145 | bellard | #endif
|
3821 | 67867308 | bellard | |
3822 | 31e31b8a | bellard | case TARGET_NR_pivot_root:
|
3823 | b03c60f3 | bellard | goto unimplemented;
|
3824 | ffa65c3b | bellard | #ifdef TARGET_NR_mincore
|
3825 | 31e31b8a | bellard | case TARGET_NR_mincore:
|
3826 | b03c60f3 | bellard | goto unimplemented;
|
3827 | ffa65c3b | bellard | #endif
|
3828 | ffa65c3b | bellard | #ifdef TARGET_NR_madvise
|
3829 | 31e31b8a | bellard | case TARGET_NR_madvise:
|
3830 | 24836689 | pbrook | /* A straight passthrough may not be safe because qemu sometimes
|
3831 | 24836689 | pbrook | turns private flie-backed mappings into anonymous mappings.
|
3832 | 24836689 | pbrook | This will break MADV_DONTNEED.
|
3833 | 24836689 | pbrook | This is a hint, so ignoring and returning success is ok. */
|
3834 | 24836689 | pbrook | ret = get_errno(0);
|
3835 | 24836689 | pbrook | break;
|
3836 | ffa65c3b | bellard | #endif
|
3837 | 60cd49d5 | bellard | #if TARGET_LONG_BITS == 32 |
3838 | 31e31b8a | bellard | case TARGET_NR_fcntl64:
|
3839 | 77e4672d | bellard | { |
3840 | 77e4672d | bellard | struct flock64 fl;
|
3841 | 53a5960a | pbrook | struct target_flock64 *target_fl;
|
3842 | ce4defa0 | pbrook | #ifdef TARGET_ARM
|
3843 | 53a5960a | pbrook | struct target_eabi_flock64 *target_efl;
|
3844 | ce4defa0 | pbrook | #endif
|
3845 | 77e4672d | bellard | |
3846 | 60cd49d5 | bellard | switch(arg2) {
|
3847 | 60cd49d5 | bellard | case F_GETLK64:
|
3848 | 77e4672d | bellard | ret = get_errno(fcntl(arg1, arg2, &fl)); |
3849 | 77e4672d | bellard | if (ret == 0) { |
3850 | ce4defa0 | pbrook | #ifdef TARGET_ARM
|
3851 | ce4defa0 | pbrook | if (((CPUARMState *)cpu_env)->eabi) {
|
3852 | 53a5960a | pbrook | lock_user_struct(target_efl, arg3, 0);
|
3853 | ce4defa0 | pbrook | target_efl->l_type = tswap16(fl.l_type); |
3854 | ce4defa0 | pbrook | target_efl->l_whence = tswap16(fl.l_whence); |
3855 | ce4defa0 | pbrook | target_efl->l_start = tswap64(fl.l_start); |
3856 | ce4defa0 | pbrook | target_efl->l_len = tswap64(fl.l_len); |
3857 | ce4defa0 | pbrook | target_efl->l_pid = tswapl(fl.l_pid); |
3858 | 53a5960a | pbrook | unlock_user_struct(target_efl, arg3, 1);
|
3859 | ce4defa0 | pbrook | } else
|
3860 | ce4defa0 | pbrook | #endif
|
3861 | ce4defa0 | pbrook | { |
3862 | 53a5960a | pbrook | lock_user_struct(target_fl, arg3, 0);
|
3863 | ce4defa0 | pbrook | target_fl->l_type = tswap16(fl.l_type); |
3864 | ce4defa0 | pbrook | target_fl->l_whence = tswap16(fl.l_whence); |
3865 | ce4defa0 | pbrook | target_fl->l_start = tswap64(fl.l_start); |
3866 | ce4defa0 | pbrook | target_fl->l_len = tswap64(fl.l_len); |
3867 | ce4defa0 | pbrook | target_fl->l_pid = tswapl(fl.l_pid); |
3868 | 53a5960a | pbrook | unlock_user_struct(target_fl, arg3, 1);
|
3869 | ce4defa0 | pbrook | } |
3870 | 77e4672d | bellard | } |
3871 | 77e4672d | bellard | break;
|
3872 | 77e4672d | bellard | |
3873 | 60cd49d5 | bellard | case F_SETLK64:
|
3874 | 60cd49d5 | bellard | case F_SETLKW64:
|
3875 | ce4defa0 | pbrook | #ifdef TARGET_ARM
|
3876 | ce4defa0 | pbrook | if (((CPUARMState *)cpu_env)->eabi) {
|
3877 | 53a5960a | pbrook | lock_user_struct(target_efl, arg3, 1);
|
3878 | ce4defa0 | pbrook | fl.l_type = tswap16(target_efl->l_type); |
3879 | ce4defa0 | pbrook | fl.l_whence = tswap16(target_efl->l_whence); |
3880 | ce4defa0 | pbrook | fl.l_start = tswap64(target_efl->l_start); |
3881 | ce4defa0 | pbrook | fl.l_len = tswap64(target_efl->l_len); |
3882 | ce4defa0 | pbrook | fl.l_pid = tswapl(target_efl->l_pid); |
3883 | 53a5960a | pbrook | unlock_user_struct(target_efl, arg3, 0);
|
3884 | ce4defa0 | pbrook | } else
|
3885 | ce4defa0 | pbrook | #endif
|
3886 | ce4defa0 | pbrook | { |
3887 | 53a5960a | pbrook | lock_user_struct(target_fl, arg3, 1);
|
3888 | ce4defa0 | pbrook | fl.l_type = tswap16(target_fl->l_type); |
3889 | ce4defa0 | pbrook | fl.l_whence = tswap16(target_fl->l_whence); |
3890 | ce4defa0 | pbrook | fl.l_start = tswap64(target_fl->l_start); |
3891 | ce4defa0 | pbrook | fl.l_len = tswap64(target_fl->l_len); |
3892 | ce4defa0 | pbrook | fl.l_pid = tswapl(target_fl->l_pid); |
3893 | 53a5960a | pbrook | unlock_user_struct(target_fl, arg3, 0);
|
3894 | ce4defa0 | pbrook | } |
3895 | 77e4672d | bellard | ret = get_errno(fcntl(arg1, arg2, &fl)); |
3896 | 77e4672d | bellard | break;
|
3897 | 60cd49d5 | bellard | default:
|
3898 | 7775e9ec | bellard | ret = get_errno(do_fcntl(arg1, arg2, arg3)); |
3899 | 60cd49d5 | bellard | break;
|
3900 | 60cd49d5 | bellard | } |
3901 | 77e4672d | bellard | break;
|
3902 | 77e4672d | bellard | } |
3903 | 60cd49d5 | bellard | #endif
|
3904 | 7d600c80 | ths | #ifdef TARGET_NR_cacheflush
|
3905 | 7d600c80 | ths | case TARGET_NR_cacheflush:
|
3906 | 7d600c80 | ths | /* self-modifying code is handled automatically, so nothing needed */
|
3907 | 7d600c80 | ths | ret = 0;
|
3908 | 7d600c80 | ths | break;
|
3909 | 7d600c80 | ths | #endif
|
3910 | ebc05488 | bellard | #ifdef TARGET_NR_security
|
3911 | 31e31b8a | bellard | case TARGET_NR_security:
|
3912 | 31e31b8a | bellard | goto unimplemented;
|
3913 | ebc05488 | bellard | #endif
|
3914 | c573ff67 | bellard | #ifdef TARGET_NR_getpagesize
|
3915 | c573ff67 | bellard | case TARGET_NR_getpagesize:
|
3916 | c573ff67 | bellard | ret = TARGET_PAGE_SIZE; |
3917 | c573ff67 | bellard | break;
|
3918 | c573ff67 | bellard | #endif
|
3919 | 31e31b8a | bellard | case TARGET_NR_gettid:
|
3920 | 31e31b8a | bellard | ret = get_errno(gettid()); |
3921 | 31e31b8a | bellard | break;
|
3922 | 31e31b8a | bellard | case TARGET_NR_readahead:
|
3923 | 5cd4393b | bellard | goto unimplemented;
|
3924 | ebc05488 | bellard | #ifdef TARGET_NR_setxattr
|
3925 | 31e31b8a | bellard | case TARGET_NR_setxattr:
|
3926 | 31e31b8a | bellard | case TARGET_NR_lsetxattr:
|
3927 | 31e31b8a | bellard | case TARGET_NR_fsetxattr:
|
3928 | 31e31b8a | bellard | case TARGET_NR_getxattr:
|
3929 | 31e31b8a | bellard | case TARGET_NR_lgetxattr:
|
3930 | 31e31b8a | bellard | case TARGET_NR_fgetxattr:
|
3931 | 31e31b8a | bellard | case TARGET_NR_listxattr:
|
3932 | 31e31b8a | bellard | case TARGET_NR_llistxattr:
|
3933 | 31e31b8a | bellard | case TARGET_NR_flistxattr:
|
3934 | 31e31b8a | bellard | case TARGET_NR_removexattr:
|
3935 | 31e31b8a | bellard | case TARGET_NR_lremovexattr:
|
3936 | 31e31b8a | bellard | case TARGET_NR_fremovexattr:
|
3937 | 5cd4393b | bellard | goto unimplemented_nowarn;
|
3938 | ebc05488 | bellard | #endif
|
3939 | ebc05488 | bellard | #ifdef TARGET_NR_set_thread_area
|
3940 | 5cd4393b | bellard | case TARGET_NR_set_thread_area:
|
3941 | 5cd4393b | bellard | case TARGET_NR_get_thread_area:
|
3942 | 5cd4393b | bellard | goto unimplemented_nowarn;
|
3943 | ebc05488 | bellard | #endif
|
3944 | 48dc41eb | bellard | #ifdef TARGET_NR_getdomainname
|
3945 | 48dc41eb | bellard | case TARGET_NR_getdomainname:
|
3946 | 48dc41eb | bellard | goto unimplemented_nowarn;
|
3947 | 48dc41eb | bellard | #endif
|
3948 | 31e31b8a | bellard | default:
|
3949 | 31e31b8a | bellard | unimplemented:
|
3950 | 5cd4393b | bellard | gemu_log("qemu: Unsupported syscall: %d\n", num);
|
3951 | 48dc41eb | bellard | #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_set_thread_area) || defined(TARGET_NR_getdomainname)
|
3952 | 5cd4393b | bellard | unimplemented_nowarn:
|
3953 | 80a9d035 | bellard | #endif
|
3954 | 31e31b8a | bellard | ret = -ENOSYS; |
3955 | 31e31b8a | bellard | break;
|
3956 | 31e31b8a | bellard | } |
3957 | 31e31b8a | bellard | fail:
|
3958 | c573ff67 | bellard | #ifdef DEBUG
|
3959 | c573ff67 | bellard | gemu_log(" = %ld\n", ret);
|
3960 | c573ff67 | bellard | #endif
|
3961 | 31e31b8a | bellard | return ret;
|
3962 | 31e31b8a | bellard | } |