]>
Commit | Line | Data |
---|---|---|
31e31b8a FB |
1 | /* |
2 | * Linux syscalls | |
5fafdf24 | 3 | * |
31e31b8a FB |
4 | * Copyright (c) 2003 Fabrice Bellard |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 | */ | |
20 | #include <stdlib.h> | |
21 | #include <stdio.h> | |
22 | #include <stdarg.h> | |
04369ff2 | 23 | #include <string.h> |
31e31b8a FB |
24 | #include <elf.h> |
25 | #include <endian.h> | |
26 | #include <errno.h> | |
27 | #include <unistd.h> | |
28 | #include <fcntl.h> | |
7854b056 | 29 | #include <time.h> |
31e31b8a | 30 | #include <sys/types.h> |
d08d3bb8 TS |
31 | #include <sys/ipc.h> |
32 | #include <sys/msg.h> | |
31e31b8a FB |
33 | #include <sys/wait.h> |
34 | #include <sys/time.h> | |
35 | #include <sys/stat.h> | |
36 | #include <sys/mount.h> | |
39b9aae1 | 37 | #include <sys/prctl.h> |
31e31b8a FB |
38 | #include <sys/resource.h> |
39 | #include <sys/mman.h> | |
40 | #include <sys/swap.h> | |
41 | #include <signal.h> | |
42 | #include <sched.h> | |
43 | #include <sys/socket.h> | |
44 | #include <sys/uio.h> | |
9de5e440 | 45 | #include <sys/poll.h> |
32f36bce | 46 | #include <sys/times.h> |
8853f86e | 47 | #include <sys/shm.h> |
fa294816 | 48 | #include <sys/sem.h> |
56c8f68f | 49 | #include <sys/statfs.h> |
ebc05488 | 50 | #include <utime.h> |
a5448a7d | 51 | #include <sys/sysinfo.h> |
72f03900 | 52 | //#include <sys/user.h> |
8853f86e | 53 | #include <netinet/ip.h> |
7854b056 | 54 | #include <netinet/tcp.h> |
31e31b8a FB |
55 | |
56 | #define termios host_termios | |
57 | #define winsize host_winsize | |
58 | #define termio host_termio | |
04369ff2 FB |
59 | #define sgttyb host_sgttyb /* same as target */ |
60 | #define tchars host_tchars /* same as target */ | |
61 | #define ltchars host_ltchars /* same as target */ | |
31e31b8a FB |
62 | |
63 | #include <linux/termios.h> | |
64 | #include <linux/unistd.h> | |
65 | #include <linux/utsname.h> | |
66 | #include <linux/cdrom.h> | |
67 | #include <linux/hdreg.h> | |
68 | #include <linux/soundcard.h> | |
dab2ed99 | 69 | #include <linux/dirent.h> |
19b84f3c | 70 | #include <linux/kd.h> |
31e31b8a | 71 | |
3ef693a0 | 72 | #include "qemu.h" |
31e31b8a | 73 | |
72f03900 | 74 | //#define DEBUG |
31e31b8a | 75 | |
e6e5906b | 76 | #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC) \ |
48733d19 | 77 | || defined(TARGET_M68K) || defined(TARGET_SH4) || defined(TARGET_CRIS) |
67867308 FB |
78 | /* 16 bit uid wrappers emulation */ |
79 | #define USE_UID16 | |
80 | #endif | |
81 | ||
1a9353d2 FB |
82 | //#include <linux/msdos_fs.h> |
83 | #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2]) | |
84 | #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2]) | |
85 | ||
70a194b9 | 86 | |
70a194b9 FB |
87 | #undef _syscall0 |
88 | #undef _syscall1 | |
89 | #undef _syscall2 | |
90 | #undef _syscall3 | |
91 | #undef _syscall4 | |
92 | #undef _syscall5 | |
83fcb515 | 93 | #undef _syscall6 |
70a194b9 | 94 | |
83fcb515 FB |
95 | #define _syscall0(type,name) \ |
96 | type name (void) \ | |
97 | { \ | |
98 | return syscall(__NR_##name); \ | |
99 | } | |
70a194b9 | 100 | |
83fcb515 FB |
101 | #define _syscall1(type,name,type1,arg1) \ |
102 | type name (type1 arg1) \ | |
103 | { \ | |
104 | return syscall(__NR_##name, arg1); \ | |
70a194b9 FB |
105 | } |
106 | ||
83fcb515 FB |
107 | #define _syscall2(type,name,type1,arg1,type2,arg2) \ |
108 | type name (type1 arg1,type2 arg2) \ | |
109 | { \ | |
110 | return syscall(__NR_##name, arg1, arg2); \ | |
70a194b9 FB |
111 | } |
112 | ||
83fcb515 FB |
113 | #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ |
114 | type name (type1 arg1,type2 arg2,type3 arg3) \ | |
115 | { \ | |
116 | return syscall(__NR_##name, arg1, arg2, arg3); \ | |
70a194b9 FB |
117 | } |
118 | ||
83fcb515 FB |
119 | #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \ |
120 | type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4) \ | |
121 | { \ | |
122 | return syscall(__NR_##name, arg1, arg2, arg3, arg4); \ | |
70a194b9 FB |
123 | } |
124 | ||
83fcb515 FB |
125 | #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ |
126 | type5,arg5) \ | |
127 | type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \ | |
128 | { \ | |
129 | return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5); \ | |
70a194b9 FB |
130 | } |
131 | ||
83fcb515 FB |
132 | |
133 | #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ | |
134 | type5,arg5,type6,arg6) \ | |
135 | type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \ | |
136 | { \ | |
137 | return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5, arg6); \ | |
70a194b9 | 138 | } |
83fcb515 | 139 | |
70a194b9 | 140 | |
31e31b8a | 141 | #define __NR_sys_uname __NR_uname |
92a34c10 | 142 | #define __NR_sys_faccessat __NR_faccessat |
814d7977 | 143 | #define __NR_sys_fchmodat __NR_fchmodat |
ccfa72b7 | 144 | #define __NR_sys_fchownat __NR_fchownat |
72f03900 | 145 | #define __NR_sys_getcwd1 __NR_getcwd |
72f03900 | 146 | #define __NR_sys_getdents __NR_getdents |
dab2ed99 | 147 | #define __NR_sys_getdents64 __NR_getdents64 |
c6cda17a | 148 | #define __NR_sys_getpriority __NR_getpriority |
64f0ce4c | 149 | #define __NR_sys_linkat __NR_linkat |
4472ad0d | 150 | #define __NR_sys_mkdirat __NR_mkdirat |
75ac37a0 | 151 | #define __NR_sys_mknodat __NR_mknodat |
82424832 | 152 | #define __NR_sys_openat __NR_openat |
5e0ccb18 | 153 | #define __NR_sys_readlinkat __NR_readlinkat |
722183f6 | 154 | #define __NR_sys_renameat __NR_renameat |
66fb9763 | 155 | #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo |
f0b6243d | 156 | #define __NR_sys_symlinkat __NR_symlinkat |
7494b0f9 | 157 | #define __NR_sys_syslog __NR_syslog |
71455574 | 158 | #define __NR_sys_tgkill __NR_tgkill |
4cae1d16 | 159 | #define __NR_sys_tkill __NR_tkill |
8170f56b | 160 | #define __NR_sys_unlinkat __NR_unlinkat |
9007f0ef | 161 | #define __NR_sys_utimensat __NR_utimensat |
31e31b8a | 162 | |
bc51c5c9 | 163 | #if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__) |
9af9eaaa FB |
164 | #define __NR__llseek __NR_lseek |
165 | #endif | |
166 | ||
72f03900 | 167 | #ifdef __NR_gettid |
31e31b8a | 168 | _syscall0(int, gettid) |
72f03900 | 169 | #else |
0da46a6e TS |
170 | /* This is a replacement for the host gettid() and must return a host |
171 | errno. */ | |
72f03900 FB |
172 | static int gettid(void) { |
173 | return -ENOSYS; | |
174 | } | |
175 | #endif | |
31e31b8a | 176 | _syscall1(int,sys_uname,struct new_utsname *,buf) |
92a34c10 TS |
177 | #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat) |
178 | _syscall4(int,sys_faccessat,int,dirfd,const char *,pathname,int,mode,int,flags) | |
179 | #endif | |
814d7977 TS |
180 | #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat) |
181 | _syscall4(int,sys_fchmodat,int,dirfd,const char *,pathname, | |
182 | mode_t,mode,int,flags) | |
183 | #endif | |
ccfa72b7 TS |
184 | #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat) |
185 | _syscall5(int,sys_fchownat,int,dirfd,const char *,pathname, | |
186 | uid_t,owner,gid_t,group,int,flags) | |
187 | #endif | |
72f03900 FB |
188 | _syscall2(int,sys_getcwd1,char *,buf,size_t,size) |
189 | _syscall3(int, sys_getdents, uint, fd, struct dirent *, dirp, uint, count); | |
3ae43202 | 190 | #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64) |
dab2ed99 | 191 | _syscall3(int, sys_getdents64, uint, fd, struct dirent64 *, dirp, uint, count); |
3ae43202 | 192 | #endif |
c6cda17a | 193 | _syscall2(int, sys_getpriority, int, which, int, who); |
31e31b8a FB |
194 | _syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo, |
195 | loff_t *, res, uint, wh); | |
64f0ce4c TS |
196 | #if defined(TARGET_NR_linkat) && defined(__NR_linkat) |
197 | _syscall5(int,sys_linkat,int,olddirfd,const char *,oldpath, | |
198 | int,newdirfd,const char *,newpath,int,flags) | |
199 | #endif | |
4472ad0d TS |
200 | #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat) |
201 | _syscall3(int,sys_mkdirat,int,dirfd,const char *,pathname,mode_t,mode) | |
202 | #endif | |
75ac37a0 TS |
203 | #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat) |
204 | _syscall4(int,sys_mknodat,int,dirfd,const char *,pathname, | |
205 | mode_t,mode,dev_t,dev) | |
206 | #endif | |
82424832 TS |
207 | #if defined(TARGET_NR_openat) && defined(__NR_openat) |
208 | _syscall4(int,sys_openat,int,dirfd,const char *,pathname,int,flags,mode_t,mode) | |
209 | #endif | |
5e0ccb18 TS |
210 | #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat) |
211 | _syscall4(int,sys_readlinkat,int,dirfd,const char *,pathname, | |
212 | char *,buf,size_t,bufsize) | |
213 | #endif | |
722183f6 TS |
214 | #if defined(TARGET_NR_renameat) && defined(__NR_renameat) |
215 | _syscall4(int,sys_renameat,int,olddirfd,const char *,oldpath, | |
216 | int,newdirfd,const char *,newpath) | |
217 | #endif | |
66fb9763 | 218 | _syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo) |
b51eaa82 | 219 | #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat) |
f0b6243d TS |
220 | _syscall3(int,sys_symlinkat,const char *,oldpath, |
221 | int,newdirfd,const char *,newpath) | |
222 | #endif | |
7494b0f9 | 223 | _syscall3(int,sys_syslog,int,type,char*,bufp,int,len) |
3ae43202 | 224 | #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill) |
71455574 | 225 | _syscall3(int,sys_tgkill,int,tgid,int,pid,int,sig) |
4cae1d16 | 226 | #endif |
3ae43202 | 227 | #if defined(TARGET_NR_tkill) && defined(__NR_tkill) |
4cae1d16 TS |
228 | _syscall2(int,sys_tkill,int,tid,int,sig) |
229 | #endif | |
ec86b0fb FB |
230 | #ifdef __NR_exit_group |
231 | _syscall1(int,exit_group,int,error_code) | |
232 | #endif | |
6f5b89a0 TS |
233 | #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address) |
234 | _syscall1(int,set_tid_address,int *,tidptr) | |
235 | #endif | |
8170f56b TS |
236 | #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat) |
237 | _syscall3(int,sys_unlinkat,int,dirfd,const char *,pathname,int,flags) | |
238 | #endif | |
9007f0ef TS |
239 | #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat) |
240 | _syscall4(int,sys_utimensat,int,dirfd,const char *,pathname, | |
241 | const struct timespec *,tsp,int,flags) | |
242 | #endif | |
66fb9763 FB |
243 | |
244 | extern int personality(int); | |
9de5e440 FB |
245 | extern int flock(int, int); |
246 | extern int setfsuid(int); | |
247 | extern int setfsgid(int); | |
5cd4393b FB |
248 | extern int setresuid(uid_t, uid_t, uid_t); |
249 | extern int getresuid(uid_t *, uid_t *, uid_t *); | |
250 | extern int setresgid(gid_t, gid_t, gid_t); | |
251 | extern int getresgid(gid_t *, gid_t *, gid_t *); | |
19b84f3c | 252 | extern int setgroups(int, gid_t *); |
31e31b8a | 253 | |
b92c47c1 TS |
254 | #define ERRNO_TABLE_SIZE 1200 |
255 | ||
256 | /* target_to_host_errno_table[] is initialized from | |
257 | * host_to_target_errno_table[] in syscall_init(). */ | |
258 | static uint16_t target_to_host_errno_table[ERRNO_TABLE_SIZE] = { | |
259 | }; | |
260 | ||
637947f1 | 261 | /* |
fe8f096b | 262 | * This list is the union of errno values overridden in asm-<arch>/errno.h |
637947f1 TS |
263 | * minus the errnos that are not actually generic to all archs. |
264 | */ | |
b92c47c1 | 265 | static uint16_t host_to_target_errno_table[ERRNO_TABLE_SIZE] = { |
637947f1 TS |
266 | [EIDRM] = TARGET_EIDRM, |
267 | [ECHRNG] = TARGET_ECHRNG, | |
268 | [EL2NSYNC] = TARGET_EL2NSYNC, | |
269 | [EL3HLT] = TARGET_EL3HLT, | |
270 | [EL3RST] = TARGET_EL3RST, | |
271 | [ELNRNG] = TARGET_ELNRNG, | |
272 | [EUNATCH] = TARGET_EUNATCH, | |
273 | [ENOCSI] = TARGET_ENOCSI, | |
274 | [EL2HLT] = TARGET_EL2HLT, | |
275 | [EDEADLK] = TARGET_EDEADLK, | |
276 | [ENOLCK] = TARGET_ENOLCK, | |
277 | [EBADE] = TARGET_EBADE, | |
278 | [EBADR] = TARGET_EBADR, | |
279 | [EXFULL] = TARGET_EXFULL, | |
280 | [ENOANO] = TARGET_ENOANO, | |
281 | [EBADRQC] = TARGET_EBADRQC, | |
282 | [EBADSLT] = TARGET_EBADSLT, | |
283 | [EBFONT] = TARGET_EBFONT, | |
284 | [ENOSTR] = TARGET_ENOSTR, | |
285 | [ENODATA] = TARGET_ENODATA, | |
286 | [ETIME] = TARGET_ETIME, | |
287 | [ENOSR] = TARGET_ENOSR, | |
288 | [ENONET] = TARGET_ENONET, | |
289 | [ENOPKG] = TARGET_ENOPKG, | |
290 | [EREMOTE] = TARGET_EREMOTE, | |
291 | [ENOLINK] = TARGET_ENOLINK, | |
292 | [EADV] = TARGET_EADV, | |
293 | [ESRMNT] = TARGET_ESRMNT, | |
294 | [ECOMM] = TARGET_ECOMM, | |
295 | [EPROTO] = TARGET_EPROTO, | |
296 | [EDOTDOT] = TARGET_EDOTDOT, | |
297 | [EMULTIHOP] = TARGET_EMULTIHOP, | |
298 | [EBADMSG] = TARGET_EBADMSG, | |
299 | [ENAMETOOLONG] = TARGET_ENAMETOOLONG, | |
300 | [EOVERFLOW] = TARGET_EOVERFLOW, | |
301 | [ENOTUNIQ] = TARGET_ENOTUNIQ, | |
302 | [EBADFD] = TARGET_EBADFD, | |
303 | [EREMCHG] = TARGET_EREMCHG, | |
304 | [ELIBACC] = TARGET_ELIBACC, | |
305 | [ELIBBAD] = TARGET_ELIBBAD, | |
306 | [ELIBSCN] = TARGET_ELIBSCN, | |
307 | [ELIBMAX] = TARGET_ELIBMAX, | |
308 | [ELIBEXEC] = TARGET_ELIBEXEC, | |
309 | [EILSEQ] = TARGET_EILSEQ, | |
310 | [ENOSYS] = TARGET_ENOSYS, | |
311 | [ELOOP] = TARGET_ELOOP, | |
312 | [ERESTART] = TARGET_ERESTART, | |
313 | [ESTRPIPE] = TARGET_ESTRPIPE, | |
314 | [ENOTEMPTY] = TARGET_ENOTEMPTY, | |
315 | [EUSERS] = TARGET_EUSERS, | |
316 | [ENOTSOCK] = TARGET_ENOTSOCK, | |
317 | [EDESTADDRREQ] = TARGET_EDESTADDRREQ, | |
318 | [EMSGSIZE] = TARGET_EMSGSIZE, | |
319 | [EPROTOTYPE] = TARGET_EPROTOTYPE, | |
320 | [ENOPROTOOPT] = TARGET_ENOPROTOOPT, | |
321 | [EPROTONOSUPPORT] = TARGET_EPROTONOSUPPORT, | |
322 | [ESOCKTNOSUPPORT] = TARGET_ESOCKTNOSUPPORT, | |
323 | [EOPNOTSUPP] = TARGET_EOPNOTSUPP, | |
324 | [EPFNOSUPPORT] = TARGET_EPFNOSUPPORT, | |
325 | [EAFNOSUPPORT] = TARGET_EAFNOSUPPORT, | |
326 | [EADDRINUSE] = TARGET_EADDRINUSE, | |
327 | [EADDRNOTAVAIL] = TARGET_EADDRNOTAVAIL, | |
328 | [ENETDOWN] = TARGET_ENETDOWN, | |
329 | [ENETUNREACH] = TARGET_ENETUNREACH, | |
330 | [ENETRESET] = TARGET_ENETRESET, | |
331 | [ECONNABORTED] = TARGET_ECONNABORTED, | |
332 | [ECONNRESET] = TARGET_ECONNRESET, | |
333 | [ENOBUFS] = TARGET_ENOBUFS, | |
334 | [EISCONN] = TARGET_EISCONN, | |
335 | [ENOTCONN] = TARGET_ENOTCONN, | |
336 | [EUCLEAN] = TARGET_EUCLEAN, | |
337 | [ENOTNAM] = TARGET_ENOTNAM, | |
338 | [ENAVAIL] = TARGET_ENAVAIL, | |
339 | [EISNAM] = TARGET_EISNAM, | |
340 | [EREMOTEIO] = TARGET_EREMOTEIO, | |
341 | [ESHUTDOWN] = TARGET_ESHUTDOWN, | |
342 | [ETOOMANYREFS] = TARGET_ETOOMANYREFS, | |
343 | [ETIMEDOUT] = TARGET_ETIMEDOUT, | |
344 | [ECONNREFUSED] = TARGET_ECONNREFUSED, | |
345 | [EHOSTDOWN] = TARGET_EHOSTDOWN, | |
346 | [EHOSTUNREACH] = TARGET_EHOSTUNREACH, | |
347 | [EALREADY] = TARGET_EALREADY, | |
348 | [EINPROGRESS] = TARGET_EINPROGRESS, | |
349 | [ESTALE] = TARGET_ESTALE, | |
350 | [ECANCELED] = TARGET_ECANCELED, | |
351 | [ENOMEDIUM] = TARGET_ENOMEDIUM, | |
352 | [EMEDIUMTYPE] = TARGET_EMEDIUMTYPE, | |
b7fe5db7 | 353 | #ifdef ENOKEY |
637947f1 | 354 | [ENOKEY] = TARGET_ENOKEY, |
b7fe5db7 TS |
355 | #endif |
356 | #ifdef EKEYEXPIRED | |
637947f1 | 357 | [EKEYEXPIRED] = TARGET_EKEYEXPIRED, |
b7fe5db7 TS |
358 | #endif |
359 | #ifdef EKEYREVOKED | |
637947f1 | 360 | [EKEYREVOKED] = TARGET_EKEYREVOKED, |
b7fe5db7 TS |
361 | #endif |
362 | #ifdef EKEYREJECTED | |
637947f1 | 363 | [EKEYREJECTED] = TARGET_EKEYREJECTED, |
b7fe5db7 TS |
364 | #endif |
365 | #ifdef EOWNERDEAD | |
637947f1 | 366 | [EOWNERDEAD] = TARGET_EOWNERDEAD, |
b7fe5db7 TS |
367 | #endif |
368 | #ifdef ENOTRECOVERABLE | |
637947f1 | 369 | [ENOTRECOVERABLE] = TARGET_ENOTRECOVERABLE, |
b7fe5db7 | 370 | #endif |
b92c47c1 | 371 | }; |
637947f1 TS |
372 | |
373 | static inline int host_to_target_errno(int err) | |
374 | { | |
375 | if(host_to_target_errno_table[err]) | |
376 | return host_to_target_errno_table[err]; | |
377 | return err; | |
378 | } | |
379 | ||
b92c47c1 TS |
380 | static inline int target_to_host_errno(int err) |
381 | { | |
382 | if (target_to_host_errno_table[err]) | |
383 | return target_to_host_errno_table[err]; | |
384 | return err; | |
385 | } | |
386 | ||
992f48a0 | 387 | static inline abi_long get_errno(abi_long ret) |
31e31b8a FB |
388 | { |
389 | if (ret == -1) | |
637947f1 | 390 | return -host_to_target_errno(errno); |
31e31b8a FB |
391 | else |
392 | return ret; | |
393 | } | |
394 | ||
992f48a0 | 395 | static inline int is_error(abi_long ret) |
31e31b8a | 396 | { |
992f48a0 | 397 | return (abi_ulong)ret >= (abi_ulong)(-4096); |
31e31b8a FB |
398 | } |
399 | ||
b92c47c1 TS |
400 | char *target_strerror(int err) |
401 | { | |
402 | return strerror(target_to_host_errno(err)); | |
403 | } | |
404 | ||
992f48a0 BS |
405 | static abi_ulong target_brk; |
406 | static abi_ulong target_original_brk; | |
31e31b8a | 407 | |
992f48a0 | 408 | void target_set_brk(abi_ulong new_brk) |
31e31b8a | 409 | { |
4c1de73d | 410 | target_original_brk = target_brk = HOST_PAGE_ALIGN(new_brk); |
31e31b8a FB |
411 | } |
412 | ||
0da46a6e | 413 | /* do_brk() must return target values and target errnos. */ |
992f48a0 | 414 | abi_long do_brk(abi_ulong new_brk) |
31e31b8a | 415 | { |
992f48a0 BS |
416 | abi_ulong brk_page; |
417 | abi_long mapped_addr; | |
31e31b8a FB |
418 | int new_alloc_size; |
419 | ||
420 | if (!new_brk) | |
53a5960a | 421 | return target_brk; |
31e31b8a | 422 | if (new_brk < target_original_brk) |
0da46a6e | 423 | return -TARGET_ENOMEM; |
3b46e624 | 424 | |
53a5960a | 425 | brk_page = HOST_PAGE_ALIGN(target_brk); |
31e31b8a FB |
426 | |
427 | /* If the new brk is less than this, set it and we're done... */ | |
428 | if (new_brk < brk_page) { | |
429 | target_brk = new_brk; | |
53a5960a | 430 | return target_brk; |
31e31b8a FB |
431 | } |
432 | ||
433 | /* We need to allocate more memory after the brk... */ | |
54936004 | 434 | new_alloc_size = HOST_PAGE_ALIGN(new_brk - brk_page + 1); |
5fafdf24 | 435 | mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size, |
54936004 FB |
436 | PROT_READ|PROT_WRITE, |
437 | MAP_ANON|MAP_FIXED|MAP_PRIVATE, 0, 0)); | |
31e31b8a FB |
438 | if (is_error(mapped_addr)) { |
439 | return mapped_addr; | |
440 | } else { | |
441 | target_brk = new_brk; | |
53a5960a | 442 | return target_brk; |
31e31b8a FB |
443 | } |
444 | } | |
445 | ||
5fafdf24 | 446 | static inline fd_set *target_to_host_fds(fd_set *fds, |
992f48a0 | 447 | abi_long *target_fds, int n) |
31e31b8a | 448 | { |
7854b056 | 449 | #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN) |
31e31b8a FB |
450 | return (fd_set *)target_fds; |
451 | #else | |
452 | int i, b; | |
453 | if (target_fds) { | |
454 | FD_ZERO(fds); | |
455 | for(i = 0;i < n; i++) { | |
992f48a0 BS |
456 | b = (tswapl(target_fds[i / TARGET_ABI_BITS]) >> |
457 | (i & (TARGET_ABI_BITS - 1))) & 1; | |
31e31b8a FB |
458 | if (b) |
459 | FD_SET(i, fds); | |
460 | } | |
461 | return fds; | |
462 | } else { | |
463 | return NULL; | |
464 | } | |
465 | #endif | |
466 | } | |
467 | ||
992f48a0 | 468 | static inline void host_to_target_fds(abi_long *target_fds, |
31e31b8a FB |
469 | fd_set *fds, int n) |
470 | { | |
7854b056 | 471 | #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN) |
31e31b8a FB |
472 | /* nothing to do */ |
473 | #else | |
474 | int i, nw, j, k; | |
992f48a0 | 475 | abi_long v; |
31e31b8a FB |
476 | |
477 | if (target_fds) { | |
992f48a0 | 478 | nw = (n + TARGET_ABI_BITS - 1) / TARGET_ABI_BITS; |
31e31b8a FB |
479 | k = 0; |
480 | for(i = 0;i < nw; i++) { | |
481 | v = 0; | |
992f48a0 | 482 | for(j = 0; j < TARGET_ABI_BITS; j++) { |
31e31b8a FB |
483 | v |= ((FD_ISSET(k, fds) != 0) << j); |
484 | k++; | |
485 | } | |
486 | target_fds[i] = tswapl(v); | |
487 | } | |
488 | } | |
489 | #endif | |
490 | } | |
491 | ||
c596ed17 FB |
492 | #if defined(__alpha__) |
493 | #define HOST_HZ 1024 | |
494 | #else | |
495 | #define HOST_HZ 100 | |
496 | #endif | |
497 | ||
992f48a0 | 498 | static inline abi_long host_to_target_clock_t(long ticks) |
c596ed17 FB |
499 | { |
500 | #if HOST_HZ == TARGET_HZ | |
501 | return ticks; | |
502 | #else | |
503 | return ((int64_t)ticks * TARGET_HZ) / HOST_HZ; | |
504 | #endif | |
505 | } | |
506 | ||
992f48a0 | 507 | static inline void host_to_target_rusage(abi_ulong target_addr, |
b409186b FB |
508 | const struct rusage *rusage) |
509 | { | |
53a5960a PB |
510 | struct target_rusage *target_rusage; |
511 | ||
512 | lock_user_struct(target_rusage, target_addr, 0); | |
b409186b FB |
513 | target_rusage->ru_utime.tv_sec = tswapl(rusage->ru_utime.tv_sec); |
514 | target_rusage->ru_utime.tv_usec = tswapl(rusage->ru_utime.tv_usec); | |
515 | target_rusage->ru_stime.tv_sec = tswapl(rusage->ru_stime.tv_sec); | |
516 | target_rusage->ru_stime.tv_usec = tswapl(rusage->ru_stime.tv_usec); | |
517 | target_rusage->ru_maxrss = tswapl(rusage->ru_maxrss); | |
518 | target_rusage->ru_ixrss = tswapl(rusage->ru_ixrss); | |
519 | target_rusage->ru_idrss = tswapl(rusage->ru_idrss); | |
520 | target_rusage->ru_isrss = tswapl(rusage->ru_isrss); | |
521 | target_rusage->ru_minflt = tswapl(rusage->ru_minflt); | |
522 | target_rusage->ru_majflt = tswapl(rusage->ru_majflt); | |
523 | target_rusage->ru_nswap = tswapl(rusage->ru_nswap); | |
524 | target_rusage->ru_inblock = tswapl(rusage->ru_inblock); | |
525 | target_rusage->ru_oublock = tswapl(rusage->ru_oublock); | |
526 | target_rusage->ru_msgsnd = tswapl(rusage->ru_msgsnd); | |
527 | target_rusage->ru_msgrcv = tswapl(rusage->ru_msgrcv); | |
528 | target_rusage->ru_nsignals = tswapl(rusage->ru_nsignals); | |
529 | target_rusage->ru_nvcsw = tswapl(rusage->ru_nvcsw); | |
530 | target_rusage->ru_nivcsw = tswapl(rusage->ru_nivcsw); | |
53a5960a | 531 | unlock_user_struct(target_rusage, target_addr, 1); |
b409186b FB |
532 | } |
533 | ||
53a5960a | 534 | static inline void target_to_host_timeval(struct timeval *tv, |
992f48a0 | 535 | abi_ulong target_addr) |
31e31b8a | 536 | { |
53a5960a PB |
537 | struct target_timeval *target_tv; |
538 | ||
539 | lock_user_struct(target_tv, target_addr, 1); | |
66fb9763 FB |
540 | tv->tv_sec = tswapl(target_tv->tv_sec); |
541 | tv->tv_usec = tswapl(target_tv->tv_usec); | |
53a5960a | 542 | unlock_user_struct(target_tv, target_addr, 0); |
31e31b8a FB |
543 | } |
544 | ||
992f48a0 | 545 | static inline void host_to_target_timeval(abi_ulong target_addr, |
5cd4393b | 546 | const struct timeval *tv) |
31e31b8a | 547 | { |
53a5960a PB |
548 | struct target_timeval *target_tv; |
549 | ||
550 | lock_user_struct(target_tv, target_addr, 0); | |
66fb9763 FB |
551 | target_tv->tv_sec = tswapl(tv->tv_sec); |
552 | target_tv->tv_usec = tswapl(tv->tv_usec); | |
53a5960a | 553 | unlock_user_struct(target_tv, target_addr, 1); |
31e31b8a FB |
554 | } |
555 | ||
556 | ||
0da46a6e | 557 | /* do_select() must return target values and target errnos. */ |
992f48a0 BS |
558 | static abi_long do_select(int n, |
559 | abi_ulong rfd_p, abi_ulong wfd_p, | |
560 | abi_ulong efd_p, abi_ulong target_tv) | |
31e31b8a FB |
561 | { |
562 | fd_set rfds, wfds, efds; | |
563 | fd_set *rfds_ptr, *wfds_ptr, *efds_ptr; | |
992f48a0 | 564 | abi_long *target_rfds, *target_wfds, *target_efds; |
31e31b8a | 565 | struct timeval tv, *tv_ptr; |
992f48a0 | 566 | abi_long ret; |
53a5960a | 567 | int ok; |
31e31b8a | 568 | |
53a5960a | 569 | if (rfd_p) { |
992f48a0 | 570 | target_rfds = lock_user(rfd_p, sizeof(abi_long) * n, 1); |
53a5960a PB |
571 | rfds_ptr = target_to_host_fds(&rfds, target_rfds, n); |
572 | } else { | |
573 | target_rfds = NULL; | |
574 | rfds_ptr = NULL; | |
575 | } | |
576 | if (wfd_p) { | |
992f48a0 | 577 | target_wfds = lock_user(wfd_p, sizeof(abi_long) * n, 1); |
53a5960a PB |
578 | wfds_ptr = target_to_host_fds(&wfds, target_wfds, n); |
579 | } else { | |
580 | target_wfds = NULL; | |
581 | wfds_ptr = NULL; | |
582 | } | |
583 | if (efd_p) { | |
992f48a0 | 584 | target_efds = lock_user(efd_p, sizeof(abi_long) * n, 1); |
53a5960a PB |
585 | efds_ptr = target_to_host_fds(&efds, target_efds, n); |
586 | } else { | |
587 | target_efds = NULL; | |
588 | efds_ptr = NULL; | |
589 | } | |
3b46e624 | 590 | |
31e31b8a | 591 | if (target_tv) { |
5cd4393b | 592 | target_to_host_timeval(&tv, target_tv); |
31e31b8a FB |
593 | tv_ptr = &tv; |
594 | } else { | |
595 | tv_ptr = NULL; | |
596 | } | |
597 | ret = get_errno(select(n, rfds_ptr, wfds_ptr, efds_ptr, tv_ptr)); | |
53a5960a PB |
598 | ok = !is_error(ret); |
599 | ||
600 | if (ok) { | |
31e31b8a FB |
601 | host_to_target_fds(target_rfds, rfds_ptr, n); |
602 | host_to_target_fds(target_wfds, wfds_ptr, n); | |
603 | host_to_target_fds(target_efds, efds_ptr, n); | |
604 | ||
605 | if (target_tv) { | |
5cd4393b | 606 | host_to_target_timeval(target_tv, &tv); |
31e31b8a FB |
607 | } |
608 | } | |
53a5960a | 609 | if (target_rfds) |
992f48a0 | 610 | unlock_user(target_rfds, rfd_p, ok ? sizeof(abi_long) * n : 0); |
53a5960a | 611 | if (target_wfds) |
992f48a0 | 612 | unlock_user(target_wfds, wfd_p, ok ? sizeof(abi_long) * n : 0); |
53a5960a | 613 | if (target_efds) |
992f48a0 | 614 | unlock_user(target_efds, efd_p, ok ? sizeof(abi_long) * n : 0); |
53a5960a | 615 | |
31e31b8a FB |
616 | return ret; |
617 | } | |
618 | ||
7854b056 | 619 | static inline void target_to_host_sockaddr(struct sockaddr *addr, |
992f48a0 | 620 | abi_ulong target_addr, |
7854b056 FB |
621 | socklen_t len) |
622 | { | |
53a5960a PB |
623 | struct target_sockaddr *target_saddr; |
624 | ||
625 | target_saddr = lock_user(target_addr, len, 1); | |
626 | memcpy(addr, target_saddr, len); | |
627 | addr->sa_family = tswap16(target_saddr->sa_family); | |
628 | unlock_user(target_saddr, target_addr, 0); | |
7854b056 FB |
629 | } |
630 | ||
992f48a0 | 631 | static inline void host_to_target_sockaddr(abi_ulong target_addr, |
7854b056 FB |
632 | struct sockaddr *addr, |
633 | socklen_t len) | |
634 | { | |
53a5960a PB |
635 | struct target_sockaddr *target_saddr; |
636 | ||
637 | target_saddr = lock_user(target_addr, len, 0); | |
638 | memcpy(target_saddr, addr, len); | |
639 | target_saddr->sa_family = tswap16(addr->sa_family); | |
640 | unlock_user(target_saddr, target_addr, len); | |
7854b056 FB |
641 | } |
642 | ||
53a5960a | 643 | /* ??? Should this also swap msgh->name? */ |
7854b056 FB |
644 | static inline void target_to_host_cmsg(struct msghdr *msgh, |
645 | struct target_msghdr *target_msgh) | |
646 | { | |
647 | struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh); | |
648 | struct target_cmsghdr *target_cmsg = TARGET_CMSG_FIRSTHDR(target_msgh); | |
649 | socklen_t space = 0; | |
650 | ||
651 | while (cmsg && target_cmsg) { | |
652 | void *data = CMSG_DATA(cmsg); | |
653 | void *target_data = TARGET_CMSG_DATA(target_cmsg); | |
654 | ||
5fafdf24 | 655 | int len = tswapl(target_cmsg->cmsg_len) |
7854b056 FB |
656 | - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr)); |
657 | ||
658 | space += CMSG_SPACE(len); | |
659 | if (space > msgh->msg_controllen) { | |
660 | space -= CMSG_SPACE(len); | |
31febb71 | 661 | gemu_log("Host cmsg overflow\n"); |
7854b056 FB |
662 | break; |
663 | } | |
664 | ||
665 | cmsg->cmsg_level = tswap32(target_cmsg->cmsg_level); | |
666 | cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type); | |
667 | cmsg->cmsg_len = CMSG_LEN(len); | |
668 | ||
3532fa74 | 669 | if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) { |
7854b056 FB |
670 | gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type); |
671 | memcpy(data, target_data, len); | |
672 | } else { | |
673 | int *fd = (int *)data; | |
674 | int *target_fd = (int *)target_data; | |
675 | int i, numfds = len / sizeof(int); | |
676 | ||
677 | for (i = 0; i < numfds; i++) | |
678 | fd[i] = tswap32(target_fd[i]); | |
679 | } | |
680 | ||
681 | cmsg = CMSG_NXTHDR(msgh, cmsg); | |
682 | target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg); | |
683 | } | |
684 | ||
685 | msgh->msg_controllen = space; | |
686 | } | |
687 | ||
53a5960a | 688 | /* ??? Should this also swap msgh->name? */ |
7854b056 FB |
689 | static inline void host_to_target_cmsg(struct target_msghdr *target_msgh, |
690 | struct msghdr *msgh) | |
691 | { | |
692 | struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh); | |
693 | struct target_cmsghdr *target_cmsg = TARGET_CMSG_FIRSTHDR(target_msgh); | |
694 | socklen_t space = 0; | |
695 | ||
696 | while (cmsg && target_cmsg) { | |
697 | void *data = CMSG_DATA(cmsg); | |
698 | void *target_data = TARGET_CMSG_DATA(target_cmsg); | |
699 | ||
700 | int len = cmsg->cmsg_len - CMSG_ALIGN(sizeof (struct cmsghdr)); | |
701 | ||
702 | space += TARGET_CMSG_SPACE(len); | |
703 | if (space > tswapl(target_msgh->msg_controllen)) { | |
704 | space -= TARGET_CMSG_SPACE(len); | |
31febb71 | 705 | gemu_log("Target cmsg overflow\n"); |
7854b056 FB |
706 | break; |
707 | } | |
708 | ||
709 | target_cmsg->cmsg_level = tswap32(cmsg->cmsg_level); | |
710 | target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type); | |
711 | target_cmsg->cmsg_len = tswapl(TARGET_CMSG_LEN(len)); | |
712 | ||
3532fa74 | 713 | if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) { |
7854b056 FB |
714 | gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type); |
715 | memcpy(target_data, data, len); | |
716 | } else { | |
717 | int *fd = (int *)data; | |
718 | int *target_fd = (int *)target_data; | |
719 | int i, numfds = len / sizeof(int); | |
720 | ||
721 | for (i = 0; i < numfds; i++) | |
722 | target_fd[i] = tswap32(fd[i]); | |
723 | } | |
724 | ||
725 | cmsg = CMSG_NXTHDR(msgh, cmsg); | |
726 | target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg); | |
727 | } | |
728 | ||
729 | msgh->msg_controllen = tswapl(space); | |
730 | } | |
731 | ||
0da46a6e | 732 | /* do_setsockopt() Must return target values and target errnos. */ |
992f48a0 BS |
733 | static abi_long do_setsockopt(int sockfd, int level, int optname, |
734 | abi_ulong optval, socklen_t optlen) | |
7854b056 | 735 | { |
992f48a0 | 736 | abi_long ret; |
32407103 | 737 | int val; |
3b46e624 | 738 | |
8853f86e FB |
739 | switch(level) { |
740 | case SOL_TCP: | |
7854b056 | 741 | /* TCP options all take an 'int' value. */ |
7854b056 | 742 | if (optlen < sizeof(uint32_t)) |
0da46a6e | 743 | return -TARGET_EINVAL; |
3b46e624 | 744 | |
53a5960a | 745 | val = tget32(optval); |
8853f86e FB |
746 | ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val))); |
747 | break; | |
748 | case SOL_IP: | |
749 | switch(optname) { | |
2efbe911 FB |
750 | case IP_TOS: |
751 | case IP_TTL: | |
8853f86e | 752 | case IP_HDRINCL: |
2efbe911 FB |
753 | case IP_ROUTER_ALERT: |
754 | case IP_RECVOPTS: | |
755 | case IP_RETOPTS: | |
756 | case IP_PKTINFO: | |
757 | case IP_MTU_DISCOVER: | |
758 | case IP_RECVERR: | |
759 | case IP_RECVTOS: | |
760 | #ifdef IP_FREEBIND | |
761 | case IP_FREEBIND: | |
762 | #endif | |
763 | case IP_MULTICAST_TTL: | |
764 | case IP_MULTICAST_LOOP: | |
8853f86e FB |
765 | val = 0; |
766 | if (optlen >= sizeof(uint32_t)) { | |
53a5960a | 767 | val = tget32(optval); |
8853f86e | 768 | } else if (optlen >= 1) { |
53a5960a | 769 | val = tget8(optval); |
8853f86e FB |
770 | } |
771 | ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val))); | |
772 | break; | |
773 | default: | |
774 | goto unimplemented; | |
775 | } | |
776 | break; | |
3532fa74 | 777 | case TARGET_SOL_SOCKET: |
8853f86e FB |
778 | switch (optname) { |
779 | /* Options with 'int' argument. */ | |
3532fa74 FB |
780 | case TARGET_SO_DEBUG: |
781 | optname = SO_DEBUG; | |
782 | break; | |
783 | case TARGET_SO_REUSEADDR: | |
784 | optname = SO_REUSEADDR; | |
785 | break; | |
786 | case TARGET_SO_TYPE: | |
787 | optname = SO_TYPE; | |
788 | break; | |
789 | case TARGET_SO_ERROR: | |
790 | optname = SO_ERROR; | |
791 | break; | |
792 | case TARGET_SO_DONTROUTE: | |
793 | optname = SO_DONTROUTE; | |
794 | break; | |
795 | case TARGET_SO_BROADCAST: | |
796 | optname = SO_BROADCAST; | |
797 | break; | |
798 | case TARGET_SO_SNDBUF: | |
799 | optname = SO_SNDBUF; | |
800 | break; | |
801 | case TARGET_SO_RCVBUF: | |
802 | optname = SO_RCVBUF; | |
803 | break; | |
804 | case TARGET_SO_KEEPALIVE: | |
805 | optname = SO_KEEPALIVE; | |
806 | break; | |
807 | case TARGET_SO_OOBINLINE: | |
808 | optname = SO_OOBINLINE; | |
809 | break; | |
810 | case TARGET_SO_NO_CHECK: | |
811 | optname = SO_NO_CHECK; | |
812 | break; | |
813 | case TARGET_SO_PRIORITY: | |
814 | optname = SO_PRIORITY; | |
815 | break; | |
5e83e8e3 | 816 | #ifdef SO_BSDCOMPAT |
3532fa74 FB |
817 | case TARGET_SO_BSDCOMPAT: |
818 | optname = SO_BSDCOMPAT; | |
819 | break; | |
5e83e8e3 | 820 | #endif |
3532fa74 FB |
821 | case TARGET_SO_PASSCRED: |
822 | optname = SO_PASSCRED; | |
823 | break; | |
824 | case TARGET_SO_TIMESTAMP: | |
825 | optname = SO_TIMESTAMP; | |
826 | break; | |
827 | case TARGET_SO_RCVLOWAT: | |
828 | optname = SO_RCVLOWAT; | |
829 | break; | |
830 | case TARGET_SO_RCVTIMEO: | |
831 | optname = SO_RCVTIMEO; | |
832 | break; | |
833 | case TARGET_SO_SNDTIMEO: | |
834 | optname = SO_SNDTIMEO; | |
835 | break; | |
8853f86e FB |
836 | break; |
837 | default: | |
838 | goto unimplemented; | |
839 | } | |
3532fa74 | 840 | if (optlen < sizeof(uint32_t)) |
0da46a6e | 841 | return -TARGET_EINVAL; |
3532fa74 FB |
842 | |
843 | val = tget32(optval); | |
844 | ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname, &val, sizeof(val))); | |
8853f86e | 845 | break; |
7854b056 | 846 | default: |
8853f86e FB |
847 | unimplemented: |
848 | gemu_log("Unsupported setsockopt level=%d optname=%d \n", level, optname); | |
0da46a6e | 849 | ret = -TARGET_ENOSYS; |
7854b056 | 850 | } |
8853f86e | 851 | return ret; |
7854b056 FB |
852 | } |
853 | ||
0da46a6e | 854 | /* do_getsockopt() Must return target values and target errnos. */ |
992f48a0 BS |
855 | static abi_long do_getsockopt(int sockfd, int level, int optname, |
856 | abi_ulong optval, abi_ulong optlen) | |
7854b056 | 857 | { |
992f48a0 | 858 | abi_long ret; |
32407103 | 859 | int len, lv, val; |
8853f86e FB |
860 | |
861 | switch(level) { | |
3532fa74 FB |
862 | case TARGET_SOL_SOCKET: |
863 | level = SOL_SOCKET; | |
8853f86e | 864 | switch (optname) { |
3532fa74 FB |
865 | case TARGET_SO_LINGER: |
866 | case TARGET_SO_RCVTIMEO: | |
867 | case TARGET_SO_SNDTIMEO: | |
868 | case TARGET_SO_PEERCRED: | |
869 | case TARGET_SO_PEERNAME: | |
8853f86e FB |
870 | /* These don't just return a single integer */ |
871 | goto unimplemented; | |
872 | default: | |
2efbe911 FB |
873 | goto int_case; |
874 | } | |
875 | break; | |
876 | case SOL_TCP: | |
877 | /* TCP options all take an 'int' value. */ | |
878 | int_case: | |
53a5960a | 879 | len = tget32(optlen); |
2efbe911 | 880 | if (len < 0) |
0da46a6e | 881 | return -TARGET_EINVAL; |
2efbe911 FB |
882 | lv = sizeof(int); |
883 | ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv)); | |
884 | if (ret < 0) | |
885 | return ret; | |
886 | val = tswap32(val); | |
887 | if (len > lv) | |
888 | len = lv; | |
53a5960a PB |
889 | if (len == 4) |
890 | tput32(optval, val); | |
891 | else | |
892 | tput8(optval, val); | |
893 | tput32(optlen, len); | |
2efbe911 FB |
894 | break; |
895 | case SOL_IP: | |
896 | switch(optname) { | |
897 | case IP_TOS: | |
898 | case IP_TTL: | |
899 | case IP_HDRINCL: | |
900 | case IP_ROUTER_ALERT: | |
901 | case IP_RECVOPTS: | |
902 | case IP_RETOPTS: | |
903 | case IP_PKTINFO: | |
904 | case IP_MTU_DISCOVER: | |
905 | case IP_RECVERR: | |
906 | case IP_RECVTOS: | |
907 | #ifdef IP_FREEBIND | |
908 | case IP_FREEBIND: | |
909 | #endif | |
910 | case IP_MULTICAST_TTL: | |
911 | case IP_MULTICAST_LOOP: | |
53a5960a | 912 | len = tget32(optlen); |
8853f86e | 913 | if (len < 0) |
0da46a6e | 914 | return -TARGET_EINVAL; |
8853f86e FB |
915 | lv = sizeof(int); |
916 | ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv)); | |
917 | if (ret < 0) | |
918 | return ret; | |
2efbe911 | 919 | if (len < sizeof(int) && len > 0 && val >= 0 && val < 255) { |
2efbe911 | 920 | len = 1; |
53a5960a PB |
921 | tput32(optlen, len); |
922 | tput8(optval, val); | |
2efbe911 | 923 | } else { |
2efbe911 FB |
924 | if (len > sizeof(int)) |
925 | len = sizeof(int); | |
53a5960a PB |
926 | tput32(optlen, len); |
927 | tput32(optval, val); | |
2efbe911 | 928 | } |
8853f86e | 929 | break; |
2efbe911 FB |
930 | default: |
931 | goto unimplemented; | |
8853f86e FB |
932 | } |
933 | break; | |
934 | default: | |
935 | unimplemented: | |
936 | gemu_log("getsockopt level=%d optname=%d not yet supported\n", | |
937 | level, optname); | |
0da46a6e | 938 | ret = -TARGET_ENOSYS; |
8853f86e FB |
939 | break; |
940 | } | |
941 | return ret; | |
7854b056 FB |
942 | } |
943 | ||
992f48a0 | 944 | static void lock_iovec(struct iovec *vec, abi_ulong target_addr, |
53a5960a PB |
945 | int count, int copy) |
946 | { | |
947 | struct target_iovec *target_vec; | |
992f48a0 | 948 | abi_ulong base; |
53a5960a PB |
949 | int i; |
950 | ||
951 | target_vec = lock_user(target_addr, count * sizeof(struct target_iovec), 1); | |
952 | for(i = 0;i < count; i++) { | |
953 | base = tswapl(target_vec[i].iov_base); | |
954 | vec[i].iov_len = tswapl(target_vec[i].iov_len); | |
955 | vec[i].iov_base = lock_user(base, vec[i].iov_len, copy); | |
956 | } | |
957 | unlock_user (target_vec, target_addr, 0); | |
958 | } | |
959 | ||
992f48a0 | 960 | static void unlock_iovec(struct iovec *vec, abi_ulong target_addr, |
53a5960a PB |
961 | int count, int copy) |
962 | { | |
963 | struct target_iovec *target_vec; | |
992f48a0 | 964 | abi_ulong base; |
53a5960a PB |
965 | int i; |
966 | ||
967 | target_vec = lock_user(target_addr, count * sizeof(struct target_iovec), 1); | |
968 | for(i = 0;i < count; i++) { | |
969 | base = tswapl(target_vec[i].iov_base); | |
970 | unlock_user(vec[i].iov_base, base, copy ? vec[i].iov_len : 0); | |
971 | } | |
972 | unlock_user (target_vec, target_addr, 0); | |
973 | } | |
974 | ||
0da46a6e | 975 | /* do_socket() Must return target values and target errnos. */ |
992f48a0 | 976 | static abi_long do_socket(int domain, int type, int protocol) |
3532fa74 FB |
977 | { |
978 | #if defined(TARGET_MIPS) | |
979 | switch(type) { | |
980 | case TARGET_SOCK_DGRAM: | |
981 | type = SOCK_DGRAM; | |
982 | break; | |
983 | case TARGET_SOCK_STREAM: | |
984 | type = SOCK_STREAM; | |
985 | break; | |
986 | case TARGET_SOCK_RAW: | |
987 | type = SOCK_RAW; | |
988 | break; | |
989 | case TARGET_SOCK_RDM: | |
990 | type = SOCK_RDM; | |
991 | break; | |
992 | case TARGET_SOCK_SEQPACKET: | |
993 | type = SOCK_SEQPACKET; | |
994 | break; | |
995 | case TARGET_SOCK_PACKET: | |
996 | type = SOCK_PACKET; | |
997 | break; | |
998 | } | |
999 | #endif | |
12bc92ab AZ |
1000 | if (domain == PF_NETLINK) |
1001 | return -EAFNOSUPPORT; /* do not NETLINK socket connections possible */ | |
3532fa74 FB |
1002 | return get_errno(socket(domain, type, protocol)); |
1003 | } | |
1004 | ||
0da46a6e | 1005 | /* do_bind() Must return target values and target errnos. */ |
992f48a0 BS |
1006 | static abi_long do_bind(int sockfd, abi_ulong target_addr, |
1007 | socklen_t addrlen) | |
3532fa74 FB |
1008 | { |
1009 | void *addr = alloca(addrlen); | |
3b46e624 | 1010 | |
3532fa74 FB |
1011 | target_to_host_sockaddr(addr, target_addr, addrlen); |
1012 | return get_errno(bind(sockfd, addr, addrlen)); | |
1013 | } | |
1014 | ||
0da46a6e | 1015 | /* do_connect() Must return target values and target errnos. */ |
992f48a0 BS |
1016 | static abi_long do_connect(int sockfd, abi_ulong target_addr, |
1017 | socklen_t addrlen) | |
3532fa74 FB |
1018 | { |
1019 | void *addr = alloca(addrlen); | |
3b46e624 | 1020 | |
3532fa74 FB |
1021 | target_to_host_sockaddr(addr, target_addr, addrlen); |
1022 | return get_errno(connect(sockfd, addr, addrlen)); | |
1023 | } | |
1024 | ||
0da46a6e | 1025 | /* do_sendrecvmsg() Must return target values and target errnos. */ |
992f48a0 BS |
1026 | static abi_long do_sendrecvmsg(int fd, abi_ulong target_msg, |
1027 | int flags, int send) | |
3532fa74 | 1028 | { |
992f48a0 | 1029 | abi_long ret; |
3532fa74 FB |
1030 | struct target_msghdr *msgp; |
1031 | struct msghdr msg; | |
1032 | int count; | |
1033 | struct iovec *vec; | |
992f48a0 | 1034 | abi_ulong target_vec; |
3532fa74 FB |
1035 | |
1036 | lock_user_struct(msgp, target_msg, 1); | |
1037 | if (msgp->msg_name) { | |
1038 | msg.msg_namelen = tswap32(msgp->msg_namelen); | |
1039 | msg.msg_name = alloca(msg.msg_namelen); | |
1040 | target_to_host_sockaddr(msg.msg_name, tswapl(msgp->msg_name), | |
1041 | msg.msg_namelen); | |
1042 | } else { | |
1043 | msg.msg_name = NULL; | |
1044 | msg.msg_namelen = 0; | |
1045 | } | |
1046 | msg.msg_controllen = 2 * tswapl(msgp->msg_controllen); | |
1047 | msg.msg_control = alloca(msg.msg_controllen); | |
1048 | msg.msg_flags = tswap32(msgp->msg_flags); | |
3b46e624 | 1049 | |
3532fa74 FB |
1050 | count = tswapl(msgp->msg_iovlen); |
1051 | vec = alloca(count * sizeof(struct iovec)); | |
1052 | target_vec = tswapl(msgp->msg_iov); | |
1053 | lock_iovec(vec, target_vec, count, send); | |
1054 | msg.msg_iovlen = count; | |
1055 | msg.msg_iov = vec; | |
3b46e624 | 1056 | |
3532fa74 FB |
1057 | if (send) { |
1058 | target_to_host_cmsg(&msg, msgp); | |
1059 | ret = get_errno(sendmsg(fd, &msg, flags)); | |
1060 | } else { | |
1061 | ret = get_errno(recvmsg(fd, &msg, flags)); | |
1062 | if (!is_error(ret)) | |
1063 | host_to_target_cmsg(msgp, &msg); | |
1064 | } | |
1065 | unlock_iovec(vec, target_vec, count, !send); | |
1066 | return ret; | |
1067 | } | |
1068 | ||
0da46a6e | 1069 | /* do_accept() Must return target values and target errnos. */ |
992f48a0 BS |
1070 | static abi_long do_accept(int fd, abi_ulong target_addr, |
1071 | abi_ulong target_addrlen) | |
1be9e1dc PB |
1072 | { |
1073 | socklen_t addrlen = tget32(target_addrlen); | |
197ea35a | 1074 | void *addr = alloca(addrlen); |
992f48a0 | 1075 | abi_long ret; |
1be9e1dc PB |
1076 | |
1077 | ret = get_errno(accept(fd, addr, &addrlen)); | |
1078 | if (!is_error(ret)) { | |
1079 | host_to_target_sockaddr(target_addr, addr, addrlen); | |
1080 | tput32(target_addrlen, addrlen); | |
1081 | } | |
1082 | return ret; | |
1083 | } | |
1084 | ||
0da46a6e | 1085 | /* do_getpeername() Must return target values and target errnos. */ |
992f48a0 BS |
1086 | static abi_long do_getpeername(int fd, abi_ulong target_addr, |
1087 | abi_ulong target_addrlen) | |
1be9e1dc PB |
1088 | { |
1089 | socklen_t addrlen = tget32(target_addrlen); | |
01c227fb | 1090 | void *addr = alloca(addrlen); |
992f48a0 | 1091 | abi_long ret; |
1be9e1dc PB |
1092 | |
1093 | ret = get_errno(getpeername(fd, addr, &addrlen)); | |
1094 | if (!is_error(ret)) { | |
1095 | host_to_target_sockaddr(target_addr, addr, addrlen); | |
1096 | tput32(target_addrlen, addrlen); | |
1097 | } | |
1098 | return ret; | |
1099 | } | |
1100 | ||
0da46a6e | 1101 | /* do_getsockname() Must return target values and target errnos. */ |
992f48a0 BS |
1102 | static abi_long do_getsockname(int fd, abi_ulong target_addr, |
1103 | abi_ulong target_addrlen) | |
1be9e1dc PB |
1104 | { |
1105 | socklen_t addrlen = tget32(target_addrlen); | |
01c227fb | 1106 | void *addr = alloca(addrlen); |
992f48a0 | 1107 | abi_long ret; |
1be9e1dc PB |
1108 | |
1109 | ret = get_errno(getsockname(fd, addr, &addrlen)); | |
1110 | if (!is_error(ret)) { | |
1111 | host_to_target_sockaddr(target_addr, addr, addrlen); | |
1112 | tput32(target_addrlen, addrlen); | |
1113 | } | |
1114 | return ret; | |
1115 | } | |
1116 | ||
0da46a6e | 1117 | /* do_socketpair() Must return target values and target errnos. */ |
992f48a0 BS |
1118 | static abi_long do_socketpair(int domain, int type, int protocol, |
1119 | abi_ulong target_tab) | |
1be9e1dc PB |
1120 | { |
1121 | int tab[2]; | |
992f48a0 | 1122 | abi_long ret; |
1be9e1dc PB |
1123 | |
1124 | ret = get_errno(socketpair(domain, type, protocol, tab)); | |
1125 | if (!is_error(ret)) { | |
1126 | tput32(target_tab, tab[0]); | |
1127 | tput32(target_tab + 4, tab[1]); | |
1128 | } | |
1129 | return ret; | |
1130 | } | |
1131 | ||
0da46a6e | 1132 | /* do_sendto() Must return target values and target errnos. */ |
992f48a0 BS |
1133 | static abi_long do_sendto(int fd, abi_ulong msg, size_t len, int flags, |
1134 | abi_ulong target_addr, socklen_t addrlen) | |
1be9e1dc PB |
1135 | { |
1136 | void *addr; | |
1137 | void *host_msg; | |
992f48a0 | 1138 | abi_long ret; |
1be9e1dc PB |
1139 | |
1140 | host_msg = lock_user(msg, len, 1); | |
1141 | if (target_addr) { | |
1142 | addr = alloca(addrlen); | |
1143 | target_to_host_sockaddr(addr, target_addr, addrlen); | |
1144 | ret = get_errno(sendto(fd, host_msg, len, flags, addr, addrlen)); | |
1145 | } else { | |
1146 | ret = get_errno(send(fd, host_msg, len, flags)); | |
1147 | } | |
1148 | unlock_user(host_msg, msg, 0); | |
1149 | return ret; | |
1150 | } | |
1151 | ||
0da46a6e | 1152 | /* do_recvfrom() Must return target values and target errnos. */ |
992f48a0 BS |
1153 | static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags, |
1154 | abi_ulong target_addr, | |
1155 | abi_ulong target_addrlen) | |
1be9e1dc PB |
1156 | { |
1157 | socklen_t addrlen; | |
1158 | void *addr; | |
1159 | void *host_msg; | |
992f48a0 | 1160 | abi_long ret; |
1be9e1dc PB |
1161 | |
1162 | host_msg = lock_user(msg, len, 0); | |
1163 | if (target_addr) { | |
1164 | addrlen = tget32(target_addrlen); | |
1165 | addr = alloca(addrlen); | |
1166 | ret = get_errno(recvfrom(fd, host_msg, len, flags, addr, &addrlen)); | |
1167 | } else { | |
1168 | addr = NULL; /* To keep compiler quiet. */ | |
1169 | ret = get_errno(recv(fd, host_msg, len, flags)); | |
1170 | } | |
1171 | if (!is_error(ret)) { | |
1172 | if (target_addr) { | |
1173 | host_to_target_sockaddr(target_addr, addr, addrlen); | |
1174 | tput32(target_addrlen, addrlen); | |
1175 | } | |
1176 | unlock_user(host_msg, msg, len); | |
1177 | } else { | |
1178 | unlock_user(host_msg, msg, 0); | |
1179 | } | |
1180 | return ret; | |
1181 | } | |
1182 | ||
32407103 | 1183 | #ifdef TARGET_NR_socketcall |
0da46a6e | 1184 | /* do_socketcall() Must return target values and target errnos. */ |
992f48a0 | 1185 | static abi_long do_socketcall(int num, abi_ulong vptr) |
31e31b8a | 1186 | { |
992f48a0 BS |
1187 | abi_long ret; |
1188 | const int n = sizeof(abi_ulong); | |
31e31b8a FB |
1189 | |
1190 | switch(num) { | |
1191 | case SOCKOP_socket: | |
7854b056 | 1192 | { |
53a5960a PB |
1193 | int domain = tgetl(vptr); |
1194 | int type = tgetl(vptr + n); | |
1195 | int protocol = tgetl(vptr + 2 * n); | |
3532fa74 | 1196 | ret = do_socket(domain, type, protocol); |
7854b056 | 1197 | } |
31e31b8a FB |
1198 | break; |
1199 | case SOCKOP_bind: | |
7854b056 | 1200 | { |
53a5960a | 1201 | int sockfd = tgetl(vptr); |
992f48a0 | 1202 | abi_ulong target_addr = tgetl(vptr + n); |
53a5960a | 1203 | socklen_t addrlen = tgetl(vptr + 2 * n); |
3532fa74 | 1204 | ret = do_bind(sockfd, target_addr, addrlen); |
7854b056 | 1205 | } |
31e31b8a FB |
1206 | break; |
1207 | case SOCKOP_connect: | |
7854b056 | 1208 | { |
53a5960a | 1209 | int sockfd = tgetl(vptr); |
992f48a0 | 1210 | abi_ulong target_addr = tgetl(vptr + n); |
53a5960a | 1211 | socklen_t addrlen = tgetl(vptr + 2 * n); |
3532fa74 | 1212 | ret = do_connect(sockfd, target_addr, addrlen); |
7854b056 | 1213 | } |
31e31b8a FB |
1214 | break; |
1215 | case SOCKOP_listen: | |
7854b056 | 1216 | { |
53a5960a PB |
1217 | int sockfd = tgetl(vptr); |
1218 | int backlog = tgetl(vptr + n); | |
7854b056 FB |
1219 | ret = get_errno(listen(sockfd, backlog)); |
1220 | } | |
31e31b8a FB |
1221 | break; |
1222 | case SOCKOP_accept: | |
1223 | { | |
53a5960a | 1224 | int sockfd = tgetl(vptr); |
992f48a0 BS |
1225 | abi_ulong target_addr = tgetl(vptr + n); |
1226 | abi_ulong target_addrlen = tgetl(vptr + 2 * n); | |
1be9e1dc | 1227 | ret = do_accept(sockfd, target_addr, target_addrlen); |
31e31b8a FB |
1228 | } |
1229 | break; | |
1230 | case SOCKOP_getsockname: | |
1231 | { | |
53a5960a | 1232 | int sockfd = tgetl(vptr); |
992f48a0 BS |
1233 | abi_ulong target_addr = tgetl(vptr + n); |
1234 | abi_ulong target_addrlen = tgetl(vptr + 2 * n); | |
1be9e1dc | 1235 | ret = do_getsockname(sockfd, target_addr, target_addrlen); |
31e31b8a FB |
1236 | } |
1237 | break; | |
1238 | case SOCKOP_getpeername: | |
1239 | { | |
53a5960a | 1240 | int sockfd = tgetl(vptr); |
992f48a0 BS |
1241 | abi_ulong target_addr = tgetl(vptr + n); |
1242 | abi_ulong target_addrlen = tgetl(vptr + 2 * n); | |
1be9e1dc | 1243 | ret = do_getpeername(sockfd, target_addr, target_addrlen); |
31e31b8a FB |
1244 | } |
1245 | break; | |
1246 | case SOCKOP_socketpair: | |
1247 | { | |
53a5960a PB |
1248 | int domain = tgetl(vptr); |
1249 | int type = tgetl(vptr + n); | |
1250 | int protocol = tgetl(vptr + 2 * n); | |
992f48a0 | 1251 | abi_ulong tab = tgetl(vptr + 3 * n); |
1be9e1dc | 1252 | ret = do_socketpair(domain, type, protocol, tab); |
31e31b8a FB |
1253 | } |
1254 | break; | |
1255 | case SOCKOP_send: | |
7854b056 | 1256 | { |
53a5960a | 1257 | int sockfd = tgetl(vptr); |
992f48a0 | 1258 | abi_ulong msg = tgetl(vptr + n); |
53a5960a PB |
1259 | size_t len = tgetl(vptr + 2 * n); |
1260 | int flags = tgetl(vptr + 3 * n); | |
1be9e1dc | 1261 | ret = do_sendto(sockfd, msg, len, flags, 0, 0); |
7854b056 | 1262 | } |
31e31b8a FB |
1263 | break; |
1264 | case SOCKOP_recv: | |
7854b056 | 1265 | { |
53a5960a | 1266 | int sockfd = tgetl(vptr); |
992f48a0 | 1267 | abi_ulong msg = tgetl(vptr + n); |
53a5960a PB |
1268 | size_t len = tgetl(vptr + 2 * n); |
1269 | int flags = tgetl(vptr + 3 * n); | |
1be9e1dc | 1270 | ret = do_recvfrom(sockfd, msg, len, flags, 0, 0); |
7854b056 | 1271 | } |
31e31b8a FB |
1272 | break; |
1273 | case SOCKOP_sendto: | |
7854b056 | 1274 | { |
53a5960a | 1275 | int sockfd = tgetl(vptr); |
992f48a0 | 1276 | abi_ulong msg = tgetl(vptr + n); |
53a5960a PB |
1277 | size_t len = tgetl(vptr + 2 * n); |
1278 | int flags = tgetl(vptr + 3 * n); | |
992f48a0 | 1279 | abi_ulong addr = tgetl(vptr + 4 * n); |
53a5960a | 1280 | socklen_t addrlen = tgetl(vptr + 5 * n); |
1be9e1dc | 1281 | ret = do_sendto(sockfd, msg, len, flags, addr, addrlen); |
7854b056 | 1282 | } |
31e31b8a FB |
1283 | break; |
1284 | case SOCKOP_recvfrom: | |
1285 | { | |
53a5960a | 1286 | int sockfd = tgetl(vptr); |
992f48a0 | 1287 | abi_ulong msg = tgetl(vptr + n); |
53a5960a PB |
1288 | size_t len = tgetl(vptr + 2 * n); |
1289 | int flags = tgetl(vptr + 3 * n); | |
992f48a0 BS |
1290 | abi_ulong addr = tgetl(vptr + 4 * n); |
1291 | abi_ulong addrlen = tgetl(vptr + 5 * n); | |
1be9e1dc | 1292 | ret = do_recvfrom(sockfd, msg, len, flags, addr, addrlen); |
31e31b8a FB |
1293 | } |
1294 | break; | |
1295 | case SOCKOP_shutdown: | |
7854b056 | 1296 | { |
53a5960a PB |
1297 | int sockfd = tgetl(vptr); |
1298 | int how = tgetl(vptr + n); | |
7854b056 FB |
1299 | |
1300 | ret = get_errno(shutdown(sockfd, how)); | |
1301 | } | |
31e31b8a FB |
1302 | break; |
1303 | case SOCKOP_sendmsg: | |
1304 | case SOCKOP_recvmsg: | |
1a9353d2 FB |
1305 | { |
1306 | int fd; | |
992f48a0 | 1307 | abi_ulong target_msg; |
3532fa74 | 1308 | int flags; |
1a9353d2 | 1309 | |
53a5960a | 1310 | fd = tgetl(vptr); |
3532fa74 | 1311 | target_msg = tgetl(vptr + n); |
53a5960a | 1312 | flags = tgetl(vptr + 2 * n); |
3532fa74 | 1313 | |
5fafdf24 | 1314 | ret = do_sendrecvmsg(fd, target_msg, flags, |
3532fa74 | 1315 | (num == SOCKOP_sendmsg)); |
1a9353d2 FB |
1316 | } |
1317 | break; | |
31e31b8a | 1318 | case SOCKOP_setsockopt: |
7854b056 | 1319 | { |
53a5960a PB |
1320 | int sockfd = tgetl(vptr); |
1321 | int level = tgetl(vptr + n); | |
1322 | int optname = tgetl(vptr + 2 * n); | |
992f48a0 | 1323 | abi_ulong optval = tgetl(vptr + 3 * n); |
53a5960a | 1324 | socklen_t optlen = tgetl(vptr + 4 * n); |
7854b056 FB |
1325 | |
1326 | ret = do_setsockopt(sockfd, level, optname, optval, optlen); | |
1327 | } | |
1328 | break; | |
31e31b8a | 1329 | case SOCKOP_getsockopt: |
7854b056 | 1330 | { |
53a5960a PB |
1331 | int sockfd = tgetl(vptr); |
1332 | int level = tgetl(vptr + n); | |
1333 | int optname = tgetl(vptr + 2 * n); | |
992f48a0 BS |
1334 | abi_ulong optval = tgetl(vptr + 3 * n); |
1335 | abi_ulong poptlen = tgetl(vptr + 4 * n); | |
7854b056 | 1336 | |
8853f86e | 1337 | ret = do_getsockopt(sockfd, level, optname, optval, poptlen); |
7854b056 FB |
1338 | } |
1339 | break; | |
31e31b8a FB |
1340 | default: |
1341 | gemu_log("Unsupported socketcall: %d\n", num); | |
0da46a6e | 1342 | ret = -TARGET_ENOSYS; |
31e31b8a FB |
1343 | break; |
1344 | } | |
1345 | return ret; | |
1346 | } | |
32407103 | 1347 | #endif |
31e31b8a | 1348 | |
32407103 | 1349 | #ifdef TARGET_NR_ipc |
8853f86e FB |
1350 | #define N_SHM_REGIONS 32 |
1351 | ||
1352 | static struct shm_region { | |
1353 | uint32_t start; | |
1354 | uint32_t size; | |
1355 | } shm_regions[N_SHM_REGIONS]; | |
1356 | ||
3eb6b044 TS |
1357 | struct target_ipc_perm |
1358 | { | |
992f48a0 BS |
1359 | abi_long __key; |
1360 | abi_ulong uid; | |
1361 | abi_ulong gid; | |
1362 | abi_ulong cuid; | |
1363 | abi_ulong cgid; | |
3eb6b044 TS |
1364 | unsigned short int mode; |
1365 | unsigned short int __pad1; | |
1366 | unsigned short int __seq; | |
1367 | unsigned short int __pad2; | |
992f48a0 BS |
1368 | abi_ulong __unused1; |
1369 | abi_ulong __unused2; | |
3eb6b044 TS |
1370 | }; |
1371 | ||
1372 | struct target_semid_ds | |
1373 | { | |
1374 | struct target_ipc_perm sem_perm; | |
992f48a0 BS |
1375 | abi_ulong sem_otime; |
1376 | abi_ulong __unused1; | |
1377 | abi_ulong sem_ctime; | |
1378 | abi_ulong __unused2; | |
1379 | abi_ulong sem_nsems; | |
1380 | abi_ulong __unused3; | |
1381 | abi_ulong __unused4; | |
3eb6b044 TS |
1382 | }; |
1383 | ||
1384 | static inline void target_to_host_ipc_perm(struct ipc_perm *host_ip, | |
992f48a0 | 1385 | abi_ulong target_addr) |
3eb6b044 TS |
1386 | { |
1387 | struct target_ipc_perm *target_ip; | |
1388 | struct target_semid_ds *target_sd; | |
1389 | ||
1390 | lock_user_struct(target_sd, target_addr, 1); | |
1391 | target_ip=&(target_sd->sem_perm); | |
1392 | host_ip->__key = tswapl(target_ip->__key); | |
1393 | host_ip->uid = tswapl(target_ip->uid); | |
1394 | host_ip->gid = tswapl(target_ip->gid); | |
1395 | host_ip->cuid = tswapl(target_ip->cuid); | |
1396 | host_ip->cgid = tswapl(target_ip->cgid); | |
1397 | host_ip->mode = tswapl(target_ip->mode); | |
1398 | unlock_user_struct(target_sd, target_addr, 0); | |
1399 | } | |
1400 | ||
992f48a0 | 1401 | static inline void host_to_target_ipc_perm(abi_ulong target_addr, |
3eb6b044 TS |
1402 | struct ipc_perm *host_ip) |
1403 | { | |
1404 | struct target_ipc_perm *target_ip; | |
1405 | struct target_semid_ds *target_sd; | |
1406 | ||
1407 | lock_user_struct(target_sd, target_addr, 0); | |
1408 | target_ip = &(target_sd->sem_perm); | |
1409 | target_ip->__key = tswapl(host_ip->__key); | |
1410 | target_ip->uid = tswapl(host_ip->uid); | |
1411 | target_ip->gid = tswapl(host_ip->gid); | |
1412 | target_ip->cuid = tswapl(host_ip->cuid); | |
1413 | target_ip->cgid = tswapl(host_ip->cgid); | |
1414 | target_ip->mode = tswapl(host_ip->mode); | |
1415 | unlock_user_struct(target_sd, target_addr, 1); | |
1416 | } | |
1417 | ||
1418 | static inline void target_to_host_semid_ds(struct semid_ds *host_sd, | |
992f48a0 | 1419 | abi_ulong target_addr) |
3eb6b044 TS |
1420 | { |
1421 | struct target_semid_ds *target_sd; | |
1422 | ||
1423 | lock_user_struct(target_sd, target_addr, 1); | |
1424 | target_to_host_ipc_perm(&(host_sd->sem_perm),target_addr); | |
1425 | host_sd->sem_nsems = tswapl(target_sd->sem_nsems); | |
1426 | host_sd->sem_otime = tswapl(target_sd->sem_otime); | |
1427 | host_sd->sem_ctime = tswapl(target_sd->sem_ctime); | |
1428 | unlock_user_struct(target_sd, target_addr, 0); | |
1429 | } | |
1430 | ||
992f48a0 | 1431 | static inline void host_to_target_semid_ds(abi_ulong target_addr, |
3eb6b044 TS |
1432 | struct semid_ds *host_sd) |
1433 | { | |
1434 | struct target_semid_ds *target_sd; | |
1435 | ||
1436 | lock_user_struct(target_sd, target_addr, 0); | |
1437 | host_to_target_ipc_perm(target_addr,&(host_sd->sem_perm)); | |
1438 | target_sd->sem_nsems = tswapl(host_sd->sem_nsems); | |
1439 | target_sd->sem_otime = tswapl(host_sd->sem_otime); | |
1440 | target_sd->sem_ctime = tswapl(host_sd->sem_ctime); | |
1441 | unlock_user_struct(target_sd, target_addr, 1); | |
1442 | } | |
1443 | ||
fa294816 TS |
1444 | union semun { |
1445 | int val; | |
3eb6b044 | 1446 | struct semid_ds *buf; |
fa294816 TS |
1447 | unsigned short *array; |
1448 | }; | |
1449 | ||
3eb6b044 TS |
1450 | union target_semun { |
1451 | int val; | |
992f48a0 | 1452 | abi_long buf; |
3eb6b044 TS |
1453 | unsigned short int *array; |
1454 | }; | |
1455 | ||
32407103 | 1456 | static inline void target_to_host_semun(int cmd, |
3eb6b044 | 1457 | union semun *host_su, |
992f48a0 | 1458 | abi_ulong target_addr, |
3eb6b044 TS |
1459 | struct semid_ds *ds) |
1460 | { | |
1461 | union target_semun *target_su; | |
1462 | ||
1463 | switch( cmd ) { | |
1464 | case IPC_STAT: | |
1465 | case IPC_SET: | |
1466 | lock_user_struct(target_su, target_addr, 1); | |
1467 | target_to_host_semid_ds(ds,target_su->buf); | |
1468 | host_su->buf = ds; | |
1469 | unlock_user_struct(target_su, target_addr, 0); | |
1470 | break; | |
1471 | case GETVAL: | |
1472 | case SETVAL: | |
1473 | lock_user_struct(target_su, target_addr, 1); | |
1474 | host_su->val = tswapl(target_su->val); | |
1475 | unlock_user_struct(target_su, target_addr, 0); | |
1476 | break; | |
1477 | case GETALL: | |
1478 | case SETALL: | |
1479 | lock_user_struct(target_su, target_addr, 1); | |
1480 | *host_su->array = tswap16(*target_su->array); | |
1481 | unlock_user_struct(target_su, target_addr, 0); | |
1482 | break; | |
1483 | default: | |
1484 | gemu_log("semun operation not fully supported: %d\n", (int)cmd); | |
1485 | } | |
1486 | } | |
1487 | ||
32407103 | 1488 | static inline void host_to_target_semun(int cmd, |
992f48a0 | 1489 | abi_ulong target_addr, |
3eb6b044 TS |
1490 | union semun *host_su, |
1491 | struct semid_ds *ds) | |
1492 | { | |
1493 | union target_semun *target_su; | |
1494 | ||
1495 | switch( cmd ) { | |
1496 | case IPC_STAT: | |
1497 | case IPC_SET: | |
1498 | lock_user_struct(target_su, target_addr, 0); | |
1499 | host_to_target_semid_ds(target_su->buf,ds); | |
1500 | unlock_user_struct(target_su, target_addr, 1); | |
1501 | break; | |
1502 | case GETVAL: | |
1503 | case SETVAL: | |
1504 | lock_user_struct(target_su, target_addr, 0); | |
1505 | target_su->val = tswapl(host_su->val); | |
1506 | unlock_user_struct(target_su, target_addr, 1); | |
1507 | break; | |
1508 | case GETALL: | |
1509 | case SETALL: | |
1510 | lock_user_struct(target_su, target_addr, 0); | |
1511 | *target_su->array = tswap16(*host_su->array); | |
1512 | unlock_user_struct(target_su, target_addr, 1); | |
1513 | break; | |
1514 | default: | |
1515 | gemu_log("semun operation not fully supported: %d\n", (int)cmd); | |
1516 | } | |
1517 | } | |
1518 | ||
992f48a0 BS |
1519 | static inline abi_long do_semctl(int first, int second, int third, |
1520 | abi_long ptr) | |
3eb6b044 TS |
1521 | { |
1522 | union semun arg; | |
1523 | struct semid_ds dsarg; | |
1524 | int cmd = third&0xff; | |
992f48a0 | 1525 | abi_long ret = 0; |
3eb6b044 TS |
1526 | |
1527 | switch( cmd ) { | |
1528 | case GETVAL: | |
1529 | target_to_host_semun(cmd,&arg,ptr,&dsarg); | |
1530 | ret = get_errno(semctl(first, second, cmd, arg)); | |
1531 | host_to_target_semun(cmd,ptr,&arg,&dsarg); | |
1532 | break; | |
1533 | case SETVAL: | |
1534 | target_to_host_semun(cmd,&arg,ptr,&dsarg); | |
1535 | ret = get_errno(semctl(first, second, cmd, arg)); | |
1536 | host_to_target_semun(cmd,ptr,&arg,&dsarg); | |
1537 | break; | |
1538 | case GETALL: | |
1539 | target_to_host_semun(cmd,&arg,ptr,&dsarg); | |
1540 | ret = get_errno(semctl(first, second, cmd, arg)); | |
1541 | host_to_target_semun(cmd,ptr,&arg,&dsarg); | |
1542 | break; | |
1543 | case SETALL: | |
1544 | target_to_host_semun(cmd,&arg,ptr,&dsarg); | |
1545 | ret = get_errno(semctl(first, second, cmd, arg)); | |
1546 | host_to_target_semun(cmd,ptr,&arg,&dsarg); | |
1547 | break; | |
1548 | case IPC_STAT: | |
1549 | target_to_host_semun(cmd,&arg,ptr,&dsarg); | |
1550 | ret = get_errno(semctl(first, second, cmd, arg)); | |
1551 | host_to_target_semun(cmd,ptr,&arg,&dsarg); | |
1552 | break; | |
1553 | case IPC_SET: | |
1554 | target_to_host_semun(cmd,&arg,ptr,&dsarg); | |
1555 | ret = get_errno(semctl(first, second, cmd, arg)); | |
1556 | host_to_target_semun(cmd,ptr,&arg,&dsarg); | |
1557 | break; | |
1558 | default: | |
1559 | ret = get_errno(semctl(first, second, cmd, arg)); | |
1560 | } | |
1561 | ||
1562 | return ret; | |
1563 | } | |
1564 | ||
1bc012f6 TS |
1565 | struct target_msqid_ds |
1566 | { | |
1567 | struct target_ipc_perm msg_perm; | |
992f48a0 BS |
1568 | abi_ulong msg_stime; |
1569 | abi_ulong __unused1; | |
1570 | abi_ulong msg_rtime; | |
1571 | abi_ulong __unused2; | |
1572 | abi_ulong msg_ctime; | |
1573 | abi_ulong __unused3; | |
1574 | abi_ulong __msg_cbytes; | |
1575 | abi_ulong msg_qnum; | |
1576 | abi_ulong msg_qbytes; | |
1577 | abi_ulong msg_lspid; | |
1578 | abi_ulong msg_lrpid; | |
1579 | abi_ulong __unused4; | |
1580 | abi_ulong __unused5; | |
1bc012f6 TS |
1581 | }; |
1582 | ||
1583 | static inline void target_to_host_msqid_ds(struct msqid_ds *host_md, | |
992f48a0 | 1584 | abi_ulong target_addr) |
1bc012f6 TS |
1585 | { |
1586 | struct target_msqid_ds *target_md; | |
1587 | ||
1588 | lock_user_struct(target_md, target_addr, 1); | |
1589 | target_to_host_ipc_perm(&(host_md->msg_perm),target_addr); | |
1590 | host_md->msg_stime = tswapl(target_md->msg_stime); | |
1591 | host_md->msg_rtime = tswapl(target_md->msg_rtime); | |
1592 | host_md->msg_ctime = tswapl(target_md->msg_ctime); | |
1593 | host_md->__msg_cbytes = tswapl(target_md->__msg_cbytes); | |
1594 | host_md->msg_qnum = tswapl(target_md->msg_qnum); | |
1595 | host_md->msg_qbytes = tswapl(target_md->msg_qbytes); | |
1596 | host_md->msg_lspid = tswapl(target_md->msg_lspid); | |
1597 | host_md->msg_lrpid = tswapl(target_md->msg_lrpid); | |
1598 | unlock_user_struct(target_md, target_addr, 0); | |
1599 | } | |
1600 | ||
992f48a0 | 1601 | static inline void host_to_target_msqid_ds(abi_ulong target_addr, |
1bc012f6 TS |
1602 | struct msqid_ds *host_md) |
1603 | { | |
1604 | struct target_msqid_ds *target_md; | |
1605 | ||
1606 | lock_user_struct(target_md, target_addr, 0); | |
1607 | host_to_target_ipc_perm(target_addr,&(host_md->msg_perm)); | |
1608 | target_md->msg_stime = tswapl(host_md->msg_stime); | |
1609 | target_md->msg_rtime = tswapl(host_md->msg_rtime); | |
1610 | target_md->msg_ctime = tswapl(host_md->msg_ctime); | |
1611 | target_md->__msg_cbytes = tswapl(host_md->__msg_cbytes); | |
1612 | target_md->msg_qnum = tswapl(host_md->msg_qnum); | |
1613 | target_md->msg_qbytes = tswapl(host_md->msg_qbytes); | |
1614 | target_md->msg_lspid = tswapl(host_md->msg_lspid); | |
1615 | target_md->msg_lrpid = tswapl(host_md->msg_lrpid); | |
1616 | unlock_user_struct(target_md, target_addr, 1); | |
1617 | } | |
1618 | ||
992f48a0 | 1619 | static inline abi_long do_msgctl(int first, int second, abi_long ptr) |
1bc012f6 TS |
1620 | { |
1621 | struct msqid_ds dsarg; | |
1622 | int cmd = second&0xff; | |
992f48a0 | 1623 | abi_long ret = 0; |
1bc012f6 TS |
1624 | switch( cmd ) { |
1625 | case IPC_STAT: | |
1626 | case IPC_SET: | |
1627 | target_to_host_msqid_ds(&dsarg,ptr); | |
1628 | ret = get_errno(msgctl(first, cmd, &dsarg)); | |
1629 | host_to_target_msqid_ds(ptr,&dsarg); | |
1630 | default: | |
1631 | ret = get_errno(msgctl(first, cmd, &dsarg)); | |
1632 | } | |
1633 | return ret; | |
1634 | } | |
1635 | ||
1636 | struct target_msgbuf { | |
992f48a0 | 1637 | abi_ulong mtype; |
1bc012f6 TS |
1638 | char mtext[1]; |
1639 | }; | |
1640 | ||
992f48a0 BS |
1641 | static inline abi_long do_msgsnd(int msqid, abi_long msgp, |
1642 | unsigned int msgsz, int msgflg) | |
1bc012f6 TS |
1643 | { |
1644 | struct target_msgbuf *target_mb; | |
1645 | struct msgbuf *host_mb; | |
992f48a0 | 1646 | abi_long ret = 0; |
1bc012f6 TS |
1647 | |
1648 | lock_user_struct(target_mb,msgp,0); | |
1649 | host_mb = malloc(msgsz+sizeof(long)); | |
1650 | host_mb->mtype = tswapl(target_mb->mtype); | |
1651 | memcpy(host_mb->mtext,target_mb->mtext,msgsz); | |
1652 | ret = get_errno(msgsnd(msqid, host_mb, msgsz, msgflg)); | |
1653 | free(host_mb); | |
1654 | unlock_user_struct(target_mb, msgp, 0); | |
1655 | ||
1656 | return ret; | |
1657 | } | |
1658 | ||
992f48a0 BS |
1659 | static inline abi_long do_msgrcv(int msqid, abi_long msgp, |
1660 | unsigned int msgsz, int msgtype, | |
1661 | int msgflg) | |
1bc012f6 TS |
1662 | { |
1663 | struct target_msgbuf *target_mb; | |
1664 | struct msgbuf *host_mb; | |
992f48a0 | 1665 | abi_long ret = 0; |
1bc012f6 TS |
1666 | |
1667 | lock_user_struct(target_mb, msgp, 0); | |
1668 | host_mb = malloc(msgsz+sizeof(long)); | |
1669 | ret = get_errno(msgrcv(msqid, host_mb, msgsz, 1, msgflg)); | |
1670 | if (ret > 0) | |
1671 | memcpy(target_mb->mtext, host_mb->mtext, ret); | |
1672 | target_mb->mtype = tswapl(host_mb->mtype); | |
1673 | free(host_mb); | |
1674 | unlock_user_struct(target_mb, msgp, 0); | |
1675 | ||
1676 | return ret; | |
1677 | } | |
1678 | ||
53a5960a | 1679 | /* ??? This only works with linear mappings. */ |
0da46a6e | 1680 | /* do_ipc() must return target values and target errnos. */ |
992f48a0 BS |
1681 | static abi_long do_ipc(unsigned int call, int first, |
1682 | int second, int third, | |
1683 | abi_long ptr, abi_long fifth) | |
8853f86e FB |
1684 | { |
1685 | int version; | |
992f48a0 | 1686 | abi_long ret = 0; |
8853f86e FB |
1687 | unsigned long raddr; |
1688 | struct shmid_ds shm_info; | |
1689 | int i; | |
1690 | ||
1691 | version = call >> 16; | |
1692 | call &= 0xffff; | |
1693 | ||
1694 | switch (call) { | |
fa294816 TS |
1695 | case IPCOP_semop: |
1696 | ret = get_errno(semop(first,(struct sembuf *) ptr, second)); | |
1697 | break; | |
1698 | ||
1699 | case IPCOP_semget: | |
1700 | ret = get_errno(semget(first, second, third)); | |
1701 | break; | |
1702 | ||
1703 | case IPCOP_semctl: | |
3eb6b044 | 1704 | ret = do_semctl(first, second, third, ptr); |
fa294816 TS |
1705 | break; |
1706 | ||
1707 | case IPCOP_semtimedop: | |
32407103 | 1708 | gemu_log("Unsupported ipc call: %d (version %d)\n", call, version); |
0da46a6e | 1709 | ret = -TARGET_ENOSYS; |
fa294816 | 1710 | break; |
d96372ef TS |
1711 | |
1712 | case IPCOP_msgget: | |
1713 | ret = get_errno(msgget(first, second)); | |
1714 | break; | |
1715 | ||
1716 | case IPCOP_msgsnd: | |
1bc012f6 | 1717 | ret = do_msgsnd(first, ptr, second, third); |
d96372ef TS |
1718 | break; |
1719 | ||
1720 | case IPCOP_msgctl: | |
1bc012f6 | 1721 | ret = do_msgctl(first, second, ptr); |
d96372ef TS |
1722 | break; |
1723 | ||
1724 | case IPCOP_msgrcv: | |
1bc012f6 TS |
1725 | { |
1726 | struct ipc_kludge | |
1727 | { | |
1728 | void *__unbounded msgp; | |
1729 | long int msgtyp; | |
1730 | }; | |
d96372ef | 1731 | |
1bc012f6 TS |
1732 | struct ipc_kludge *foo = (struct ipc_kludge *) ptr; |
1733 | struct msgbuf *msgp = (struct msgbuf *) foo->msgp; | |
d96372ef | 1734 | |
1bc012f6 | 1735 | ret = do_msgrcv(first, (long)msgp, second, 0, third); |
d96372ef | 1736 | |
1bc012f6 | 1737 | } |
d96372ef TS |
1738 | break; |
1739 | ||
8853f86e FB |
1740 | case IPCOP_shmat: |
1741 | /* SHM_* flags are the same on all linux platforms */ | |
1742 | ret = get_errno((long) shmat(first, (void *) ptr, second)); | |
1743 | if (is_error(ret)) | |
1744 | break; | |
1745 | raddr = ret; | |
1746 | /* find out the length of the shared memory segment */ | |
3b46e624 | 1747 | |
8853f86e FB |
1748 | ret = get_errno(shmctl(first, IPC_STAT, &shm_info)); |
1749 | if (is_error(ret)) { | |
1750 | /* can't get length, bail out */ | |
1751 | shmdt((void *) raddr); | |
1752 | break; | |
1753 | } | |
1754 | page_set_flags(raddr, raddr + shm_info.shm_segsz, | |
1755 | PAGE_VALID | PAGE_READ | | |
1756 | ((second & SHM_RDONLY)? 0: PAGE_WRITE)); | |
1757 | for (i = 0; i < N_SHM_REGIONS; ++i) { | |
1758 | if (shm_regions[i].start == 0) { | |
1759 | shm_regions[i].start = raddr; | |
1760 | shm_regions[i].size = shm_info.shm_segsz; | |
1761 | break; | |
1762 | } | |
1763 | } | |
992f48a0 | 1764 | if (put_user(raddr, (abi_ulong *)third)) |
0da46a6e | 1765 | return -TARGET_EFAULT; |
8853f86e FB |
1766 | ret = 0; |
1767 | break; | |
1768 | case IPCOP_shmdt: | |
1769 | for (i = 0; i < N_SHM_REGIONS; ++i) { | |
1770 | if (shm_regions[i].start == ptr) { | |
1771 | shm_regions[i].start = 0; | |
1772 | page_set_flags(ptr, shm_regions[i].size, 0); | |
1773 | break; | |
1774 | } | |
1775 | } | |
1776 | ret = get_errno(shmdt((void *) ptr)); | |
1777 | break; | |
1778 | ||
1779 | case IPCOP_shmget: | |
1780 | /* IPC_* flag values are the same on all linux platforms */ | |
1781 | ret = get_errno(shmget(first, second, third)); | |
1782 | break; | |
1783 | ||
1784 | /* IPC_* and SHM_* command values are the same on all linux platforms */ | |
1785 | case IPCOP_shmctl: | |
1786 | switch(second) { | |
1787 | case IPC_RMID: | |
1788 | case SHM_LOCK: | |
1789 | case SHM_UNLOCK: | |
1790 | ret = get_errno(shmctl(first, second, NULL)); | |
1791 | break; | |
1792 | default: | |
1793 | goto unimplemented; | |
1794 | } | |
1795 | break; | |
1796 | default: | |
1797 | unimplemented: | |
32407103 | 1798 | gemu_log("Unsupported ipc call: %d (version %d)\n", call, version); |
0da46a6e | 1799 | ret = -TARGET_ENOSYS; |
8853f86e FB |
1800 | break; |
1801 | } | |
1802 | return ret; | |
1803 | } | |
32407103 | 1804 | #endif |
8853f86e | 1805 | |
31e31b8a FB |
1806 | /* kernel structure types definitions */ |
1807 | #define IFNAMSIZ 16 | |
1808 | ||
1809 | #define STRUCT(name, list...) STRUCT_ ## name, | |
1810 | #define STRUCT_SPECIAL(name) STRUCT_ ## name, | |
1811 | enum { | |
1812 | #include "syscall_types.h" | |
1813 | }; | |
1814 | #undef STRUCT | |
1815 | #undef STRUCT_SPECIAL | |
1816 | ||
1817 | #define STRUCT(name, list...) const argtype struct_ ## name ## _def[] = { list, TYPE_NULL }; | |
1818 | #define STRUCT_SPECIAL(name) | |
1819 | #include "syscall_types.h" | |
1820 | #undef STRUCT | |
1821 | #undef STRUCT_SPECIAL | |
1822 | ||
1823 | typedef struct IOCTLEntry { | |
2ab83ea7 FB |
1824 | unsigned int target_cmd; |
1825 | unsigned int host_cmd; | |
31e31b8a FB |
1826 | const char *name; |
1827 | int access; | |
1a9353d2 | 1828 | const argtype arg_type[5]; |
31e31b8a FB |
1829 | } IOCTLEntry; |
1830 | ||
1831 | #define IOC_R 0x0001 | |
1832 | #define IOC_W 0x0002 | |
1833 | #define IOC_RW (IOC_R | IOC_W) | |
1834 | ||
1835 | #define MAX_STRUCT_SIZE 4096 | |
1836 | ||
2ab83ea7 | 1837 | IOCTLEntry ioctl_entries[] = { |
31e31b8a FB |
1838 | #define IOCTL(cmd, access, types...) \ |
1839 | { TARGET_ ## cmd, cmd, #cmd, access, { types } }, | |
1840 | #include "ioctls.h" | |
1841 | { 0, 0, }, | |
1842 | }; | |
1843 | ||
53a5960a | 1844 | /* ??? Implement proper locking for ioctls. */ |
0da46a6e | 1845 | /* do_ioctl() Must return target values and target errnos. */ |
992f48a0 | 1846 | static abi_long do_ioctl(int fd, abi_long cmd, abi_long arg) |
31e31b8a FB |
1847 | { |
1848 | const IOCTLEntry *ie; | |
1849 | const argtype *arg_type; | |
992f48a0 | 1850 | abi_long ret; |
31e31b8a | 1851 | uint8_t buf_temp[MAX_STRUCT_SIZE]; |
53a5960a PB |
1852 | int target_size; |
1853 | void *argptr; | |
31e31b8a FB |
1854 | |
1855 | ie = ioctl_entries; | |
1856 | for(;;) { | |
1857 | if (ie->target_cmd == 0) { | |
32407103 | 1858 | gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd); |
0da46a6e | 1859 | return -TARGET_ENOSYS; |
31e31b8a FB |
1860 | } |
1861 | if (ie->target_cmd == cmd) | |
1862 | break; | |
1863 | ie++; | |
1864 | } | |
1865 | arg_type = ie->arg_type; | |
9de5e440 | 1866 | #if defined(DEBUG) |
32407103 | 1867 | gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd, ie->name); |
72f03900 | 1868 | #endif |
31e31b8a FB |
1869 | switch(arg_type[0]) { |
1870 | case TYPE_NULL: | |
1871 | /* no argument */ | |
1872 | ret = get_errno(ioctl(fd, ie->host_cmd)); | |
1873 | break; | |
1874 | case TYPE_PTRVOID: | |
1875 | case TYPE_INT: | |
1876 | /* int argment */ | |
1877 | ret = get_errno(ioctl(fd, ie->host_cmd, arg)); | |
1878 | break; | |
1879 | case TYPE_PTR: | |
1880 | arg_type++; | |
53a5960a | 1881 | target_size = thunk_type_size(arg_type, 0); |
31e31b8a FB |
1882 | switch(ie->access) { |
1883 | case IOC_R: | |
1884 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); | |
1885 | if (!is_error(ret)) { | |
53a5960a PB |
1886 | argptr = lock_user(arg, target_size, 0); |
1887 | thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); | |
1888 | unlock_user(argptr, arg, target_size); | |
31e31b8a FB |
1889 | } |
1890 | break; | |
1891 | case IOC_W: | |
53a5960a PB |
1892 | argptr = lock_user(arg, target_size, 1); |
1893 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); | |
1894 | unlock_user(argptr, arg, 0); | |
31e31b8a FB |
1895 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
1896 | break; | |
1897 | default: | |
1898 | case IOC_RW: | |
53a5960a PB |
1899 | argptr = lock_user(arg, target_size, 1); |
1900 | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); | |
1901 | unlock_user(argptr, arg, 0); | |
31e31b8a FB |
1902 | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
1903 | if (!is_error(ret)) { | |
53a5960a PB |
1904 | argptr = lock_user(arg, target_size, 0); |
1905 | thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); | |
1906 | unlock_user(argptr, arg, target_size); | |
31e31b8a FB |
1907 | } |
1908 | break; | |
1909 | } | |
1910 | break; | |
1911 | default: | |
32407103 JM |
1912 | gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", |
1913 | (long)cmd, arg_type[0]); | |
0da46a6e | 1914 | ret = -TARGET_ENOSYS; |
31e31b8a FB |
1915 | break; |
1916 | } | |
1917 | return ret; | |
1918 | } | |
1919 | ||
1920 | bitmask_transtbl iflag_tbl[] = { | |
1921 | { TARGET_IGNBRK, TARGET_IGNBRK, IGNBRK, IGNBRK }, | |
1922 | { TARGET_BRKINT, TARGET_BRKINT, BRKINT, BRKINT }, | |
1923 | { TARGET_IGNPAR, TARGET_IGNPAR, IGNPAR, IGNPAR }, | |
1924 | { TARGET_PARMRK, TARGET_PARMRK, PARMRK, PARMRK }, | |
1925 | { TARGET_INPCK, TARGET_INPCK, INPCK, INPCK }, | |
1926 | { TARGET_ISTRIP, TARGET_ISTRIP, ISTRIP, ISTRIP }, | |
1927 | { TARGET_INLCR, TARGET_INLCR, INLCR, INLCR }, | |
1928 | { TARGET_IGNCR, TARGET_IGNCR, IGNCR, IGNCR }, | |
1929 | { TARGET_ICRNL, TARGET_ICRNL, ICRNL, ICRNL }, | |
1930 | { TARGET_IUCLC, TARGET_IUCLC, IUCLC, IUCLC }, | |
1931 | { TARGET_IXON, TARGET_IXON, IXON, IXON }, | |
1932 | { TARGET_IXANY, TARGET_IXANY, IXANY, IXANY }, | |
1933 | { TARGET_IXOFF, TARGET_IXOFF, IXOFF, IXOFF }, | |
1934 | { TARGET_IMAXBEL, TARGET_IMAXBEL, IMAXBEL, IMAXBEL }, | |
1935 | { 0, 0, 0, 0 } | |
1936 | }; | |
1937 | ||
1938 | bitmask_transtbl oflag_tbl[] = { | |
1939 | { TARGET_OPOST, TARGET_OPOST, OPOST, OPOST }, | |
1940 | { TARGET_OLCUC, TARGET_OLCUC, OLCUC, OLCUC }, | |
1941 | { TARGET_ONLCR, TARGET_ONLCR, ONLCR, ONLCR }, | |
1942 | { TARGET_OCRNL, TARGET_OCRNL, OCRNL, OCRNL }, | |
1943 | { TARGET_ONOCR, TARGET_ONOCR, ONOCR, ONOCR }, | |
1944 | { TARGET_ONLRET, TARGET_ONLRET, ONLRET, ONLRET }, | |
1945 | { TARGET_OFILL, TARGET_OFILL, OFILL, OFILL }, | |
1946 | { TARGET_OFDEL, TARGET_OFDEL, OFDEL, OFDEL }, | |
1947 | { TARGET_NLDLY, TARGET_NL0, NLDLY, NL0 }, | |
1948 | { TARGET_NLDLY, TARGET_NL1, NLDLY, NL1 }, | |
1949 | { TARGET_CRDLY, TARGET_CR0, CRDLY, CR0 }, | |
1950 | { TARGET_CRDLY, TARGET_CR1, CRDLY, CR1 }, | |
1951 | { TARGET_CRDLY, TARGET_CR2, CRDLY, CR2 }, | |
1952 | { TARGET_CRDLY, TARGET_CR3, CRDLY, CR3 }, | |
1953 | { TARGET_TABDLY, TARGET_TAB0, TABDLY, TAB0 }, | |
1954 | { TARGET_TABDLY, TARGET_TAB1, TABDLY, TAB1 }, | |
1955 | { TARGET_TABDLY, TARGET_TAB2, TABDLY, TAB2 }, | |
1956 | { TARGET_TABDLY, TARGET_TAB3, TABDLY, TAB3 }, | |
1957 | { TARGET_BSDLY, TARGET_BS0, BSDLY, BS0 }, | |
1958 | { TARGET_BSDLY, TARGET_BS1, BSDLY, BS1 }, | |
1959 | { TARGET_VTDLY, TARGET_VT0, VTDLY, VT0 }, | |
1960 | { TARGET_VTDLY, TARGET_VT1, VTDLY, VT1 }, | |
1961 | { TARGET_FFDLY, TARGET_FF0, FFDLY, FF0 }, | |
1962 | { TARGET_FFDLY, TARGET_FF1, FFDLY, FF1 }, | |
1963 | { 0, 0, 0, 0 } | |
1964 | }; | |
1965 | ||
1966 | bitmask_transtbl cflag_tbl[] = { | |
1967 | { TARGET_CBAUD, TARGET_B0, CBAUD, B0 }, | |
1968 | { TARGET_CBAUD, TARGET_B50, CBAUD, B50 }, | |
1969 | { TARGET_CBAUD, TARGET_B75, CBAUD, B75 }, | |
1970 | { TARGET_CBAUD, TARGET_B110, CBAUD, B110 }, | |
1971 | { TARGET_CBAUD, TARGET_B134, CBAUD, B134 }, | |
1972 | { TARGET_CBAUD, TARGET_B150, CBAUD, B150 }, | |
1973 | { TARGET_CBAUD, TARGET_B200, CBAUD, B200 }, | |
1974 | { TARGET_CBAUD, TARGET_B300, CBAUD, B300 }, | |
1975 | { TARGET_CBAUD, TARGET_B600, CBAUD, B600 }, | |
1976 | { TARGET_CBAUD, TARGET_B1200, CBAUD, B1200 }, | |
1977 | { TARGET_CBAUD, TARGET_B1800, CBAUD, B1800 }, | |
1978 | { TARGET_CBAUD, TARGET_B2400, CBAUD, B2400 }, | |
1979 | { TARGET_CBAUD, TARGET_B4800, CBAUD, B4800 }, | |
1980 | { TARGET_CBAUD, TARGET_B9600, CBAUD, B9600 }, | |
1981 | { TARGET_CBAUD, TARGET_B19200, CBAUD, B19200 }, | |
1982 | { TARGET_CBAUD, TARGET_B38400, CBAUD, B38400 }, | |
1983 | { TARGET_CBAUD, TARGET_B57600, CBAUD, B57600 }, | |
1984 | { TARGET_CBAUD, TARGET_B115200, CBAUD, B115200 }, | |
1985 | { TARGET_CBAUD, TARGET_B230400, CBAUD, B230400 }, | |
1986 | { TARGET_CBAUD, TARGET_B460800, CBAUD, B460800 }, | |
1987 | { TARGET_CSIZE, TARGET_CS5, CSIZE, CS5 }, | |
1988 | { TARGET_CSIZE, TARGET_CS6, CSIZE, CS6 }, | |
1989 | { TARGET_CSIZE, TARGET_CS7, CSIZE, CS7 }, | |
1990 | { TARGET_CSIZE, TARGET_CS8, CSIZE, CS8 }, | |
1991 | { TARGET_CSTOPB, TARGET_CSTOPB, CSTOPB, CSTOPB }, | |
1992 | { TARGET_CREAD, TARGET_CREAD, CREAD, CREAD }, | |
1993 | { TARGET_PARENB, TARGET_PARENB, PARENB, PARENB }, | |
1994 | { TARGET_PARODD, TARGET_PARODD, PARODD, PARODD }, | |
1995 | { TARGET_HUPCL, TARGET_HUPCL, HUPCL, HUPCL }, | |
1996 | { TARGET_CLOCAL, TARGET_CLOCAL, CLOCAL, CLOCAL }, | |
1997 | { TARGET_CRTSCTS, TARGET_CRTSCTS, CRTSCTS, CRTSCTS }, | |
1998 | { 0, 0, 0, 0 } | |
1999 | }; | |
2000 | ||
2001 | bitmask_transtbl lflag_tbl[] = { | |
2002 | { TARGET_ISIG, TARGET_ISIG, ISIG, ISIG }, | |
2003 | { TARGET_ICANON, TARGET_ICANON, ICANON, ICANON }, | |
2004 | { TARGET_XCASE, TARGET_XCASE, XCASE, XCASE }, | |
2005 | { TARGET_ECHO, TARGET_ECHO, ECHO, ECHO }, | |
2006 | { TARGET_ECHOE, TARGET_ECHOE, ECHOE, ECHOE }, | |
2007 | { TARGET_ECHOK, TARGET_ECHOK, ECHOK, ECHOK }, | |
2008 | { TARGET_ECHONL, TARGET_ECHONL, ECHONL, ECHONL }, | |
2009 | { TARGET_NOFLSH, TARGET_NOFLSH, NOFLSH, NOFLSH }, | |
2010 | { TARGET_TOSTOP, TARGET_TOSTOP, TOSTOP, TOSTOP }, | |
2011 | { TARGET_ECHOCTL, TARGET_ECHOCTL, ECHOCTL, ECHOCTL }, | |
2012 | { TARGET_ECHOPRT, TARGET_ECHOPRT, ECHOPRT, ECHOPRT }, | |
2013 | { TARGET_ECHOKE, TARGET_ECHOKE, ECHOKE, ECHOKE }, | |
2014 | { TARGET_FLUSHO, TARGET_FLUSHO, FLUSHO, FLUSHO }, | |
2015 | { TARGET_PENDIN, TARGET_PENDIN, PENDIN, PENDIN }, | |
2016 | { TARGET_IEXTEN, TARGET_IEXTEN, IEXTEN, IEXTEN }, | |
2017 | { 0, 0, 0, 0 } | |
2018 | }; | |
2019 | ||
2020 | static void target_to_host_termios (void *dst, const void *src) | |
2021 | { | |
2022 | struct host_termios *host = dst; | |
2023 | const struct target_termios *target = src; | |
3b46e624 | 2024 | |
5fafdf24 | 2025 | host->c_iflag = |
31e31b8a | 2026 | target_to_host_bitmask(tswap32(target->c_iflag), iflag_tbl); |
5fafdf24 | 2027 | host->c_oflag = |
31e31b8a | 2028 | target_to_host_bitmask(tswap32(target->c_oflag), oflag_tbl); |
5fafdf24 | 2029 | host->c_cflag = |
31e31b8a | 2030 | target_to_host_bitmask(tswap32(target->c_cflag), cflag_tbl); |
5fafdf24 | 2031 | host->c_lflag = |
31e31b8a FB |
2032 | target_to_host_bitmask(tswap32(target->c_lflag), lflag_tbl); |
2033 | host->c_line = target->c_line; | |
3b46e624 | 2034 | |
5fafdf24 TS |
2035 | host->c_cc[VINTR] = target->c_cc[TARGET_VINTR]; |
2036 | host->c_cc[VQUIT] = target->c_cc[TARGET_VQUIT]; | |
3b46e624 | 2037 | host->c_cc[VERASE] = target->c_cc[TARGET_VERASE]; |
5fafdf24 | 2038 | host->c_cc[VKILL] = target->c_cc[TARGET_VKILL]; |
3b46e624 | 2039 | host->c_cc[VEOF] = target->c_cc[TARGET_VEOF]; |
5fafdf24 | 2040 | host->c_cc[VTIME] = target->c_cc[TARGET_VTIME]; |
3b46e624 | 2041 | host->c_cc[VMIN] = target->c_cc[TARGET_VMIN]; |
5fafdf24 | 2042 | host->c_cc[VSWTC] = target->c_cc[TARGET_VSWTC]; |
3b46e624 | 2043 | host->c_cc[VSTART] = target->c_cc[TARGET_VSTART]; |
5fafdf24 TS |
2044 | host->c_cc[VSTOP] = target->c_cc[TARGET_VSTOP]; |
2045 | host->c_cc[VSUSP] = target->c_cc[TARGET_VSUSP]; | |
3b46e624 TS |
2046 | host->c_cc[VEOL] = target->c_cc[TARGET_VEOL]; |
2047 | host->c_cc[VREPRINT] = target->c_cc[TARGET_VREPRINT]; | |
2048 | host->c_cc[VDISCARD] = target->c_cc[TARGET_VDISCARD]; | |
2049 | host->c_cc[VWERASE] = target->c_cc[TARGET_VWERASE]; | |
2050 | host->c_cc[VLNEXT] = target->c_cc[TARGET_VLNEXT]; | |
5fafdf24 | 2051 | host->c_cc[VEOL2] = target->c_cc[TARGET_VEOL2]; |
31e31b8a | 2052 | } |
3b46e624 | 2053 | |
31e31b8a FB |
2054 | static void host_to_target_termios (void *dst, const void *src) |
2055 | { | |
2056 | struct target_termios *target = dst; | |
2057 | const struct host_termios *host = src; | |
2058 | ||
5fafdf24 | 2059 | target->c_iflag = |
31e31b8a | 2060 | tswap32(host_to_target_bitmask(host->c_iflag, iflag_tbl)); |
5fafdf24 | 2061 | target->c_oflag = |
31e31b8a | 2062 | tswap32(host_to_target_bitmask(host->c_oflag, oflag_tbl)); |
5fafdf24 | 2063 | target->c_cflag = |
31e31b8a | 2064 | tswap32(host_to_target_bitmask(host->c_cflag, cflag_tbl)); |
5fafdf24 | 2065 | target->c_lflag = |
31e31b8a FB |
2066 | tswap32(host_to_target_bitmask(host->c_lflag, lflag_tbl)); |
2067 | target->c_line = host->c_line; | |
3b46e624 | 2068 | |
31e31b8a FB |
2069 | target->c_cc[TARGET_VINTR] = host->c_cc[VINTR]; |
2070 | target->c_cc[TARGET_VQUIT] = host->c_cc[VQUIT]; | |
2071 | target->c_cc[TARGET_VERASE] = host->c_cc[VERASE]; | |
2072 | target->c_cc[TARGET_VKILL] = host->c_cc[VKILL]; | |
2073 | target->c_cc[TARGET_VEOF] = host->c_cc[VEOF]; | |
2074 | target->c_cc[TARGET_VTIME] = host->c_cc[VTIME]; | |
2075 | target->c_cc[TARGET_VMIN] = host->c_cc[VMIN]; | |
2076 | target->c_cc[TARGET_VSWTC] = host->c_cc[VSWTC]; | |
2077 | target->c_cc[TARGET_VSTART] = host->c_cc[VSTART]; | |
2078 | target->c_cc[TARGET_VSTOP] = host->c_cc[VSTOP]; | |
2079 | target->c_cc[TARGET_VSUSP] = host->c_cc[VSUSP]; | |
2080 | target->c_cc[TARGET_VEOL] = host->c_cc[VEOL]; | |
2081 | target->c_cc[TARGET_VREPRINT] = host->c_cc[VREPRINT]; | |
2082 | target->c_cc[TARGET_VDISCARD] = host->c_cc[VDISCARD]; | |
2083 | target->c_cc[TARGET_VWERASE] = host->c_cc[VWERASE]; | |
2084 | target->c_cc[TARGET_VLNEXT] = host->c_cc[VLNEXT]; | |
2085 | target->c_cc[TARGET_VEOL2] = host->c_cc[VEOL2]; | |
2086 | } | |
2087 | ||
2088 | StructEntry struct_termios_def = { | |
2089 | .convert = { host_to_target_termios, target_to_host_termios }, | |
2090 | .size = { sizeof(struct target_termios), sizeof(struct host_termios) }, | |
2091 | .align = { __alignof__(struct target_termios), __alignof__(struct host_termios) }, | |
2092 | }; | |
2093 | ||
5286db75 FB |
2094 | static bitmask_transtbl mmap_flags_tbl[] = { |
2095 | { TARGET_MAP_SHARED, TARGET_MAP_SHARED, MAP_SHARED, MAP_SHARED }, | |
2096 | { TARGET_MAP_PRIVATE, TARGET_MAP_PRIVATE, MAP_PRIVATE, MAP_PRIVATE }, | |
2097 | { TARGET_MAP_FIXED, TARGET_MAP_FIXED, MAP_FIXED, MAP_FIXED }, | |
2098 | { TARGET_MAP_ANONYMOUS, TARGET_MAP_ANONYMOUS, MAP_ANONYMOUS, MAP_ANONYMOUS }, | |
2099 | { TARGET_MAP_GROWSDOWN, TARGET_MAP_GROWSDOWN, MAP_GROWSDOWN, MAP_GROWSDOWN }, | |
2100 | { TARGET_MAP_DENYWRITE, TARGET_MAP_DENYWRITE, MAP_DENYWRITE, MAP_DENYWRITE }, | |
2101 | { TARGET_MAP_EXECUTABLE, TARGET_MAP_EXECUTABLE, MAP_EXECUTABLE, MAP_EXECUTABLE }, | |
2102 | { TARGET_MAP_LOCKED, TARGET_MAP_LOCKED, MAP_LOCKED, MAP_LOCKED }, | |
2103 | { 0, 0, 0, 0 } | |
2104 | }; | |
2105 | ||
ffa65c3b FB |
2106 | static bitmask_transtbl fcntl_flags_tbl[] = { |
2107 | { TARGET_O_ACCMODE, TARGET_O_WRONLY, O_ACCMODE, O_WRONLY, }, | |
2108 | { TARGET_O_ACCMODE, TARGET_O_RDWR, O_ACCMODE, O_RDWR, }, | |
2109 | { TARGET_O_CREAT, TARGET_O_CREAT, O_CREAT, O_CREAT, }, | |
2110 | { TARGET_O_EXCL, TARGET_O_EXCL, O_EXCL, O_EXCL, }, | |
2111 | { TARGET_O_NOCTTY, TARGET_O_NOCTTY, O_NOCTTY, O_NOCTTY, }, | |
2112 | { TARGET_O_TRUNC, TARGET_O_TRUNC, O_TRUNC, O_TRUNC, }, | |
2113 | { TARGET_O_APPEND, TARGET_O_APPEND, O_APPEND, O_APPEND, }, | |
2114 | { TARGET_O_NONBLOCK, TARGET_O_NONBLOCK, O_NONBLOCK, O_NONBLOCK, }, | |
2115 | { TARGET_O_SYNC, TARGET_O_SYNC, O_SYNC, O_SYNC, }, | |
2116 | { TARGET_FASYNC, TARGET_FASYNC, FASYNC, FASYNC, }, | |
2117 | { TARGET_O_DIRECTORY, TARGET_O_DIRECTORY, O_DIRECTORY, O_DIRECTORY, }, | |
2118 | { TARGET_O_NOFOLLOW, TARGET_O_NOFOLLOW, O_NOFOLLOW, O_NOFOLLOW, }, | |
2119 | { TARGET_O_LARGEFILE, TARGET_O_LARGEFILE, O_LARGEFILE, O_LARGEFILE, }, | |
121061dc | 2120 | #if defined(O_DIRECT) |
ffa65c3b | 2121 | { TARGET_O_DIRECT, TARGET_O_DIRECT, O_DIRECT, O_DIRECT, }, |
121061dc | 2122 | #endif |
ffa65c3b FB |
2123 | { 0, 0, 0, 0 } |
2124 | }; | |
2125 | ||
2ab83ea7 | 2126 | #if defined(TARGET_I386) |
6dbad63e FB |
2127 | |
2128 | /* NOTE: there is really one LDT for all the threads */ | |
2129 | uint8_t *ldt_table; | |
2130 | ||
992f48a0 | 2131 | static int read_ldt(abi_ulong ptr, unsigned long bytecount) |
6dbad63e FB |
2132 | { |
2133 | int size; | |
53a5960a | 2134 | void *p; |
6dbad63e FB |
2135 | |
2136 | if (!ldt_table) | |
2137 | return 0; | |
2138 | size = TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE; | |
2139 | if (size > bytecount) | |
2140 | size = bytecount; | |
53a5960a PB |
2141 | p = lock_user(ptr, size, 0); |
2142 | /* ??? Shoudl this by byteswapped? */ | |
2143 | memcpy(p, ldt_table, size); | |
2144 | unlock_user(p, ptr, size); | |
6dbad63e FB |
2145 | return size; |
2146 | } | |
2147 | ||
2148 | /* XXX: add locking support */ | |
0da46a6e | 2149 | /* write_ldt() returns host errnos */ |
5fafdf24 | 2150 | static int write_ldt(CPUX86State *env, |
992f48a0 | 2151 | abi_ulong ptr, unsigned long bytecount, int oldmode) |
6dbad63e FB |
2152 | { |
2153 | struct target_modify_ldt_ldt_s ldt_info; | |
53a5960a | 2154 | struct target_modify_ldt_ldt_s *target_ldt_info; |
6dbad63e FB |
2155 | int seg_32bit, contents, read_exec_only, limit_in_pages; |
2156 | int seg_not_present, useable; | |
2157 | uint32_t *lp, entry_1, entry_2; | |
2158 | ||
2159 | if (bytecount != sizeof(ldt_info)) | |
2160 | return -EINVAL; | |
53a5960a PB |
2161 | lock_user_struct(target_ldt_info, ptr, 1); |
2162 | ldt_info.entry_number = tswap32(target_ldt_info->entry_number); | |
2163 | ldt_info.base_addr = tswapl(target_ldt_info->base_addr); | |
2164 | ldt_info.limit = tswap32(target_ldt_info->limit); | |
2165 | ldt_info.flags = tswap32(target_ldt_info->flags); | |
2166 | unlock_user_struct(target_ldt_info, ptr, 0); | |
3b46e624 | 2167 | |
6dbad63e FB |
2168 | if (ldt_info.entry_number >= TARGET_LDT_ENTRIES) |
2169 | return -EINVAL; | |
2170 | seg_32bit = ldt_info.flags & 1; | |
2171 | contents = (ldt_info.flags >> 1) & 3; | |
2172 | read_exec_only = (ldt_info.flags >> 3) & 1; | |
2173 | limit_in_pages = (ldt_info.flags >> 4) & 1; | |
2174 | seg_not_present = (ldt_info.flags >> 5) & 1; | |
2175 | useable = (ldt_info.flags >> 6) & 1; | |
2176 | ||
2177 | if (contents == 3) { | |
2178 | if (oldmode) | |
2179 | return -EINVAL; | |
2180 | if (seg_not_present == 0) | |
2181 | return -EINVAL; | |
2182 | } | |
2183 | /* allocate the LDT */ | |
2184 | if (!ldt_table) { | |
2185 | ldt_table = malloc(TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE); | |
2186 | if (!ldt_table) | |
2187 | return -ENOMEM; | |
2188 | memset(ldt_table, 0, TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE); | |
53a5960a | 2189 | env->ldt.base = h2g(ldt_table); |
6dbad63e FB |
2190 | env->ldt.limit = 0xffff; |
2191 | } | |
2192 | ||
2193 | /* NOTE: same code as Linux kernel */ | |
2194 | /* Allow LDTs to be cleared by the user. */ | |
2195 | if (ldt_info.base_addr == 0 && ldt_info.limit == 0) { | |
2196 | if (oldmode || | |
2197 | (contents == 0 && | |
2198 | read_exec_only == 1 && | |
2199 | seg_32bit == 0 && | |
2200 | limit_in_pages == 0 && | |
2201 | seg_not_present == 1 && | |
2202 | useable == 0 )) { | |
2203 | entry_1 = 0; | |
2204 | entry_2 = 0; | |
2205 | goto install; | |
2206 | } | |
2207 | } | |
3b46e624 | 2208 | |
6dbad63e FB |
2209 | entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) | |
2210 | (ldt_info.limit & 0x0ffff); | |
2211 | entry_2 = (ldt_info.base_addr & 0xff000000) | | |
2212 | ((ldt_info.base_addr & 0x00ff0000) >> 16) | | |
2213 | (ldt_info.limit & 0xf0000) | | |
2214 | ((read_exec_only ^ 1) << 9) | | |
2215 | (contents << 10) | | |
2216 | ((seg_not_present ^ 1) << 15) | | |
2217 | (seg_32bit << 22) | | |
2218 | (limit_in_pages << 23) | | |
2219 | 0x7000; | |
2220 | if (!oldmode) | |
2221 | entry_2 |= (useable << 20); | |
14ae3ba7 | 2222 | |
6dbad63e FB |
2223 | /* Install the new entry ... */ |
2224 | install: | |
2225 | lp = (uint32_t *)(ldt_table + (ldt_info.entry_number << 3)); | |
2226 | lp[0] = tswap32(entry_1); | |
2227 | lp[1] = tswap32(entry_2); | |
2228 | return 0; | |
2229 | } | |
2230 | ||
2231 | /* specific and weird i386 syscalls */ | |
0da46a6e TS |
2232 | /* do_modify_ldt() returns host errnos (it is inconsistent with the |
2233 | other do_*() functions which return target errnos). */ | |
992f48a0 | 2234 | int do_modify_ldt(CPUX86State *env, int func, abi_ulong ptr, unsigned long bytecount) |
6dbad63e FB |
2235 | { |
2236 | int ret = -ENOSYS; | |
3b46e624 | 2237 | |
6dbad63e FB |
2238 | switch (func) { |
2239 | case 0: | |
2240 | ret = read_ldt(ptr, bytecount); | |
2241 | break; | |
2242 | case 1: | |
2243 | ret = write_ldt(env, ptr, bytecount, 1); | |
2244 | break; | |
2245 | case 0x11: | |
2246 | ret = write_ldt(env, ptr, bytecount, 0); | |
2247 | break; | |
2248 | } | |
2249 | return ret; | |
2250 | } | |
1b6b029e | 2251 | |
2ab83ea7 FB |
2252 | #endif /* defined(TARGET_I386) */ |
2253 | ||
1b6b029e FB |
2254 | /* this stack is the equivalent of the kernel stack associated with a |
2255 | thread/process */ | |
2256 | #define NEW_STACK_SIZE 8192 | |
2257 | ||
2258 | static int clone_func(void *arg) | |
2259 | { | |
2ab83ea7 | 2260 | CPUState *env = arg; |
1b6b029e FB |
2261 | cpu_loop(env); |
2262 | /* never exits */ | |
2263 | return 0; | |
2264 | } | |
2265 | ||
0da46a6e TS |
2266 | /* do_fork() Must return host values and target errnos (unlike most |
2267 | do_*() functions). */ | |
992f48a0 | 2268 | int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp) |
1b6b029e FB |
2269 | { |
2270 | int ret; | |
5cd4393b | 2271 | TaskState *ts; |
1b6b029e | 2272 | uint8_t *new_stack; |
2ab83ea7 | 2273 | CPUState *new_env; |
3b46e624 | 2274 | |
1b6b029e | 2275 | if (flags & CLONE_VM) { |
5cd4393b FB |
2276 | ts = malloc(sizeof(TaskState) + NEW_STACK_SIZE); |
2277 | memset(ts, 0, sizeof(TaskState)); | |
2278 | new_stack = ts->stack; | |
2279 | ts->used = 1; | |
2280 | /* add in task state list */ | |
2281 | ts->next = first_task_state; | |
2282 | first_task_state = ts; | |
1b6b029e | 2283 | /* we create a new CPU instance. */ |
c5be9f08 | 2284 | new_env = cpu_copy(env); |
2ab83ea7 FB |
2285 | #if defined(TARGET_I386) |
2286 | if (!newsp) | |
2287 | newsp = env->regs[R_ESP]; | |
1b6b029e FB |
2288 | new_env->regs[R_ESP] = newsp; |
2289 | new_env->regs[R_EAX] = 0; | |
2ab83ea7 FB |
2290 | #elif defined(TARGET_ARM) |
2291 | if (!newsp) | |
2292 | newsp = env->regs[13]; | |
2293 | new_env->regs[13] = newsp; | |
2294 | new_env->regs[0] = 0; | |
ebc05488 | 2295 | #elif defined(TARGET_SPARC) |
48dc41eb FB |
2296 | if (!newsp) |
2297 | newsp = env->regwptr[22]; | |
2298 | new_env->regwptr[22] = newsp; | |
2299 | new_env->regwptr[0] = 0; | |
2300 | /* XXXXX */ | |
67867308 | 2301 | printf ("HELPME: %s:%d\n", __FILE__, __LINE__); |
e6e5906b PB |
2302 | #elif defined(TARGET_M68K) |
2303 | if (!newsp) | |
2304 | newsp = env->aregs[7]; | |
2305 | new_env->aregs[7] = newsp; | |
2306 | new_env->dregs[0] = 0; | |
2307 | /* ??? is this sufficient? */ | |
048f6b4d | 2308 | #elif defined(TARGET_MIPS) |
388bb21a | 2309 | if (!newsp) |
ead9360e TS |
2310 | newsp = env->gpr[29][env->current_tc]; |
2311 | new_env->gpr[29][env->current_tc] = newsp; | |
67867308 FB |
2312 | #elif defined(TARGET_PPC) |
2313 | if (!newsp) | |
2314 | newsp = env->gpr[1]; | |
2315 | new_env->gpr[1] = newsp; | |
5fafdf24 | 2316 | { |
67867308 FB |
2317 | int i; |
2318 | for (i = 7; i < 32; i++) | |
2319 | new_env->gpr[i] = 0; | |
2320 | } | |
fdf9b3e8 FB |
2321 | #elif defined(TARGET_SH4) |
2322 | if (!newsp) | |
2323 | newsp = env->gregs[15]; | |
2324 | new_env->gregs[15] = newsp; | |
2325 | /* XXXXX */ | |
7a3148a9 JM |
2326 | #elif defined(TARGET_ALPHA) |
2327 | if (!newsp) | |
2328 | newsp = env->ir[30]; | |
2329 | new_env->ir[30] = newsp; | |
2330 | /* ? */ | |
2331 | { | |
2332 | int i; | |
2333 | for (i = 7; i < 30; i++) | |
2334 | new_env->ir[i] = 0; | |
2335 | } | |
48733d19 TS |
2336 | #elif defined(TARGET_CRIS) |
2337 | if (!newsp) | |
2338 | newsp = env->regs[14]; | |
2339 | new_env->regs[14] = newsp; | |
2ab83ea7 FB |
2340 | #else |
2341 | #error unsupported target CPU | |
2342 | #endif | |
5cd4393b | 2343 | new_env->opaque = ts; |
27725c1d | 2344 | #ifdef __ia64__ |
fd4a43e4 | 2345 | ret = __clone2(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env); |
27725c1d FB |
2346 | #else |
2347 | ret = clone(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env); | |
2348 | #endif | |
1b6b029e FB |
2349 | } else { |
2350 | /* if no CLONE_VM, we consider it is a fork */ | |
2351 | if ((flags & ~CSIGNAL) != 0) | |
2352 | return -EINVAL; | |
2353 | ret = fork(); | |
2354 | } | |
2355 | return ret; | |
2356 | } | |
2357 | ||
992f48a0 | 2358 | static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) |
7775e9ec FB |
2359 | { |
2360 | struct flock fl; | |
53a5960a | 2361 | struct target_flock *target_fl; |
43f238d7 TS |
2362 | struct flock64 fl64; |
2363 | struct target_flock64 *target_fl64; | |
992f48a0 | 2364 | abi_long ret; |
53a5960a | 2365 | |
7775e9ec FB |
2366 | switch(cmd) { |
2367 | case TARGET_F_GETLK: | |
5813427b TS |
2368 | lock_user_struct(target_fl, arg, 1); |
2369 | fl.l_type = tswap16(target_fl->l_type); | |
2370 | fl.l_whence = tswap16(target_fl->l_whence); | |
2371 | fl.l_start = tswapl(target_fl->l_start); | |
2372 | fl.l_len = tswapl(target_fl->l_len); | |
2373 | fl.l_pid = tswapl(target_fl->l_pid); | |
2374 | unlock_user_struct(target_fl, arg, 0); | |
7775e9ec FB |
2375 | ret = fcntl(fd, cmd, &fl); |
2376 | if (ret == 0) { | |
53a5960a | 2377 | lock_user_struct(target_fl, arg, 0); |
7775e9ec FB |
2378 | target_fl->l_type = tswap16(fl.l_type); |
2379 | target_fl->l_whence = tswap16(fl.l_whence); | |
2380 | target_fl->l_start = tswapl(fl.l_start); | |
2381 | target_fl->l_len = tswapl(fl.l_len); | |
2382 | target_fl->l_pid = tswapl(fl.l_pid); | |
53a5960a | 2383 | unlock_user_struct(target_fl, arg, 1); |
7775e9ec FB |
2384 | } |
2385 | break; | |
3b46e624 | 2386 | |
7775e9ec FB |
2387 | case TARGET_F_SETLK: |
2388 | case TARGET_F_SETLKW: | |
53a5960a | 2389 | lock_user_struct(target_fl, arg, 1); |
7775e9ec FB |
2390 | fl.l_type = tswap16(target_fl->l_type); |
2391 | fl.l_whence = tswap16(target_fl->l_whence); | |
2392 | fl.l_start = tswapl(target_fl->l_start); | |
2393 | fl.l_len = tswapl(target_fl->l_len); | |
2394 | fl.l_pid = tswapl(target_fl->l_pid); | |
53a5960a | 2395 | unlock_user_struct(target_fl, arg, 0); |
7775e9ec FB |
2396 | ret = fcntl(fd, cmd, &fl); |
2397 | break; | |
3b46e624 | 2398 | |
7775e9ec | 2399 | case TARGET_F_GETLK64: |
5813427b TS |
2400 | lock_user_struct(target_fl64, arg, 1); |
2401 | fl64.l_type = tswap16(target_fl64->l_type) >> 1; | |
2402 | fl64.l_whence = tswap16(target_fl64->l_whence); | |
2403 | fl64.l_start = tswapl(target_fl64->l_start); | |
2404 | fl64.l_len = tswapl(target_fl64->l_len); | |
2405 | fl64.l_pid = tswap16(target_fl64->l_pid); | |
2406 | unlock_user_struct(target_fl64, arg, 0); | |
43f238d7 TS |
2407 | ret = fcntl(fd, cmd >> 1, &fl64); |
2408 | if (ret == 0) { | |
2409 | lock_user_struct(target_fl64, arg, 0); | |
2410 | target_fl64->l_type = tswap16(fl64.l_type) >> 1; | |
2411 | target_fl64->l_whence = tswap16(fl64.l_whence); | |
2412 | target_fl64->l_start = tswapl(fl64.l_start); | |
2413 | target_fl64->l_len = tswapl(fl64.l_len); | |
2414 | target_fl64->l_pid = tswapl(fl64.l_pid); | |
2415 | unlock_user_struct(target_fl64, arg, 1); | |
2416 | } | |
2417 | break; | |
7775e9ec FB |
2418 | case TARGET_F_SETLK64: |
2419 | case TARGET_F_SETLKW64: | |
43f238d7 TS |
2420 | lock_user_struct(target_fl64, arg, 1); |
2421 | fl64.l_type = tswap16(target_fl64->l_type) >> 1; | |
2422 | fl64.l_whence = tswap16(target_fl64->l_whence); | |
2423 | fl64.l_start = tswapl(target_fl64->l_start); | |
2424 | fl64.l_len = tswapl(target_fl64->l_len); | |
2425 | fl64.l_pid = tswap16(target_fl64->l_pid); | |
2426 | unlock_user_struct(target_fl64, arg, 0); | |
2427 | ret = fcntl(fd, cmd >> 1, &fl64); | |
7775e9ec FB |
2428 | break; |
2429 | ||
ffa65c3b FB |
2430 | case F_GETFL: |
2431 | ret = fcntl(fd, cmd, arg); | |
2432 | ret = host_to_target_bitmask(ret, fcntl_flags_tbl); | |
2433 | break; | |
2434 | ||
2435 | case F_SETFL: | |
2436 | ret = fcntl(fd, cmd, target_to_host_bitmask(arg, fcntl_flags_tbl)); | |
2437 | break; | |
2438 | ||
7775e9ec FB |
2439 | default: |
2440 | ret = fcntl(fd, cmd, arg); | |
2441 | break; | |
2442 | } | |
2443 | return ret; | |
2444 | } | |
2445 | ||
67867308 | 2446 | #ifdef USE_UID16 |
7775e9ec | 2447 | |
67867308 FB |
2448 | static inline int high2lowuid(int uid) |
2449 | { | |
2450 | if (uid > 65535) | |
2451 | return 65534; | |
2452 | else | |
2453 | return uid; | |
2454 | } | |
2455 | ||
2456 | static inline int high2lowgid(int gid) | |
2457 | { | |
2458 | if (gid > 65535) | |
2459 | return 65534; | |
2460 | else | |
2461 | return gid; | |
2462 | } | |
2463 | ||
2464 | static inline int low2highuid(int uid) | |
2465 | { | |
2466 | if ((int16_t)uid == -1) | |
2467 | return -1; | |
2468 | else | |
2469 | return uid; | |
2470 | } | |
2471 | ||
2472 | static inline int low2highgid(int gid) | |
2473 | { | |
2474 | if ((int16_t)gid == -1) | |
2475 | return -1; | |
2476 | else | |
2477 | return gid; | |
2478 | } | |
2479 | ||
2480 | #endif /* USE_UID16 */ | |
1b6b029e | 2481 | |
31e31b8a FB |
2482 | void syscall_init(void) |
2483 | { | |
2ab83ea7 FB |
2484 | IOCTLEntry *ie; |
2485 | const argtype *arg_type; | |
2486 | int size; | |
b92c47c1 | 2487 | int i; |
2ab83ea7 | 2488 | |
5fafdf24 TS |
2489 | #define STRUCT(name, list...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def); |
2490 | #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def); | |
31e31b8a FB |
2491 | #include "syscall_types.h" |
2492 | #undef STRUCT | |
2493 | #undef STRUCT_SPECIAL | |
2ab83ea7 FB |
2494 | |
2495 | /* we patch the ioctl size if necessary. We rely on the fact that | |
2496 | no ioctl has all the bits at '1' in the size field */ | |
2497 | ie = ioctl_entries; | |
2498 | while (ie->target_cmd != 0) { | |
2499 | if (((ie->target_cmd >> TARGET_IOC_SIZESHIFT) & TARGET_IOC_SIZEMASK) == | |
2500 | TARGET_IOC_SIZEMASK) { | |
2501 | arg_type = ie->arg_type; | |
2502 | if (arg_type[0] != TYPE_PTR) { | |
5fafdf24 | 2503 | fprintf(stderr, "cannot patch size for ioctl 0x%x\n", |
2ab83ea7 FB |
2504 | ie->target_cmd); |
2505 | exit(1); | |
2506 | } | |
2507 | arg_type++; | |
2508 | size = thunk_type_size(arg_type, 0); | |
5fafdf24 | 2509 | ie->target_cmd = (ie->target_cmd & |
2ab83ea7 FB |
2510 | ~(TARGET_IOC_SIZEMASK << TARGET_IOC_SIZESHIFT)) | |
2511 | (size << TARGET_IOC_SIZESHIFT); | |
2512 | } | |
b92c47c1 TS |
2513 | |
2514 | /* Build target_to_host_errno_table[] table from | |
2515 | * host_to_target_errno_table[]. */ | |
2516 | for (i=0; i < ERRNO_TABLE_SIZE; i++) | |
2517 | target_to_host_errno_table[host_to_target_errno_table[i]] = i; | |
2518 | ||
2ab83ea7 FB |
2519 | /* automatic consistency check if same arch */ |
2520 | #if defined(__i386__) && defined(TARGET_I386) | |
2521 | if (ie->target_cmd != ie->host_cmd) { | |
5fafdf24 | 2522 | fprintf(stderr, "ERROR: ioctl: target=0x%x host=0x%x\n", |
2ab83ea7 FB |
2523 | ie->target_cmd, ie->host_cmd); |
2524 | } | |
2525 | #endif | |
2526 | ie++; | |
2527 | } | |
31e31b8a | 2528 | } |
c573ff67 | 2529 | |
992f48a0 | 2530 | #if TARGET_ABI_BITS == 32 |
ce4defa0 PB |
2531 | static inline uint64_t target_offset64(uint32_t word0, uint32_t word1) |
2532 | { | |
2533 | #ifdef TARGET_WORDS_BIG_ENDIAN | |
2534 | return ((uint64_t)word0 << 32) | word1; | |
2535 | #else | |
2536 | return ((uint64_t)word1 << 32) | word0; | |
2537 | #endif | |
2538 | } | |
992f48a0 | 2539 | #else /* TARGET_ABI_BITS == 32 */ |
32407103 JM |
2540 | static inline uint64_t target_offset64(uint64_t word0, uint64_t word1) |
2541 | { | |
2542 | return word0; | |
2543 | } | |
992f48a0 | 2544 | #endif /* TARGET_ABI_BITS != 32 */ |
ce4defa0 PB |
2545 | |
2546 | #ifdef TARGET_NR_truncate64 | |
992f48a0 BS |
2547 | static inline abi_long target_truncate64(void *cpu_env, const char *arg1, |
2548 | abi_long arg2, | |
2549 | abi_long arg3, | |
2550 | abi_long arg4) | |
ce4defa0 PB |
2551 | { |
2552 | #ifdef TARGET_ARM | |
2553 | if (((CPUARMState *)cpu_env)->eabi) | |
2554 | { | |
2555 | arg2 = arg3; | |
2556 | arg3 = arg4; | |
2557 | } | |
2558 | #endif | |
2559 | return get_errno(truncate64(arg1, target_offset64(arg2, arg3))); | |
2560 | } | |
2561 | #endif | |
2562 | ||
2563 | #ifdef TARGET_NR_ftruncate64 | |
992f48a0 BS |
2564 | static inline abi_long target_ftruncate64(void *cpu_env, abi_long arg1, |
2565 | abi_long arg2, | |
2566 | abi_long arg3, | |
2567 | abi_long arg4) | |
ce4defa0 PB |
2568 | { |
2569 | #ifdef TARGET_ARM | |
2570 | if (((CPUARMState *)cpu_env)->eabi) | |
2571 | { | |
2572 | arg2 = arg3; | |
2573 | arg3 = arg4; | |
2574 | } | |
2575 | #endif | |
2576 | return get_errno(ftruncate64(arg1, target_offset64(arg2, arg3))); | |
2577 | } | |
2578 | #endif | |
2579 | ||
53a5960a | 2580 | static inline void target_to_host_timespec(struct timespec *host_ts, |
992f48a0 | 2581 | abi_ulong target_addr) |
53a5960a PB |
2582 | { |
2583 | struct target_timespec *target_ts; | |
2584 | ||
2585 | lock_user_struct(target_ts, target_addr, 1); | |
2586 | host_ts->tv_sec = tswapl(target_ts->tv_sec); | |
2587 | host_ts->tv_nsec = tswapl(target_ts->tv_nsec); | |
2588 | unlock_user_struct(target_ts, target_addr, 0); | |
2589 | } | |
2590 | ||
992f48a0 | 2591 | static inline void host_to_target_timespec(abi_ulong target_addr, |
53a5960a PB |
2592 | struct timespec *host_ts) |
2593 | { | |
2594 | struct target_timespec *target_ts; | |
2595 | ||
2596 | lock_user_struct(target_ts, target_addr, 0); | |
2597 | target_ts->tv_sec = tswapl(host_ts->tv_sec); | |
2598 | target_ts->tv_nsec = tswapl(host_ts->tv_nsec); | |
2599 | unlock_user_struct(target_ts, target_addr, 1); | |
2600 | } | |
2601 | ||
0da46a6e TS |
2602 | /* do_syscall() should always have a single exit point at the end so |
2603 | that actions, such as logging of syscall results, can be performed. | |
2604 | All errnos that do_syscall() returns must be -TARGET_<errcode>. */ | |
992f48a0 BS |
2605 | abi_long do_syscall(void *cpu_env, int num, abi_long arg1, |
2606 | abi_long arg2, abi_long arg3, abi_long arg4, | |
2607 | abi_long arg5, abi_long arg6) | |
31e31b8a | 2608 | { |
992f48a0 | 2609 | abi_long ret; |
31e31b8a | 2610 | struct stat st; |
56c8f68f | 2611 | struct statfs stfs; |
53a5960a | 2612 | void *p; |
3b46e624 | 2613 | |
72f03900 | 2614 | #ifdef DEBUG |
c573ff67 | 2615 | gemu_log("syscall %d", num); |
72f03900 | 2616 | #endif |
b92c47c1 TS |
2617 | if(do_strace) |
2618 | print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); | |
2619 | ||
31e31b8a FB |
2620 | switch(num) { |
2621 | case TARGET_NR_exit: | |
7d13299d FB |
2622 | #ifdef HAVE_GPROF |
2623 | _mcleanup(); | |
2624 | #endif | |
e9009676 | 2625 | gdb_exit(cpu_env, arg1); |
1b6b029e | 2626 | /* XXX: should free thread stack and CPU env */ |
31e31b8a FB |
2627 | _exit(arg1); |
2628 | ret = 0; /* avoid warning */ | |
2629 | break; | |
2630 | case TARGET_NR_read: | |
53a5960a PB |
2631 | page_unprotect_range(arg2, arg3); |
2632 | p = lock_user(arg2, arg3, 0); | |
2633 | ret = get_errno(read(arg1, p, arg3)); | |
2634 | unlock_user(p, arg2, ret); | |
31e31b8a FB |
2635 | break; |
2636 | case TARGET_NR_write: | |
53a5960a PB |
2637 | p = lock_user(arg2, arg3, 1); |
2638 | ret = get_errno(write(arg1, p, arg3)); | |
2639 | unlock_user(p, arg2, 0); | |
31e31b8a FB |
2640 | break; |
2641 | case TARGET_NR_open: | |
53a5960a PB |
2642 | p = lock_user_string(arg1); |
2643 | ret = get_errno(open(path(p), | |
ffa65c3b FB |
2644 | target_to_host_bitmask(arg2, fcntl_flags_tbl), |
2645 | arg3)); | |
53a5960a | 2646 | unlock_user(p, arg1, 0); |
31e31b8a | 2647 | break; |
82424832 TS |
2648 | #if defined(TARGET_NR_openat) && defined(__NR_openat) |
2649 | case TARGET_NR_openat: | |
2650 | if (!arg2) { | |
0da46a6e | 2651 | ret = -TARGET_EFAULT; |
82424832 TS |
2652 | goto fail; |
2653 | } | |
2654 | p = lock_user_string(arg2); | |
2655 | if (!access_ok(VERIFY_READ, p, 1)) | |
0da46a6e TS |
2656 | /* Don't "goto fail" so that cleanup can happen. */ |
2657 | ret = -TARGET_EFAULT; | |
82424832 TS |
2658 | else |
2659 | ret = get_errno(sys_openat(arg1, | |
2660 | path(p), | |
2661 | target_to_host_bitmask(arg3, fcntl_flags_tbl), | |
2662 | arg4)); | |
2663 | if (p) | |
2664 | unlock_user(p, arg2, 0); | |
2665 | break; | |
2666 | #endif | |
31e31b8a FB |
2667 | case TARGET_NR_close: |
2668 | ret = get_errno(close(arg1)); | |
2669 | break; | |
2670 | case TARGET_NR_brk: | |
53a5960a | 2671 | ret = do_brk(arg1); |
31e31b8a FB |
2672 | break; |
2673 | case TARGET_NR_fork: | |
1b6b029e | 2674 | ret = get_errno(do_fork(cpu_env, SIGCHLD, 0)); |
31e31b8a | 2675 | break; |
e5febef5 | 2676 | #ifdef TARGET_NR_waitpid |
31e31b8a FB |
2677 | case TARGET_NR_waitpid: |
2678 | { | |
53a5960a PB |
2679 | int status; |
2680 | ret = get_errno(waitpid(arg1, &status, arg3)); | |
2681 | if (!is_error(ret) && arg2) | |
2682 | tput32(arg2, status); | |
31e31b8a FB |
2683 | } |
2684 | break; | |
e5febef5 | 2685 | #endif |
7a3148a9 | 2686 | #ifdef TARGET_NR_creat /* not on alpha */ |
31e31b8a | 2687 | case TARGET_NR_creat: |
53a5960a PB |
2688 | p = lock_user_string(arg1); |
2689 | ret = get_errno(creat(p, arg2)); | |
2690 | unlock_user(p, arg1, 0); | |
31e31b8a | 2691 | break; |
7a3148a9 | 2692 | #endif |
31e31b8a | 2693 | case TARGET_NR_link: |
53a5960a PB |
2694 | { |
2695 | void * p2; | |
2696 | p = lock_user_string(arg1); | |
2697 | p2 = lock_user_string(arg2); | |
2698 | ret = get_errno(link(p, p2)); | |
2699 | unlock_user(p2, arg2, 0); | |
2700 | unlock_user(p, arg1, 0); | |
2701 | } | |
31e31b8a | 2702 | break; |
64f0ce4c TS |
2703 | #if defined(TARGET_NR_linkat) && defined(__NR_linkat) |
2704 | case TARGET_NR_linkat: | |
2705 | if (!arg2 || !arg4) { | |
0da46a6e | 2706 | ret = -TARGET_EFAULT; |
64f0ce4c | 2707 | goto fail; |
0da46a6e | 2708 | } |
64f0ce4c TS |
2709 | { |
2710 | void * p2 = NULL; | |
2711 | p = lock_user_string(arg2); | |
2712 | p2 = lock_user_string(arg4); | |
2713 | if (!access_ok(VERIFY_READ, p, 1) | |
2714 | || !access_ok(VERIFY_READ, p2, 1)) | |
0da46a6e TS |
2715 | /* Don't "goto fail" so that cleanup can happen. */ |
2716 | ret = -TARGET_EFAULT; | |
64f0ce4c TS |
2717 | else |
2718 | ret = get_errno(sys_linkat(arg1, p, arg3, p2, arg5)); | |
2719 | if (p2) | |
2720 | unlock_user(p, arg2, 0); | |
2721 | if (p) | |
2722 | unlock_user(p2, arg4, 0); | |
2723 | } | |
2724 | break; | |
2725 | #endif | |
31e31b8a | 2726 | case TARGET_NR_unlink: |
53a5960a PB |
2727 | p = lock_user_string(arg1); |
2728 | ret = get_errno(unlink(p)); | |
2729 | unlock_user(p, arg1, 0); | |
31e31b8a | 2730 | break; |
8170f56b TS |
2731 | #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat) |
2732 | case TARGET_NR_unlinkat: | |
2733 | if (!arg2) { | |
0da46a6e | 2734 | ret = -TARGET_EFAULT; |
8170f56b TS |
2735 | goto fail; |
2736 | } | |
2737 | p = lock_user_string(arg2); | |
2738 | if (!access_ok(VERIFY_READ, p, 1)) | |
0da46a6e TS |
2739 | /* Don't "goto fail" so that cleanup can happen. */ |
2740 | ret = -TARGET_EFAULT; | |
8170f56b TS |
2741 | else |
2742 | ret = get_errno(sys_unlinkat(arg1, p, arg3)); | |
2743 | if (p) | |
2744 | unlock_user(p, arg2, 0); | |
2745 | break; | |
2746 | #endif | |
31e31b8a | 2747 | case TARGET_NR_execve: |
7854b056 FB |
2748 | { |
2749 | char **argp, **envp; | |
f7341ff4 | 2750 | int argc, envc; |
992f48a0 BS |
2751 | abi_ulong gp; |
2752 | abi_ulong guest_argp; | |
2753 | abi_ulong guest_envp; | |
2754 | abi_ulong addr; | |
7854b056 FB |
2755 | char **q; |
2756 | ||
f7341ff4 | 2757 | argc = 0; |
53a5960a PB |
2758 | guest_argp = arg2; |
2759 | for (gp = guest_argp; tgetl(gp); gp++) | |
7854b056 | 2760 | argc++; |
f7341ff4 | 2761 | envc = 0; |
53a5960a PB |
2762 | guest_envp = arg3; |
2763 | for (gp = guest_envp; tgetl(gp); gp++) | |
7854b056 FB |
2764 | envc++; |
2765 | ||
f7341ff4 FB |
2766 | argp = alloca((argc + 1) * sizeof(void *)); |
2767 | envp = alloca((envc + 1) * sizeof(void *)); | |
7854b056 | 2768 | |
53a5960a | 2769 | for (gp = guest_argp, q = argp; ; |
992f48a0 | 2770 | gp += sizeof(abi_ulong), q++) { |
53a5960a PB |
2771 | addr = tgetl(gp); |
2772 | if (!addr) | |
2773 | break; | |
2774 | *q = lock_user_string(addr); | |
2775 | } | |
f7341ff4 FB |
2776 | *q = NULL; |
2777 | ||
53a5960a | 2778 | for (gp = guest_envp, q = envp; ; |
992f48a0 | 2779 | gp += sizeof(abi_ulong), q++) { |
53a5960a PB |
2780 | addr = tgetl(gp); |
2781 | if (!addr) | |
2782 | break; | |
2783 | *q = lock_user_string(addr); | |
2784 | } | |
f7341ff4 | 2785 | *q = NULL; |
7854b056 | 2786 | |
53a5960a PB |
2787 | p = lock_user_string(arg1); |
2788 | ret = get_errno(execve(p, argp, envp)); | |
2789 | unlock_user(p, arg1, 0); | |
2790 | ||
2791 | for (gp = guest_argp, q = argp; *q; | |
992f48a0 | 2792 | gp += sizeof(abi_ulong), q++) { |
53a5960a PB |
2793 | addr = tgetl(gp); |
2794 | unlock_user(*q, addr, 0); | |
2795 | } | |
2796 | for (gp = guest_envp, q = envp; *q; | |
992f48a0 | 2797 | gp += sizeof(abi_ulong), q++) { |
53a5960a PB |
2798 | addr = tgetl(gp); |
2799 | unlock_user(*q, addr, 0); | |
2800 | } | |
7854b056 | 2801 | } |
31e31b8a FB |
2802 | break; |
2803 | case TARGET_NR_chdir: | |
53a5960a PB |
2804 | p = lock_user_string(arg1); |
2805 | ret = get_errno(chdir(p)); | |
2806 | unlock_user(p, arg1, 0); | |
31e31b8a | 2807 | break; |
a315a145 | 2808 | #ifdef TARGET_NR_time |
31e31b8a FB |
2809 | case TARGET_NR_time: |
2810 | { | |
53a5960a PB |
2811 | time_t host_time; |
2812 | ret = get_errno(time(&host_time)); | |
2813 | if (!is_error(ret) && arg1) | |
2814 | tputl(arg1, host_time); | |
31e31b8a FB |
2815 | } |
2816 | break; | |
a315a145 | 2817 | #endif |
31e31b8a | 2818 | case TARGET_NR_mknod: |
53a5960a PB |
2819 | p = lock_user_string(arg1); |
2820 | ret = get_errno(mknod(p, arg2, arg3)); | |
2821 | unlock_user(p, arg1, 0); | |
31e31b8a | 2822 | break; |
75ac37a0 TS |
2823 | #if defined(TARGET_NR_mknodat) && defined(__NR_mknodat) |
2824 | case TARGET_NR_mknodat: | |
2825 | if (!arg2) { | |
0da46a6e | 2826 | ret = -TARGET_EFAULT; |
75ac37a0 TS |
2827 | goto fail; |
2828 | } | |
2829 | p = lock_user_string(arg2); | |
2830 | if (!access_ok(VERIFY_READ, p, 1)) | |
0da46a6e TS |
2831 | /* Don't "goto fail" so that cleanup can happen. */ |
2832 | ret = -TARGET_EFAULT; | |
75ac37a0 TS |
2833 | else |
2834 | ret = get_errno(sys_mknodat(arg1, p, arg3, arg4)); | |
2835 | if (p) | |
2836 | unlock_user(p, arg2, 0); | |
2837 | break; | |
2838 | #endif | |
31e31b8a | 2839 | case TARGET_NR_chmod: |
53a5960a PB |
2840 | p = lock_user_string(arg1); |
2841 | ret = get_errno(chmod(p, arg2)); | |
2842 | unlock_user(p, arg1, 0); | |
31e31b8a | 2843 | break; |
ebc05488 | 2844 | #ifdef TARGET_NR_break |
31e31b8a FB |
2845 | case TARGET_NR_break: |
2846 | goto unimplemented; | |
ebc05488 FB |
2847 | #endif |
2848 | #ifdef TARGET_NR_oldstat | |
31e31b8a FB |
2849 | case TARGET_NR_oldstat: |
2850 | goto unimplemented; | |
ebc05488 | 2851 | #endif |
31e31b8a FB |
2852 | case TARGET_NR_lseek: |
2853 | ret = get_errno(lseek(arg1, arg2, arg3)); | |
2854 | break; | |
7a3148a9 JM |
2855 | #ifdef TARGET_NR_getxpid |
2856 | case TARGET_NR_getxpid: | |
2857 | #else | |
31e31b8a | 2858 | case TARGET_NR_getpid: |
7a3148a9 | 2859 | #endif |
31e31b8a FB |
2860 | ret = get_errno(getpid()); |
2861 | break; | |
2862 | case TARGET_NR_mount: | |
80265918 TS |
2863 | { |
2864 | /* need to look at the data field */ | |
2865 | void *p2, *p3; | |
2866 | p = lock_user_string(arg1); | |
2867 | p2 = lock_user_string(arg2); | |
2868 | p3 = lock_user_string(arg3); | |
2869 | ret = get_errno(mount(p, p2, p3, (unsigned long)arg4, (const void *)arg5)); | |
2870 | unlock_user(p, arg1, 0); | |
2871 | unlock_user(p2, arg2, 0); | |
2872 | unlock_user(p3, arg3, 0); | |
2873 | break; | |
2874 | } | |
e5febef5 | 2875 | #ifdef TARGET_NR_umount |
31e31b8a | 2876 | case TARGET_NR_umount: |
53a5960a PB |
2877 | p = lock_user_string(arg1); |
2878 | ret = get_errno(umount(p)); | |
2879 | unlock_user(p, arg1, 0); | |
31e31b8a | 2880 | break; |
e5febef5 | 2881 | #endif |
7a3148a9 | 2882 | #ifdef TARGET_NR_stime /* not on alpha */ |
31e31b8a FB |
2883 | case TARGET_NR_stime: |
2884 | { | |
53a5960a PB |
2885 | time_t host_time; |
2886 | host_time = tgetl(arg1); | |
2887 | ret = get_errno(stime(&host_time)); | |
31e31b8a FB |
2888 | } |
2889 | break; | |
7a3148a9 | 2890 | #endif |
31e31b8a FB |
2891 | case TARGET_NR_ptrace: |
2892 | goto unimplemented; | |
7a3148a9 | 2893 | #ifdef TARGET_NR_alarm /* not on alpha */ |
31e31b8a FB |
2894 | case TARGET_NR_alarm: |
2895 | ret = alarm(arg1); | |
2896 | break; | |
7a3148a9 | 2897 | #endif |
ebc05488 | 2898 | #ifdef TARGET_NR_oldfstat |
31e31b8a FB |
2899 | case TARGET_NR_oldfstat: |
2900 | goto unimplemented; | |
ebc05488 | 2901 | #endif |
7a3148a9 | 2902 | #ifdef TARGET_NR_pause /* not on alpha */ |
31e31b8a FB |
2903 | case TARGET_NR_pause: |
2904 | ret = get_errno(pause()); | |
2905 | break; | |
7a3148a9 | 2906 | #endif |
e5febef5 | 2907 | #ifdef TARGET_NR_utime |
31e31b8a | 2908 | case TARGET_NR_utime: |
ebc05488 | 2909 | { |
53a5960a PB |
2910 | struct utimbuf tbuf, *host_tbuf; |
2911 | struct target_utimbuf *target_tbuf; | |
2912 | if (arg2) { | |
2913 | lock_user_struct(target_tbuf, arg2, 1); | |
2914 | tbuf.actime = tswapl(target_tbuf->actime); | |
2915 | tbuf.modtime = tswapl(target_tbuf->modtime); | |
2916 | unlock_user_struct(target_tbuf, arg2, 0); | |
2917 | host_tbuf = &tbuf; | |
f72e8ff4 | 2918 | } else { |
53a5960a | 2919 | host_tbuf = NULL; |
f72e8ff4 | 2920 | } |
53a5960a PB |
2921 | p = lock_user_string(arg1); |
2922 | ret = get_errno(utime(p, host_tbuf)); | |
2923 | unlock_user(p, arg1, 0); | |
ebc05488 FB |
2924 | } |
2925 | break; | |
e5febef5 | 2926 | #endif |
978a66ff FB |
2927 | case TARGET_NR_utimes: |
2928 | { | |
978a66ff | 2929 | struct timeval *tvp, tv[2]; |
53a5960a PB |
2930 | if (arg2) { |
2931 | target_to_host_timeval(&tv[0], arg2); | |
2932 | target_to_host_timeval(&tv[1], | |
2933 | arg2 + sizeof (struct target_timeval)); | |
978a66ff FB |
2934 | tvp = tv; |
2935 | } else { | |
2936 | tvp = NULL; | |
2937 | } | |
53a5960a PB |
2938 | p = lock_user_string(arg1); |
2939 | ret = get_errno(utimes(p, tvp)); | |
2940 | unlock_user(p, arg1, 0); | |
978a66ff FB |
2941 | } |
2942 | break; | |
ebc05488 | 2943 | #ifdef TARGET_NR_stty |
31e31b8a FB |
2944 | case TARGET_NR_stty: |
2945 | goto unimplemented; | |
ebc05488 FB |
2946 | #endif |
2947 | #ifdef TARGET_NR_gtty | |
31e31b8a FB |
2948 | case TARGET_NR_gtty: |
2949 | goto unimplemented; | |
ebc05488 | 2950 | #endif |
31e31b8a | 2951 | case TARGET_NR_access: |
53a5960a PB |
2952 | p = lock_user_string(arg1); |
2953 | ret = get_errno(access(p, arg2)); | |
2954 | unlock_user(p, arg1, 0); | |
31e31b8a | 2955 | break; |
92a34c10 TS |
2956 | #if defined(TARGET_NR_faccessat) && defined(__NR_faccessat) |
2957 | case TARGET_NR_faccessat: | |
2958 | if (!arg2) { | |
0da46a6e | 2959 | ret = -TARGET_EFAULT; |
92a34c10 TS |
2960 | goto fail; |
2961 | } | |
2962 | p = lock_user_string(arg2); | |
2963 | if (!access_ok(VERIFY_READ, p, 1)) | |
0da46a6e TS |
2964 | /* Don't "goto fail" so that cleanup can happen. */ |
2965 | ret = -TARGET_EFAULT; | |
92a34c10 TS |
2966 | else |
2967 | ret = get_errno(sys_faccessat(arg1, p, arg3, arg4)); | |
2968 | if (p) | |
2969 | unlock_user(p, arg2, 0); | |
2970 | break; | |
2971 | #endif | |
7a3148a9 | 2972 | #ifdef TARGET_NR_nice /* not on alpha */ |
31e31b8a FB |
2973 | case TARGET_NR_nice: |
2974 | ret = get_errno(nice(arg1)); | |
2975 | break; | |
7a3148a9 | 2976 | #endif |
ebc05488 | 2977 | #ifdef TARGET_NR_ftime |
31e31b8a FB |
2978 | case TARGET_NR_ftime: |
2979 | goto unimplemented; | |
ebc05488 | 2980 | #endif |
31e31b8a | 2981 | case TARGET_NR_sync: |
04369ff2 FB |
2982 | sync(); |
2983 | ret = 0; | |
31e31b8a FB |
2984 | break; |
2985 | case TARGET_NR_kill: | |
2986 | ret = get_errno(kill(arg1, arg2)); | |
2987 | break; | |
2988 | case TARGET_NR_rename: | |
53a5960a PB |
2989 | { |
2990 | void *p2; | |
2991 | p = lock_user_string(arg1); | |
2992 | p2 = lock_user_string(arg2); | |
2993 | ret = get_errno(rename(p, p2)); | |
2994 | unlock_user(p2, arg2, 0); | |
2995 | unlock_user(p, arg1, 0); | |
2996 | } | |
31e31b8a | 2997 | break; |
722183f6 TS |
2998 | #if defined(TARGET_NR_renameat) && defined(__NR_renameat) |
2999 | case TARGET_NR_renameat: | |
3000 | if (!arg2 || !arg4) { | |
0da46a6e TS |
3001 | ret = -TARGET_EFAULT; |
3002 | goto fail; | |
722183f6 TS |
3003 | } |
3004 | { | |
3005 | void *p2 = NULL; | |
3006 | p = lock_user_string(arg2); | |
3007 | p2 = lock_user_string(arg4); | |
3008 | if (!access_ok(VERIFY_READ, p, 1) | |
3009 | || !access_ok(VERIFY_READ, p2, 1)) | |
0da46a6e TS |
3010 | /* Don't "goto fail" so that cleanup can happen. */ |
3011 | ret = -TARGET_EFAULT; | |
722183f6 TS |
3012 | else |
3013 | ret = get_errno(sys_renameat(arg1, p, arg3, p2)); | |
3014 | if (p2) | |
3015 | unlock_user(p2, arg4, 0); | |
3016 | if (p) | |
3017 | unlock_user(p, arg2, 0); | |
3018 | } | |
3019 | break; | |
3020 | #endif | |
31e31b8a | 3021 | case TARGET_NR_mkdir: |
53a5960a PB |
3022 | p = lock_user_string(arg1); |
3023 | ret = get_errno(mkdir(p, arg2)); | |
3024 | unlock_user(p, arg1, 0); | |
31e31b8a | 3025 | break; |
4472ad0d TS |
3026 | #if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat) |
3027 | case TARGET_NR_mkdirat: | |
3028 | if (!arg2) { | |
0da46a6e | 3029 | ret = -TARGET_EFAULT; |
4472ad0d TS |
3030 | goto fail; |
3031 | } | |
3032 | p = lock_user_string(arg2); | |
3033 | if (!access_ok(VERIFY_READ, p, 1)) | |
0da46a6e TS |
3034 | /* Don't "goto fail" so that cleanup can happen. */ |
3035 | ret = -TARGET_EFAULT; | |
4472ad0d TS |
3036 | else |
3037 | ret = get_errno(sys_mkdirat(arg1, p, arg3)); | |
3038 | if (p) | |
3039 | unlock_user(p, arg2, 0); | |
3040 | break; | |
3041 | #endif | |
31e31b8a | 3042 | case TARGET_NR_rmdir: |
53a5960a PB |
3043 | p = lock_user_string(arg1); |
3044 | ret = get_errno(rmdir(p)); | |
3045 | unlock_user(p, arg1, 0); | |
31e31b8a FB |
3046 | break; |
3047 | case TARGET_NR_dup: | |
3048 | ret = get_errno(dup(arg1)); | |
3049 | break; | |
3050 | case TARGET_NR_pipe: | |
3051 | { | |
53a5960a PB |
3052 | int host_pipe[2]; |
3053 | ret = get_errno(pipe(host_pipe)); | |
31e31b8a | 3054 | if (!is_error(ret)) { |
c12ab05c | 3055 | #if defined(TARGET_MIPS) |
ead9360e TS |
3056 | CPUMIPSState *env = (CPUMIPSState*)cpu_env; |
3057 | env->gpr[3][env->current_tc] = host_pipe[1]; | |
c12ab05c TS |
3058 | ret = host_pipe[0]; |
3059 | #else | |
53a5960a PB |
3060 | tput32(arg1, host_pipe[0]); |
3061 | tput32(arg1 + 4, host_pipe[1]); | |
c12ab05c | 3062 | #endif |
31e31b8a FB |
3063 | } |
3064 | } | |
3065 | break; | |
3066 | case TARGET_NR_times: | |
32f36bce | 3067 | { |
53a5960a | 3068 | struct target_tms *tmsp; |
32f36bce FB |
3069 | struct tms tms; |
3070 | ret = get_errno(times(&tms)); | |
53a5960a PB |
3071 | if (arg1) { |
3072 | tmsp = lock_user(arg1, sizeof(struct target_tms), 0); | |
c596ed17 FB |
3073 | tmsp->tms_utime = tswapl(host_to_target_clock_t(tms.tms_utime)); |
3074 | tmsp->tms_stime = tswapl(host_to_target_clock_t(tms.tms_stime)); | |
3075 | tmsp->tms_cutime = tswapl(host_to_target_clock_t(tms.tms_cutime)); | |
3076 | tmsp->tms_cstime = tswapl(host_to_target_clock_t(tms.tms_cstime)); | |
32f36bce | 3077 | } |
c596ed17 FB |
3078 | if (!is_error(ret)) |
3079 | ret = host_to_target_clock_t(ret); | |
32f36bce FB |
3080 | } |
3081 | break; | |
ebc05488 | 3082 | #ifdef TARGET_NR_prof |
31e31b8a FB |
3083 | case TARGET_NR_prof: |
3084 | goto unimplemented; | |
ebc05488 | 3085 | #endif |
e5febef5 | 3086 | #ifdef TARGET_NR_signal |
31e31b8a FB |
3087 | case TARGET_NR_signal: |
3088 | goto unimplemented; | |
e5febef5 | 3089 | #endif |
31e31b8a | 3090 | case TARGET_NR_acct: |
24836689 PB |
3091 | p = lock_user_string(arg1); |
3092 | ret = get_errno(acct(path(p))); | |
3093 | unlock_user(p, arg1, 0); | |
3094 | break; | |
7a3148a9 | 3095 | #ifdef TARGET_NR_umount2 /* not on alpha */ |
31e31b8a | 3096 | case TARGET_NR_umount2: |
53a5960a PB |
3097 | p = lock_user_string(arg1); |
3098 | ret = get_errno(umount2(p, arg2)); | |
3099 | unlock_user(p, arg1, 0); | |
31e31b8a | 3100 | break; |
7a3148a9 | 3101 | #endif |
ebc05488 | 3102 | #ifdef TARGET_NR_lock |
31e31b8a FB |
3103 | case TARGET_NR_lock: |
3104 | goto unimplemented; | |
ebc05488 | 3105 | #endif |
31e31b8a FB |
3106 | case TARGET_NR_ioctl: |
3107 | ret = do_ioctl(arg1, arg2, arg3); | |
3108 | break; | |
3109 | case TARGET_NR_fcntl: | |
7775e9ec | 3110 | ret = get_errno(do_fcntl(arg1, arg2, arg3)); |
31e31b8a | 3111 | break; |
ebc05488 | 3112 | #ifdef TARGET_NR_mpx |
31e31b8a FB |
3113 | case TARGET_NR_mpx: |
3114 | goto unimplemented; | |
ebc05488 | 3115 | #endif |
31e31b8a FB |
3116 | case TARGET_NR_setpgid: |
3117 | ret = get_errno(setpgid(arg1, arg2)); | |
3118 | break; | |
ebc05488 | 3119 | #ifdef TARGET_NR_ulimit |
31e31b8a FB |
3120 | case TARGET_NR_ulimit: |
3121 | goto unimplemented; | |
ebc05488 FB |
3122 | #endif |
3123 | #ifdef TARGET_NR_oldolduname | |
31e31b8a FB |
3124 | case TARGET_NR_oldolduname: |
3125 | goto unimplemented; | |
ebc05488 | 3126 | #endif |
31e31b8a FB |
3127 | case TARGET_NR_umask: |
3128 | ret = get_errno(umask(arg1)); | |
3129 | break; | |
3130 | case TARGET_NR_chroot: | |
53a5960a PB |
3131 | p = lock_user_string(arg1); |
3132 | ret = get_errno(chroot(p)); | |
3133 | unlock_user(p, arg1, 0); | |
31e31b8a FB |
3134 | break; |
3135 | case TARGET_NR_ustat: | |
3136 | goto unimplemented; | |
3137 | case TARGET_NR_dup2: | |
3138 | ret = get_errno(dup2(arg1, arg2)); | |
3139 | break; | |
7a3148a9 | 3140 | #ifdef TARGET_NR_getppid /* not on alpha */ |
31e31b8a FB |
3141 | case TARGET_NR_getppid: |
3142 | ret = get_errno(getppid()); | |
3143 | break; | |
7a3148a9 | 3144 | #endif |
31e31b8a FB |
3145 | case TARGET_NR_getpgrp: |
3146 | ret = get_errno(getpgrp()); | |
3147 | break; | |
3148 | case TARGET_NR_setsid: | |
3149 | ret = get_errno(setsid()); | |
3150 | break; | |
e5febef5 | 3151 | #ifdef TARGET_NR_sigaction |
31e31b8a | 3152 | case TARGET_NR_sigaction: |
31e31b8a | 3153 | { |
388bb21a | 3154 | #if !defined(TARGET_MIPS) |
53a5960a | 3155 | struct target_old_sigaction *old_act; |
66fb9763 | 3156 | struct target_sigaction act, oact, *pact; |
53a5960a PB |
3157 | if (arg2) { |
3158 | lock_user_struct(old_act, arg2, 1); | |
66fb9763 FB |
3159 | act._sa_handler = old_act->_sa_handler; |
3160 | target_siginitset(&act.sa_mask, old_act->sa_mask); | |
3161 | act.sa_flags = old_act->sa_flags; | |
3162 | act.sa_restorer = old_act->sa_restorer; | |
53a5960a | 3163 | unlock_user_struct(old_act, arg2, 0); |
66fb9763 FB |
3164 | pact = &act; |
3165 | } else { | |
3166 | pact = NULL; | |
3167 | } | |
3168 | ret = get_errno(do_sigaction(arg1, pact, &oact)); | |
53a5960a PB |
3169 | if (!is_error(ret) && arg3) { |
3170 | lock_user_struct(old_act, arg3, 0); | |
3171 | old_act->_sa_handler = oact._sa_handler; | |
3172 | old_act->sa_mask = oact.sa_mask.sig[0]; | |
3173 | old_act->sa_flags = oact.sa_flags; | |
3174 | old_act->sa_restorer = oact.sa_restorer; | |
3175 | unlock_user_struct(old_act, arg3, 1); | |
66fb9763 | 3176 | } |
388bb21a | 3177 | #else |
106ec879 FB |
3178 | struct target_sigaction act, oact, *pact, *old_act; |
3179 | ||
3180 | if (arg2) { | |
3181 | lock_user_struct(old_act, arg2, 1); | |
3182 | act._sa_handler = old_act->_sa_handler; | |
3183 | target_siginitset(&act.sa_mask, old_act->sa_mask.sig[0]); | |
3184 | act.sa_flags = old_act->sa_flags; | |
3185 | unlock_user_struct(old_act, arg2, 0); | |
3186 | pact = &act; | |
3187 | } else { | |
3188 | pact = NULL; | |
3189 | } | |
3190 | ||
3191 | ret = get_errno(do_sigaction(arg1, pact, &oact)); | |
3192 | ||
3193 | if (!is_error(ret) && arg3) { | |
3194 | lock_user_struct(old_act, arg3, 0); | |
3195 | old_act->_sa_handler = oact._sa_handler; | |
3196 | old_act->sa_flags = oact.sa_flags; | |
3197 | old_act->sa_mask.sig[0] = oact.sa_mask.sig[0]; | |
3198 | old_act->sa_mask.sig[1] = 0; | |
3199 | old_act->sa_mask.sig[2] = 0; | |
3200 | old_act->sa_mask.sig[3] = 0; | |
3201 | unlock_user_struct(old_act, arg3, 1); | |
3202 | } | |
388bb21a | 3203 | #endif |
31e31b8a FB |
3204 | } |
3205 | break; | |
e5febef5 | 3206 | #endif |
66fb9763 | 3207 | case TARGET_NR_rt_sigaction: |
53a5960a PB |
3208 | { |
3209 | struct target_sigaction *act; | |
3210 | struct target_sigaction *oact; | |
3211 | ||
3212 | if (arg2) | |
3213 | lock_user_struct(act, arg2, 1); | |
3214 | else | |
3215 | act = NULL; | |
3216 | if (arg3) | |
3217 | lock_user_struct(oact, arg3, 0); | |
3218 | else | |
3219 | oact = NULL; | |
3220 | ret = get_errno(do_sigaction(arg1, act, oact)); | |
3221 | if (arg2) | |
3222 | unlock_user_struct(act, arg2, 0); | |
3223 | if (arg3) | |
3224 | unlock_user_struct(oact, arg3, 1); | |
3225 | } | |
66fb9763 | 3226 | break; |
7a3148a9 | 3227 | #ifdef TARGET_NR_sgetmask /* not on alpha */ |
31e31b8a | 3228 | case TARGET_NR_sgetmask: |
66fb9763 FB |
3229 | { |
3230 | sigset_t cur_set; | |
992f48a0 | 3231 | abi_ulong target_set; |
66fb9763 FB |
3232 | sigprocmask(0, NULL, &cur_set); |
3233 | host_to_target_old_sigset(&target_set, &cur_set); | |
3234 | ret = target_set; | |
3235 | } | |
3236 | break; | |
7a3148a9 JM |
3237 | #endif |
3238 | #ifdef TARGET_NR_ssetmask /* not on alpha */ | |
31e31b8a | 3239 | case TARGET_NR_ssetmask: |
66fb9763 FB |
3240 | { |
3241 | sigset_t set, oset, cur_set; | |
992f48a0 | 3242 | abi_ulong target_set = arg1; |
66fb9763 FB |
3243 | sigprocmask(0, NULL, &cur_set); |
3244 | target_to_host_old_sigset(&set, &target_set); | |
3245 | sigorset(&set, &set, &cur_set); | |
3246 | sigprocmask(SIG_SETMASK, &set, &oset); | |
3247 | host_to_target_old_sigset(&target_set, &oset); | |
3248 | ret = target_set; | |
3249 | } | |
3250 | break; | |
7a3148a9 | 3251 | #endif |
e5febef5 | 3252 | #ifdef TARGET_NR_sigprocmask |
66fb9763 FB |
3253 | case TARGET_NR_sigprocmask: |
3254 | { | |
3255 | int how = arg1; | |
3256 | sigset_t set, oldset, *set_ptr; | |
3b46e624 | 3257 | |
53a5960a | 3258 | if (arg2) { |
66fb9763 FB |
3259 | switch(how) { |
3260 | case TARGET_SIG_BLOCK: | |
3261 | how = SIG_BLOCK; | |
3262 | break; | |
3263 | case TARGET_SIG_UNBLOCK: | |
3264 | how = SIG_UNBLOCK; | |
3265 | break; | |
3266 | case TARGET_SIG_SETMASK: | |
3267 | how = SIG_SETMASK; | |
3268 | break; | |
3269 | default: | |
0da46a6e | 3270 | ret = -TARGET_EINVAL; |
66fb9763 FB |
3271 | goto fail; |
3272 | } | |
53a5960a PB |
3273 | p = lock_user(arg2, sizeof(target_sigset_t), 1); |
3274 | target_to_host_old_sigset(&set, p); | |
3275 | unlock_user(p, arg2, 0); | |
66fb9763 FB |
3276 | set_ptr = &set; |
3277 | } else { | |
3278 | how = 0; | |
3279 | set_ptr = NULL; | |
3280 | } | |
3281 | ret = get_errno(sigprocmask(arg1, set_ptr, &oldset)); | |
53a5960a PB |
3282 | if (!is_error(ret) && arg3) { |
3283 | p = lock_user(arg3, sizeof(target_sigset_t), 0); | |
3284 | host_to_target_old_sigset(p, &oldset); | |
3285 | unlock_user(p, arg3, sizeof(target_sigset_t)); | |
66fb9763 FB |
3286 | } |
3287 | } | |
3288 | break; | |
e5febef5 | 3289 | #endif |
66fb9763 FB |
3290 | case TARGET_NR_rt_sigprocmask: |
3291 | { | |
3292 | int how = arg1; | |
3293 | sigset_t set, oldset, *set_ptr; | |
3b46e624 | 3294 | |
53a5960a | 3295 | if (arg2) { |
66fb9763 FB |
3296 | switch(how) { |
3297 | case TARGET_SIG_BLOCK: | |
3298 | how = SIG_BLOCK; | |
3299 | break; | |
3300 | case TARGET_SIG_UNBLOCK: | |
3301 | how = SIG_UNBLOCK; | |
3302 | break; | |
3303 | case TARGET_SIG_SETMASK: | |
3304 | how = SIG_SETMASK; | |
3305 | break; | |
3306 | default: | |
0da46a6e | 3307 | ret = -TARGET_EINVAL; |
66fb9763 FB |
3308 | goto fail; |
3309 | } | |
53a5960a PB |
3310 | p = lock_user(arg2, sizeof(target_sigset_t), 1); |
3311 | target_to_host_sigset(&set, p); | |
3312 | unlock_user(p, arg2, 0); | |
66fb9763 FB |
3313 | set_ptr = &set; |
3314 | } else { | |
3315 | how = 0; | |
3316 | set_ptr = NULL; | |
3317 | } | |
3318 | ret = get_errno(sigprocmask(how, set_ptr, &oldset)); | |
53a5960a PB |
3319 | if (!is_error(ret) && arg3) { |
3320 | p = lock_user(arg3, sizeof(target_sigset_t), 0); | |
3321 | host_to_target_sigset(p, &oldset); | |
3322 | unlock_user(p, arg3, sizeof(target_sigset_t)); | |
66fb9763 FB |
3323 | } |
3324 | } | |
3325 | break; | |
e5febef5 | 3326 | #ifdef TARGET_NR_sigpending |
66fb9763 FB |
3327 | case TARGET_NR_sigpending: |
3328 | { | |
3329 | sigset_t set; | |
3330 | ret = get_errno(sigpending(&set)); | |
3331 | if (!is_error(ret)) { | |
53a5960a PB |
3332 | p = lock_user(arg1, sizeof(target_sigset_t), 0); |
3333 | host_to_target_old_sigset(p, &set); | |
3334 | unlock_user(p, arg1, sizeof(target_sigset_t)); | |
66fb9763 FB |
3335 | } |
3336 | } | |
3337 | break; | |
e5febef5 | 3338 | #endif |
66fb9763 FB |
3339 | case TARGET_NR_rt_sigpending: |
3340 | { | |
3341 | sigset_t set; | |
3342 | ret = get_errno(sigpending(&set)); | |
3343 | if (!is_error(ret)) { | |
53a5960a PB |
3344 | p = lock_user(arg1, sizeof(target_sigset_t), 0); |
3345 | host_to_target_sigset(p, &set); | |
3346 | unlock_user(p, arg1, sizeof(target_sigset_t)); | |
66fb9763 FB |
3347 | } |
3348 | } | |
3349 | break; | |
e5febef5 | 3350 | #ifdef TARGET_NR_sigsuspend |
66fb9763 FB |
3351 | case TARGET_NR_sigsuspend: |
3352 | { | |
3353 | sigset_t set; | |
53a5960a PB |
3354 | p = lock_user(arg1, sizeof(target_sigset_t), 1); |
3355 | target_to_host_old_sigset(&set, p); | |
3356 | unlock_user(p, arg1, 0); | |
66fb9763 FB |
3357 | ret = get_errno(sigsuspend(&set)); |
3358 | } | |
3359 | break; | |
e5febef5 | 3360 | #endif |
66fb9763 FB |
3361 | case TARGET_NR_rt_sigsuspend: |
3362 | { | |
3363 | sigset_t set; | |
53a5960a PB |
3364 | p = lock_user(arg1, sizeof(target_sigset_t), 1); |
3365 | target_to_host_sigset(&set, p); | |
3366 | unlock_user(p, arg1, 0); | |
66fb9763 FB |
3367 | ret = get_errno(sigsuspend(&set)); |
3368 | } | |
3369 | break; | |
3370 | case TARGET_NR_rt_sigtimedwait: | |
3371 | { | |
66fb9763 FB |
3372 | sigset_t set; |
3373 | struct timespec uts, *puts; | |
3374 | siginfo_t uinfo; | |
3b46e624 | 3375 | |
53a5960a PB |
3376 | p = lock_user(arg1, sizeof(target_sigset_t), 1); |
3377 | target_to_host_sigset(&set, p); | |
3378 | unlock_user(p, arg1, 0); | |
3379 | if (arg3) { | |
66fb9763 | 3380 | puts = &uts; |
53a5960a | 3381 | target_to_host_timespec(puts, arg3); |
66fb9763 FB |
3382 | } else { |
3383 | puts = NULL; | |
3384 | } | |
3385 | ret = get_errno(sigtimedwait(&set, &uinfo, puts)); | |
53a5960a PB |
3386 | if (!is_error(ret) && arg2) { |
3387 | p = lock_user(arg2, sizeof(target_sigset_t), 0); | |
3388 | host_to_target_siginfo(p, &uinfo); | |
3389 | unlock_user(p, arg2, sizeof(target_sigset_t)); | |
66fb9763 FB |
3390 | } |
3391 | } | |
3392 | break; | |
3393 | case TARGET_NR_rt_sigqueueinfo: | |
3394 | { | |
3395 | siginfo_t uinfo; | |
53a5960a PB |
3396 | p = lock_user(arg3, sizeof(target_sigset_t), 1); |
3397 | target_to_host_siginfo(&uinfo, p); | |
3398 | unlock_user(p, arg1, 0); | |
66fb9763 FB |
3399 | ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, &uinfo)); |
3400 | } | |
3401 | break; | |
e5febef5 | 3402 | #ifdef TARGET_NR_sigreturn |
66fb9763 FB |
3403 | case TARGET_NR_sigreturn: |
3404 | /* NOTE: ret is eax, so not transcoding must be done */ | |
3405 | ret = do_sigreturn(cpu_env); | |
3406 | break; | |
e5febef5 | 3407 | #endif |
66fb9763 FB |
3408 | case TARGET_NR_rt_sigreturn: |
3409 | /* NOTE: ret is eax, so not transcoding must be done */ | |
3410 | ret = do_rt_sigreturn(cpu_env); | |
3411 | break; | |
31e31b8a | 3412 | case TARGET_NR_sethostname: |
53a5960a PB |
3413 | p = lock_user_string(arg1); |
3414 | ret = get_errno(sethostname(p, arg2)); | |
3415 | unlock_user(p, arg1, 0); | |
31e31b8a FB |
3416 | break; |
3417 | case TARGET_NR_setrlimit: | |
9de5e440 FB |
3418 | { |
3419 | /* XXX: convert resource ? */ | |
3420 | int resource = arg1; | |
53a5960a | 3421 | struct target_rlimit *target_rlim; |
9de5e440 | 3422 | struct rlimit rlim; |
53a5960a | 3423 | lock_user_struct(target_rlim, arg2, 1); |
9de5e440 FB |
3424 | rlim.rlim_cur = tswapl(target_rlim->rlim_cur); |
3425 | rlim.rlim_max = tswapl(target_rlim->rlim_max); | |
53a5960a | 3426 | unlock_user_struct(target_rlim, arg2, 0); |
9de5e440 FB |
3427 | ret = get_errno(setrlimit(resource, &rlim)); |
3428 | } | |
3429 | break; | |
31e31b8a | 3430 | case TARGET_NR_getrlimit: |
9de5e440 FB |
3431 | { |
3432 | /* XXX: convert resource ? */ | |
3433 | int resource = arg1; | |
53a5960a | 3434 | struct target_rlimit *target_rlim; |
9de5e440 | 3435 | struct rlimit rlim; |
3b46e624 | 3436 | |
9de5e440 FB |
3437 | ret = get_errno(getrlimit(resource, &rlim)); |
3438 | if (!is_error(ret)) { | |
53a5960a PB |
3439 | lock_user_struct(target_rlim, arg2, 0); |
3440 | rlim.rlim_cur = tswapl(target_rlim->rlim_cur); | |
3441 | rlim.rlim_max = tswapl(target_rlim->rlim_max); | |
3442 | unlock_user_struct(target_rlim, arg2, 1); | |
9de5e440 FB |
3443 | } |
3444 | } | |
3445 | break; | |
31e31b8a | 3446 | case TARGET_NR_getrusage: |
b409186b FB |
3447 | { |
3448 | struct rusage rusage; | |
b409186b FB |
3449 | ret = get_errno(getrusage(arg1, &rusage)); |
3450 | if (!is_error(ret)) { | |
53a5960a | 3451 | host_to_target_rusage(arg2, &rusage); |
b409186b FB |
3452 | } |
3453 | } | |
3454 | break; | |
31e31b8a FB |
3455 | case TARGET_NR_gettimeofday: |
3456 | { | |
31e31b8a FB |
3457 | struct timeval tv; |
3458 | ret = get_errno(gettimeofday(&tv, NULL)); | |
3459 | if (!is_error(ret)) { | |
53a5960a | 3460 | host_to_target_timeval(arg1, &tv); |
31e31b8a FB |
3461 | } |
3462 | } | |
3463 | break; | |
3464 | case TARGET_NR_settimeofday: | |
3465 | { | |
31e31b8a | 3466 | struct timeval tv; |
53a5960a | 3467 | target_to_host_timeval(&tv, arg1); |
31e31b8a FB |
3468 | ret = get_errno(settimeofday(&tv, NULL)); |
3469 | } | |
3470 | break; | |
048f6b4d | 3471 | #ifdef TARGET_NR_select |
31e31b8a | 3472 | case TARGET_NR_select: |
f2674e31 | 3473 | { |
53a5960a | 3474 | struct target_sel_arg_struct *sel; |
992f48a0 | 3475 | abi_ulong inp, outp, exp, tvp; |
53a5960a PB |
3476 | long nsel; |
3477 | ||
3478 | lock_user_struct(sel, arg1, 1); | |
3479 | nsel = tswapl(sel->n); | |
3480 | inp = tswapl(sel->inp); | |
3481 | outp = tswapl(sel->outp); | |
3482 | exp = tswapl(sel->exp); | |
3483 | tvp = tswapl(sel->tvp); | |
3484 | unlock_user_struct(sel, arg1, 0); | |
3485 | ret = do_select(nsel, inp, outp, exp, tvp); | |
f2674e31 FB |
3486 | } |
3487 | break; | |
048f6b4d | 3488 | #endif |
31e31b8a | 3489 | case TARGET_NR_symlink: |
53a5960a PB |
3490 | { |
3491 | void *p2; | |
3492 | p = lock_user_string(arg1); | |
3493 | p2 = lock_user_string(arg2); | |
3494 | ret = get_errno(symlink(p, p2)); | |
3495 | unlock_user(p2, arg2, 0); | |
3496 | unlock_user(p, arg1, 0); | |
3497 | } | |
31e31b8a | 3498 | break; |
f0b6243d TS |
3499 | #if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat) |
3500 | case TARGET_NR_symlinkat: | |
3501 | if (!arg1 || !arg3) { | |
0da46a6e TS |
3502 | ret = -TARGET_EFAULT; |
3503 | goto fail; | |
3504 | } | |
f0b6243d TS |
3505 | { |
3506 | void *p2 = NULL; | |
3507 | p = lock_user_string(arg1); | |
3508 | p2 = lock_user_string(arg3); | |
3509 | if (!access_ok(VERIFY_READ, p, 1) | |
3510 | || !access_ok(VERIFY_READ, p2, 1)) | |
0da46a6e TS |
3511 | /* Don't "goto fail" so that cleanup can happen. */ |
3512 | ret = -TARGET_EFAULT; | |
f0b6243d TS |
3513 | else |
3514 | ret = get_errno(sys_symlinkat(p, arg2, p2)); | |
3515 | if (p2) | |
3516 | unlock_user(p2, arg3, 0); | |
3517 | if (p) | |
3518 | unlock_user(p, arg1, 0); | |
3519 | } | |
3520 | break; | |
3521 | #endif | |
ebc05488 | 3522 | #ifdef TARGET_NR_oldlstat |
31e31b8a FB |
3523 | case TARGET_NR_oldlstat: |
3524 | goto unimplemented; | |
ebc05488 | 3525 | #endif |
31e31b8a | 3526 | case TARGET_NR_readlink: |
53a5960a PB |
3527 | { |
3528 | void *p2; | |
3529 | p = lock_user_string(arg1); | |
3530 | p2 = lock_user(arg2, arg3, 0); | |
3531 | ret = get_errno(readlink(path(p), p2, arg3)); | |
3532 | unlock_user(p2, arg2, ret); | |
3533 | unlock_user(p, arg1, 0); | |
3534 | } | |
31e31b8a | 3535 | break; |
5e0ccb18 TS |
3536 | #if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat) |
3537 | case TARGET_NR_readlinkat: | |
3538 | if (!arg2 || !arg3) { | |
0da46a6e | 3539 | ret = -TARGET_EFAULT; |
5e0ccb18 | 3540 | goto fail; |
0da46a6e | 3541 | } |
5e0ccb18 TS |
3542 | { |
3543 | void *p2 = NULL; | |
3544 | p = lock_user_string(arg2); | |
3545 | p2 = lock_user(arg3, arg4, 0); | |
3546 | if (!access_ok(VERIFY_READ, p, 1) | |
3547 | || !access_ok(VERIFY_READ, p2, 1)) | |
0da46a6e TS |
3548 | /* Don't "goto fail" so that cleanup can happen. */ |
3549 | ret = -TARGET_EFAULT; | |
5e0ccb18 TS |
3550 | else |
3551 | ret = get_errno(sys_readlinkat(arg1, path(p), p2, arg4)); | |
3552 | if (p2) | |
3553 | unlock_user(p2, arg3, ret); | |
3554 | if (p) | |
3555 | unlock_user(p, arg2, 0); | |
3556 | } | |
3557 | break; | |
3558 | #endif | |
e5febef5 | 3559 | #ifdef TARGET_NR_uselib |
31e31b8a FB |
3560 | case TARGET_NR_uselib: |
3561 | goto unimplemented; | |
e5febef5 TS |
3562 | #endif |
3563 | #ifdef TARGET_NR_swapon | |
31e31b8a | 3564 | case TARGET_NR_swapon: |
53a5960a PB |
3565 | p = lock_user_string(arg1); |
3566 | ret = get_errno(swapon(p, arg2)); | |
3567 | unlock_user(p, arg1, 0); | |
31e31b8a | 3568 | break; |
e5febef5 | 3569 | #endif |
31e31b8a FB |
3570 | case TARGET_NR_reboot: |
3571 | goto unimplemented; | |
e5febef5 | 3572 | #ifdef TARGET_NR_readdir |
31e31b8a FB |
3573 | case TARGET_NR_readdir: |
3574 | goto unimplemented; | |
e5febef5 TS |
3575 | #endif |
3576 | #ifdef TARGET_NR_mmap | |
31e31b8a | 3577 | case TARGET_NR_mmap: |
48733d19 | 3578 | #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_CRIS) |
31e31b8a | 3579 | { |
992f48a0 BS |
3580 | abi_ulong *v; |
3581 | abi_ulong v1, v2, v3, v4, v5, v6; | |
3582 | v = lock_user(arg1, 6 * sizeof(abi_ulong), 1); | |
53a5960a PB |
3583 | v1 = tswapl(v[0]); |
3584 | v2 = tswapl(v[1]); | |
3585 | v3 = tswapl(v[2]); | |
3586 | v4 = tswapl(v[3]); | |
3587 | v5 = tswapl(v[4]); | |
3588 | v6 = tswapl(v[5]); | |
3589 | unlock_user(v, arg1, 0); | |
5fafdf24 | 3590 | ret = get_errno(target_mmap(v1, v2, v3, |
5286db75 FB |
3591 | target_to_host_bitmask(v4, mmap_flags_tbl), |
3592 | v5, v6)); | |
31e31b8a | 3593 | } |
31e31b8a | 3594 | #else |
5fafdf24 TS |
3595 | ret = get_errno(target_mmap(arg1, arg2, arg3, |
3596 | target_to_host_bitmask(arg4, mmap_flags_tbl), | |
6fb883e8 FB |
3597 | arg5, |
3598 | arg6)); | |
31e31b8a | 3599 | #endif |
6fb883e8 | 3600 | break; |
e5febef5 | 3601 | #endif |
a315a145 | 3602 | #ifdef TARGET_NR_mmap2 |
6fb883e8 | 3603 | case TARGET_NR_mmap2: |
0d3267a7 | 3604 | #if defined(TARGET_SPARC) || defined(TARGET_MIPS) |
c573ff67 FB |
3605 | #define MMAP_SHIFT 12 |
3606 | #else | |
3607 | #define MMAP_SHIFT TARGET_PAGE_BITS | |
3608 | #endif | |
5fafdf24 TS |
3609 | ret = get_errno(target_mmap(arg1, arg2, arg3, |
3610 | target_to_host_bitmask(arg4, mmap_flags_tbl), | |
5286db75 | 3611 | arg5, |
c573ff67 | 3612 | arg6 << MMAP_SHIFT)); |
31e31b8a | 3613 | break; |
a315a145 | 3614 | #endif |
31e31b8a | 3615 | case TARGET_NR_munmap: |
54936004 | 3616 | ret = get_errno(target_munmap(arg1, arg2)); |
31e31b8a | 3617 | break; |
9de5e440 | 3618 | case TARGET_NR_mprotect: |
54936004 | 3619 | ret = get_errno(target_mprotect(arg1, arg2, arg3)); |
9de5e440 | 3620 | break; |
e5febef5 | 3621 | #ifdef TARGET_NR_mremap |
9de5e440 | 3622 | case TARGET_NR_mremap: |
54936004 | 3623 | ret = get_errno(target_mremap(arg1, arg2, arg3, arg4, arg5)); |
9de5e440 | 3624 | break; |
e5febef5 | 3625 | #endif |
53a5960a | 3626 | /* ??? msync/mlock/munlock are broken for softmmu. */ |
e5febef5 | 3627 | #ifdef TARGET_NR_msync |
9de5e440 | 3628 | case TARGET_NR_msync: |
53a5960a | 3629 | ret = get_errno(msync(g2h(arg1), arg2, arg3)); |
9de5e440 | 3630 | break; |
e5febef5 TS |
3631 | #endif |
3632 | #ifdef TARGET_NR_mlock | |
9de5e440 | 3633 | case TARGET_NR_mlock: |
53a5960a | 3634 | ret = get_errno(mlock(g2h(arg1), arg2)); |
9de5e440 | 3635 | break; |
e5febef5 TS |
3636 | #endif |
3637 | #ifdef TARGET_NR_munlock | |
9de5e440 | 3638 | case TARGET_NR_munlock: |
53a5960a | 3639 | ret = get_errno(munlock(g2h(arg1), arg2)); |
9de5e440 | 3640 | break; |
e5febef5 TS |
3641 | #endif |
3642 | #ifdef TARGET_NR_mlockall | |
9de5e440 FB |
3643 | case TARGET_NR_mlockall: |
3644 | ret = get_errno(mlockall(arg1)); | |
3645 | break; | |
e5febef5 TS |
3646 | #endif |
3647 | #ifdef TARGET_NR_munlockall | |
9de5e440 FB |
3648 | case TARGET_NR_munlockall: |
3649 | ret = get_errno(munlockall()); | |
3650 | break; | |
e5febef5 | 3651 | #endif |
31e31b8a | 3652 | case TARGET_NR_truncate: |
53a5960a PB |
3653 | p = lock_user_string(arg1); |
3654 | ret = get_errno(truncate(p, arg2)); | |
3655 | unlock_user(p, arg1, 0); | |
31e31b8a FB |
3656 | break; |
3657 | case TARGET_NR_ftruncate: | |
3658 | ret = get_errno(ftruncate(arg1, arg2)); | |
3659 | break; | |
3660 | case TARGET_NR_fchmod: | |
3661 | ret = get_errno(fchmod(arg1, arg2)); | |
3662 | break; | |
814d7977 TS |
3663 | #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat) |
3664 | case TARGET_NR_fchmodat: | |
3665 | if (!arg2) { | |
0da46a6e | 3666 | ret = -TARGET_EFAULT; |
814d7977 TS |
3667 | goto fail; |
3668 | } | |
3669 | p = lock_user_string(arg2); | |
3670 | if (!access_ok(VERIFY_READ, p, 1)) | |
0da46a6e TS |
3671 | /* Don't "goto fail" so that cleanup can happen. */ |
3672 | ret = -TARGET_EFAULT; | |
814d7977 TS |
3673 | else |
3674 | ret = get_errno(sys_fchmodat(arg1, p, arg3, arg4)); | |
3675 | if (p) | |
3676 | unlock_user(p, arg2, 0); | |
3677 | break; | |
3678 | #endif | |
31e31b8a | 3679 | case TARGET_NR_getpriority: |
c6cda17a TS |
3680 | /* libc does special remapping of the return value of |
3681 | * sys_getpriority() so it's just easiest to call | |
3682 | * sys_getpriority() directly rather than through libc. */ | |
3683 | ret = sys_getpriority(arg1, arg2); | |
31e31b8a FB |
3684 | break; |
3685 | case TARGET_NR_setpriority: | |
3686 | ret = get_errno(setpriority(arg1, arg2, arg3)); | |
3687 | break; | |
ebc05488 | 3688 | #ifdef TARGET_NR_profil |
31e31b8a FB |
3689 | case TARGET_NR_profil: |
3690 | goto unimplemented; | |
ebc05488 | 3691 | #endif |
31e31b8a | 3692 | case TARGET_NR_statfs: |
53a5960a PB |
3693 | p = lock_user_string(arg1); |
3694 | ret = get_errno(statfs(path(p), &stfs)); | |
3695 | unlock_user(p, arg1, 0); | |
31e31b8a FB |
3696 | convert_statfs: |
3697 | if (!is_error(ret)) { | |
53a5960a | 3698 | struct target_statfs *target_stfs; |
3b46e624 | 3699 | |
53a5960a PB |
3700 | lock_user_struct(target_stfs, arg2, 0); |
3701 | /* ??? put_user is probably wrong. */ | |
56c8f68f FB |
3702 | put_user(stfs.f_type, &target_stfs->f_type); |
3703 | put_user(stfs.f_bsize, &target_stfs->f_bsize); | |
3704 | put_user(stfs.f_blocks, &target_stfs->f_blocks); | |
3705 | put_user(stfs.f_bfree, &target_stfs->f_bfree); | |
3706 | put_user(stfs.f_bavail, &target_stfs->f_bavail); | |
3707 | put_user(stfs.f_files, &target_stfs->f_files); | |
3708 | put_user(stfs.f_ffree, &target_stfs->f_ffree); | |
4ce6f8de TS |
3709 | put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]); |
3710 | put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]); | |
56c8f68f | 3711 | put_user(stfs.f_namelen, &target_stfs->f_namelen); |
53a5960a | 3712 | unlock_user_struct(target_stfs, arg2, 1); |
31e31b8a FB |
3713 | } |
3714 | break; | |
3715 | case TARGET_NR_fstatfs: | |
56c8f68f | 3716 | ret = get_errno(fstatfs(arg1, &stfs)); |
31e31b8a | 3717 | goto convert_statfs; |
56c8f68f FB |
3718 | #ifdef TARGET_NR_statfs64 |
3719 | case TARGET_NR_statfs64: | |
53a5960a PB |
3720 | p = lock_user_string(arg1); |
3721 | ret = get_errno(statfs(path(p), &stfs)); | |
3722 | unlock_user(p, arg1, 0); | |
56c8f68f FB |
3723 | convert_statfs64: |
3724 | if (!is_error(ret)) { | |
53a5960a | 3725 | struct target_statfs64 *target_stfs; |
3b46e624 | 3726 | |
53a5960a PB |
3727 | lock_user_struct(target_stfs, arg3, 0); |
3728 | /* ??? put_user is probably wrong. */ | |
56c8f68f FB |
3729 | put_user(stfs.f_type, &target_stfs->f_type); |
3730 | put_user(stfs.f_bsize, &target_stfs->f_bsize); | |
3731 | put_user(stfs.f_blocks, &target_stfs->f_blocks); | |
3732 | put_user(stfs.f_bfree, &target_stfs->f_bfree); | |
3733 | put_user(stfs.f_bavail, &target_stfs->f_bavail); | |
3734 | put_user(stfs.f_files, &target_stfs->f_files); | |
3735 | put_user(stfs.f_ffree, &target_stfs->f_ffree); | |
4ce6f8de TS |
3736 | put_user(stfs.f_fsid.__val[0], &target_stfs->f_fsid.val[0]); |
3737 | put_user(stfs.f_fsid.__val[1], &target_stfs->f_fsid.val[1]); | |
56c8f68f | 3738 | put_user(stfs.f_namelen, &target_stfs->f_namelen); |
53a5960a | 3739 | unlock_user_struct(target_stfs, arg3, 0); |
56c8f68f FB |
3740 | } |
3741 | break; | |
3742 | case TARGET_NR_fstatfs64: | |
3743 | ret = get_errno(fstatfs(arg1, &stfs)); | |
3744 | goto convert_statfs64; | |
3745 | #endif | |
ebc05488 | 3746 | #ifdef TARGET_NR_ioperm |
31e31b8a FB |
3747 | case TARGET_NR_ioperm: |
3748 | goto unimplemented; | |
ebc05488 | 3749 | #endif |
e5febef5 | 3750 | #ifdef TARGET_NR_socketcall |
31e31b8a | 3751 | case TARGET_NR_socketcall: |
53a5960a | 3752 | ret = do_socketcall(arg1, arg2); |
31e31b8a | 3753 | break; |
e5febef5 | 3754 | #endif |
3532fa74 FB |
3755 | #ifdef TARGET_NR_accept |
3756 | case TARGET_NR_accept: | |
1be9e1dc | 3757 | ret = do_accept(arg1, arg2, arg3); |
3532fa74 FB |
3758 | break; |
3759 | #endif | |
3760 | #ifdef TARGET_NR_bind | |
3761 | case TARGET_NR_bind: | |
3762 | ret = do_bind(arg1, arg2, arg3); | |
3763 | break; | |
3764 | #endif | |
3765 | #ifdef TARGET_NR_connect | |
3766 | case TARGET_NR_connect: | |
3767 | ret = do_connect(arg1, arg2, arg3); | |
3768 | break; | |
3769 | #endif | |
3770 | #ifdef TARGET_NR_getpeername | |
3771 | case TARGET_NR_getpeername: | |
1be9e1dc | 3772 | ret = do_getpeername(arg1, arg2, arg3); |
3532fa74 FB |
3773 | break; |
3774 | #endif | |
3775 | #ifdef TARGET_NR_getsockname | |
3776 | case TARGET_NR_getsockname: | |
1be9e1dc | 3777 | ret = do_getsockname(arg1, arg2, arg3); |
3532fa74 FB |
3778 | break; |
3779 | #endif | |
3780 | #ifdef TARGET_NR_getsockopt | |
3781 | case TARGET_NR_getsockopt: | |
3782 | ret = do_getsockopt(arg1, arg2, arg3, arg4, arg5); | |
3783 | break; | |
3784 | #endif | |
3785 | #ifdef TARGET_NR_listen | |
3786 | case TARGET_NR_listen: | |
1be9e1dc | 3787 | ret = get_errno(listen(arg1, arg2)); |
3532fa74 FB |
3788 | break; |
3789 | #endif | |
3790 | #ifdef TARGET_NR_recv | |
3791 | case TARGET_NR_recv: | |
214201bd | 3792 | ret = do_recvfrom(arg1, arg2, arg3, arg4, 0, 0); |
3532fa74 FB |
3793 | break; |
3794 | #endif | |
3795 | #ifdef TARGET_NR_recvfrom | |
3796 | case TARGET_NR_recvfrom: | |
214201bd | 3797 | ret = do_recvfrom(arg1, arg2, arg3, arg4, arg5, arg6); |
3532fa74 FB |
3798 | break; |
3799 | #endif | |
3800 | #ifdef TARGET_NR_recvmsg | |
3801 | case TARGET_NR_recvmsg: | |
3802 | ret = do_sendrecvmsg(arg1, arg2, arg3, 0); | |
3803 | break; | |
3804 | #endif | |
3805 | #ifdef TARGET_NR_send | |
3806 | case TARGET_NR_send: | |
1be9e1dc | 3807 | ret = do_sendto(arg1, arg2, arg3, arg4, 0, 0); |
3532fa74 FB |
3808 | break; |
3809 | #endif | |
3810 | #ifdef TARGET_NR_sendmsg | |
3811 | case TARGET_NR_sendmsg: | |
3812 | ret = do_sendrecvmsg(arg1, arg2, arg3, 1); | |
3813 | break; | |
3814 | #endif | |
3815 | #ifdef TARGET_NR_sendto | |
3816 | case TARGET_NR_sendto: | |
1be9e1dc | 3817 | ret = do_sendto(arg1, arg2, arg3, arg4, arg5, arg6); |
3532fa74 FB |
3818 | break; |
3819 | #endif | |
3820 | #ifdef TARGET_NR_shutdown | |
3821 | case TARGET_NR_shutdown: | |
1be9e1dc | 3822 | ret = get_errno(shutdown(arg1, arg2)); |
3532fa74 FB |
3823 | break; |
3824 | #endif | |
3825 | #ifdef TARGET_NR_socket | |
3826 | case TARGET_NR_socket: | |
3827 | ret = do_socket(arg1, arg2, arg3); | |
3828 | break; | |
3829 | #endif | |
3830 | #ifdef TARGET_NR_socketpair | |
3831 | case TARGET_NR_socketpair: | |
1be9e1dc | 3832 | ret = do_socketpair(arg1, arg2, arg3, arg4); |
3532fa74 FB |
3833 | break; |
3834 | #endif | |
3835 | #ifdef TARGET_NR_setsockopt | |
3836 | case TARGET_NR_setsockopt: | |
3837 | ret = do_setsockopt(arg1, arg2, arg3, arg4, (socklen_t) arg5); | |
3838 | break; | |
3839 | #endif | |
7494b0f9 | 3840 | |
31e31b8a | 3841 | case TARGET_NR_syslog: |
e5574487 TS |
3842 | p = lock_user_string(arg2); |
3843 | ret = get_errno(sys_syslog((int)arg1, p, (int)arg3)); | |
3844 | unlock_user(p, arg2, 0); | |
7494b0f9 TS |
3845 | break; |
3846 | ||
31e31b8a | 3847 | case TARGET_NR_setitimer: |
66fb9763 | 3848 | { |
66fb9763 FB |
3849 | struct itimerval value, ovalue, *pvalue; |
3850 | ||
53a5960a | 3851 | if (arg2) { |
66fb9763 | 3852 | pvalue = &value; |
5fafdf24 | 3853 | target_to_host_timeval(&pvalue->it_interval, |
53a5960a | 3854 | arg2); |
5fafdf24 | 3855 | target_to_host_timeval(&pvalue->it_value, |
53a5960a | 3856 | arg2 + sizeof(struct target_timeval)); |
66fb9763 FB |
3857 | } else { |
3858 | pvalue = NULL; | |
3859 | } | |
3860 | ret = get_errno(setitimer(arg1, pvalue, &ovalue)); | |
53a5960a PB |
3861 | if (!is_error(ret) && arg3) { |
3862 | host_to_target_timeval(arg3, | |
66fb9763 | 3863 | &ovalue.it_interval); |
53a5960a | 3864 | host_to_target_timeval(arg3 + sizeof(struct target_timeval), |
66fb9763 FB |
3865 | &ovalue.it_value); |
3866 | } | |
3867 | } | |
3868 | break; | |
31e31b8a | 3869 | case TARGET_NR_getitimer: |
66fb9763 | 3870 | { |
66fb9763 | 3871 | struct itimerval value; |
3b46e624 | 3872 | |
66fb9763 | 3873 | ret = get_errno(getitimer(arg1, &value)); |
53a5960a PB |
3874 | if (!is_error(ret) && arg2) { |
3875 | host_to_target_timeval(arg2, | |
66fb9763 | 3876 | &value.it_interval); |
53a5960a | 3877 | host_to_target_timeval(arg2 + sizeof(struct target_timeval), |
66fb9763 FB |
3878 | &value.it_value); |
3879 | } | |
3880 | } | |
3881 | break; | |
31e31b8a | 3882 | case TARGET_NR_stat: |
53a5960a PB |
3883 | p = lock_user_string(arg1); |
3884 | ret = get_errno(stat(path(p), &st)); | |
3885 | unlock_user(p, arg1, 0); | |
31e31b8a FB |
3886 | goto do_stat; |
3887 | case TARGET_NR_lstat: | |
53a5960a PB |
3888 | p = lock_user_string(arg1); |
3889 | ret = get_errno(lstat(path(p), &st)); | |
3890 | unlock_user(p, arg1, 0); | |
31e31b8a FB |
3891 | goto do_stat; |
3892 | case TARGET_NR_fstat: | |
3893 | { | |
3894 | ret = get_errno(fstat(arg1, &st)); | |
3895 | do_stat: | |
3896 | if (!is_error(ret)) { | |
53a5960a | 3897 | struct target_stat *target_st; |
e3584658 | 3898 | |
53a5960a | 3899 | lock_user_struct(target_st, arg2, 0); |
992f48a0 | 3900 | #if defined(TARGET_MIPS) || (defined(TARGET_SPARC64) && !defined(TARGET_ABI32)) |
e3584658 TS |
3901 | target_st->st_dev = tswap32(st.st_dev); |
3902 | #else | |
31e31b8a | 3903 | target_st->st_dev = tswap16(st.st_dev); |
e3584658 | 3904 | #endif |
31e31b8a | 3905 | target_st->st_ino = tswapl(st.st_ino); |
7d600c80 | 3906 | #if defined(TARGET_PPC) || defined(TARGET_MIPS) |
67867308 FB |
3907 | target_st->st_mode = tswapl(st.st_mode); /* XXX: check this */ |
3908 | target_st->st_uid = tswap32(st.st_uid); | |
3909 | target_st->st_gid = tswap32(st.st_gid); | |
992f48a0 | 3910 | #elif defined(TARGET_SPARC64) && !defined(TARGET_ABI32) |
1b8dd648 BS |
3911 | target_st->st_mode = tswap32(st.st_mode); |
3912 | target_st->st_uid = tswap32(st.st_uid); | |
3913 | target_st->st_gid = tswap32(st.st_gid); | |
67867308 | 3914 | #else |
ec86b0fb | 3915 | target_st->st_mode = tswap16(st.st_mode); |
31e31b8a FB |
3916 | target_st->st_uid = tswap16(st.st_uid); |
3917 | target_st->st_gid = tswap16(st.st_gid); | |
67867308 | 3918 | #endif |
e3584658 TS |
3919 | #if defined(TARGET_MIPS) |
3920 | /* If this is the same on PPC, then just merge w/ the above ifdef */ | |
3921 | target_st->st_nlink = tswapl(st.st_nlink); | |
3922 | target_st->st_rdev = tswapl(st.st_rdev); | |
992f48a0 | 3923 | #elif defined(TARGET_SPARC64) && !defined(TARGET_ABI32) |
1b8dd648 BS |
3924 | target_st->st_nlink = tswap32(st.st_nlink); |
3925 | target_st->st_rdev = tswap32(st.st_rdev); | |
e3584658 | 3926 | #else |
67867308 | 3927 | target_st->st_nlink = tswap16(st.st_nlink); |
31e31b8a | 3928 | target_st->st_rdev = tswap16(st.st_rdev); |
e3584658 | 3929 | #endif |
31e31b8a FB |
3930 | target_st->st_size = tswapl(st.st_size); |
3931 | target_st->st_blksize = tswapl(st.st_blksize); | |
3932 | target_st->st_blocks = tswapl(st.st_blocks); | |
7854b056 FB |
3933 | target_st->target_st_atime = tswapl(st.st_atime); |
3934 | target_st->target_st_mtime = tswapl(st.st_mtime); | |
3935 | target_st->target_st_ctime = tswapl(st.st_ctime); | |
53a5960a | 3936 | unlock_user_struct(target_st, arg2, 1); |
31e31b8a FB |
3937 | } |
3938 | } | |
3939 | break; | |
ebc05488 | 3940 | #ifdef TARGET_NR_olduname |
31e31b8a FB |
3941 | case TARGET_NR_olduname: |
3942 | goto unimplemented; | |
ebc05488 FB |
3943 | #endif |
3944 | #ifdef TARGET_NR_iopl | |
31e31b8a FB |
3945 | case TARGET_NR_iopl: |
3946 | goto unimplemented; | |
ebc05488 | 3947 | #endif |
31e31b8a FB |
3948 | case TARGET_NR_vhangup: |
3949 | ret = get_errno(vhangup()); | |
3950 | break; | |
ebc05488 | 3951 | #ifdef TARGET_NR_idle |
31e31b8a FB |
3952 | case TARGET_NR_idle: |
3953 | goto unimplemented; | |
42ad6ae9 FB |
3954 | #endif |
3955 | #ifdef TARGET_NR_syscall | |
3956 | case TARGET_NR_syscall: | |
3957 | ret = do_syscall(cpu_env,arg1 & 0xffff,arg2,arg3,arg4,arg5,arg6,0); | |
3958 | break; | |
ebc05488 | 3959 | #endif |
31e31b8a FB |
3960 | case TARGET_NR_wait4: |
3961 | { | |
3962 | int status; | |
992f48a0 | 3963 | abi_long status_ptr = arg2; |
31e31b8a | 3964 | struct rusage rusage, *rusage_ptr; |
992f48a0 | 3965 | abi_ulong target_rusage = arg4; |
31e31b8a FB |
3966 | if (target_rusage) |
3967 | rusage_ptr = &rusage; | |
3968 | else | |
3969 | rusage_ptr = NULL; | |
3970 | ret = get_errno(wait4(arg1, &status, arg3, rusage_ptr)); | |
3971 | if (!is_error(ret)) { | |
3972 | if (status_ptr) | |
53a5960a | 3973 | tputl(status_ptr, status); |
31e31b8a | 3974 | if (target_rusage) { |
b409186b | 3975 | host_to_target_rusage(target_rusage, &rusage); |
31e31b8a FB |
3976 | } |
3977 | } | |
3978 | } | |
3979 | break; | |
e5febef5 | 3980 | #ifdef TARGET_NR_swapoff |
31e31b8a | 3981 | case TARGET_NR_swapoff: |
53a5960a PB |
3982 | p = lock_user_string(arg1); |
3983 | ret = get_errno(swapoff(p)); | |
3984 | unlock_user(p, arg1, 0); | |
31e31b8a | 3985 | break; |
e5febef5 | 3986 | #endif |
31e31b8a | 3987 | case TARGET_NR_sysinfo: |
a5448a7d | 3988 | { |
53a5960a | 3989 | struct target_sysinfo *target_value; |
a5448a7d FB |
3990 | struct sysinfo value; |
3991 | ret = get_errno(sysinfo(&value)); | |
53a5960a | 3992 | if (!is_error(ret) && arg1) |
a5448a7d | 3993 | { |
53a5960a PB |
3994 | /* ??? __put_user is probably wrong. */ |
3995 | lock_user_struct(target_value, arg1, 0); | |
a5448a7d FB |
3996 | __put_user(value.uptime, &target_value->uptime); |
3997 | __put_user(value.loads[0], &target_value->loads[0]); | |
3998 | __put_user(value.loads[1], &target_value->loads[1]); | |
3999 | __put_user(value.loads[2], &target_value->loads[2]); | |
4000 | __put_user(value.totalram, &target_value->totalram); | |
4001 | __put_user(value.freeram, &target_value->freeram); | |
4002 | __put_user(value.sharedram, &target_value->sharedram); | |
4003 | __put_user(value.bufferram, &target_value->bufferram); | |
4004 | __put_user(value.totalswap, &target_value->totalswap); | |
4005 | __put_user(value.freeswap, &target_value->freeswap); | |
4006 | __put_user(value.procs, &target_value->procs); | |
4007 | __put_user(value.totalhigh, &target_value->totalhigh); | |
4008 | __put_user(value.freehigh, &target_value->freehigh); | |
4009 | __put_user(value.mem_unit, &target_value->mem_unit); | |
53a5960a | 4010 | unlock_user_struct(target_value, arg1, 1); |
a5448a7d FB |
4011 | } |
4012 | } | |
4013 | break; | |
e5febef5 | 4014 | #ifdef TARGET_NR_ipc |
31e31b8a | 4015 | case TARGET_NR_ipc: |
8853f86e FB |
4016 | ret = do_ipc(arg1, arg2, arg3, arg4, arg5, arg6); |
4017 | break; | |
e5febef5 | 4018 | #endif |
31e31b8a FB |
4019 | case TARGET_NR_fsync: |
4020 | ret = get_errno(fsync(arg1)); | |
4021 | break; | |
31e31b8a | 4022 | case TARGET_NR_clone: |
1b6b029e FB |
4023 | ret = get_errno(do_fork(cpu_env, arg1, arg2)); |
4024 | break; | |
ec86b0fb FB |
4025 | #ifdef __NR_exit_group |
4026 | /* new thread calls */ | |
4027 | case TARGET_NR_exit_group: | |
e9009676 | 4028 | gdb_exit(cpu_env, arg1); |
ec86b0fb FB |
4029 | ret = get_errno(exit_group(arg1)); |
4030 | break; | |
4031 | #endif | |
31e31b8a | 4032 | case TARGET_NR_setdomainname: |
53a5960a PB |
4033 | p = lock_user_string(arg1); |
4034 | ret = get_errno(setdomainname(p, arg2)); | |
4035 | unlock_user(p, arg1, 0); | |
31e31b8a FB |
4036 | break; |
4037 | case TARGET_NR_uname: | |
4038 | /* no need to transcode because we use the linux syscall */ | |
29e619b1 FB |
4039 | { |
4040 | struct new_utsname * buf; | |
3b46e624 | 4041 | |
53a5960a | 4042 | lock_user_struct(buf, arg1, 0); |
29e619b1 FB |
4043 | ret = get_errno(sys_uname(buf)); |
4044 | if (!is_error(ret)) { | |
4045 | /* Overrite the native machine name with whatever is being | |
4046 | emulated. */ | |
4047 | strcpy (buf->machine, UNAME_MACHINE); | |
c5937220 PB |
4048 | /* Allow the user to override the reported release. */ |
4049 | if (qemu_uname_release && *qemu_uname_release) | |
4050 | strcpy (buf->release, qemu_uname_release); | |
29e619b1 | 4051 | } |
53a5960a | 4052 | unlock_user_struct(buf, arg1, 1); |
29e619b1 | 4053 | } |
31e31b8a | 4054 | break; |
6dbad63e | 4055 | #ifdef TARGET_I386 |
31e31b8a | 4056 | case TARGET_NR_modify_ldt: |
53a5960a | 4057 | ret = get_errno(do_modify_ldt(cpu_env, arg1, arg2, arg3)); |
5cd4393b | 4058 | break; |
84409ddb | 4059 | #if !defined(TARGET_X86_64) |
5cd4393b FB |
4060 | case TARGET_NR_vm86old: |
4061 | goto unimplemented; | |
4062 | case TARGET_NR_vm86: | |
53a5960a | 4063 | ret = do_vm86(cpu_env, arg1, arg2); |
6dbad63e | 4064 | break; |
84409ddb | 4065 | #endif |
6dbad63e | 4066 | #endif |
31e31b8a FB |
4067 | case TARGET_NR_adjtimex: |
4068 | goto unimplemented; | |
e5febef5 | 4069 | #ifdef TARGET_NR_create_module |
31e31b8a | 4070 | case TARGET_NR_create_module: |
e5febef5 | 4071 | #endif |
31e31b8a FB |
4072 | case TARGET_NR_init_module: |
4073 | case TARGET_NR_delete_module: | |
e5febef5 | 4074 | #ifdef TARGET_NR_get_kernel_syms |
31e31b8a | 4075 | case TARGET_NR_get_kernel_syms: |
e5febef5 | 4076 | #endif |
31e31b8a FB |
4077 | goto unimplemented; |
4078 | case TARGET_NR_quotactl: | |
4079 | goto unimplemented; | |
4080 | case TARGET_NR_getpgid: | |
4081 | ret = get_errno(getpgid(arg1)); | |
4082 | break; | |
4083 | case TARGET_NR_fchdir: | |
4084 | ret = get_errno(fchdir(arg1)); | |
4085 | break; | |
84409ddb | 4086 | #ifdef TARGET_NR_bdflush /* not on x86_64 */ |
31e31b8a FB |
4087 | case TARGET_NR_bdflush: |
4088 | goto unimplemented; | |
84409ddb | 4089 | #endif |
e5febef5 | 4090 | #ifdef TARGET_NR_sysfs |
31e31b8a FB |
4091 | case TARGET_NR_sysfs: |
4092 | goto unimplemented; | |
e5febef5 | 4093 | #endif |
31e31b8a | 4094 | case TARGET_NR_personality: |
1b6b029e | 4095 | ret = get_errno(personality(arg1)); |
31e31b8a | 4096 | break; |
e5febef5 | 4097 | #ifdef TARGET_NR_afs_syscall |
31e31b8a FB |
4098 | case TARGET_NR_afs_syscall: |
4099 | goto unimplemented; | |
e5febef5 | 4100 | #endif |
7a3148a9 | 4101 | #ifdef TARGET_NR__llseek /* Not on alpha */ |
31e31b8a FB |
4102 | case TARGET_NR__llseek: |
4103 | { | |
4f2ac237 FB |
4104 | #if defined (__x86_64__) |
4105 | ret = get_errno(lseek(arg1, ((uint64_t )arg2 << 32) | arg3, arg5)); | |
53a5960a | 4106 | tput64(arg4, ret); |
4f2ac237 | 4107 | #else |
31e31b8a FB |
4108 | int64_t res; |
4109 | ret = get_errno(_llseek(arg1, arg2, arg3, &res, arg5)); | |
53a5960a | 4110 | tput64(arg4, res); |
4f2ac237 | 4111 | #endif |
31e31b8a FB |
4112 | } |
4113 | break; | |
7a3148a9 | 4114 | #endif |
31e31b8a | 4115 | case TARGET_NR_getdents: |
992f48a0 | 4116 | #if TARGET_ABI_BITS != 32 |
53a5960a | 4117 | goto unimplemented; |
a315a145 | 4118 | #warning not supported |
992f48a0 | 4119 | #elif TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64 |
4add45b4 | 4120 | { |
53a5960a | 4121 | struct target_dirent *target_dirp; |
4add45b4 | 4122 | struct dirent *dirp; |
992f48a0 | 4123 | abi_long count = arg3; |
4add45b4 FB |
4124 | |
4125 | dirp = malloc(count); | |
0da46a6e TS |
4126 | if (!dirp) { |
4127 | ret = -TARGET_EFAULT; | |
4128 | goto fail; | |
4129 | } | |
3b46e624 | 4130 | |
4add45b4 FB |
4131 | ret = get_errno(sys_getdents(arg1, dirp, count)); |
4132 | if (!is_error(ret)) { | |
4133 | struct dirent *de; | |
4134 | struct target_dirent *tde; | |
4135 | int len = ret; | |
4136 | int reclen, treclen; | |
4137 | int count1, tnamelen; | |
4138 | ||
4139 | count1 = 0; | |
4140 | de = dirp; | |
53a5960a | 4141 | target_dirp = lock_user(arg2, count, 0); |
4add45b4 FB |
4142 | tde = target_dirp; |
4143 | while (len > 0) { | |
4144 | reclen = de->d_reclen; | |
992f48a0 | 4145 | treclen = reclen - (2 * (sizeof(long) - sizeof(abi_long))); |
4add45b4 FB |
4146 | tde->d_reclen = tswap16(treclen); |
4147 | tde->d_ino = tswapl(de->d_ino); | |
4148 | tde->d_off = tswapl(de->d_off); | |
992f48a0 | 4149 | tnamelen = treclen - (2 * sizeof(abi_long) + 2); |
4add45b4 FB |
4150 | if (tnamelen > 256) |
4151 | tnamelen = 256; | |
80a9d035 | 4152 | /* XXX: may not be correct */ |
4add45b4 FB |
4153 | strncpy(tde->d_name, de->d_name, tnamelen); |
4154 | de = (struct dirent *)((char *)de + reclen); | |
4155 | len -= reclen; | |
1c5bf3bf | 4156 | tde = (struct target_dirent *)((char *)tde + treclen); |
4add45b4 FB |
4157 | count1 += treclen; |
4158 | } | |
4159 | ret = count1; | |
4160 | } | |
53a5960a | 4161 | unlock_user(target_dirp, arg2, ret); |
4add45b4 FB |
4162 | free(dirp); |
4163 | } | |
4164 | #else | |
31e31b8a | 4165 | { |
53a5960a | 4166 | struct dirent *dirp; |
992f48a0 | 4167 | abi_long count = arg3; |
dab2ed99 | 4168 | |
53a5960a | 4169 | dirp = lock_user(arg2, count, 0); |
72f03900 | 4170 | ret = get_errno(sys_getdents(arg1, dirp, count)); |
31e31b8a FB |
4171 | if (!is_error(ret)) { |
4172 | struct dirent *de; | |
4173 | int len = ret; | |
4174 | int reclen; | |
4175 | de = dirp; | |
4176 | while (len > 0) { | |
8083a3e5 | 4177 | reclen = de->d_reclen; |
31e31b8a FB |
4178 | if (reclen > len) |
4179 | break; | |
8083a3e5 | 4180 | de->d_reclen = tswap16(reclen); |
31e31b8a FB |
4181 | tswapls(&de->d_ino); |
4182 | tswapls(&de->d_off); | |
4183 | de = (struct dirent *)((char *)de + reclen); | |
4184 | len -= reclen; | |
4185 | } | |
4186 | } | |
53a5960a | 4187 | unlock_user(dirp, arg2, ret); |
31e31b8a | 4188 | } |
4add45b4 | 4189 | #endif |
31e31b8a | 4190 | break; |
3ae43202 | 4191 | #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64) |
dab2ed99 FB |
4192 | case TARGET_NR_getdents64: |
4193 | { | |
53a5960a | 4194 | struct dirent64 *dirp; |
992f48a0 | 4195 | abi_long count = arg3; |
53a5960a | 4196 | dirp = lock_user(arg2, count, 0); |
dab2ed99 FB |
4197 | ret = get_errno(sys_getdents64(arg1, dirp, count)); |
4198 | if (!is_error(ret)) { | |
4199 | struct dirent64 *de; | |
4200 | int len = ret; | |
4201 | int reclen; | |
4202 | de = dirp; | |
4203 | while (len > 0) { | |
8083a3e5 | 4204 | reclen = de->d_reclen; |
dab2ed99 FB |
4205 | if (reclen > len) |
4206 | break; | |
8083a3e5 | 4207 | de->d_reclen = tswap16(reclen); |
dab2ed99 FB |
4208 | tswap64s(&de->d_ino); |
4209 | tswap64s(&de->d_off); | |
4210 | de = (struct dirent64 *)((char *)de + reclen); | |
4211 | len -= reclen; | |
4212 | } | |
4213 | } | |
53a5960a | 4214 | unlock_user(dirp, arg2, ret); |
dab2ed99 FB |
4215 | } |
4216 | break; | |
a541f297 | 4217 | #endif /* TARGET_NR_getdents64 */ |
e5febef5 | 4218 | #ifdef TARGET_NR__newselect |
31e31b8a | 4219 | case TARGET_NR__newselect: |
53a5960a | 4220 | ret = do_select(arg1, arg2, arg3, arg4, arg5); |
31e31b8a | 4221 | break; |
e5febef5 TS |
4222 | #endif |
4223 | #ifdef TARGET_NR_poll | |
9de5e440 FB |
4224 | case TARGET_NR_poll: |
4225 | { | |
53a5960a | 4226 | struct target_pollfd *target_pfd; |
9de5e440 FB |
4227 | unsigned int nfds = arg2; |
4228 | int timeout = arg3; | |
4229 | struct pollfd *pfd; | |
7854b056 | 4230 | unsigned int i; |
9de5e440 | 4231 | |
53a5960a | 4232 | target_pfd = lock_user(arg1, sizeof(struct target_pollfd) * nfds, 1); |
9de5e440 FB |
4233 | pfd = alloca(sizeof(struct pollfd) * nfds); |
4234 | for(i = 0; i < nfds; i++) { | |
5cd4393b FB |
4235 | pfd[i].fd = tswap32(target_pfd[i].fd); |
4236 | pfd[i].events = tswap16(target_pfd[i].events); | |
9de5e440 FB |
4237 | } |
4238 | ret = get_errno(poll(pfd, nfds, timeout)); | |
4239 | if (!is_error(ret)) { | |
4240 | for(i = 0; i < nfds; i++) { | |
5cd4393b | 4241 | target_pfd[i].revents = tswap16(pfd[i].revents); |
9de5e440 | 4242 | } |
53a5960a PB |
4243 | ret += nfds * (sizeof(struct target_pollfd) |
4244 | - sizeof(struct pollfd)); | |
9de5e440 | 4245 | } |
53a5960a | 4246 | unlock_user(target_pfd, arg1, ret); |
9de5e440 FB |
4247 | } |
4248 | break; | |
e5febef5 | 4249 | #endif |
31e31b8a | 4250 | case TARGET_NR_flock: |
9de5e440 FB |
4251 | /* NOTE: the flock constant seems to be the same for every |
4252 | Linux platform */ | |
4253 | ret = get_errno(flock(arg1, arg2)); | |
31e31b8a FB |
4254 | break; |
4255 | case TARGET_NR_readv: | |
4256 | { | |
4257 | int count = arg3; | |
31e31b8a | 4258 | struct iovec *vec; |
31e31b8a FB |
4259 | |
4260 | vec = alloca(count * sizeof(struct iovec)); | |
53a5960a | 4261 | lock_iovec(vec, arg2, count, 0); |
31e31b8a | 4262 | ret = get_errno(readv(arg1, vec, count)); |
53a5960a | 4263 | unlock_iovec(vec, arg2, count, 1); |
31e31b8a FB |
4264 | } |
4265 | break; | |
4266 | case TARGET_NR_writev: | |
4267 | { | |
4268 | int count = arg3; | |
31e31b8a | 4269 | struct iovec *vec; |
31e31b8a FB |
4270 | |
4271 | vec = alloca(count * sizeof(struct iovec)); | |
53a5960a | 4272 | lock_iovec(vec, arg2, count, 1); |
31e31b8a | 4273 | ret = get_errno(writev(arg1, vec, count)); |
53a5960a | 4274 | unlock_iovec(vec, arg2, count, 0); |
31e31b8a FB |
4275 | } |
4276 | break; | |
4277 | case TARGET_NR_getsid: | |
4278 | ret = get_errno(getsid(arg1)); | |
4279 | break; | |
7a3148a9 | 4280 | #if defined(TARGET_NR_fdatasync) /* Not on alpha (osf_datasync ?) */ |
31e31b8a | 4281 | case TARGET_NR_fdatasync: |
5cd4393b FB |
4282 | ret = get_errno(fdatasync(arg1)); |
4283 | break; | |
7a3148a9 | 4284 | #endif |
31e31b8a | 4285 | case TARGET_NR__sysctl: |
0da46a6e | 4286 | /* We don't implement this, but ENOTDIR is always a safe |
29e619b1 | 4287 | return value. */ |
0da46a6e TS |
4288 | ret = -TARGET_ENOTDIR; |
4289 | break; | |
31e31b8a | 4290 | case TARGET_NR_sched_setparam: |
5cd4393b | 4291 | { |
53a5960a | 4292 | struct sched_param *target_schp; |
5cd4393b | 4293 | struct sched_param schp; |
53a5960a PB |
4294 | |
4295 | lock_user_struct(target_schp, arg2, 1); | |
5cd4393b | 4296 | schp.sched_priority = tswap32(target_schp->sched_priority); |
53a5960a | 4297 | unlock_user_struct(target_schp, arg2, 0); |
5cd4393b FB |
4298 | ret = get_errno(sched_setparam(arg1, &schp)); |
4299 | } | |
4300 | break; | |
31e31b8a | 4301 | case TARGET_NR_sched_getparam: |
5cd4393b | 4302 | { |
53a5960a | 4303 | struct sched_param *target_schp; |
5cd4393b FB |
4304 | struct sched_param schp; |
4305 | ret = get_errno(sched_getparam(arg1, &schp)); | |
4306 | if (!is_error(ret)) { | |
53a5960a | 4307 | lock_user_struct(target_schp, arg2, 0); |
5cd4393b | 4308 | target_schp->sched_priority = tswap32(schp.sched_priority); |
53a5960a | 4309 | unlock_user_struct(target_schp, arg2, 1); |
5cd4393b FB |
4310 | } |
4311 | } | |
4312 | break; | |
31e31b8a | 4313 | case TARGET_NR_sched_setscheduler: |
5cd4393b | 4314 | { |
53a5960a | 4315 | struct sched_param *target_schp; |
5cd4393b | 4316 | struct sched_param schp; |
53a5960a | 4317 | lock_user_struct(target_schp, arg3, 1); |
5cd4393b | 4318 | schp.sched_priority = tswap32(target_schp->sched_priority); |
53a5960a | 4319 | unlock_user_struct(target_schp, arg3, 0); |
5cd4393b FB |
4320 | ret = get_errno(sched_setscheduler(arg1, arg2, &schp)); |
4321 | } | |
4322 | break; | |
31e31b8a | 4323 | case TARGET_NR_sched_getscheduler: |
5cd4393b FB |
4324 | ret = get_errno(sched_getscheduler(arg1)); |
4325 | break; | |
31e31b8a FB |
4326 | case TARGET_NR_sched_yield: |
4327 | ret = get_errno(sched_yield()); | |
4328 | break; | |
4329 | case TARGET_NR_sched_get_priority_max: | |
5cd4393b FB |
4330 | ret = get_errno(sched_get_priority_max(arg1)); |
4331 | break; | |
31e31b8a | 4332 | case TARGET_NR_sched_get_priority_min: |
5cd4393b FB |
4333 | ret = get_errno(sched_get_priority_min(arg1)); |
4334 | break; | |
31e31b8a | 4335 | case TARGET_NR_sched_rr_get_interval: |
5cd4393b | 4336 | { |
5cd4393b FB |
4337 | struct timespec ts; |
4338 | ret = get_errno(sched_rr_get_interval(arg1, &ts)); | |
4339 | if (!is_error(ret)) { | |
53a5960a | 4340 | host_to_target_timespec(arg2, &ts); |
5cd4393b FB |
4341 | } |
4342 | } | |
4343 | break; | |
31e31b8a | 4344 | case TARGET_NR_nanosleep: |
1b6b029e | 4345 | { |
1b6b029e | 4346 | struct timespec req, rem; |
53a5960a | 4347 | target_to_host_timespec(&req, arg1); |
1b6b029e | 4348 | ret = get_errno(nanosleep(&req, &rem)); |
53a5960a PB |
4349 | if (is_error(ret) && arg2) { |
4350 | host_to_target_timespec(arg2, &rem); | |
1b6b029e FB |
4351 | } |
4352 | } | |
4353 | break; | |
e5febef5 | 4354 | #ifdef TARGET_NR_query_module |
31e31b8a | 4355 | case TARGET_NR_query_module: |
5cd4393b | 4356 | goto unimplemented; |
e5febef5 TS |
4357 | #endif |
4358 | #ifdef TARGET_NR_nfsservctl | |
31e31b8a | 4359 | case TARGET_NR_nfsservctl: |
5cd4393b | 4360 | goto unimplemented; |
e5febef5 | 4361 | #endif |
31e31b8a | 4362 | case TARGET_NR_prctl: |
e5574487 TS |
4363 | switch (arg1) |
4364 | { | |
4365 | case PR_GET_PDEATHSIG: | |
4366 | { | |
4367 | int deathsig; | |
4368 | ret = get_errno(prctl(arg1, &deathsig, arg3, arg4, arg5)); | |
4369 | if (!is_error(ret) && arg2) | |
4370 | tput32(arg2, deathsig); | |
4371 | } | |
4372 | break; | |
4373 | default: | |
4374 | ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5)); | |
4375 | break; | |
4376 | } | |
39b9aae1 | 4377 | break; |
67867308 | 4378 | #ifdef TARGET_NR_pread |
31e31b8a | 4379 | case TARGET_NR_pread: |
53a5960a PB |
4380 | page_unprotect_range(arg2, arg3); |
4381 | p = lock_user(arg2, arg3, 0); | |
4382 | ret = get_errno(pread(arg1, p, arg3, arg4)); | |
4383 | unlock_user(p, arg2, ret); | |
206f0fa7 | 4384 | break; |
31e31b8a | 4385 | case TARGET_NR_pwrite: |
53a5960a PB |
4386 | p = lock_user(arg2, arg3, 1); |
4387 | ret = get_errno(pwrite(arg1, p, arg3, arg4)); | |
4388 | unlock_user(p, arg2, 0); | |
206f0fa7 | 4389 | break; |
67867308 | 4390 | #endif |
31e31b8a | 4391 | case TARGET_NR_getcwd: |
53a5960a PB |
4392 | p = lock_user(arg1, arg2, 0); |
4393 | ret = get_errno(sys_getcwd1(p, arg2)); | |
4394 | unlock_user(p, arg1, ret); | |
31e31b8a FB |
4395 | break; |
4396 | case TARGET_NR_capget: | |
5cd4393b | 4397 | goto unimplemented; |
31e31b8a | 4398 | case TARGET_NR_capset: |
5cd4393b | 4399 | goto unimplemented; |
31e31b8a | 4400 | case TARGET_NR_sigaltstack: |
198a74de TS |
4401 | #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \ |
4402 | defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA) | |
a04e134a TS |
4403 | ret = do_sigaltstack((struct target_sigaltstack *)arg1, |
4404 | (struct target_sigaltstack *)arg2, | |
4405 | get_sp_from_cpustate((CPUState *)cpu_env)); | |
4406 | break; | |
4407 | #else | |
5cd4393b | 4408 | goto unimplemented; |
a04e134a | 4409 | #endif |
31e31b8a | 4410 | case TARGET_NR_sendfile: |
5cd4393b | 4411 | goto unimplemented; |
ebc05488 | 4412 | #ifdef TARGET_NR_getpmsg |
31e31b8a | 4413 | case TARGET_NR_getpmsg: |
5cd4393b | 4414 | goto unimplemented; |
ebc05488 FB |
4415 | #endif |
4416 | #ifdef TARGET_NR_putpmsg | |
31e31b8a | 4417 | case TARGET_NR_putpmsg: |
5cd4393b | 4418 | goto unimplemented; |
ebc05488 | 4419 | #endif |
048f6b4d | 4420 | #ifdef TARGET_NR_vfork |
31e31b8a | 4421 | case TARGET_NR_vfork: |
1b6b029e | 4422 | ret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD, 0)); |
31e31b8a | 4423 | break; |
048f6b4d | 4424 | #endif |
ebc05488 | 4425 | #ifdef TARGET_NR_ugetrlimit |
31e31b8a | 4426 | case TARGET_NR_ugetrlimit: |
728584be FB |
4427 | { |
4428 | struct rlimit rlim; | |
4429 | ret = get_errno(getrlimit(arg1, &rlim)); | |
4430 | if (!is_error(ret)) { | |
53a5960a PB |
4431 | struct target_rlimit *target_rlim; |
4432 | lock_user_struct(target_rlim, arg2, 0); | |
728584be FB |
4433 | target_rlim->rlim_cur = tswapl(rlim.rlim_cur); |
4434 | target_rlim->rlim_max = tswapl(rlim.rlim_max); | |
53a5960a | 4435 | unlock_user_struct(target_rlim, arg2, 1); |
728584be FB |
4436 | } |
4437 | break; | |
4438 | } | |
ebc05488 | 4439 | #endif |
a315a145 | 4440 | #ifdef TARGET_NR_truncate64 |
31e31b8a | 4441 | case TARGET_NR_truncate64: |
53a5960a PB |
4442 | p = lock_user_string(arg1); |
4443 | ret = target_truncate64(cpu_env, p, arg2, arg3, arg4); | |
4444 | unlock_user(p, arg1, 0); | |
667f38b1 | 4445 | break; |
a315a145 FB |
4446 | #endif |
4447 | #ifdef TARGET_NR_ftruncate64 | |
31e31b8a | 4448 | case TARGET_NR_ftruncate64: |
ce4defa0 | 4449 | ret = target_ftruncate64(cpu_env, arg1, arg2, arg3, arg4); |
667f38b1 | 4450 | break; |
a315a145 FB |
4451 | #endif |
4452 | #ifdef TARGET_NR_stat64 | |
31e31b8a | 4453 | case TARGET_NR_stat64: |
53a5960a PB |
4454 | p = lock_user_string(arg1); |
4455 | ret = get_errno(stat(path(p), &st)); | |
4456 | unlock_user(p, arg1, 0); | |
60cd49d5 | 4457 | goto do_stat64; |
a315a145 FB |
4458 | #endif |
4459 | #ifdef TARGET_NR_lstat64 | |
31e31b8a | 4460 | case TARGET_NR_lstat64: |
53a5960a PB |
4461 | p = lock_user_string(arg1); |
4462 | ret = get_errno(lstat(path(p), &st)); | |
4463 | unlock_user(p, arg1, 0); | |
60cd49d5 | 4464 | goto do_stat64; |
a315a145 FB |
4465 | #endif |
4466 | #ifdef TARGET_NR_fstat64 | |
31e31b8a | 4467 | case TARGET_NR_fstat64: |
60cd49d5 FB |
4468 | { |
4469 | ret = get_errno(fstat(arg1, &st)); | |
4470 | do_stat64: | |
4471 | if (!is_error(ret)) { | |
ce4defa0 PB |
4472 | #ifdef TARGET_ARM |
4473 | if (((CPUARMState *)cpu_env)->eabi) { | |
53a5960a PB |
4474 | struct target_eabi_stat64 *target_st; |
4475 | lock_user_struct(target_st, arg2, 1); | |
ce4defa0 | 4476 | memset(target_st, 0, sizeof(struct target_eabi_stat64)); |
53a5960a | 4477 | /* put_user is probably wrong. */ |
ce4defa0 PB |
4478 | put_user(st.st_dev, &target_st->st_dev); |
4479 | put_user(st.st_ino, &target_st->st_ino); | |
4480 | #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO | |
4481 | put_user(st.st_ino, &target_st->__st_ino); | |
4482 | #endif | |
4483 | put_user(st.st_mode, &target_st->st_mode); | |
4484 | put_user(st.st_nlink, &target_st->st_nlink); | |
4485 | put_user(st.st_uid, &target_st->st_uid); | |
4486 | put_user(st.st_gid, &target_st->st_gid); | |
4487 | put_user(st.st_rdev, &target_st->st_rdev); | |
4488 | /* XXX: better use of kernel struct */ | |
4489 | put_user(st.st_size, &target_st->st_size); | |
4490 | put_user(st.st_blksize, &target_st->st_blksize); | |
4491 | put_user(st.st_blocks, &target_st->st_blocks); | |
4492 | put_user(st.st_atime, &target_st->target_st_atime); | |
4493 | put_user(st.st_mtime, &target_st->target_st_mtime); | |
4494 | put_user(st.st_ctime, &target_st->target_st_ctime); | |
53a5960a | 4495 | unlock_user_struct(target_st, arg2, 0); |
ce4defa0 PB |
4496 | } else |
4497 | #endif | |
4498 | { | |
53a5960a PB |
4499 | struct target_stat64 *target_st; |
4500 | lock_user_struct(target_st, arg2, 1); | |
ce4defa0 | 4501 | memset(target_st, 0, sizeof(struct target_stat64)); |
53a5960a | 4502 | /* ??? put_user is probably wrong. */ |
ce4defa0 PB |
4503 | put_user(st.st_dev, &target_st->st_dev); |
4504 | put_user(st.st_ino, &target_st->st_ino); | |
ec86b0fb | 4505 | #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO |
ce4defa0 PB |
4506 | put_user(st.st_ino, &target_st->__st_ino); |
4507 | #endif | |
4508 | put_user(st.st_mode, &target_st->st_mode); | |
4509 | put_user(st.st_nlink, &target_st->st_nlink); | |
4510 | put_user(st.st_uid, &target_st->st_uid); | |
4511 | put_user(st.st_gid, &target_st->st_gid); | |
4512 | put_user(st.st_rdev, &target_st->st_rdev); | |
4513 | /* XXX: better use of kernel struct */ | |
4514 | put_user(st.st_size, &target_st->st_size); | |
4515 | put_user(st.st_blksize, &target_st->st_blksize); | |
4516 | put_user(st.st_blocks, &target_st->st_blocks); | |
4517 | put_user(st.st_atime, &target_st->target_st_atime); | |
4518 | put_user(st.st_mtime, &target_st->target_st_mtime); | |
4519 | put_user(st.st_ctime, &target_st->target_st_ctime); | |
53a5960a | 4520 | unlock_user_struct(target_st, arg2, 0); |
ce4defa0 | 4521 | } |
60cd49d5 FB |
4522 | } |
4523 | } | |
4524 | break; | |
a315a145 | 4525 | #endif |
67867308 FB |
4526 | #ifdef USE_UID16 |
4527 | case TARGET_NR_lchown: | |
53a5960a PB |
4528 | p = lock_user_string(arg1); |
4529 | ret = get_errno(lchown(p, low2highuid(arg2), low2highgid(arg3))); | |
4530 | unlock_user(p, arg1, 0); | |
67867308 FB |
4531 | break; |
4532 | case TARGET_NR_getuid: | |
4533 | ret = get_errno(high2lowuid(getuid())); | |
4534 | break; | |
4535 | case TARGET_NR_getgid: | |
4536 | ret = get_errno(high2lowgid(getgid())); | |
4537 | break; | |
4538 | case TARGET_NR_geteuid: | |
4539 | ret = get_errno(high2lowuid(geteuid())); | |
4540 | break; | |
4541 | case TARGET_NR_getegid: | |
4542 | ret = get_errno(high2lowgid(getegid())); | |
4543 | break; | |
4544 | case TARGET_NR_setreuid: | |
4545 | ret = get_errno(setreuid(low2highuid(arg1), low2highuid(arg2))); | |
4546 | break; | |
4547 | case TARGET_NR_setregid: | |
4548 | ret = get_errno(setregid(low2highgid(arg1), low2highgid(arg2))); | |
4549 | break; | |
4550 | case TARGET_NR_getgroups: | |
4551 | { | |
4552 | int gidsetsize = arg1; | |
53a5960a | 4553 | uint16_t *target_grouplist; |
67867308 FB |
4554 | gid_t *grouplist; |
4555 | int i; | |
4556 | ||
4557 | grouplist = alloca(gidsetsize * sizeof(gid_t)); | |
4558 | ret = get_errno(getgroups(gidsetsize, grouplist)); | |
4559 | if (!is_error(ret)) { | |
53a5960a | 4560 | target_grouplist = lock_user(arg2, gidsetsize * 2, 0); |
67867308 FB |
4561 | for(i = 0;i < gidsetsize; i++) |
4562 | target_grouplist[i] = tswap16(grouplist[i]); | |
53a5960a | 4563 | unlock_user(target_grouplist, arg2, gidsetsize * 2); |
67867308 FB |
4564 | } |
4565 | } | |
4566 | break; | |
4567 | case TARGET_NR_setgroups: | |
4568 | { | |
4569 | int gidsetsize = arg1; | |
53a5960a | 4570 | uint16_t *target_grouplist; |
67867308 FB |
4571 | gid_t *grouplist; |
4572 | int i; | |
4573 | ||
4574 | grouplist = alloca(gidsetsize * sizeof(gid_t)); | |
53a5960a | 4575 | target_grouplist = lock_user(arg2, gidsetsize * 2, 1); |
67867308 FB |
4576 | for(i = 0;i < gidsetsize; i++) |
4577 | grouplist[i] = tswap16(target_grouplist[i]); | |
53a5960a | 4578 | unlock_user(target_grouplist, arg2, 0); |
67867308 FB |
4579 | ret = get_errno(setgroups(gidsetsize, grouplist)); |
4580 | } | |
4581 | break; | |
4582 | case TARGET_NR_fchown: | |
4583 | ret = get_errno(fchown(arg1, low2highuid(arg2), low2highgid(arg3))); | |
4584 | break; | |
ccfa72b7 TS |
4585 | #if defined(TARGET_NR_fchownat) && defined(__NR_fchownat) |
4586 | case TARGET_NR_fchownat: | |
4587 | if (!arg2) { | |
0da46a6e | 4588 | ret = -TARGET_EFAULT; |
ccfa72b7 TS |
4589 | goto fail; |
4590 | } | |
4591 | p = lock_user_string(arg2); | |
4592 | if (!access_ok(VERIFY_READ, p, 1)) | |
0da46a6e TS |
4593 | /* Don't "goto fail" so that cleanup can happen. */ |
4594 | ret = -TARGET_EFAULT; | |
ccfa72b7 TS |
4595 | else |
4596 | ret = get_errno(sys_fchownat(arg1, p, low2highuid(arg3), low2highgid(arg4), arg5)); | |
4597 | if (p) | |
4598 | unlock_user(p, arg2, 0); | |
4599 | break; | |
4600 | #endif | |
67867308 FB |
4601 | #ifdef TARGET_NR_setresuid |
4602 | case TARGET_NR_setresuid: | |
5fafdf24 TS |
4603 | ret = get_errno(setresuid(low2highuid(arg1), |
4604 | low2highuid(arg2), | |
67867308 FB |
4605 | low2highuid(arg3))); |
4606 | break; | |
4607 | #endif | |
4608 | #ifdef TARGET_NR_getresuid | |
4609 | case TARGET_NR_getresuid: | |
4610 | { | |
53a5960a | 4611 | uid_t ruid, euid, suid; |
67867308 FB |
4612 | ret = get_errno(getresuid(&ruid, &euid, &suid)); |
4613 | if (!is_error(ret)) { | |
53a5960a PB |
4614 | tput16(arg1, tswap16(high2lowuid(ruid))); |
4615 | tput16(arg2, tswap16(high2lowuid(euid))); | |
4616 | tput16(arg3, tswap16(high2lowuid(suid))); | |
67867308 FB |
4617 | } |
4618 | } | |
4619 | break; | |
4620 | #endif | |
4621 | #ifdef TARGET_NR_getresgid | |
4622 | case TARGET_NR_setresgid: | |
5fafdf24 TS |
4623 | ret = get_errno(setresgid(low2highgid(arg1), |
4624 | low2highgid(arg2), | |
67867308 FB |
4625 | low2highgid(arg3))); |
4626 | break; | |
4627 | #endif | |
4628 | #ifdef TARGET_NR_getresgid | |
4629 | case TARGET_NR_getresgid: | |
4630 | { | |
53a5960a | 4631 | gid_t rgid, egid, sgid; |
67867308 FB |
4632 | ret = get_errno(getresgid(&rgid, &egid, &sgid)); |
4633 | if (!is_error(ret)) { | |
53a5960a PB |
4634 | tput16(arg1, tswap16(high2lowgid(rgid))); |
4635 | tput16(arg2, tswap16(high2lowgid(egid))); | |
4636 | tput16(arg3, tswap16(high2lowgid(sgid))); | |
67867308 FB |
4637 | } |
4638 | } | |
4639 | break; | |
4640 | #endif | |
4641 | case TARGET_NR_chown: | |
53a5960a PB |
4642 | p = lock_user_string(arg1); |
4643 | ret = get_errno(chown(p, low2highuid(arg2), low2highgid(arg3))); | |
4644 | unlock_user(p, arg1, 0); | |
67867308 FB |
4645 | break; |
4646 | case TARGET_NR_setuid: | |
4647 | ret = get_errno(setuid(low2highuid(arg1))); | |
4648 | break; | |
4649 | case TARGET_NR_setgid: | |
4650 | ret = get_errno(setgid(low2highgid(arg1))); | |
4651 | break; | |
4652 | case TARGET_NR_setfsuid: | |
4653 | ret = get_errno(setfsuid(arg1)); | |
4654 | break; | |
4655 | case TARGET_NR_setfsgid: | |
4656 | ret = get_errno(setfsgid(arg1)); | |
4657 | break; | |
4658 | #endif /* USE_UID16 */ | |
4659 | ||
a315a145 | 4660 | #ifdef TARGET_NR_lchown32 |
31e31b8a | 4661 | case TARGET_NR_lchown32: |
53a5960a PB |
4662 | p = lock_user_string(arg1); |
4663 | ret = get_errno(lchown(p, arg2, arg3)); | |
4664 | unlock_user(p, arg1, 0); | |
b03c60f3 | 4665 | break; |
a315a145 FB |
4666 | #endif |
4667 | #ifdef TARGET_NR_getuid32 | |
31e31b8a | 4668 | case TARGET_NR_getuid32: |
b03c60f3 FB |
4669 | ret = get_errno(getuid()); |
4670 | break; | |
a315a145 FB |
4671 | #endif |
4672 | #ifdef TARGET_NR_getgid32 | |
31e31b8a | 4673 | case TARGET_NR_getgid32: |
b03c60f3 FB |
4674 | ret = get_errno(getgid()); |
4675 | break; | |
a315a145 FB |
4676 | #endif |
4677 | #ifdef TARGET_NR_geteuid32 | |
31e31b8a | 4678 | case TARGET_NR_geteuid32: |
b03c60f3 FB |
4679 | ret = get_errno(geteuid()); |
4680 | break; | |
a315a145 FB |
4681 | #endif |
4682 | #ifdef TARGET_NR_getegid32 | |
31e31b8a | 4683 | case TARGET_NR_getegid32: |
b03c60f3 FB |
4684 | ret = get_errno(getegid()); |
4685 | break; | |
a315a145 FB |
4686 | #endif |
4687 | #ifdef TARGET_NR_setreuid32 | |
31e31b8a | 4688 | case TARGET_NR_setreuid32: |
b03c60f3 FB |
4689 | ret = get_errno(setreuid(arg1, arg2)); |
4690 | break; | |
a315a145 FB |
4691 | #endif |
4692 | #ifdef TARGET_NR_setregid32 | |
31e31b8a | 4693 | case TARGET_NR_setregid32: |
b03c60f3 FB |
4694 | ret = get_errno(setregid(arg1, arg2)); |
4695 | break; | |
a315a145 FB |
4696 | #endif |
4697 | #ifdef TARGET_NR_getgroups32 | |
31e31b8a | 4698 | case TARGET_NR_getgroups32: |
99c475ab FB |
4699 | { |
4700 | int gidsetsize = arg1; | |
53a5960a | 4701 | uint32_t *target_grouplist; |
99c475ab FB |
4702 | gid_t *grouplist; |
4703 | int i; | |
4704 | ||
4705 | grouplist = alloca(gidsetsize * sizeof(gid_t)); | |
4706 | ret = get_errno(getgroups(gidsetsize, grouplist)); | |
4707 | if (!is_error(ret)) { | |
53a5960a | 4708 | target_grouplist = lock_user(arg2, gidsetsize * 4, 0); |
99c475ab | 4709 | for(i = 0;i < gidsetsize; i++) |
53a5960a PB |
4710 | target_grouplist[i] = tswap32(grouplist[i]); |
4711 | unlock_user(target_grouplist, arg2, gidsetsize * 4); | |
99c475ab FB |
4712 | } |
4713 | } | |
4714 | break; | |
a315a145 FB |
4715 | #endif |
4716 | #ifdef TARGET_NR_setgroups32 | |
31e31b8a | 4717 | case TARGET_NR_setgroups32: |
99c475ab FB |
4718 | { |
4719 | int gidsetsize = arg1; | |
53a5960a | 4720 | uint32_t *target_grouplist; |
99c475ab FB |
4721 | gid_t *grouplist; |
4722 | int i; | |
3b46e624 | 4723 | |
99c475ab | 4724 | grouplist = alloca(gidsetsize * sizeof(gid_t)); |
53a5960a | 4725 | target_grouplist = lock_user(arg2, gidsetsize * 4, 1); |
99c475ab | 4726 | for(i = 0;i < gidsetsize; i++) |
53a5960a PB |
4727 | grouplist[i] = tswap32(target_grouplist[i]); |
4728 | unlock_user(target_grouplist, arg2, 0); | |
99c475ab FB |
4729 | ret = get_errno(setgroups(gidsetsize, grouplist)); |
4730 | } | |
4731 | break; | |
a315a145 FB |
4732 | #endif |
4733 | #ifdef TARGET_NR_fchown32 | |
31e31b8a | 4734 | case TARGET_NR_fchown32: |
b03c60f3 FB |
4735 | ret = get_errno(fchown(arg1, arg2, arg3)); |
4736 | break; | |
a315a145 FB |
4737 | #endif |
4738 | #ifdef TARGET_NR_setresuid32 | |
31e31b8a | 4739 | case TARGET_NR_setresuid32: |
b03c60f3 FB |
4740 | ret = get_errno(setresuid(arg1, arg2, arg3)); |
4741 | break; | |
a315a145 FB |
4742 | #endif |
4743 | #ifdef TARGET_NR_getresuid32 | |
31e31b8a | 4744 | case TARGET_NR_getresuid32: |
b03c60f3 | 4745 | { |
53a5960a | 4746 | uid_t ruid, euid, suid; |
b03c60f3 FB |
4747 | ret = get_errno(getresuid(&ruid, &euid, &suid)); |
4748 | if (!is_error(ret)) { | |
53a5960a PB |
4749 | tput32(arg1, tswap32(ruid)); |
4750 | tput32(arg2, tswap32(euid)); | |
4751 | tput32(arg3, tswap32(suid)); | |
b03c60f3 FB |
4752 | } |
4753 | } | |
4754 | break; | |
a315a145 FB |
4755 | #endif |
4756 | #ifdef TARGET_NR_setresgid32 | |
31e31b8a | 4757 | case TARGET_NR_setresgid32: |
b03c60f3 FB |
4758 | ret = get_errno(setresgid(arg1, arg2, arg3)); |
4759 | break; | |
a315a145 FB |
4760 | #endif |
4761 | #ifdef TARGET_NR_getresgid32 | |
31e31b8a | 4762 | case TARGET_NR_getresgid32: |
b03c60f3 | 4763 | { |
53a5960a | 4764 | gid_t rgid, egid, sgid; |
b03c60f3 FB |
4765 | ret = get_errno(getresgid(&rgid, &egid, &sgid)); |
4766 | if (!is_error(ret)) { | |
53a5960a PB |
4767 | tput32(arg1, tswap32(rgid)); |
4768 | tput32(arg2, tswap32(egid)); | |
4769 | tput32(arg3, tswap32(sgid)); | |
b03c60f3 FB |
4770 | } |
4771 | } | |
4772 | break; | |
a315a145 FB |
4773 | #endif |
4774 | #ifdef TARGET_NR_chown32 | |
31e31b8a | 4775 | case TARGET_NR_chown32: |
53a5960a PB |
4776 | p = lock_user_string(arg1); |
4777 | ret = get_errno(chown(p, arg2, arg3)); | |
4778 | unlock_user(p, arg1, 0); | |
b03c60f3 | 4779 | break; |
a315a145 FB |
4780 | #endif |
4781 | #ifdef TARGET_NR_setuid32 | |
31e31b8a | 4782 | case TARGET_NR_setuid32: |
b03c60f3 FB |
4783 | ret = get_errno(setuid(arg1)); |
4784 | break; | |
a315a145 FB |
4785 | #endif |
4786 | #ifdef TARGET_NR_setgid32 | |
31e31b8a | 4787 | case TARGET_NR_setgid32: |
b03c60f3 FB |
4788 | ret = get_errno(setgid(arg1)); |
4789 | break; | |
a315a145 FB |
4790 | #endif |
4791 | #ifdef TARGET_NR_setfsuid32 | |
31e31b8a | 4792 | case TARGET_NR_setfsuid32: |
b03c60f3 FB |
4793 | ret = get_errno(setfsuid(arg1)); |
4794 | break; | |
a315a145 FB |
4795 | #endif |
4796 | #ifdef TARGET_NR_setfsgid32 | |
31e31b8a | 4797 | case TARGET_NR_setfsgid32: |
b03c60f3 FB |
4798 | ret = get_errno(setfsgid(arg1)); |
4799 | break; | |
a315a145 | 4800 | #endif |
67867308 | 4801 | |
31e31b8a | 4802 | case TARGET_NR_pivot_root: |
b03c60f3 | 4803 | goto unimplemented; |
ffa65c3b | 4804 | #ifdef TARGET_NR_mincore |
31e31b8a | 4805 | case TARGET_NR_mincore: |
b03c60f3 | 4806 | goto unimplemented; |
ffa65c3b FB |
4807 | #endif |
4808 | #ifdef TARGET_NR_madvise | |
31e31b8a | 4809 | case TARGET_NR_madvise: |
24836689 PB |
4810 | /* A straight passthrough may not be safe because qemu sometimes |
4811 | turns private flie-backed mappings into anonymous mappings. | |
4812 | This will break MADV_DONTNEED. | |
4813 | This is a hint, so ignoring and returning success is ok. */ | |
4814 | ret = get_errno(0); | |
4815 | break; | |
ffa65c3b | 4816 | #endif |
992f48a0 | 4817 | #if TARGET_ABI_BITS == 32 |
31e31b8a | 4818 | case TARGET_NR_fcntl64: |
77e4672d | 4819 | { |
b1e341eb | 4820 | int cmd; |
77e4672d | 4821 | struct flock64 fl; |
53a5960a | 4822 | struct target_flock64 *target_fl; |
ce4defa0 | 4823 | #ifdef TARGET_ARM |
53a5960a | 4824 | struct target_eabi_flock64 *target_efl; |
ce4defa0 | 4825 | #endif |
77e4672d | 4826 | |
b1e341eb TS |
4827 | switch(arg2){ |
4828 | case TARGET_F_GETLK64: | |
4829 | cmd = F_GETLK64; | |
a7222580 | 4830 | break; |
b1e341eb TS |
4831 | case TARGET_F_SETLK64: |
4832 | cmd = F_SETLK64; | |
a7222580 | 4833 | break; |
b1e341eb TS |
4834 | case TARGET_F_SETLKW64: |
4835 | cmd = F_SETLK64; | |
a7222580 | 4836 | break; |
b1e341eb TS |
4837 | default: |
4838 | cmd = arg2; | |
a7222580 | 4839 | break; |
b1e341eb TS |
4840 | } |
4841 | ||
60cd49d5 | 4842 | switch(arg2) { |
b1e341eb | 4843 | case TARGET_F_GETLK64: |
5813427b TS |
4844 | #ifdef TARGET_ARM |
4845 | if (((CPUARMState *)cpu_env)->eabi) { | |
4846 | lock_user_struct(target_efl, arg3, 1); | |
4847 | fl.l_type = tswap16(target_efl->l_type); | |
4848 | fl.l_whence = tswap16(target_efl->l_whence); | |
4849 | fl.l_start = tswap64(target_efl->l_start); | |
4850 | fl.l_len = tswap64(target_efl->l_len); | |
4851 | fl.l_pid = tswapl(target_efl->l_pid); | |
4852 | unlock_user_struct(target_efl, arg3, 0); | |
4853 | } else | |
4854 | #endif | |
4855 | { | |
4856 | lock_user_struct(target_fl, arg3, 1); | |
4857 | fl.l_type = tswap16(target_fl->l_type); | |
4858 | fl.l_whence = tswap16(target_fl->l_whence); | |
4859 | fl.l_start = tswap64(target_fl->l_start); | |
4860 | fl.l_len = tswap64(target_fl->l_len); | |
4861 | fl.l_pid = tswapl(target_fl->l_pid); | |
4862 | unlock_user_struct(target_fl, arg3, 0); | |
4863 | } | |
b1e341eb | 4864 | ret = get_errno(fcntl(arg1, cmd, &fl)); |
77e4672d | 4865 | if (ret == 0) { |
ce4defa0 PB |
4866 | #ifdef TARGET_ARM |
4867 | if (((CPUARMState *)cpu_env)->eabi) { | |
53a5960a | 4868 | lock_user_struct(target_efl, arg3, 0); |
ce4defa0 PB |
4869 | target_efl->l_type = tswap16(fl.l_type); |
4870 | target_efl->l_whence = tswap16(fl.l_whence); | |
4871 | target_efl->l_start = tswap64(fl.l_start); | |
4872 | target_efl->l_len = tswap64(fl.l_len); | |
4873 | target_efl->l_pid = tswapl(fl.l_pid); | |
53a5960a | 4874 | unlock_user_struct(target_efl, arg3, 1); |
ce4defa0 PB |
4875 | } else |
4876 | #endif | |
4877 | { | |
53a5960a | 4878 | lock_user_struct(target_fl, arg3, 0); |
ce4defa0 PB |
4879 | target_fl->l_type = tswap16(fl.l_type); |
4880 | target_fl->l_whence = tswap16(fl.l_whence); | |
4881 | target_fl->l_start = tswap64(fl.l_start); | |
4882 | target_fl->l_len = tswap64(fl.l_len); | |
4883 | target_fl->l_pid = tswapl(fl.l_pid); | |
53a5960a | 4884 | unlock_user_struct(target_fl, arg3, 1); |
ce4defa0 | 4885 | } |
77e4672d FB |
4886 | } |
4887 | break; | |
4888 | ||
b1e341eb TS |
4889 | case TARGET_F_SETLK64: |
4890 | case TARGET_F_SETLKW64: | |
ce4defa0 PB |
4891 | #ifdef TARGET_ARM |
4892 | if (((CPUARMState *)cpu_env)->eabi) { | |
53a5960a | 4893 | lock_user_struct(target_efl, arg3, 1); |
ce4defa0 PB |
4894 | fl.l_type = tswap16(target_efl->l_type); |
4895 | fl.l_whence = tswap16(target_efl->l_whence); | |
4896 | fl.l_start = tswap64(target_efl->l_start); | |
4897 | fl.l_len = tswap64(target_efl->l_len); | |
4898 | fl.l_pid = tswapl(target_efl->l_pid); | |
53a5960a | 4899 | unlock_user_struct(target_efl, arg3, 0); |
ce4defa0 PB |
4900 | } else |
4901 | #endif | |
4902 | { | |
53a5960a | 4903 | lock_user_struct(target_fl, arg3, 1); |
ce4defa0 PB |
4904 | fl.l_type = tswap16(target_fl->l_type); |
4905 | fl.l_whence = tswap16(target_fl->l_whence); | |
4906 | fl.l_start = tswap64(target_fl->l_start); | |
4907 | fl.l_len = tswap64(target_fl->l_len); | |
4908 | fl.l_pid = tswapl(target_fl->l_pid); | |
53a5960a | 4909 | unlock_user_struct(target_fl, arg3, 0); |
ce4defa0 | 4910 | } |
b1e341eb | 4911 | ret = get_errno(fcntl(arg1, cmd, &fl)); |
77e4672d | 4912 | break; |
60cd49d5 | 4913 | default: |
b1e341eb | 4914 | ret = get_errno(do_fcntl(arg1, cmd, arg3)); |
60cd49d5 FB |
4915 | break; |
4916 | } | |
77e4672d FB |
4917 | break; |
4918 | } | |
60cd49d5 | 4919 | #endif |
7d600c80 TS |
4920 | #ifdef TARGET_NR_cacheflush |
4921 | case TARGET_NR_cacheflush: | |
4922 | /* self-modifying code is handled automatically, so nothing needed */ | |
4923 | ret = 0; | |
4924 | break; | |
4925 | #endif | |
ebc05488 | 4926 | #ifdef TARGET_NR_security |
31e31b8a FB |
4927 | case TARGET_NR_security: |
4928 | goto unimplemented; | |
c573ff67 FB |
4929 | #endif |
4930 | #ifdef TARGET_NR_getpagesize | |
4931 | case TARGET_NR_getpagesize: | |
4932 | ret = TARGET_PAGE_SIZE; | |
4933 | break; | |
ebc05488 | 4934 | #endif |
31e31b8a FB |
4935 | case TARGET_NR_gettid: |
4936 | ret = get_errno(gettid()); | |
4937 | break; | |
e5febef5 | 4938 | #ifdef TARGET_NR_readahead |
31e31b8a | 4939 | case TARGET_NR_readahead: |
5cd4393b | 4940 | goto unimplemented; |
e5febef5 | 4941 | #endif |
ebc05488 | 4942 | #ifdef TARGET_NR_setxattr |
31e31b8a FB |
4943 | case TARGET_NR_setxattr: |
4944 | case TARGET_NR_lsetxattr: | |
4945 | case TARGET_NR_fsetxattr: | |
4946 | case TARGET_NR_getxattr: | |
4947 | case TARGET_NR_lgetxattr: | |
4948 | case TARGET_NR_fgetxattr: | |
4949 | case TARGET_NR_listxattr: | |
4950 | case TARGET_NR_llistxattr: | |
4951 | case TARGET_NR_flistxattr: | |
4952 | case TARGET_NR_removexattr: | |
4953 | case TARGET_NR_lremovexattr: | |
4954 | case TARGET_NR_fremovexattr: | |
5cd4393b | 4955 | goto unimplemented_nowarn; |
ebc05488 FB |
4956 | #endif |
4957 | #ifdef TARGET_NR_set_thread_area | |
5cd4393b | 4958 | case TARGET_NR_set_thread_area: |
6f5b89a0 TS |
4959 | #ifdef TARGET_MIPS |
4960 | ((CPUMIPSState *) cpu_env)->tls_value = arg1; | |
4961 | ret = 0; | |
4962 | break; | |
4963 | #else | |
4964 | goto unimplemented_nowarn; | |
4965 | #endif | |
4966 | #endif | |
4967 | #ifdef TARGET_NR_get_thread_area | |
5cd4393b FB |
4968 | case TARGET_NR_get_thread_area: |
4969 | goto unimplemented_nowarn; | |
48dc41eb FB |
4970 | #endif |
4971 | #ifdef TARGET_NR_getdomainname | |
4972 | case TARGET_NR_getdomainname: | |
4973 | goto unimplemented_nowarn; | |
ebc05488 | 4974 | #endif |
6f5b89a0 | 4975 | |
b5906f95 TS |
4976 | #ifdef TARGET_NR_clock_gettime |
4977 | case TARGET_NR_clock_gettime: | |
4978 | { | |
4979 | struct timespec ts; | |
4980 | ret = get_errno(clock_gettime(arg1, &ts)); | |
4981 | if (!is_error(ret)) { | |
4982 | host_to_target_timespec(arg2, &ts); | |
4983 | } | |
4984 | break; | |
4985 | } | |
4986 | #endif | |
4987 | #ifdef TARGET_NR_clock_getres | |
4988 | case TARGET_NR_clock_getres: | |
4989 | { | |
4990 | struct timespec ts; | |
4991 | ret = get_errno(clock_getres(arg1, &ts)); | |
4992 | if (!is_error(ret)) { | |
4993 | host_to_target_timespec(arg2, &ts); | |
4994 | } | |
4995 | break; | |
4996 | } | |
4997 | #endif | |
4998 | ||
6f5b89a0 TS |
4999 | #if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address) |
5000 | case TARGET_NR_set_tid_address: | |
5001 | ret = get_errno(set_tid_address((int *) arg1)); | |
5002 | break; | |
5003 | #endif | |
5004 | ||
3ae43202 | 5005 | #if defined(TARGET_NR_tkill) && defined(__NR_tkill) |
4cae1d16 TS |
5006 | case TARGET_NR_tkill: |
5007 | ret = get_errno(sys_tkill((int)arg1, (int)arg2)); | |
5008 | break; | |
5009 | #endif | |
5010 | ||
3ae43202 | 5011 | #if defined(TARGET_NR_tgkill) && defined(__NR_tgkill) |
71455574 TS |
5012 | case TARGET_NR_tgkill: |
5013 | ret = get_errno(sys_tgkill((int)arg1, (int)arg2, (int)arg3)); | |
5014 | break; | |
5015 | #endif | |
5016 | ||
4f2b1fe8 TS |
5017 | #ifdef TARGET_NR_set_robust_list |
5018 | case TARGET_NR_set_robust_list: | |
5019 | goto unimplemented_nowarn; | |
5020 | #endif | |
5021 | ||
9007f0ef TS |
5022 | #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat) |
5023 | case TARGET_NR_utimensat: | |
5024 | { | |
5025 | struct timespec ts[2]; | |
5026 | target_to_host_timespec(ts, arg3); | |
5027 | target_to_host_timespec(ts+1, arg3+sizeof(struct target_timespec)); | |
5028 | if (!arg2) | |
5029 | ret = get_errno(sys_utimensat(arg1, NULL, ts, arg4)); | |
5030 | else { | |
5031 | p = lock_user_string(arg2); | |
5032 | if (!access_ok(VERIFY_READ, p, 1)) | |
0da46a6e TS |
5033 | /* Don't "goto fail" so that cleanup can happen. */ |
5034 | ret = -TARGET_EFAULT; | |
9007f0ef TS |
5035 | else |
5036 | ret = get_errno(sys_utimensat(arg1, path(p), ts, arg4)); | |
5037 | if (p) | |
5038 | unlock_user(p, arg2, 0); | |
5039 | } | |
5040 | } | |
5041 | break; | |
5042 | #endif | |
5043 | ||
31e31b8a FB |
5044 | default: |
5045 | unimplemented: | |
5cd4393b | 5046 | gemu_log("qemu: Unsupported syscall: %d\n", num); |
4f2b1fe8 | 5047 | #if defined(TARGET_NR_setxattr) || defined(TARGET_NR_get_thread_area) || defined(TARGET_NR_getdomainname) || defined(TARGET_NR_set_robust_list) |
5cd4393b | 5048 | unimplemented_nowarn: |
80a9d035 | 5049 | #endif |
0da46a6e | 5050 | ret = -TARGET_ENOSYS; |
31e31b8a FB |
5051 | break; |
5052 | } | |
5053 | fail: | |
c573ff67 FB |
5054 | #ifdef DEBUG |
5055 | gemu_log(" = %ld\n", ret); | |
5056 | #endif | |
b92c47c1 TS |
5057 | if(do_strace) |
5058 | print_syscall_ret(num, ret); | |
31e31b8a FB |
5059 | return ret; |
5060 | } |