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