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