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