Bug Summary

File:linux-user/syscall.c
Location:line 4445, column 9
Description:Value stored to 'ret' is never read

Annotated Source Code

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, see <http://www.gnu.org/licenses/>.
18 */
19#define _ATFILE_SOURCE1
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(*__errno_location ()).h>
27#include <unistd.h>
28#include <fcntl.h>
29#include <time.h>
30#include <limits.h>
31#include <grp.h>
32#include <sys/types.h>
33#include <sys/ipc.h>
34#include <sys/msg.h>
35#include <sys/wait.h>
36#include <sys/time.h>
37#include <sys/stat.h>
38#include <sys/mount.h>
39#include <sys/file.h>
40#include <sys/fsuid.h>
41#include <sys/personality.h>
42#include <sys/prctl.h>
43#include <sys/resource.h>
44#include <sys/mman.h>
45#include <sys/swap.h>
46#include <signal.h>
47#include <sched.h>
48#ifdef __ia64__
49int __clone2(int (*fn)(void *), void *child_stack_base,
50 size_t stack_size, int flags, void *arg, ...);
51#endif
52#include <sys/socket.h>
53#include <sys/un.h>
54#include <sys/uio.h>
55#include <sys/poll.h>
56#include <sys/times.h>
57#include <sys/shm.h>
58#include <sys/sem.h>
59#include <sys/statfs.h>
60#include <utime.h>
61#include <sys/sysinfo.h>
62#include <sys/utsname.h>
63//#include <sys/user.h>
64#include <netinet/ip.h>
65#include <netinet/tcp.h>
66#include <linux1/wireless.h>
67#include <linux1/icmp.h>
68#include "qemu-common.h"
69#ifdef TARGET_GPROF
70#include <sys/gmon.h>
71#endif
72#ifdef CONFIG_EVENTFD1
73#include <sys/eventfd.h>
74#endif
75#ifdef CONFIG_EPOLL1
76#include <sys/epoll.h>
77#endif
78#ifdef CONFIG_ATTR1
79#include "qemu/xattr.h"
80#endif
81#ifdef CONFIG_SENDFILE1
82#include <sys/sendfile.h>
83#endif
84
85#define termioshost_termios host_termios
86#define winsizehost_winsize host_winsize
87#define termiohost_termio host_termio
88#define sgttybhost_sgttyb host_sgttyb /* same as target */
89#define tcharshost_tchars host_tchars /* same as target */
90#define ltcharshost_ltchars host_ltchars /* same as target */
91
92#include <linux1/termioshost_termios.h>
93#include <linux1/unistd.h>
94#include <linux1/utsname.h>
95#include <linux1/cdrom.h>
96#include <linux1/hdreg.h>
97#include <linux1/soundcard.h>
98#include <linux1/kd.h>
99#include <linux1/mtio.h>
100#include <linux1/fs.h>
101#if defined(CONFIG_FIEMAP1)
102#include <linux1/fiemap.h>
103#endif
104#include <linux1/fb.h>
105#include <linux1/vt.h>
106#include <linux1/dm-ioctl.h>
107#include <linux1/reboot.h>
108#include <linux1/route.h>
109#include <linux1/filter.h>
110#include "linux_loop.h"
111#include "cpu-uname.h"
112
113#include "qemu.h"
114
115#define CLONE_NPTL_FLAGS2(0x00080000 | 0x00100000 | 0x01000000 | 0x00200000) (CLONE_SETTLS0x00080000 | \
116 CLONE_PARENT_SETTID0x00100000 | CLONE_CHILD_SETTID0x01000000 | CLONE_CHILD_CLEARTID0x00200000)
117
118//#define DEBUG
119
120//#include <linux/msdos_fs.h>
121#define VFAT_IOCTL_READDIR_BOTH(((2U) << (((0 +8)+8)+14)) | ((('r')) << (0 +8)) |
(((1)) << 0) | ((((sizeof(struct linux_dirent [2])))) <<
((0 +8)+8)))
_IOR('r', 1, struct linux_dirent [2])(((2U) << (((0 +8)+8)+14)) | ((('r')) << (0 +8)) |
(((1)) << 0) | ((((sizeof(struct linux_dirent [2])))) <<
((0 +8)+8)))
122#define VFAT_IOCTL_READDIR_SHORT(((2U) << (((0 +8)+8)+14)) | ((('r')) << (0 +8)) |
(((2)) << 0) | ((((sizeof(struct linux_dirent [2])))) <<
((0 +8)+8)))
_IOR('r', 2, struct linux_dirent [2])(((2U) << (((0 +8)+8)+14)) | ((('r')) << (0 +8)) |
(((2)) << 0) | ((((sizeof(struct linux_dirent [2])))) <<
((0 +8)+8)))
123
124
125#undef _syscall0
126#undef _syscall1
127#undef _syscall2
128#undef _syscall3
129#undef _syscall4
130#undef _syscall5
131#undef _syscall6
132
133#define _syscall0(type,name)static type name (void) { return syscall(__NR_name); } \
134static type name (void) \
135{ \
136 return syscall(__NR_##name); \
137}
138
139#define _syscall1(type,name,type1,arg1)static type name (type1 arg1) { return syscall(__NR_name, arg1
); }
\
140static type name (type1 arg1) \
141{ \
142 return syscall(__NR_##name, arg1); \
143}
144
145#define _syscall2(type,name,type1,arg1,type2,arg2)static type name (type1 arg1,type2 arg2) { return syscall(__NR_name
, arg1, arg2); }
\
146static type name (type1 arg1,type2 arg2) \
147{ \
148 return syscall(__NR_##name, arg1, arg2); \
149}
150
151#define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3)static type name (type1 arg1,type2 arg2,type3 arg3) { return syscall
(__NR_name, arg1, arg2, arg3); }
\
152static type name (type1 arg1,type2 arg2,type3 arg3) \
153{ \
154 return syscall(__NR_##name, arg1, arg2, arg3); \
155}
156
157#define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4)static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4
) { return syscall(__NR_name, arg1, arg2, arg3, arg4); }
\
158static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4) \
159{ \
160 return syscall(__NR_##name, arg1, arg2, arg3, arg4); \
161}
162
163#define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4
,type5 arg5) { return syscall(__NR_name, arg1, arg2, arg3, arg4
, arg5); }
164 type5,arg5)static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4
,type5 arg5) { return syscall(__NR_name, arg1, arg2, arg3, arg4
, arg5); }
\
165static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
166{ \
167 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5); \
168}
169
170
171#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4
,type5 arg5, type6 arg6) { return syscall(__NR_name, arg1, arg2
, arg3, arg4, arg5, arg6); }
172 type5,arg5,type6,arg6)static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4
,type5 arg5, type6 arg6) { return syscall(__NR_name, arg1, arg2
, arg3, arg4, arg5, arg6); }
\
173static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \
174 type6 arg6) \
175{ \
176 return syscall(__NR_##name, arg1, arg2, arg3, arg4, arg5, arg6); \
177}
178
179
180#define __NR_sys_uname63 __NR_uname63
181#define __NR_sys_getcwd179 __NR_getcwd79
182#define __NR_sys_getdents78 __NR_getdents78
183#define __NR_sys_getdents64217 __NR_getdents64217
184#define __NR_sys_getpriority140 __NR_getpriority140
185#define __NR_sys_rt_sigqueueinfo129 __NR_rt_sigqueueinfo129
186#define __NR_sys_syslog103 __NR_syslog103
187#define __NR_sys_tgkill234 __NR_tgkill234
188#define __NR_sys_tkill200 __NR_tkill200
189#define __NR_sys_futex202 __NR_futex202
190#define __NR_sys_inotify_init253 __NR_inotify_init253
191#define __NR_sys_inotify_add_watch254 __NR_inotify_add_watch254
192#define __NR_sys_inotify_rm_watch255 __NR_inotify_rm_watch255
193
194#if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__1) || \
195 defined(__s390x__)
196#define __NR__llseek8 __NR_lseek8
197#endif
198
199#ifdef __NR_gettid186
200_syscall0(int, gettid)static int gettid (void) { return syscall(186); }
201#else
202/* This is a replacement for the host gettid() and must return a host
203 errno. */
204static int gettid(void) {
205 return -ENOSYS38;
206}
207#endif
208#ifdef __NR_getdents78
209_syscall3(int, sys_getdents, uint, fd, struct linux_dirent *, dirp, uint, count)static int sys_getdents (uint fd,struct linux_dirent * dirp,uint
count) { return syscall(78, fd, dirp, count); }
;
210#endif
211#if !defined(__NR_getdents78) || \
212 (defined(TARGET_NR_getdents64220) && defined(__NR_getdents64217))
213_syscall3(int, sys_getdents64, uint, fd, struct linux_dirent64 *, dirp, uint, count)static int sys_getdents64 (uint fd,struct linux_dirent64 * dirp
,uint count) { return syscall(217, fd, dirp, count); }
;
214#endif
215#if defined(TARGET_NR__llseek) && defined(__NR_llseek)
216_syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo,static int _llseek (uint fd,ulong hi,ulong lo,loff_t * res,uint
wh) { return syscall(8, fd, hi, lo, res, wh); }
217 loff_t *, res, uint, wh)static int _llseek (uint fd,ulong hi,ulong lo,loff_t * res,uint
wh) { return syscall(8, fd, hi, lo, res, wh); }
;
218#endif
219_syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo)static int sys_rt_sigqueueinfo (int pid,int sig,siginfo_t * uinfo
) { return syscall(129, pid, sig, uinfo); }
220_syscall3(int,sys_syslog,int,type,char*,bufp,int,len)static int sys_syslog (int type,char* bufp,int len) { return syscall
(103, type, bufp, len); }
221#if defined(TARGET_NR_tgkill241) && defined(__NR_tgkill234)
222_syscall3(int,sys_tgkill,int,tgid,int,pid,int,sig)static int sys_tgkill (int tgid,int pid,int sig) { return syscall
(234, tgid, pid, sig); }
223#endif
224#if defined(TARGET_NR_tkill237) && defined(__NR_tkill200)
225_syscall2(int,sys_tkill,int,tid,int,sig)static int sys_tkill (int tid,int sig) { return syscall(200, tid
, sig); }
226#endif
227#ifdef __NR_exit_group231
228_syscall1(int,exit_group,int,error_code)static int exit_group (int error_code) { return syscall(231, error_code
); }
229#endif
230#if defined(TARGET_NR_set_tid_address252) && defined(__NR_set_tid_address218)
231_syscall1(int,set_tid_address,int *,tidptr)static int set_tid_address (int * tidptr) { return syscall(218
, tidptr); }
232#endif
233#if defined(TARGET_NR_futex238) && defined(__NR_futex202)
234_syscall6(int,sys_futex,int *,uaddr,int,op,int,val,static int sys_futex (int * uaddr,int op,int val,const struct
timespec * timeout,int * uaddr2, int val3) { return syscall(
202, uaddr, op, val, timeout, uaddr2, val3); }
235 const struct timespec *,timeout,int *,uaddr2,int,val3)static int sys_futex (int * uaddr,int op,int val,const struct
timespec * timeout,int * uaddr2, int val3) { return syscall(
202, uaddr, op, val, timeout, uaddr2, val3); }
236#endif
237#define __NR_sys_sched_getaffinity204 __NR_sched_getaffinity204
238_syscall3(int, sys_sched_getaffinity, pid_t, pid, unsigned int, len,static int sys_sched_getaffinity (pid_t pid,unsigned int len,
unsigned long * user_mask_ptr) { return syscall(204, pid, len
, user_mask_ptr); }
239 unsigned long *, user_mask_ptr)static int sys_sched_getaffinity (pid_t pid,unsigned int len,
unsigned long * user_mask_ptr) { return syscall(204, pid, len
, user_mask_ptr); }
;
240#define __NR_sys_sched_setaffinity203 __NR_sched_setaffinity203
241_syscall3(int, sys_sched_setaffinity, pid_t, pid, unsigned int, len,static int sys_sched_setaffinity (pid_t pid,unsigned int len,
unsigned long * user_mask_ptr) { return syscall(203, pid, len
, user_mask_ptr); }
242 unsigned long *, user_mask_ptr)static int sys_sched_setaffinity (pid_t pid,unsigned int len,
unsigned long * user_mask_ptr) { return syscall(203, pid, len
, user_mask_ptr); }
;
243_syscall4(int, reboot, int, magic1, int, magic2, unsigned int, cmd,static int reboot (int magic1,int magic2,unsigned int cmd,void
* arg) { return syscall(169, magic1, magic2, cmd, arg); }
244 void *, arg)static int reboot (int magic1,int magic2,unsigned int cmd,void
* arg) { return syscall(169, magic1, magic2, cmd, arg); }
;
245
246static bitmask_transtbl fcntl_flags_tbl[] = {
247 { TARGET_O_ACCMODE0003, TARGET_O_WRONLY01, O_ACCMODE0003, O_WRONLY01, },
248 { TARGET_O_ACCMODE0003, TARGET_O_RDWR02, O_ACCMODE0003, O_RDWR02, },
249 { TARGET_O_CREAT0100, TARGET_O_CREAT0100, O_CREAT0100, O_CREAT0100, },
250 { TARGET_O_EXCL0200, TARGET_O_EXCL0200, O_EXCL0200, O_EXCL0200, },
251 { TARGET_O_NOCTTY0400, TARGET_O_NOCTTY0400, O_NOCTTY0400, O_NOCTTY0400, },
252 { TARGET_O_TRUNC01000, TARGET_O_TRUNC01000, O_TRUNC01000, O_TRUNC01000, },
253 { TARGET_O_APPEND02000, TARGET_O_APPEND02000, O_APPEND02000, O_APPEND02000, },
254 { TARGET_O_NONBLOCK04000, TARGET_O_NONBLOCK04000, O_NONBLOCK04000, O_NONBLOCK04000, },
255 { TARGET_O_SYNC(04000000 | 010000), TARGET_O_DSYNC010000, O_SYNC04010000, O_DSYNC010000, },
256 { TARGET_O_SYNC(04000000 | 010000), TARGET_O_SYNC(04000000 | 010000), O_SYNC04010000, O_SYNC04010000, },
257 { TARGET_FASYNC020000, TARGET_FASYNC020000, FASYNC020000, FASYNC020000, },
258 { TARGET_O_DIRECTORY0200000, TARGET_O_DIRECTORY0200000, O_DIRECTORY0200000, O_DIRECTORY0200000, },
259 { TARGET_O_NOFOLLOW0400000, TARGET_O_NOFOLLOW0400000, O_NOFOLLOW0400000, O_NOFOLLOW0400000, },
260#if defined(O_DIRECT040000)
261 { TARGET_O_DIRECT040000, TARGET_O_DIRECT040000, O_DIRECT040000, O_DIRECT040000, },
262#endif
263#if defined(O_NOATIME01000000)
264 { TARGET_O_NOATIME01000000, TARGET_O_NOATIME01000000, O_NOATIME01000000, O_NOATIME01000000 },
265#endif
266#if defined(O_CLOEXEC02000000)
267 { TARGET_O_CLOEXEC02000000, TARGET_O_CLOEXEC02000000, O_CLOEXEC02000000, O_CLOEXEC02000000 },
268#endif
269#if defined(O_PATH010000000)
270 { TARGET_O_PATH010000000, TARGET_O_PATH010000000, O_PATH010000000, O_PATH010000000 },
271#endif
272 /* Don't terminate the list prematurely on 64-bit host+guest. */
273#if TARGET_O_LARGEFILE0100000 != 0 || O_LARGEFILE0 != 0
274 { TARGET_O_LARGEFILE0100000, TARGET_O_LARGEFILE0100000, O_LARGEFILE0, O_LARGEFILE0, },
275#endif
276 { 0, 0, 0, 0 }
277};
278
279#define COPY_UTSNAME_FIELD(dest, src) \
280 do { \
281 /* __NEW_UTS_LEN doesn't include terminating null */ \
282 (void) strncpy((dest), (src), __NEW_UTS_LEN64); \
283 (dest)[__NEW_UTS_LEN64] = '\0'; \
284 } while (0)
285
286static int sys_uname(struct new_utsname *buf)
287{
288 struct utsname uts_buf;
289
290 if (uname(&uts_buf) < 0)
291 return (-1);
292
293 /*
294 * Just in case these have some differences, we
295 * translate utsname to new_utsname (which is the
296 * struct linux kernel uses).
297 */
298
299 memset(buf, 0, sizeof(*buf));
300 COPY_UTSNAME_FIELD(buf->sysname, uts_buf.sysname);
301 COPY_UTSNAME_FIELD(buf->nodename, uts_buf.nodename);
302 COPY_UTSNAME_FIELD(buf->release, uts_buf.release);
303 COPY_UTSNAME_FIELD(buf->version, uts_buf.version);
304 COPY_UTSNAME_FIELD(buf->machine, uts_buf.machine);
305#ifdef _GNU_SOURCE1
306 COPY_UTSNAME_FIELD(buf->domainname, uts_buf.domainname);
307#endif
308 return (0);
309
310#undef COPY_UTSNAME_FIELD
311}
312
313static int sys_getcwd1(char *buf, size_t size)
314{
315 if (getcwd(buf, size) == NULL((void*)0)) {
316 /* getcwd() sets errno */
317 return (-1);
318 }
319 return strlen(buf)+1;
320}
321
322#ifdef TARGET_NR_openat288
323static int sys_openat(int dirfd, const char *pathname, int flags, mode_t mode)
324{
325 /*
326 * open(2) has extra parameter 'mode' when called with
327 * flag O_CREAT.
328 */
329 if ((flags & O_CREAT0100) != 0) {
330 return (openat(dirfd, pathname, flags, mode));
331 }
332 return (openat(dirfd, pathname, flags));
333}
334#endif
335
336#ifdef TARGET_NR_utimensat315
337#ifdef CONFIG_UTIMENSAT1
338static int sys_utimensat(int dirfd, const char *pathname,
339 const struct timespec times[2], int flags)
340{
341 if (pathname == NULL((void*)0))
342 return futimens(dirfd, times);
343 else
344 return utimensat(dirfd, pathname, times, flags);
345}
346#elif defined(__NR_utimensat280)
347#define __NR_sys_utimensat __NR_utimensat280
348_syscall4(int,sys_utimensat,int,dirfd,const char *,pathname,static int sys_utimensat (int dirfd,const char * pathname,const
struct timespec * tsp,int flags) { return syscall(__NR_sys_utimensat
, dirfd, pathname, tsp, flags); }
349 const struct timespec *,tsp,int,flags)static int sys_utimensat (int dirfd,const char * pathname,const
struct timespec * tsp,int flags) { return syscall(__NR_sys_utimensat
, dirfd, pathname, tsp, flags); }
350#else
351static int sys_utimensat(int dirfd, const char *pathname,
352 const struct timespec times[2], int flags)
353{
354 errno(*__errno_location ()) = ENOSYS38;
355 return -1;
356}
357#endif
358#endif /* TARGET_NR_utimensat */
359
360#ifdef CONFIG_INOTIFY1
361#include <sys/inotify.h>
362
363#if defined(TARGET_NR_inotify_init284) && defined(__NR_inotify_init253)
364static int sys_inotify_init(void)
365{
366 return (inotify_init());
367}
368#endif
369#if defined(TARGET_NR_inotify_add_watch285) && defined(__NR_inotify_add_watch254)
370static int sys_inotify_add_watch(int fd,const char *pathname, int32_t mask)
371{
372 return (inotify_add_watch(fd, pathname, mask));
373}
374#endif
375#if defined(TARGET_NR_inotify_rm_watch286) && defined(__NR_inotify_rm_watch255)
376static int sys_inotify_rm_watch(int fd, int32_t wd)
377{
378 return (inotify_rm_watch(fd, wd));
379}
380#endif
381#ifdef CONFIG_INOTIFY11
382#if defined(TARGET_NR_inotify_init1324) && defined(__NR_inotify_init1294)
383static int sys_inotify_init1(int flags)
384{
385 return (inotify_init1(flags));
386}
387#endif
388#endif
389#else
390/* Userspace can usually survive runtime without inotify */
391#undef TARGET_NR_inotify_init284
392#undef TARGET_NR_inotify_init1324
393#undef TARGET_NR_inotify_add_watch285
394#undef TARGET_NR_inotify_rm_watch286
395#endif /* CONFIG_INOTIFY */
396
397#if defined(TARGET_NR_ppoll302)
398#ifndef __NR_ppoll271
399# define __NR_ppoll271 -1
400#endif
401#define __NR_sys_ppoll271 __NR_ppoll271
402_syscall5(int, sys_ppoll, struct pollfd *, fds, nfds_t, nfds,static int sys_ppoll (struct pollfd * fds,nfds_t nfds,struct timespec
* timeout,const __sigset_t * sigmask,size_t sigsetsize) { return
syscall(271, fds, nfds, timeout, sigmask, sigsetsize); }
403 struct timespec *, timeout, const __sigset_t *, sigmask,static int sys_ppoll (struct pollfd * fds,nfds_t nfds,struct timespec
* timeout,const __sigset_t * sigmask,size_t sigsetsize) { return
syscall(271, fds, nfds, timeout, sigmask, sigsetsize); }
404 size_t, sigsetsize)static int sys_ppoll (struct pollfd * fds,nfds_t nfds,struct timespec
* timeout,const __sigset_t * sigmask,size_t sigsetsize) { return
syscall(271, fds, nfds, timeout, sigmask, sigsetsize); }
405#endif
406
407#if defined(TARGET_NR_pselect6301)
408#ifndef __NR_pselect6270
409# define __NR_pselect6270 -1
410#endif
411#define __NR_sys_pselect6270 __NR_pselect6270
412_syscall6(int, sys_pselect6, int, nfds, fd_set *, readfds, fd_set *, writefds,static int sys_pselect6 (int nfds,fd_set * readfds,fd_set * writefds
,fd_set * exceptfds,struct timespec * timeout, void * sig) { return
syscall(270, nfds, readfds, writefds, exceptfds, timeout, sig
); }
413 fd_set *, exceptfds, struct timespec *, timeout, void *, sig)static int sys_pselect6 (int nfds,fd_set * readfds,fd_set * writefds
,fd_set * exceptfds,struct timespec * timeout, void * sig) { return
syscall(270, nfds, readfds, writefds, exceptfds, timeout, sig
); }
;
414#endif
415
416#if defined(TARGET_NR_prlimit64334)
417#ifndef __NR_prlimit64302
418# define __NR_prlimit64302 -1
419#endif
420#define __NR_sys_prlimit64302 __NR_prlimit64302
421/* The glibc rlimit structure may not be that used by the underlying syscall */
422struct host_rlimit64 {
423 uint64_t rlim_cur;
424 uint64_t rlim_max;
425};
426_syscall4(int, sys_prlimit64, pid_t, pid, int, resource,static int sys_prlimit64 (pid_t pid,int resource,const struct
host_rlimit64 * new_limit,struct host_rlimit64 * old_limit) {
return syscall(302, pid, resource, new_limit, old_limit); }
427 const struct host_rlimit64 *, new_limit,static int sys_prlimit64 (pid_t pid,int resource,const struct
host_rlimit64 * new_limit,struct host_rlimit64 * old_limit) {
return syscall(302, pid, resource, new_limit, old_limit); }
428 struct host_rlimit64 *, old_limit)static int sys_prlimit64 (pid_t pid,int resource,const struct
host_rlimit64 * new_limit,struct host_rlimit64 * old_limit) {
return syscall(302, pid, resource, new_limit, old_limit); }
429#endif
430
431
432#if defined(TARGET_NR_timer_create254)
433/* Maxiumum of 32 active POSIX timers allowed at any one time. */
434static timer_t g_posix_timers[32] = { 0, } ;
435
436static inline int next_free_host_timer(void)
437{
438 int k ;
439 /* FIXME: Does finding the next free slot require a lock? */
440 for (k = 0; k < ARRAY_SIZE(g_posix_timers)(sizeof(g_posix_timers) / sizeof((g_posix_timers)[0])); k++) {
441 if (g_posix_timers[k] == 0) {
442 g_posix_timers[k] = (timer_t) 1;
443 return k;
444 }
445 }
446 return -1;
447}
448#endif
449
450/* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */
451#ifdef TARGET_ARM
452static inline int regpairs_aligned(void *cpu_env) {
453 return ((((CPUARMState *)cpu_env)->eabi) == 1) ;
454}
455#elif defined(TARGET_MIPS)
456static inline int regpairs_aligned(void *cpu_env) { return 1; }
457#elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
458/* SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even pairs
459 * of registers which translates to the same as ARM/MIPS, because we start with
460 * r3 as arg1 */
461static inline int regpairs_aligned(void *cpu_env) { return 1; }
462#else
463static inline int regpairs_aligned(void *cpu_env) { return 0; }
464#endif
465
466#define ERRNO_TABLE_SIZE1200 1200
467
468/* target_to_host_errno_table[] is initialized from
469 * host_to_target_errno_table[] in syscall_init(). */
470static uint16_t target_to_host_errno_table[ERRNO_TABLE_SIZE1200] = {
471};
472
473/*
474 * This list is the union of errno values overridden in asm-<arch>/errno.h
475 * minus the errnos that are not actually generic to all archs.
476 */
477static uint16_t host_to_target_errno_table[ERRNO_TABLE_SIZE1200] = {
478 [EIDRM43] = TARGET_EIDRM43,
479 [ECHRNG44] = TARGET_ECHRNG44,
480 [EL2NSYNC45] = TARGET_EL2NSYNC45,
481 [EL3HLT46] = TARGET_EL3HLT46,
482 [EL3RST47] = TARGET_EL3RST47,
483 [ELNRNG48] = TARGET_ELNRNG48,
484 [EUNATCH49] = TARGET_EUNATCH49,
485 [ENOCSI50] = TARGET_ENOCSI50,
486 [EL2HLT51] = TARGET_EL2HLT51,
487 [EDEADLK35] = TARGET_EDEADLK35,
488 [ENOLCK37] = TARGET_ENOLCK37,
489 [EBADE52] = TARGET_EBADE52,
490 [EBADR53] = TARGET_EBADR53,
491 [EXFULL54] = TARGET_EXFULL54,
492 [ENOANO55] = TARGET_ENOANO55,
493 [EBADRQC56] = TARGET_EBADRQC56,
494 [EBADSLT57] = TARGET_EBADSLT57,
495 [EBFONT59] = TARGET_EBFONT59,
496 [ENOSTR60] = TARGET_ENOSTR60,
497 [ENODATA61] = TARGET_ENODATA61,
498 [ETIME62] = TARGET_ETIME62,
499 [ENOSR63] = TARGET_ENOSR63,
500 [ENONET64] = TARGET_ENONET64,
501 [ENOPKG65] = TARGET_ENOPKG65,
502 [EREMOTE66] = TARGET_EREMOTE66,
503 [ENOLINK67] = TARGET_ENOLINK67,
504 [EADV68] = TARGET_EADV68,
505 [ESRMNT69] = TARGET_ESRMNT69,
506 [ECOMM70] = TARGET_ECOMM70,
507 [EPROTO71] = TARGET_EPROTO71,
508 [EDOTDOT73] = TARGET_EDOTDOT73,
509 [EMULTIHOP72] = TARGET_EMULTIHOP72,
510 [EBADMSG74] = TARGET_EBADMSG74,
511 [ENAMETOOLONG36] = TARGET_ENAMETOOLONG36,
512 [EOVERFLOW75] = TARGET_EOVERFLOW75,
513 [ENOTUNIQ76] = TARGET_ENOTUNIQ76,
514 [EBADFD77] = TARGET_EBADFD77,
515 [EREMCHG78] = TARGET_EREMCHG78,
516 [ELIBACC79] = TARGET_ELIBACC79,
517 [ELIBBAD80] = TARGET_ELIBBAD80,
518 [ELIBSCN81] = TARGET_ELIBSCN81,
519 [ELIBMAX82] = TARGET_ELIBMAX82,
520 [ELIBEXEC83] = TARGET_ELIBEXEC83,
521 [EILSEQ84] = TARGET_EILSEQ84,
522 [ENOSYS38] = TARGET_ENOSYS38,
523 [ELOOP40] = TARGET_ELOOP40,
524 [ERESTART85] = TARGET_ERESTART85,
525 [ESTRPIPE86] = TARGET_ESTRPIPE86,
526 [ENOTEMPTY39] = TARGET_ENOTEMPTY39,
527 [EUSERS87] = TARGET_EUSERS87,
528 [ENOTSOCK88] = TARGET_ENOTSOCK88,
529 [EDESTADDRREQ89] = TARGET_EDESTADDRREQ89,
530 [EMSGSIZE90] = TARGET_EMSGSIZE90,
531 [EPROTOTYPE91] = TARGET_EPROTOTYPE91,
532 [ENOPROTOOPT92] = TARGET_ENOPROTOOPT92,
533 [EPROTONOSUPPORT93] = TARGET_EPROTONOSUPPORT93,
534 [ESOCKTNOSUPPORT94] = TARGET_ESOCKTNOSUPPORT94,
535 [EOPNOTSUPP95] = TARGET_EOPNOTSUPP95,
536 [EPFNOSUPPORT96] = TARGET_EPFNOSUPPORT96,
537 [EAFNOSUPPORT97] = TARGET_EAFNOSUPPORT97,
538 [EADDRINUSE98] = TARGET_EADDRINUSE98,
539 [EADDRNOTAVAIL99] = TARGET_EADDRNOTAVAIL99,
540 [ENETDOWN100] = TARGET_ENETDOWN100,
541 [ENETUNREACH101] = TARGET_ENETUNREACH101,
542 [ENETRESET102] = TARGET_ENETRESET102,
543 [ECONNABORTED103] = TARGET_ECONNABORTED103,
544 [ECONNRESET104] = TARGET_ECONNRESET104,
545 [ENOBUFS105] = TARGET_ENOBUFS105,
546 [EISCONN106] = TARGET_EISCONN106,
547 [ENOTCONN107] = TARGET_ENOTCONN107,
548 [EUCLEAN117] = TARGET_EUCLEAN117,
549 [ENOTNAM118] = TARGET_ENOTNAM118,
550 [ENAVAIL119] = TARGET_ENAVAIL119,
551 [EISNAM120] = TARGET_EISNAM120,
552 [EREMOTEIO121] = TARGET_EREMOTEIO121,
553 [ESHUTDOWN108] = TARGET_ESHUTDOWN108,
554 [ETOOMANYREFS109] = TARGET_ETOOMANYREFS109,
555 [ETIMEDOUT110] = TARGET_ETIMEDOUT110,
556 [ECONNREFUSED111] = TARGET_ECONNREFUSED111,
557 [EHOSTDOWN112] = TARGET_EHOSTDOWN112,
558 [EHOSTUNREACH113] = TARGET_EHOSTUNREACH113,
559 [EALREADY114] = TARGET_EALREADY114,
560 [EINPROGRESS115] = TARGET_EINPROGRESS115,
561 [ESTALE116] = TARGET_ESTALE116,
562 [ECANCELED125] = TARGET_ECANCELED125,
563 [ENOMEDIUM123] = TARGET_ENOMEDIUM123,
564 [EMEDIUMTYPE124] = TARGET_EMEDIUMTYPE124,
565#ifdef ENOKEY126
566 [ENOKEY126] = TARGET_ENOKEY126,
567#endif
568#ifdef EKEYEXPIRED127
569 [EKEYEXPIRED127] = TARGET_EKEYEXPIRED127,
570#endif
571#ifdef EKEYREVOKED128
572 [EKEYREVOKED128] = TARGET_EKEYREVOKED128,
573#endif
574#ifdef EKEYREJECTED129
575 [EKEYREJECTED129] = TARGET_EKEYREJECTED129,
576#endif
577#ifdef EOWNERDEAD130
578 [EOWNERDEAD130] = TARGET_EOWNERDEAD130,
579#endif
580#ifdef ENOTRECOVERABLE131
581 [ENOTRECOVERABLE131] = TARGET_ENOTRECOVERABLE131,
582#endif
583};
584
585static inline int host_to_target_errno(int err)
586{
587 if(host_to_target_errno_table[err])
588 return host_to_target_errno_table[err];
589 return err;
590}
591
592static inline int target_to_host_errno(int err)
593{
594 if (target_to_host_errno_table[err])
595 return target_to_host_errno_table[err];
596 return err;
597}
598
599static inline abi_long get_errno(abi_long ret)
600{
601 if (ret == -1)
602 return -host_to_target_errno(errno(*__errno_location ()));
603 else
604 return ret;
605}
606
607static inline int is_error(abi_long ret)
608{
609 return (abi_ulong)ret >= (abi_ulong)(-4096);
610}
611
612char *target_strerror(int err)
613{
614 if ((err >= ERRNO_TABLE_SIZE1200) || (err < 0)) {
615 return NULL((void*)0);
616 }
617 return strerror(target_to_host_errno(err));
618}
619
620static abi_ulong target_brk;
621static abi_ulong target_original_brk;
622static abi_ulong brk_page;
623
624void target_set_brk(abi_ulong new_brk)
625{
626 target_original_brk = target_brk = HOST_PAGE_ALIGN(new_brk)(((new_brk) + qemu_host_page_size - 1) & qemu_host_page_mask
)
;
627 brk_page = HOST_PAGE_ALIGN(target_brk)(((target_brk) + qemu_host_page_size - 1) & qemu_host_page_mask
)
;
628}
629
630//#define DEBUGF_BRK(message, args...) do { fprintf(stderr, (message), ## args); } while (0)
631#define DEBUGF_BRK(message, args...)
632
633/* do_brk() must return target values and target errnos. */
634abi_long do_brk(abi_ulong new_brk)
635{
636 abi_long mapped_addr;
637 int new_alloc_size;
638
639 DEBUGF_BRK("do_brk(" TARGET_ABI_FMT_lx ") -> ", new_brk);
640
641 if (!new_brk) {
642 DEBUGF_BRK(TARGET_ABI_FMT_lx " (!new_brk)\n", target_brk);
643 return target_brk;
644 }
645 if (new_brk < target_original_brk) {
646 DEBUGF_BRK(TARGET_ABI_FMT_lx " (new_brk < target_original_brk)\n",
647 target_brk);
648 return target_brk;
649 }
650
651 /* If the new brk is less than the highest page reserved to the
652 * target heap allocation, set it and we're almost done... */
653 if (new_brk <= brk_page) {
654 /* Heap contents are initialized to zero, as for anonymous
655 * mapped pages. */
656 if (new_brk > target_brk) {
657 memset(g2h(target_brk)((void *)((unsigned long)(target_ulong)(target_brk) + guest_base
))
, 0, new_brk - target_brk);
658 }
659 target_brk = new_brk;
660 DEBUGF_BRK(TARGET_ABI_FMT_lx " (new_brk <= brk_page)\n", target_brk);
661 return target_brk;
662 }
663
664 /* We need to allocate more memory after the brk... Note that
665 * we don't use MAP_FIXED because that will map over the top of
666 * any existing mapping (like the one with the host libc or qemu
667 * itself); instead we treat "mapped but at wrong address" as
668 * a failure and unmap again.
669 */
670 new_alloc_size = HOST_PAGE_ALIGN(new_brk - brk_page)(((new_brk - brk_page) + qemu_host_page_size - 1) & qemu_host_page_mask
)
;
671 mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size,
672 PROT_READ0x1|PROT_WRITE0x2,
673 MAP_ANON0x20|MAP_PRIVATE0x02, 0, 0));
674
675 if (mapped_addr == brk_page) {
676 /* Heap contents are initialized to zero, as for anonymous
677 * mapped pages. Technically the new pages are already
678 * initialized to zero since they *are* anonymous mapped
679 * pages, however we have to take care with the contents that
680 * come from the remaining part of the previous page: it may
681 * contains garbage data due to a previous heap usage (grown
682 * then shrunken). */
683 memset(g2h(target_brk)((void *)((unsigned long)(target_ulong)(target_brk) + guest_base
))
, 0, brk_page - target_brk);
684
685 target_brk = new_brk;
686 brk_page = HOST_PAGE_ALIGN(target_brk)(((target_brk) + qemu_host_page_size - 1) & qemu_host_page_mask
)
;
687 DEBUGF_BRK(TARGET_ABI_FMT_lx " (mapped_addr == brk_page)\n",
688 target_brk);
689 return target_brk;
690 } else if (mapped_addr != -1) {
691 /* Mapped but at wrong address, meaning there wasn't actually
692 * enough space for this brk.
693 */
694 target_munmap(mapped_addr, new_alloc_size);
695 mapped_addr = -1;
696 DEBUGF_BRK(TARGET_ABI_FMT_lx " (mapped_addr != -1)\n", target_brk);
697 }
698 else {
699 DEBUGF_BRK(TARGET_ABI_FMT_lx " (otherwise)\n", target_brk);
700 }
701
702#if defined(TARGET_ALPHA)
703 /* We (partially) emulate OSF/1 on Alpha, which requires we
704 return a proper errno, not an unchanged brk value. */
705 return -TARGET_ENOMEM12;
706#endif
707 /* For everything else, return the previous break. */
708 return target_brk;
709}
710
711static inline abi_long copy_from_user_fdset(fd_set *fds,
712 abi_ulong target_fds_addr,
713 int n)
714{
715 int i, nw, j, k;
716 abi_ulong b, *target_fds;
717
718 nw = (n + TARGET_ABI_BITS64 - 1) / TARGET_ABI_BITS64;
719 if (!(target_fds = lock_user(VERIFY_READ0,
720 target_fds_addr,
721 sizeof(abi_ulong) * nw,
722 1)))
723 return -TARGET_EFAULT14;
724
725 FD_ZERO(fds)do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq"
: "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) /
sizeof (__fd_mask)), "1" (&((fds)->fds_bits)[0]) : "memory"
); } while (0)
;
726 k = 0;
727 for (i = 0; i < nw; i++) {
728 /* grab the abi_ulong */
729 __get_user(b, &target_fds[i])((b) = (typeof(*&target_fds[i]))( __builtin_choose_expr(sizeof
(*(&target_fds[i])) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(&target_fds[i])) == 2, lduw_be_p, __builtin_choose_expr
(sizeof(*(&target_fds[i])) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&target_fds[i])) == 8, ldq_be_p, abort)))) (&
target_fds[i])), 0)
;
730 for (j = 0; j < TARGET_ABI_BITS64; j++) {
731 /* check the bit inside the abi_ulong */
732 if ((b >> j) & 1)
733 FD_SET(k, fds)((void) (((fds)->fds_bits)[((k) / (8 * (int) sizeof (__fd_mask
)))] |= ((__fd_mask) 1 << ((k) % (8 * (int) sizeof (__fd_mask
))))))
;
734 k++;
735 }
736 }
737
738 unlock_user(target_fds, target_fds_addr, 0);
739
740 return 0;
741}
742
743static inline abi_ulong copy_from_user_fdset_ptr(fd_set *fds, fd_set **fds_ptr,
744 abi_ulong target_fds_addr,
745 int n)
746{
747 if (target_fds_addr) {
748 if (copy_from_user_fdset(fds, target_fds_addr, n))
749 return -TARGET_EFAULT14;
750 *fds_ptr = fds;
751 } else {
752 *fds_ptr = NULL((void*)0);
753 }
754 return 0;
755}
756
757static inline abi_long copy_to_user_fdset(abi_ulong target_fds_addr,
758 const fd_set *fds,
759 int n)
760{
761 int i, nw, j, k;
762 abi_long v;
763 abi_ulong *target_fds;
764
765 nw = (n + TARGET_ABI_BITS64 - 1) / TARGET_ABI_BITS64;
766 if (!(target_fds = lock_user(VERIFY_WRITE1,
767 target_fds_addr,
768 sizeof(abi_ulong) * nw,
769 0)))
770 return -TARGET_EFAULT14;
771
772 k = 0;
773 for (i = 0; i < nw; i++) {
774 v = 0;
775 for (j = 0; j < TARGET_ABI_BITS64; j++) {
776 v |= ((abi_ulong)(FD_ISSET(k, fds)((((fds)->fds_bits)[((k) / (8 * (int) sizeof (__fd_mask)))
] & ((__fd_mask) 1 << ((k) % (8 * (int) sizeof (__fd_mask
))))) != 0)
!= 0) << j);
777 k++;
778 }
779 __put_user(v, &target_fds[i])(__builtin_choose_expr(sizeof(*(&target_fds[i])) == 1, stb_p
, __builtin_choose_expr(sizeof(*(&target_fds[i])) == 2, stw_be_p
, __builtin_choose_expr(sizeof(*(&target_fds[i])) == 4, stl_be_p
, __builtin_choose_expr(sizeof(*(&target_fds[i])) == 8, stq_be_p
, abort)))) ((&target_fds[i]), (v)), 0)
;
780 }
781
782 unlock_user(target_fds, target_fds_addr, sizeof(abi_ulong) * nw);
783
784 return 0;
785}
786
787#if defined(__alpha__)
788#define HOST_HZ100 1024
789#else
790#define HOST_HZ100 100
791#endif
792
793static inline abi_long host_to_target_clock_t(long ticks)
794{
795#if HOST_HZ100 == TARGET_HZ100
796 return ticks;
797#else
798 return ((int64_t)ticks * TARGET_HZ100) / HOST_HZ100;
799#endif
800}
801
802static inline abi_long host_to_target_rusage(abi_ulong target_addr,
803 const struct rusage *rusage)
804{
805 struct target_rusage *target_rusage;
806
807 if (!lock_user_struct(VERIFY_WRITE, target_rusage, target_addr, 0)(target_rusage = lock_user(1, target_addr, sizeof(*target_rusage
), 0))
)
808 return -TARGET_EFAULT14;
809 target_rusage->ru_utime.tv_sec = tswapal(rusage->ru_utime.tv_sec);
810 target_rusage->ru_utime.tv_usec = tswapal(rusage->ru_utime.tv_usec);
811 target_rusage->ru_stime.tv_sec = tswapal(rusage->ru_stime.tv_sec);
812 target_rusage->ru_stime.tv_usec = tswapal(rusage->ru_stime.tv_usec);
813 target_rusage->ru_maxrss = tswapal(rusage->ru_maxrss);
814 target_rusage->ru_ixrss = tswapal(rusage->ru_ixrss);
815 target_rusage->ru_idrss = tswapal(rusage->ru_idrss);
816 target_rusage->ru_isrss = tswapal(rusage->ru_isrss);
817 target_rusage->ru_minflt = tswapal(rusage->ru_minflt);
818 target_rusage->ru_majflt = tswapal(rusage->ru_majflt);
819 target_rusage->ru_nswap = tswapal(rusage->ru_nswap);
820 target_rusage->ru_inblock = tswapal(rusage->ru_inblock);
821 target_rusage->ru_oublock = tswapal(rusage->ru_oublock);
822 target_rusage->ru_msgsnd = tswapal(rusage->ru_msgsnd);
823 target_rusage->ru_msgrcv = tswapal(rusage->ru_msgrcv);
824 target_rusage->ru_nsignals = tswapal(rusage->ru_nsignals);
825 target_rusage->ru_nvcsw = tswapal(rusage->ru_nvcsw);
826 target_rusage->ru_nivcsw = tswapal(rusage->ru_nivcsw);
827 unlock_user_struct(target_rusage, target_addr, 1)unlock_user(target_rusage, target_addr, (1) ? sizeof(*target_rusage
) : 0)
;
828
829 return 0;
830}
831
832static inline rlim_t target_to_host_rlim(abi_ulong target_rlim)
833{
834 abi_ulong target_rlim_swap;
835 rlim_t result;
836
837 target_rlim_swap = tswapal(target_rlim);
838 if (target_rlim_swap == TARGET_RLIM_INFINITY((abi_ulong)-1))
839 return RLIM_INFINITY0xffffffffffffffffuLL;
840
841 result = target_rlim_swap;
842 if (target_rlim_swap != (rlim_t)result)
843 return RLIM_INFINITY0xffffffffffffffffuLL;
844
845 return result;
846}
847
848static inline abi_ulong host_to_target_rlim(rlim_t rlim)
849{
850 abi_ulong target_rlim_swap;
851 abi_ulong result;
852
853 if (rlim == RLIM_INFINITY0xffffffffffffffffuLL || rlim != (abi_long)rlim)
854 target_rlim_swap = TARGET_RLIM_INFINITY((abi_ulong)-1);
855 else
856 target_rlim_swap = rlim;
857 result = tswapal(target_rlim_swap);
858
859 return result;
860}
861
862static inline int target_to_host_resource(int code)
863{
864 switch (code) {
865 case TARGET_RLIMIT_AS9:
866 return RLIMIT_ASRLIMIT_AS;
867 case TARGET_RLIMIT_CORE4:
868 return RLIMIT_CORERLIMIT_CORE;
869 case TARGET_RLIMIT_CPU0:
870 return RLIMIT_CPURLIMIT_CPU;
871 case TARGET_RLIMIT_DATA2:
872 return RLIMIT_DATARLIMIT_DATA;
873 case TARGET_RLIMIT_FSIZE1:
874 return RLIMIT_FSIZERLIMIT_FSIZE;
875 case TARGET_RLIMIT_LOCKS10:
876 return RLIMIT_LOCKS__RLIMIT_LOCKS;
877 case TARGET_RLIMIT_MEMLOCK8:
878 return RLIMIT_MEMLOCK__RLIMIT_MEMLOCK;
879 case TARGET_RLIMIT_MSGQUEUE12:
880 return RLIMIT_MSGQUEUE__RLIMIT_MSGQUEUE;
881 case TARGET_RLIMIT_NICE13:
882 return RLIMIT_NICE__RLIMIT_NICE;
883 case TARGET_RLIMIT_NOFILE7:
884 return RLIMIT_NOFILERLIMIT_NOFILE;
885 case TARGET_RLIMIT_NPROC6:
886 return RLIMIT_NPROC__RLIMIT_NPROC;
887 case TARGET_RLIMIT_RSS5:
888 return RLIMIT_RSS__RLIMIT_RSS;
889 case TARGET_RLIMIT_RTPRIO14:
890 return RLIMIT_RTPRIO__RLIMIT_RTPRIO;
891 case TARGET_RLIMIT_SIGPENDING11:
892 return RLIMIT_SIGPENDING__RLIMIT_SIGPENDING;
893 case TARGET_RLIMIT_STACK3:
894 return RLIMIT_STACKRLIMIT_STACK;
895 default:
896 return code;
897 }
898}
899
900static inline abi_long copy_from_user_timeval(struct timeval *tv,
901 abi_ulong target_tv_addr)
902{
903 struct target_timeval *target_tv;
904
905 if (!lock_user_struct(VERIFY_READ, target_tv, target_tv_addr, 1)(target_tv = lock_user(0, target_tv_addr, sizeof(*target_tv),
1))
)
906 return -TARGET_EFAULT14;
907
908 __get_user(tv->tv_sec, &target_tv->tv_sec)((tv->tv_sec) = (typeof(*&target_tv->tv_sec))( __builtin_choose_expr
(sizeof(*(&target_tv->tv_sec)) == 1, ldub_p, __builtin_choose_expr
(sizeof(*(&target_tv->tv_sec)) == 2, lduw_be_p, __builtin_choose_expr
(sizeof(*(&target_tv->tv_sec)) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&target_tv->tv_sec)) == 8, ldq_be_p, abort))
)) (&target_tv->tv_sec)), 0)
;
909 __get_user(tv->tv_usec, &target_tv->tv_usec)((tv->tv_usec) = (typeof(*&target_tv->tv_usec))( __builtin_choose_expr
(sizeof(*(&target_tv->tv_usec)) == 1, ldub_p, __builtin_choose_expr
(sizeof(*(&target_tv->tv_usec)) == 2, lduw_be_p, __builtin_choose_expr
(sizeof(*(&target_tv->tv_usec)) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&target_tv->tv_usec)) == 8, ldq_be_p, abort)
))) (&target_tv->tv_usec)), 0)
;
910
911 unlock_user_struct(target_tv, target_tv_addr, 0)unlock_user(target_tv, target_tv_addr, (0) ? sizeof(*target_tv
) : 0)
;
912
913 return 0;
914}
915
916static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr,
917 const struct timeval *tv)
918{
919 struct target_timeval *target_tv;
920
921 if (!lock_user_struct(VERIFY_WRITE, target_tv, target_tv_addr, 0)(target_tv = lock_user(1, target_tv_addr, sizeof(*target_tv),
0))
)
922 return -TARGET_EFAULT14;
923
924 __put_user(tv->tv_sec, &target_tv->tv_sec)(__builtin_choose_expr(sizeof(*(&target_tv->tv_sec)) ==
1, stb_p, __builtin_choose_expr(sizeof(*(&target_tv->
tv_sec)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_tv->tv_sec)) == 4, stl_be_p, __builtin_choose_expr(
sizeof(*(&target_tv->tv_sec)) == 8, stq_be_p, abort)))
) ((&target_tv->tv_sec), (tv->tv_sec)), 0)
;
925 __put_user(tv->tv_usec, &target_tv->tv_usec)(__builtin_choose_expr(sizeof(*(&target_tv->tv_usec)) ==
1, stb_p, __builtin_choose_expr(sizeof(*(&target_tv->
tv_usec)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_tv->tv_usec)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_tv->tv_usec)) == 8, stq_be_p, abort)
))) ((&target_tv->tv_usec), (tv->tv_usec)), 0)
;
926
927 unlock_user_struct(target_tv, target_tv_addr, 1)unlock_user(target_tv, target_tv_addr, (1) ? sizeof(*target_tv
) : 0)
;
928
929 return 0;
930}
931
932#if defined(TARGET_NR_mq_open271) && defined(__NR_mq_open240)
933#include <mqueue.h>
934
935static inline abi_long copy_from_user_mq_attr(struct mq_attr *attr,
936 abi_ulong target_mq_attr_addr)
937{
938 struct target_mq_attr *target_mq_attr;
939
940 if (!lock_user_struct(VERIFY_READ, target_mq_attr,(target_mq_attr = lock_user(0, target_mq_attr_addr, sizeof(*target_mq_attr
), 1))
941 target_mq_attr_addr, 1)(target_mq_attr = lock_user(0, target_mq_attr_addr, sizeof(*target_mq_attr
), 1))
)
942 return -TARGET_EFAULT14;
943
944 __get_user(attr->mq_flags, &target_mq_attr->mq_flags)((attr->mq_flags) = (typeof(*&target_mq_attr->mq_flags
))( __builtin_choose_expr(sizeof(*(&target_mq_attr->mq_flags
)) == 1, ldub_p, __builtin_choose_expr(sizeof(*(&target_mq_attr
->mq_flags)) == 2, lduw_be_p, __builtin_choose_expr(sizeof
(*(&target_mq_attr->mq_flags)) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&target_mq_attr->mq_flags)) == 8, ldq_be_p, abort
)))) (&target_mq_attr->mq_flags)), 0)
;
945 __get_user(attr->mq_maxmsg, &target_mq_attr->mq_maxmsg)((attr->mq_maxmsg) = (typeof(*&target_mq_attr->mq_maxmsg
))( __builtin_choose_expr(sizeof(*(&target_mq_attr->mq_maxmsg
)) == 1, ldub_p, __builtin_choose_expr(sizeof(*(&target_mq_attr
->mq_maxmsg)) == 2, lduw_be_p, __builtin_choose_expr(sizeof
(*(&target_mq_attr->mq_maxmsg)) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&target_mq_attr->mq_maxmsg)) == 8, ldq_be_p,
abort)))) (&target_mq_attr->mq_maxmsg)), 0)
;
946 __get_user(attr->mq_msgsize, &target_mq_attr->mq_msgsize)((attr->mq_msgsize) = (typeof(*&target_mq_attr->mq_msgsize
))( __builtin_choose_expr(sizeof(*(&target_mq_attr->mq_msgsize
)) == 1, ldub_p, __builtin_choose_expr(sizeof(*(&target_mq_attr
->mq_msgsize)) == 2, lduw_be_p, __builtin_choose_expr(sizeof
(*(&target_mq_attr->mq_msgsize)) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&target_mq_attr->mq_msgsize)) == 8, ldq_be_p
, abort)))) (&target_mq_attr->mq_msgsize)), 0)
;
947 __get_user(attr->mq_curmsgs, &target_mq_attr->mq_curmsgs)((attr->mq_curmsgs) = (typeof(*&target_mq_attr->mq_curmsgs
))( __builtin_choose_expr(sizeof(*(&target_mq_attr->mq_curmsgs
)) == 1, ldub_p, __builtin_choose_expr(sizeof(*(&target_mq_attr
->mq_curmsgs)) == 2, lduw_be_p, __builtin_choose_expr(sizeof
(*(&target_mq_attr->mq_curmsgs)) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&target_mq_attr->mq_curmsgs)) == 8, ldq_be_p
, abort)))) (&target_mq_attr->mq_curmsgs)), 0)
;
948
949 unlock_user_struct(target_mq_attr, target_mq_attr_addr, 0)unlock_user(target_mq_attr, target_mq_attr_addr, (0) ? sizeof
(*target_mq_attr) : 0)
;
950
951 return 0;
952}
953
954static inline abi_long copy_to_user_mq_attr(abi_ulong target_mq_attr_addr,
955 const struct mq_attr *attr)
956{
957 struct target_mq_attr *target_mq_attr;
958
959 if (!lock_user_struct(VERIFY_WRITE, target_mq_attr,(target_mq_attr = lock_user(1, target_mq_attr_addr, sizeof(*target_mq_attr
), 0))
960 target_mq_attr_addr, 0)(target_mq_attr = lock_user(1, target_mq_attr_addr, sizeof(*target_mq_attr
), 0))
)
961 return -TARGET_EFAULT14;
962
963 __put_user(attr->mq_flags, &target_mq_attr->mq_flags)(__builtin_choose_expr(sizeof(*(&target_mq_attr->mq_flags
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_mq_attr
->mq_flags)) == 2, stw_be_p, __builtin_choose_expr(sizeof(
*(&target_mq_attr->mq_flags)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_mq_attr->mq_flags)) == 8, stq_be_p, abort
)))) ((&target_mq_attr->mq_flags), (attr->mq_flags)
), 0)
;
964 __put_user(attr->mq_maxmsg, &target_mq_attr->mq_maxmsg)(__builtin_choose_expr(sizeof(*(&target_mq_attr->mq_maxmsg
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_mq_attr
->mq_maxmsg)) == 2, stw_be_p, __builtin_choose_expr(sizeof
(*(&target_mq_attr->mq_maxmsg)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_mq_attr->mq_maxmsg)) == 8, stq_be_p,
abort)))) ((&target_mq_attr->mq_maxmsg), (attr->mq_maxmsg
)), 0)
;
965 __put_user(attr->mq_msgsize, &target_mq_attr->mq_msgsize)(__builtin_choose_expr(sizeof(*(&target_mq_attr->mq_msgsize
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_mq_attr
->mq_msgsize)) == 2, stw_be_p, __builtin_choose_expr(sizeof
(*(&target_mq_attr->mq_msgsize)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_mq_attr->mq_msgsize)) == 8, stq_be_p
, abort)))) ((&target_mq_attr->mq_msgsize), (attr->
mq_msgsize)), 0)
;
966 __put_user(attr->mq_curmsgs, &target_mq_attr->mq_curmsgs)(__builtin_choose_expr(sizeof(*(&target_mq_attr->mq_curmsgs
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_mq_attr
->mq_curmsgs)) == 2, stw_be_p, __builtin_choose_expr(sizeof
(*(&target_mq_attr->mq_curmsgs)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_mq_attr->mq_curmsgs)) == 8, stq_be_p
, abort)))) ((&target_mq_attr->mq_curmsgs), (attr->
mq_curmsgs)), 0)
;
967
968 unlock_user_struct(target_mq_attr, target_mq_attr_addr, 1)unlock_user(target_mq_attr, target_mq_attr_addr, (1) ? sizeof
(*target_mq_attr) : 0)
;
969
970 return 0;
971}
972#endif
973
974#if defined(TARGET_NR_select142) || defined(TARGET_NR__newselect)
975/* do_select() must return target values and target errnos. */
976static abi_long do_select(int n,
977 abi_ulong rfd_addr, abi_ulong wfd_addr,
978 abi_ulong efd_addr, abi_ulong target_tv_addr)
979{
980 fd_set rfds, wfds, efds;
981 fd_set *rfds_ptr, *wfds_ptr, *efds_ptr;
982 struct timeval tv, *tv_ptr;
983 abi_long ret;
984
985 ret = copy_from_user_fdset_ptr(&rfds, &rfds_ptr, rfd_addr, n);
986 if (ret) {
987 return ret;
988 }
989 ret = copy_from_user_fdset_ptr(&wfds, &wfds_ptr, wfd_addr, n);
990 if (ret) {
991 return ret;
992 }
993 ret = copy_from_user_fdset_ptr(&efds, &efds_ptr, efd_addr, n);
994 if (ret) {
995 return ret;
996 }
997
998 if (target_tv_addr) {
999 if (copy_from_user_timeval(&tv, target_tv_addr))
1000 return -TARGET_EFAULT14;
1001 tv_ptr = &tv;
1002 } else {
1003 tv_ptr = NULL((void*)0);
1004 }
1005
1006 ret = get_errno(select(n, rfds_ptr, wfds_ptr, efds_ptr, tv_ptr));
1007
1008 if (!is_error(ret)) {
1009 if (rfd_addr && copy_to_user_fdset(rfd_addr, &rfds, n))
1010 return -TARGET_EFAULT14;
1011 if (wfd_addr && copy_to_user_fdset(wfd_addr, &wfds, n))
1012 return -TARGET_EFAULT14;
1013 if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n))
1014 return -TARGET_EFAULT14;
1015
1016 if (target_tv_addr && copy_to_user_timeval(target_tv_addr, &tv))
1017 return -TARGET_EFAULT14;
1018 }
1019
1020 return ret;
1021}
1022#endif
1023
1024static abi_long do_pipe2(int host_pipe[], int flags)
1025{
1026#ifdef CONFIG_PIPE21
1027 return pipe2(host_pipe, flags);
1028#else
1029 return -ENOSYS38;
1030#endif
1031}
1032
1033static abi_long do_pipe(void *cpu_env, abi_ulong pipedes,
1034 int flags, int is_pipe2)
1035{
1036 int host_pipe[2];
1037 abi_long ret;
1038 ret = flags ? do_pipe2(host_pipe, flags) : pipe(host_pipe);
1039
1040 if (is_error(ret))
1041 return get_errno(ret);
1042
1043 /* Several targets have special calling conventions for the original
1044 pipe syscall, but didn't replicate this into the pipe2 syscall. */
1045 if (!is_pipe2) {
1046#if defined(TARGET_ALPHA)
1047 ((CPUAlphaState *)cpu_env)->ir[IR_A4] = host_pipe[1];
1048 return host_pipe[0];
1049#elif defined(TARGET_MIPS)
1050 ((CPUMIPSState*)cpu_env)->active_tc.gpr[3] = host_pipe[1];
1051 return host_pipe[0];
1052#elif defined(TARGET_SH4)
1053 ((CPUSH4State*)cpu_env)->gregs[1] = host_pipe[1];
1054 return host_pipe[0];
1055#elif defined(TARGET_SPARC)
1056 ((CPUSPARCState*)cpu_env)->regwptr[1] = host_pipe[1];
1057 return host_pipe[0];
1058#endif
1059 }
1060
1061 if (put_user_s32(host_pipe[0], pipedes)({ abi_ulong __gaddr = ((pipedes)); int32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(1, __gaddr, sizeof(int32_t), 0
))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1, stb_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), (((host_pipe
[0])))), 0); unlock_user(__hptr, __gaddr, sizeof(int32_t)); }
else __ret = -14; __ret; })
1062 || put_user_s32(host_pipe[1], pipedes + sizeof(host_pipe[0]))({ abi_ulong __gaddr = ((pipedes + sizeof(host_pipe[0]))); int32_t
*__hptr; abi_long __ret; if ((__hptr = lock_user(1, __gaddr,
sizeof(int32_t), 0))) { __ret = (__builtin_choose_expr(sizeof
(*(__hptr)) == 1, stb_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
4, stl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) == 8, stq_be_p
, abort)))) ((__hptr), (((host_pipe[1])))), 0); unlock_user(__hptr
, __gaddr, sizeof(int32_t)); } else __ret = -14; __ret; })
)
1063 return -TARGET_EFAULT14;
1064 return get_errno(ret);
1065}
1066
1067static inline abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn,
1068 abi_ulong target_addr,
1069 socklen_t len)
1070{
1071 struct target_ip_mreqn *target_smreqn;
1072
1073 target_smreqn = lock_user(VERIFY_READ0, target_addr, len, 1);
1074 if (!target_smreqn)
1075 return -TARGET_EFAULT14;
1076 mreqn->imr_multiaddr.s_addr = target_smreqn->imr_multiaddr.s_addr;
1077 mreqn->imr_address.s_addr = target_smreqn->imr_address.s_addr;
1078 if (len == sizeof(struct target_ip_mreqn))
1079 mreqn->imr_ifindex = tswapal(target_smreqn->imr_ifindex);
1080 unlock_user(target_smreqn, target_addr, 0);
1081
1082 return 0;
1083}
1084
1085static inline abi_long target_to_host_sockaddr(struct sockaddr *addr,
1086 abi_ulong target_addr,
1087 socklen_t len)
1088{
1089 const socklen_t unix_maxlen = sizeof (struct sockaddr_un);
1090 sa_family_t sa_family;
1091 struct target_sockaddr *target_saddr;
1092
1093 target_saddr = lock_user(VERIFY_READ0, target_addr, len, 1);
1094 if (!target_saddr)
1095 return -TARGET_EFAULT14;
1096
1097 sa_family = tswap16(target_saddr->sa_family);
1098
1099 /* Oops. The caller might send a incomplete sun_path; sun_path
1100 * must be terminated by \0 (see the manual page), but
1101 * unfortunately it is quite common to specify sockaddr_un
1102 * length as "strlen(x->sun_path)" while it should be
1103 * "strlen(...) + 1". We'll fix that here if needed.
1104 * Linux kernel has a similar feature.
1105 */
1106
1107 if (sa_family == AF_UNIX1) {
1108 if (len < unix_maxlen && len > 0) {
1109 char *cp = (char*)target_saddr;
1110
1111 if ( cp[len-1] && !cp[len] )
1112 len++;
1113 }
1114 if (len > unix_maxlen)
1115 len = unix_maxlen;
1116 }
1117
1118 memcpy(addr, target_saddr, len);
1119 addr->sa_family = sa_family;
1120 unlock_user(target_saddr, target_addr, 0);
1121
1122 return 0;
1123}
1124
1125static inline abi_long host_to_target_sockaddr(abi_ulong target_addr,
1126 struct sockaddr *addr,
1127 socklen_t len)
1128{
1129 struct target_sockaddr *target_saddr;
1130
1131 target_saddr = lock_user(VERIFY_WRITE1, target_addr, len, 0);
1132 if (!target_saddr)
1133 return -TARGET_EFAULT14;
1134 memcpy(target_saddr, addr, len);
1135 target_saddr->sa_family = tswap16(addr->sa_family);
1136 unlock_user(target_saddr, target_addr, len);
1137
1138 return 0;
1139}
1140
1141static inline abi_long target_to_host_cmsg(struct msghdr *msgh,
1142 struct target_msghdr *target_msgh)
1143{
1144 struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh)((size_t) (msgh)->msg_controllen >= sizeof (struct cmsghdr
) ? (struct cmsghdr *) (msgh)->msg_control : (struct cmsghdr
*) 0)
;
1145 abi_long msg_controllen;
1146 abi_ulong target_cmsg_addr;
1147 struct target_cmsghdr *target_cmsg;
1148 socklen_t space = 0;
1149
1150 msg_controllen = tswapal(target_msgh->msg_controllen);
1151 if (msg_controllen < sizeof (struct target_cmsghdr))
1152 goto the_end;
1153 target_cmsg_addr = tswapal(target_msgh->msg_control);
1154 target_cmsg = lock_user(VERIFY_READ0, target_cmsg_addr, msg_controllen, 1);
1155 if (!target_cmsg)
1156 return -TARGET_EFAULT14;
1157
1158 while (cmsg && target_cmsg) {
1159 void *data = CMSG_DATA(cmsg)((cmsg)->__cmsg_data);
1160 void *target_data = TARGET_CMSG_DATA(target_cmsg)((unsigned char *) ((struct target_cmsghdr *) (target_cmsg) +
1))
;
1161
1162 int len = tswapal(target_cmsg->cmsg_len)
1163 - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr))(((sizeof (struct target_cmsghdr)) + sizeof (abi_long) - 1) &
(size_t) ~(sizeof (abi_long) - 1))
;
1164
1165 space += CMSG_SPACE(len)((((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t
) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) &
(size_t) ~(sizeof (size_t) - 1)))
;
1166 if (space > msgh->msg_controllen) {
1167 space -= CMSG_SPACE(len)((((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t
) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) &
(size_t) ~(sizeof (size_t) - 1)))
;
1168 gemu_log("Host cmsg overflow\n");
1169 break;
1170 }
1171
1172 if (tswap32(target_cmsg->cmsg_level) == TARGET_SOL_SOCKET1) {
1173 cmsg->cmsg_level = SOL_SOCKET1;
1174 } else {
1175 cmsg->cmsg_level = tswap32(target_cmsg->cmsg_level);
1176 }
1177 cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type);
1178 cmsg->cmsg_len = CMSG_LEN(len)((((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t
) ~(sizeof (size_t) - 1)) + (len))
;
1179
1180 if (cmsg->cmsg_level != SOL_SOCKET1 || cmsg->cmsg_type != SCM_RIGHTSSCM_RIGHTS) {
1181 gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
1182 memcpy(data, target_data, len);
1183 } else {
1184 int *fd = (int *)data;
1185 int *target_fd = (int *)target_data;
1186 int i, numfds = len / sizeof(int);
1187
1188 for (i = 0; i < numfds; i++)
1189 fd[i] = tswap32(target_fd[i]);
1190 }
1191
1192 cmsg = CMSG_NXTHDR(msgh, cmsg)__cmsg_nxthdr (msgh, cmsg);
1193 target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg)__target_cmsg_nxthdr (target_msgh, target_cmsg);
1194 }
1195 unlock_user(target_cmsg, target_cmsg_addr, 0);
1196 the_end:
1197 msgh->msg_controllen = space;
1198 return 0;
1199}
1200
1201static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
1202 struct msghdr *msgh)
1203{
1204 struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh)((size_t) (msgh)->msg_controllen >= sizeof (struct cmsghdr
) ? (struct cmsghdr *) (msgh)->msg_control : (struct cmsghdr
*) 0)
;
1205 abi_long msg_controllen;
1206 abi_ulong target_cmsg_addr;
1207 struct target_cmsghdr *target_cmsg;
1208 socklen_t space = 0;
1209
1210 msg_controllen = tswapal(target_msgh->msg_controllen);
1211 if (msg_controllen < sizeof (struct target_cmsghdr))
1212 goto the_end;
1213 target_cmsg_addr = tswapal(target_msgh->msg_control);
1214 target_cmsg = lock_user(VERIFY_WRITE1, target_cmsg_addr, msg_controllen, 0);
1215 if (!target_cmsg)
1216 return -TARGET_EFAULT14;
1217
1218 while (cmsg && target_cmsg) {
1219 void *data = CMSG_DATA(cmsg)((cmsg)->__cmsg_data);
1220 void *target_data = TARGET_CMSG_DATA(target_cmsg)((unsigned char *) ((struct target_cmsghdr *) (target_cmsg) +
1))
;
1221
1222 int len = cmsg->cmsg_len - CMSG_ALIGN(sizeof (struct cmsghdr))(((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t
) ~(sizeof (size_t) - 1))
;
1223
1224 space += TARGET_CMSG_SPACE(len)((((len) + sizeof (abi_long) - 1) & (size_t) ~(sizeof (abi_long
) - 1)) + (((sizeof (struct target_cmsghdr)) + sizeof (abi_long
) - 1) & (size_t) ~(sizeof (abi_long) - 1)))
;
1225 if (space > msg_controllen) {
1226 space -= TARGET_CMSG_SPACE(len)((((len) + sizeof (abi_long) - 1) & (size_t) ~(sizeof (abi_long
) - 1)) + (((sizeof (struct target_cmsghdr)) + sizeof (abi_long
) - 1) & (size_t) ~(sizeof (abi_long) - 1)))
;
1227 gemu_log("Target cmsg overflow\n");
1228 break;
1229 }
1230
1231 if (cmsg->cmsg_level == SOL_SOCKET1) {
1232 target_cmsg->cmsg_level = tswap32(TARGET_SOL_SOCKET1);
1233 } else {
1234 target_cmsg->cmsg_level = tswap32(cmsg->cmsg_level);
1235 }
1236 target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type);
1237 target_cmsg->cmsg_len = tswapal(TARGET_CMSG_LEN(len)((((sizeof (struct target_cmsghdr)) + sizeof (abi_long) - 1) &
(size_t) ~(sizeof (abi_long) - 1)) + (len))
);
1238
1239 if ((cmsg->cmsg_level == SOL_SOCKET1) &&
1240 (cmsg->cmsg_type == SCM_RIGHTSSCM_RIGHTS)) {
1241 int *fd = (int *)data;
1242 int *target_fd = (int *)target_data;
1243 int i, numfds = len / sizeof(int);
1244
1245 for (i = 0; i < numfds; i++)
1246 target_fd[i] = tswap32(fd[i]);
1247 } else if ((cmsg->cmsg_level == SOL_SOCKET1) &&
1248 (cmsg->cmsg_type == SO_TIMESTAMP29) &&
1249 (len == sizeof(struct timeval))) {
1250 /* copy struct timeval to target */
1251 struct timeval *tv = (struct timeval *)data;
1252 struct target_timeval *target_tv =
1253 (struct target_timeval *)target_data;
1254
1255 target_tv->tv_sec = tswapal(tv->tv_sec);
1256 target_tv->tv_usec = tswapal(tv->tv_usec);
1257 } else {
1258 gemu_log("Unsupported ancillary data: %d/%d\n",
1259 cmsg->cmsg_level, cmsg->cmsg_type);
1260 memcpy(target_data, data, len);
1261 }
1262
1263 cmsg = CMSG_NXTHDR(msgh, cmsg)__cmsg_nxthdr (msgh, cmsg);
1264 target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg)__target_cmsg_nxthdr (target_msgh, target_cmsg);
1265 }
1266 unlock_user(target_cmsg, target_cmsg_addr, space);
1267 the_end:
1268 target_msgh->msg_controllen = tswapal(space);
1269 return 0;
1270}
1271
1272/* do_setsockopt() Must return target values and target errnos. */
1273static abi_long do_setsockopt(int sockfd, int level, int optname,
1274 abi_ulong optval_addr, socklen_t optlen)
1275{
1276 abi_long ret;
1277 int val;
1278 struct ip_mreqn *ip_mreq;
1279 struct ip_mreq_source *ip_mreq_source;
1280
1281 switch(level) {
1282 case SOL_TCP6:
1283 /* TCP options all take an 'int' value. */
1284 if (optlen < sizeof(uint32_t))
1285 return -TARGET_EINVAL22;
1286
1287 if (get_user_u32(val, optval_addr)({ abi_ulong __gaddr = ((optval_addr)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(uint32_t),
1))) { __ret = ((((val))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((val)) = 0; __ret = -14; } __ret; })
)
1288 return -TARGET_EFAULT14;
1289 ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
1290 break;
1291 case SOL_IP0:
1292 switch(optname) {
1293 case IP_TOS1:
1294 case IP_TTL2:
1295 case IP_HDRINCL3:
1296 case IP_ROUTER_ALERT5:
1297 case IP_RECVOPTS6:
1298 case IP_RETOPTS7:
1299 case IP_PKTINFO8:
1300 case IP_MTU_DISCOVER10:
1301 case IP_RECVERR11:
1302 case IP_RECVTOS13:
1303#ifdef IP_FREEBIND15
1304 case IP_FREEBIND15:
1305#endif
1306 case IP_MULTICAST_TTL33:
1307 case IP_MULTICAST_LOOP34:
1308 val = 0;
1309 if (optlen >= sizeof(uint32_t)) {
1310 if (get_user_u32(val, optval_addr)({ abi_ulong __gaddr = ((optval_addr)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(uint32_t),
1))) { __ret = ((((val))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((val)) = 0; __ret = -14; } __ret; })
)
1311 return -TARGET_EFAULT14;
1312 } else if (optlen >= 1) {
1313 if (get_user_u8(val, optval_addr)({ abi_ulong __gaddr = ((optval_addr)); uint8_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(uint8_t), 1
))) { __ret = ((((val))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((val)) = 0; __ret = -14; } __ret; })
)
1314 return -TARGET_EFAULT14;
1315 }
1316 ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
1317 break;
1318 case IP_ADD_MEMBERSHIP35:
1319 case IP_DROP_MEMBERSHIP36:
1320 if (optlen < sizeof (struct target_ip_mreq) ||
1321 optlen > sizeof (struct target_ip_mreqn))
1322 return -TARGET_EINVAL22;
1323
1324 ip_mreq = (struct ip_mreqn *) alloca(optlen)__builtin_alloca (optlen);
1325 target_to_host_ip_mreq(ip_mreq, optval_addr, optlen);
1326 ret = get_errno(setsockopt(sockfd, level, optname, ip_mreq, optlen));
1327 break;
1328
1329 case IP_BLOCK_SOURCE38:
1330 case IP_UNBLOCK_SOURCE37:
1331 case IP_ADD_SOURCE_MEMBERSHIP39:
1332 case IP_DROP_SOURCE_MEMBERSHIP40:
1333 if (optlen != sizeof (struct target_ip_mreq_source))
1334 return -TARGET_EINVAL22;
1335
1336 ip_mreq_source = lock_user(VERIFY_READ0, optval_addr, optlen, 1);
1337 ret = get_errno(setsockopt(sockfd, level, optname, ip_mreq_source, optlen));
1338 unlock_user (ip_mreq_source, optval_addr, 0);
1339 break;
1340
1341 default:
1342 goto unimplemented;
1343 }
1344 break;
1345 case SOL_IPV641:
1346 switch (optname) {
1347 case IPV6_MTU_DISCOVER23:
1348 case IPV6_MTU24:
1349 case IPV6_V6ONLY26:
1350 case IPV6_RECVPKTINFO49:
1351 val = 0;
1352 if (optlen < sizeof(uint32_t)) {
1353 return -TARGET_EINVAL22;
1354 }
1355 if (get_user_u32(val, optval_addr)({ abi_ulong __gaddr = ((optval_addr)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(uint32_t),
1))) { __ret = ((((val))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((val)) = 0; __ret = -14; } __ret; })
) {
1356 return -TARGET_EFAULT14;
1357 }
1358 ret = get_errno(setsockopt(sockfd, level, optname,
1359 &val, sizeof(val)));
1360 break;
1361 default:
1362 goto unimplemented;
1363 }
1364 break;
1365 case SOL_RAW255:
1366 switch (optname) {
1367 case ICMP_FILTER1:
1368 /* struct icmp_filter takes an u32 value */
1369 if (optlen < sizeof(uint32_t)) {
1370 return -TARGET_EINVAL22;
1371 }
1372
1373 if (get_user_u32(val, optval_addr)({ abi_ulong __gaddr = ((optval_addr)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(uint32_t),
1))) { __ret = ((((val))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((val)) = 0; __ret = -14; } __ret; })
) {
1374 return -TARGET_EFAULT14;
1375 }
1376 ret = get_errno(setsockopt(sockfd, level, optname,
1377 &val, sizeof(val)));
1378 break;
1379
1380 default:
1381 goto unimplemented;
1382 }
1383 break;
1384 case TARGET_SOL_SOCKET1:
1385 switch (optname) {
1386 case TARGET_SO_RCVTIMEO20:
1387 {
1388 struct timeval tv;
1389
1390 optname = SO_RCVTIMEO20;
1391
1392set_timeout:
1393 if (optlen != sizeof(struct target_timeval)) {
1394 return -TARGET_EINVAL22;
1395 }
1396
1397 if (copy_from_user_timeval(&tv, optval_addr)) {
1398 return -TARGET_EFAULT14;
1399 }
1400
1401 ret = get_errno(setsockopt(sockfd, SOL_SOCKET1, optname,
1402 &tv, sizeof(tv)));
1403 return ret;
1404 }
1405 case TARGET_SO_SNDTIMEO21:
1406 optname = SO_SNDTIMEO21;
1407 goto set_timeout;
1408 case TARGET_SO_ATTACH_FILTER26:
1409 {
1410 struct target_sock_fprog *tfprog;
1411 struct target_sock_filter *tfilter;
1412 struct sock_fprog fprog;
1413 struct sock_filter *filter;
1414 int i;
1415
1416 if (optlen != sizeof(*tfprog)) {
1417 return -TARGET_EINVAL22;
1418 }
1419 if (!lock_user_struct(VERIFY_READ, tfprog, optval_addr, 0)(tfprog = lock_user(0, optval_addr, sizeof(*tfprog), 0))) {
1420 return -TARGET_EFAULT14;
1421 }
1422 if (!lock_user_struct(VERIFY_READ, tfilter,(tfilter = lock_user(0, tswapal(tfprog->filter), sizeof(*tfilter
), 0))
1423 tswapal(tfprog->filter), 0)(tfilter = lock_user(0, tswapal(tfprog->filter), sizeof(*tfilter
), 0))
) {
1424 unlock_user_struct(tfprog, optval_addr, 1)unlock_user(tfprog, optval_addr, (1) ? sizeof(*tfprog) : 0);
1425 return -TARGET_EFAULT14;
1426 }
1427
1428 fprog.len = tswap16(tfprog->len);
1429 filter = malloc(fprog.len * sizeof(*filter));
1430 if (filter == NULL((void*)0)) {
1431 unlock_user_struct(tfilter, tfprog->filter, 1)unlock_user(tfilter, tfprog->filter, (1) ? sizeof(*tfilter
) : 0)
;
1432 unlock_user_struct(tfprog, optval_addr, 1)unlock_user(tfprog, optval_addr, (1) ? sizeof(*tfprog) : 0);
1433 return -TARGET_ENOMEM12;
1434 }
1435 for (i = 0; i < fprog.len; i++) {
1436 filter[i].code = tswap16(tfilter[i].code);
1437 filter[i].jt = tfilter[i].jt;
1438 filter[i].jf = tfilter[i].jf;
1439 filter[i].k = tswap32(tfilter[i].k);
1440 }
1441 fprog.filter = filter;
1442
1443 ret = get_errno(setsockopt(sockfd, SOL_SOCKET1,
1444 SO_ATTACH_FILTER26, &fprog, sizeof(fprog)));
1445 free(filter);
1446
1447 unlock_user_struct(tfilter, tfprog->filter, 1)unlock_user(tfilter, tfprog->filter, (1) ? sizeof(*tfilter
) : 0)
;
1448 unlock_user_struct(tfprog, optval_addr, 1)unlock_user(tfprog, optval_addr, (1) ? sizeof(*tfprog) : 0);
1449 return ret;
1450 }
1451 /* Options with 'int' argument. */
1452 case TARGET_SO_DEBUG1:
1453 optname = SO_DEBUG1;
1454 break;
1455 case TARGET_SO_REUSEADDR2:
1456 optname = SO_REUSEADDR2;
1457 break;
1458 case TARGET_SO_TYPE3:
1459 optname = SO_TYPE3;
1460 break;
1461 case TARGET_SO_ERROR4:
1462 optname = SO_ERROR4;
1463 break;
1464 case TARGET_SO_DONTROUTE5:
1465 optname = SO_DONTROUTE5;
1466 break;
1467 case TARGET_SO_BROADCAST6:
1468 optname = SO_BROADCAST6;
1469 break;
1470 case TARGET_SO_SNDBUF7:
1471 optname = SO_SNDBUF7;
1472 break;
1473 case TARGET_SO_RCVBUF8:
1474 optname = SO_RCVBUF8;
1475 break;
1476 case TARGET_SO_KEEPALIVE9:
1477 optname = SO_KEEPALIVE9;
1478 break;
1479 case TARGET_SO_OOBINLINE10:
1480 optname = SO_OOBINLINE10;
1481 break;
1482 case TARGET_SO_NO_CHECK11:
1483 optname = SO_NO_CHECK11;
1484 break;
1485 case TARGET_SO_PRIORITY12:
1486 optname = SO_PRIORITY12;
1487 break;
1488#ifdef SO_BSDCOMPAT14
1489 case TARGET_SO_BSDCOMPAT14:
1490 optname = SO_BSDCOMPAT14;
1491 break;
1492#endif
1493 case TARGET_SO_PASSCRED16:
1494 optname = SO_PASSCRED16;
1495 break;
1496 case TARGET_SO_TIMESTAMP29:
1497 optname = SO_TIMESTAMP29;
1498 break;
1499 case TARGET_SO_RCVLOWAT18:
1500 optname = SO_RCVLOWAT18;
1501 break;
1502 break;
1503 default:
1504 goto unimplemented;
1505 }
1506 if (optlen < sizeof(uint32_t))
1507 return -TARGET_EINVAL22;
1508
1509 if (get_user_u32(val, optval_addr)({ abi_ulong __gaddr = ((optval_addr)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(uint32_t),
1))) { __ret = ((((val))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((val)) = 0; __ret = -14; } __ret; })
)
1510 return -TARGET_EFAULT14;
1511 ret = get_errno(setsockopt(sockfd, SOL_SOCKET1, optname, &val, sizeof(val)));
1512 break;
1513 default:
1514 unimplemented:
1515 gemu_log("Unsupported setsockopt level=%d optname=%d\n", level, optname);
1516 ret = -TARGET_ENOPROTOOPT92;
1517 }
1518 return ret;
1519}
1520
1521/* do_getsockopt() Must return target values and target errnos. */
1522static abi_long do_getsockopt(int sockfd, int level, int optname,
1523 abi_ulong optval_addr, abi_ulong optlen)
1524{
1525 abi_long ret;
1526 int len, val;
1527 socklen_t lv;
1528
1529 switch(level) {
1530 case TARGET_SOL_SOCKET1:
1531 level = SOL_SOCKET1;
1532 switch (optname) {
1533 /* These don't just return a single integer */
1534 case TARGET_SO_LINGER13:
1535 case TARGET_SO_RCVTIMEO20:
1536 case TARGET_SO_SNDTIMEO21:
1537 case TARGET_SO_PEERNAME28:
1538 goto unimplemented;
1539 case TARGET_SO_PEERCRED17: {
1540 struct ucred cr;
1541 socklen_t crlen;
1542 struct target_ucred *tcr;
1543
1544 if (get_user_u32(len, optlen)({ abi_ulong __gaddr = ((optlen)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(uint32_t),
1))) { __ret = ((((len))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((len)) = 0; __ret = -14; } __ret; })
) {
1545 return -TARGET_EFAULT14;
1546 }
1547 if (len < 0) {
1548 return -TARGET_EINVAL22;
1549 }
1550
1551 crlen = sizeof(cr);
1552 ret = get_errno(getsockopt(sockfd, level, SO_PEERCRED17,
1553 &cr, &crlen));
1554 if (ret < 0) {
1555 return ret;
1556 }
1557 if (len > crlen) {
1558 len = crlen;
1559 }
1560 if (!lock_user_struct(VERIFY_WRITE, tcr, optval_addr, 0)(tcr = lock_user(1, optval_addr, sizeof(*tcr), 0))) {
1561 return -TARGET_EFAULT14;
1562 }
1563 __put_user(cr.pid, &tcr->pid)(__builtin_choose_expr(sizeof(*(&tcr->pid)) == 1, stb_p
, __builtin_choose_expr(sizeof(*(&tcr->pid)) == 2, stw_be_p
, __builtin_choose_expr(sizeof(*(&tcr->pid)) == 4, stl_be_p
, __builtin_choose_expr(sizeof(*(&tcr->pid)) == 8, stq_be_p
, abort)))) ((&tcr->pid), (cr.pid)), 0)
;
1564 __put_user(cr.uid, &tcr->uid)(__builtin_choose_expr(sizeof(*(&tcr->uid)) == 1, stb_p
, __builtin_choose_expr(sizeof(*(&tcr->uid)) == 2, stw_be_p
, __builtin_choose_expr(sizeof(*(&tcr->uid)) == 4, stl_be_p
, __builtin_choose_expr(sizeof(*(&tcr->uid)) == 8, stq_be_p
, abort)))) ((&tcr->uid), (cr.uid)), 0)
;
1565 __put_user(cr.gid, &tcr->gid)(__builtin_choose_expr(sizeof(*(&tcr->gid)) == 1, stb_p
, __builtin_choose_expr(sizeof(*(&tcr->gid)) == 2, stw_be_p
, __builtin_choose_expr(sizeof(*(&tcr->gid)) == 4, stl_be_p
, __builtin_choose_expr(sizeof(*(&tcr->gid)) == 8, stq_be_p
, abort)))) ((&tcr->gid), (cr.gid)), 0)
;
1566 unlock_user_struct(tcr, optval_addr, 1)unlock_user(tcr, optval_addr, (1) ? sizeof(*tcr) : 0);
1567 if (put_user_u32(len, optlen)({ abi_ulong __gaddr = ((optlen)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(1, __gaddr, sizeof(uint32_t),
0))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1
, stb_p, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), (((len
)))), 0); unlock_user(__hptr, __gaddr, sizeof(uint32_t)); } else
__ret = -14; __ret; })
) {
1568 return -TARGET_EFAULT14;
1569 }
1570 break;
1571 }
1572 /* Options with 'int' argument. */
1573 case TARGET_SO_DEBUG1:
1574 optname = SO_DEBUG1;
1575 goto int_case;
1576 case TARGET_SO_REUSEADDR2:
1577 optname = SO_REUSEADDR2;
1578 goto int_case;
1579 case TARGET_SO_TYPE3:
1580 optname = SO_TYPE3;
1581 goto int_case;
1582 case TARGET_SO_ERROR4:
1583 optname = SO_ERROR4;
1584 goto int_case;
1585 case TARGET_SO_DONTROUTE5:
1586 optname = SO_DONTROUTE5;
1587 goto int_case;
1588 case TARGET_SO_BROADCAST6:
1589 optname = SO_BROADCAST6;
1590 goto int_case;
1591 case TARGET_SO_SNDBUF7:
1592 optname = SO_SNDBUF7;
1593 goto int_case;
1594 case TARGET_SO_RCVBUF8:
1595 optname = SO_RCVBUF8;
1596 goto int_case;
1597 case TARGET_SO_KEEPALIVE9:
1598 optname = SO_KEEPALIVE9;
1599 goto int_case;
1600 case TARGET_SO_OOBINLINE10:
1601 optname = SO_OOBINLINE10;
1602 goto int_case;
1603 case TARGET_SO_NO_CHECK11:
1604 optname = SO_NO_CHECK11;
1605 goto int_case;
1606 case TARGET_SO_PRIORITY12:
1607 optname = SO_PRIORITY12;
1608 goto int_case;
1609#ifdef SO_BSDCOMPAT14
1610 case TARGET_SO_BSDCOMPAT14:
1611 optname = SO_BSDCOMPAT14;
1612 goto int_case;
1613#endif
1614 case TARGET_SO_PASSCRED16:
1615 optname = SO_PASSCRED16;
1616 goto int_case;
1617 case TARGET_SO_TIMESTAMP29:
1618 optname = SO_TIMESTAMP29;
1619 goto int_case;
1620 case TARGET_SO_RCVLOWAT18:
1621 optname = SO_RCVLOWAT18;
1622 goto int_case;
1623 default:
1624 goto int_case;
1625 }
1626 break;
1627 case SOL_TCP6:
1628 /* TCP options all take an 'int' value. */
1629 int_case:
1630 if (get_user_u32(len, optlen)({ abi_ulong __gaddr = ((optlen)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(uint32_t),
1))) { __ret = ((((len))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((len)) = 0; __ret = -14; } __ret; })
)
1631 return -TARGET_EFAULT14;
1632 if (len < 0)
1633 return -TARGET_EINVAL22;
1634 lv = sizeof(lv);
1635 ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
1636 if (ret < 0)
1637 return ret;
1638 if (len > lv)
1639 len = lv;
1640 if (len == 4) {
1641 if (put_user_u32(val, optval_addr)({ abi_ulong __gaddr = ((optval_addr)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(1, __gaddr, sizeof(uint32_t),
0))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1
, stb_p, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), (((val
)))), 0); unlock_user(__hptr, __gaddr, sizeof(uint32_t)); } else
__ret = -14; __ret; })
)
1642 return -TARGET_EFAULT14;
1643 } else {
1644 if (put_user_u8(val, optval_addr)({ abi_ulong __gaddr = ((optval_addr)); uint8_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(1, __gaddr, sizeof(uint8_t), 0
))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1, stb_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), (((val)))), 0
); unlock_user(__hptr, __gaddr, sizeof(uint8_t)); } else __ret
= -14; __ret; })
)
1645 return -TARGET_EFAULT14;
1646 }
1647 if (put_user_u32(len, optlen)({ abi_ulong __gaddr = ((optlen)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(1, __gaddr, sizeof(uint32_t),
0))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1
, stb_p, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), (((len
)))), 0); unlock_user(__hptr, __gaddr, sizeof(uint32_t)); } else
__ret = -14; __ret; })
)
1648 return -TARGET_EFAULT14;
1649 break;
1650 case SOL_IP0:
1651 switch(optname) {
1652 case IP_TOS1:
1653 case IP_TTL2:
1654 case IP_HDRINCL3:
1655 case IP_ROUTER_ALERT5:
1656 case IP_RECVOPTS6:
1657 case IP_RETOPTS7:
1658 case IP_PKTINFO8:
1659 case IP_MTU_DISCOVER10:
1660 case IP_RECVERR11:
1661 case IP_RECVTOS13:
1662#ifdef IP_FREEBIND15
1663 case IP_FREEBIND15:
1664#endif
1665 case IP_MULTICAST_TTL33:
1666 case IP_MULTICAST_LOOP34:
1667 if (get_user_u32(len, optlen)({ abi_ulong __gaddr = ((optlen)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(uint32_t),
1))) { __ret = ((((len))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((len)) = 0; __ret = -14; } __ret; })
)
1668 return -TARGET_EFAULT14;
1669 if (len < 0)
1670 return -TARGET_EINVAL22;
1671 lv = sizeof(lv);
1672 ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
1673 if (ret < 0)
1674 return ret;
1675 if (len < sizeof(int) && len > 0 && val >= 0 && val < 255) {
1676 len = 1;
1677 if (put_user_u32(len, optlen)({ abi_ulong __gaddr = ((optlen)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(1, __gaddr, sizeof(uint32_t),
0))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1
, stb_p, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), (((len
)))), 0); unlock_user(__hptr, __gaddr, sizeof(uint32_t)); } else
__ret = -14; __ret; })
1678 || put_user_u8(val, optval_addr)({ abi_ulong __gaddr = ((optval_addr)); uint8_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(1, __gaddr, sizeof(uint8_t), 0
))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1, stb_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), (((val)))), 0
); unlock_user(__hptr, __gaddr, sizeof(uint8_t)); } else __ret
= -14; __ret; })
)
1679 return -TARGET_EFAULT14;
1680 } else {
1681 if (len > sizeof(int))
1682 len = sizeof(int);
1683 if (put_user_u32(len, optlen)({ abi_ulong __gaddr = ((optlen)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(1, __gaddr, sizeof(uint32_t),
0))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1
, stb_p, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), (((len
)))), 0); unlock_user(__hptr, __gaddr, sizeof(uint32_t)); } else
__ret = -14; __ret; })
1684 || put_user_u32(val, optval_addr)({ abi_ulong __gaddr = ((optval_addr)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(1, __gaddr, sizeof(uint32_t),
0))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1
, stb_p, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), (((val
)))), 0); unlock_user(__hptr, __gaddr, sizeof(uint32_t)); } else
__ret = -14; __ret; })
)
1685 return -TARGET_EFAULT14;
1686 }
1687 break;
1688 default:
1689 ret = -TARGET_ENOPROTOOPT92;
1690 break;
1691 }
1692 break;
1693 default:
1694 unimplemented:
1695 gemu_log("getsockopt level=%d optname=%d not yet supported\n",
1696 level, optname);
1697 ret = -TARGET_EOPNOTSUPP95;
1698 break;
1699 }
1700 return ret;
1701}
1702
1703static struct iovec *lock_iovec(int type, abi_ulong target_addr,
1704 int count, int copy)
1705{
1706 struct target_iovec *target_vec;
1707 struct iovec *vec;
1708 abi_ulong total_len, max_len;
1709 int i;
1710
1711 if (count == 0) {
1712 errno(*__errno_location ()) = 0;
1713 return NULL((void*)0);
1714 }
1715 if (count < 0 || count > IOV_MAX1024) {
1716 errno(*__errno_location ()) = EINVAL22;
1717 return NULL((void*)0);
1718 }
1719
1720 vec = calloc(count, sizeof(struct iovec));
1721 if (vec == NULL((void*)0)) {
1722 errno(*__errno_location ()) = ENOMEM12;
1723 return NULL((void*)0);
1724 }
1725
1726 target_vec = lock_user(VERIFY_READ0, target_addr,
1727 count * sizeof(struct target_iovec), 1);
1728 if (target_vec == NULL((void*)0)) {
1729 errno(*__errno_location ()) = EFAULT14;
1730 goto fail2;
1731 }
1732
1733 /* ??? If host page size > target page size, this will result in a
1734 value larger than what we can actually support. */
1735 max_len = 0x7fffffff & TARGET_PAGE_MASK~((1 << 12) - 1);
1736 total_len = 0;
1737
1738 for (i = 0; i < count; i++) {
1739 abi_ulong base = tswapal(target_vec[i].iov_base);
1740 abi_long len = tswapal(target_vec[i].iov_len);
1741
1742 if (len < 0) {
1743 errno(*__errno_location ()) = EINVAL22;
1744 goto fail;
1745 } else if (len == 0) {
1746 /* Zero length pointer is ignored. */
1747 vec[i].iov_base = 0;
1748 } else {
1749 vec[i].iov_base = lock_user(type, base, len, copy);
1750 if (!vec[i].iov_base) {
1751 errno(*__errno_location ()) = EFAULT14;
1752 goto fail;
1753 }
1754 if (len > max_len - total_len) {
1755 len = max_len - total_len;
1756 }
1757 }
1758 vec[i].iov_len = len;
1759 total_len += len;
1760 }
1761
1762 unlock_user(target_vec, target_addr, 0);
1763 return vec;
1764
1765 fail:
1766 free(vec);
1767 fail2:
1768 unlock_user(target_vec, target_addr, 0);
1769 return NULL((void*)0);
1770}
1771
1772static void unlock_iovec(struct iovec *vec, abi_ulong target_addr,
1773 int count, int copy)
1774{
1775 struct target_iovec *target_vec;
1776 int i;
1777
1778 target_vec = lock_user(VERIFY_READ0, target_addr,
1779 count * sizeof(struct target_iovec), 1);
1780 if (target_vec) {
1781 for (i = 0; i < count; i++) {
1782 abi_ulong base = tswapal(target_vec[i].iov_base);
1783 abi_long len = tswapal(target_vec[i].iov_base);
1784 if (len < 0) {
1785 break;
1786 }
1787 unlock_user(vec[i].iov_base, base, copy ? vec[i].iov_len : 0);
1788 }
1789 unlock_user(target_vec, target_addr, 0);
1790 }
1791
1792 free(vec);
1793}
1794
1795static inline int target_to_host_sock_type(int *type)
1796{
1797 int host_type = 0;
1798 int target_type = *type;
1799
1800 switch (target_type & TARGET_SOCK_TYPE_MASK0xf) {
1801 case TARGET_SOCK_DGRAM:
1802 host_type = SOCK_DGRAMSOCK_DGRAM;
1803 break;
1804 case TARGET_SOCK_STREAM:
1805 host_type = SOCK_STREAMSOCK_STREAM;
1806 break;
1807 default:
1808 host_type = target_type & TARGET_SOCK_TYPE_MASK0xf;
1809 break;
1810 }
1811 if (target_type & TARGET_SOCK_CLOEXEC) {
1812#if defined(SOCK_CLOEXECSOCK_CLOEXEC)
1813 host_type |= SOCK_CLOEXECSOCK_CLOEXEC;
1814#else
1815 return -TARGET_EINVAL22;
1816#endif
1817 }
1818 if (target_type & TARGET_SOCK_NONBLOCK) {
1819#if defined(SOCK_NONBLOCKSOCK_NONBLOCK)
1820 host_type |= SOCK_NONBLOCKSOCK_NONBLOCK;
1821#elif !defined(O_NONBLOCK04000)
1822 return -TARGET_EINVAL22;
1823#endif
1824 }
1825 *type = host_type;
1826 return 0;
1827}
1828
1829/* Try to emulate socket type flags after socket creation. */
1830static int sock_flags_fixup(int fd, int target_type)
1831{
1832#if !defined(SOCK_NONBLOCKSOCK_NONBLOCK) && defined(O_NONBLOCK04000)
1833 if (target_type & TARGET_SOCK_NONBLOCK) {
1834 int flags = fcntl(fd, F_GETFL3);
1835 if (fcntl(fd, F_SETFL4, O_NONBLOCK04000 | flags) == -1) {
1836 close(fd);
1837 return -TARGET_EINVAL22;
1838 }
1839 }
1840#endif
1841 return fd;
1842}
1843
1844/* do_socket() Must return target values and target errnos. */
1845static abi_long do_socket(int domain, int type, int protocol)
1846{
1847 int target_type = type;
1848 int ret;
1849
1850 ret = target_to_host_sock_type(&type);
1851 if (ret) {
1852 return ret;
1853 }
1854
1855 if (domain == PF_NETLINK16)
1856 return -EAFNOSUPPORT97; /* do not NETLINK socket connections possible */
1857 ret = get_errno(socket(domain, type, protocol));
1858 if (ret >= 0) {
1859 ret = sock_flags_fixup(ret, target_type);
1860 }
1861 return ret;
1862}
1863
1864/* do_bind() Must return target values and target errnos. */
1865static abi_long do_bind(int sockfd, abi_ulong target_addr,
1866 socklen_t addrlen)
1867{
1868 void *addr;
1869 abi_long ret;
1870
1871 if ((int)addrlen < 0) {
1872 return -TARGET_EINVAL22;
1873 }
1874
1875 addr = alloca(addrlen+1)__builtin_alloca (addrlen+1);
1876
1877 ret = target_to_host_sockaddr(addr, target_addr, addrlen);
1878 if (ret)
1879 return ret;
1880
1881 return get_errno(bind(sockfd, addr, addrlen));
1882}
1883
1884/* do_connect() Must return target values and target errnos. */
1885static abi_long do_connect(int sockfd, abi_ulong target_addr,
1886 socklen_t addrlen)
1887{
1888 void *addr;
1889 abi_long ret;
1890
1891 if ((int)addrlen < 0) {
1892 return -TARGET_EINVAL22;
1893 }
1894
1895 addr = alloca(addrlen)__builtin_alloca (addrlen);
1896
1897 ret = target_to_host_sockaddr(addr, target_addr, addrlen);
1898 if (ret)
1899 return ret;
1900
1901 return get_errno(connect(sockfd, addr, addrlen));
1902}
1903
1904/* do_sendrecvmsg() Must return target values and target errnos. */
1905static abi_long do_sendrecvmsg(int fd, abi_ulong target_msg,
1906 int flags, int send)
1907{
1908 abi_long ret, len;
1909 struct target_msghdr *msgp;
1910 struct msghdr msg;
1911 int count;
1912 struct iovec *vec;
1913 abi_ulong target_vec;
1914
1915 /* FIXME */
1916 if (!lock_user_struct(send ? VERIFY_READ : VERIFY_WRITE,(msgp = lock_user(send ? 0 : 1, target_msg, sizeof(*msgp), send
? 1 : 0))
1917 msgp,(msgp = lock_user(send ? 0 : 1, target_msg, sizeof(*msgp), send
? 1 : 0))
1918 target_msg,(msgp = lock_user(send ? 0 : 1, target_msg, sizeof(*msgp), send
? 1 : 0))
1919 send ? 1 : 0)(msgp = lock_user(send ? 0 : 1, target_msg, sizeof(*msgp), send
? 1 : 0))
)
1920 return -TARGET_EFAULT14;
1921 if (msgp->msg_name) {
1922 msg.msg_namelen = tswap32(msgp->msg_namelen);
1923 msg.msg_name = alloca(msg.msg_namelen)__builtin_alloca (msg.msg_namelen);
1924 ret = target_to_host_sockaddr(msg.msg_name, tswapal(msgp->msg_name),
1925 msg.msg_namelen);
1926 if (ret) {
1927 goto out2;
1928 }
1929 } else {
1930 msg.msg_name = NULL((void*)0);
1931 msg.msg_namelen = 0;
1932 }
1933 msg.msg_controllen = 2 * tswapal(msgp->msg_controllen);
1934 msg.msg_control = alloca(msg.msg_controllen)__builtin_alloca (msg.msg_controllen);
1935 msg.msg_flags = tswap32(msgp->msg_flags);
1936
1937 count = tswapal(msgp->msg_iovlen);
1938 target_vec = tswapal(msgp->msg_iov);
1939 vec = lock_iovec(send ? VERIFY_READ0 : VERIFY_WRITE1,
1940 target_vec, count, send);
1941 if (vec == NULL((void*)0)) {
1942 ret = -host_to_target_errno(errno(*__errno_location ()));
1943 goto out2;
1944 }
1945 msg.msg_iovlen = count;
1946 msg.msg_iov = vec;
1947
1948 if (send) {
1949 ret = target_to_host_cmsg(&msg, msgp);
1950 if (ret == 0)
1951 ret = get_errno(sendmsg(fd, &msg, flags));
1952 } else {
1953 ret = get_errno(recvmsg(fd, &msg, flags));
1954 if (!is_error(ret)) {
1955 len = ret;
1956 ret = host_to_target_cmsg(msgp, &msg);
1957 if (!is_error(ret)) {
1958 msgp->msg_namelen = tswap32(msg.msg_namelen);
1959 if (msg.msg_name != NULL((void*)0)) {
1960 ret = host_to_target_sockaddr(tswapal(msgp->msg_name),
1961 msg.msg_name, msg.msg_namelen);
1962 if (ret) {
1963 goto out;
1964 }
1965 }
1966
1967 ret = len;
1968 }
1969 }
1970 }
1971
1972out:
1973 unlock_iovec(vec, target_vec, count, !send);
1974out2:
1975 unlock_user_struct(msgp, target_msg, send ? 0 : 1)unlock_user(msgp, target_msg, (send ? 0 : 1) ? sizeof(*msgp) :
0)
;
1976 return ret;
1977}
1978
1979/* If we don't have a system accept4() then just call accept.
1980 * The callsites to do_accept4() will ensure that they don't
1981 * pass a non-zero flags argument in this config.
1982 */
1983#ifndef CONFIG_ACCEPT41
1984static inline int accept4(int sockfd, struct sockaddr *addr,
1985 socklen_t *addrlen, int flags)
1986{
1987 assert(flags == 0)((flags == 0) ? (void) (0) : __assert_fail ("flags == 0", "/home/stefan/src/qemu/qemu.org/qemu/linux-user/syscall.c"
, 1987, __PRETTY_FUNCTION__))
;
1988 return accept(sockfd, addr, addrlen);
1989}
1990#endif
1991
1992/* do_accept4() Must return target values and target errnos. */
1993static abi_long do_accept4(int fd, abi_ulong target_addr,
1994 abi_ulong target_addrlen_addr, int flags)
1995{
1996 socklen_t addrlen;
1997 void *addr;
1998 abi_long ret;
1999
2000 if (target_addr == 0) {
2001 return get_errno(accept4(fd, NULL((void*)0), NULL((void*)0), flags));
2002 }
2003
2004 /* linux returns EINVAL if addrlen pointer is invalid */
2005 if (get_user_u32(addrlen, target_addrlen_addr)({ abi_ulong __gaddr = ((target_addrlen_addr)); uint32_t *__hptr
; abi_long __ret; if ((__hptr = lock_user(0, __gaddr, sizeof(
uint32_t), 1))) { __ret = ((((addrlen))) = (typeof(*__hptr))(
__builtin_choose_expr(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr
, __gaddr, 0); } else { ((addrlen)) = 0; __ret = -14; } __ret
; })
)
2006 return -TARGET_EINVAL22;
2007
2008 if ((int)addrlen < 0) {
2009 return -TARGET_EINVAL22;
2010 }
2011
2012 if (!access_ok(VERIFY_WRITE1, target_addr, addrlen))
2013 return -TARGET_EINVAL22;
2014
2015 addr = alloca(addrlen)__builtin_alloca (addrlen);
2016
2017 ret = get_errno(accept4(fd, addr, &addrlen, flags));
2018 if (!is_error(ret)) {
2019 host_to_target_sockaddr(target_addr, addr, addrlen);
2020 if (put_user_u32(addrlen, target_addrlen_addr)({ abi_ulong __gaddr = ((target_addrlen_addr)); uint32_t *__hptr
; abi_long __ret; if ((__hptr = lock_user(1, __gaddr, sizeof(
uint32_t), 0))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(__hptr)) == 2,
stw_be_p, __builtin_choose_expr(sizeof(*(__hptr)) == 4, stl_be_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 8, stq_be_p, abort
)))) ((__hptr), (((addrlen)))), 0); unlock_user(__hptr, __gaddr
, sizeof(uint32_t)); } else __ret = -14; __ret; })
)
2021 ret = -TARGET_EFAULT14;
2022 }
2023 return ret;
2024}
2025
2026/* do_getpeername() Must return target values and target errnos. */
2027static abi_long do_getpeername(int fd, abi_ulong target_addr,
2028 abi_ulong target_addrlen_addr)
2029{
2030 socklen_t addrlen;
2031 void *addr;
2032 abi_long ret;
2033
2034 if (get_user_u32(addrlen, target_addrlen_addr)({ abi_ulong __gaddr = ((target_addrlen_addr)); uint32_t *__hptr
; abi_long __ret; if ((__hptr = lock_user(0, __gaddr, sizeof(
uint32_t), 1))) { __ret = ((((addrlen))) = (typeof(*__hptr))(
__builtin_choose_expr(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr
, __gaddr, 0); } else { ((addrlen)) = 0; __ret = -14; } __ret
; })
)
2035 return -TARGET_EFAULT14;
2036
2037 if ((int)addrlen < 0) {
2038 return -TARGET_EINVAL22;
2039 }
2040
2041 if (!access_ok(VERIFY_WRITE1, target_addr, addrlen))
2042 return -TARGET_EFAULT14;
2043
2044 addr = alloca(addrlen)__builtin_alloca (addrlen);
2045
2046 ret = get_errno(getpeername(fd, addr, &addrlen));
2047 if (!is_error(ret)) {
2048 host_to_target_sockaddr(target_addr, addr, addrlen);
2049 if (put_user_u32(addrlen, target_addrlen_addr)({ abi_ulong __gaddr = ((target_addrlen_addr)); uint32_t *__hptr
; abi_long __ret; if ((__hptr = lock_user(1, __gaddr, sizeof(
uint32_t), 0))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(__hptr)) == 2,
stw_be_p, __builtin_choose_expr(sizeof(*(__hptr)) == 4, stl_be_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 8, stq_be_p, abort
)))) ((__hptr), (((addrlen)))), 0); unlock_user(__hptr, __gaddr
, sizeof(uint32_t)); } else __ret = -14; __ret; })
)
2050 ret = -TARGET_EFAULT14;
2051 }
2052 return ret;
2053}
2054
2055/* do_getsockname() Must return target values and target errnos. */
2056static abi_long do_getsockname(int fd, abi_ulong target_addr,
2057 abi_ulong target_addrlen_addr)
2058{
2059 socklen_t addrlen;
2060 void *addr;
2061 abi_long ret;
2062
2063 if (get_user_u32(addrlen, target_addrlen_addr)({ abi_ulong __gaddr = ((target_addrlen_addr)); uint32_t *__hptr
; abi_long __ret; if ((__hptr = lock_user(0, __gaddr, sizeof(
uint32_t), 1))) { __ret = ((((addrlen))) = (typeof(*__hptr))(
__builtin_choose_expr(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr
, __gaddr, 0); } else { ((addrlen)) = 0; __ret = -14; } __ret
; })
)
2064 return -TARGET_EFAULT14;
2065
2066 if ((int)addrlen < 0) {
2067 return -TARGET_EINVAL22;
2068 }
2069
2070 if (!access_ok(VERIFY_WRITE1, target_addr, addrlen))
2071 return -TARGET_EFAULT14;
2072
2073 addr = alloca(addrlen)__builtin_alloca (addrlen);
2074
2075 ret = get_errno(getsockname(fd, addr, &addrlen));
2076 if (!is_error(ret)) {
2077 host_to_target_sockaddr(target_addr, addr, addrlen);
2078 if (put_user_u32(addrlen, target_addrlen_addr)({ abi_ulong __gaddr = ((target_addrlen_addr)); uint32_t *__hptr
; abi_long __ret; if ((__hptr = lock_user(1, __gaddr, sizeof(
uint32_t), 0))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(__hptr)) == 2,
stw_be_p, __builtin_choose_expr(sizeof(*(__hptr)) == 4, stl_be_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 8, stq_be_p, abort
)))) ((__hptr), (((addrlen)))), 0); unlock_user(__hptr, __gaddr
, sizeof(uint32_t)); } else __ret = -14; __ret; })
)
2079 ret = -TARGET_EFAULT14;
2080 }
2081 return ret;
2082}
2083
2084/* do_socketpair() Must return target values and target errnos. */
2085static abi_long do_socketpair(int domain, int type, int protocol,
2086 abi_ulong target_tab_addr)
2087{
2088 int tab[2];
2089 abi_long ret;
2090
2091 target_to_host_sock_type(&type);
2092
2093 ret = get_errno(socketpair(domain, type, protocol, tab));
2094 if (!is_error(ret)) {
2095 if (put_user_s32(tab[0], target_tab_addr)({ abi_ulong __gaddr = ((target_tab_addr)); int32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(1, __gaddr, sizeof(int32_t), 0
))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1, stb_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), (((tab[0])))
), 0); unlock_user(__hptr, __gaddr, sizeof(int32_t)); } else __ret
= -14; __ret; })
2096 || put_user_s32(tab[1], target_tab_addr + sizeof(tab[0]))({ abi_ulong __gaddr = ((target_tab_addr + sizeof(tab[0]))); int32_t
*__hptr; abi_long __ret; if ((__hptr = lock_user(1, __gaddr,
sizeof(int32_t), 0))) { __ret = (__builtin_choose_expr(sizeof
(*(__hptr)) == 1, stb_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
4, stl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) == 8, stq_be_p
, abort)))) ((__hptr), (((tab[1])))), 0); unlock_user(__hptr,
__gaddr, sizeof(int32_t)); } else __ret = -14; __ret; })
)
2097 ret = -TARGET_EFAULT14;
2098 }
2099 return ret;
2100}
2101
2102/* do_sendto() Must return target values and target errnos. */
2103static abi_long do_sendto(int fd, abi_ulong msg, size_t len, int flags,
2104 abi_ulong target_addr, socklen_t addrlen)
2105{
2106 void *addr;
2107 void *host_msg;
2108 abi_long ret;
2109
2110 if ((int)addrlen < 0) {
2111 return -TARGET_EINVAL22;
2112 }
2113
2114 host_msg = lock_user(VERIFY_READ0, msg, len, 1);
2115 if (!host_msg)
2116 return -TARGET_EFAULT14;
2117 if (target_addr) {
2118 addr = alloca(addrlen)__builtin_alloca (addrlen);
2119 ret = target_to_host_sockaddr(addr, target_addr, addrlen);
2120 if (ret) {
2121 unlock_user(host_msg, msg, 0);
2122 return ret;
2123 }
2124 ret = get_errno(sendto(fd, host_msg, len, flags, addr, addrlen));
2125 } else {
2126 ret = get_errno(send(fd, host_msg, len, flags));
2127 }
2128 unlock_user(host_msg, msg, 0);
2129 return ret;
2130}
2131
2132/* do_recvfrom() Must return target values and target errnos. */
2133static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags,
2134 abi_ulong target_addr,
2135 abi_ulong target_addrlen)
2136{
2137 socklen_t addrlen;
2138 void *addr;
2139 void *host_msg;
2140 abi_long ret;
2141
2142 host_msg = lock_user(VERIFY_WRITE1, msg, len, 0);
2143 if (!host_msg)
2144 return -TARGET_EFAULT14;
2145 if (target_addr) {
2146 if (get_user_u32(addrlen, target_addrlen)({ abi_ulong __gaddr = ((target_addrlen)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(uint32_t),
1))) { __ret = ((((addrlen))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((addrlen)) = 0; __ret = -14; } __ret; })
) {
2147 ret = -TARGET_EFAULT14;
2148 goto fail;
2149 }
2150 if ((int)addrlen < 0) {
2151 ret = -TARGET_EINVAL22;
2152 goto fail;
2153 }
2154 addr = alloca(addrlen)__builtin_alloca (addrlen);
2155 ret = get_errno(recvfrom(fd, host_msg, len, flags, addr, &addrlen));
2156 } else {
2157 addr = NULL((void*)0); /* To keep compiler quiet. */
2158 ret = get_errno(qemu_recv(fd, host_msg, len, flags)recv(fd, host_msg, len, flags));
2159 }
2160 if (!is_error(ret)) {
2161 if (target_addr) {
2162 host_to_target_sockaddr(target_addr, addr, addrlen);
2163 if (put_user_u32(addrlen, target_addrlen)({ abi_ulong __gaddr = ((target_addrlen)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(1, __gaddr, sizeof(uint32_t),
0))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1
, stb_p, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), (((addrlen
)))), 0); unlock_user(__hptr, __gaddr, sizeof(uint32_t)); } else
__ret = -14; __ret; })
) {
2164 ret = -TARGET_EFAULT14;
2165 goto fail;
2166 }
2167 }
2168 unlock_user(host_msg, msg, len);
2169 } else {
2170fail:
2171 unlock_user(host_msg, msg, 0);
2172 }
2173 return ret;
2174}
2175
2176#ifdef TARGET_NR_socketcall102
2177/* do_socketcall() Must return target values and target errnos. */
2178static abi_long do_socketcall(int num, abi_ulong vptr)
2179{
2180 abi_long ret;
2181 const int n = sizeof(abi_ulong);
2182
2183 switch(num) {
2184 case SOCKOP_socket1:
2185 {
2186 abi_ulong domain, type, protocol;
2187
2188 if (get_user_ual(domain, vptr)({ abi_ulong __gaddr = ((vptr)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((domain))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((domain)) = 0; __ret = -14; } __ret; })
2189 || get_user_ual(type, vptr + n)({ abi_ulong __gaddr = ((vptr + n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((type))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((type)) = 0; __ret = -14; } __ret; })
2190 || get_user_ual(protocol, vptr + 2 * n)({ abi_ulong __gaddr = ((vptr + 2 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((protocol))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((protocol)) = 0; __ret = -14; } __ret; })
)
2191 return -TARGET_EFAULT14;
2192
2193 ret = do_socket(domain, type, protocol);
2194 }
2195 break;
2196 case SOCKOP_bind2:
2197 {
2198 abi_ulong sockfd;
2199 abi_ulong target_addr;
2200 socklen_t addrlen;
2201
2202 if (get_user_ual(sockfd, vptr)({ abi_ulong __gaddr = ((vptr)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((sockfd))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((sockfd)) = 0; __ret = -14; } __ret; })
2203 || get_user_ual(target_addr, vptr + n)({ abi_ulong __gaddr = ((vptr + n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((target_addr))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((target_addr)) = 0; __ret = -14; } __ret; })
2204 || get_user_ual(addrlen, vptr + 2 * n)({ abi_ulong __gaddr = ((vptr + 2 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((addrlen))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((addrlen)) = 0; __ret = -14; } __ret; })
)
2205 return -TARGET_EFAULT14;
2206
2207 ret = do_bind(sockfd, target_addr, addrlen);
2208 }
2209 break;
2210 case SOCKOP_connect3:
2211 {
2212 abi_ulong sockfd;
2213 abi_ulong target_addr;
2214 socklen_t addrlen;
2215
2216 if (get_user_ual(sockfd, vptr)({ abi_ulong __gaddr = ((vptr)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((sockfd))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((sockfd)) = 0; __ret = -14; } __ret; })
2217 || get_user_ual(target_addr, vptr + n)({ abi_ulong __gaddr = ((vptr + n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((target_addr))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((target_addr)) = 0; __ret = -14; } __ret; })
2218 || get_user_ual(addrlen, vptr + 2 * n)({ abi_ulong __gaddr = ((vptr + 2 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((addrlen))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((addrlen)) = 0; __ret = -14; } __ret; })
)
2219 return -TARGET_EFAULT14;
2220
2221 ret = do_connect(sockfd, target_addr, addrlen);
2222 }
2223 break;
2224 case SOCKOP_listen4:
2225 {
2226 abi_ulong sockfd, backlog;
2227
2228 if (get_user_ual(sockfd, vptr)({ abi_ulong __gaddr = ((vptr)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((sockfd))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((sockfd)) = 0; __ret = -14; } __ret; })
2229 || get_user_ual(backlog, vptr + n)({ abi_ulong __gaddr = ((vptr + n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((backlog))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((backlog)) = 0; __ret = -14; } __ret; })
)
2230 return -TARGET_EFAULT14;
2231
2232 ret = get_errno(listen(sockfd, backlog));
2233 }
2234 break;
2235 case SOCKOP_accept5:
2236 {
2237 abi_ulong sockfd;
2238 abi_ulong target_addr, target_addrlen;
2239
2240 if (get_user_ual(sockfd, vptr)({ abi_ulong __gaddr = ((vptr)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((sockfd))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((sockfd)) = 0; __ret = -14; } __ret; })
2241 || get_user_ual(target_addr, vptr + n)({ abi_ulong __gaddr = ((vptr + n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((target_addr))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((target_addr)) = 0; __ret = -14; } __ret; })
2242 || get_user_ual(target_addrlen, vptr + 2 * n)({ abi_ulong __gaddr = ((vptr + 2 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((target_addrlen))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((target_addrlen)) = 0; __ret = -14; } __ret; }
)
)
2243 return -TARGET_EFAULT14;
2244
2245 ret = do_accept4(sockfd, target_addr, target_addrlen, 0);
2246 }
2247 break;
2248 case SOCKOP_accept418:
2249 {
2250 abi_ulong sockfd;
2251 abi_ulong target_addr, target_addrlen;
2252 abi_ulong flags;
2253
2254 if (get_user_ual(sockfd, vptr)({ abi_ulong __gaddr = ((vptr)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((sockfd))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((sockfd)) = 0; __ret = -14; } __ret; })
2255 || get_user_ual(target_addr, vptr + n)({ abi_ulong __gaddr = ((vptr + n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((target_addr))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((target_addr)) = 0; __ret = -14; } __ret; })
2256 || get_user_ual(target_addrlen, vptr + 2 * n)({ abi_ulong __gaddr = ((vptr + 2 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((target_addrlen))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((target_addrlen)) = 0; __ret = -14; } __ret; }
)
2257 || get_user_ual(flags, vptr + 3 * n)({ abi_ulong __gaddr = ((vptr + 3 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((flags))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((flags)) = 0; __ret = -14; } __ret; })
) {
2258 return -TARGET_EFAULT14;
2259 }
2260
2261 ret = do_accept4(sockfd, target_addr, target_addrlen, flags);
2262 }
2263 break;
2264 case SOCKOP_getsockname6:
2265 {
2266 abi_ulong sockfd;
2267 abi_ulong target_addr, target_addrlen;
2268
2269 if (get_user_ual(sockfd, vptr)({ abi_ulong __gaddr = ((vptr)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((sockfd))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((sockfd)) = 0; __ret = -14; } __ret; })
2270 || get_user_ual(target_addr, vptr + n)({ abi_ulong __gaddr = ((vptr + n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((target_addr))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((target_addr)) = 0; __ret = -14; } __ret; })
2271 || get_user_ual(target_addrlen, vptr + 2 * n)({ abi_ulong __gaddr = ((vptr + 2 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((target_addrlen))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((target_addrlen)) = 0; __ret = -14; } __ret; }
)
)
2272 return -TARGET_EFAULT14;
2273
2274 ret = do_getsockname(sockfd, target_addr, target_addrlen);
2275 }
2276 break;
2277 case SOCKOP_getpeername7:
2278 {
2279 abi_ulong sockfd;
2280 abi_ulong target_addr, target_addrlen;
2281
2282 if (get_user_ual(sockfd, vptr)({ abi_ulong __gaddr = ((vptr)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((sockfd))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((sockfd)) = 0; __ret = -14; } __ret; })
2283 || get_user_ual(target_addr, vptr + n)({ abi_ulong __gaddr = ((vptr + n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((target_addr))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((target_addr)) = 0; __ret = -14; } __ret; })
2284 || get_user_ual(target_addrlen, vptr + 2 * n)({ abi_ulong __gaddr = ((vptr + 2 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((target_addrlen))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((target_addrlen)) = 0; __ret = -14; } __ret; }
)
)
2285 return -TARGET_EFAULT14;
2286
2287 ret = do_getpeername(sockfd, target_addr, target_addrlen);
2288 }
2289 break;
2290 case SOCKOP_socketpair8:
2291 {
2292 abi_ulong domain, type, protocol;
2293 abi_ulong tab;
2294
2295 if (get_user_ual(domain, vptr)({ abi_ulong __gaddr = ((vptr)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((domain))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((domain)) = 0; __ret = -14; } __ret; })
2296 || get_user_ual(type, vptr + n)({ abi_ulong __gaddr = ((vptr + n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((type))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((type)) = 0; __ret = -14; } __ret; })
2297 || get_user_ual(protocol, vptr + 2 * n)({ abi_ulong __gaddr = ((vptr + 2 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((protocol))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((protocol)) = 0; __ret = -14; } __ret; })
2298 || get_user_ual(tab, vptr + 3 * n)({ abi_ulong __gaddr = ((vptr + 3 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((tab))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((tab)) = 0; __ret = -14; } __ret; })
)
2299 return -TARGET_EFAULT14;
2300
2301 ret = do_socketpair(domain, type, protocol, tab);
2302 }
2303 break;
2304 case SOCKOP_send9:
2305 {
2306 abi_ulong sockfd;
2307 abi_ulong msg;
2308 size_t len;
2309 abi_ulong flags;
2310
2311 if (get_user_ual(sockfd, vptr)({ abi_ulong __gaddr = ((vptr)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((sockfd))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((sockfd)) = 0; __ret = -14; } __ret; })
2312 || get_user_ual(msg, vptr + n)({ abi_ulong __gaddr = ((vptr + n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((msg))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((msg)) = 0; __ret = -14; } __ret; })
2313 || get_user_ual(len, vptr + 2 * n)({ abi_ulong __gaddr = ((vptr + 2 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((len))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((len)) = 0; __ret = -14; } __ret; })
2314 || get_user_ual(flags, vptr + 3 * n)({ abi_ulong __gaddr = ((vptr + 3 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((flags))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((flags)) = 0; __ret = -14; } __ret; })
)
2315 return -TARGET_EFAULT14;
2316
2317 ret = do_sendto(sockfd, msg, len, flags, 0, 0);
2318 }
2319 break;
2320 case SOCKOP_recv10:
2321 {
2322 abi_ulong sockfd;
2323 abi_ulong msg;
2324 size_t len;
2325 abi_ulong flags;
2326
2327 if (get_user_ual(sockfd, vptr)({ abi_ulong __gaddr = ((vptr)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((sockfd))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((sockfd)) = 0; __ret = -14; } __ret; })
2328 || get_user_ual(msg, vptr + n)({ abi_ulong __gaddr = ((vptr + n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((msg))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((msg)) = 0; __ret = -14; } __ret; })
2329 || get_user_ual(len, vptr + 2 * n)({ abi_ulong __gaddr = ((vptr + 2 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((len))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((len)) = 0; __ret = -14; } __ret; })
2330 || get_user_ual(flags, vptr + 3 * n)({ abi_ulong __gaddr = ((vptr + 3 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((flags))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((flags)) = 0; __ret = -14; } __ret; })
)
2331 return -TARGET_EFAULT14;
2332
2333 ret = do_recvfrom(sockfd, msg, len, flags, 0, 0);
2334 }
2335 break;
2336 case SOCKOP_sendto11:
2337 {
2338 abi_ulong sockfd;
2339 abi_ulong msg;
2340 size_t len;
2341 abi_ulong flags;
2342 abi_ulong addr;
2343 socklen_t addrlen;
2344
2345 if (get_user_ual(sockfd, vptr)({ abi_ulong __gaddr = ((vptr)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((sockfd))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((sockfd)) = 0; __ret = -14; } __ret; })
2346 || get_user_ual(msg, vptr + n)({ abi_ulong __gaddr = ((vptr + n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((msg))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((msg)) = 0; __ret = -14; } __ret; })
2347 || get_user_ual(len, vptr + 2 * n)({ abi_ulong __gaddr = ((vptr + 2 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((len))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((len)) = 0; __ret = -14; } __ret; })
2348 || get_user_ual(flags, vptr + 3 * n)({ abi_ulong __gaddr = ((vptr + 3 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((flags))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((flags)) = 0; __ret = -14; } __ret; })
2349 || get_user_ual(addr, vptr + 4 * n)({ abi_ulong __gaddr = ((vptr + 4 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((addr))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((addr)) = 0; __ret = -14; } __ret; })
2350 || get_user_ual(addrlen, vptr + 5 * n)({ abi_ulong __gaddr = ((vptr + 5 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((addrlen))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((addrlen)) = 0; __ret = -14; } __ret; })
)
2351 return -TARGET_EFAULT14;
2352
2353 ret = do_sendto(sockfd, msg, len, flags, addr, addrlen);
2354 }
2355 break;
2356 case SOCKOP_recvfrom12:
2357 {
2358 abi_ulong sockfd;
2359 abi_ulong msg;
2360 size_t len;
2361 abi_ulong flags;
2362 abi_ulong addr;
2363 socklen_t addrlen;
2364
2365 if (get_user_ual(sockfd, vptr)({ abi_ulong __gaddr = ((vptr)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((sockfd))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((sockfd)) = 0; __ret = -14; } __ret; })
2366 || get_user_ual(msg, vptr + n)({ abi_ulong __gaddr = ((vptr + n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((msg))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((msg)) = 0; __ret = -14; } __ret; })
2367 || get_user_ual(len, vptr + 2 * n)({ abi_ulong __gaddr = ((vptr + 2 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((len))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((len)) = 0; __ret = -14; } __ret; })
2368 || get_user_ual(flags, vptr + 3 * n)({ abi_ulong __gaddr = ((vptr + 3 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((flags))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((flags)) = 0; __ret = -14; } __ret; })
2369 || get_user_ual(addr, vptr + 4 * n)({ abi_ulong __gaddr = ((vptr + 4 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((addr))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((addr)) = 0; __ret = -14; } __ret; })
2370 || get_user_ual(addrlen, vptr + 5 * n)({ abi_ulong __gaddr = ((vptr + 5 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((addrlen))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((addrlen)) = 0; __ret = -14; } __ret; })
)
2371 return -TARGET_EFAULT14;
2372
2373 ret = do_recvfrom(sockfd, msg, len, flags, addr, addrlen);
2374 }
2375 break;
2376 case SOCKOP_shutdown13:
2377 {
2378 abi_ulong sockfd, how;
2379
2380 if (get_user_ual(sockfd, vptr)({ abi_ulong __gaddr = ((vptr)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((sockfd))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((sockfd)) = 0; __ret = -14; } __ret; })
2381 || get_user_ual(how, vptr + n)({ abi_ulong __gaddr = ((vptr + n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((how))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((how)) = 0; __ret = -14; } __ret; })
)
2382 return -TARGET_EFAULT14;
2383
2384 ret = get_errno(shutdown(sockfd, how));
2385 }
2386 break;
2387 case SOCKOP_sendmsg16:
2388 case SOCKOP_recvmsg17:
2389 {
2390 abi_ulong fd;
2391 abi_ulong target_msg;
2392 abi_ulong flags;
2393
2394 if (get_user_ual(fd, vptr)({ abi_ulong __gaddr = ((vptr)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((fd))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((fd)) = 0; __ret = -14; } __ret; })
2395 || get_user_ual(target_msg, vptr + n)({ abi_ulong __gaddr = ((vptr + n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((target_msg))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((target_msg)) = 0; __ret = -14; } __ret; })
2396 || get_user_ual(flags, vptr + 2 * n)({ abi_ulong __gaddr = ((vptr + 2 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((flags))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((flags)) = 0; __ret = -14; } __ret; })
)
2397 return -TARGET_EFAULT14;
2398
2399 ret = do_sendrecvmsg(fd, target_msg, flags,
2400 (num == SOCKOP_sendmsg16));
2401 }
2402 break;
2403 case SOCKOP_setsockopt14:
2404 {
2405 abi_ulong sockfd;
2406 abi_ulong level;
2407 abi_ulong optname;
2408 abi_ulong optval;
2409 socklen_t optlen;
2410
2411 if (get_user_ual(sockfd, vptr)({ abi_ulong __gaddr = ((vptr)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((sockfd))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((sockfd)) = 0; __ret = -14; } __ret; })
2412 || get_user_ual(level, vptr + n)({ abi_ulong __gaddr = ((vptr + n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((level))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((level)) = 0; __ret = -14; } __ret; })
2413 || get_user_ual(optname, vptr + 2 * n)({ abi_ulong __gaddr = ((vptr + 2 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((optname))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((optname)) = 0; __ret = -14; } __ret; })
2414 || get_user_ual(optval, vptr + 3 * n)({ abi_ulong __gaddr = ((vptr + 3 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((optval))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((optval)) = 0; __ret = -14; } __ret; })
2415 || get_user_ual(optlen, vptr + 4 * n)({ abi_ulong __gaddr = ((vptr + 4 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((optlen))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((optlen)) = 0; __ret = -14; } __ret; })
)
2416 return -TARGET_EFAULT14;
2417
2418 ret = do_setsockopt(sockfd, level, optname, optval, optlen);
2419 }
2420 break;
2421 case SOCKOP_getsockopt15:
2422 {
2423 abi_ulong sockfd;
2424 abi_ulong level;
2425 abi_ulong optname;
2426 abi_ulong optval;
2427 socklen_t optlen;
2428
2429 if (get_user_ual(sockfd, vptr)({ abi_ulong __gaddr = ((vptr)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((sockfd))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((sockfd)) = 0; __ret = -14; } __ret; })
2430 || get_user_ual(level, vptr + n)({ abi_ulong __gaddr = ((vptr + n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((level))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((level)) = 0; __ret = -14; } __ret; })
2431 || get_user_ual(optname, vptr + 2 * n)({ abi_ulong __gaddr = ((vptr + 2 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((optname))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((optname)) = 0; __ret = -14; } __ret; })
2432 || get_user_ual(optval, vptr + 3 * n)({ abi_ulong __gaddr = ((vptr + 3 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((optval))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((optval)) = 0; __ret = -14; } __ret; })
2433 || get_user_ual(optlen, vptr + 4 * n)({ abi_ulong __gaddr = ((vptr + 4 * n)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong)
, 1))) { __ret = ((((optlen))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((optlen)) = 0; __ret = -14; } __ret; })
)
2434 return -TARGET_EFAULT14;
2435
2436 ret = do_getsockopt(sockfd, level, optname, optval, optlen);
2437 }
2438 break;
2439 default:
2440 gemu_log("Unsupported socketcall: %d\n", num);
2441 ret = -TARGET_ENOSYS38;
2442 break;
2443 }
2444 return ret;
2445}
2446#endif
2447
2448#define N_SHM_REGIONS32 32
2449
2450static struct shm_region {
2451 abi_ulong start;
2452 abi_ulong size;
2453} shm_regions[N_SHM_REGIONS32];
2454
2455struct target_semid_ds
2456{
2457 struct target_ipc_perm sem_perm;
2458 abi_ulong sem_otime;
2459 abi_ulong __unused1;
2460 abi_ulong sem_ctime;
2461 abi_ulong __unused2;
2462 abi_ulong sem_nsems;
2463 abi_ulong __unused3;
2464 abi_ulong __unused4;
2465};
2466
2467static inline abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip,
2468 abi_ulong target_addr)
2469{
2470 struct target_ipc_perm *target_ip;
2471 struct target_semid_ds *target_sd;
2472
2473 if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)(target_sd = lock_user(0, target_addr, sizeof(*target_sd), 1)
)
)
2474 return -TARGET_EFAULT14;
2475 target_ip = &(target_sd->sem_perm);
2476 host_ip->__key = tswap32(target_ip->__key);
2477 host_ip->uid = tswap32(target_ip->uid);
2478 host_ip->gid = tswap32(target_ip->gid);
2479 host_ip->cuid = tswap32(target_ip->cuid);
2480 host_ip->cgid = tswap32(target_ip->cgid);
2481#if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_PPC)
2482 host_ip->mode = tswap32(target_ip->mode);
2483#else
2484 host_ip->mode = tswap16(target_ip->mode);
2485#endif
2486#if defined(TARGET_PPC)
2487 host_ip->__seq = tswap32(target_ip->__seq);
2488#else
2489 host_ip->__seq = tswap16(target_ip->__seq);
2490#endif
2491 unlock_user_struct(target_sd, target_addr, 0)unlock_user(target_sd, target_addr, (0) ? sizeof(*target_sd) :
0)
;
2492 return 0;
2493}
2494
2495static inline abi_long host_to_target_ipc_perm(abi_ulong target_addr,
2496 struct ipc_perm *host_ip)
2497{
2498 struct target_ipc_perm *target_ip;
2499 struct target_semid_ds *target_sd;
2500
2501 if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)(target_sd = lock_user(1, target_addr, sizeof(*target_sd), 0)
)
)
2502 return -TARGET_EFAULT14;
2503 target_ip = &(target_sd->sem_perm);
2504 target_ip->__key = tswap32(host_ip->__key);
2505 target_ip->uid = tswap32(host_ip->uid);
2506 target_ip->gid = tswap32(host_ip->gid);
2507 target_ip->cuid = tswap32(host_ip->cuid);
2508 target_ip->cgid = tswap32(host_ip->cgid);
2509#if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_PPC)
2510 target_ip->mode = tswap32(host_ip->mode);
2511#else
2512 target_ip->mode = tswap16(host_ip->mode);
2513#endif
2514#if defined(TARGET_PPC)
2515 target_ip->__seq = tswap32(host_ip->__seq);
2516#else
2517 target_ip->__seq = tswap16(host_ip->__seq);
2518#endif
2519 unlock_user_struct(target_sd, target_addr, 1)unlock_user(target_sd, target_addr, (1) ? sizeof(*target_sd) :
0)
;
2520 return 0;
2521}
2522
2523static inline abi_long target_to_host_semid_ds(struct semid_ds *host_sd,
2524 abi_ulong target_addr)
2525{
2526 struct target_semid_ds *target_sd;
2527
2528 if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)(target_sd = lock_user(0, target_addr, sizeof(*target_sd), 1)
)
)
2529 return -TARGET_EFAULT14;
2530 if (target_to_host_ipc_perm(&(host_sd->sem_perm),target_addr))
2531 return -TARGET_EFAULT14;
2532 host_sd->sem_nsems = tswapal(target_sd->sem_nsems);
2533 host_sd->sem_otime = tswapal(target_sd->sem_otime);
2534 host_sd->sem_ctime = tswapal(target_sd->sem_ctime);
2535 unlock_user_struct(target_sd, target_addr, 0)unlock_user(target_sd, target_addr, (0) ? sizeof(*target_sd) :
0)
;
2536 return 0;
2537}
2538
2539static inline abi_long host_to_target_semid_ds(abi_ulong target_addr,
2540 struct semid_ds *host_sd)
2541{
2542 struct target_semid_ds *target_sd;
2543
2544 if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)(target_sd = lock_user(1, target_addr, sizeof(*target_sd), 0)
)
)
2545 return -TARGET_EFAULT14;
2546 if (host_to_target_ipc_perm(target_addr,&(host_sd->sem_perm)))
2547 return -TARGET_EFAULT14;
2548 target_sd->sem_nsems = tswapal(host_sd->sem_nsems);
2549 target_sd->sem_otime = tswapal(host_sd->sem_otime);
2550 target_sd->sem_ctime = tswapal(host_sd->sem_ctime);
2551 unlock_user_struct(target_sd, target_addr, 1)unlock_user(target_sd, target_addr, (1) ? sizeof(*target_sd) :
0)
;
2552 return 0;
2553}
2554
2555struct target_seminfo {
2556 int semmap;
2557 int semmni;
2558 int semmns;
2559 int semmnu;
2560 int semmsl;
2561 int semopm;
2562 int semume;
2563 int semusz;
2564 int semvmx;
2565 int semaem;
2566};
2567
2568static inline abi_long host_to_target_seminfo(abi_ulong target_addr,
2569 struct seminfo *host_seminfo)
2570{
2571 struct target_seminfo *target_seminfo;
2572 if (!lock_user_struct(VERIFY_WRITE, target_seminfo, target_addr, 0)(target_seminfo = lock_user(1, target_addr, sizeof(*target_seminfo
), 0))
)
2573 return -TARGET_EFAULT14;
2574 __put_user(host_seminfo->semmap, &target_seminfo->semmap)(__builtin_choose_expr(sizeof(*(&target_seminfo->semmap
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_seminfo
->semmap)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_seminfo->semmap)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_seminfo->semmap)) == 8, stq_be_p, abort
)))) ((&target_seminfo->semmap), (host_seminfo->semmap
)), 0)
;
2575 __put_user(host_seminfo->semmni, &target_seminfo->semmni)(__builtin_choose_expr(sizeof(*(&target_seminfo->semmni
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_seminfo
->semmni)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_seminfo->semmni)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_seminfo->semmni)) == 8, stq_be_p, abort
)))) ((&target_seminfo->semmni), (host_seminfo->semmni
)), 0)
;
2576 __put_user(host_seminfo->semmns, &target_seminfo->semmns)(__builtin_choose_expr(sizeof(*(&target_seminfo->semmns
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_seminfo
->semmns)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_seminfo->semmns)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_seminfo->semmns)) == 8, stq_be_p, abort
)))) ((&target_seminfo->semmns), (host_seminfo->semmns
)), 0)
;
2577 __put_user(host_seminfo->semmnu, &target_seminfo->semmnu)(__builtin_choose_expr(sizeof(*(&target_seminfo->semmnu
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_seminfo
->semmnu)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_seminfo->semmnu)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_seminfo->semmnu)) == 8, stq_be_p, abort
)))) ((&target_seminfo->semmnu), (host_seminfo->semmnu
)), 0)
;
2578 __put_user(host_seminfo->semmsl, &target_seminfo->semmsl)(__builtin_choose_expr(sizeof(*(&target_seminfo->semmsl
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_seminfo
->semmsl)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_seminfo->semmsl)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_seminfo->semmsl)) == 8, stq_be_p, abort
)))) ((&target_seminfo->semmsl), (host_seminfo->semmsl
)), 0)
;
2579 __put_user(host_seminfo->semopm, &target_seminfo->semopm)(__builtin_choose_expr(sizeof(*(&target_seminfo->semopm
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_seminfo
->semopm)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_seminfo->semopm)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_seminfo->semopm)) == 8, stq_be_p, abort
)))) ((&target_seminfo->semopm), (host_seminfo->semopm
)), 0)
;
2580 __put_user(host_seminfo->semume, &target_seminfo->semume)(__builtin_choose_expr(sizeof(*(&target_seminfo->semume
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_seminfo
->semume)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_seminfo->semume)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_seminfo->semume)) == 8, stq_be_p, abort
)))) ((&target_seminfo->semume), (host_seminfo->semume
)), 0)
;
2581 __put_user(host_seminfo->semusz, &target_seminfo->semusz)(__builtin_choose_expr(sizeof(*(&target_seminfo->semusz
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_seminfo
->semusz)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_seminfo->semusz)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_seminfo->semusz)) == 8, stq_be_p, abort
)))) ((&target_seminfo->semusz), (host_seminfo->semusz
)), 0)
;
2582 __put_user(host_seminfo->semvmx, &target_seminfo->semvmx)(__builtin_choose_expr(sizeof(*(&target_seminfo->semvmx
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_seminfo
->semvmx)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_seminfo->semvmx)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_seminfo->semvmx)) == 8, stq_be_p, abort
)))) ((&target_seminfo->semvmx), (host_seminfo->semvmx
)), 0)
;
2583 __put_user(host_seminfo->semaem, &target_seminfo->semaem)(__builtin_choose_expr(sizeof(*(&target_seminfo->semaem
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_seminfo
->semaem)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_seminfo->semaem)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_seminfo->semaem)) == 8, stq_be_p, abort
)))) ((&target_seminfo->semaem), (host_seminfo->semaem
)), 0)
;
2584 unlock_user_struct(target_seminfo, target_addr, 1)unlock_user(target_seminfo, target_addr, (1) ? sizeof(*target_seminfo
) : 0)
;
2585 return 0;
2586}
2587
2588union semun {
2589 int val;
2590 struct semid_ds *buf;
2591 unsigned short *array;
2592 struct seminfo *__buf;
2593};
2594
2595union target_semun {
2596 int val;
2597 abi_ulong buf;
2598 abi_ulong array;
2599 abi_ulong __buf;
2600};
2601
2602static inline abi_long target_to_host_semarray(int semid, unsigned short **host_array,
2603 abi_ulong target_addr)
2604{
2605 int nsems;
2606 unsigned short *array;
2607 union semun semun;
2608 struct semid_ds semid_ds;
2609 int i, ret;
2610
2611 semun.buf = &semid_ds;
2612
2613 ret = semctl(semid, 0, IPC_STAT2, semun);
2614 if (ret == -1)
2615 return get_errno(ret);
2616
2617 nsems = semid_ds.sem_nsems;
2618
2619 *host_array = malloc(nsems*sizeof(unsigned short));
2620 array = lock_user(VERIFY_READ0, target_addr,
2621 nsems*sizeof(unsigned short), 1);
2622 if (!array)
2623 return -TARGET_EFAULT14;
2624
2625 for(i=0; i<nsems; i++) {
2626 __get_user((*host_array)[i], &array[i])(((*host_array)[i]) = (typeof(*&array[i]))( __builtin_choose_expr
(sizeof(*(&array[i])) == 1, ldub_p, __builtin_choose_expr
(sizeof(*(&array[i])) == 2, lduw_be_p, __builtin_choose_expr
(sizeof(*(&array[i])) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&array[i])) == 8, ldq_be_p, abort)))) (&array
[i])), 0)
;
2627 }
2628 unlock_user(array, target_addr, 0);
2629
2630 return 0;
2631}
2632
2633static inline abi_long host_to_target_semarray(int semid, abi_ulong target_addr,
2634 unsigned short **host_array)
2635{
2636 int nsems;
2637 unsigned short *array;
2638 union semun semun;
2639 struct semid_ds semid_ds;
2640 int i, ret;
2641
2642 semun.buf = &semid_ds;
2643
2644 ret = semctl(semid, 0, IPC_STAT2, semun);
2645 if (ret == -1)
2646 return get_errno(ret);
2647
2648 nsems = semid_ds.sem_nsems;
2649
2650 array = lock_user(VERIFY_WRITE1, target_addr,
2651 nsems*sizeof(unsigned short), 0);
2652 if (!array)
2653 return -TARGET_EFAULT14;
2654
2655 for(i=0; i<nsems; i++) {
2656 __put_user((*host_array)[i], &array[i])(__builtin_choose_expr(sizeof(*(&array[i])) == 1, stb_p, __builtin_choose_expr
(sizeof(*(&array[i])) == 2, stw_be_p, __builtin_choose_expr
(sizeof(*(&array[i])) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&array[i])) == 8, stq_be_p, abort)))) ((&array
[i]), ((*host_array)[i])), 0)
;
2657 }
2658 free(*host_array);
2659 unlock_user(array, target_addr, 1);
2660
2661 return 0;
2662}
2663
2664static inline abi_long do_semctl(int semid, int semnum, int cmd,
2665 union target_semun target_su)
2666{
2667 union semun arg;
2668 struct semid_ds dsarg;
2669 unsigned short *array = NULL((void*)0);
2670 struct seminfo seminfo;
2671 abi_long ret = -TARGET_EINVAL22;
2672 abi_long err;
2673 cmd &= 0xff;
2674
2675 switch( cmd ) {
2676 case GETVAL12:
2677 case SETVAL16:
2678 arg.val = tswap32(target_su.val);
2679 ret = get_errno(semctl(semid, semnum, cmd, arg));
2680 target_su.val = tswap32(arg.val);
2681 break;
2682 case GETALL13:
2683 case SETALL17:
2684 err = target_to_host_semarray(semid, &array, target_su.array);
2685 if (err)
2686 return err;
2687 arg.array = array;
2688 ret = get_errno(semctl(semid, semnum, cmd, arg));
2689 err = host_to_target_semarray(semid, target_su.array, &array);
2690 if (err)
2691 return err;
2692 break;
2693 case IPC_STAT2:
2694 case IPC_SET1:
2695 case SEM_STAT18:
2696 err = target_to_host_semid_ds(&dsarg, target_su.buf);
2697 if (err)
2698 return err;
2699 arg.buf = &dsarg;
2700 ret = get_errno(semctl(semid, semnum, cmd, arg));
2701 err = host_to_target_semid_ds(target_su.buf, &dsarg);
2702 if (err)
2703 return err;
2704 break;
2705 case IPC_INFO3:
2706 case SEM_INFO19:
2707 arg.__buf = &seminfo;
2708 ret = get_errno(semctl(semid, semnum, cmd, arg));
2709 err = host_to_target_seminfo(target_su.__buf, &seminfo);
2710 if (err)
2711 return err;
2712 break;
2713 case IPC_RMID0:
2714 case GETPID11:
2715 case GETNCNT14:
2716 case GETZCNT15:
2717 ret = get_errno(semctl(semid, semnum, cmd, NULL((void*)0)));
2718 break;
2719 }
2720
2721 return ret;
2722}
2723
2724struct target_sembuf {
2725 unsigned short sem_num;
2726 short sem_op;
2727 short sem_flg;
2728};
2729
2730static inline abi_long target_to_host_sembuf(struct sembuf *host_sembuf,
2731 abi_ulong target_addr,
2732 unsigned nsops)
2733{
2734 struct target_sembuf *target_sembuf;
2735 int i;
2736
2737 target_sembuf = lock_user(VERIFY_READ0, target_addr,
2738 nsops*sizeof(struct target_sembuf), 1);
2739 if (!target_sembuf)
2740 return -TARGET_EFAULT14;
2741
2742 for(i=0; i<nsops; i++) {
2743 __get_user(host_sembuf[i].sem_num, &target_sembuf[i].sem_num)((host_sembuf[i].sem_num) = (typeof(*&target_sembuf[i].sem_num
))( __builtin_choose_expr(sizeof(*(&target_sembuf[i].sem_num
)) == 1, ldub_p, __builtin_choose_expr(sizeof(*(&target_sembuf
[i].sem_num)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*
(&target_sembuf[i].sem_num)) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&target_sembuf[i].sem_num)) == 8, ldq_be_p, abort
)))) (&target_sembuf[i].sem_num)), 0)
;
2744 __get_user(host_sembuf[i].sem_op, &target_sembuf[i].sem_op)((host_sembuf[i].sem_op) = (typeof(*&target_sembuf[i].sem_op
))( __builtin_choose_expr(sizeof(*(&target_sembuf[i].sem_op
)) == 1, ldub_p, __builtin_choose_expr(sizeof(*(&target_sembuf
[i].sem_op)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(
&target_sembuf[i].sem_op)) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&target_sembuf[i].sem_op)) == 8, ldq_be_p, abort
)))) (&target_sembuf[i].sem_op)), 0)
;
2745 __get_user(host_sembuf[i].sem_flg, &target_sembuf[i].sem_flg)((host_sembuf[i].sem_flg) = (typeof(*&target_sembuf[i].sem_flg
))( __builtin_choose_expr(sizeof(*(&target_sembuf[i].sem_flg
)) == 1, ldub_p, __builtin_choose_expr(sizeof(*(&target_sembuf
[i].sem_flg)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*
(&target_sembuf[i].sem_flg)) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&target_sembuf[i].sem_flg)) == 8, ldq_be_p, abort
)))) (&target_sembuf[i].sem_flg)), 0)
;
2746 }
2747
2748 unlock_user(target_sembuf, target_addr, 0);
2749
2750 return 0;
2751}
2752
2753static inline abi_long do_semop(int semid, abi_long ptr, unsigned nsops)
2754{
2755 struct sembuf sops[nsops];
2756
2757 if (target_to_host_sembuf(sops, ptr, nsops))
2758 return -TARGET_EFAULT14;
2759
2760 return get_errno(semop(semid, sops, nsops));
2761}
2762
2763struct target_msqid_ds
2764{
2765 struct target_ipc_perm msg_perm;
2766 abi_ulong msg_stime;
2767#if TARGET_ABI_BITS64 == 32
2768 abi_ulong __unused1;
2769#endif
2770 abi_ulong msg_rtime;
2771#if TARGET_ABI_BITS64 == 32
2772 abi_ulong __unused2;
2773#endif
2774 abi_ulong msg_ctime;
2775#if TARGET_ABI_BITS64 == 32
2776 abi_ulong __unused3;
2777#endif
2778 abi_ulong __msg_cbytes;
2779 abi_ulong msg_qnum;
2780 abi_ulong msg_qbytes;
2781 abi_ulong msg_lspid;
2782 abi_ulong msg_lrpid;
2783 abi_ulong __unused4;
2784 abi_ulong __unused5;
2785};
2786
2787static inline abi_long target_to_host_msqid_ds(struct msqid_ds *host_md,
2788 abi_ulong target_addr)
2789{
2790 struct target_msqid_ds *target_md;
2791
2792 if (!lock_user_struct(VERIFY_READ, target_md, target_addr, 1)(target_md = lock_user(0, target_addr, sizeof(*target_md), 1)
)
)
2793 return -TARGET_EFAULT14;
2794 if (target_to_host_ipc_perm(&(host_md->msg_perm),target_addr))
2795 return -TARGET_EFAULT14;
2796 host_md->msg_stime = tswapal(target_md->msg_stime);
2797 host_md->msg_rtime = tswapal(target_md->msg_rtime);
2798 host_md->msg_ctime = tswapal(target_md->msg_ctime);
2799 host_md->__msg_cbytes = tswapal(target_md->__msg_cbytes);
2800 host_md->msg_qnum = tswapal(target_md->msg_qnum);
2801 host_md->msg_qbytes = tswapal(target_md->msg_qbytes);
2802 host_md->msg_lspid = tswapal(target_md->msg_lspid);
2803 host_md->msg_lrpid = tswapal(target_md->msg_lrpid);
2804 unlock_user_struct(target_md, target_addr, 0)unlock_user(target_md, target_addr, (0) ? sizeof(*target_md) :
0)
;
2805 return 0;
2806}
2807
2808static inline abi_long host_to_target_msqid_ds(abi_ulong target_addr,
2809 struct msqid_ds *host_md)
2810{
2811 struct target_msqid_ds *target_md;
2812
2813 if (!lock_user_struct(VERIFY_WRITE, target_md, target_addr, 0)(target_md = lock_user(1, target_addr, sizeof(*target_md), 0)
)
)
2814 return -TARGET_EFAULT14;
2815 if (host_to_target_ipc_perm(target_addr,&(host_md->msg_perm)))
2816 return -TARGET_EFAULT14;
2817 target_md->msg_stime = tswapal(host_md->msg_stime);
2818 target_md->msg_rtime = tswapal(host_md->msg_rtime);
2819 target_md->msg_ctime = tswapal(host_md->msg_ctime);
2820 target_md->__msg_cbytes = tswapal(host_md->__msg_cbytes);
2821 target_md->msg_qnum = tswapal(host_md->msg_qnum);
2822 target_md->msg_qbytes = tswapal(host_md->msg_qbytes);
2823 target_md->msg_lspid = tswapal(host_md->msg_lspid);
2824 target_md->msg_lrpid = tswapal(host_md->msg_lrpid);
2825 unlock_user_struct(target_md, target_addr, 1)unlock_user(target_md, target_addr, (1) ? sizeof(*target_md) :
0)
;
2826 return 0;
2827}
2828
2829struct target_msginfo {
2830 int msgpool;
2831 int msgmap;
2832 int msgmax;
2833 int msgmnb;
2834 int msgmni;
2835 int msgssz;
2836 int msgtql;
2837 unsigned short int msgseg;
2838};
2839
2840static inline abi_long host_to_target_msginfo(abi_ulong target_addr,
2841 struct msginfo *host_msginfo)
2842{
2843 struct target_msginfo *target_msginfo;
2844 if (!lock_user_struct(VERIFY_WRITE, target_msginfo, target_addr, 0)(target_msginfo = lock_user(1, target_addr, sizeof(*target_msginfo
), 0))
)
2845 return -TARGET_EFAULT14;
2846 __put_user(host_msginfo->msgpool, &target_msginfo->msgpool)(__builtin_choose_expr(sizeof(*(&target_msginfo->msgpool
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_msginfo
->msgpool)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*
(&target_msginfo->msgpool)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_msginfo->msgpool)) == 8, stq_be_p, abort
)))) ((&target_msginfo->msgpool), (host_msginfo->msgpool
)), 0)
;
2847 __put_user(host_msginfo->msgmap, &target_msginfo->msgmap)(__builtin_choose_expr(sizeof(*(&target_msginfo->msgmap
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_msginfo
->msgmap)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_msginfo->msgmap)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_msginfo->msgmap)) == 8, stq_be_p, abort
)))) ((&target_msginfo->msgmap), (host_msginfo->msgmap
)), 0)
;
2848 __put_user(host_msginfo->msgmax, &target_msginfo->msgmax)(__builtin_choose_expr(sizeof(*(&target_msginfo->msgmax
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_msginfo
->msgmax)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_msginfo->msgmax)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_msginfo->msgmax)) == 8, stq_be_p, abort
)))) ((&target_msginfo->msgmax), (host_msginfo->msgmax
)), 0)
;
2849 __put_user(host_msginfo->msgmnb, &target_msginfo->msgmnb)(__builtin_choose_expr(sizeof(*(&target_msginfo->msgmnb
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_msginfo
->msgmnb)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_msginfo->msgmnb)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_msginfo->msgmnb)) == 8, stq_be_p, abort
)))) ((&target_msginfo->msgmnb), (host_msginfo->msgmnb
)), 0)
;
2850 __put_user(host_msginfo->msgmni, &target_msginfo->msgmni)(__builtin_choose_expr(sizeof(*(&target_msginfo->msgmni
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_msginfo
->msgmni)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_msginfo->msgmni)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_msginfo->msgmni)) == 8, stq_be_p, abort
)))) ((&target_msginfo->msgmni), (host_msginfo->msgmni
)), 0)
;
2851 __put_user(host_msginfo->msgssz, &target_msginfo->msgssz)(__builtin_choose_expr(sizeof(*(&target_msginfo->msgssz
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_msginfo
->msgssz)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_msginfo->msgssz)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_msginfo->msgssz)) == 8, stq_be_p, abort
)))) ((&target_msginfo->msgssz), (host_msginfo->msgssz
)), 0)
;
2852 __put_user(host_msginfo->msgtql, &target_msginfo->msgtql)(__builtin_choose_expr(sizeof(*(&target_msginfo->msgtql
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_msginfo
->msgtql)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_msginfo->msgtql)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_msginfo->msgtql)) == 8, stq_be_p, abort
)))) ((&target_msginfo->msgtql), (host_msginfo->msgtql
)), 0)
;
2853 __put_user(host_msginfo->msgseg, &target_msginfo->msgseg)(__builtin_choose_expr(sizeof(*(&target_msginfo->msgseg
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_msginfo
->msgseg)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_msginfo->msgseg)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_msginfo->msgseg)) == 8, stq_be_p, abort
)))) ((&target_msginfo->msgseg), (host_msginfo->msgseg
)), 0)
;
2854 unlock_user_struct(target_msginfo, target_addr, 1)unlock_user(target_msginfo, target_addr, (1) ? sizeof(*target_msginfo
) : 0)
;
2855 return 0;
2856}
2857
2858static inline abi_long do_msgctl(int msgid, int cmd, abi_long ptr)
2859{
2860 struct msqid_ds dsarg;
2861 struct msginfo msginfo;
2862 abi_long ret = -TARGET_EINVAL22;
2863
2864 cmd &= 0xff;
2865
2866 switch (cmd) {
2867 case IPC_STAT2:
2868 case IPC_SET1:
2869 case MSG_STAT11:
2870 if (target_to_host_msqid_ds(&dsarg,ptr))
2871 return -TARGET_EFAULT14;
2872 ret = get_errno(msgctl(msgid, cmd, &dsarg));
2873 if (host_to_target_msqid_ds(ptr,&dsarg))
2874 return -TARGET_EFAULT14;
2875 break;
2876 case IPC_RMID0:
2877 ret = get_errno(msgctl(msgid, cmd, NULL((void*)0)));
2878 break;
2879 case IPC_INFO3:
2880 case MSG_INFO12:
2881 ret = get_errno(msgctl(msgid, cmd, (struct msqid_ds *)&msginfo));
2882 if (host_to_target_msginfo(ptr, &msginfo))
2883 return -TARGET_EFAULT14;
2884 break;
2885 }
2886
2887 return ret;
2888}
2889
2890struct target_msgbuf {
2891 abi_long mtype;
2892 char mtext[1];
2893};
2894
2895static inline abi_long do_msgsnd(int msqid, abi_long msgp,
2896 unsigned int msgsz, int msgflg)
2897{
2898 struct target_msgbuf *target_mb;
2899 struct msgbuf *host_mb;
2900 abi_long ret = 0;
2901
2902 if (!lock_user_struct(VERIFY_READ, target_mb, msgp, 0)(target_mb = lock_user(0, msgp, sizeof(*target_mb), 0)))
2903 return -TARGET_EFAULT14;
2904 host_mb = malloc(msgsz+sizeof(long));
2905 host_mb->mtype = (abi_long) tswapal(target_mb->mtype);
2906 memcpy(host_mb->mtext, target_mb->mtext, msgsz);
2907 ret = get_errno(msgsnd(msqid, host_mb, msgsz, msgflg));
2908 free(host_mb);
2909 unlock_user_struct(target_mb, msgp, 0)unlock_user(target_mb, msgp, (0) ? sizeof(*target_mb) : 0);
2910
2911 return ret;
2912}
2913
2914static inline abi_long do_msgrcv(int msqid, abi_long msgp,
2915 unsigned int msgsz, abi_long msgtyp,
2916 int msgflg)
2917{
2918 struct target_msgbuf *target_mb;
2919 char *target_mtext;
2920 struct msgbuf *host_mb;
2921 abi_long ret = 0;
2922
2923 if (!lock_user_struct(VERIFY_WRITE, target_mb, msgp, 0)(target_mb = lock_user(1, msgp, sizeof(*target_mb), 0)))
2924 return -TARGET_EFAULT14;
2925
2926 host_mb = g_malloc(msgsz+sizeof(long));
2927 ret = get_errno(msgrcv(msqid, host_mb, msgsz, msgtyp, msgflg));
2928
2929 if (ret > 0) {
2930 abi_ulong target_mtext_addr = msgp + sizeof(abi_ulong);
2931 target_mtext = lock_user(VERIFY_WRITE1, target_mtext_addr, ret, 0);
2932 if (!target_mtext) {
2933 ret = -TARGET_EFAULT14;
2934 goto end;
2935 }
2936 memcpy(target_mb->mtext, host_mb->mtext, ret);
2937 unlock_user(target_mtext, target_mtext_addr, ret);
2938 }
2939
2940 target_mb->mtype = tswapal(host_mb->mtype);
2941
2942end:
2943 if (target_mb)
2944 unlock_user_struct(target_mb, msgp, 1)unlock_user(target_mb, msgp, (1) ? sizeof(*target_mb) : 0);
2945 g_free(host_mb);
2946 return ret;
2947}
2948
2949static inline abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd,
2950 abi_ulong target_addr)
2951{
2952 struct target_shmid_ds *target_sd;
2953
2954 if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)(target_sd = lock_user(0, target_addr, sizeof(*target_sd), 1)
)
)
2955 return -TARGET_EFAULT14;
2956 if (target_to_host_ipc_perm(&(host_sd->shm_perm), target_addr))
2957 return -TARGET_EFAULT14;
2958 __get_user(host_sd->shm_segsz, &target_sd->shm_segsz)((host_sd->shm_segsz) = (typeof(*&target_sd->shm_segsz
))( __builtin_choose_expr(sizeof(*(&target_sd->shm_segsz
)) == 1, ldub_p, __builtin_choose_expr(sizeof(*(&target_sd
->shm_segsz)) == 2, lduw_be_p, __builtin_choose_expr(sizeof
(*(&target_sd->shm_segsz)) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&target_sd->shm_segsz)) == 8, ldq_be_p, abort
)))) (&target_sd->shm_segsz)), 0)
;
2959 __get_user(host_sd->shm_atime, &target_sd->shm_atime)((host_sd->shm_atime) = (typeof(*&target_sd->shm_atime
))( __builtin_choose_expr(sizeof(*(&target_sd->shm_atime
)) == 1, ldub_p, __builtin_choose_expr(sizeof(*(&target_sd
->shm_atime)) == 2, lduw_be_p, __builtin_choose_expr(sizeof
(*(&target_sd->shm_atime)) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&target_sd->shm_atime)) == 8, ldq_be_p, abort
)))) (&target_sd->shm_atime)), 0)
;
2960 __get_user(host_sd->shm_dtime, &target_sd->shm_dtime)((host_sd->shm_dtime) = (typeof(*&target_sd->shm_dtime
))( __builtin_choose_expr(sizeof(*(&target_sd->shm_dtime
)) == 1, ldub_p, __builtin_choose_expr(sizeof(*(&target_sd
->shm_dtime)) == 2, lduw_be_p, __builtin_choose_expr(sizeof
(*(&target_sd->shm_dtime)) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&target_sd->shm_dtime)) == 8, ldq_be_p, abort
)))) (&target_sd->shm_dtime)), 0)
;
2961 __get_user(host_sd->shm_ctime, &target_sd->shm_ctime)((host_sd->shm_ctime) = (typeof(*&target_sd->shm_ctime
))( __builtin_choose_expr(sizeof(*(&target_sd->shm_ctime
)) == 1, ldub_p, __builtin_choose_expr(sizeof(*(&target_sd
->shm_ctime)) == 2, lduw_be_p, __builtin_choose_expr(sizeof
(*(&target_sd->shm_ctime)) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&target_sd->shm_ctime)) == 8, ldq_be_p, abort
)))) (&target_sd->shm_ctime)), 0)
;
2962 __get_user(host_sd->shm_cpid, &target_sd->shm_cpid)((host_sd->shm_cpid) = (typeof(*&target_sd->shm_cpid
))( __builtin_choose_expr(sizeof(*(&target_sd->shm_cpid
)) == 1, ldub_p, __builtin_choose_expr(sizeof(*(&target_sd
->shm_cpid)) == 2, lduw_be_p, __builtin_choose_expr(sizeof
(*(&target_sd->shm_cpid)) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&target_sd->shm_cpid)) == 8, ldq_be_p, abort
)))) (&target_sd->shm_cpid)), 0)
;
2963 __get_user(host_sd->shm_lpid, &target_sd->shm_lpid)((host_sd->shm_lpid) = (typeof(*&target_sd->shm_lpid
))( __builtin_choose_expr(sizeof(*(&target_sd->shm_lpid
)) == 1, ldub_p, __builtin_choose_expr(sizeof(*(&target_sd
->shm_lpid)) == 2, lduw_be_p, __builtin_choose_expr(sizeof
(*(&target_sd->shm_lpid)) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&target_sd->shm_lpid)) == 8, ldq_be_p, abort
)))) (&target_sd->shm_lpid)), 0)
;
2964 __get_user(host_sd->shm_nattch, &target_sd->shm_nattch)((host_sd->shm_nattch) = (typeof(*&target_sd->shm_nattch
))( __builtin_choose_expr(sizeof(*(&target_sd->shm_nattch
)) == 1, ldub_p, __builtin_choose_expr(sizeof(*(&target_sd
->shm_nattch)) == 2, lduw_be_p, __builtin_choose_expr(sizeof
(*(&target_sd->shm_nattch)) == 4, ldl_be_p, __builtin_choose_expr
(sizeof(*(&target_sd->shm_nattch)) == 8, ldq_be_p, abort
)))) (&target_sd->shm_nattch)), 0)
;
2965 unlock_user_struct(target_sd, target_addr, 0)unlock_user(target_sd, target_addr, (0) ? sizeof(*target_sd) :
0)
;
2966 return 0;
2967}
2968
2969static inline abi_long host_to_target_shmid_ds(abi_ulong target_addr,
2970 struct shmid_ds *host_sd)
2971{
2972 struct target_shmid_ds *target_sd;
2973
2974 if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)(target_sd = lock_user(1, target_addr, sizeof(*target_sd), 0)
)
)
2975 return -TARGET_EFAULT14;
2976 if (host_to_target_ipc_perm(target_addr, &(host_sd->shm_perm)))
2977 return -TARGET_EFAULT14;
2978 __put_user(host_sd->shm_segsz, &target_sd->shm_segsz)(__builtin_choose_expr(sizeof(*(&target_sd->shm_segsz)
) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_sd->
shm_segsz)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_sd->shm_segsz)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_sd->shm_segsz)) == 8, stq_be_p, abort
)))) ((&target_sd->shm_segsz), (host_sd->shm_segsz)
), 0)
;
2979 __put_user(host_sd->shm_atime, &target_sd->shm_atime)(__builtin_choose_expr(sizeof(*(&target_sd->shm_atime)
) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_sd->
shm_atime)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_sd->shm_atime)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_sd->shm_atime)) == 8, stq_be_p, abort
)))) ((&target_sd->shm_atime), (host_sd->shm_atime)
), 0)
;
2980 __put_user(host_sd->shm_dtime, &target_sd->shm_dtime)(__builtin_choose_expr(sizeof(*(&target_sd->shm_dtime)
) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_sd->
shm_dtime)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_sd->shm_dtime)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_sd->shm_dtime)) == 8, stq_be_p, abort
)))) ((&target_sd->shm_dtime), (host_sd->shm_dtime)
), 0)
;
2981 __put_user(host_sd->shm_ctime, &target_sd->shm_ctime)(__builtin_choose_expr(sizeof(*(&target_sd->shm_ctime)
) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_sd->
shm_ctime)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_sd->shm_ctime)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_sd->shm_ctime)) == 8, stq_be_p, abort
)))) ((&target_sd->shm_ctime), (host_sd->shm_ctime)
), 0)
;
2982 __put_user(host_sd->shm_cpid, &target_sd->shm_cpid)(__builtin_choose_expr(sizeof(*(&target_sd->shm_cpid))
== 1, stb_p, __builtin_choose_expr(sizeof(*(&target_sd->
shm_cpid)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_sd->shm_cpid)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_sd->shm_cpid)) == 8, stq_be_p, abort
)))) ((&target_sd->shm_cpid), (host_sd->shm_cpid)),
0)
;
2983 __put_user(host_sd->shm_lpid, &target_sd->shm_lpid)(__builtin_choose_expr(sizeof(*(&target_sd->shm_lpid))
== 1, stb_p, __builtin_choose_expr(sizeof(*(&target_sd->
shm_lpid)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_sd->shm_lpid)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_sd->shm_lpid)) == 8, stq_be_p, abort
)))) ((&target_sd->shm_lpid), (host_sd->shm_lpid)),
0)
;
2984 __put_user(host_sd->shm_nattch, &target_sd->shm_nattch)(__builtin_choose_expr(sizeof(*(&target_sd->shm_nattch
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_sd
->shm_nattch)) == 2, stw_be_p, __builtin_choose_expr(sizeof
(*(&target_sd->shm_nattch)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_sd->shm_nattch)) == 8, stq_be_p, abort
)))) ((&target_sd->shm_nattch), (host_sd->shm_nattch
)), 0)
;
2985 unlock_user_struct(target_sd, target_addr, 1)unlock_user(target_sd, target_addr, (1) ? sizeof(*target_sd) :
0)
;
2986 return 0;
2987}
2988
2989struct target_shminfo {
2990 abi_ulong shmmax;
2991 abi_ulong shmmin;
2992 abi_ulong shmmni;
2993 abi_ulong shmseg;
2994 abi_ulong shmall;
2995};
2996
2997static inline abi_long host_to_target_shminfo(abi_ulong target_addr,
2998 struct shminfo *host_shminfo)
2999{
3000 struct target_shminfo *target_shminfo;
3001 if (!lock_user_struct(VERIFY_WRITE, target_shminfo, target_addr, 0)(target_shminfo = lock_user(1, target_addr, sizeof(*target_shminfo
), 0))
)
3002 return -TARGET_EFAULT14;
3003 __put_user(host_shminfo->shmmax, &target_shminfo->shmmax)(__builtin_choose_expr(sizeof(*(&target_shminfo->shmmax
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_shminfo
->shmmax)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_shminfo->shmmax)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_shminfo->shmmax)) == 8, stq_be_p, abort
)))) ((&target_shminfo->shmmax), (host_shminfo->shmmax
)), 0)
;
3004 __put_user(host_shminfo->shmmin, &target_shminfo->shmmin)(__builtin_choose_expr(sizeof(*(&target_shminfo->shmmin
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_shminfo
->shmmin)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_shminfo->shmmin)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_shminfo->shmmin)) == 8, stq_be_p, abort
)))) ((&target_shminfo->shmmin), (host_shminfo->shmmin
)), 0)
;
3005 __put_user(host_shminfo->shmmni, &target_shminfo->shmmni)(__builtin_choose_expr(sizeof(*(&target_shminfo->shmmni
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_shminfo
->shmmni)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_shminfo->shmmni)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_shminfo->shmmni)) == 8, stq_be_p, abort
)))) ((&target_shminfo->shmmni), (host_shminfo->shmmni
)), 0)
;
3006 __put_user(host_shminfo->shmseg, &target_shminfo->shmseg)(__builtin_choose_expr(sizeof(*(&target_shminfo->shmseg
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_shminfo
->shmseg)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_shminfo->shmseg)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_shminfo->shmseg)) == 8, stq_be_p, abort
)))) ((&target_shminfo->shmseg), (host_shminfo->shmseg
)), 0)
;
3007 __put_user(host_shminfo->shmall, &target_shminfo->shmall)(__builtin_choose_expr(sizeof(*(&target_shminfo->shmall
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_shminfo
->shmall)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(
&target_shminfo->shmall)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_shminfo->shmall)) == 8, stq_be_p, abort
)))) ((&target_shminfo->shmall), (host_shminfo->shmall
)), 0)
;
3008 unlock_user_struct(target_shminfo, target_addr, 1)unlock_user(target_shminfo, target_addr, (1) ? sizeof(*target_shminfo
) : 0)
;
3009 return 0;
3010}
3011
3012struct target_shm_info {
3013 int used_ids;
3014 abi_ulong shm_tot;
3015 abi_ulong shm_rss;
3016 abi_ulong shm_swp;
3017 abi_ulong swap_attempts;
3018 abi_ulong swap_successes;
3019};
3020
3021static inline abi_long host_to_target_shm_info(abi_ulong target_addr,
3022 struct shm_info *host_shm_info)
3023{
3024 struct target_shm_info *target_shm_info;
3025 if (!lock_user_struct(VERIFY_WRITE, target_shm_info, target_addr, 0)(target_shm_info = lock_user(1, target_addr, sizeof(*target_shm_info
), 0))
)
3026 return -TARGET_EFAULT14;
3027 __put_user(host_shm_info->used_ids, &target_shm_info->used_ids)(__builtin_choose_expr(sizeof(*(&target_shm_info->used_ids
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_shm_info
->used_ids)) == 2, stw_be_p, __builtin_choose_expr(sizeof(
*(&target_shm_info->used_ids)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_shm_info->used_ids)) == 8, stq_be_p,
abort)))) ((&target_shm_info->used_ids), (host_shm_info
->used_ids)), 0)
;
3028 __put_user(host_shm_info->shm_tot, &target_shm_info->shm_tot)(__builtin_choose_expr(sizeof(*(&target_shm_info->shm_tot
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_shm_info
->shm_tot)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*
(&target_shm_info->shm_tot)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_shm_info->shm_tot)) == 8, stq_be_p, abort
)))) ((&target_shm_info->shm_tot), (host_shm_info->
shm_tot)), 0)
;
3029 __put_user(host_shm_info->shm_rss, &target_shm_info->shm_rss)(__builtin_choose_expr(sizeof(*(&target_shm_info->shm_rss
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_shm_info
->shm_rss)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*
(&target_shm_info->shm_rss)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_shm_info->shm_rss)) == 8, stq_be_p, abort
)))) ((&target_shm_info->shm_rss), (host_shm_info->
shm_rss)), 0)
;
3030 __put_user(host_shm_info->shm_swp, &target_shm_info->shm_swp)(__builtin_choose_expr(sizeof(*(&target_shm_info->shm_swp
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_shm_info
->shm_swp)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*
(&target_shm_info->shm_swp)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_shm_info->shm_swp)) == 8, stq_be_p, abort
)))) ((&target_shm_info->shm_swp), (host_shm_info->
shm_swp)), 0)
;
3031 __put_user(host_shm_info->swap_attempts, &target_shm_info->swap_attempts)(__builtin_choose_expr(sizeof(*(&target_shm_info->swap_attempts
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_shm_info
->swap_attempts)) == 2, stw_be_p, __builtin_choose_expr(sizeof
(*(&target_shm_info->swap_attempts)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_shm_info->swap_attempts)) == 8, stq_be_p
, abort)))) ((&target_shm_info->swap_attempts), (host_shm_info
->swap_attempts)), 0)
;
3032 __put_user(host_shm_info->swap_successes, &target_shm_info->swap_successes)(__builtin_choose_expr(sizeof(*(&target_shm_info->swap_successes
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_shm_info
->swap_successes)) == 2, stw_be_p, __builtin_choose_expr(sizeof
(*(&target_shm_info->swap_successes)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_shm_info->swap_successes)) == 8, stq_be_p
, abort)))) ((&target_shm_info->swap_successes), (host_shm_info
->swap_successes)), 0)
;
3033 unlock_user_struct(target_shm_info, target_addr, 1)unlock_user(target_shm_info, target_addr, (1) ? sizeof(*target_shm_info
) : 0)
;
3034 return 0;
3035}
3036
3037static inline abi_long do_shmctl(int shmid, int cmd, abi_long buf)
3038{
3039 struct shmid_ds dsarg;
3040 struct shminfo shminfo;
3041 struct shm_info shm_info;
3042 abi_long ret = -TARGET_EINVAL22;
3043
3044 cmd &= 0xff;
3045
3046 switch(cmd) {
3047 case IPC_STAT2:
3048 case IPC_SET1:
3049 case SHM_STAT13:
3050 if (target_to_host_shmid_ds(&dsarg, buf))
3051 return -TARGET_EFAULT14;
3052 ret = get_errno(shmctl(shmid, cmd, &dsarg));
3053 if (host_to_target_shmid_ds(buf, &dsarg))
3054 return -TARGET_EFAULT14;
3055 break;
3056 case IPC_INFO3:
3057 ret = get_errno(shmctl(shmid, cmd, (struct shmid_ds *)&shminfo));
3058 if (host_to_target_shminfo(buf, &shminfo))
3059 return -TARGET_EFAULT14;
3060 break;
3061 case SHM_INFO14:
3062 ret = get_errno(shmctl(shmid, cmd, (struct shmid_ds *)&shm_info));
3063 if (host_to_target_shm_info(buf, &shm_info))
3064 return -TARGET_EFAULT14;
3065 break;
3066 case IPC_RMID0:
3067 case SHM_LOCK11:
3068 case SHM_UNLOCK12:
3069 ret = get_errno(shmctl(shmid, cmd, NULL((void*)0)));
3070 break;
3071 }
3072
3073 return ret;
3074}
3075
3076static inline abi_ulong do_shmat(int shmid, abi_ulong shmaddr, int shmflg)
3077{
3078 abi_long raddr;
3079 void *host_raddr;
3080 struct shmid_ds shm_info;
3081 int i,ret;
3082
3083 /* find out the length of the shared memory segment */
3084 ret = get_errno(shmctl(shmid, IPC_STAT2, &shm_info));
3085 if (is_error(ret)) {
3086 /* can't get length, bail out */
3087 return ret;
3088 }
3089
3090 mmap_lock();
3091
3092 if (shmaddr)
3093 host_raddr = shmat(shmid, (void *)g2h(shmaddr)((void *)((unsigned long)(target_ulong)(shmaddr) + guest_base
))
, shmflg);
3094 else {
3095 abi_ulong mmap_start;
3096
3097 mmap_start = mmap_find_vma(0, shm_info.shm_segsz);
3098
3099 if (mmap_start == -1) {
3100 errno(*__errno_location ()) = ENOMEM12;
3101 host_raddr = (void *)-1;
3102 } else
3103 host_raddr = shmat(shmid, g2h(mmap_start)((void *)((unsigned long)(target_ulong)(mmap_start) + guest_base
))
, shmflg | SHM_REMAP040000);
3104 }
3105
3106 if (host_raddr == (void *)-1) {
3107 mmap_unlock();
3108 return get_errno((long)host_raddr);
3109 }
3110 raddr=h2g((unsigned long)host_raddr)({ ((1) ? (void) (0) : __assert_fail ("1", "/home/stefan/src/qemu/qemu.org/qemu/linux-user/syscall.c"
, 3110, __PRETTY_FUNCTION__)); ({ unsigned long __ret = (unsigned
long)((unsigned long)host_raddr) - guest_base; (abi_ulong)__ret
; }); })
;
3111
3112 page_set_flags(raddr, raddr + shm_info.shm_segsz,
3113 PAGE_VALID0x0008 | PAGE_READ0x0001 |
3114 ((shmflg & SHM_RDONLY010000)? 0 : PAGE_WRITE0x0002));
3115
3116 for (i = 0; i < N_SHM_REGIONS32; i++) {
3117 if (shm_regions[i].start == 0) {
3118 shm_regions[i].start = raddr;
3119 shm_regions[i].size = shm_info.shm_segsz;
3120 break;
3121 }
3122 }
3123
3124 mmap_unlock();
3125 return raddr;
3126
3127}
3128
3129static inline abi_long do_shmdt(abi_ulong shmaddr)
3130{
3131 int i;
3132
3133 for (i = 0; i < N_SHM_REGIONS32; ++i) {
3134 if (shm_regions[i].start == shmaddr) {
3135 shm_regions[i].start = 0;
3136 page_set_flags(shmaddr, shmaddr + shm_regions[i].size, 0);
3137 break;
3138 }
3139 }
3140
3141 return get_errno(shmdt(g2h(shmaddr)((void *)((unsigned long)(target_ulong)(shmaddr) + guest_base
))
));
3142}
3143
3144#ifdef TARGET_NR_ipc117
3145/* ??? This only works with linear mappings. */
3146/* do_ipc() must return target values and target errnos. */
3147static abi_long do_ipc(unsigned int call, int first,
3148 int second, int third,
3149 abi_long ptr, abi_long fifth)
3150{
3151 int version;
3152 abi_long ret = 0;
3153
3154 version = call >> 16;
3155 call &= 0xffff;
3156
3157 switch (call) {
3158 case IPCOP_semop1:
3159 ret = do_semop(first, ptr, second);
3160 break;
3161
3162 case IPCOP_semget2:
3163 ret = get_errno(semget(first, second, third));
3164 break;
3165
3166 case IPCOP_semctl3:
3167 ret = do_semctl(first, second, third, (union target_semun)(abi_ulong) ptr);
3168 break;
3169
3170 case IPCOP_msgget13:
3171 ret = get_errno(msgget(first, second));
3172 break;
3173
3174 case IPCOP_msgsnd11:
3175 ret = do_msgsnd(first, ptr, second, third);
3176 break;
3177
3178 case IPCOP_msgctl14:
3179 ret = do_msgctl(first, second, ptr);
3180 break;
3181
3182 case IPCOP_msgrcv12:
3183 switch (version) {
3184 case 0:
3185 {
3186 struct target_ipc_kludge {
3187 abi_long msgp;
3188 abi_long msgtyp;
3189 } *tmp;
3190
3191 if (!lock_user_struct(VERIFY_READ, tmp, ptr, 1)(tmp = lock_user(0, ptr, sizeof(*tmp), 1))) {
3192 ret = -TARGET_EFAULT14;
3193 break;
3194 }
3195
3196 ret = do_msgrcv(first, tswapal(tmp->msgp), second, tswapal(tmp->msgtyp), third);
3197
3198 unlock_user_struct(tmp, ptr, 0)unlock_user(tmp, ptr, (0) ? sizeof(*tmp) : 0);
3199 break;
3200 }
3201 default:
3202 ret = do_msgrcv(first, ptr, second, fifth, third);
3203 }
3204 break;
3205
3206 case IPCOP_shmat21:
3207 switch (version) {
3208 default:
3209 {
3210 abi_ulong raddr;
3211 raddr = do_shmat(first, ptr, second);
3212 if (is_error(raddr))
3213 return get_errno(raddr);
3214 if (put_user_ual(raddr, third)({ abi_ulong __gaddr = ((third)); abi_ulong *__hptr; abi_long
__ret; if ((__hptr = lock_user(1, __gaddr, sizeof(abi_ulong)
, 0))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1
, stb_p, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), (((raddr
)))), 0); unlock_user(__hptr, __gaddr, sizeof(abi_ulong)); } else
__ret = -14; __ret; })
)
3215 return -TARGET_EFAULT14;
3216 break;
3217 }
3218 case 1:
3219 ret = -TARGET_EINVAL22;
3220 break;
3221 }
3222 break;
3223 case IPCOP_shmdt22:
3224 ret = do_shmdt(ptr);
3225 break;
3226
3227 case IPCOP_shmget23:
3228 /* IPC_* flag values are the same on all linux platforms */
3229 ret = get_errno(shmget(first, second, third));
3230 break;
3231
3232 /* IPC_* and SHM_* command values are the same on all linux platforms */
3233 case IPCOP_shmctl24:
3234 ret = do_shmctl(first, second, ptr);
3235 break;
3236 default:
3237 gemu_log("Unsupported ipc call: %d (version %d)\n", call, version);
3238 ret = -TARGET_ENOSYS38;
3239 break;
3240 }
3241 return ret;
3242}
3243#endif
3244
3245/* kernel structure types definitions */
3246
3247#define STRUCT(name, ...) STRUCT_ ## name,
3248#define STRUCT_SPECIAL(name) STRUCT_ ## name,
3249enum {
3250#include "syscall_types.h"
3251};
3252#undef STRUCT
3253#undef STRUCT_SPECIAL
3254
3255#define STRUCT(name, ...) static const argtype struct_ ## name ## _def[] = { __VA_ARGS__, TYPE_NULL };
3256#define STRUCT_SPECIAL(name)
3257#include "syscall_types.h"
3258#undef STRUCT
3259#undef STRUCT_SPECIAL
3260
3261typedef struct IOCTLEntry IOCTLEntry;
3262
3263typedef abi_long do_ioctl_fn(const IOCTLEntry *ie, uint8_t *buf_temp,
3264 int fd, abi_long cmd, abi_long arg);
3265
3266struct IOCTLEntry {
3267 unsigned int target_cmd;
3268 unsigned int host_cmd;
3269 const char *name;
3270 int access;
3271 do_ioctl_fn *do_ioctl;
3272 const argtype arg_type[5];
3273};
3274
3275#define IOC_R0x0001 0x0001
3276#define IOC_W0x0002 0x0002
3277#define IOC_RW(0x0001 | 0x0002) (IOC_R0x0001 | IOC_W0x0002)
3278
3279#define MAX_STRUCT_SIZE4096 4096
3280
3281#ifdef CONFIG_FIEMAP1
3282/* So fiemap access checks don't overflow on 32 bit systems.
3283 * This is very slightly smaller than the limit imposed by
3284 * the underlying kernel.
3285 */
3286#define FIEMAP_MAX_EXTENTS(((2147483647 *2U +1U) - sizeof(struct fiemap)) / sizeof(struct
fiemap_extent))
((UINT_MAX(2147483647 *2U +1U) - sizeof(struct fiemap)) \
3287 / sizeof(struct fiemap_extent))
3288
3289static abi_long do_ioctl_fs_ioc_fiemap(const IOCTLEntry *ie, uint8_t *buf_temp,
3290 int fd, abi_long cmd, abi_long arg)
3291{
3292 /* The parameter for this ioctl is a struct fiemap followed
3293 * by an array of struct fiemap_extent whose size is set
3294 * in fiemap->fm_extent_count. The array is filled in by the
3295 * ioctl.
3296 */
3297 int target_size_in, target_size_out;
3298 struct fiemap *fm;
3299 const argtype *arg_type = ie->arg_type;
3300 const argtype extent_arg_type[] = { MK_STRUCT(STRUCT_fiemap_extent)TYPE_STRUCT, STRUCT_fiemap_extent };
3301 void *argptr, *p;
3302 abi_long ret;
3303 int i, extent_size = thunk_type_size(extent_arg_type, 0);
3304 uint32_t outbufsz;
3305 int free_fm = 0;
3306
3307 assert(arg_type[0] == TYPE_PTR)((arg_type[0] == TYPE_PTR) ? (void) (0) : __assert_fail ("arg_type[0] == TYPE_PTR"
, "/home/stefan/src/qemu/qemu.org/qemu/linux-user/syscall.c",
3307, __PRETTY_FUNCTION__))
;
3308 assert(ie->access == IOC_RW)((ie->access == (0x0001 | 0x0002)) ? (void) (0) : __assert_fail
("ie->access == (0x0001 | 0x0002)", "/home/stefan/src/qemu/qemu.org/qemu/linux-user/syscall.c"
, 3308, __PRETTY_FUNCTION__))
;
3309 arg_type++;
3310 target_size_in = thunk_type_size(arg_type, 0);
3311 argptr = lock_user(VERIFY_READ0, arg, target_size_in, 1);
3312 if (!argptr) {
3313 return -TARGET_EFAULT14;
3314 }
3315 thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST1);
3316 unlock_user(argptr, arg, 0);
3317 fm = (struct fiemap *)buf_temp;
3318 if (fm->fm_extent_count > FIEMAP_MAX_EXTENTS(((2147483647 *2U +1U) - sizeof(struct fiemap)) / sizeof(struct
fiemap_extent))
) {
3319 return -TARGET_EINVAL22;
3320 }
3321
3322 outbufsz = sizeof (*fm) +
3323 (sizeof(struct fiemap_extent) * fm->fm_extent_count);
3324
3325 if (outbufsz > MAX_STRUCT_SIZE4096) {
3326 /* We can't fit all the extents into the fixed size buffer.
3327 * Allocate one that is large enough and use it instead.
3328 */
3329 fm = malloc(outbufsz);
3330 if (!fm) {
3331 return -TARGET_ENOMEM12;
3332 }
3333 memcpy(fm, buf_temp, sizeof(struct fiemap));
3334 free_fm = 1;
3335 }
3336 ret = get_errno(ioctl(fd, ie->host_cmd, fm));
3337 if (!is_error(ret)) {
3338 target_size_out = target_size_in;
3339 /* An extent_count of 0 means we were only counting the extents
3340 * so there are no structs to copy
3341 */
3342 if (fm->fm_extent_count != 0) {
3343 target_size_out += fm->fm_mapped_extents * extent_size;
3344 }
3345 argptr = lock_user(VERIFY_WRITE1, arg, target_size_out, 0);
3346 if (!argptr) {
3347 ret = -TARGET_EFAULT14;
3348 } else {
3349 /* Convert the struct fiemap */
3350 thunk_convert(argptr, fm, arg_type, THUNK_TARGET0);
3351 if (fm->fm_extent_count != 0) {
3352 p = argptr + target_size_in;
3353 /* ...and then all the struct fiemap_extents */
3354 for (i = 0; i < fm->fm_mapped_extents; i++) {
3355 thunk_convert(p, &fm->fm_extents[i], extent_arg_type,
3356 THUNK_TARGET0);
3357 p += extent_size;
3358 }
3359 }
3360 unlock_user(argptr, arg, target_size_out);
3361 }
3362 }
3363 if (free_fm) {
3364 free(fm);
3365 }
3366 return ret;
3367}
3368#endif
3369
3370static abi_long do_ioctl_ifconf(const IOCTLEntry *ie, uint8_t *buf_temp,
3371 int fd, abi_long cmd, abi_long arg)
3372{
3373 const argtype *arg_type = ie->arg_type;
3374 int target_size;
3375 void *argptr;
3376 int ret;
3377 struct ifconf *host_ifconf;
3378 uint32_t outbufsz;
3379 const argtype ifreq_arg_type[] = { MK_STRUCT(STRUCT_sockaddr_ifreq)TYPE_STRUCT, STRUCT_sockaddr_ifreq };
3380 int target_ifreq_size;
3381 int nb_ifreq;
3382 int free_buf = 0;
3383 int i;
3384 int target_ifc_len;
3385 abi_long target_ifc_buf;
3386 int host_ifc_len;
3387 char *host_ifc_buf;
3388
3389 assert(arg_type[0] == TYPE_PTR)((arg_type[0] == TYPE_PTR) ? (void) (0) : __assert_fail ("arg_type[0] == TYPE_PTR"
, "/home/stefan/src/qemu/qemu.org/qemu/linux-user/syscall.c",
3389, __PRETTY_FUNCTION__))
;
3390 assert(ie->access == IOC_RW)((ie->access == (0x0001 | 0x0002)) ? (void) (0) : __assert_fail
("ie->access == (0x0001 | 0x0002)", "/home/stefan/src/qemu/qemu.org/qemu/linux-user/syscall.c"
, 3390, __PRETTY_FUNCTION__))
;
3391
3392 arg_type++;
3393 target_size = thunk_type_size(arg_type, 0);
3394
3395 argptr = lock_user(VERIFY_READ0, arg, target_size, 1);
3396 if (!argptr)
3397 return -TARGET_EFAULT14;
3398 thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST1);
3399 unlock_user(argptr, arg, 0);
3400
3401 host_ifconf = (struct ifconf *)(unsigned long)buf_temp;
3402 target_ifc_len = host_ifconf->ifc_len;
3403 target_ifc_buf = (abi_long)(unsigned long)host_ifconf->ifc_bufifc_ifcu.ifcu_buf;
3404
3405 target_ifreq_size = thunk_type_size(ifreq_arg_type, 0);
3406 nb_ifreq = target_ifc_len / target_ifreq_size;
3407 host_ifc_len = nb_ifreq * sizeof(struct ifreq);
3408
3409 outbufsz = sizeof(*host_ifconf) + host_ifc_len;
3410 if (outbufsz > MAX_STRUCT_SIZE4096) {
3411 /* We can't fit all the extents into the fixed size buffer.
3412 * Allocate one that is large enough and use it instead.
3413 */
3414 host_ifconf = malloc(outbufsz);
3415 if (!host_ifconf) {
3416 return -TARGET_ENOMEM12;
3417 }
3418 memcpy(host_ifconf, buf_temp, sizeof(*host_ifconf));
3419 free_buf = 1;
3420 }
3421 host_ifc_buf = (char*)host_ifconf + sizeof(*host_ifconf);
3422
3423 host_ifconf->ifc_len = host_ifc_len;
3424 host_ifconf->ifc_bufifc_ifcu.ifcu_buf = host_ifc_buf;
3425
3426 ret = get_errno(ioctl(fd, ie->host_cmd, host_ifconf));
3427 if (!is_error(ret)) {
3428 /* convert host ifc_len to target ifc_len */
3429
3430 nb_ifreq = host_ifconf->ifc_len / sizeof(struct ifreq);
3431 target_ifc_len = nb_ifreq * target_ifreq_size;
3432 host_ifconf->ifc_len = target_ifc_len;
3433
3434 /* restore target ifc_buf */
3435
3436 host_ifconf->ifc_bufifc_ifcu.ifcu_buf = (char *)(unsigned long)target_ifc_buf;
3437
3438 /* copy struct ifconf to target user */
3439
3440 argptr = lock_user(VERIFY_WRITE1, arg, target_size, 0);
3441 if (!argptr)
3442 return -TARGET_EFAULT14;
3443 thunk_convert(argptr, host_ifconf, arg_type, THUNK_TARGET0);
3444 unlock_user(argptr, arg, target_size);
3445
3446 /* copy ifreq[] to target user */
3447
3448 argptr = lock_user(VERIFY_WRITE1, target_ifc_buf, target_ifc_len, 0);
3449 for (i = 0; i < nb_ifreq ; i++) {
3450 thunk_convert(argptr + i * target_ifreq_size,
3451 host_ifc_buf + i * sizeof(struct ifreq),
3452 ifreq_arg_type, THUNK_TARGET0);
3453 }
3454 unlock_user(argptr, target_ifc_buf, target_ifc_len);
3455 }
3456
3457 if (free_buf) {
3458 free(host_ifconf);
3459 }
3460
3461 return ret;
3462}
3463
3464static abi_long do_ioctl_dm(const IOCTLEntry *ie, uint8_t *buf_temp, int fd,
3465 abi_long cmd, abi_long arg)
3466{
3467 void *argptr;
3468 struct dm_ioctl *host_dm;
3469 abi_long guest_data;
3470 uint32_t guest_data_size;
3471 int target_size;
3472 const argtype *arg_type = ie->arg_type;
3473 abi_long ret;
3474 void *big_buf = NULL((void*)0);
3475 char *host_data;
3476
3477 arg_type++;
3478 target_size = thunk_type_size(arg_type, 0);
3479 argptr = lock_user(VERIFY_READ0, arg, target_size, 1);
3480 if (!argptr) {
3481 ret = -TARGET_EFAULT14;
3482 goto out;
3483 }
3484 thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST1);
3485 unlock_user(argptr, arg, 0);
3486
3487 /* buf_temp is too small, so fetch things into a bigger buffer */
3488 big_buf = g_malloc0(((struct dm_ioctl*)buf_temp)->data_size * 2);
3489 memcpy(big_buf, buf_temp, target_size);
3490 buf_temp = big_buf;
3491 host_dm = big_buf;
3492
3493 guest_data = arg + host_dm->data_start;
3494 if ((guest_data - arg) < 0) {
3495 ret = -EINVAL22;
3496 goto out;
3497 }
3498 guest_data_size = host_dm->data_size - host_dm->data_start;
3499 host_data = (char*)host_dm + host_dm->data_start;
3500
3501 argptr = lock_user(VERIFY_READ0, guest_data, guest_data_size, 1);
3502 switch (ie->host_cmd) {
3503 case DM_REMOVE_ALL(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_REMOVE_ALL_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3504 case DM_LIST_DEVICES(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_LIST_DEVICES_CMD)) << 0) | ((((sizeof(struct
dm_ioctl)))) << ((0 +8)+8)))
:
3505 case DM_DEV_CREATE(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_DEV_CREATE_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3506 case DM_DEV_REMOVE(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_DEV_REMOVE_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3507 case DM_DEV_SUSPEND(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_DEV_SUSPEND_CMD)) << 0) | ((((sizeof(struct
dm_ioctl)))) << ((0 +8)+8)))
:
3508 case DM_DEV_STATUS(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_DEV_STATUS_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3509 case DM_DEV_WAIT(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_DEV_WAIT_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3510 case DM_TABLE_STATUS(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_TABLE_STATUS_CMD)) << 0) | ((((sizeof(struct
dm_ioctl)))) << ((0 +8)+8)))
:
3511 case DM_TABLE_CLEAR(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_TABLE_CLEAR_CMD)) << 0) | ((((sizeof(struct
dm_ioctl)))) << ((0 +8)+8)))
:
3512 case DM_TABLE_DEPS(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_TABLE_DEPS_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3513 case DM_LIST_VERSIONS(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_LIST_VERSIONS_CMD)) << 0) | ((((sizeof(struct
dm_ioctl)))) << ((0 +8)+8)))
:
3514 /* no input data */
3515 break;
3516 case DM_DEV_RENAME(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_DEV_RENAME_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3517 case DM_DEV_SET_GEOMETRY(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_DEV_SET_GEOMETRY_CMD)) << 0) | ((((sizeof(struct
dm_ioctl)))) << ((0 +8)+8)))
:
3518 /* data contains only strings */
3519 memcpy(host_data, argptr, guest_data_size);
3520 break;
3521 case DM_TARGET_MSG(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_TARGET_MSG_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3522 memcpy(host_data, argptr, guest_data_size);
3523 *(uint64_t*)host_data = tswap64(*(uint64_t*)argptr);
3524 break;
3525 case DM_TABLE_LOAD(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_TABLE_LOAD_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3526 {
3527 void *gspec = argptr;
3528 void *cur_data = host_data;
3529 const argtype arg_type[] = { MK_STRUCT(STRUCT_dm_target_spec)TYPE_STRUCT, STRUCT_dm_target_spec };
3530 int spec_size = thunk_type_size(arg_type, 0);
3531 int i;
3532
3533 for (i = 0; i < host_dm->target_count; i++) {
3534 struct dm_target_spec *spec = cur_data;
3535 uint32_t next;
3536 int slen;
3537
3538 thunk_convert(spec, gspec, arg_type, THUNK_HOST1);
3539 slen = strlen((char*)gspec + spec_size) + 1;
3540 next = spec->next;
3541 spec->next = sizeof(*spec) + slen;
3542 strcpy((char*)&spec[1], gspec + spec_size);
3543 gspec += next;
3544 cur_data += spec->next;
3545 }
3546 break;
3547 }
3548 default:
3549 ret = -TARGET_EINVAL22;
3550 goto out;
3551 }
3552 unlock_user(argptr, guest_data, 0);
3553
3554 ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp));
3555 if (!is_error(ret)) {
3556 guest_data = arg + host_dm->data_start;
3557 guest_data_size = host_dm->data_size - host_dm->data_start;
3558 argptr = lock_user(VERIFY_WRITE1, guest_data, guest_data_size, 0);
3559 switch (ie->host_cmd) {
3560 case DM_REMOVE_ALL(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_REMOVE_ALL_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3561 case DM_DEV_CREATE(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_DEV_CREATE_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3562 case DM_DEV_REMOVE(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_DEV_REMOVE_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3563 case DM_DEV_RENAME(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_DEV_RENAME_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3564 case DM_DEV_SUSPEND(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_DEV_SUSPEND_CMD)) << 0) | ((((sizeof(struct
dm_ioctl)))) << ((0 +8)+8)))
:
3565 case DM_DEV_STATUS(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_DEV_STATUS_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3566 case DM_TABLE_LOAD(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_TABLE_LOAD_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3567 case DM_TABLE_CLEAR(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_TABLE_CLEAR_CMD)) << 0) | ((((sizeof(struct
dm_ioctl)))) << ((0 +8)+8)))
:
3568 case DM_TARGET_MSG(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_TARGET_MSG_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3569 case DM_DEV_SET_GEOMETRY(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_DEV_SET_GEOMETRY_CMD)) << 0) | ((((sizeof(struct
dm_ioctl)))) << ((0 +8)+8)))
:
3570 /* no return data */
3571 break;
3572 case DM_LIST_DEVICES(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_LIST_DEVICES_CMD)) << 0) | ((((sizeof(struct
dm_ioctl)))) << ((0 +8)+8)))
:
3573 {
3574 struct dm_name_list *nl = (void*)host_dm + host_dm->data_start;
3575 uint32_t remaining_data = guest_data_size;
3576 void *cur_data = argptr;
3577 const argtype arg_type[] = { MK_STRUCT(STRUCT_dm_name_list)TYPE_STRUCT, STRUCT_dm_name_list };
3578 int nl_size = 12; /* can't use thunk_size due to alignment */
3579
3580 while (1) {
3581 uint32_t next = nl->next;
3582 if (next) {
3583 nl->next = nl_size + (strlen(nl->name) + 1);
3584 }
3585 if (remaining_data < nl->next) {
3586 host_dm->flags |= DM_BUFFER_FULL_FLAG(1 << 8);
3587 break;
3588 }
3589 thunk_convert(cur_data, nl, arg_type, THUNK_TARGET0);
3590 strcpy(cur_data + nl_size, nl->name);
3591 cur_data += nl->next;
3592 remaining_data -= nl->next;
3593 if (!next) {
3594 break;
3595 }
3596 nl = (void*)nl + next;
3597 }
3598 break;
3599 }
3600 case DM_DEV_WAIT(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_DEV_WAIT_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3601 case DM_TABLE_STATUS(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_TABLE_STATUS_CMD)) << 0) | ((((sizeof(struct
dm_ioctl)))) << ((0 +8)+8)))
:
3602 {
3603 struct dm_target_spec *spec = (void*)host_dm + host_dm->data_start;
3604 void *cur_data = argptr;
3605 const argtype arg_type[] = { MK_STRUCT(STRUCT_dm_target_spec)TYPE_STRUCT, STRUCT_dm_target_spec };
3606 int spec_size = thunk_type_size(arg_type, 0);
3607 int i;
3608
3609 for (i = 0; i < host_dm->target_count; i++) {
3610 uint32_t next = spec->next;
3611 int slen = strlen((char*)&spec[1]) + 1;
3612 spec->next = (cur_data - argptr) + spec_size + slen;
3613 if (guest_data_size < spec->next) {
3614 host_dm->flags |= DM_BUFFER_FULL_FLAG(1 << 8);
3615 break;
3616 }
3617 thunk_convert(cur_data, spec, arg_type, THUNK_TARGET0);
3618 strcpy(cur_data + spec_size, (char*)&spec[1]);
3619 cur_data = argptr + spec->next;
3620 spec = (void*)host_dm + host_dm->data_start + next;
3621 }
3622 break;
3623 }
3624 case DM_TABLE_DEPS(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_TABLE_DEPS_CMD)) << 0) | ((((sizeof(struct dm_ioctl
)))) << ((0 +8)+8)))
:
3625 {
3626 void *hdata = (void*)host_dm + host_dm->data_start;
3627 int count = *(uint32_t*)hdata;
3628 uint64_t *hdev = hdata + 8;
3629 uint64_t *gdev = argptr + 8;
3630 int i;
3631
3632 *(uint32_t*)argptr = tswap32(count);
3633 for (i = 0; i < count; i++) {
3634 *gdev = tswap64(*hdev);
3635 gdev++;
3636 hdev++;
3637 }
3638 break;
3639 }
3640 case DM_LIST_VERSIONS(((2U|1U) << (((0 +8)+8)+14)) | (((0xfd)) << (0 +
8)) | (((DM_LIST_VERSIONS_CMD)) << 0) | ((((sizeof(struct
dm_ioctl)))) << ((0 +8)+8)))
:
3641 {
3642 struct dm_target_versions *vers = (void*)host_dm + host_dm->data_start;
3643 uint32_t remaining_data = guest_data_size;
3644 void *cur_data = argptr;
3645 const argtype arg_type[] = { MK_STRUCT(STRUCT_dm_target_versions)TYPE_STRUCT, STRUCT_dm_target_versions };
3646 int vers_size = thunk_type_size(arg_type, 0);
3647
3648 while (1) {
3649 uint32_t next = vers->next;
3650 if (next) {
3651 vers->next = vers_size + (strlen(vers->name) + 1);
3652 }
3653 if (remaining_data < vers->next) {
3654 host_dm->flags |= DM_BUFFER_FULL_FLAG(1 << 8);
3655 break;
3656 }
3657 thunk_convert(cur_data, vers, arg_type, THUNK_TARGET0);
3658 strcpy(cur_data + vers_size, vers->name);
3659 cur_data += vers->next;
3660 remaining_data -= vers->next;
3661 if (!next) {
3662 break;
3663 }
3664 vers = (void*)vers + next;
3665 }
3666 break;
3667 }
3668 default:
3669 ret = -TARGET_EINVAL22;
3670 goto out;
3671 }
3672 unlock_user(argptr, guest_data, guest_data_size);
3673
3674 argptr = lock_user(VERIFY_WRITE1, arg, target_size, 0);
3675 if (!argptr) {
3676 ret = -TARGET_EFAULT14;
3677 goto out;
3678 }
3679 thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET0);
3680 unlock_user(argptr, arg, target_size);
3681 }
3682out:
3683 g_free(big_buf);
3684 return ret;
3685}
3686
3687static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp,
3688 int fd, abi_long cmd, abi_long arg)
3689{
3690 const argtype *arg_type = ie->arg_type;
3691 const StructEntry *se;
3692 const argtype *field_types;
3693 const int *dst_offsets, *src_offsets;
3694 int target_size;
3695 void *argptr;
3696 abi_ulong *target_rt_dev_ptr;
3697 unsigned long *host_rt_dev_ptr;
3698 abi_long ret;
3699 int i;
3700
3701 assert(ie->access == IOC_W)((ie->access == 0x0002) ? (void) (0) : __assert_fail ("ie->access == 0x0002"
, "/home/stefan/src/qemu/qemu.org/qemu/linux-user/syscall.c",
3701, __PRETTY_FUNCTION__))
;
3702 assert(*arg_type == TYPE_PTR)((*arg_type == TYPE_PTR) ? (void) (0) : __assert_fail ("*arg_type == TYPE_PTR"
, "/home/stefan/src/qemu/qemu.org/qemu/linux-user/syscall.c",
3702, __PRETTY_FUNCTION__))
;
3703 arg_type++;
3704 assert(*arg_type == TYPE_STRUCT)((*arg_type == TYPE_STRUCT) ? (void) (0) : __assert_fail ("*arg_type == TYPE_STRUCT"
, "/home/stefan/src/qemu/qemu.org/qemu/linux-user/syscall.c",
3704, __PRETTY_FUNCTION__))
;
3705 target_size = thunk_type_size(arg_type, 0);
3706 argptr = lock_user(VERIFY_READ0, arg, target_size, 1);
3707 if (!argptr) {
3708 return -TARGET_EFAULT14;
3709 }
3710 arg_type++;
3711 assert(*arg_type == (int)STRUCT_rtentry)((*arg_type == (int)STRUCT_rtentry) ? (void) (0) : __assert_fail
("*arg_type == (int)STRUCT_rtentry", "/home/stefan/src/qemu/qemu.org/qemu/linux-user/syscall.c"
, 3711, __PRETTY_FUNCTION__))
;
3712 se = struct_entries + *arg_type++;
3713 assert(se->convert[0] == NULL)((se->convert[0] == ((void*)0)) ? (void) (0) : __assert_fail
("se->convert[0] == ((void*)0)", "/home/stefan/src/qemu/qemu.org/qemu/linux-user/syscall.c"
, 3713, __PRETTY_FUNCTION__))
;
3714 /* convert struct here to be able to catch rt_dev string */
3715 field_types = se->field_types;
3716 dst_offsets = se->field_offsets[THUNK_HOST1];
3717 src_offsets = se->field_offsets[THUNK_TARGET0];
3718 for (i = 0; i < se->nb_fields; i++) {
3719 if (dst_offsets[i] == offsetof(struct rtentry, rt_dev)__builtin_offsetof(struct rtentry, rt_dev)) {
3720 assert(*field_types == TYPE_PTRVOID)((*field_types == TYPE_PTRVOID) ? (void) (0) : __assert_fail (
"*field_types == TYPE_PTRVOID", "/home/stefan/src/qemu/qemu.org/qemu/linux-user/syscall.c"
, 3720, __PRETTY_FUNCTION__))
;
3721 target_rt_dev_ptr = (abi_ulong *)(argptr + src_offsets[i]);
3722 host_rt_dev_ptr = (unsigned long *)(buf_temp + dst_offsets[i]);
3723 if (*target_rt_dev_ptr != 0) {
3724 *host_rt_dev_ptr = (unsigned long)lock_user_string(
3725 tswapal(*target_rt_dev_ptr));
3726 if (!*host_rt_dev_ptr) {
3727 unlock_user(argptr, arg, 0);
3728 return -TARGET_EFAULT14;
3729 }
3730 } else {
3731 *host_rt_dev_ptr = 0;
3732 }
3733 field_types++;
3734 continue;
3735 }
3736 field_types = thunk_convert(buf_temp + dst_offsets[i],
3737 argptr + src_offsets[i],
3738 field_types, THUNK_HOST1);
3739 }
3740 unlock_user(argptr, arg, 0);
3741
3742 ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp));
3743 if (*host_rt_dev_ptr != 0) {
3744 unlock_user((void *)*host_rt_dev_ptr,
3745 *target_rt_dev_ptr, 0);
3746 }
3747 return ret;
3748}
3749
3750static IOCTLEntry ioctl_entries[] = {
3751#define IOCTL(cmd, access, ...){ TARGET_cmd, cmd, "cmd", access, 0, { ... } }, \
3752 { TARGET_ ## cmd, cmd, #cmd, access, 0, { __VA_ARGS__ } },
3753#define IOCTL_SPECIAL(cmd, access, dofn, ...){ TARGET_cmd, cmd, "cmd", access, dofn, { ... } }, \
3754 { TARGET_ ## cmd, cmd, #cmd, access, dofn, { __VA_ARGS__ } },
3755#include "ioctls.h"
3756 { 0, 0, },
3757};
3758
3759/* ??? Implement proper locking for ioctls. */
3760/* do_ioctl() Must return target values and target errnos. */
3761static abi_long do_ioctl(int fd, abi_long cmd, abi_long arg)
3762{
3763 const IOCTLEntry *ie;
3764 const argtype *arg_type;
3765 abi_long ret;
3766 uint8_t buf_temp[MAX_STRUCT_SIZE4096];
3767 int target_size;
3768 void *argptr;
3769
3770 ie = ioctl_entries;
3771 for(;;) {
3772 if (ie->target_cmd == 0) {
3773 gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd);
3774 return -TARGET_ENOSYS38;
3775 }
3776 if (ie->target_cmd == cmd)
3777 break;
3778 ie++;
3779 }
3780 arg_type = ie->arg_type;
3781#if defined(DEBUG)
3782 gemu_log("ioctl: cmd=0x%04lx (%s)\n", (long)cmd, ie->name);
3783#endif
3784 if (ie->do_ioctl) {
3785 return ie->do_ioctl(ie, buf_temp, fd, cmd, arg);
3786 }
3787
3788 switch(arg_type[0]) {
3789 case TYPE_NULL:
3790 /* no argument */
3791 ret = get_errno(ioctl(fd, ie->host_cmd));
3792 break;
3793 case TYPE_PTRVOID:
3794 case TYPE_INT:
3795 /* int argment */
3796 ret = get_errno(ioctl(fd, ie->host_cmd, arg));
3797 break;
3798 case TYPE_PTR:
3799 arg_type++;
3800 target_size = thunk_type_size(arg_type, 0);
3801 switch(ie->access) {
3802 case IOC_R0x0001:
3803 ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp));
3804 if (!is_error(ret)) {
3805 argptr = lock_user(VERIFY_WRITE1, arg, target_size, 0);
3806 if (!argptr)
3807 return -TARGET_EFAULT14;
3808 thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET0);
3809 unlock_user(argptr, arg, target_size);
3810 }
3811 break;
3812 case IOC_W0x0002:
3813 argptr = lock_user(VERIFY_READ0, arg, target_size, 1);
3814 if (!argptr)
3815 return -TARGET_EFAULT14;
3816 thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST1);
3817 unlock_user(argptr, arg, 0);
3818 ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp));
3819 break;
3820 default:
3821 case IOC_RW(0x0001 | 0x0002):
3822 argptr = lock_user(VERIFY_READ0, arg, target_size, 1);
3823 if (!argptr)
3824 return -TARGET_EFAULT14;
3825 thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST1);
3826 unlock_user(argptr, arg, 0);
3827 ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp));
3828 if (!is_error(ret)) {
3829 argptr = lock_user(VERIFY_WRITE1, arg, target_size, 0);
3830 if (!argptr)
3831 return -TARGET_EFAULT14;
3832 thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET0);
3833 unlock_user(argptr, arg, target_size);
3834 }
3835 break;
3836 }
3837 break;
3838 default:
3839 gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n",
3840 (long)cmd, arg_type[0]);
3841 ret = -TARGET_ENOSYS38;
3842 break;
3843 }
3844 return ret;
3845}
3846
3847static const bitmask_transtbl iflag_tbl[] = {
3848 { TARGET_IGNBRK0000001, TARGET_IGNBRK0000001, IGNBRK0000001, IGNBRK0000001 },
3849 { TARGET_BRKINT0000002, TARGET_BRKINT0000002, BRKINT0000002, BRKINT0000002 },
3850 { TARGET_IGNPAR0000004, TARGET_IGNPAR0000004, IGNPAR0000004, IGNPAR0000004 },
3851 { TARGET_PARMRK0000010, TARGET_PARMRK0000010, PARMRK0000010, PARMRK0000010 },
3852 { TARGET_INPCK0000020, TARGET_INPCK0000020, INPCK0000020, INPCK0000020 },
3853 { TARGET_ISTRIP0000040, TARGET_ISTRIP0000040, ISTRIP0000040, ISTRIP0000040 },
3854 { TARGET_INLCR0000100, TARGET_INLCR0000100, INLCR0000100, INLCR0000100 },
3855 { TARGET_IGNCR0000200, TARGET_IGNCR0000200, IGNCR0000200, IGNCR0000200 },
3856 { TARGET_ICRNL0000400, TARGET_ICRNL0000400, ICRNL0000400, ICRNL0000400 },
3857 { TARGET_IUCLC0001000, TARGET_IUCLC0001000, IUCLC0001000, IUCLC0001000 },
3858 { TARGET_IXON0002000, TARGET_IXON0002000, IXON0002000, IXON0002000 },
3859 { TARGET_IXANY0004000, TARGET_IXANY0004000, IXANY0004000, IXANY0004000 },
3860 { TARGET_IXOFF0010000, TARGET_IXOFF0010000, IXOFF0010000, IXOFF0010000 },
3861 { TARGET_IMAXBEL0020000, TARGET_IMAXBEL0020000, IMAXBEL0020000, IMAXBEL0020000 },
3862 { 0, 0, 0, 0 }
3863};
3864
3865static const bitmask_transtbl oflag_tbl[] = {
3866 { TARGET_OPOST0000001, TARGET_OPOST0000001, OPOST0000001, OPOST0000001 },
3867 { TARGET_OLCUC0000002, TARGET_OLCUC0000002, OLCUC0000002, OLCUC0000002 },
3868 { TARGET_ONLCR0000004, TARGET_ONLCR0000004, ONLCR0000004, ONLCR0000004 },
3869 { TARGET_OCRNL0000010, TARGET_OCRNL0000010, OCRNL0000010, OCRNL0000010 },
3870 { TARGET_ONOCR0000020, TARGET_ONOCR0000020, ONOCR0000020, ONOCR0000020 },
3871 { TARGET_ONLRET0000040, TARGET_ONLRET0000040, ONLRET0000040, ONLRET0000040 },
3872 { TARGET_OFILL0000100, TARGET_OFILL0000100, OFILL0000100, OFILL0000100 },
3873 { TARGET_OFDEL0000200, TARGET_OFDEL0000200, OFDEL0000200, OFDEL0000200 },
3874 { TARGET_NLDLY0000400, TARGET_NL00000000, NLDLY0000400, NL00000000 },
3875 { TARGET_NLDLY0000400, TARGET_NL10000400, NLDLY0000400, NL10000400 },
3876 { TARGET_CRDLY0003000, TARGET_CR00000000, CRDLY0003000, CR00000000 },
3877 { TARGET_CRDLY0003000, TARGET_CR10001000, CRDLY0003000, CR10001000 },
3878 { TARGET_CRDLY0003000, TARGET_CR20002000, CRDLY0003000, CR20002000 },
3879 { TARGET_CRDLY0003000, TARGET_CR30003000, CRDLY0003000, CR30003000 },
3880 { TARGET_TABDLY0014000, TARGET_TAB00000000, TABDLY0014000, TAB00000000 },
3881 { TARGET_TABDLY0014000, TARGET_TAB10004000, TABDLY0014000, TAB10004000 },
3882 { TARGET_TABDLY0014000, TARGET_TAB20010000, TABDLY0014000, TAB20010000 },
3883 { TARGET_TABDLY0014000, TARGET_TAB30014000, TABDLY0014000, TAB30014000 },
3884 { TARGET_BSDLY0020000, TARGET_BS00000000, BSDLY0020000, BS00000000 },
3885 { TARGET_BSDLY0020000, TARGET_BS10020000, BSDLY0020000, BS10020000 },
3886 { TARGET_VTDLY0040000, TARGET_VT00000000, VTDLY0040000, VT00000000 },
3887 { TARGET_VTDLY0040000, TARGET_VT10040000, VTDLY0040000, VT10040000 },
3888 { TARGET_FFDLY0100000, TARGET_FF00000000, FFDLY0100000, FF00000000 },
3889 { TARGET_FFDLY0100000, TARGET_FF10100000, FFDLY0100000, FF10100000 },
3890 { 0, 0, 0, 0 }
3891};
3892
3893static const bitmask_transtbl cflag_tbl[] = {
3894 { TARGET_CBAUD0010017, TARGET_B00000000, CBAUD0010017, B00000000 },
3895 { TARGET_CBAUD0010017, TARGET_B500000001, CBAUD0010017, B500000001 },
3896 { TARGET_CBAUD0010017, TARGET_B750000002, CBAUD0010017, B750000002 },
3897 { TARGET_CBAUD0010017, TARGET_B1100000003, CBAUD0010017, B1100000003 },
3898 { TARGET_CBAUD0010017, TARGET_B1340000004, CBAUD0010017, B1340000004 },
3899 { TARGET_CBAUD0010017, TARGET_B1500000005, CBAUD0010017, B1500000005 },
3900 { TARGET_CBAUD0010017, TARGET_B2000000006, CBAUD0010017, B2000000006 },
3901 { TARGET_CBAUD0010017, TARGET_B3000000007, CBAUD0010017, B3000000007 },
3902 { TARGET_CBAUD0010017, TARGET_B6000000010, CBAUD0010017, B6000000010 },
3903 { TARGET_CBAUD0010017, TARGET_B12000000011, CBAUD0010017, B12000000011 },
3904 { TARGET_CBAUD0010017, TARGET_B18000000012, CBAUD0010017, B18000000012 },
3905 { TARGET_CBAUD0010017, TARGET_B24000000013, CBAUD0010017, B24000000013 },
3906 { TARGET_CBAUD0010017, TARGET_B48000000014, CBAUD0010017, B48000000014 },
3907 { TARGET_CBAUD0010017, TARGET_B96000000015, CBAUD0010017, B96000000015 },
3908 { TARGET_CBAUD0010017, TARGET_B192000000016, CBAUD0010017, B192000000016 },
3909 { TARGET_CBAUD0010017, TARGET_B384000000017, CBAUD0010017, B384000000017 },
3910 { TARGET_CBAUD0010017, TARGET_B576000010001, CBAUD0010017, B576000010001 },
3911 { TARGET_CBAUD0010017, TARGET_B1152000010002, CBAUD0010017, B1152000010002 },
3912 { TARGET_CBAUD0010017, TARGET_B2304000010003, CBAUD0010017, B2304000010003 },
3913 { TARGET_CBAUD0010017, TARGET_B4608000010004, CBAUD0010017, B4608000010004 },
3914 { TARGET_CSIZE0000060, TARGET_CS50000000, CSIZE0000060, CS50000000 },
3915 { TARGET_CSIZE0000060, TARGET_CS60000020, CSIZE0000060, CS60000020 },
3916 { TARGET_CSIZE0000060, TARGET_CS70000040, CSIZE0000060, CS70000040 },
3917 { TARGET_CSIZE0000060, TARGET_CS80000060, CSIZE0000060, CS80000060 },
3918 { TARGET_CSTOPB0000100, TARGET_CSTOPB0000100, CSTOPB0000100, CSTOPB0000100 },
3919 { TARGET_CREAD0000200, TARGET_CREAD0000200, CREAD0000200, CREAD0000200 },
3920 { TARGET_PARENB0000400, TARGET_PARENB0000400, PARENB0000400, PARENB0000400 },
3921 { TARGET_PARODD0001000, TARGET_PARODD0001000, PARODD0001000, PARODD0001000 },
3922 { TARGET_HUPCL0002000, TARGET_HUPCL0002000, HUPCL0002000, HUPCL0002000 },
3923 { TARGET_CLOCAL0004000, TARGET_CLOCAL0004000, CLOCAL0004000, CLOCAL0004000 },
3924 { TARGET_CRTSCTS020000000000, TARGET_CRTSCTS020000000000, CRTSCTS020000000000, CRTSCTS020000000000 },
3925 { 0, 0, 0, 0 }
3926};
3927
3928static const bitmask_transtbl lflag_tbl[] = {
3929 { TARGET_ISIG0000001, TARGET_ISIG0000001, ISIG0000001, ISIG0000001 },
3930 { TARGET_ICANON0000002, TARGET_ICANON0000002, ICANON0000002, ICANON0000002 },
3931 { TARGET_XCASE0000004, TARGET_XCASE0000004, XCASE0000004, XCASE0000004 },
3932 { TARGET_ECHO0000010, TARGET_ECHO0000010, ECHO0000010, ECHO0000010 },
3933 { TARGET_ECHOE0000020, TARGET_ECHOE0000020, ECHOE0000020, ECHOE0000020 },
3934 { TARGET_ECHOK0000040, TARGET_ECHOK0000040, ECHOK0000040, ECHOK0000040 },
3935 { TARGET_ECHONL0000100, TARGET_ECHONL0000100, ECHONL0000100, ECHONL0000100 },
3936 { TARGET_NOFLSH0000200, TARGET_NOFLSH0000200, NOFLSH0000200, NOFLSH0000200 },
3937 { TARGET_TOSTOP0000400, TARGET_TOSTOP0000400, TOSTOP0000400, TOSTOP0000400 },
3938 { TARGET_ECHOCTL0001000, TARGET_ECHOCTL0001000, ECHOCTL0001000, ECHOCTL0001000 },
3939 { TARGET_ECHOPRT0002000, TARGET_ECHOPRT0002000, ECHOPRT0002000, ECHOPRT0002000 },
3940 { TARGET_ECHOKE0004000, TARGET_ECHOKE0004000, ECHOKE0004000, ECHOKE0004000 },
3941 { TARGET_FLUSHO0010000, TARGET_FLUSHO0010000, FLUSHO0010000, FLUSHO0010000 },
3942 { TARGET_PENDIN0040000, TARGET_PENDIN0040000, PENDIN0040000, PENDIN0040000 },
3943 { TARGET_IEXTEN0100000, TARGET_IEXTEN0100000, IEXTEN0100000, IEXTEN0100000 },
3944 { 0, 0, 0, 0 }
3945};
3946
3947static void target_to_host_termios (void *dst, const void *src)
3948{
3949 struct host_termios *host = dst;
3950 const struct target_termios *target = src;
3951
3952 host->c_iflag =
3953 target_to_host_bitmask(tswap32(target->c_iflag), iflag_tbl);
3954 host->c_oflag =
3955 target_to_host_bitmask(tswap32(target->c_oflag), oflag_tbl);
3956 host->c_cflag =
3957 target_to_host_bitmask(tswap32(target->c_cflag), cflag_tbl);
3958 host->c_lflag =
3959 target_to_host_bitmask(tswap32(target->c_lflag), lflag_tbl);
3960 host->c_line = target->c_line;
3961
3962 memset(host->c_cc, 0, sizeof(host->c_cc));
3963 host->c_cc[VINTR0] = target->c_cc[TARGET_VINTR0];
3964 host->c_cc[VQUIT1] = target->c_cc[TARGET_VQUIT1];
3965 host->c_cc[VERASE2] = target->c_cc[TARGET_VERASE2];
3966 host->c_cc[VKILL3] = target->c_cc[TARGET_VKILL3];
3967 host->c_cc[VEOF4] = target->c_cc[TARGET_VEOF4];
3968 host->c_cc[VTIME5] = target->c_cc[TARGET_VTIME5];
3969 host->c_cc[VMIN6] = target->c_cc[TARGET_VMIN6];
3970 host->c_cc[VSWTC7] = target->c_cc[TARGET_VSWTC7];
3971 host->c_cc[VSTART8] = target->c_cc[TARGET_VSTART8];
3972 host->c_cc[VSTOP9] = target->c_cc[TARGET_VSTOP9];
3973 host->c_cc[VSUSP10] = target->c_cc[TARGET_VSUSP10];
3974 host->c_cc[VEOL11] = target->c_cc[TARGET_VEOL11];
3975 host->c_cc[VREPRINT12] = target->c_cc[TARGET_VREPRINT12];
3976 host->c_cc[VDISCARD13] = target->c_cc[TARGET_VDISCARD13];
3977 host->c_cc[VWERASE14] = target->c_cc[TARGET_VWERASE14];
3978 host->c_cc[VLNEXT15] = target->c_cc[TARGET_VLNEXT15];
3979 host->c_cc[VEOL216] = target->c_cc[TARGET_VEOL216];
3980}
3981
3982static void host_to_target_termios (void *dst, const void *src)
3983{
3984 struct target_termios *target = dst;
3985 const struct host_termios *host = src;
3986
3987 target->c_iflag =
3988 tswap32(host_to_target_bitmask(host->c_iflag, iflag_tbl));
3989 target->c_oflag =
3990 tswap32(host_to_target_bitmask(host->c_oflag, oflag_tbl));
3991 target->c_cflag =
3992 tswap32(host_to_target_bitmask(host->c_cflag, cflag_tbl));
3993 target->c_lflag =
3994 tswap32(host_to_target_bitmask(host->c_lflag, lflag_tbl));
3995 target->c_line = host->c_line;
3996
3997 memset(target->c_cc, 0, sizeof(target->c_cc));
3998 target->c_cc[TARGET_VINTR0] = host->c_cc[VINTR0];
3999 target->c_cc[TARGET_VQUIT1] = host->c_cc[VQUIT1];
4000 target->c_cc[TARGET_VERASE2] = host->c_cc[VERASE2];
4001 target->c_cc[TARGET_VKILL3] = host->c_cc[VKILL3];
4002 target->c_cc[TARGET_VEOF4] = host->c_cc[VEOF4];
4003 target->c_cc[TARGET_VTIME5] = host->c_cc[VTIME5];
4004 target->c_cc[TARGET_VMIN6] = host->c_cc[VMIN6];
4005 target->c_cc[TARGET_VSWTC7] = host->c_cc[VSWTC7];
4006 target->c_cc[TARGET_VSTART8] = host->c_cc[VSTART8];
4007 target->c_cc[TARGET_VSTOP9] = host->c_cc[VSTOP9];
4008 target->c_cc[TARGET_VSUSP10] = host->c_cc[VSUSP10];
4009 target->c_cc[TARGET_VEOL11] = host->c_cc[VEOL11];
4010 target->c_cc[TARGET_VREPRINT12] = host->c_cc[VREPRINT12];
4011 target->c_cc[TARGET_VDISCARD13] = host->c_cc[VDISCARD13];
4012 target->c_cc[TARGET_VWERASE14] = host->c_cc[VWERASE14];
4013 target->c_cc[TARGET_VLNEXT15] = host->c_cc[VLNEXT15];
4014 target->c_cc[TARGET_VEOL216] = host->c_cc[VEOL216];
4015}
4016
4017static const StructEntry struct_termios_def = {
4018 .convert = { host_to_target_termios, target_to_host_termios },
4019 .size = { sizeof(struct target_termios), sizeof(struct host_termios) },
4020 .align = { __alignof__(struct target_termios), __alignof__(struct host_termios) },
4021};
4022
4023static bitmask_transtbl mmap_flags_tbl[] = {
4024 { TARGET_MAP_SHARED0x01, TARGET_MAP_SHARED0x01, MAP_SHARED0x01, MAP_SHARED0x01 },
4025 { TARGET_MAP_PRIVATE0x02, TARGET_MAP_PRIVATE0x02, MAP_PRIVATE0x02, MAP_PRIVATE0x02 },
4026 { TARGET_MAP_FIXED0x10, TARGET_MAP_FIXED0x10, MAP_FIXED0x10, MAP_FIXED0x10 },
4027 { TARGET_MAP_ANONYMOUS0x20, TARGET_MAP_ANONYMOUS0x20, MAP_ANONYMOUS0x20, MAP_ANONYMOUS0x20 },
4028 { TARGET_MAP_GROWSDOWN0x0100, TARGET_MAP_GROWSDOWN0x0100, MAP_GROWSDOWN0x00100, MAP_GROWSDOWN0x00100 },
4029 { TARGET_MAP_DENYWRITE0x0800, TARGET_MAP_DENYWRITE0x0800, MAP_DENYWRITE0x00800, MAP_DENYWRITE0x00800 },
4030 { TARGET_MAP_EXECUTABLE0x1000, TARGET_MAP_EXECUTABLE0x1000, MAP_EXECUTABLE0x01000, MAP_EXECUTABLE0x01000 },
4031 { TARGET_MAP_LOCKED0x2000, TARGET_MAP_LOCKED0x2000, MAP_LOCKED0x02000, MAP_LOCKED0x02000 },
4032 { 0, 0, 0, 0 }
4033};
4034
4035#if defined(TARGET_I386)
4036
4037/* NOTE: there is really one LDT for all the threads */
4038static uint8_t *ldt_table;
4039
4040static abi_long read_ldt(abi_ulong ptr, unsigned long bytecount)
4041{
4042 int size;
4043 void *p;
4044
4045 if (!ldt_table)
4046 return 0;
4047 size = TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE;
4048 if (size > bytecount)
4049 size = bytecount;
4050 p = lock_user(VERIFY_WRITE1, ptr, size, 0);
4051 if (!p)
4052 return -TARGET_EFAULT14;
4053 /* ??? Should this by byteswapped? */
4054 memcpy(p, ldt_table, size);
4055 unlock_user(p, ptr, size);
4056 return size;
4057}
4058
4059/* XXX: add locking support */
4060static abi_long write_ldt(CPUX86State *env,
4061 abi_ulong ptr, unsigned long bytecount, int oldmode)
4062{
4063 struct target_modify_ldt_ldt_s ldt_info;
4064 struct target_modify_ldt_ldt_s *target_ldt_info;
4065 int seg_32bit, contents, read_exec_only, limit_in_pages;
4066 int seg_not_present, useable, lm;
4067 uint32_t *lp, entry_1, entry_2;
4068
4069 if (bytecount != sizeof(ldt_info))
4070 return -TARGET_EINVAL22;
4071 if (!lock_user_struct(VERIFY_READ, target_ldt_info, ptr, 1)(target_ldt_info = lock_user(0, ptr, sizeof(*target_ldt_info)
, 1))
)
4072 return -TARGET_EFAULT14;
4073 ldt_info.entry_number = tswap32(target_ldt_info->entry_number);
4074 ldt_info.base_addr = tswapal(target_ldt_info->base_addr);
4075 ldt_info.limit = tswap32(target_ldt_info->limit);
4076 ldt_info.flags = tswap32(target_ldt_info->flags);
4077 unlock_user_struct(target_ldt_info, ptr, 0)unlock_user(target_ldt_info, ptr, (0) ? sizeof(*target_ldt_info
) : 0)
;
4078
4079 if (ldt_info.entry_number >= TARGET_LDT_ENTRIES)
4080 return -TARGET_EINVAL22;
4081 seg_32bit = ldt_info.flags & 1;
4082 contents = (ldt_info.flags >> 1) & 3;
4083 read_exec_only = (ldt_info.flags >> 3) & 1;
4084 limit_in_pages = (ldt_info.flags >> 4) & 1;
4085 seg_not_present = (ldt_info.flags >> 5) & 1;
4086 useable = (ldt_info.flags >> 6) & 1;
4087#ifdef TARGET_ABI32
4088 lm = 0;
4089#else
4090 lm = (ldt_info.flags >> 7) & 1;
4091#endif
4092 if (contents == 3) {
4093 if (oldmode)
4094 return -TARGET_EINVAL22;
4095 if (seg_not_present == 0)
4096 return -TARGET_EINVAL22;
4097 }
4098 /* allocate the LDT */
4099 if (!ldt_table) {
4100 env->ldt.base = target_mmap(0,
4101 TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE,
4102 PROT_READ0x1|PROT_WRITE0x2,
4103 MAP_ANONYMOUS0x20|MAP_PRIVATE0x02, -1, 0);
4104 if (env->ldt.base == -1)
4105 return -TARGET_ENOMEM12;
4106 memset(g2h(env->ldt.base)((void *)((unsigned long)(target_ulong)(env->ldt.base) + guest_base
))
, 0,
4107 TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE);
4108 env->ldt.limit = 0xffff;
4109 ldt_table = g2h(env->ldt.base)((void *)((unsigned long)(target_ulong)(env->ldt.base) + guest_base
))
;
4110 }
4111
4112 /* NOTE: same code as Linux kernel */
4113 /* Allow LDTs to be cleared by the user. */
4114 if (ldt_info.base_addr == 0 && ldt_info.limit == 0) {
4115 if (oldmode ||
4116 (contents == 0 &&
4117 read_exec_only == 1 &&
4118 seg_32bit == 0 &&
4119 limit_in_pages == 0 &&
4120 seg_not_present == 1 &&
4121 useable == 0 )) {
4122 entry_1 = 0;
4123 entry_2 = 0;
4124 goto install;
4125 }
4126 }
4127
4128 entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) |
4129 (ldt_info.limit & 0x0ffff);
4130 entry_2 = (ldt_info.base_addr & 0xff000000) |
4131 ((ldt_info.base_addr & 0x00ff0000) >> 16) |
4132 (ldt_info.limit & 0xf0000) |
4133 ((read_exec_only ^ 1) << 9) |
4134 (contents << 10) |
4135 ((seg_not_present ^ 1) << 15) |
4136 (seg_32bit << 22) |
4137 (limit_in_pages << 23) |
4138 (lm << 21) |
4139 0x7000;
4140 if (!oldmode)
4141 entry_2 |= (useable << 20);
4142
4143 /* Install the new entry ... */
4144install:
4145 lp = (uint32_t *)(ldt_table + (ldt_info.entry_number << 3));
4146 lp[0] = tswap32(entry_1);
4147 lp[1] = tswap32(entry_2);
4148 return 0;
4149}
4150
4151/* specific and weird i386 syscalls */
4152static abi_long do_modify_ldt(CPUX86State *env, int func, abi_ulong ptr,
4153 unsigned long bytecount)
4154{
4155 abi_long ret;
4156
4157 switch (func) {
4158 case 0:
4159 ret = read_ldt(ptr, bytecount);
4160 break;
4161 case 1:
4162 ret = write_ldt(env, ptr, bytecount, 1);
4163 break;
4164 case 0x11:
4165 ret = write_ldt(env, ptr, bytecount, 0);
4166 break;
4167 default:
4168 ret = -TARGET_ENOSYS38;
4169 break;
4170 }
4171 return ret;
4172}
4173
4174#if defined(TARGET_I386) && defined(TARGET_ABI32)
4175abi_long do_set_thread_area(CPUX86State *env, abi_ulong ptr)
4176{
4177 uint64_t *gdt_table = g2h(env->gdt.base)((void *)((unsigned long)(target_ulong)(env->gdt.base) + guest_base
))
;
4178 struct target_modify_ldt_ldt_s ldt_info;
4179 struct target_modify_ldt_ldt_s *target_ldt_info;
4180 int seg_32bit, contents, read_exec_only, limit_in_pages;
4181 int seg_not_present, useable, lm;
4182 uint32_t *lp, entry_1, entry_2;
4183 int i;
4184
4185 lock_user_struct(VERIFY_WRITE, target_ldt_info, ptr, 1)(target_ldt_info = lock_user(1, ptr, sizeof(*target_ldt_info)
, 1))
;
4186 if (!target_ldt_info)
4187 return -TARGET_EFAULT14;
4188 ldt_info.entry_number = tswap32(target_ldt_info->entry_number);
4189 ldt_info.base_addr = tswapal(target_ldt_info->base_addr);
4190 ldt_info.limit = tswap32(target_ldt_info->limit);
4191 ldt_info.flags = tswap32(target_ldt_info->flags);
4192 if (ldt_info.entry_number == -1) {
4193 for (i=TARGET_GDT_ENTRY_TLS_MIN; i<=TARGET_GDT_ENTRY_TLS_MAX; i++) {
4194 if (gdt_table[i] == 0) {
4195 ldt_info.entry_number = i;
4196 target_ldt_info->entry_number = tswap32(i);
4197 break;
4198 }
4199 }
4200 }
4201 unlock_user_struct(target_ldt_info, ptr, 1)unlock_user(target_ldt_info, ptr, (1) ? sizeof(*target_ldt_info
) : 0)
;
4202
4203 if (ldt_info.entry_number < TARGET_GDT_ENTRY_TLS_MIN ||
4204 ldt_info.entry_number > TARGET_GDT_ENTRY_TLS_MAX)
4205 return -TARGET_EINVAL22;
4206 seg_32bit = ldt_info.flags & 1;
4207 contents = (ldt_info.flags >> 1) & 3;
4208 read_exec_only = (ldt_info.flags >> 3) & 1;
4209 limit_in_pages = (ldt_info.flags >> 4) & 1;
4210 seg_not_present = (ldt_info.flags >> 5) & 1;
4211 useable = (ldt_info.flags >> 6) & 1;
4212#ifdef TARGET_ABI32
4213 lm = 0;
4214#else
4215 lm = (ldt_info.flags >> 7) & 1;
4216#endif
4217
4218 if (contents == 3) {
4219 if (seg_not_present == 0)
4220 return -TARGET_EINVAL22;
4221 }
4222
4223 /* NOTE: same code as Linux kernel */
4224 /* Allow LDTs to be cleared by the user. */
4225 if (ldt_info.base_addr == 0 && ldt_info.limit == 0) {
4226 if ((contents == 0 &&
4227 read_exec_only == 1 &&
4228 seg_32bit == 0 &&
4229 limit_in_pages == 0 &&
4230 seg_not_present == 1 &&
4231 useable == 0 )) {
4232 entry_1 = 0;
4233 entry_2 = 0;
4234 goto install;
4235 }
4236 }
4237
4238 entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) |
4239 (ldt_info.limit & 0x0ffff);
4240 entry_2 = (ldt_info.base_addr & 0xff000000) |
4241 ((ldt_info.base_addr & 0x00ff0000) >> 16) |
4242 (ldt_info.limit & 0xf0000) |
4243 ((read_exec_only ^ 1) << 9) |
4244 (contents << 10) |
4245 ((seg_not_present ^ 1) << 15) |
4246 (seg_32bit << 22) |
4247 (limit_in_pages << 23) |
4248 (useable << 20) |
4249 (lm << 21) |
4250 0x7000;
4251
4252 /* Install the new entry ... */
4253install:
4254 lp = (uint32_t *)(gdt_table + ldt_info.entry_number);
4255 lp[0] = tswap32(entry_1);
4256 lp[1] = tswap32(entry_2);
4257 return 0;
4258}
4259
4260static abi_long do_get_thread_area(CPUX86State *env, abi_ulong ptr)
4261{
4262 struct target_modify_ldt_ldt_s *target_ldt_info;
4263 uint64_t *gdt_table = g2h(env->gdt.base)((void *)((unsigned long)(target_ulong)(env->gdt.base) + guest_base
))
;
4264 uint32_t base_addr, limit, flags;
4265 int seg_32bit, contents, read_exec_only, limit_in_pages, idx;
4266 int seg_not_present, useable, lm;
4267 uint32_t *lp, entry_1, entry_2;
4268
4269 lock_user_struct(VERIFY_WRITE, target_ldt_info, ptr, 1)(target_ldt_info = lock_user(1, ptr, sizeof(*target_ldt_info)
, 1))
;
4270 if (!target_ldt_info)
4271 return -TARGET_EFAULT14;
4272 idx = tswap32(target_ldt_info->entry_number);
4273 if (idx < TARGET_GDT_ENTRY_TLS_MIN ||
4274 idx > TARGET_GDT_ENTRY_TLS_MAX) {
4275 unlock_user_struct(target_ldt_info, ptr, 1)unlock_user(target_ldt_info, ptr, (1) ? sizeof(*target_ldt_info
) : 0)
;
4276 return -TARGET_EINVAL22;
4277 }
4278 lp = (uint32_t *)(gdt_table + idx);
4279 entry_1 = tswap32(lp[0]);
4280 entry_2 = tswap32(lp[1]);
4281
4282 read_exec_only = ((entry_2 >> 9) & 1) ^ 1;
4283 contents = (entry_2 >> 10) & 3;
4284 seg_not_present = ((entry_2 >> 15) & 1) ^ 1;
4285 seg_32bit = (entry_2 >> 22) & 1;
4286 limit_in_pages = (entry_2 >> 23) & 1;
4287 useable = (entry_2 >> 20) & 1;
4288#ifdef TARGET_ABI32
4289 lm = 0;
4290#else
4291 lm = (entry_2 >> 21) & 1;
4292#endif
4293 flags = (seg_32bit << 0) | (contents << 1) |
4294 (read_exec_only << 3) | (limit_in_pages << 4) |
4295 (seg_not_present << 5) | (useable << 6) | (lm << 7);
4296 limit = (entry_1 & 0xffff) | (entry_2 & 0xf0000);
4297 base_addr = (entry_1 >> 16) |
4298 (entry_2 & 0xff000000) |
4299 ((entry_2 & 0xff) << 16);
4300 target_ldt_info->base_addr = tswapal(base_addr);
4301 target_ldt_info->limit = tswap32(limit);
4302 target_ldt_info->flags = tswap32(flags);
4303 unlock_user_struct(target_ldt_info, ptr, 1)unlock_user(target_ldt_info, ptr, (1) ? sizeof(*target_ldt_info
) : 0)
;
4304 return 0;
4305}
4306#endif /* TARGET_I386 && TARGET_ABI32 */
4307
4308#ifndef TARGET_ABI32
4309abi_long do_arch_prctl(CPUX86State *env, int code, abi_ulong addr)
4310{
4311 abi_long ret = 0;
4312 abi_ulong val;
4313 int idx;
4314
4315 switch(code) {
4316 case TARGET_ARCH_SET_GS:
4317 case TARGET_ARCH_SET_FS:
4318 if (code == TARGET_ARCH_SET_GS)
4319 idx = R_GS;
4320 else
4321 idx = R_FS;
4322 cpu_x86_load_seg(env, idx, 0);
4323 env->segs[idx].base = addr;
4324 break;
4325 case TARGET_ARCH_GET_GS:
4326 case TARGET_ARCH_GET_FS:
4327 if (code == TARGET_ARCH_GET_GS)
4328 idx = R_GS;
4329 else
4330 idx = R_FS;
4331 val = env->segs[idx].base;
4332 if (put_user(val, addr, abi_ulong)({ abi_ulong __gaddr = (addr); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(1, __gaddr, sizeof(abi_ulong), 0)))
{ __ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1, stb_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), ((val))), 0)
; unlock_user(__hptr, __gaddr, sizeof(abi_ulong)); } else __ret
= -14; __ret; })
)
4333 ret = -TARGET_EFAULT14;
4334 break;
4335 default:
4336 ret = -TARGET_EINVAL22;
4337 break;
4338 }
4339 return ret;
4340}
4341#endif
4342
4343#endif /* defined(TARGET_I386) */
4344
4345#define NEW_STACK_SIZE0x40000 0x40000
4346
4347
4348static pthread_mutex_t clone_lock = PTHREAD_MUTEX_INITIALIZER{ { 0, 0, 0, 0, 0, 0, { 0, 0 } } };
4349typedef struct {
4350 CPUArchStatestruct CPUS390XState *env;
4351 pthread_mutex_t mutex;
4352 pthread_cond_t cond;
4353 pthread_t thread;
4354 uint32_t tid;
4355 abi_ulong child_tidptr;
4356 abi_ulong parent_tidptr;
4357 sigset_t sigmask;
4358} new_thread_info;
4359
4360static void *clone_func(void *arg)
4361{
4362 new_thread_info *info = arg;
4363 CPUArchStatestruct CPUS390XState *env;
4364 CPUState *cpu;
4365 TaskState *ts;
4366
4367 env = info->env;
4368 cpu = ENV_GET_CPU(env)((CPUState *)object_dynamic_cast_assert(((Object *)((s390_env_get_cpu
(env)))), ("cpu"), "/home/stefan/src/qemu/qemu.org/qemu/linux-user/syscall.c"
, 4368, __func__))
;
4369 thread_cpu = cpu;
4370 ts = (TaskState *)env->opaque;
4371 info->tid = gettid();
4372 cpu->host_tid = info->tid;
4373 task_settid(ts);
4374 if (info->child_tidptr)
4375 put_user_u32(info->tid, info->child_tidptr)({ abi_ulong __gaddr = ((info->child_tidptr)); uint32_t *__hptr
; abi_long __ret; if ((__hptr = lock_user(1, __gaddr, sizeof(
uint32_t), 0))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(__hptr)) == 2,
stw_be_p, __builtin_choose_expr(sizeof(*(__hptr)) == 4, stl_be_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 8, stq_be_p, abort
)))) ((__hptr), (((info->tid)))), 0); unlock_user(__hptr, __gaddr
, sizeof(uint32_t)); } else __ret = -14; __ret; })
;
4376 if (info->parent_tidptr)
4377 put_user_u32(info->tid, info->parent_tidptr)({ abi_ulong __gaddr = ((info->parent_tidptr)); uint32_t *
__hptr; abi_long __ret; if ((__hptr = lock_user(1, __gaddr, sizeof
(uint32_t), 0))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(__hptr)) == 2,
stw_be_p, __builtin_choose_expr(sizeof(*(__hptr)) == 4, stl_be_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 8, stq_be_p, abort
)))) ((__hptr), (((info->tid)))), 0); unlock_user(__hptr, __gaddr
, sizeof(uint32_t)); } else __ret = -14; __ret; })
;
4378 /* Enable signals. */
4379 sigprocmask(SIG_SETMASK2, &info->sigmask, NULL((void*)0));
4380 /* Signal to the parent that we're ready. */
4381 pthread_mutex_lock(&info->mutex);
4382 pthread_cond_broadcast(&info->cond);
4383 pthread_mutex_unlock(&info->mutex);
4384 /* Wait until the parent has finshed initializing the tls state. */
4385 pthread_mutex_lock(&clone_lock);
4386 pthread_mutex_unlock(&clone_lock);
4387 cpu_loop(env);
4388 /* never exits */
4389 return NULL((void*)0);
4390}
4391
4392/* do_fork() Must return host values and target errnos (unlike most
4393 do_*() functions). */
4394static int do_fork(CPUArchStatestruct CPUS390XState *env, unsigned int flags, abi_ulong newsp,
4395 abi_ulong parent_tidptr, target_ulong newtls,
4396 abi_ulong child_tidptr)
4397{
4398 int ret;
4399 TaskState *ts;
4400 CPUArchStatestruct CPUS390XState *new_env;
4401 unsigned int nptl_flags;
4402 sigset_t sigmask;
4403
4404 /* Emulate vfork() with fork() */
4405 if (flags & CLONE_VFORK0x00004000)
4406 flags &= ~(CLONE_VFORK0x00004000 | CLONE_VM0x00000100);
4407
4408 if (flags & CLONE_VM0x00000100) {
4409 TaskState *parent_ts = (TaskState *)env->opaque;
4410 new_thread_info info;
4411 pthread_attr_t attr;
4412
4413 ts = g_malloc0(sizeof(TaskState));
4414 init_task_state(ts);
4415 /* we create a new CPU instance. */
4416 new_env = cpu_copy(env);
4417 /* Init regs that differ from the parent. */
4418 cpu_clone_regs(new_env, newsp);
4419 new_env->opaque = ts;
4420 ts->bprm = parent_ts->bprm;
4421 ts->info = parent_ts->info;
4422 nptl_flags = flags;
4423 flags &= ~CLONE_NPTL_FLAGS2(0x00080000 | 0x00100000 | 0x01000000 | 0x00200000);
4424
4425 if (nptl_flags & CLONE_CHILD_CLEARTID0x00200000) {
4426 ts->child_tidptr = child_tidptr;
4427 }
4428
4429 if (nptl_flags & CLONE_SETTLS0x00080000)
4430 cpu_set_tls (new_env, newtls);
4431
4432 /* Grab a mutex so that thread setup appears atomic. */
4433 pthread_mutex_lock(&clone_lock);
4434
4435 memset(&info, 0, sizeof(info));
4436 pthread_mutex_init(&info.mutex, NULL((void*)0));
4437 pthread_mutex_lock(&info.mutex);
4438 pthread_cond_init(&info.cond, NULL((void*)0));
4439 info.env = new_env;
4440 if (nptl_flags & CLONE_CHILD_SETTID0x01000000)
4441 info.child_tidptr = child_tidptr;
4442 if (nptl_flags & CLONE_PARENT_SETTID0x00100000)
4443 info.parent_tidptr = parent_tidptr;
4444
4445 ret = pthread_attr_init(&attr);
Value stored to 'ret' is never read
4446 ret = pthread_attr_setstacksize(&attr, NEW_STACK_SIZE0x40000);
4447 ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHEDPTHREAD_CREATE_DETACHED);
4448 /* It is not safe to deliver signals until the child has finished
4449 initializing, so temporarily block all signals. */
4450 sigfillset(&sigmask);
4451 sigprocmask(SIG_BLOCK0, &sigmask, &info.sigmask);
4452
4453 ret = pthread_create(&info.thread, &attr, clone_func, &info);
4454 /* TODO: Free new CPU state if thread creation failed. */
4455
4456 sigprocmask(SIG_SETMASK2, &info.sigmask, NULL((void*)0));
4457 pthread_attr_destroy(&attr);
4458 if (ret == 0) {
4459 /* Wait for the child to initialize. */
4460 pthread_cond_wait(&info.cond, &info.mutex);
4461 ret = info.tid;
4462 if (flags & CLONE_PARENT_SETTID0x00100000)
4463 put_user_u32(ret, parent_tidptr)({ abi_ulong __gaddr = ((parent_tidptr)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(1, __gaddr, sizeof(uint32_t),
0))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1
, stb_p, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), (((ret
)))), 0); unlock_user(__hptr, __gaddr, sizeof(uint32_t)); } else
__ret = -14; __ret; })
;
4464 } else {
4465 ret = -1;
4466 }
4467 pthread_mutex_unlock(&info.mutex);
4468 pthread_cond_destroy(&info.cond);
4469 pthread_mutex_destroy(&info.mutex);
4470 pthread_mutex_unlock(&clone_lock);
4471 } else {
4472 /* if no CLONE_VM, we consider it is a fork */
4473 if ((flags & ~(CSIGNAL0x000000ff | CLONE_NPTL_FLAGS2(0x00080000 | 0x00100000 | 0x01000000 | 0x00200000))) != 0)
4474 return -EINVAL22;
4475 fork_start();
4476 ret = fork();
4477 if (ret == 0) {
4478 /* Child Process. */
4479 cpu_clone_regs(env, newsp);
4480 fork_end(1);
4481 /* There is a race condition here. The parent process could
4482 theoretically read the TID in the child process before the child
4483 tid is set. This would require using either ptrace
4484 (not implemented) or having *_tidptr to point at a shared memory
4485 mapping. We can't repeat the spinlock hack used above because
4486 the child process gets its own copy of the lock. */
4487 if (flags & CLONE_CHILD_SETTID0x01000000)
4488 put_user_u32(gettid(), child_tidptr)({ abi_ulong __gaddr = ((child_tidptr)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(1, __gaddr, sizeof(uint32_t),
0))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1
, stb_p, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), (((gettid
())))), 0); unlock_user(__hptr, __gaddr, sizeof(uint32_t)); }
else __ret = -14; __ret; })
;
4489 if (flags & CLONE_PARENT_SETTID0x00100000)
4490 put_user_u32(gettid(), parent_tidptr)({ abi_ulong __gaddr = ((parent_tidptr)); uint32_t *__hptr; abi_long
__ret; if ((__hptr = lock_user(1, __gaddr, sizeof(uint32_t),
0))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1
, stb_p, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), (((gettid
())))), 0); unlock_user(__hptr, __gaddr, sizeof(uint32_t)); }
else __ret = -14; __ret; })
;
4491 ts = (TaskState *)env->opaque;
4492 if (flags & CLONE_SETTLS0x00080000)
4493 cpu_set_tls (env, newtls);
4494 if (flags & CLONE_CHILD_CLEARTID0x00200000)
4495 ts->child_tidptr = child_tidptr;
4496 } else {
4497 fork_end(0);
4498 }
4499 }
4500 return ret;
4501}
4502
4503/* warning : doesn't handle linux specific flags... */
4504static int target_to_host_fcntl_cmd(int cmd)
4505{
4506 switch(cmd) {
4507 case TARGET_F_DUPFD0:
4508 case TARGET_F_GETFD1:
4509 case TARGET_F_SETFD2:
4510 case TARGET_F_GETFL3:
4511 case TARGET_F_SETFL4:
4512 return cmd;
4513 case TARGET_F_GETLK5:
4514 return F_GETLK5;
4515 case TARGET_F_SETLK6:
4516 return F_SETLK6;
4517 case TARGET_F_SETLKW7:
4518 return F_SETLKW7;
4519 case TARGET_F_GETOWN9:
4520 return F_GETOWN9;
4521 case TARGET_F_SETOWN8:
4522 return F_SETOWN8;
4523 case TARGET_F_GETSIG11:
4524 return F_GETSIG11;
4525 case TARGET_F_SETSIG10:
4526 return F_SETSIG10;
4527#if TARGET_ABI_BITS64 == 32
4528 case TARGET_F_GETLK6412:
4529 return F_GETLK645;
4530 case TARGET_F_SETLK6413:
4531 return F_SETLK646;
4532 case TARGET_F_SETLKW6414:
4533 return F_SETLKW647;
4534#endif
4535 case TARGET_F_SETLEASE(1024 + 0):
4536 return F_SETLEASE1024;
4537 case TARGET_F_GETLEASE(1024 + 1):
4538 return F_GETLEASE1025;
4539#ifdef F_DUPFD_CLOEXEC1030
4540 case TARGET_F_DUPFD_CLOEXEC(1024 + 6):
4541 return F_DUPFD_CLOEXEC1030;
4542#endif
4543 case TARGET_F_NOTIFY(1024 +2):
4544 return F_NOTIFY1026;
4545 default:
4546 return -TARGET_EINVAL22;
4547 }
4548 return -TARGET_EINVAL22;
4549}
4550
4551#define TRANSTBL_CONVERT(a){ -1, TARGET_a, -1, a } { -1, TARGET_##a, -1, a }
4552static const bitmask_transtbl flock_tbl[] = {
4553 TRANSTBL_CONVERT(F_RDLCK){ -1, 0, -1, 0 },
4554 TRANSTBL_CONVERT(F_WRLCK){ -1, 1, -1, 1 },
4555 TRANSTBL_CONVERT(F_UNLCK){ -1, 2, -1, 2 },
4556 TRANSTBL_CONVERT(F_EXLCK){ -1, 4, -1, 4 },
4557 TRANSTBL_CONVERT(F_SHLCK){ -1, 8, -1, 8 },
4558 { 0, 0, 0, 0 }
4559};
4560
4561static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
4562{
4563 struct flock fl;
4564 struct target_flock *target_fl;
4565 struct flock64 fl64;
4566 struct target_flock64 *target_fl64;
4567 abi_long ret;
4568 int host_cmd = target_to_host_fcntl_cmd(cmd);
4569
4570 if (host_cmd == -TARGET_EINVAL22)
4571 return host_cmd;
4572
4573 switch(cmd) {
4574 case TARGET_F_GETLK5:
4575 if (!lock_user_struct(VERIFY_READ, target_fl, arg, 1)(target_fl = lock_user(0, arg, sizeof(*target_fl), 1)))
4576 return -TARGET_EFAULT14;
4577 fl.l_type =
4578 target_to_host_bitmask(tswap16(target_fl->l_type), flock_tbl);
4579 fl.l_whence = tswap16(target_fl->l_whence);
4580 fl.l_start = tswapal(target_fl->l_start);
4581 fl.l_len = tswapal(target_fl->l_len);
4582 fl.l_pid = tswap32(target_fl->l_pid);
4583 unlock_user_struct(target_fl, arg, 0)unlock_user(target_fl, arg, (0) ? sizeof(*target_fl) : 0);
4584 ret = get_errno(fcntl(fd, host_cmd, &fl));
4585 if (ret == 0) {
4586 if (!lock_user_struct(VERIFY_WRITE, target_fl, arg, 0)(target_fl = lock_user(1, arg, sizeof(*target_fl), 0)))
4587 return -TARGET_EFAULT14;
4588 target_fl->l_type =
4589 host_to_target_bitmask(tswap16(fl.l_type), flock_tbl);
4590 target_fl->l_whence = tswap16(fl.l_whence);
4591 target_fl->l_start = tswapal(fl.l_start);
4592 target_fl->l_len = tswapal(fl.l_len);
4593 target_fl->l_pid = tswap32(fl.l_pid);
4594 unlock_user_struct(target_fl, arg, 1)unlock_user(target_fl, arg, (1) ? sizeof(*target_fl) : 0);
4595 }
4596 break;
4597
4598 case TARGET_F_SETLK6:
4599 case TARGET_F_SETLKW7:
4600 if (!lock_user_struct(VERIFY_READ, target_fl, arg, 1)(target_fl = lock_user(0, arg, sizeof(*target_fl), 1)))
4601 return -TARGET_EFAULT14;
4602 fl.l_type =
4603 target_to_host_bitmask(tswap16(target_fl->l_type), flock_tbl);
4604 fl.l_whence = tswap16(target_fl->l_whence);
4605 fl.l_start = tswapal(target_fl->l_start);
4606 fl.l_len = tswapal(target_fl->l_len);
4607 fl.l_pid = tswap32(target_fl->l_pid);
4608 unlock_user_struct(target_fl, arg, 0)unlock_user(target_fl, arg, (0) ? sizeof(*target_fl) : 0);
4609 ret = get_errno(fcntl(fd, host_cmd, &fl));
4610 break;
4611
4612 case TARGET_F_GETLK6412:
4613 if (!lock_user_struct(VERIFY_READ, target_fl64, arg, 1)(target_fl64 = lock_user(0, arg, sizeof(*target_fl64), 1)))
4614 return -TARGET_EFAULT14;
4615 fl64.l_type =
4616 target_to_host_bitmask(tswap16(target_fl64->l_type), flock_tbl) >> 1;
4617 fl64.l_whence = tswap16(target_fl64->l_whence);
4618 fl64.l_start = tswap64(target_fl64->l_start);
4619 fl64.l_len = tswap64(target_fl64->l_len);
4620 fl64.l_pid = tswap32(target_fl64->l_pid);
4621 unlock_user_struct(target_fl64, arg, 0)unlock_user(target_fl64, arg, (0) ? sizeof(*target_fl64) : 0);
4622 ret = get_errno(fcntl(fd, host_cmd, &fl64));
4623 if (ret == 0) {
4624 if (!lock_user_struct(VERIFY_WRITE, target_fl64, arg, 0)(target_fl64 = lock_user(1, arg, sizeof(*target_fl64), 0)))
4625 return -TARGET_EFAULT14;
4626 target_fl64->l_type =
4627 host_to_target_bitmask(tswap16(fl64.l_type), flock_tbl) >> 1;
4628 target_fl64->l_whence = tswap16(fl64.l_whence);
4629 target_fl64->l_start = tswap64(fl64.l_start);
4630 target_fl64->l_len = tswap64(fl64.l_len);
4631 target_fl64->l_pid = tswap32(fl64.l_pid);
4632 unlock_user_struct(target_fl64, arg, 1)unlock_user(target_fl64, arg, (1) ? sizeof(*target_fl64) : 0);
4633 }
4634 break;
4635 case TARGET_F_SETLK6413:
4636 case TARGET_F_SETLKW6414:
4637 if (!lock_user_struct(VERIFY_READ, target_fl64, arg, 1)(target_fl64 = lock_user(0, arg, sizeof(*target_fl64), 1)))
4638 return -TARGET_EFAULT14;
4639 fl64.l_type =
4640 target_to_host_bitmask(tswap16(target_fl64->l_type), flock_tbl) >> 1;
4641 fl64.l_whence = tswap16(target_fl64->l_whence);
4642 fl64.l_start = tswap64(target_fl64->l_start);
4643 fl64.l_len = tswap64(target_fl64->l_len);
4644 fl64.l_pid = tswap32(target_fl64->l_pid);
4645 unlock_user_struct(target_fl64, arg, 0)unlock_user(target_fl64, arg, (0) ? sizeof(*target_fl64) : 0);
4646 ret = get_errno(fcntl(fd, host_cmd, &fl64));
4647 break;
4648
4649 case TARGET_F_GETFL3:
4650 ret = get_errno(fcntl(fd, host_cmd, arg));
4651 if (ret >= 0) {
4652 ret = host_to_target_bitmask(ret, fcntl_flags_tbl);
4653 }
4654 break;
4655
4656 case TARGET_F_SETFL4:
4657 ret = get_errno(fcntl(fd, host_cmd, target_to_host_bitmask(arg, fcntl_flags_tbl)));
4658 break;
4659
4660 case TARGET_F_SETOWN8:
4661 case TARGET_F_GETOWN9:
4662 case TARGET_F_SETSIG10:
4663 case TARGET_F_GETSIG11:
4664 case TARGET_F_SETLEASE(1024 + 0):
4665 case TARGET_F_GETLEASE(1024 + 1):
4666 ret = get_errno(fcntl(fd, host_cmd, arg));
4667 break;
4668
4669 default:
4670 ret = get_errno(fcntl(fd, cmd, arg));
4671 break;
4672 }
4673 return ret;
4674}
4675
4676#ifdef USE_UID16
4677
4678static inline int high2lowuid(int uid)
4679{
4680 if (uid > 65535)
4681 return 65534;
4682 else
4683 return uid;
4684}
4685
4686static inline int high2lowgid(int gid)
4687{
4688 if (gid > 65535)
4689 return 65534;
4690 else
4691 return gid;
4692}
4693
4694static inline int low2highuid(int uid)
4695{
4696 if ((int16_t)uid == -1)
4697 return -1;
4698 else
4699 return uid;
4700}
4701
4702static inline int low2highgid(int gid)
4703{
4704 if ((int16_t)gid == -1)
4705 return -1;
4706 else
4707 return gid;
4708}
4709static inline int tswapid(int id)
4710{
4711 return tswap16(id);
4712}
4713#else /* !USE_UID16 */
4714static inline int high2lowuid(int uid)
4715{
4716 return uid;
4717}
4718static inline int high2lowgid(int gid)
4719{
4720 return gid;
4721}
4722static inline int low2highuid(int uid)
4723{
4724 return uid;
4725}
4726static inline int low2highgid(int gid)
4727{
4728 return gid;
4729}
4730static inline int tswapid(int id)
4731{
4732 return tswap32(id);
4733}
4734#endif /* USE_UID16 */
4735
4736void syscall_init(void)
4737{
4738 IOCTLEntry *ie;
4739 const argtype *arg_type;
4740 int size;
4741 int i;
4742
4743#define STRUCT(name, ...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def);
4744#define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def);
4745#include "syscall_types.h"
4746#undef STRUCT
4747#undef STRUCT_SPECIAL
4748
4749 /* Build target_to_host_errno_table[] table from
4750 * host_to_target_errno_table[]. */
4751 for (i = 0; i < ERRNO_TABLE_SIZE1200; i++) {
4752 target_to_host_errno_table[host_to_target_errno_table[i]] = i;
4753 }
4754
4755 /* we patch the ioctl size if necessary. We rely on the fact that
4756 no ioctl has all the bits at '1' in the size field */
4757 ie = ioctl_entries;
4758 while (ie->target_cmd != 0) {
4759 if (((ie->target_cmd >> TARGET_IOC_SIZESHIFT((0 +8)+8)) & TARGET_IOC_SIZEMASK((1 << 14)-1)) ==
4760 TARGET_IOC_SIZEMASK((1 << 14)-1)) {
4761 arg_type = ie->arg_type;
4762 if (arg_type[0] != TYPE_PTR) {
4763 fprintf(stderrstderr, "cannot patch size for ioctl 0x%x\n",
4764 ie->target_cmd);
4765 exit(1);
4766 }
4767 arg_type++;
4768 size = thunk_type_size(arg_type, 0);
4769 ie->target_cmd = (ie->target_cmd &
4770 ~(TARGET_IOC_SIZEMASK((1 << 14)-1) << TARGET_IOC_SIZESHIFT((0 +8)+8))) |
4771 (size << TARGET_IOC_SIZESHIFT((0 +8)+8));
4772 }
4773
4774 /* automatic consistency check if same arch */
4775#if (defined(__i386__) && defined(TARGET_I386) && defined(TARGET_ABI32)) || \
4776 (defined(__x86_64__1) && defined(TARGET_X86_64))
4777 if (unlikely(ie->target_cmd != ie->host_cmd)__builtin_expect(!!(ie->target_cmd != ie->host_cmd), 0)) {
4778 fprintf(stderrstderr, "ERROR: ioctl(%s): target=0x%x host=0x%x\n",
4779 ie->name, ie->target_cmd, ie->host_cmd);
4780 }
4781#endif
4782 ie++;
4783 }
4784}
4785
4786#if TARGET_ABI_BITS64 == 32
4787static inline uint64_t target_offset64(uint32_t word0, uint32_t word1)
4788{
4789#ifdef TARGET_WORDS_BIGENDIAN1
4790 return ((uint64_t)word0 << 32) | word1;
4791#else
4792 return ((uint64_t)word1 << 32) | word0;
4793#endif
4794}
4795#else /* TARGET_ABI_BITS == 32 */
4796static inline uint64_t target_offset64(uint64_t word0, uint64_t word1)
4797{
4798 return word0;
4799}
4800#endif /* TARGET_ABI_BITS != 32 */
4801
4802#ifdef TARGET_NR_truncate64
4803static inline abi_long target_truncate64(void *cpu_env, const char *arg1,
4804 abi_long arg2,
4805 abi_long arg3,
4806 abi_long arg4)
4807{
4808 if (regpairs_aligned(cpu_env)) {
4809 arg2 = arg3;
4810 arg3 = arg4;
4811 }
4812 return get_errno(truncate64(arg1, target_offset64(arg2, arg3)));
4813}
4814#endif
4815
4816#ifdef TARGET_NR_ftruncate64
4817static inline abi_long target_ftruncate64(void *cpu_env, abi_long arg1,
4818 abi_long arg2,
4819 abi_long arg3,
4820 abi_long arg4)
4821{
4822 if (regpairs_aligned(cpu_env)) {
4823 arg2 = arg3;
4824 arg3 = arg4;
4825 }
4826 return get_errno(ftruncate64(arg1, target_offset64(arg2, arg3)));
4827}
4828#endif
4829
4830static inline abi_long target_to_host_timespec(struct timespec *host_ts,
4831 abi_ulong target_addr)
4832{
4833 struct target_timespec *target_ts;
4834
4835 if (!lock_user_struct(VERIFY_READ, target_ts, target_addr, 1)(target_ts = lock_user(0, target_addr, sizeof(*target_ts), 1)
)
)
4836 return -TARGET_EFAULT14;
4837 host_ts->tv_sec = tswapal(target_ts->tv_sec);
4838 host_ts->tv_nsec = tswapal(target_ts->tv_nsec);
4839 unlock_user_struct(target_ts, target_addr, 0)unlock_user(target_ts, target_addr, (0) ? sizeof(*target_ts) :
0)
;
4840 return 0;
4841}
4842
4843static inline abi_long host_to_target_timespec(abi_ulong target_addr,
4844 struct timespec *host_ts)
4845{
4846 struct target_timespec *target_ts;
4847
4848 if (!lock_user_struct(VERIFY_WRITE, target_ts, target_addr, 0)(target_ts = lock_user(1, target_addr, sizeof(*target_ts), 0)
)
)
4849 return -TARGET_EFAULT14;
4850 target_ts->tv_sec = tswapal(host_ts->tv_sec);
4851 target_ts->tv_nsec = tswapal(host_ts->tv_nsec);
4852 unlock_user_struct(target_ts, target_addr, 1)unlock_user(target_ts, target_addr, (1) ? sizeof(*target_ts) :
0)
;
4853 return 0;
4854}
4855
4856static inline abi_long target_to_host_itimerspec(struct itimerspec *host_itspec,
4857 abi_ulong target_addr)
4858{
4859 struct target_itimerspec *target_itspec;
4860
4861 if (!lock_user_struct(VERIFY_READ, target_itspec, target_addr, 1)(target_itspec = lock_user(0, target_addr, sizeof(*target_itspec
), 1))
) {
4862 return -TARGET_EFAULT14;
4863 }
4864
4865 host_itspec->it_interval.tv_sec =
4866 tswapal(target_itspec->it_interval.tv_sec);
4867 host_itspec->it_interval.tv_nsec =
4868 tswapal(target_itspec->it_interval.tv_nsec);
4869 host_itspec->it_value.tv_sec = tswapal(target_itspec->it_value.tv_sec);
4870 host_itspec->it_value.tv_nsec = tswapal(target_itspec->it_value.tv_nsec);
4871
4872 unlock_user_struct(target_itspec, target_addr, 1)unlock_user(target_itspec, target_addr, (1) ? sizeof(*target_itspec
) : 0)
;
4873 return 0;
4874}
4875
4876static inline abi_long host_to_target_itimerspec(abi_ulong target_addr,
4877 struct itimerspec *host_its)
4878{
4879 struct target_itimerspec *target_itspec;
4880
4881 if (!lock_user_struct(VERIFY_WRITE, target_itspec, target_addr, 0)(target_itspec = lock_user(1, target_addr, sizeof(*target_itspec
), 0))
) {
4882 return -TARGET_EFAULT14;
4883 }
4884
4885 target_itspec->it_interval.tv_sec = tswapal(host_its->it_interval.tv_sec);
4886 target_itspec->it_interval.tv_nsec = tswapal(host_its->it_interval.tv_nsec);
4887
4888 target_itspec->it_value.tv_sec = tswapal(host_its->it_value.tv_sec);
4889 target_itspec->it_value.tv_nsec = tswapal(host_its->it_value.tv_nsec);
4890
4891 unlock_user_struct(target_itspec, target_addr, 0)unlock_user(target_itspec, target_addr, (0) ? sizeof(*target_itspec
) : 0)
;
4892 return 0;
4893}
4894
4895#if defined(TARGET_NR_stat64) || defined(TARGET_NR_newfstatat293)
4896static inline abi_long host_to_target_stat64(void *cpu_env,
4897 abi_ulong target_addr,
4898 struct stat *host_st)
4899{
4900#if defined(TARGET_ARM) && defined(TARGET_ABI32)
4901 if (((CPUARMState *)cpu_env)->eabi) {
4902 struct target_eabi_stat64 *target_st;
4903
4904 if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)(target_st = lock_user(1, target_addr, sizeof(*target_st), 0)
)
)
4905 return -TARGET_EFAULT14;
4906 memset(target_st, 0, sizeof(struct target_eabi_stat64));
4907 __put_user(host_st->st_dev, &target_st->st_dev)(__builtin_choose_expr(sizeof(*(&target_st->st_dev)) ==
1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_dev)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_dev)) == 4, stl_be_p, __builtin_choose_expr(
sizeof(*(&target_st->st_dev)) == 8, stq_be_p, abort)))
) ((&target_st->st_dev), (host_st->st_dev)), 0)
;
4908 __put_user(host_st->st_ino, &target_st->st_ino)(__builtin_choose_expr(sizeof(*(&target_st->st_ino)) ==
1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_ino)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_ino)) == 4, stl_be_p, __builtin_choose_expr(
sizeof(*(&target_st->st_ino)) == 8, stq_be_p, abort)))
) ((&target_st->st_ino), (host_st->st_ino)), 0)
;
4909#ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4910 __put_user(host_st->st_ino, &target_st->__st_ino)(__builtin_choose_expr(sizeof(*(&target_st->__st_ino))
== 1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
__st_ino)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->__st_ino)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_st->__st_ino)) == 8, stq_be_p, abort
)))) ((&target_st->__st_ino), (host_st->st_ino)), 0
)
;
4911#endif
4912 __put_user(host_st->st_mode, &target_st->st_mode)(__builtin_choose_expr(sizeof(*(&target_st->st_mode)) ==
1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_mode)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_mode)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_st->st_mode)) == 8, stq_be_p, abort)
))) ((&target_st->st_mode), (host_st->st_mode)), 0)
;
4913 __put_user(host_st->st_nlink, &target_st->st_nlink)(__builtin_choose_expr(sizeof(*(&target_st->st_nlink))
== 1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_nlink)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_nlink)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_st->st_nlink)) == 8, stq_be_p, abort
)))) ((&target_st->st_nlink), (host_st->st_nlink)),
0)
;
4914 __put_user(host_st->st_uid, &target_st->st_uid)(__builtin_choose_expr(sizeof(*(&target_st->st_uid)) ==
1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_uid)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_uid)) == 4, stl_be_p, __builtin_choose_expr(
sizeof(*(&target_st->st_uid)) == 8, stq_be_p, abort)))
) ((&target_st->st_uid), (host_st->st_uid)), 0)
;
4915 __put_user(host_st->st_gid, &target_st->st_gid)(__builtin_choose_expr(sizeof(*(&target_st->st_gid)) ==
1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_gid)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_gid)) == 4, stl_be_p, __builtin_choose_expr(
sizeof(*(&target_st->st_gid)) == 8, stq_be_p, abort)))
) ((&target_st->st_gid), (host_st->st_gid)), 0)
;
4916 __put_user(host_st->st_rdev, &target_st->st_rdev)(__builtin_choose_expr(sizeof(*(&target_st->st_rdev)) ==
1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_rdev)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_rdev)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_st->st_rdev)) == 8, stq_be_p, abort)
))) ((&target_st->st_rdev), (host_st->st_rdev)), 0)
;
4917 __put_user(host_st->st_size, &target_st->st_size)(__builtin_choose_expr(sizeof(*(&target_st->st_size)) ==
1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_size)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_size)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_st->st_size)) == 8, stq_be_p, abort)
))) ((&target_st->st_size), (host_st->st_size)), 0)
;
4918 __put_user(host_st->st_blksize, &target_st->st_blksize)(__builtin_choose_expr(sizeof(*(&target_st->st_blksize
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_st
->st_blksize)) == 2, stw_be_p, __builtin_choose_expr(sizeof
(*(&target_st->st_blksize)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_st->st_blksize)) == 8, stq_be_p, abort
)))) ((&target_st->st_blksize), (host_st->st_blksize
)), 0)
;
4919 __put_user(host_st->st_blocks, &target_st->st_blocks)(__builtin_choose_expr(sizeof(*(&target_st->st_blocks)
) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_blocks)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_blocks)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_st->st_blocks)) == 8, stq_be_p, abort
)))) ((&target_st->st_blocks), (host_st->st_blocks)
), 0)
;
4920 __put_user(host_st->st_atime, &target_st->target_st_atime)(__builtin_choose_expr(sizeof(*(&target_st->target_st_atime
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_st
->target_st_atime)) == 2, stw_be_p, __builtin_choose_expr(
sizeof(*(&target_st->target_st_atime)) == 4, stl_be_p,
__builtin_choose_expr(sizeof(*(&target_st->target_st_atime
)) == 8, stq_be_p, abort)))) ((&target_st->target_st_atime
), (host_st->st_atim.tv_sec)), 0)
;
4921 __put_user(host_st->st_mtime, &target_st->target_st_mtime)(__builtin_choose_expr(sizeof(*(&target_st->target_st_mtime
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_st
->target_st_mtime)) == 2, stw_be_p, __builtin_choose_expr(
sizeof(*(&target_st->target_st_mtime)) == 4, stl_be_p,
__builtin_choose_expr(sizeof(*(&target_st->target_st_mtime
)) == 8, stq_be_p, abort)))) ((&target_st->target_st_mtime
), (host_st->st_mtim.tv_sec)), 0)
;
4922 __put_user(host_st->st_ctime, &target_st->target_st_ctime)(__builtin_choose_expr(sizeof(*(&target_st->target_st_ctime
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_st
->target_st_ctime)) == 2, stw_be_p, __builtin_choose_expr(
sizeof(*(&target_st->target_st_ctime)) == 4, stl_be_p,
__builtin_choose_expr(sizeof(*(&target_st->target_st_ctime
)) == 8, stq_be_p, abort)))) ((&target_st->target_st_ctime
), (host_st->st_ctim.tv_sec)), 0)
;
4923 unlock_user_struct(target_st, target_addr, 1)unlock_user(target_st, target_addr, (1) ? sizeof(*target_st) :
0)
;
4924 } else
4925#endif
4926 {
4927#if defined(TARGET_HAS_STRUCT_STAT64)
4928 struct target_stat64 *target_st;
4929#else
4930 struct target_stat *target_st;
4931#endif
4932
4933 if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)(target_st = lock_user(1, target_addr, sizeof(*target_st), 0)
)
)
4934 return -TARGET_EFAULT14;
4935 memset(target_st, 0, sizeof(*target_st));
4936 __put_user(host_st->st_dev, &target_st->st_dev)(__builtin_choose_expr(sizeof(*(&target_st->st_dev)) ==
1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_dev)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_dev)) == 4, stl_be_p, __builtin_choose_expr(
sizeof(*(&target_st->st_dev)) == 8, stq_be_p, abort)))
) ((&target_st->st_dev), (host_st->st_dev)), 0)
;
4937 __put_user(host_st->st_ino, &target_st->st_ino)(__builtin_choose_expr(sizeof(*(&target_st->st_ino)) ==
1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_ino)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_ino)) == 4, stl_be_p, __builtin_choose_expr(
sizeof(*(&target_st->st_ino)) == 8, stq_be_p, abort)))
) ((&target_st->st_ino), (host_st->st_ino)), 0)
;
4938#ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
4939 __put_user(host_st->st_ino, &target_st->__st_ino)(__builtin_choose_expr(sizeof(*(&target_st->__st_ino))
== 1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
__st_ino)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->__st_ino)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_st->__st_ino)) == 8, stq_be_p, abort
)))) ((&target_st->__st_ino), (host_st->st_ino)), 0
)
;
4940#endif
4941 __put_user(host_st->st_mode, &target_st->st_mode)(__builtin_choose_expr(sizeof(*(&target_st->st_mode)) ==
1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_mode)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_mode)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_st->st_mode)) == 8, stq_be_p, abort)
))) ((&target_st->st_mode), (host_st->st_mode)), 0)
;
4942 __put_user(host_st->st_nlink, &target_st->st_nlink)(__builtin_choose_expr(sizeof(*(&target_st->st_nlink))
== 1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_nlink)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_nlink)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_st->st_nlink)) == 8, stq_be_p, abort
)))) ((&target_st->st_nlink), (host_st->st_nlink)),
0)
;
4943 __put_user(host_st->st_uid, &target_st->st_uid)(__builtin_choose_expr(sizeof(*(&target_st->st_uid)) ==
1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_uid)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_uid)) == 4, stl_be_p, __builtin_choose_expr(
sizeof(*(&target_st->st_uid)) == 8, stq_be_p, abort)))
) ((&target_st->st_uid), (host_st->st_uid)), 0)
;
4944 __put_user(host_st->st_gid, &target_st->st_gid)(__builtin_choose_expr(sizeof(*(&target_st->st_gid)) ==
1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_gid)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_gid)) == 4, stl_be_p, __builtin_choose_expr(
sizeof(*(&target_st->st_gid)) == 8, stq_be_p, abort)))
) ((&target_st->st_gid), (host_st->st_gid)), 0)
;
4945 __put_user(host_st->st_rdev, &target_st->st_rdev)(__builtin_choose_expr(sizeof(*(&target_st->st_rdev)) ==
1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_rdev)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_rdev)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_st->st_rdev)) == 8, stq_be_p, abort)
))) ((&target_st->st_rdev), (host_st->st_rdev)), 0)
;
4946 /* XXX: better use of kernel struct */
4947 __put_user(host_st->st_size, &target_st->st_size)(__builtin_choose_expr(sizeof(*(&target_st->st_size)) ==
1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_size)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_size)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_st->st_size)) == 8, stq_be_p, abort)
))) ((&target_st->st_size), (host_st->st_size)), 0)
;
4948 __put_user(host_st->st_blksize, &target_st->st_blksize)(__builtin_choose_expr(sizeof(*(&target_st->st_blksize
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_st
->st_blksize)) == 2, stw_be_p, __builtin_choose_expr(sizeof
(*(&target_st->st_blksize)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_st->st_blksize)) == 8, stq_be_p, abort
)))) ((&target_st->st_blksize), (host_st->st_blksize
)), 0)
;
4949 __put_user(host_st->st_blocks, &target_st->st_blocks)(__builtin_choose_expr(sizeof(*(&target_st->st_blocks)
) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_st->
st_blocks)) == 2, stw_be_p, __builtin_choose_expr(sizeof(*(&
target_st->st_blocks)) == 4, stl_be_p, __builtin_choose_expr
(sizeof(*(&target_st->st_blocks)) == 8, stq_be_p, abort
)))) ((&target_st->st_blocks), (host_st->st_blocks)
), 0)
;
4950 __put_user(host_st->st_atime, &target_st->target_st_atime)(__builtin_choose_expr(sizeof(*(&target_st->target_st_atime
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_st
->target_st_atime)) == 2, stw_be_p, __builtin_choose_expr(
sizeof(*(&target_st->target_st_atime)) == 4, stl_be_p,
__builtin_choose_expr(sizeof(*(&target_st->target_st_atime
)) == 8, stq_be_p, abort)))) ((&target_st->target_st_atime
), (host_st->st_atim.tv_sec)), 0)
;
4951 __put_user(host_st->st_mtime, &target_st->target_st_mtime)(__builtin_choose_expr(sizeof(*(&target_st->target_st_mtime
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_st
->target_st_mtime)) == 2, stw_be_p, __builtin_choose_expr(
sizeof(*(&target_st->target_st_mtime)) == 4, stl_be_p,
__builtin_choose_expr(sizeof(*(&target_st->target_st_mtime
)) == 8, stq_be_p, abort)))) ((&target_st->target_st_mtime
), (host_st->st_mtim.tv_sec)), 0)
;
4952 __put_user(host_st->st_ctime, &target_st->target_st_ctime)(__builtin_choose_expr(sizeof(*(&target_st->target_st_ctime
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(&target_st
->target_st_ctime)) == 2, stw_be_p, __builtin_choose_expr(
sizeof(*(&target_st->target_st_ctime)) == 4, stl_be_p,
__builtin_choose_expr(sizeof(*(&target_st->target_st_ctime
)) == 8, stq_be_p, abort)))) ((&target_st->target_st_ctime
), (host_st->st_ctim.tv_sec)), 0)
;
4953 unlock_user_struct(target_st, target_addr, 1)unlock_user(target_st, target_addr, (1) ? sizeof(*target_st) :
0)
;
4954 }
4955
4956 return 0;
4957}
4958#endif
4959
4960/* ??? Using host futex calls even when target atomic operations
4961 are not really atomic probably breaks things. However implementing
4962 futexes locally would make futexes shared between multiple processes
4963 tricky. However they're probably useless because guest atomic
4964 operations won't work either. */
4965static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout,
4966 target_ulong uaddr2, int val3)
4967{
4968 struct timespec ts, *pts;
4969 int base_op;
4970
4971 /* ??? We assume FUTEX_* constants are the same on both host
4972 and target. */
4973#ifdef FUTEX_CMD_MASK~(128 | 256)
4974 base_op = op & FUTEX_CMD_MASK~(128 | 256);
4975#else
4976 base_op = op;
4977#endif
4978 switch (base_op) {
4979 case FUTEX_WAIT0:
4980 case FUTEX_WAIT_BITSET9:
4981 if (timeout) {
4982 pts = &ts;
4983 target_to_host_timespec(pts, timeout);
4984 } else {
4985 pts = NULL((void*)0);
4986 }
4987 return get_errno(sys_futex(g2h(uaddr)((void *)((unsigned long)(target_ulong)(uaddr) + guest_base)), op, tswap32(val),
4988 pts, NULL((void*)0), val3));
4989 case FUTEX_WAKE1:
4990 return get_errno(sys_futex(g2h(uaddr)((void *)((unsigned long)(target_ulong)(uaddr) + guest_base)), op, val, NULL((void*)0), NULL((void*)0), 0));
4991 case FUTEX_FD2:
4992 return get_errno(sys_futex(g2h(uaddr)((void *)((unsigned long)(target_ulong)(uaddr) + guest_base)), op, val, NULL((void*)0), NULL((void*)0), 0));
4993 case FUTEX_REQUEUE3:
4994 case FUTEX_CMP_REQUEUE4:
4995 case FUTEX_WAKE_OP5:
4996 /* For FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, and FUTEX_WAKE_OP, the
4997 TIMEOUT parameter is interpreted as a uint32_t by the kernel.
4998 But the prototype takes a `struct timespec *'; insert casts
4999 to satisfy the compiler. We do not need to tswap TIMEOUT
5000 since it's not compared to guest memory. */
5001 pts = (struct timespec *)(uintptr_t) timeout;
5002 return get_errno(sys_futex(g2h(uaddr)((void *)((unsigned long)(target_ulong)(uaddr) + guest_base)), op, val, pts,
5003 g2h(uaddr2)((void *)((unsigned long)(target_ulong)(uaddr2) + guest_base)
)
,
5004 (base_op == FUTEX_CMP_REQUEUE4
5005 ? tswap32(val3)
5006 : val3)));
5007 default:
5008 return -TARGET_ENOSYS38;
5009 }
5010}
5011
5012/* Map host to target signal numbers for the wait family of syscalls.
5013 Assume all other status bits are the same. */
5014int host_to_target_waitstatus(int status)
5015{
5016 if (WIFSIGNALED(status)(((signed char) ((((__extension__ (((union { __typeof(status)
__in; int __i; }) { .__in = (status) }).__i))) & 0x7f) +
1) >> 1) > 0)
) {
5017 return host_to_target_signal(WTERMSIG(status)(((__extension__ (((union { __typeof(status) __in; int __i; }
) { .__in = (status) }).__i))) & 0x7f)
) | (status & ~0x7f);
5018 }
5019 if (WIFSTOPPED(status)((((__extension__ (((union { __typeof(status) __in; int __i; }
) { .__in = (status) }).__i))) & 0xff) == 0x7f)
) {
5020 return (host_to_target_signal(WSTOPSIG(status)((((__extension__ (((union { __typeof(status) __in; int __i; }
) { .__in = (status) }).__i))) & 0xff00) >> 8)
) << 8)
5021 | (status & 0xff);
5022 }
5023 return status;
5024}
5025
5026static int relstr_to_int(const char *s)
5027{
5028 /* Convert a uname release string like "2.6.18" to an integer
5029 * of the form 0x020612. (Beware that 0x020612 is *not* 2.6.12.)
5030 */
5031 int i, n, tmp;
5032
5033 tmp = 0;
5034 for (i = 0; i < 3; i++) {
5035 n = 0;
5036 while (*s >= '0' && *s <= '9') {
5037 n *= 10;
5038 n += *s - '0';
5039 s++;
5040 }
5041 tmp = (tmp << 8) + n;
5042 if (*s == '.') {
5043 s++;
5044 }
5045 }
5046 return tmp;
5047}
5048
5049int get_osversion(void)
5050{
5051 static int osversion;
5052 struct new_utsname buf;
5053 const char *s;
5054
5055 if (osversion)
5056 return osversion;
5057 if (qemu_uname_release && *qemu_uname_release) {
5058 s = qemu_uname_release;
5059 } else {
5060 if (sys_uname(&buf))
5061 return 0;
5062 s = buf.release;
5063 }
5064 osversion = relstr_to_int(s);
5065 return osversion;
5066}
5067
5068void init_qemu_uname_release(void)
5069{
5070 /* Initialize qemu_uname_release for later use.
5071 * If the host kernel is too old and the user hasn't asked for
5072 * a specific fake version number, we might want to fake a minimum
5073 * target kernel version.
5074 */
5075#ifdef UNAME_MINIMUM_RELEASE
5076 struct new_utsname buf;
5077
5078 if (qemu_uname_release && *qemu_uname_release) {
5079 return;
5080 }
5081
5082 if (sys_uname(&buf)) {
5083 return;
5084 }
5085
5086 if (relstr_to_int(buf.release) < relstr_to_int(UNAME_MINIMUM_RELEASE)) {
5087 qemu_uname_release = UNAME_MINIMUM_RELEASE;
5088 }
5089#endif
5090}
5091
5092static int open_self_maps(void *cpu_env, int fd)
5093{
5094#if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32)
5095 TaskState *ts = ((CPUArchStatestruct CPUS390XState *)cpu_env)->opaque;
5096#endif
5097 FILE *fp;
5098 char *line = NULL((void*)0);
5099 size_t len = 0;
5100 ssize_t read;
5101
5102 fp = fopen("/proc/self/maps", "r");
5103 if (fp == NULL((void*)0)) {
5104 return -EACCES13;
5105 }
5106
5107 while ((read = getline(&line, &len, fp)) != -1) {
5108 int fields, dev_maj, dev_min, inode;
5109 uint64_t min, max, offset;
5110 char flag_r, flag_w, flag_x, flag_p;
5111 char path[512] = "";
5112 fields = sscanf(line, "%"PRIx64"l" "x""-%"PRIx64"l" "x"" %c%c%c%c %"PRIx64"l" "x"" %x:%x %d"
5113 " %512s", &min, &max, &flag_r, &flag_w, &flag_x,
5114 &flag_p, &offset, &dev_maj, &dev_min, &inode, path);
5115
5116 if ((fields < 10) || (fields > 11)) {
5117 continue;
5118 }
5119 if (!strncmp(path, "[stack]", 7)) {
5120 continue;
5121 }
5122 if (h2g_valid(min)1 && h2g_valid(max)1) {
5123 dprintf(fd, TARGET_ABI_FMT_lx"%016" "l" "x" "-" TARGET_ABI_FMT_lx"%016" "l" "x"
5124 " %c%c%c%c %08" PRIx64"l" "x" " %02x:%02x %d %s%s\n",
5125 h2g(min)({ ((1) ? (void) (0) : __assert_fail ("1", "/home/stefan/src/qemu/qemu.org/qemu/linux-user/syscall.c"
, 5125, __PRETTY_FUNCTION__)); ({ unsigned long __ret = (unsigned
long)(min) - guest_base; (abi_ulong)__ret; }); })
, h2g(max)({ ((1) ? (void) (0) : __assert_fail ("1", "/home/stefan/src/qemu/qemu.org/qemu/linux-user/syscall.c"
, 5125, __PRETTY_FUNCTION__)); ({ unsigned long __ret = (unsigned
long)(max) - guest_base; (abi_ulong)__ret; }); })
, flag_r, flag_w,
5126 flag_x, flag_p, offset, dev_maj, dev_min, inode,
5127 path[0] ? " " : "", path);
5128 }
5129 }
5130
5131 free(line);
5132 fclose(fp);
5133
5134#if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32)
5135 dprintf(fd, "%08llx-%08llx rw-p %08llx 00:00 0 [stack]\n",
5136 (unsigned long long)ts->info->stack_limit,
5137 (unsigned long long)(ts->info->start_stack +
5138 (TARGET_PAGE_SIZE(1 << 12) - 1)) & TARGET_PAGE_MASK~((1 << 12) - 1),
5139 (unsigned long long)0);
5140#endif
5141
5142 return 0;
5143}
5144
5145static int open_self_stat(void *cpu_env, int fd)
5146{
5147 TaskState *ts = ((CPUArchStatestruct CPUS390XState *)cpu_env)->opaque;
5148 abi_ulong start_stack = ts->info->start_stack;
5149 int i;
5150
5151 for (i = 0; i < 44; i++) {
5152 char buf[128];
5153 int len;
5154 uint64_t val = 0;
5155
5156 if (i == 0) {
5157 /* pid */
5158 val = getpid();
5159 snprintf(buf, sizeof(buf), "%"PRId64"l" "d" " ", val);
5160 } else if (i == 1) {
5161 /* app name */
5162 snprintf(buf, sizeof(buf), "(%s) ", ts->bprm->argv[0]);
5163 } else if (i == 27) {
5164 /* stack bottom */
5165 val = start_stack;
5166 snprintf(buf, sizeof(buf), "%"PRId64"l" "d" " ", val);
5167 } else {
5168 /* for the rest, there is MasterCard */
5169 snprintf(buf, sizeof(buf), "0%c", i == 43 ? '\n' : ' ');
5170 }
5171
5172 len = strlen(buf);
5173 if (write(fd, buf, len) != len) {
5174 return -1;
5175 }
5176 }
5177
5178 return 0;
5179}
5180
5181static int open_self_auxv(void *cpu_env, int fd)
5182{
5183 TaskState *ts = ((CPUArchStatestruct CPUS390XState *)cpu_env)->opaque;
5184 abi_ulong auxv = ts->info->saved_auxv;
5185 abi_ulong len = ts->info->auxv_len;
5186 char *ptr;
5187
5188 /*
5189 * Auxiliary vector is stored in target process stack.
5190 * read in whole auxv vector and copy it to file
5191 */
5192 ptr = lock_user(VERIFY_READ0, auxv, len, 0);
5193 if (ptr != NULL((void*)0)) {
5194 while (len > 0) {
5195 ssize_t r;
5196 r = write(fd, ptr, len);
5197 if (r <= 0) {
5198 break;
5199 }
5200 len -= r;
5201 ptr += r;
5202 }
5203 lseek(fd, 0, SEEK_SET0);
5204 unlock_user(ptr, auxv, len);
5205 }
5206
5207 return 0;
5208}
5209
5210static int is_proc_myself(const char *filename, const char *entry)
5211{
5212 if (!strncmp(filename, "/proc/", strlen("/proc/"))) {
5213 filename += strlen("/proc/");
5214 if (!strncmp(filename, "self/", strlen("self/"))) {
5215 filename += strlen("self/");
5216 } else if (*filename >= '1' && *filename <= '9') {
5217 char myself[80];
5218 snprintf(myself, sizeof(myself), "%d/", getpid());
5219 if (!strncmp(filename, myself, strlen(myself))) {
5220 filename += strlen(myself);
5221 } else {
5222 return 0;
5223 }
5224 } else {
5225 return 0;
5226 }
5227 if (!strcmp(filename, entry)) {
5228 return 1;
5229 }
5230 }
5231 return 0;
5232}
5233
5234#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN1)
5235static int is_proc(const char *filename, const char *entry)
5236{
5237 return strcmp(filename, entry) == 0;
5238}
5239
5240static int open_net_route(void *cpu_env, int fd)
5241{
5242 FILE *fp;
5243 char *line = NULL((void*)0);
5244 size_t len = 0;
5245 ssize_t read;
5246
5247 fp = fopen("/proc/net/route", "r");
5248 if (fp == NULL((void*)0)) {
5249 return -EACCES13;
5250 }
5251
5252 /* read header */
5253
5254 read = getline(&line, &len, fp);
5255 dprintf(fd, "%s", line);
5256
5257 /* read routes */
5258
5259 while ((read = getline(&line, &len, fp)) != -1) {
5260 char iface[16];
5261 uint32_t dest, gw, mask;
5262 unsigned int flags, refcnt, use, metric, mtu, window, irtt;
5263 sscanf(line, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
5264 iface, &dest, &gw, &flags, &refcnt, &use, &metric,
5265 &mask, &mtu, &window, &irtt);
5266 dprintf(fd, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
5267 iface, tswap32(dest), tswap32(gw), flags, refcnt, use,
5268 metric, tswap32(mask), mtu, window, irtt);
5269 }
5270
5271 free(line);
5272 fclose(fp);
5273
5274 return 0;
5275}
5276#endif
5277
5278static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
5279{
5280 struct fake_open {
5281 const char *filename;
5282 int (*fill)(void *cpu_env, int fd);
5283 int (*cmp)(const char *s1, const char *s2);
5284 };
5285 const struct fake_open *fake_open;
5286 static const struct fake_open fakes[] = {
5287 { "maps", open_self_maps, is_proc_myself },
5288 { "stat", open_self_stat, is_proc_myself },
5289 { "auxv", open_self_auxv, is_proc_myself },
5290#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN1)
5291 { "/proc/net/route", open_net_route, is_proc },
5292#endif
5293 { NULL((void*)0), NULL((void*)0), NULL((void*)0) }
5294 };
5295
5296 for (fake_open = fakes; fake_open->filename; fake_open++) {
5297 if (fake_open->cmp(pathname, fake_open->filename)) {
5298 break;
5299 }
5300 }
5301
5302 if (fake_open->filename) {
5303 const char *tmpdir;
5304 char filename[PATH_MAX4096];
5305 int fd, r;
5306
5307 /* create temporary file to map stat to */
5308 tmpdir = getenv("TMPDIR");
5309 if (!tmpdir)
5310 tmpdir = "/tmp";
5311 snprintf(filename, sizeof(filename), "%s/qemu-open.XXXXXX", tmpdir);
5312 fd = mkstemp(filename);
5313 if (fd < 0) {
5314 return fd;
5315 }
5316 unlink(filename);
5317
5318 if ((r = fake_open->fill(cpu_env, fd))) {
5319 close(fd);
5320 return r;
5321 }
5322 lseek(fd, 0, SEEK_SET0);
5323
5324 return fd;
5325 }
5326
5327 return get_errno(open(path(pathname), flags, mode));
5328}
5329
5330/* do_syscall() should always have a single exit point at the end so
5331 that actions, such as logging of syscall results, can be performed.
5332 All errnos that do_syscall() returns must be -TARGET_<errcode>. */
5333abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
5334 abi_long arg2, abi_long arg3, abi_long arg4,
5335 abi_long arg5, abi_long arg6, abi_long arg7,
5336 abi_long arg8)
5337{
5338 CPUState *cpu = ENV_GET_CPU(cpu_env)((CPUState *)object_dynamic_cast_assert(((Object *)((s390_env_get_cpu
(cpu_env)))), ("cpu"), "/home/stefan/src/qemu/qemu.org/qemu/linux-user/syscall.c"
, 5338, __func__))
;
5339 abi_long ret;
5340 struct stat st;
5341 struct statfs stfs;
5342 void *p;
5343
5344#ifdef DEBUG
5345 gemu_log("syscall %d", num);
5346#endif
5347 if(do_strace)
5348 print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
5349
5350 switch(num) {
5351 case TARGET_NR_exit1:
5352 /* In old applications this may be used to implement _exit(2).
5353 However in threaded applictions it is used for thread termination,
5354 and _exit_group is used for application termination.
5355 Do thread termination if we have more then one thread. */
5356 /* FIXME: This probably breaks if a signal arrives. We should probably
5357 be disabling signals. */
5358 if (CPU_NEXT(first_cpu)((((&cpus)->tqh_first))->node.tqe_next)) {
5359 TaskState *ts;
5360
5361 cpu_list_lock();
5362 /* Remove the CPU from the list. */
5363 QTAILQ_REMOVE(&cpus, cpu, node)do { if (((cpu)->node.tqe_next) != ((void*)0)) (cpu)->node
.tqe_next->node.tqe_prev = (cpu)->node.tqe_prev; else (
&cpus)->tqh_last = (cpu)->node.tqe_prev; *(cpu)->
node.tqe_prev = (cpu)->node.tqe_next; } while ( 0)
;
5364 cpu_list_unlock();
5365 ts = ((CPUArchStatestruct CPUS390XState *)cpu_env)->opaque;
5366 if (ts->child_tidptr) {
5367 put_user_u32(0, ts->child_tidptr)({ abi_ulong __gaddr = ((ts->child_tidptr)); uint32_t *__hptr
; abi_long __ret; if ((__hptr = lock_user(1, __gaddr, sizeof(
uint32_t), 0))) { __ret = (__builtin_choose_expr(sizeof(*(__hptr
)) == 1, stb_p, __builtin_choose_expr(sizeof(*(__hptr)) == 2,
stw_be_p, __builtin_choose_expr(sizeof(*(__hptr)) == 4, stl_be_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 8, stq_be_p, abort
)))) ((__hptr), (((0)))), 0); unlock_user(__hptr, __gaddr, sizeof
(uint32_t)); } else __ret = -14; __ret; })
;
5368 sys_futex(g2h(ts->child_tidptr)((void *)((unsigned long)(target_ulong)(ts->child_tidptr) +
guest_base))
, FUTEX_WAKE1, INT_MAX2147483647,
5369 NULL((void*)0), NULL((void*)0), 0);
5370 }
5371 thread_cpu = NULL((void*)0);
5372 object_unref(OBJECT(ENV_GET_CPU(cpu_env))((Object *)(((CPUState *)object_dynamic_cast_assert(((Object *
)((s390_env_get_cpu(cpu_env)))), ("cpu"), "/home/stefan/src/qemu/qemu.org/qemu/linux-user/syscall.c"
, 5372, __func__))))
);
5373 g_free(ts);
5374 pthread_exit(NULL((void*)0));
5375 }
5376#ifdef TARGET_GPROF
5377 _mcleanup();
5378#endif
5379 gdb_exit(cpu_env, arg1);
5380 _exit(arg1);
5381 ret = 0; /* avoid warning */
5382 break;
5383 case TARGET_NR_read3:
5384 if (arg3 == 0)
5385 ret = 0;
5386 else {
5387 if (!(p = lock_user(VERIFY_WRITE1, arg2, arg3, 0)))
5388 goto efault;
5389 ret = get_errno(read(arg1, p, arg3));
5390 unlock_user(p, arg2, ret);
5391 }
5392 break;
5393 case TARGET_NR_write4:
5394 if (!(p = lock_user(VERIFY_READ0, arg2, arg3, 1)))
5395 goto efault;
5396 ret = get_errno(write(arg1, p, arg3));
5397 unlock_user(p, arg2, 0);
5398 break;
5399 case TARGET_NR_open5:
5400 if (!(p = lock_user_string(arg1)))
5401 goto efault;
5402 ret = get_errno(do_open(cpu_env, p,
5403 target_to_host_bitmask(arg2, fcntl_flags_tbl),
5404 arg3));
5405 unlock_user(p, arg1, 0);
5406 break;
5407#if defined(TARGET_NR_openat288) && defined(__NR_openat257)
5408 case TARGET_NR_openat288:
5409 if (!(p = lock_user_string(arg2)))
5410 goto efault;
5411 ret = get_errno(sys_openat(arg1,
5412 path(p),
5413 target_to_host_bitmask(arg3, fcntl_flags_tbl),
5414 arg4));
5415 unlock_user(p, arg2, 0);
5416 break;
5417#endif
5418 case TARGET_NR_close6:
5419 ret = get_errno(close(arg1));
5420 break;
5421 case TARGET_NR_brk45:
5422 ret = do_brk(arg1);
5423 break;
5424 case TARGET_NR_fork2:
5425 ret = get_errno(do_fork(cpu_env, SIGCHLD17, 0, 0, 0, 0));
5426 break;
5427#ifdef TARGET_NR_waitpid
5428 case TARGET_NR_waitpid:
5429 {
5430 int status;
5431 ret = get_errno(waitpid(arg1, &status, arg3));
5432 if (!is_error(ret) && arg2 && ret
5433 && put_user_s32(host_to_target_waitstatus(status), arg2)({ abi_ulong __gaddr = ((arg2)); int32_t *__hptr; abi_long __ret
; if ((__hptr = lock_user(1, __gaddr, sizeof(int32_t), 0))) {
__ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1, stb_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), (((host_to_target_waitstatus
(status))))), 0); unlock_user(__hptr, __gaddr, sizeof(int32_t
)); } else __ret = -14; __ret; })
)
5434 goto efault;
5435 }
5436 break;
5437#endif
5438#ifdef TARGET_NR_waitid281
5439 case TARGET_NR_waitid281:
5440 {
5441 siginfo_t info;
5442 info.si_pid_sifields._kill.si_pid = 0;
5443 ret = get_errno(waitid(arg1, arg2, &info, arg4));
5444 if (!is_error(ret) && arg3 && info.si_pid_sifields._kill.si_pid != 0) {
5445 if (!(p = lock_user(VERIFY_WRITE1, arg3, sizeof(target_siginfo_t), 0)))
5446 goto efault;
5447 host_to_target_siginfo(p, &info);
5448 unlock_user(p, arg3, sizeof(target_siginfo_t));
5449 }
5450 }
5451 break;
5452#endif
5453#ifdef TARGET_NR_creat8 /* not on alpha */
5454 case TARGET_NR_creat8:
5455 if (!(p = lock_user_string(arg1)))
5456 goto efault;
5457 ret = get_errno(creat(p, arg2));
5458 unlock_user(p, arg1, 0);
5459 break;
5460#endif
5461 case TARGET_NR_link9:
5462 {
5463 void * p2;
5464 p = lock_user_string(arg1);
5465 p2 = lock_user_string(arg2);
5466 if (!p || !p2)
5467 ret = -TARGET_EFAULT14;
5468 else
5469 ret = get_errno(link(p, p2));
5470 unlock_user(p2, arg2, 0);
5471 unlock_user(p, arg1, 0);
5472 }
5473 break;
5474#if defined(TARGET_NR_linkat296)
5475 case TARGET_NR_linkat296:
5476 {
5477 void * p2 = NULL((void*)0);
5478 if (!arg2 || !arg4)
5479 goto efault;
5480 p = lock_user_string(arg2);
5481 p2 = lock_user_string(arg4);
5482 if (!p || !p2)
5483 ret = -TARGET_EFAULT14;
5484 else
5485 ret = get_errno(linkat(arg1, p, arg3, p2, arg5));
5486 unlock_user(p, arg2, 0);
5487 unlock_user(p2, arg4, 0);
5488 }
5489 break;
5490#endif
5491 case TARGET_NR_unlink10:
5492 if (!(p = lock_user_string(arg1)))
5493 goto efault;
5494 ret = get_errno(unlink(p));
5495 unlock_user(p, arg1, 0);
5496 break;
5497#if defined(TARGET_NR_unlinkat294)
5498 case TARGET_NR_unlinkat294:
5499 if (!(p = lock_user_string(arg2)))
5500 goto efault;
5501 ret = get_errno(unlinkat(arg1, p, arg3));
5502 unlock_user(p, arg2, 0);
5503 break;
5504#endif
5505 case TARGET_NR_execve11:
5506 {
5507 char **argp, **envp;
5508 int argc, envc;
5509 abi_ulong gp;
5510 abi_ulong guest_argp;
5511 abi_ulong guest_envp;
5512 abi_ulong addr;
5513 char **q;
5514 int total_size = 0;
5515
5516 argc = 0;
5517 guest_argp = arg2;
5518 for (gp = guest_argp; gp; gp += sizeof(abi_ulong)) {
5519 if (get_user_ual(addr, gp)({ abi_ulong __gaddr = ((gp)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((addr))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((addr)) = 0; __ret = -14; } __ret; })
)
5520 goto efault;
5521 if (!addr)
5522 break;
5523 argc++;
5524 }
5525 envc = 0;
5526 guest_envp = arg3;
5527 for (gp = guest_envp; gp; gp += sizeof(abi_ulong)) {
5528 if (get_user_ual(addr, gp)({ abi_ulong __gaddr = ((gp)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((addr))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((addr)) = 0; __ret = -14; } __ret; })
)
5529 goto efault;
5530 if (!addr)
5531 break;
5532 envc++;
5533 }
5534
5535 argp = alloca((argc + 1) * sizeof(void *))__builtin_alloca ((argc + 1) * sizeof(void *));
5536 envp = alloca((envc + 1) * sizeof(void *))__builtin_alloca ((envc + 1) * sizeof(void *));
5537
5538 for (gp = guest_argp, q = argp; gp;
5539 gp += sizeof(abi_ulong), q++) {
5540 if (get_user_ual(addr, gp)({ abi_ulong __gaddr = ((gp)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((addr))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((addr)) = 0; __ret = -14; } __ret; })
)
5541 goto execve_efault;
5542 if (!addr)
5543 break;
5544 if (!(*q = lock_user_string(addr)))
5545 goto execve_efault;
5546 total_size += strlen(*q) + 1;
5547 }
5548 *q = NULL((void*)0);
5549
5550 for (gp = guest_envp, q = envp; gp;
5551 gp += sizeof(abi_ulong), q++) {
5552 if (get_user_ual(addr, gp)({ abi_ulong __gaddr = ((gp)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((addr))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((addr)) = 0; __ret = -14; } __ret; })
)
5553 goto execve_efault;
5554 if (!addr)
5555 break;
5556 if (!(*q = lock_user_string(addr)))
5557 goto execve_efault;
5558 total_size += strlen(*q) + 1;
5559 }
5560 *q = NULL((void*)0);
5561
5562 /* This case will not be caught by the host's execve() if its
5563 page size is bigger than the target's. */
5564 if (total_size > MAX_ARG_PAGES33 * TARGET_PAGE_SIZE(1 << 12)) {
5565 ret = -TARGET_E2BIG7;
5566 goto execve_end;
5567 }
5568 if (!(p = lock_user_string(arg1)))
5569 goto execve_efault;
5570 ret = get_errno(execve(p, argp, envp));
5571 unlock_user(p, arg1, 0);
5572
5573 goto execve_end;
5574
5575 execve_efault:
5576 ret = -TARGET_EFAULT14;
5577
5578 execve_end:
5579 for (gp = guest_argp, q = argp; *q;
5580 gp += sizeof(abi_ulong), q++) {
5581 if (get_user_ual(addr, gp)({ abi_ulong __gaddr = ((gp)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((addr))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((addr)) = 0; __ret = -14; } __ret; })
5582 || !addr)
5583 break;
5584 unlock_user(*q, addr, 0);
5585 }
5586 for (gp = guest_envp, q = envp; *q;
5587 gp += sizeof(abi_ulong), q++) {
5588 if (get_user_ual(addr, gp)({ abi_ulong __gaddr = ((gp)); abi_ulong *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_ulong), 1)))
{ __ret = ((((addr))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((addr)) = 0; __ret = -14; } __ret; })
5589 || !addr)
5590 break;
5591 unlock_user(*q, addr, 0);
5592 }
5593 }
5594 break;
5595 case TARGET_NR_chdir12:
5596 if (!(p = lock_user_string(arg1)))
5597 goto efault;
5598 ret = get_errno(chdir(p));
5599 unlock_user(p, arg1, 0);
5600 break;
5601#ifdef TARGET_NR_time
5602 case TARGET_NR_time:
5603 {
5604 time_t host_time;
5605 ret = get_errno(time(&host_time));
5606 if (!is_error(ret)
5607 && arg1
5608 && put_user_sal(host_time, arg1)({ abi_ulong __gaddr = ((arg1)); abi_long *__hptr; abi_long __ret
; if ((__hptr = lock_user(1, __gaddr, sizeof(abi_long), 0))) {
__ret = (__builtin_choose_expr(sizeof(*(__hptr)) == 1, stb_p
, __builtin_choose_expr(sizeof(*(__hptr)) == 2, stw_be_p, __builtin_choose_expr
(sizeof(*(__hptr)) == 4, stl_be_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 8, stq_be_p, abort)))) ((__hptr), (((host_time
)))), 0); unlock_user(__hptr, __gaddr, sizeof(abi_long)); } else
__ret = -14; __ret; })
)
5609 goto efault;
5610 }
5611 break;
5612#endif
5613 case TARGET_NR_mknod14:
5614 if (!(p = lock_user_string(arg1)))
5615 goto efault;
5616 ret = get_errno(mknod(p, arg2, arg3));
5617 unlock_user(p, arg1, 0);
5618 break;
5619#if defined(TARGET_NR_mknodat290)
5620 case TARGET_NR_mknodat290:
5621 if (!(p = lock_user_string(arg2)))
5622 goto efault;
5623 ret = get_errno(mknodat(arg1, p, arg3, arg4));
5624 unlock_user(p, arg2, 0);
5625 break;
5626#endif
5627 case TARGET_NR_chmod15:
5628 if (!(p = lock_user_string(arg1)))
5629 goto efault;
5630 ret = get_errno(chmod(p, arg2));
5631 unlock_user(p, arg1, 0);
5632 break;
5633#ifdef TARGET_NR_break
5634 case TARGET_NR_break:
5635 goto unimplemented;
5636#endif
5637#ifdef TARGET_NR_oldstat
5638 case TARGET_NR_oldstat:
5639 goto unimplemented;
5640#endif
5641 case TARGET_NR_lseek19:
5642 ret = get_errno(lseek(arg1, arg2, arg3));
5643 break;
5644#if defined(TARGET_NR_getxpid) && defined(TARGET_ALPHA)
5645 /* Alpha specific */
5646 case TARGET_NR_getxpid:
5647 ((CPUAlphaState *)cpu_env)->ir[IR_A4] = getppid();
5648 ret = get_errno(getpid());
5649 break;
5650#endif
5651#ifdef TARGET_NR_getpid20
5652 case TARGET_NR_getpid20:
5653 ret = get_errno(getpid());
5654 break;
5655#endif
5656 case TARGET_NR_mount21:
5657 {
5658 /* need to look at the data field */
5659 void *p2, *p3;
5660 p = lock_user_string(arg1);
5661 p2 = lock_user_string(arg2);
5662 p3 = lock_user_string(arg3);
5663 if (!p || !p2 || !p3)
5664 ret = -TARGET_EFAULT14;
5665 else {
5666 /* FIXME - arg5 should be locked, but it isn't clear how to
5667 * do that since it's not guaranteed to be a NULL-terminated
5668 * string.
5669 */
5670 if ( ! arg5 )
5671 ret = get_errno(mount(p, p2, p3, (unsigned long)arg4, NULL((void*)0)));
5672 else
5673 ret = get_errno(mount(p, p2, p3, (unsigned long)arg4, g2h(arg5)((void *)((unsigned long)(target_ulong)(arg5) + guest_base))));
5674 }
5675 unlock_user(p, arg1, 0);
5676 unlock_user(p2, arg2, 0);
5677 unlock_user(p3, arg3, 0);
5678 break;
5679 }
5680#ifdef TARGET_NR_umount22
5681 case TARGET_NR_umount22:
5682 if (!(p = lock_user_string(arg1)))
5683 goto efault;
5684 ret = get_errno(umount(p));
5685 unlock_user(p, arg1, 0);
5686 break;
5687#endif
5688#ifdef TARGET_NR_stime /* not on alpha */
5689 case TARGET_NR_stime:
5690 {
5691 time_t host_time;
5692 if (get_user_sal(host_time, arg1)({ abi_ulong __gaddr = ((arg1)); abi_long *__hptr; abi_long __ret
; if ((__hptr = lock_user(0, __gaddr, sizeof(abi_long), 1))) {
__ret = ((((host_time))) = (typeof(*__hptr))( __builtin_choose_expr
(sizeof(*(__hptr)) == 1, ldub_p, __builtin_choose_expr(sizeof
(*(__hptr)) == 2, lduw_be_p, __builtin_choose_expr(sizeof(*(__hptr
)) == 4, ldl_be_p, __builtin_choose_expr(sizeof(*(__hptr)) ==
8, ldq_be_p, abort)))) (__hptr)), 0); unlock_user(__hptr, __gaddr
, 0); } else { ((host_time)) = 0; __ret = -14; } __ret; })
)
5693 goto efault;
5694 ret = get_errno(stime(&host_time));
5695 }
5696 break;
5697#endif
5698 case TARGET_NR_ptrace26:
5699 goto unimplemented;
5700#ifdef TARGET_NR_alarm27 /* not on alpha */
5701 case TARGET_NR_alarm27:
5702 ret = alarm(arg1);
5703 break;
5704#endif
5705#ifdef TARGET_NR_oldfstat
5706 case TARGET_NR_oldfstat:
5707 goto unimplemented;
5708#endif
5709#ifdef TARGET_NR_pause29 /* not on alpha */
5710 case TARGET_NR_pause29:
5711 ret = get_errno(pause());
5712 break;
5713#endif
5714#ifdef TARGET_NR_utime30
5715 case TARGET_NR_utime30:
5716 {
5717 struct utimbuf tbuf, *host_tbuf;
5718 struct target_utimbuf *target_tbuf;
5719 if (arg2) {
5720 if (!lock_user_struct(VERIFY_READ, target_tbuf, arg2, 1)(target_tbuf = lock_user(0, arg2, sizeof(*target_tbuf), 1)))
5721 goto efault;
5722 tbuf.actime = tswapal(target_tbuf->actime);
5723 tbuf.modtime = tswapal(target_tbuf->modtime);
5724 unlock_user_struct(target_tbuf, arg2, 0)unlock_user(target_tbuf, arg2, (0) ? sizeof(*target_tbuf) : 0
)
;
5725 host_tbuf = &tbuf;
5726 } else {
5727 host_tbuf = NULL((void*)0);
5728 }
5729 if (!(p = lock_user_string(arg1)))
5730 goto efault;
5731 ret = get_errno(utime(p, host_tbuf));
5732 unlock_user(p, arg1, 0);
5733 }
5734 break;
5735#endif
5736 case TARGET_NR_utimes313:
5737 {
5738 struct timeval *tvp, tv[2];
5739 if (arg2) {
5740 if (copy_from_user_timeval(&tv[0], arg2)
5741 || copy_from_user_timeval(&tv[1],
5742 arg2 + sizeof(struct target_timeval)))
5743 goto efault;
5744 tvp = tv;
5745 } else {
5746 tvp = NULL((void*)0);
5747 }
5748 if (!(p = lock_user_string(arg1)))
5749 goto efault;
5750 ret = get_errno(utimes(p, tvp));
5751 unlock_user(p, arg1, 0);
5752 }
5753 break;
5754#if defined(TARGET_NR_futimesat292)
5755 case TARGET_NR_futimesat292:
5756 {
5757 struct timeval *tvp, tv[2];
5758 if (arg3) {
5759 if (copy_from_user_timeval(&tv[0], arg3)
5760 || copy_from_user_timeval(&tv[1],
5761 arg3 + sizeof(struct target_timeval)))
5762 goto efault;
5763 tvp = tv;
5764 } else {
5765 tvp = NULL((void*)0);
5766 }
5767 if (!(p = lock_user_string(arg2)))
5768 goto efault;
5769 ret = get_errno(futimesat(arg1, path(p), tvp));
5770 unlock_user(p, arg2, 0);
5771 }
5772 break;
5773#endif
5774#ifdef TARGET_NR_stty
5775 case TARGET_NR_stty:
5776 goto unimplemented;
5777#endif
5778#ifdef TARGET_NR_gtty
5779 case TARGET_NR_gtty:
5780 goto unimplemented;
5781#endif
5782 case TARGET_NR_access33:
5783 if (!(p = lock_user_string(arg1)))
5784 goto efault;
5785 ret = get_errno(access(path(p), arg2));
5786 unlock_user(p, arg1, 0);
5787 break;
5788#if defined(TARGET_NR_faccessat300) && defined(__NR_faccessat269)
5789 case TARGET_NR_faccessat300:
5790 if (!(p = lock_user_string(arg2)))
5791 goto efault;
5792 ret = get_errno(faccessat(arg1, p, arg3, 0));
5793 unlock_user(p, arg2, 0);
5794 break;
5795#endif
5796#ifdef TARGET_NR_nice34 /* not on alpha */
5797 case TARGET_NR_nice34:
5798 ret = get_errno(nice(arg1));
5799 break;
5800#endif
5801#ifdef TARGET_NR_ftime
5802 case TARGET_NR_ftime:
5803 goto unimplemented;
5804#endif
5805 case TARGET_NR_sync36:
5806 sync();
5807 ret = 0;
5808 break;
5809 case TARGET_NR_kill37:
5810 ret = get_errno(kill(arg1, target_to_host_signal(arg2)));
5811 break;
5812 case TARGET_NR_rename38:
5813 {
5814 void *p2;
5815 p = lock_user_string(arg1);
5816 p2 = lock_user_string(arg2);
5817 if (!p || !p2)
5818 ret = -TARGET_EFAULT14;
5819 else
5820 ret = get_errno(rename(p, p2));
5821 unlock_user(p2, arg2, 0);
5822 unlock_user(p, arg1, 0);
5823 }
5824 break;
5825#if defined(TARGET_NR_renameat295)
5826 case TARGET_NR_renameat295:
5827 {
5828 void *p2;
5829 p = lock_user_string(arg2);
5830 p2 = lock_user_string(arg4);
5831 if (!p || !p2)
5832 ret = -TARGET_EFAULT14;
5833 else
5834 ret = get_errno(renameat(arg1, p, arg3, p2));
5835 unlock_user(p2, arg4, 0);
5836 unlock_user(p, arg2, 0);
5837 }
5838 break;
5839#endif
5840 case TARGET_NR_mkdir39:
5841 if (!(p = lock_user_string(arg1)))
5842 goto efault;
5843 ret = get_errno(mkdir(p, arg2));
5844 unlock_user(p, arg1, 0);
5845 break;
5846#if defined(TARGET_NR_mkdirat289)
5847 case TARGET_NR_mkdirat289:
5848 if (!(p = lock_user_string(arg2)))
5849 goto efault;
5850 ret = get_errno(mkdirat(arg1, p, arg3));
5851 unlock_user(p, arg2, 0);
5852 break;
5853#endif
5854 case TARGET_NR_rmdir40:
5855 if (!(p = lock_user_string(arg1)))
5856 goto efault;
5857 ret = get_errno(rmdir(p));
5858 unlock_user(p, arg1, 0);
5859 break;
5860 case TARGET_NR_dup41:
5861 ret = get_errno(dup(arg1));
5862 break;
5863 case TARGET_NR_pipe42:
5864 ret = do_pipe(cpu_env, arg1, 0, 0);
5865 break;
5866#ifdef TARGET_NR_pipe2325
5867 case TARGET_NR_pipe2325:
5868 ret = do_pipe(cpu_env, arg1,
5869 target_to_host_bitmask(arg2, fcntl_flags_tbl), 1);
5870 break;
5871#endif
5872 case TARGET_NR_times43:
5873 {
5874 struct target_tms *tmsp;
5875 struct tms tms;
5876 ret = get_errno(times(&tms));
5877 if (arg1) {
5878 tmsp = lock_user(VERIFY_WRITE1, arg1, sizeof(struct target_tms), 0);
5879 if (!tmsp)
5880 goto efault;
5881 tmsp->tms_utime = tswapal(host_to_target_clock_t(tms.tms_utime));
5882 tmsp->tms_stime = tswapal(host_to_target_clock_t(tms.tms_stime));
5883 tmsp->tms_cutime = tswapal(host_to_target_clock_t(tms.tms_cutime));
5884 tmsp->tms_cstime = tswapal(host_to_target_clock_t(tms.tms_cstime));
5885 }
5886 if (!is_error(ret))
5887 ret = host_to_target_clock_t(ret);
5888 }
5889 break;
5890#ifdef TARGET_NR_prof
5891 case TARGET_NR_prof:
5892 goto unimplemented;
5893#endif
5894#ifdef TARGET_NR_signal48
5895 case TARGET_NR_signal48:
5896 goto unimplemented;
5897#endif
5898 case TARGET_NR_acct51:
5899 if (arg1 == 0) {
5900 ret = get_errno(acct(NULL((void*)0)));
5901 } else {
5902 if (!(p = lock_user_string(arg1)))
5903 goto efault;
5904 ret = get_errno(acct(path(p)));
5905 unlock_user(p, arg1, 0);
5906 }
5907 break;
5908#ifdef TARGET_NR_umount252
5909 case TARGET_NR_umount252:
5910 if (!(p = lock_user_string(arg1)))
5911 goto efault;
5912 ret = get_errno(umount2(p, arg2));
5913 unlock_user(p, arg1, 0);
5914 break;
5915#endif
5916#ifdef TARGET_NR_lock
5917 case TARGET_NR_lock:
5918 goto unimplemented;
5919#endif
5920 case TARGET_NR_ioctl54:
5921 ret = do_ioctl(arg1, arg2, arg3);
5922 break;
5923 case TARGET_NR_fcntl55:
5924 ret = do_fcntl(arg1, arg2, arg3);
5925 break;
5926#ifdef TARGET_NR_mpx
5927 case TARGET_NR_mpx:
5928 goto unimplemented;
5929#endif
5930 case TARGET_NR_setpgid57:
5931 ret = get_errno(setpgid(arg1, arg2));
5932 break;
5933#ifdef TARGET_NR_ulimit
5934 case TARGET_NR_ulimit:
5935 goto unimplemented;
5936#endif
5937#ifdef TARGET_NR_oldolduname
5938 case TARGET_NR_oldolduname:
5939 goto unimplemented;
5940#endif
5941 case TARGET_NR_umask60:
5942 ret = get_errno(umask(arg1));
5943 break;
5944 case TARGET_NR_chroot61:
5945 if (!(p = lock_user_string(arg1)))
5946 goto efault;
5947 ret = get_errno(chroot(p));
5948 unlock_user(p, arg1, 0);
5949 break;
5950 case TARGET_NR_ustat62:
5951 goto unimplemented;
5952 case TARGET_NR_dup263:
5953 ret = get_errno(dup2(arg1, arg2));
5954 break;
5955#if defined(CONFIG_DUP31) && defined(TARGET_NR_dup3326)
5956 case TARGET_NR_dup3326:
5957 ret = get_errno(dup3(arg1, arg2, arg3));
5958 break;
5959#endif
5960#ifdef TARGET_NR_getppid64 /* not on alpha */
5961 case TARGET_NR_getppid64:
5962 ret = get_errno(getppid());
5963 break;
5964#endif
5965 case TARGET_NR_getpgrp65:
5966 ret = get_errno(getpgrp());
5967 break;
5968 case TARGET_NR_setsid66:
5969 ret = get_errno(setsid());
5970 break;
5971#ifdef TARGET_NR_sigaction67
5972 case TARGET_NR_sigaction67:
5973 {
5974#if defined(TARGET_ALPHA)
5975 struct target_sigaction act, oact, *pact = 0;
5976 struct target_old_sigaction *old_act;
5977 if (arg2) {
5978 if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1)(old_act = lock_user(0, arg2, sizeof(*old_act), 1)))
5979 goto efault;
5980 act._sa_handler = old_act->_sa_handler;
5981 target_siginitset(&act.sa_mask, old_act->sa_mask);
5982 act.sa_flags = old_act->sa_flags;
5983 act.sa_restorer = 0;
5984 unlock_user_struct(old_act, arg2, 0)unlock_user(old_act, arg2, (0) ? sizeof(*old_act) : 0);
5985 pact = &act;
5986 }
5987 ret = get_errno(do_sigaction(arg1, pact, &oact));
5988 if (!is_error(ret) && arg3) {
5989 if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0)(old_act = lock_user(1, arg3, sizeof(*old_act), 0)))
5990 goto efault;
5991 old_act->_sa_handler = oact._sa_handler;
5992 old_act->sa_mask = oact.sa_mask.sig[0];
5993 old_act->sa_flags = oact.sa_flags;
5994 unlock_user_struct(old_act, arg3, 1)unlock_user(old_act, arg3, (1) ? sizeof(*old_act) : 0);
5995 }
5996#elif defined(TARGET_MIPS)
5997 struct target_sigaction act, oact, *pact, *old_act;
5998
5999 if (arg2) {
6000 if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1)(old_act = lock_user(0, arg2, sizeof(*old_act), 1)))
6001 goto efault;
6002 act._sa_handler = old_act->_sa_handler;
6003 target_siginitset(&act.sa_mask, old_act->sa_mask.sig[0]);
6004 act.sa_flags = old_act->sa_flags;
6005 unlock_user_struct(old_act, arg2, 0)unlock_user(old_act, arg2, (0) ? sizeof(*old_act) : 0);
6006 pact = &act;
6007 } else {
6008 pact = NULL((void*)0);
6009 }
6010
6011 ret = get_errno(do_sigaction(arg1, pact, &oact));
6012
6013 if (!is_error(ret) && arg3) {
6014 if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0)(old_act = lock_user(1, arg3, sizeof(*old_act), 0)))
6015 goto efault;
6016 old_act->_sa_handler = oact._sa_handler;
6017 old_act->sa_flags = oact.sa_flags;
6018 old_act->sa_mask.sig[0] = oact.sa_mask.sig[0];
6019 old_act->sa_mask.sig[1] = 0;
6020 old_act->sa_mask.sig[2] = 0;
6021 old_act->sa_mask.sig[3] = 0;
6022 unlock_user_struct(old_act, arg3, 1)unlock_user(old_act, arg3, (1) ? sizeof(*old_act) : 0);
6023 }
6024#else
6025 struct target_old_sigaction *old_act;
6026 struct target_sigaction act, oact, *pact;
6027 if (arg2) {
6028 if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1)(old_act = lock_user(0, arg2, sizeof(*old_act), 1)))
6029 goto efault;
6030 act._sa_handler = old_act->_sa_handler;
6031 target_siginitset(&act.sa_mask, old_act->sa_mask);
6032 act.sa_flags = old_act->sa_flags;
6033 act.sa_restorer = old_act->sa_restorer;
6034 unlock_user_struct(old_act, arg2, 0)unlock_user(old_act, arg2, (0) ? sizeof(*old_act) : 0);
6035 pact = &act;
6036 } else {
6037 pact = NULL((void*)0);
6038 }
6039 ret = get_errno(do_sigaction(arg1, pact, &oact));
6040 if (!is_error(ret) && arg3) {
6041 if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0)(old_act = lock_user(1, arg3, sizeof(*old_act), 0)))
6042 goto efault;
6043 old_act->_sa_handler = oact._sa_handler;
6044 old_act->sa_mask = oact.sa_mask.sig[0];
6045 old_act->sa_flags = oact.sa_flags;
6046 old_act->sa_restorer = oact.sa_restorer;
6047 unlock_user_struct(old_act, arg3, 1)unlock_user(old_act, arg3, (1) ? sizeof(*old_act) : 0);
6048 }
6049#endif
6050 }
6051 break;
6052#endif
6053 case TARGET_NR_rt_sigaction174:
6054 {
6055#if defined(TARGET_ALPHA)
6056 struct target_sigaction act, oact, *pact = 0;
6057 struct target_rt_sigaction *rt_act;
6058 /* ??? arg4 == sizeof(sigset_t). */
6059 if (arg2) {
6060 if (!lock_user_struct(VERIFY_READ, rt_act, arg2, 1)(rt_act = lock_user(0, arg2, sizeof(*rt_act), 1)))
6061 goto efault;
6062 act._sa_handler = rt_act->_sa_handler;
6063 act.sa_mask = rt_act->sa_mask;
6064 act.sa_flags = rt_act->sa_flags;
6065 act.sa_restorer = arg5;
6066 unlock_user_struct(rt_act, arg2, 0)unlock_user(rt_act, arg2, (0) ? sizeof(*rt_act) : 0);
6067 pact = &act;
6068 }
6069 ret = get_errno(do_sigaction(arg1, pact, &oact));
6070 if (!is_error(ret) && arg3) {
6071 if (!lock_user_struct(VERIFY_WRITE, rt_act, arg3, 0)(rt_act = lock_user(1, arg3, sizeof(*rt_act), 0)))
6072 goto efault;
6073 rt_act->_sa_handler = oact._sa_handler;
6074 rt_act->sa_mask = oact.sa_mask;
6075 rt_act->sa_flags = oact.sa_flags;
6076 unlock_user_struct(rt_act, arg3, 1)unlock_user(rt_act, arg3, (1) ? sizeof(*rt_act) : 0);
6077 }
6078#else
6079 struct target_sigaction *act;
6080 struct target_sigaction *oact;
6081
6082 if (arg2) {
6083 if (!lock_user_struct(VERIFY_READ, act, arg2, 1)(act = lock_user(0, arg2, sizeof(*act), 1)))
6084 goto efault;
6085 } else
6086 act = NULL((void*)0);
6087 if (arg3) {
6088 if (!lock_user_struct(VERIFY_WRITE, oact, arg3, 0)(oact = lock_user(1, arg3, sizeof(*oact), 0))) {
6089 ret = -TARGET_EFAULT14;
6090 goto rt_sigaction_fail;
6091 }
6092 } else
6093 oact = NULL((void*)0);
6094 ret = get_errno(do_sigaction(arg1, act, oact));
6095 rt_sigaction_fail:
6096 if (act)
6097 unlock_user_struct(act, arg2, 0)unlock_user(act, arg2, (0) ? sizeof(*act) : 0);
6098 if (oact)
6099 unlock_user_struct(oact, arg3, 1)unlock_user(oact, arg3, (1) ? sizeof(*oact) : 0);
6100#endif
6101 }
6102 break;
6103#ifdef TARGET_NR_sgetmask /* not on alpha */
6104 case TARGET_NR_sgetmask:
6105 {
6106 sigset_t cur_set;
6107 abi_ulong target_set;
6108 sigprocmask(0, NULL((void*)0), &cur_set);
6109 host_to_target_old_sigset(&target_set, &cur_set);
6110 ret = target_set;
6111 }
6112 break;
6113#endif
6114#ifdef TARGET_NR_ssetmask /* not on alpha */
6115 case TARGET_NR_ssetmask:
6116 {
6117 sigset_t set, oset, cur_set;
6118 abi_ulong target_set = arg1;
6119 sigprocmask(0, NULL((void*)0), &cur_set);
6120 target_to_host_old_sigset(&set, &target_set);
6121 sigorset(&set, &set, &cur_set);
6122 sigprocmask(SIG_SETMASK2, &set, &oset);
6123 host_to_target_old_sigset(&target_set, &oset);
6124 ret = target_set;
6125 }
6126 break;
6127#endif
6128#ifdef TARGET_NR_sigprocmask126
6129 case TARGET_NR_sigprocmask126:
6130 {
6131#if defined(TARGET_ALPHA)
6132 sigset_t set, oldset;
6133 abi_ulong mask;
6134 int how;
6135
6136 switch (arg1) {
6137 case TARGET_SIG_BLOCK0:
6138 how = SIG_BLOCK0;
6139 break;
6140 case TARGET_SIG_UNBLOCK1:
6141 how = SIG_UNBLOCK1;
6142 break;
6143 case TARGET_SIG_SETMASK2:
6144 how = SIG_SETMASK2;
6145 break;
6146 default:
6147 ret = -TARGET_EINVAL22;
6148 goto fail;
6149 }
6150 mask = arg2;
6151 target_to_host_old_sigset(&set, &mask);
6152
6153 ret = get_errno(sigprocmask(how, &set, &oldset));
6154 if (!is_error(ret)) {
6155 host_to_target_old_sigset(&mask, &oldset);
6156 ret = mask;
6157 ((CPUAlphaState *)cpu_env)->ir[IR_V0] = 0; /* force no error */
6158 }
6159#else
6160 sigset_t set, oldset, *set_ptr;
6161 int how;
6162
6163 if (arg2) {
6164 switch (arg1) {
6165 case TARGET_SIG_BLOCK0:
6166 how = SIG_BLOCK0;
6167 break;
6168 case TARGET_SIG_UNBLOCK1:
6169 how = SIG_UNBLOCK1;
6170 break;
6171 case TARGET_SIG_SETMASK2:
6172 how = SIG_SETMASK2;
6173 break;
6174 default:
6175 ret = -TARGET_EINVAL22;
6176 goto fail;
6177 }
6178 if (!(p = lock_user(VERIFY_READ0, arg2, sizeof(target_sigset_t), 1)))
6179 goto efault;
6180 target_to_host_old_sigset(&set, p);
6181 unlock_user(p, arg2, 0);
6182 set_ptr = &set;
6183 } else {
6184 how = 0;
6185 set_ptr = NULL((void*)0);
6186 }
6187 ret = get_errno(sigprocmask(how, set_ptr, &oldset));
6188 if (!is_error(ret) && arg3) {
6189 if (!(p = lock_user(VERIFY_WRITE1, arg3, sizeof(target_sigset_t), 0)))
6190 goto efault;
6191 host_to_target_old_sigset(p, &oldset);
6192 unlock_user(p, arg3, sizeof(target_sigset_t));
6193 }
6194#endif
6195 }
6196 break;
6197#endif
6198 case TARGET_NR_rt_sigprocmask175:
6199 {
6200 int how = arg1;
6201 sigset_t set, oldset, *set_ptr;
6202
6203 if (arg2) {
6204 switch(how) {
6205 case TARGET_SIG_BLOCK0:
6206 how = SIG_BLOCK0;
6207 break;
6208 case TARGET_SIG_UNBLOCK1:
6209 how = SIG_UNBLOCK1;
6210 break;
6211 case TARGET_SIG_SETMASK2:
6212 how = SIG_SETMASK2;
6213 break;
6214 default:
6215 ret = -TARGET_EINVAL22;
6216 goto fail;
6217 }
6218 if (!(p = lock_user(VERIFY_READ0, arg2, sizeof(target_sigset_t), 1)))
6219 goto efault;
6220 target_to_host_sigset(&set, p);
6221 unlock_user(p, arg2, 0);
6222 set_ptr = &set;
6223 } else {
6224 how = 0;
6225 set_ptr = NULL((void*)0);
6226 }
6227 ret = get_errno(sigprocmask(how, set_ptr, &oldset));
6228 if (!is_error(ret) && arg3) {
6229 if (!(p = lock_user(VERIFY_WRITE1, arg3, sizeof(target_sigset_t), 0)))
6230 goto efault;
6231 host_to_target_sigset(p, &oldset);
6232 unlock_user(p, arg3, sizeof(target_sigset_t));
6233 }
6234 }
6235 break;
6236#ifdef TARGET_NR_sigpending73
6237 case TARGET_NR_sigpending73:
6238 {
6239 sigset_t set;
6240 ret = get_errno(sigpending(&set));
6241 if (!is_error(ret)) {
6242 if (!(p = lock_user(VERIFY_WRITE1, arg1, sizeof(target_sigset_t), 0)))
6243 goto efault;
6244 host_to_target_old_sigset(p, &set);
6245 unlock_user(p, arg1, sizeof(target_sigset_t));
6246 }
6247 }
6248 break;
6249#endif
6250 case TARGET_NR_rt_sigpending176:
6251 {
6252 sigset_t set;
6253 ret = get_errno(sigpending(&set));
6254 if (!is_error(ret)) {
6255 if (!(p = lock_user(VERIFY_WRITE1, arg1, sizeof(target_sigset_t), 0)))
6256 goto efault;
6257 host_to_target_sigset(p, &set);
6258 unlock_user(p, arg1, sizeof(target_sigset_t));
6259 }
6260 }
6261 break;
6262#ifdef TARGET_NR_sigsuspend72
6263 case TARGET_NR_sigsuspend72:
6264 {
6265 sigset_t set;
6266#if defined(TARGET_ALPHA)
6267 abi_ulong mask = arg1;
6268 target_to_host_old_sigset(&set, &mask);
6269#else
6270 if (!(p = lock_user(VERIFY_READ0, arg1, sizeof(target_sigset_t), 1)))
6271 goto efault;
6272 target_to_host_old_sigset(&set, p);
6273 unlock_user(p, arg1, 0);
6274#endif
6275 ret = get_errno(sigsuspend(&set));
6276 }
6277 break;
6278#endif
6279 case TARGET_NR_rt_sigsuspend179:
6280 {
6281 sigset_t set;
6282 if (!(p = lock_user(VERIFY_READ0, arg1, sizeof(target_sigset_t), 1)))
6283 goto efault;
6284 target_to_host_sigset(&set, p);
6285 unlock_user(p, arg1, 0);
6286 ret = get_errno(sigsuspend(&set));
6287 }
6288 break;
6289 case TARGET_NR_rt_sigtimedwait177:
6290 {
6291 sigset_t set;
6292 struct timespec uts, *puts;
6293 siginfo_t uinfo;
6294
6295 if (!(p = lock_user(VERIFY_READ0, arg1, sizeof(target_sigset_t), 1)))
6296 goto efault;
6297 target_to_host_sigset(&set, p);
6298 unlock_user(p, arg1, 0);
6299 if (arg3) {
6300 puts = &uts;
6301 target_to_host_timespec(puts, arg3);
6302 } else {
6303 puts = NULL((void*)0);
6304 }
6305 ret = get_errno(sigtimedwait(&set, &uinfo, puts));
6306 if (!is_error(ret) && arg2) {
6307 if (!(p = lock_user(VERIFY_WRITE1, arg2, sizeof(target_siginfo_t), 0)))
6308 goto efault;
6309 host_to_target_siginfo(p, &uinfo);
6310 unlock_user(p, arg2, sizeof(target_siginfo_t));
6311 }
6312 }
6313 break;
6314 case TARGET_NR_rt_sigqueueinfo178:
6315 {
6316 siginfo_t uinfo;
6317 if (!(p = lock_user(VERIFY_READ0, arg3, sizeof(target_sigset_t), 1)))
6318 goto efault;
6319 target_to_host_siginfo(&uinfo, p);
6320 unlock_user(p, arg1, 0);
6321 ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, &uinfo));
6322 }
6323 break;
6324#ifdef TARGET_NR_sigreturn119
6325 case TARGET_NR_sigreturn119:
6326 /* NOTE: ret is eax, so not transcoding must be done */
6327 ret = do_sigreturn(cpu_env);
6328 break;
6329#endif
6330 case TARGET_NR_rt_sigreturn173:
6331 /* NOTE: ret is eax, so not transcoding must be done */
6332 ret = do_rt_sigreturn(cpu_env);
6333 break;
6334 case TARGET_NR_sethostname74:
6335 if (!(p = lock_user_string(arg1)))
6336 goto efault;
6337 ret = get_errno(sethostname(p, arg2));
6338 unlock_user(p, arg1, 0);
6339 break;
6340 case TARGET_NR_setrlimit75:
6341 {
6342 int resource = target_to_host_resource(arg1);
6343 struct target_rlimit *target_rlim;
6344 struct rlimit rlim;
6345 if (!lock_user_struct(VERIFY_READ, target_rlim, arg2, 1)(target_rlim = lock_user(0, arg2, sizeof(*target_rlim), 1)))
6346 goto efault;
6347 rlim.rlim_cur = target_to_host_rlim(target_rlim->rlim_cur);
6348 rlim.rlim_max = target_to_host_rlim(target_rlim->rlim_max);
6349 unlock_user_struct(target_rlim, arg2, 0)unlock_user(target_rlim, arg2, (0) ? sizeof(*target_rlim) : 0
)
;
6350 ret = get_errno(setrlimit(resource, &rlim));
6351 }
6352 break;
6353 case TARGET_NR_getrlimit191:
6354 {
6355 int resource = target_to_host_resource(arg1);
6356 struct target_rlimit *target_rlim;
6357 struct rlimit rlim;
6358
6359 ret = get_errno(getrlimit(resource, &rlim));
6360 if (!is_error(ret)) {
6361 if (!lock_user_struct(VERIFY_WRITE, target_rlim, arg2, 0)(target_rlim = lock_user(1, arg2, sizeof(*target_rlim), 0)))
6362 goto efault;
6363 target_rlim->rlim_cur = host_to_target_rlim(rlim.rlim_cur);
6364 target_rlim->rlim_max = host_to_target_rlim(rlim.rlim_max);
6365 unlock_user_struct(target_rlim, arg2, 1)unlock_user(target_rlim, arg2, (1) ? sizeof(*target_rlim) : 0
)
;
6366 }
6367 }
6368 break;
6369 case TARGET_NR_getrusage77:
6370 {
6371 struct rusage rusage;
6372 ret = get_errno(getrusage(arg1, &rusage));
6373 if (!is_error(ret)) {
6374 host_to_target_rusage(arg2, &rusage);
6375 }
6376 }
6377 break;
6378 case TARGET_NR_gettimeofday78:
6379 {
6380 struct timeval tv;
6381 ret = get_errno(gettimeofday(&tv, NULL((void*)0)));
6382 if (!is_error(ret)) {
6383 if (copy_to_user_timeval(arg1, &tv))
6384 goto efault;
6385 }
6386 }
6387 break;
6388 case TARGET_NR_settimeofday79:
6389 {
6390 struct timeval tv;
6391 if (copy_from_user_timeval(&tv, arg1))
6392 goto efault;
6393 ret = get_errno(settimeofday(&tv, NULL((void*)0)));
6394 }
6395 break;
6396#if defined(TARGET_NR_select142)
6397 case TARGET_NR_select142:
6398#if defined(TARGET_S390X1) || defined(TARGET_ALPHA)
6399 ret = do_select(arg1, arg2, arg3, arg4, arg5);
6400#else
6401 {
6402 struct target_sel_arg_struct *sel;
6403 abi_ulong inp, outp, exp, tvp;
6404 long nsel;
6405
6406 if (!lock_user_struct(VERIFY_READ, sel, arg1, 1)(sel = lock_user(0, arg1, sizeof(*sel), 1)))
6407 goto efault;
6408 nsel = tswapal(sel->n);
6409 inp = tswapal(sel->inp);
6410 outp = tswapal(sel->outp);
6411 exp = tswapal(sel->exp);
6412 tvp = tswapal(sel->tvp);
6413 unlock_user_struct(sel, arg1, 0)unlock_user(sel, arg1, (0) ? sizeof(*sel) : 0);
6414 ret = do_select(nsel, inp, outp, exp, tvp);
6415 }
6416#endif
6417 break;
6418#endif
6419#ifdef TARGET_NR_pselect6301
6420 case TARGET_NR_pselect6301:
6421 {
6422 abi_long rfd_addr, wfd_addr, efd_addr, n, ts_addr;
6423 fd_set rfds, wfds, efds;
6424 fd_set *rfds_ptr, *wfds_ptr, *efds_ptr;
6425 struct timespec ts, *ts_ptr;
6426
6427 /*
6428 * The 6th arg is actually two args smashed together,
6429 * so we cannot use the C library.
6430 */
6431 sigset_t set;
6432 struct {
6433 sigset_t *set;
6434 size_t size;
6435 } sig, *sig_ptr;
6436
6437 abi_ulong arg_sigset, arg_sigsize, *arg7;
6438 target_sigset_t *target_sigset;
6439
6440 n = arg1;
6441 rfd_addr = arg2;
6442 wfd_addr = arg3;
6443 efd_addr = arg4;
6444 ts_addr = arg5;
6445
6446 ret = copy_from_user_fdset_ptr(&rfds, &rfds_ptr, rfd_addr, n);
6447 if (ret) {
6448 goto fail;
6449 }
6450 ret = copy_from_user_fdset_ptr(&wfds, &wfds_ptr, wfd_addr, n);
6451 if (ret) {
6452 goto fail;
6453 }
6454 ret = copy_from_user_fdset_ptr(&efds, &efds_ptr, efd_addr, n);
6455 if (ret) {
6456 goto fail;
6457 }
6458
6459 /*
6460 * This takes a timespec, and not a timeval, so we cannot
6461 * use the do_select() helper ...
6462 */
6463 if (ts_addr) {
6464 if (target_to_host_timespec(&ts, ts_addr)) {
6465 goto efault;
6466 }
6467 ts_ptr = &ts;
6468 } else {
6469 ts_ptr = NULL((void*)0);
6470 }
6471
6472 /* Extract the two packed args for the sigset */
6473 if (arg6) {
6474 sig_ptr = &sig;
6475 sig.size = _NSIG65 / 8;
6476
6477 arg7 = lock_user(VERIFY_READ0, arg6, sizeof(*arg7) * 2, 1);
6478 if (!arg7) {
6479 goto efault;
6480 }
6481 arg_sigset = tswapal(arg7[0]);
6482 arg_sigsize = tswapal(arg7[1]);
6483 unlock_user(arg7, arg6, 0);
6484
6485 if (arg_sigset) {
6486 sig.set = &set;
6487 if (arg_sigsize != sizeof(*target_sigset)) {
6488 /* Like the kernel, we enforce correct size sigsets */
6489 ret = -TARGET_EINVAL22;
6490 goto fail;
6491 }
6492 target_sigset = lock_user(VERIFY_READ0, arg_sigset,
6493 sizeof(*target_sigset), 1);
6494 if (!target_sigset) {
6495 goto efault;
6496 }
6497 target_to_host_sigset(&set, target_sigset);
6498 unlock_user(target_sigset, arg_sigset, 0);
6499 } else {
6500 sig.set = NULL((void*)0);
6501 }
6502 } else {
6503 sig_ptr = NULL((void*)0);
6504 }
6505
6506 ret = get_errno(sys_pselect6(n, rfds_ptr, wfds_ptr, efds_ptr,
6507 ts_ptr, sig_ptr));
6508
6509 if (!is_error(ret)) {
6510 if (rfd_addr && copy_to_user_fdset(rfd_addr, &rfds, n))
6511 goto efault;
6512 if (wfd_addr && copy_to_user_fdset(wfd_addr, &wfds, n))
6513 goto efault;
6514 if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n))
6515 goto efault;
6516
6517 if (ts_addr && host_to_target_timespec(ts_addr, &ts))
6518 goto efault;
6519 }
6520 }
6521 break;
6522#endif
6523 case TARGET_NR_symlink83:
6524 {
6525 void *p2;
6526 p = lock_user_string(arg1);
6527 p2 = lock_user_string(arg2);
6528 if (!p || !p2)
6529 ret = -TARGET_EFAULT14;
6530 else
6531 ret = get_errno(symlink(p, p2));
6532 unlock_user(p2, arg2, 0);
6533 unlock_user(p, arg1, 0);
6534 }
6535 break;
6536#if defined(TARGET_NR_symlinkat297)
6537 case TARGET_NR_symlinkat297:
6538 {
6539 void *p2;
6540 p = lock_user_string(arg1);
6541 p2 = lock_user_string(arg3);
6542 if (!p || !p2)
6543 ret = -TARGET_EFAULT14;
6544 else
6545 ret = get_errno(symlinkat(p, arg2, p2));
6546 unlock_user(p2, arg3, 0);
6547 unlock_user(p, arg1, 0);
6548 }
6549 break;
6550#endif
6551#ifdef TARGET_NR_oldlstat
6552 case TARGET_NR_oldlstat:
6553 goto unimplemented;
6554#endif
6555 case TARGET_NR_readlink85:
6556 {
6557 void *p2;
6558 p = lock_user_string(arg1);
6559 p2 = lock_user(VERIFY_WRITE1, arg2, arg3, 0);
6560 if (!p || !p2) {
6561 ret = -TARGET_EFAULT14;
6562 } else if (is_proc_myself((const char *)p, "exe")) {
6563 char real[PATH_MAX4096], *temp;
6564 temp = realpath(exec_path, real);
6565 ret = temp == NULL((void*)0) ? get_errno(-1) : strlen(real) ;
6566 snprintf((char *)p2, arg3, "%s", real);
6567 } else {
6568 ret = get_errno(readlink(path(p), p2, arg3));
6569 }
6570 unlock_user(p2, arg2, ret);
6571 unlock_user(p, arg1, 0);
6572 }
6573 break;
6574#if defined(TARGET_NR_readlinkat298)
6575 case TARGET_NR_readlinkat298:
6576 {
6577 void *p2;
6578 p = lock_user_string(arg2);
6579 p2 = lock_user(VERIFY_WRITE1, arg3, arg4, 0);
6580 if (!p || !p2) {
6581 ret = -TARGET_EFAULT14;
6582 } else if (is_proc_myself((const char *)p, "exe")) {
6583 char real[PATH_MAX4096], *temp;
6584 temp = realpath(exec_path, real);
6585 ret = temp == NULL((void*)0) ? get_errno(-1) : strlen(real) ;
6586 snprintf((char *)p2, arg4, "%s", real);
6587 } else {
6588 ret = get_errno(readlinkat(arg1, path(p), p2, arg4));
6589 }
6590 unlock_user(p2, arg3, ret);
6591 unlock_user(p, arg2, 0);
6592 }
6593 break;
6594#endif
6595#ifdef TARGET_NR_uselib86
6596 case TARGET_NR_uselib86:
6597 goto unimplemented;
6598#endif
6599#ifdef TARGET_NR_swapon87
6600 case TARGET_NR_swapon87:
6601 if (!(p = lock_user_string(arg1)))
6602 goto efault;
6603 ret = get_errno(swapon(p, arg2));
6604 unlock_user(p, arg1, 0);
6605 break;
6606#endif
6607 case TARGET_NR_reboot88:
6608 if (arg3 == LINUX_REBOOT_CMD_RESTART20xA1B2C3D4) {
6609 /* arg4 must be ignored in all other cases */
6610 p = lock_user_string(arg4);
6611 if (!p) {
6612 goto efault;
6613 }
6614 ret = get_errno(reboot(arg1, arg2, arg3, p));
6615 unlock_user(p, arg4, 0);
6616 } else {
6617 ret = get_errno(reboot(arg1, arg2, arg3, NULL((void*)0)));
6618 }
6619 break;
6620#ifdef TARGET_NR_readdir89
6621 case TARGET_NR_readdir89:
6622 goto unimplemented;
6623#endif
6624#ifdef TARGET_NR_mmap90
6625 case TARGET_NR_mmap90:
6626#if (defined(TARGET_I386) && defined(TARGET_ABI32)) || \
6627 (defined(TARGET_ARM) && defined(TARGET_ABI32)) || \
6628 defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE) \
6629 || defined(TARGET_S390X1)
6630 {
6631 abi_ulong *v;
6632 abi_ulong v1, v2, v3, v4, v5, v6;
6633 if (!(v = lock_user(VERIFY_READ0, arg1, 6 * sizeof(abi_ulong), 1)))
6634 goto efault;
6635 v1 = tswapal(v[0]);
6636 v2 = tswapal(v[1]);
6637 v3 = tswapal(v[2]);
6638 v4 = tswapal(v[3]);
6639 v5 = tswapal(v[4]);
6640 v6 = tswapal(v[5]);
6641 unlock_user(v, arg1, 0);
6642 ret = get_errno(target_mmap(v1, v2, v3,
6643 target_to_host_bitmask(v4, mmap_flags_tbl),
6644 v5, v6));
6645 }
6646#else
6647 ret = get_errno(target_mmap(arg1, arg2, arg3,
6648 target_to_host_bitmask(arg4, mmap_flags_tbl),
6649 arg5,
6650 arg6));
6651#endif
6652 break;
6653#endif
6654#ifdef TARGET_NR_mmap2
6655 case TARGET_NR_mmap2:
6656#ifndef MMAP_SHIFT
6657#define MMAP_SHIFT 12
6658#endif
6659 ret = get_errno(target_mmap(arg1, arg2, arg3,
6660 target_to_host_bitmask(arg4, mmap_flags_tbl),
6661 arg5,
6662 arg6 << MMAP_SHIFT));
6663 break;
6664#endif
6665 case TARGET_NR_munmap91:
6666 ret = get_errno(target_munmap(arg1, arg2));
6667 break;
6668 case TARGET_NR_mprotect125:
6669 {
6670 TaskState *ts = ((CPUArchStatestruct CPUS390XState *)cpu_env)->opaque;
6671 /* Special hack to detect libc making the stack executable. */
6672 if ((arg3 & PROT_GROWSDOWN0x01000000)
6673 && arg1 >= ts->info->stack_limit
6674 && arg1 <= ts->info->start_stack) {
6675