root / linux-user / syscall.c @ 2c1794c4
History | View | Annotate | Download (81.6 kB)
1 | 31e31b8a | bellard | /*
|
---|---|---|---|
2 | 31e31b8a | bellard | * Linux syscalls
|
3 | 31e31b8a | bellard | *
|
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 | 31e31b8a | bellard | #include <sys/wait.h> |
32 | 31e31b8a | bellard | #include <sys/time.h> |
33 | 31e31b8a | bellard | #include <sys/stat.h> |
34 | 31e31b8a | bellard | #include <sys/mount.h> |
35 | 31e31b8a | bellard | #include <sys/resource.h> |
36 | 31e31b8a | bellard | #include <sys/mman.h> |
37 | 31e31b8a | bellard | #include <sys/swap.h> |
38 | 31e31b8a | bellard | #include <signal.h> |
39 | 31e31b8a | bellard | #include <sched.h> |
40 | 31e31b8a | bellard | #include <sys/socket.h> |
41 | 31e31b8a | bellard | #include <sys/uio.h> |
42 | 9de5e440 | bellard | #include <sys/poll.h> |
43 | 32f36bce | bellard | #include <sys/times.h> |
44 | 72f03900 | bellard | //#include <sys/user.h>
|
45 | 7854b056 | bellard | #include <netinet/tcp.h> |
46 | 31e31b8a | bellard | |
47 | 31e31b8a | bellard | #define termios host_termios
|
48 | 31e31b8a | bellard | #define winsize host_winsize
|
49 | 31e31b8a | bellard | #define termio host_termio
|
50 | 04369ff2 | bellard | #define sgttyb host_sgttyb /* same as target */ |
51 | 04369ff2 | bellard | #define tchars host_tchars /* same as target */ |
52 | 04369ff2 | bellard | #define ltchars host_ltchars /* same as target */ |
53 | 31e31b8a | bellard | |
54 | 31e31b8a | bellard | #include <linux/termios.h> |
55 | 31e31b8a | bellard | #include <linux/unistd.h> |
56 | 31e31b8a | bellard | #include <linux/utsname.h> |
57 | 31e31b8a | bellard | #include <linux/cdrom.h> |
58 | 31e31b8a | bellard | #include <linux/hdreg.h> |
59 | 31e31b8a | bellard | #include <linux/soundcard.h> |
60 | dab2ed99 | bellard | #include <linux/dirent.h> |
61 | 19b84f3c | bellard | #include <linux/kd.h> |
62 | 31e31b8a | bellard | |
63 | 3ef693a0 | bellard | #include "qemu.h" |
64 | 31e31b8a | bellard | |
65 | 72f03900 | bellard | //#define DEBUG
|
66 | 31e31b8a | bellard | |
67 | 1a9353d2 | bellard | //#include <linux/msdos_fs.h>
|
68 | 1a9353d2 | bellard | #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2]) |
69 | 1a9353d2 | bellard | #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2]) |
70 | 1a9353d2 | bellard | |
71 | 31e31b8a | bellard | #define __NR_sys_uname __NR_uname
|
72 | 72f03900 | bellard | #define __NR_sys_getcwd1 __NR_getcwd
|
73 | 31e31b8a | bellard | #define __NR_sys_statfs __NR_statfs
|
74 | 31e31b8a | bellard | #define __NR_sys_fstatfs __NR_fstatfs
|
75 | 72f03900 | bellard | #define __NR_sys_getdents __NR_getdents
|
76 | dab2ed99 | bellard | #define __NR_sys_getdents64 __NR_getdents64
|
77 | 66fb9763 | bellard | #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
|
78 | 31e31b8a | bellard | |
79 | 27725c1d | bellard | #if defined(__alpha__) || defined (__ia64__)
|
80 | 9af9eaaa | bellard | #define __NR__llseek __NR_lseek
|
81 | 9af9eaaa | bellard | #endif
|
82 | 9af9eaaa | bellard | |
83 | 72f03900 | bellard | #ifdef __NR_gettid
|
84 | 31e31b8a | bellard | _syscall0(int, gettid)
|
85 | 72f03900 | bellard | #else
|
86 | 72f03900 | bellard | static int gettid(void) { |
87 | 72f03900 | bellard | return -ENOSYS;
|
88 | 72f03900 | bellard | } |
89 | 72f03900 | bellard | #endif
|
90 | 31e31b8a | bellard | _syscall1(int,sys_uname,struct new_utsname *,buf) |
91 | 72f03900 | bellard | _syscall2(int,sys_getcwd1,char *,buf,size_t,size) |
92 | 72f03900 | bellard | _syscall3(int, sys_getdents, uint, fd, struct dirent *, dirp, uint, count); |
93 | dab2ed99 | bellard | _syscall3(int, sys_getdents64, uint, fd, struct dirent64 *, dirp, uint, count); |
94 | 31e31b8a | bellard | _syscall5(int, _llseek, uint, fd, ulong, hi, ulong, lo,
|
95 | 31e31b8a | bellard | loff_t *, res, uint, wh); |
96 | 72f03900 | bellard | _syscall2(int,sys_statfs,const char *,path,struct kernel_statfs *,buf) |
97 | 72f03900 | bellard | _syscall2(int,sys_fstatfs,int,fd,struct kernel_statfs *,buf) |
98 | 66fb9763 | bellard | _syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo) |
99 | ec86b0fb | bellard | #ifdef __NR_exit_group
|
100 | ec86b0fb | bellard | _syscall1(int,exit_group,int,error_code) |
101 | ec86b0fb | bellard | #endif
|
102 | 66fb9763 | bellard | |
103 | 66fb9763 | bellard | extern int personality(int); |
104 | 9de5e440 | bellard | extern int flock(int, int); |
105 | 9de5e440 | bellard | extern int setfsuid(int); |
106 | 9de5e440 | bellard | extern int setfsgid(int); |
107 | 5cd4393b | bellard | extern int setresuid(uid_t, uid_t, uid_t); |
108 | 5cd4393b | bellard | extern int getresuid(uid_t *, uid_t *, uid_t *); |
109 | 5cd4393b | bellard | extern int setresgid(gid_t, gid_t, gid_t); |
110 | 5cd4393b | bellard | extern int getresgid(gid_t *, gid_t *, gid_t *); |
111 | 19b84f3c | bellard | extern int setgroups(int, gid_t *); |
112 | 31e31b8a | bellard | |
113 | 31e31b8a | bellard | static inline long get_errno(long ret) |
114 | 31e31b8a | bellard | { |
115 | 31e31b8a | bellard | if (ret == -1) |
116 | 31e31b8a | bellard | return -errno;
|
117 | 31e31b8a | bellard | else
|
118 | 31e31b8a | bellard | return ret;
|
119 | 31e31b8a | bellard | } |
120 | 31e31b8a | bellard | |
121 | 31e31b8a | bellard | static inline int is_error(long ret) |
122 | 31e31b8a | bellard | { |
123 | 31e31b8a | bellard | return (unsigned long)ret >= (unsigned long)(-4096); |
124 | 31e31b8a | bellard | } |
125 | 31e31b8a | bellard | |
126 | 31e31b8a | bellard | static char *target_brk; |
127 | 31e31b8a | bellard | static char *target_original_brk; |
128 | 31e31b8a | bellard | |
129 | 31e31b8a | bellard | void target_set_brk(char *new_brk) |
130 | 31e31b8a | bellard | { |
131 | 31e31b8a | bellard | target_brk = new_brk; |
132 | 31e31b8a | bellard | target_original_brk = new_brk; |
133 | 31e31b8a | bellard | } |
134 | 31e31b8a | bellard | |
135 | 31e31b8a | bellard | static long do_brk(char *new_brk) |
136 | 31e31b8a | bellard | { |
137 | 31e31b8a | bellard | char *brk_page;
|
138 | 31e31b8a | bellard | long mapped_addr;
|
139 | 31e31b8a | bellard | int new_alloc_size;
|
140 | 31e31b8a | bellard | |
141 | 31e31b8a | bellard | if (!new_brk)
|
142 | 31e31b8a | bellard | return (long)target_brk; |
143 | 31e31b8a | bellard | if (new_brk < target_original_brk)
|
144 | 31e31b8a | bellard | return -ENOMEM;
|
145 | 31e31b8a | bellard | |
146 | 54936004 | bellard | brk_page = (char *)HOST_PAGE_ALIGN((unsigned long)target_brk); |
147 | 31e31b8a | bellard | |
148 | 31e31b8a | bellard | /* If the new brk is less than this, set it and we're done... */
|
149 | 31e31b8a | bellard | if (new_brk < brk_page) {
|
150 | 31e31b8a | bellard | target_brk = new_brk; |
151 | 31e31b8a | bellard | return (long)target_brk; |
152 | 31e31b8a | bellard | } |
153 | 31e31b8a | bellard | |
154 | 31e31b8a | bellard | /* We need to allocate more memory after the brk... */
|
155 | 54936004 | bellard | new_alloc_size = HOST_PAGE_ALIGN(new_brk - brk_page + 1);
|
156 | 54936004 | bellard | mapped_addr = get_errno(target_mmap((unsigned long)brk_page, new_alloc_size, |
157 | 54936004 | bellard | PROT_READ|PROT_WRITE, |
158 | 54936004 | bellard | MAP_ANON|MAP_FIXED|MAP_PRIVATE, 0, 0)); |
159 | 31e31b8a | bellard | if (is_error(mapped_addr)) {
|
160 | 31e31b8a | bellard | return mapped_addr;
|
161 | 31e31b8a | bellard | } else {
|
162 | 31e31b8a | bellard | target_brk = new_brk; |
163 | 31e31b8a | bellard | return (long)target_brk; |
164 | 31e31b8a | bellard | } |
165 | 31e31b8a | bellard | } |
166 | 31e31b8a | bellard | |
167 | 31e31b8a | bellard | static inline fd_set *target_to_host_fds(fd_set *fds, |
168 | 31e31b8a | bellard | target_long *target_fds, int n)
|
169 | 31e31b8a | bellard | { |
170 | 7854b056 | bellard | #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
|
171 | 31e31b8a | bellard | return (fd_set *)target_fds;
|
172 | 31e31b8a | bellard | #else
|
173 | 31e31b8a | bellard | int i, b;
|
174 | 31e31b8a | bellard | if (target_fds) {
|
175 | 31e31b8a | bellard | FD_ZERO(fds); |
176 | 31e31b8a | bellard | for(i = 0;i < n; i++) { |
177 | 31e31b8a | bellard | b = (tswapl(target_fds[i / TARGET_LONG_BITS]) >> |
178 | 31e31b8a | bellard | (i & (TARGET_LONG_BITS - 1))) & 1; |
179 | 31e31b8a | bellard | if (b)
|
180 | 31e31b8a | bellard | FD_SET(i, fds); |
181 | 31e31b8a | bellard | } |
182 | 31e31b8a | bellard | return fds;
|
183 | 31e31b8a | bellard | } else {
|
184 | 31e31b8a | bellard | return NULL; |
185 | 31e31b8a | bellard | } |
186 | 31e31b8a | bellard | #endif
|
187 | 31e31b8a | bellard | } |
188 | 31e31b8a | bellard | |
189 | 31e31b8a | bellard | static inline void host_to_target_fds(target_long *target_fds, |
190 | 31e31b8a | bellard | fd_set *fds, int n)
|
191 | 31e31b8a | bellard | { |
192 | 7854b056 | bellard | #if !defined(BSWAP_NEEDED) && !defined(WORDS_BIGENDIAN)
|
193 | 31e31b8a | bellard | /* nothing to do */
|
194 | 31e31b8a | bellard | #else
|
195 | 31e31b8a | bellard | int i, nw, j, k;
|
196 | 31e31b8a | bellard | target_long v; |
197 | 31e31b8a | bellard | |
198 | 31e31b8a | bellard | if (target_fds) {
|
199 | 31e31b8a | bellard | nw = n / TARGET_LONG_BITS; |
200 | 31e31b8a | bellard | k = 0;
|
201 | 31e31b8a | bellard | for(i = 0;i < nw; i++) { |
202 | 31e31b8a | bellard | v = 0;
|
203 | 31e31b8a | bellard | for(j = 0; j < TARGET_LONG_BITS; j++) { |
204 | 31e31b8a | bellard | v |= ((FD_ISSET(k, fds) != 0) << j);
|
205 | 31e31b8a | bellard | k++; |
206 | 31e31b8a | bellard | } |
207 | 31e31b8a | bellard | target_fds[i] = tswapl(v); |
208 | 31e31b8a | bellard | } |
209 | 31e31b8a | bellard | } |
210 | 31e31b8a | bellard | #endif
|
211 | 31e31b8a | bellard | } |
212 | 31e31b8a | bellard | |
213 | c596ed17 | bellard | #if defined(__alpha__)
|
214 | c596ed17 | bellard | #define HOST_HZ 1024 |
215 | c596ed17 | bellard | #else
|
216 | c596ed17 | bellard | #define HOST_HZ 100 |
217 | c596ed17 | bellard | #endif
|
218 | c596ed17 | bellard | |
219 | c596ed17 | bellard | static inline long host_to_target_clock_t(long ticks) |
220 | c596ed17 | bellard | { |
221 | c596ed17 | bellard | #if HOST_HZ == TARGET_HZ
|
222 | c596ed17 | bellard | return ticks;
|
223 | c596ed17 | bellard | #else
|
224 | c596ed17 | bellard | return ((int64_t)ticks * TARGET_HZ) / HOST_HZ;
|
225 | c596ed17 | bellard | #endif
|
226 | c596ed17 | bellard | } |
227 | c596ed17 | bellard | |
228 | b409186b | bellard | static inline void host_to_target_rusage(struct target_rusage *target_rusage, |
229 | b409186b | bellard | const struct rusage *rusage) |
230 | b409186b | bellard | { |
231 | b409186b | bellard | target_rusage->ru_utime.tv_sec = tswapl(rusage->ru_utime.tv_sec); |
232 | b409186b | bellard | target_rusage->ru_utime.tv_usec = tswapl(rusage->ru_utime.tv_usec); |
233 | b409186b | bellard | target_rusage->ru_stime.tv_sec = tswapl(rusage->ru_stime.tv_sec); |
234 | b409186b | bellard | target_rusage->ru_stime.tv_usec = tswapl(rusage->ru_stime.tv_usec); |
235 | b409186b | bellard | target_rusage->ru_maxrss = tswapl(rusage->ru_maxrss); |
236 | b409186b | bellard | target_rusage->ru_ixrss = tswapl(rusage->ru_ixrss); |
237 | b409186b | bellard | target_rusage->ru_idrss = tswapl(rusage->ru_idrss); |
238 | b409186b | bellard | target_rusage->ru_isrss = tswapl(rusage->ru_isrss); |
239 | b409186b | bellard | target_rusage->ru_minflt = tswapl(rusage->ru_minflt); |
240 | b409186b | bellard | target_rusage->ru_majflt = tswapl(rusage->ru_majflt); |
241 | b409186b | bellard | target_rusage->ru_nswap = tswapl(rusage->ru_nswap); |
242 | b409186b | bellard | target_rusage->ru_inblock = tswapl(rusage->ru_inblock); |
243 | b409186b | bellard | target_rusage->ru_oublock = tswapl(rusage->ru_oublock); |
244 | b409186b | bellard | target_rusage->ru_msgsnd = tswapl(rusage->ru_msgsnd); |
245 | b409186b | bellard | target_rusage->ru_msgrcv = tswapl(rusage->ru_msgrcv); |
246 | b409186b | bellard | target_rusage->ru_nsignals = tswapl(rusage->ru_nsignals); |
247 | b409186b | bellard | target_rusage->ru_nvcsw = tswapl(rusage->ru_nvcsw); |
248 | b409186b | bellard | target_rusage->ru_nivcsw = tswapl(rusage->ru_nivcsw); |
249 | b409186b | bellard | } |
250 | b409186b | bellard | |
251 | 66fb9763 | bellard | static inline void target_to_host_timeval(struct timeval *tv, |
252 | 5cd4393b | bellard | const struct target_timeval *target_tv) |
253 | 31e31b8a | bellard | { |
254 | 66fb9763 | bellard | tv->tv_sec = tswapl(target_tv->tv_sec); |
255 | 66fb9763 | bellard | tv->tv_usec = tswapl(target_tv->tv_usec); |
256 | 31e31b8a | bellard | } |
257 | 31e31b8a | bellard | |
258 | 66fb9763 | bellard | static inline void host_to_target_timeval(struct target_timeval *target_tv, |
259 | 5cd4393b | bellard | const struct timeval *tv) |
260 | 31e31b8a | bellard | { |
261 | 66fb9763 | bellard | target_tv->tv_sec = tswapl(tv->tv_sec); |
262 | 66fb9763 | bellard | target_tv->tv_usec = tswapl(tv->tv_usec); |
263 | 31e31b8a | bellard | } |
264 | 31e31b8a | bellard | |
265 | 31e31b8a | bellard | |
266 | 31e31b8a | bellard | static long do_select(long n, |
267 | 31e31b8a | bellard | target_long *target_rfds, target_long *target_wfds, |
268 | 31e31b8a | bellard | target_long *target_efds, struct target_timeval *target_tv)
|
269 | 31e31b8a | bellard | { |
270 | 31e31b8a | bellard | fd_set rfds, wfds, efds; |
271 | 31e31b8a | bellard | fd_set *rfds_ptr, *wfds_ptr, *efds_ptr; |
272 | 31e31b8a | bellard | struct timeval tv, *tv_ptr;
|
273 | 31e31b8a | bellard | long ret;
|
274 | 31e31b8a | bellard | |
275 | 31e31b8a | bellard | rfds_ptr = target_to_host_fds(&rfds, target_rfds, n); |
276 | 31e31b8a | bellard | wfds_ptr = target_to_host_fds(&wfds, target_wfds, n); |
277 | 31e31b8a | bellard | efds_ptr = target_to_host_fds(&efds, target_efds, n); |
278 | 31e31b8a | bellard | |
279 | 31e31b8a | bellard | if (target_tv) {
|
280 | 5cd4393b | bellard | target_to_host_timeval(&tv, target_tv); |
281 | 31e31b8a | bellard | tv_ptr = &tv; |
282 | 31e31b8a | bellard | } else {
|
283 | 31e31b8a | bellard | tv_ptr = NULL;
|
284 | 31e31b8a | bellard | } |
285 | 31e31b8a | bellard | ret = get_errno(select(n, rfds_ptr, wfds_ptr, efds_ptr, tv_ptr)); |
286 | 31e31b8a | bellard | if (!is_error(ret)) {
|
287 | 31e31b8a | bellard | host_to_target_fds(target_rfds, rfds_ptr, n); |
288 | 31e31b8a | bellard | host_to_target_fds(target_wfds, wfds_ptr, n); |
289 | 31e31b8a | bellard | host_to_target_fds(target_efds, efds_ptr, n); |
290 | 31e31b8a | bellard | |
291 | 31e31b8a | bellard | if (target_tv) {
|
292 | 5cd4393b | bellard | host_to_target_timeval(target_tv, &tv); |
293 | 31e31b8a | bellard | } |
294 | 31e31b8a | bellard | } |
295 | 31e31b8a | bellard | return ret;
|
296 | 31e31b8a | bellard | } |
297 | 31e31b8a | bellard | |
298 | 7854b056 | bellard | static inline void target_to_host_sockaddr(struct sockaddr *addr, |
299 | 7854b056 | bellard | struct target_sockaddr *target_addr,
|
300 | 7854b056 | bellard | socklen_t len) |
301 | 7854b056 | bellard | { |
302 | 7854b056 | bellard | memcpy(addr, target_addr, len); |
303 | 7854b056 | bellard | addr->sa_family = tswap16(target_addr->sa_family); |
304 | 7854b056 | bellard | } |
305 | 7854b056 | bellard | |
306 | 7854b056 | bellard | static inline void host_to_target_sockaddr(struct target_sockaddr *target_addr, |
307 | 7854b056 | bellard | struct sockaddr *addr,
|
308 | 7854b056 | bellard | socklen_t len) |
309 | 7854b056 | bellard | { |
310 | 7854b056 | bellard | memcpy(target_addr, addr, len); |
311 | 7854b056 | bellard | target_addr->sa_family = tswap16(addr->sa_family); |
312 | 7854b056 | bellard | } |
313 | 7854b056 | bellard | |
314 | 7854b056 | bellard | static inline void target_to_host_cmsg(struct msghdr *msgh, |
315 | 7854b056 | bellard | struct target_msghdr *target_msgh)
|
316 | 7854b056 | bellard | { |
317 | 7854b056 | bellard | struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh);
|
318 | 7854b056 | bellard | struct target_cmsghdr *target_cmsg = TARGET_CMSG_FIRSTHDR(target_msgh);
|
319 | 7854b056 | bellard | socklen_t space = 0;
|
320 | 7854b056 | bellard | |
321 | 7854b056 | bellard | while (cmsg && target_cmsg) {
|
322 | 7854b056 | bellard | void *data = CMSG_DATA(cmsg);
|
323 | 7854b056 | bellard | void *target_data = TARGET_CMSG_DATA(target_cmsg);
|
324 | 7854b056 | bellard | |
325 | 7854b056 | bellard | int len = tswapl(target_cmsg->cmsg_len)
|
326 | 7854b056 | bellard | - TARGET_CMSG_ALIGN(sizeof (struct target_cmsghdr)); |
327 | 7854b056 | bellard | |
328 | 7854b056 | bellard | space += CMSG_SPACE(len); |
329 | 7854b056 | bellard | if (space > msgh->msg_controllen) {
|
330 | 7854b056 | bellard | space -= CMSG_SPACE(len); |
331 | 7854b056 | bellard | gemu_log("Host cmsg overflow");
|
332 | 7854b056 | bellard | break;
|
333 | 7854b056 | bellard | } |
334 | 7854b056 | bellard | |
335 | 7854b056 | bellard | cmsg->cmsg_level = tswap32(target_cmsg->cmsg_level); |
336 | 7854b056 | bellard | cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type); |
337 | 7854b056 | bellard | cmsg->cmsg_len = CMSG_LEN(len); |
338 | 7854b056 | bellard | |
339 | 7854b056 | bellard | if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
|
340 | 7854b056 | bellard | gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
|
341 | 7854b056 | bellard | memcpy(data, target_data, len); |
342 | 7854b056 | bellard | } else {
|
343 | 7854b056 | bellard | int *fd = (int *)data; |
344 | 7854b056 | bellard | int *target_fd = (int *)target_data; |
345 | 7854b056 | bellard | int i, numfds = len / sizeof(int); |
346 | 7854b056 | bellard | |
347 | 7854b056 | bellard | for (i = 0; i < numfds; i++) |
348 | 7854b056 | bellard | fd[i] = tswap32(target_fd[i]); |
349 | 7854b056 | bellard | } |
350 | 7854b056 | bellard | |
351 | 7854b056 | bellard | cmsg = CMSG_NXTHDR(msgh, cmsg); |
352 | 7854b056 | bellard | target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg); |
353 | 7854b056 | bellard | } |
354 | 7854b056 | bellard | |
355 | 7854b056 | bellard | msgh->msg_controllen = space; |
356 | 7854b056 | bellard | } |
357 | 7854b056 | bellard | |
358 | 7854b056 | bellard | static inline void host_to_target_cmsg(struct target_msghdr *target_msgh, |
359 | 7854b056 | bellard | struct msghdr *msgh)
|
360 | 7854b056 | bellard | { |
361 | 7854b056 | bellard | struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh);
|
362 | 7854b056 | bellard | struct target_cmsghdr *target_cmsg = TARGET_CMSG_FIRSTHDR(target_msgh);
|
363 | 7854b056 | bellard | socklen_t space = 0;
|
364 | 7854b056 | bellard | |
365 | 7854b056 | bellard | while (cmsg && target_cmsg) {
|
366 | 7854b056 | bellard | void *data = CMSG_DATA(cmsg);
|
367 | 7854b056 | bellard | void *target_data = TARGET_CMSG_DATA(target_cmsg);
|
368 | 7854b056 | bellard | |
369 | 7854b056 | bellard | int len = cmsg->cmsg_len - CMSG_ALIGN(sizeof (struct cmsghdr)); |
370 | 7854b056 | bellard | |
371 | 7854b056 | bellard | space += TARGET_CMSG_SPACE(len); |
372 | 7854b056 | bellard | if (space > tswapl(target_msgh->msg_controllen)) {
|
373 | 7854b056 | bellard | space -= TARGET_CMSG_SPACE(len); |
374 | 7854b056 | bellard | gemu_log("Target cmsg overflow");
|
375 | 7854b056 | bellard | break;
|
376 | 7854b056 | bellard | } |
377 | 7854b056 | bellard | |
378 | 7854b056 | bellard | target_cmsg->cmsg_level = tswap32(cmsg->cmsg_level); |
379 | 7854b056 | bellard | target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type); |
380 | 7854b056 | bellard | target_cmsg->cmsg_len = tswapl(TARGET_CMSG_LEN(len)); |
381 | 7854b056 | bellard | |
382 | 7854b056 | bellard | if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
|
383 | 7854b056 | bellard | gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
|
384 | 7854b056 | bellard | memcpy(target_data, data, len); |
385 | 7854b056 | bellard | } else {
|
386 | 7854b056 | bellard | int *fd = (int *)data; |
387 | 7854b056 | bellard | int *target_fd = (int *)target_data; |
388 | 7854b056 | bellard | int i, numfds = len / sizeof(int); |
389 | 7854b056 | bellard | |
390 | 7854b056 | bellard | for (i = 0; i < numfds; i++) |
391 | 7854b056 | bellard | target_fd[i] = tswap32(fd[i]); |
392 | 7854b056 | bellard | } |
393 | 7854b056 | bellard | |
394 | 7854b056 | bellard | cmsg = CMSG_NXTHDR(msgh, cmsg); |
395 | 7854b056 | bellard | target_cmsg = TARGET_CMSG_NXTHDR(target_msgh, target_cmsg); |
396 | 7854b056 | bellard | } |
397 | 7854b056 | bellard | |
398 | 7854b056 | bellard | msgh->msg_controllen = tswapl(space); |
399 | 7854b056 | bellard | } |
400 | 7854b056 | bellard | |
401 | 7854b056 | bellard | static long do_setsockopt(int sockfd, int level, int optname, |
402 | 7854b056 | bellard | void *optval, socklen_t optlen)
|
403 | 7854b056 | bellard | { |
404 | 7854b056 | bellard | if (level == SOL_TCP) {
|
405 | 7854b056 | bellard | /* TCP options all take an 'int' value. */
|
406 | 7854b056 | bellard | int val;
|
407 | 7854b056 | bellard | |
408 | 7854b056 | bellard | if (optlen < sizeof(uint32_t)) |
409 | 7854b056 | bellard | return -EINVAL;
|
410 | 7854b056 | bellard | |
411 | 7854b056 | bellard | val = tswap32(*(uint32_t *)optval); |
412 | 7854b056 | bellard | return get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val))); |
413 | 7854b056 | bellard | } |
414 | 7854b056 | bellard | |
415 | 7854b056 | bellard | else if (level != SOL_SOCKET) { |
416 | 7854b056 | bellard | gemu_log("Unsupported setsockopt level: %d\n", level);
|
417 | 7854b056 | bellard | return -ENOSYS;
|
418 | 7854b056 | bellard | } |
419 | 7854b056 | bellard | |
420 | 7854b056 | bellard | switch (optname) {
|
421 | 7854b056 | bellard | /* Options with 'int' argument. */
|
422 | 7854b056 | bellard | case SO_DEBUG:
|
423 | 7854b056 | bellard | case SO_REUSEADDR:
|
424 | 7854b056 | bellard | case SO_TYPE:
|
425 | 7854b056 | bellard | case SO_ERROR:
|
426 | 7854b056 | bellard | case SO_DONTROUTE:
|
427 | 7854b056 | bellard | case SO_BROADCAST:
|
428 | 7854b056 | bellard | case SO_SNDBUF:
|
429 | 7854b056 | bellard | case SO_RCVBUF:
|
430 | 7854b056 | bellard | case SO_KEEPALIVE:
|
431 | 7854b056 | bellard | case SO_OOBINLINE:
|
432 | 7854b056 | bellard | case SO_NO_CHECK:
|
433 | 7854b056 | bellard | case SO_PRIORITY:
|
434 | 7854b056 | bellard | case SO_BSDCOMPAT:
|
435 | 7854b056 | bellard | case SO_PASSCRED:
|
436 | 7854b056 | bellard | case SO_TIMESTAMP:
|
437 | 7854b056 | bellard | case SO_RCVLOWAT:
|
438 | 7854b056 | bellard | case SO_RCVTIMEO:
|
439 | 7854b056 | bellard | case SO_SNDTIMEO:
|
440 | 7854b056 | bellard | { |
441 | 7854b056 | bellard | int val;
|
442 | 7854b056 | bellard | if (optlen < sizeof(uint32_t)) |
443 | 7854b056 | bellard | return -EINVAL;
|
444 | 7854b056 | bellard | val = tswap32(*(uint32_t *)optval); |
445 | 7854b056 | bellard | return get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val))); |
446 | 7854b056 | bellard | } |
447 | 7854b056 | bellard | |
448 | 7854b056 | bellard | default:
|
449 | 7854b056 | bellard | gemu_log("Unsupported setsockopt SOL_SOCKET option: %d\n", optname);
|
450 | 7854b056 | bellard | return -ENOSYS;
|
451 | 7854b056 | bellard | } |
452 | 7854b056 | bellard | } |
453 | 7854b056 | bellard | |
454 | 7854b056 | bellard | static long do_getsockopt(int sockfd, int level, int optname, |
455 | 7854b056 | bellard | void *optval, socklen_t *optlen)
|
456 | 7854b056 | bellard | { |
457 | 7854b056 | bellard | gemu_log("getsockopt not yet supported\n");
|
458 | 7854b056 | bellard | return -ENOSYS;
|
459 | 7854b056 | bellard | } |
460 | 7854b056 | bellard | |
461 | 7854b056 | bellard | static long do_socketcall(int num, int32_t *vptr) |
462 | 31e31b8a | bellard | { |
463 | 31e31b8a | bellard | long ret;
|
464 | 31e31b8a | bellard | |
465 | 31e31b8a | bellard | switch(num) {
|
466 | 31e31b8a | bellard | case SOCKOP_socket:
|
467 | 7854b056 | bellard | { |
468 | 7854b056 | bellard | int domain = tswap32(vptr[0]); |
469 | 7854b056 | bellard | int type = tswap32(vptr[1]); |
470 | 7854b056 | bellard | int protocol = tswap32(vptr[2]); |
471 | 7854b056 | bellard | |
472 | 7854b056 | bellard | ret = get_errno(socket(domain, type, protocol)); |
473 | 7854b056 | bellard | } |
474 | 31e31b8a | bellard | break;
|
475 | 31e31b8a | bellard | case SOCKOP_bind:
|
476 | 7854b056 | bellard | { |
477 | 7854b056 | bellard | int sockfd = tswap32(vptr[0]); |
478 | 7854b056 | bellard | void *target_addr = (void *)tswap32(vptr[1]); |
479 | 7854b056 | bellard | socklen_t addrlen = tswap32(vptr[2]);
|
480 | 7854b056 | bellard | void *addr = alloca(addrlen);
|
481 | 7854b056 | bellard | |
482 | 7854b056 | bellard | target_to_host_sockaddr(addr, target_addr, addrlen); |
483 | 7854b056 | bellard | ret = get_errno(bind(sockfd, addr, addrlen)); |
484 | 7854b056 | bellard | } |
485 | 31e31b8a | bellard | break;
|
486 | 31e31b8a | bellard | case SOCKOP_connect:
|
487 | 7854b056 | bellard | { |
488 | 7854b056 | bellard | int sockfd = tswap32(vptr[0]); |
489 | 7854b056 | bellard | void *target_addr = (void *)tswap32(vptr[1]); |
490 | 7854b056 | bellard | socklen_t addrlen = tswap32(vptr[2]);
|
491 | 7854b056 | bellard | void *addr = alloca(addrlen);
|
492 | 7854b056 | bellard | |
493 | 7854b056 | bellard | target_to_host_sockaddr(addr, target_addr, addrlen); |
494 | 7854b056 | bellard | ret = get_errno(connect(sockfd, addr, addrlen)); |
495 | 7854b056 | bellard | } |
496 | 31e31b8a | bellard | break;
|
497 | 31e31b8a | bellard | case SOCKOP_listen:
|
498 | 7854b056 | bellard | { |
499 | 7854b056 | bellard | int sockfd = tswap32(vptr[0]); |
500 | 7854b056 | bellard | int backlog = tswap32(vptr[1]); |
501 | 7854b056 | bellard | |
502 | 7854b056 | bellard | ret = get_errno(listen(sockfd, backlog)); |
503 | 7854b056 | bellard | } |
504 | 31e31b8a | bellard | break;
|
505 | 31e31b8a | bellard | case SOCKOP_accept:
|
506 | 31e31b8a | bellard | { |
507 | 7854b056 | bellard | int sockfd = tswap32(vptr[0]); |
508 | 7854b056 | bellard | void *target_addr = (void *)tswap32(vptr[1]); |
509 | 7854b056 | bellard | uint32_t *target_addrlen = (void *)tswap32(vptr[2]); |
510 | 7854b056 | bellard | socklen_t addrlen = tswap32(*target_addrlen); |
511 | 7854b056 | bellard | void *addr = alloca(addrlen);
|
512 | 7854b056 | bellard | |
513 | 7854b056 | bellard | ret = get_errno(accept(sockfd, addr, &addrlen)); |
514 | 7854b056 | bellard | if (!is_error(ret)) {
|
515 | 7854b056 | bellard | host_to_target_sockaddr(target_addr, addr, addrlen); |
516 | 7854b056 | bellard | *target_addrlen = tswap32(addrlen); |
517 | 7854b056 | bellard | } |
518 | 31e31b8a | bellard | } |
519 | 31e31b8a | bellard | break;
|
520 | 31e31b8a | bellard | case SOCKOP_getsockname:
|
521 | 31e31b8a | bellard | { |
522 | 7854b056 | bellard | int sockfd = tswap32(vptr[0]); |
523 | 7854b056 | bellard | void *target_addr = (void *)tswap32(vptr[1]); |
524 | 7854b056 | bellard | uint32_t *target_addrlen = (void *)tswap32(vptr[2]); |
525 | 7854b056 | bellard | socklen_t addrlen = tswap32(*target_addrlen); |
526 | 7854b056 | bellard | void *addr = alloca(addrlen);
|
527 | 7854b056 | bellard | |
528 | 7854b056 | bellard | ret = get_errno(getsockname(sockfd, addr, &addrlen)); |
529 | 7854b056 | bellard | if (!is_error(ret)) {
|
530 | 7854b056 | bellard | host_to_target_sockaddr(target_addr, addr, addrlen); |
531 | 7854b056 | bellard | *target_addrlen = tswap32(addrlen); |
532 | 7854b056 | bellard | } |
533 | 31e31b8a | bellard | } |
534 | 31e31b8a | bellard | break;
|
535 | 31e31b8a | bellard | case SOCKOP_getpeername:
|
536 | 31e31b8a | bellard | { |
537 | 7854b056 | bellard | int sockfd = tswap32(vptr[0]); |
538 | 7854b056 | bellard | void *target_addr = (void *)tswap32(vptr[1]); |
539 | 7854b056 | bellard | uint32_t *target_addrlen = (void *)tswap32(vptr[2]); |
540 | 7854b056 | bellard | socklen_t addrlen = tswap32(*target_addrlen); |
541 | 7854b056 | bellard | void *addr = alloca(addrlen);
|
542 | 7854b056 | bellard | |
543 | 7854b056 | bellard | ret = get_errno(getpeername(sockfd, addr, &addrlen)); |
544 | 7854b056 | bellard | if (!is_error(ret)) {
|
545 | 7854b056 | bellard | host_to_target_sockaddr(target_addr, addr, addrlen); |
546 | 7854b056 | bellard | *target_addrlen = tswap32(addrlen); |
547 | 7854b056 | bellard | } |
548 | 31e31b8a | bellard | } |
549 | 31e31b8a | bellard | break;
|
550 | 31e31b8a | bellard | case SOCKOP_socketpair:
|
551 | 31e31b8a | bellard | { |
552 | 7854b056 | bellard | int domain = tswap32(vptr[0]); |
553 | 7854b056 | bellard | int type = tswap32(vptr[1]); |
554 | 7854b056 | bellard | int protocol = tswap32(vptr[2]); |
555 | 7854b056 | bellard | int32_t *target_tab = (void *)tswap32(vptr[3]); |
556 | 31e31b8a | bellard | int tab[2]; |
557 | 7854b056 | bellard | |
558 | 7854b056 | bellard | ret = get_errno(socketpair(domain, type, protocol, tab)); |
559 | 31e31b8a | bellard | if (!is_error(ret)) {
|
560 | 31e31b8a | bellard | target_tab[0] = tswap32(tab[0]); |
561 | 31e31b8a | bellard | target_tab[1] = tswap32(tab[1]); |
562 | 31e31b8a | bellard | } |
563 | 31e31b8a | bellard | } |
564 | 31e31b8a | bellard | break;
|
565 | 31e31b8a | bellard | case SOCKOP_send:
|
566 | 7854b056 | bellard | { |
567 | 7854b056 | bellard | int sockfd = tswap32(vptr[0]); |
568 | 7854b056 | bellard | void *msg = (void *)tswap32(vptr[1]); |
569 | 7854b056 | bellard | size_t len = tswap32(vptr[2]);
|
570 | 7854b056 | bellard | int flags = tswap32(vptr[3]); |
571 | 7854b056 | bellard | |
572 | 7854b056 | bellard | ret = get_errno(send(sockfd, msg, len, flags)); |
573 | 7854b056 | bellard | } |
574 | 31e31b8a | bellard | break;
|
575 | 31e31b8a | bellard | case SOCKOP_recv:
|
576 | 7854b056 | bellard | { |
577 | 7854b056 | bellard | int sockfd = tswap32(vptr[0]); |
578 | 7854b056 | bellard | void *msg = (void *)tswap32(vptr[1]); |
579 | 7854b056 | bellard | size_t len = tswap32(vptr[2]);
|
580 | 7854b056 | bellard | int flags = tswap32(vptr[3]); |
581 | 7854b056 | bellard | |
582 | 7854b056 | bellard | ret = get_errno(recv(sockfd, msg, len, flags)); |
583 | 7854b056 | bellard | } |
584 | 31e31b8a | bellard | break;
|
585 | 31e31b8a | bellard | case SOCKOP_sendto:
|
586 | 7854b056 | bellard | { |
587 | 7854b056 | bellard | int sockfd = tswap32(vptr[0]); |
588 | 7854b056 | bellard | void *msg = (void *)tswap32(vptr[1]); |
589 | 7854b056 | bellard | size_t len = tswap32(vptr[2]);
|
590 | 7854b056 | bellard | int flags = tswap32(vptr[3]); |
591 | 7854b056 | bellard | void *target_addr = (void *)tswap32(vptr[4]); |
592 | 7854b056 | bellard | socklen_t addrlen = tswap32(vptr[5]);
|
593 | 7854b056 | bellard | void *addr = alloca(addrlen);
|
594 | 7854b056 | bellard | |
595 | 7854b056 | bellard | target_to_host_sockaddr(addr, target_addr, addrlen); |
596 | 7854b056 | bellard | ret = get_errno(sendto(sockfd, msg, len, flags, addr, addrlen)); |
597 | 7854b056 | bellard | } |
598 | 31e31b8a | bellard | break;
|
599 | 31e31b8a | bellard | case SOCKOP_recvfrom:
|
600 | 31e31b8a | bellard | { |
601 | 7854b056 | bellard | int sockfd = tswap32(vptr[0]); |
602 | 7854b056 | bellard | void *msg = (void *)tswap32(vptr[1]); |
603 | 7854b056 | bellard | size_t len = tswap32(vptr[2]);
|
604 | 7854b056 | bellard | int flags = tswap32(vptr[3]); |
605 | 7854b056 | bellard | void *target_addr = (void *)tswap32(vptr[4]); |
606 | 7854b056 | bellard | uint32_t *target_addrlen = (void *)tswap32(vptr[5]); |
607 | 7854b056 | bellard | socklen_t addrlen = tswap32(*target_addrlen); |
608 | 7854b056 | bellard | void *addr = alloca(addrlen);
|
609 | 7854b056 | bellard | |
610 | 7854b056 | bellard | ret = get_errno(recvfrom(sockfd, msg, len, flags, addr, &addrlen)); |
611 | 7854b056 | bellard | if (!is_error(ret)) {
|
612 | 7854b056 | bellard | host_to_target_sockaddr(target_addr, addr, addrlen); |
613 | 7854b056 | bellard | *target_addrlen = tswap32(addrlen); |
614 | 7854b056 | bellard | } |
615 | 31e31b8a | bellard | } |
616 | 31e31b8a | bellard | break;
|
617 | 31e31b8a | bellard | case SOCKOP_shutdown:
|
618 | 7854b056 | bellard | { |
619 | 7854b056 | bellard | int sockfd = tswap32(vptr[0]); |
620 | 7854b056 | bellard | int how = tswap32(vptr[1]); |
621 | 7854b056 | bellard | |
622 | 7854b056 | bellard | ret = get_errno(shutdown(sockfd, how)); |
623 | 7854b056 | bellard | } |
624 | 31e31b8a | bellard | break;
|
625 | 31e31b8a | bellard | case SOCKOP_sendmsg:
|
626 | 31e31b8a | bellard | case SOCKOP_recvmsg:
|
627 | 1a9353d2 | bellard | { |
628 | 1a9353d2 | bellard | int fd;
|
629 | 1a9353d2 | bellard | struct target_msghdr *msgp;
|
630 | 1a9353d2 | bellard | struct msghdr msg;
|
631 | 1a9353d2 | bellard | int flags, count, i;
|
632 | 1a9353d2 | bellard | struct iovec *vec;
|
633 | 1a9353d2 | bellard | struct target_iovec *target_vec;
|
634 | 1a9353d2 | bellard | |
635 | 7854b056 | bellard | msgp = (void *)tswap32(vptr[1]); |
636 | 1a9353d2 | bellard | msg.msg_name = (void *)tswapl(msgp->msg_name);
|
637 | 1a9353d2 | bellard | msg.msg_namelen = tswapl(msgp->msg_namelen); |
638 | 7854b056 | bellard | msg.msg_controllen = 2 * tswapl(msgp->msg_controllen);
|
639 | 7854b056 | bellard | msg.msg_control = alloca(msg.msg_controllen); |
640 | 1a9353d2 | bellard | msg.msg_flags = tswap32(msgp->msg_flags); |
641 | 1a9353d2 | bellard | |
642 | 1a9353d2 | bellard | count = tswapl(msgp->msg_iovlen); |
643 | 1a9353d2 | bellard | vec = alloca(count * sizeof(struct iovec)); |
644 | 1a9353d2 | bellard | target_vec = (void *)tswapl(msgp->msg_iov);
|
645 | 1a9353d2 | bellard | for(i = 0;i < count; i++) { |
646 | 1a9353d2 | bellard | vec[i].iov_base = (void *)tswapl(target_vec[i].iov_base);
|
647 | 1a9353d2 | bellard | vec[i].iov_len = tswapl(target_vec[i].iov_len); |
648 | 1a9353d2 | bellard | } |
649 | 1a9353d2 | bellard | msg.msg_iovlen = count; |
650 | 1a9353d2 | bellard | msg.msg_iov = vec; |
651 | 1a9353d2 | bellard | |
652 | 7854b056 | bellard | fd = tswap32(vptr[0]);
|
653 | 7854b056 | bellard | flags = tswap32(vptr[2]);
|
654 | 7854b056 | bellard | if (num == SOCKOP_sendmsg) {
|
655 | 7854b056 | bellard | target_to_host_cmsg(&msg, msgp); |
656 | 7854b056 | bellard | ret = get_errno(sendmsg(fd, &msg, flags)); |
657 | 7854b056 | bellard | } else {
|
658 | 7854b056 | bellard | ret = get_errno(recvmsg(fd, &msg, flags)); |
659 | 7854b056 | bellard | if (!is_error(ret))
|
660 | 7854b056 | bellard | host_to_target_cmsg(msgp, &msg); |
661 | 7854b056 | bellard | } |
662 | 1a9353d2 | bellard | } |
663 | 1a9353d2 | bellard | break;
|
664 | 31e31b8a | bellard | case SOCKOP_setsockopt:
|
665 | 7854b056 | bellard | { |
666 | 7854b056 | bellard | int sockfd = tswap32(vptr[0]); |
667 | 7854b056 | bellard | int level = tswap32(vptr[1]); |
668 | 7854b056 | bellard | int optname = tswap32(vptr[2]); |
669 | 7854b056 | bellard | void *optval = (void *)tswap32(vptr[3]); |
670 | 7854b056 | bellard | socklen_t optlen = tswap32(vptr[4]);
|
671 | 7854b056 | bellard | |
672 | 7854b056 | bellard | ret = do_setsockopt(sockfd, level, optname, optval, optlen); |
673 | 7854b056 | bellard | } |
674 | 7854b056 | bellard | break;
|
675 | 31e31b8a | bellard | case SOCKOP_getsockopt:
|
676 | 7854b056 | bellard | { |
677 | 7854b056 | bellard | int sockfd = tswap32(vptr[0]); |
678 | 7854b056 | bellard | int level = tswap32(vptr[1]); |
679 | 7854b056 | bellard | int optname = tswap32(vptr[2]); |
680 | 7854b056 | bellard | void *optval = (void *)tswap32(vptr[3]); |
681 | 7854b056 | bellard | uint32_t *target_len = (void *)tswap32(vptr[4]); |
682 | 7854b056 | bellard | socklen_t optlen = tswap32(*target_len); |
683 | 7854b056 | bellard | |
684 | 7854b056 | bellard | ret = do_getsockopt(sockfd, level, optname, optval, &optlen); |
685 | 7854b056 | bellard | if (!is_error(ret))
|
686 | 7854b056 | bellard | *target_len = tswap32(optlen); |
687 | 7854b056 | bellard | } |
688 | 7854b056 | bellard | break;
|
689 | 31e31b8a | bellard | default:
|
690 | 31e31b8a | bellard | gemu_log("Unsupported socketcall: %d\n", num);
|
691 | 31e31b8a | bellard | ret = -ENOSYS; |
692 | 31e31b8a | bellard | break;
|
693 | 31e31b8a | bellard | } |
694 | 31e31b8a | bellard | return ret;
|
695 | 31e31b8a | bellard | } |
696 | 31e31b8a | bellard | |
697 | 31e31b8a | bellard | /* kernel structure types definitions */
|
698 | 31e31b8a | bellard | #define IFNAMSIZ 16 |
699 | 31e31b8a | bellard | |
700 | 31e31b8a | bellard | #define STRUCT(name, list...) STRUCT_ ## name, |
701 | 31e31b8a | bellard | #define STRUCT_SPECIAL(name) STRUCT_ ## name, |
702 | 31e31b8a | bellard | enum {
|
703 | 31e31b8a | bellard | #include "syscall_types.h" |
704 | 31e31b8a | bellard | }; |
705 | 31e31b8a | bellard | #undef STRUCT
|
706 | 31e31b8a | bellard | #undef STRUCT_SPECIAL
|
707 | 31e31b8a | bellard | |
708 | 31e31b8a | bellard | #define STRUCT(name, list...) const argtype struct_ ## name ## _def[] = { list, TYPE_NULL }; |
709 | 31e31b8a | bellard | #define STRUCT_SPECIAL(name)
|
710 | 31e31b8a | bellard | #include "syscall_types.h" |
711 | 31e31b8a | bellard | #undef STRUCT
|
712 | 31e31b8a | bellard | #undef STRUCT_SPECIAL
|
713 | 31e31b8a | bellard | |
714 | 31e31b8a | bellard | typedef struct IOCTLEntry { |
715 | 2ab83ea7 | bellard | unsigned int target_cmd; |
716 | 2ab83ea7 | bellard | unsigned int host_cmd; |
717 | 31e31b8a | bellard | const char *name; |
718 | 31e31b8a | bellard | int access;
|
719 | 1a9353d2 | bellard | const argtype arg_type[5]; |
720 | 31e31b8a | bellard | } IOCTLEntry; |
721 | 31e31b8a | bellard | |
722 | 31e31b8a | bellard | #define IOC_R 0x0001 |
723 | 31e31b8a | bellard | #define IOC_W 0x0002 |
724 | 31e31b8a | bellard | #define IOC_RW (IOC_R | IOC_W)
|
725 | 31e31b8a | bellard | |
726 | 31e31b8a | bellard | #define MAX_STRUCT_SIZE 4096 |
727 | 31e31b8a | bellard | |
728 | 2ab83ea7 | bellard | IOCTLEntry ioctl_entries[] = { |
729 | 31e31b8a | bellard | #define IOCTL(cmd, access, types...) \
|
730 | 31e31b8a | bellard | { TARGET_ ## cmd, cmd, #cmd, access, { types } }, |
731 | 31e31b8a | bellard | #include "ioctls.h" |
732 | 31e31b8a | bellard | { 0, 0, }, |
733 | 31e31b8a | bellard | }; |
734 | 31e31b8a | bellard | |
735 | 31e31b8a | bellard | static long do_ioctl(long fd, long cmd, long arg) |
736 | 31e31b8a | bellard | { |
737 | 31e31b8a | bellard | const IOCTLEntry *ie;
|
738 | 31e31b8a | bellard | const argtype *arg_type;
|
739 | 31e31b8a | bellard | long ret;
|
740 | 31e31b8a | bellard | uint8_t buf_temp[MAX_STRUCT_SIZE]; |
741 | 31e31b8a | bellard | |
742 | 31e31b8a | bellard | ie = ioctl_entries; |
743 | 31e31b8a | bellard | for(;;) {
|
744 | 31e31b8a | bellard | if (ie->target_cmd == 0) { |
745 | 31e31b8a | bellard | gemu_log("Unsupported ioctl: cmd=0x%04lx\n", cmd);
|
746 | 31e31b8a | bellard | return -ENOSYS;
|
747 | 31e31b8a | bellard | } |
748 | 31e31b8a | bellard | if (ie->target_cmd == cmd)
|
749 | 31e31b8a | bellard | break;
|
750 | 31e31b8a | bellard | ie++; |
751 | 31e31b8a | bellard | } |
752 | 31e31b8a | bellard | arg_type = ie->arg_type; |
753 | 9de5e440 | bellard | #if defined(DEBUG)
|
754 | 72f03900 | bellard | gemu_log("ioctl: cmd=0x%04lx (%s)\n", cmd, ie->name);
|
755 | 72f03900 | bellard | #endif
|
756 | 31e31b8a | bellard | switch(arg_type[0]) { |
757 | 31e31b8a | bellard | case TYPE_NULL:
|
758 | 31e31b8a | bellard | /* no argument */
|
759 | 31e31b8a | bellard | ret = get_errno(ioctl(fd, ie->host_cmd)); |
760 | 31e31b8a | bellard | break;
|
761 | 31e31b8a | bellard | case TYPE_PTRVOID:
|
762 | 31e31b8a | bellard | case TYPE_INT:
|
763 | 31e31b8a | bellard | /* int argment */
|
764 | 31e31b8a | bellard | ret = get_errno(ioctl(fd, ie->host_cmd, arg)); |
765 | 31e31b8a | bellard | break;
|
766 | 31e31b8a | bellard | case TYPE_PTR:
|
767 | 31e31b8a | bellard | arg_type++; |
768 | 31e31b8a | bellard | switch(ie->access) {
|
769 | 31e31b8a | bellard | case IOC_R:
|
770 | 31e31b8a | bellard | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
771 | 31e31b8a | bellard | if (!is_error(ret)) {
|
772 | 31e31b8a | bellard | thunk_convert((void *)arg, buf_temp, arg_type, THUNK_TARGET);
|
773 | 31e31b8a | bellard | } |
774 | 31e31b8a | bellard | break;
|
775 | 31e31b8a | bellard | case IOC_W:
|
776 | 31e31b8a | bellard | thunk_convert(buf_temp, (void *)arg, arg_type, THUNK_HOST);
|
777 | 31e31b8a | bellard | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
778 | 31e31b8a | bellard | break;
|
779 | 31e31b8a | bellard | default:
|
780 | 31e31b8a | bellard | case IOC_RW:
|
781 | 31e31b8a | bellard | thunk_convert(buf_temp, (void *)arg, arg_type, THUNK_HOST);
|
782 | 31e31b8a | bellard | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
783 | 31e31b8a | bellard | if (!is_error(ret)) {
|
784 | 31e31b8a | bellard | thunk_convert((void *)arg, buf_temp, arg_type, THUNK_TARGET);
|
785 | 31e31b8a | bellard | } |
786 | 31e31b8a | bellard | break;
|
787 | 31e31b8a | bellard | } |
788 | 31e31b8a | bellard | break;
|
789 | 31e31b8a | bellard | default:
|
790 | 31e31b8a | bellard | gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", cmd, arg_type[0]); |
791 | 31e31b8a | bellard | ret = -ENOSYS; |
792 | 31e31b8a | bellard | break;
|
793 | 31e31b8a | bellard | } |
794 | 31e31b8a | bellard | return ret;
|
795 | 31e31b8a | bellard | } |
796 | 31e31b8a | bellard | |
797 | 31e31b8a | bellard | bitmask_transtbl iflag_tbl[] = { |
798 | 31e31b8a | bellard | { TARGET_IGNBRK, TARGET_IGNBRK, IGNBRK, IGNBRK }, |
799 | 31e31b8a | bellard | { TARGET_BRKINT, TARGET_BRKINT, BRKINT, BRKINT }, |
800 | 31e31b8a | bellard | { TARGET_IGNPAR, TARGET_IGNPAR, IGNPAR, IGNPAR }, |
801 | 31e31b8a | bellard | { TARGET_PARMRK, TARGET_PARMRK, PARMRK, PARMRK }, |
802 | 31e31b8a | bellard | { TARGET_INPCK, TARGET_INPCK, INPCK, INPCK }, |
803 | 31e31b8a | bellard | { TARGET_ISTRIP, TARGET_ISTRIP, ISTRIP, ISTRIP }, |
804 | 31e31b8a | bellard | { TARGET_INLCR, TARGET_INLCR, INLCR, INLCR }, |
805 | 31e31b8a | bellard | { TARGET_IGNCR, TARGET_IGNCR, IGNCR, IGNCR }, |
806 | 31e31b8a | bellard | { TARGET_ICRNL, TARGET_ICRNL, ICRNL, ICRNL }, |
807 | 31e31b8a | bellard | { TARGET_IUCLC, TARGET_IUCLC, IUCLC, IUCLC }, |
808 | 31e31b8a | bellard | { TARGET_IXON, TARGET_IXON, IXON, IXON }, |
809 | 31e31b8a | bellard | { TARGET_IXANY, TARGET_IXANY, IXANY, IXANY }, |
810 | 31e31b8a | bellard | { TARGET_IXOFF, TARGET_IXOFF, IXOFF, IXOFF }, |
811 | 31e31b8a | bellard | { TARGET_IMAXBEL, TARGET_IMAXBEL, IMAXBEL, IMAXBEL }, |
812 | 31e31b8a | bellard | { 0, 0, 0, 0 } |
813 | 31e31b8a | bellard | }; |
814 | 31e31b8a | bellard | |
815 | 31e31b8a | bellard | bitmask_transtbl oflag_tbl[] = { |
816 | 31e31b8a | bellard | { TARGET_OPOST, TARGET_OPOST, OPOST, OPOST }, |
817 | 31e31b8a | bellard | { TARGET_OLCUC, TARGET_OLCUC, OLCUC, OLCUC }, |
818 | 31e31b8a | bellard | { TARGET_ONLCR, TARGET_ONLCR, ONLCR, ONLCR }, |
819 | 31e31b8a | bellard | { TARGET_OCRNL, TARGET_OCRNL, OCRNL, OCRNL }, |
820 | 31e31b8a | bellard | { TARGET_ONOCR, TARGET_ONOCR, ONOCR, ONOCR }, |
821 | 31e31b8a | bellard | { TARGET_ONLRET, TARGET_ONLRET, ONLRET, ONLRET }, |
822 | 31e31b8a | bellard | { TARGET_OFILL, TARGET_OFILL, OFILL, OFILL }, |
823 | 31e31b8a | bellard | { TARGET_OFDEL, TARGET_OFDEL, OFDEL, OFDEL }, |
824 | 31e31b8a | bellard | { TARGET_NLDLY, TARGET_NL0, NLDLY, NL0 }, |
825 | 31e31b8a | bellard | { TARGET_NLDLY, TARGET_NL1, NLDLY, NL1 }, |
826 | 31e31b8a | bellard | { TARGET_CRDLY, TARGET_CR0, CRDLY, CR0 }, |
827 | 31e31b8a | bellard | { TARGET_CRDLY, TARGET_CR1, CRDLY, CR1 }, |
828 | 31e31b8a | bellard | { TARGET_CRDLY, TARGET_CR2, CRDLY, CR2 }, |
829 | 31e31b8a | bellard | { TARGET_CRDLY, TARGET_CR3, CRDLY, CR3 }, |
830 | 31e31b8a | bellard | { TARGET_TABDLY, TARGET_TAB0, TABDLY, TAB0 }, |
831 | 31e31b8a | bellard | { TARGET_TABDLY, TARGET_TAB1, TABDLY, TAB1 }, |
832 | 31e31b8a | bellard | { TARGET_TABDLY, TARGET_TAB2, TABDLY, TAB2 }, |
833 | 31e31b8a | bellard | { TARGET_TABDLY, TARGET_TAB3, TABDLY, TAB3 }, |
834 | 31e31b8a | bellard | { TARGET_BSDLY, TARGET_BS0, BSDLY, BS0 }, |
835 | 31e31b8a | bellard | { TARGET_BSDLY, TARGET_BS1, BSDLY, BS1 }, |
836 | 31e31b8a | bellard | { TARGET_VTDLY, TARGET_VT0, VTDLY, VT0 }, |
837 | 31e31b8a | bellard | { TARGET_VTDLY, TARGET_VT1, VTDLY, VT1 }, |
838 | 31e31b8a | bellard | { TARGET_FFDLY, TARGET_FF0, FFDLY, FF0 }, |
839 | 31e31b8a | bellard | { TARGET_FFDLY, TARGET_FF1, FFDLY, FF1 }, |
840 | 31e31b8a | bellard | { 0, 0, 0, 0 } |
841 | 31e31b8a | bellard | }; |
842 | 31e31b8a | bellard | |
843 | 31e31b8a | bellard | bitmask_transtbl cflag_tbl[] = { |
844 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B0, CBAUD, B0 }, |
845 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B50, CBAUD, B50 }, |
846 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B75, CBAUD, B75 }, |
847 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B110, CBAUD, B110 }, |
848 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B134, CBAUD, B134 }, |
849 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B150, CBAUD, B150 }, |
850 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B200, CBAUD, B200 }, |
851 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B300, CBAUD, B300 }, |
852 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B600, CBAUD, B600 }, |
853 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B1200, CBAUD, B1200 }, |
854 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B1800, CBAUD, B1800 }, |
855 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B2400, CBAUD, B2400 }, |
856 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B4800, CBAUD, B4800 }, |
857 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B9600, CBAUD, B9600 }, |
858 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B19200, CBAUD, B19200 }, |
859 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B38400, CBAUD, B38400 }, |
860 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B57600, CBAUD, B57600 }, |
861 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B115200, CBAUD, B115200 }, |
862 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B230400, CBAUD, B230400 }, |
863 | 31e31b8a | bellard | { TARGET_CBAUD, TARGET_B460800, CBAUD, B460800 }, |
864 | 31e31b8a | bellard | { TARGET_CSIZE, TARGET_CS5, CSIZE, CS5 }, |
865 | 31e31b8a | bellard | { TARGET_CSIZE, TARGET_CS6, CSIZE, CS6 }, |
866 | 31e31b8a | bellard | { TARGET_CSIZE, TARGET_CS7, CSIZE, CS7 }, |
867 | 31e31b8a | bellard | { TARGET_CSIZE, TARGET_CS8, CSIZE, CS8 }, |
868 | 31e31b8a | bellard | { TARGET_CSTOPB, TARGET_CSTOPB, CSTOPB, CSTOPB }, |
869 | 31e31b8a | bellard | { TARGET_CREAD, TARGET_CREAD, CREAD, CREAD }, |
870 | 31e31b8a | bellard | { TARGET_PARENB, TARGET_PARENB, PARENB, PARENB }, |
871 | 31e31b8a | bellard | { TARGET_PARODD, TARGET_PARODD, PARODD, PARODD }, |
872 | 31e31b8a | bellard | { TARGET_HUPCL, TARGET_HUPCL, HUPCL, HUPCL }, |
873 | 31e31b8a | bellard | { TARGET_CLOCAL, TARGET_CLOCAL, CLOCAL, CLOCAL }, |
874 | 31e31b8a | bellard | { TARGET_CRTSCTS, TARGET_CRTSCTS, CRTSCTS, CRTSCTS }, |
875 | 31e31b8a | bellard | { 0, 0, 0, 0 } |
876 | 31e31b8a | bellard | }; |
877 | 31e31b8a | bellard | |
878 | 31e31b8a | bellard | bitmask_transtbl lflag_tbl[] = { |
879 | 31e31b8a | bellard | { TARGET_ISIG, TARGET_ISIG, ISIG, ISIG }, |
880 | 31e31b8a | bellard | { TARGET_ICANON, TARGET_ICANON, ICANON, ICANON }, |
881 | 31e31b8a | bellard | { TARGET_XCASE, TARGET_XCASE, XCASE, XCASE }, |
882 | 31e31b8a | bellard | { TARGET_ECHO, TARGET_ECHO, ECHO, ECHO }, |
883 | 31e31b8a | bellard | { TARGET_ECHOE, TARGET_ECHOE, ECHOE, ECHOE }, |
884 | 31e31b8a | bellard | { TARGET_ECHOK, TARGET_ECHOK, ECHOK, ECHOK }, |
885 | 31e31b8a | bellard | { TARGET_ECHONL, TARGET_ECHONL, ECHONL, ECHONL }, |
886 | 31e31b8a | bellard | { TARGET_NOFLSH, TARGET_NOFLSH, NOFLSH, NOFLSH }, |
887 | 31e31b8a | bellard | { TARGET_TOSTOP, TARGET_TOSTOP, TOSTOP, TOSTOP }, |
888 | 31e31b8a | bellard | { TARGET_ECHOCTL, TARGET_ECHOCTL, ECHOCTL, ECHOCTL }, |
889 | 31e31b8a | bellard | { TARGET_ECHOPRT, TARGET_ECHOPRT, ECHOPRT, ECHOPRT }, |
890 | 31e31b8a | bellard | { TARGET_ECHOKE, TARGET_ECHOKE, ECHOKE, ECHOKE }, |
891 | 31e31b8a | bellard | { TARGET_FLUSHO, TARGET_FLUSHO, FLUSHO, FLUSHO }, |
892 | 31e31b8a | bellard | { TARGET_PENDIN, TARGET_PENDIN, PENDIN, PENDIN }, |
893 | 31e31b8a | bellard | { TARGET_IEXTEN, TARGET_IEXTEN, IEXTEN, IEXTEN }, |
894 | 31e31b8a | bellard | { 0, 0, 0, 0 } |
895 | 31e31b8a | bellard | }; |
896 | 31e31b8a | bellard | |
897 | 31e31b8a | bellard | static void target_to_host_termios (void *dst, const void *src) |
898 | 31e31b8a | bellard | { |
899 | 31e31b8a | bellard | struct host_termios *host = dst;
|
900 | 31e31b8a | bellard | const struct target_termios *target = src; |
901 | 31e31b8a | bellard | |
902 | 31e31b8a | bellard | host->c_iflag = |
903 | 31e31b8a | bellard | target_to_host_bitmask(tswap32(target->c_iflag), iflag_tbl); |
904 | 31e31b8a | bellard | host->c_oflag = |
905 | 31e31b8a | bellard | target_to_host_bitmask(tswap32(target->c_oflag), oflag_tbl); |
906 | 31e31b8a | bellard | host->c_cflag = |
907 | 31e31b8a | bellard | target_to_host_bitmask(tswap32(target->c_cflag), cflag_tbl); |
908 | 31e31b8a | bellard | host->c_lflag = |
909 | 31e31b8a | bellard | target_to_host_bitmask(tswap32(target->c_lflag), lflag_tbl); |
910 | 31e31b8a | bellard | host->c_line = target->c_line; |
911 | 31e31b8a | bellard | |
912 | 31e31b8a | bellard | host->c_cc[VINTR] = target->c_cc[TARGET_VINTR]; |
913 | 31e31b8a | bellard | host->c_cc[VQUIT] = target->c_cc[TARGET_VQUIT]; |
914 | 31e31b8a | bellard | host->c_cc[VERASE] = target->c_cc[TARGET_VERASE]; |
915 | 31e31b8a | bellard | host->c_cc[VKILL] = target->c_cc[TARGET_VKILL]; |
916 | 31e31b8a | bellard | host->c_cc[VEOF] = target->c_cc[TARGET_VEOF]; |
917 | 31e31b8a | bellard | host->c_cc[VTIME] = target->c_cc[TARGET_VTIME]; |
918 | 31e31b8a | bellard | host->c_cc[VMIN] = target->c_cc[TARGET_VMIN]; |
919 | 31e31b8a | bellard | host->c_cc[VSWTC] = target->c_cc[TARGET_VSWTC]; |
920 | 31e31b8a | bellard | host->c_cc[VSTART] = target->c_cc[TARGET_VSTART]; |
921 | 31e31b8a | bellard | host->c_cc[VSTOP] = target->c_cc[TARGET_VSTOP]; |
922 | 31e31b8a | bellard | host->c_cc[VSUSP] = target->c_cc[TARGET_VSUSP]; |
923 | 31e31b8a | bellard | host->c_cc[VEOL] = target->c_cc[TARGET_VEOL]; |
924 | 31e31b8a | bellard | host->c_cc[VREPRINT] = target->c_cc[TARGET_VREPRINT]; |
925 | 31e31b8a | bellard | host->c_cc[VDISCARD] = target->c_cc[TARGET_VDISCARD]; |
926 | 31e31b8a | bellard | host->c_cc[VWERASE] = target->c_cc[TARGET_VWERASE]; |
927 | 31e31b8a | bellard | host->c_cc[VLNEXT] = target->c_cc[TARGET_VLNEXT]; |
928 | 31e31b8a | bellard | host->c_cc[VEOL2] = target->c_cc[TARGET_VEOL2]; |
929 | 31e31b8a | bellard | } |
930 | 31e31b8a | bellard | |
931 | 31e31b8a | bellard | static void host_to_target_termios (void *dst, const void *src) |
932 | 31e31b8a | bellard | { |
933 | 31e31b8a | bellard | struct target_termios *target = dst;
|
934 | 31e31b8a | bellard | const struct host_termios *host = src; |
935 | 31e31b8a | bellard | |
936 | 31e31b8a | bellard | target->c_iflag = |
937 | 31e31b8a | bellard | tswap32(host_to_target_bitmask(host->c_iflag, iflag_tbl)); |
938 | 31e31b8a | bellard | target->c_oflag = |
939 | 31e31b8a | bellard | tswap32(host_to_target_bitmask(host->c_oflag, oflag_tbl)); |
940 | 31e31b8a | bellard | target->c_cflag = |
941 | 31e31b8a | bellard | tswap32(host_to_target_bitmask(host->c_cflag, cflag_tbl)); |
942 | 31e31b8a | bellard | target->c_lflag = |
943 | 31e31b8a | bellard | tswap32(host_to_target_bitmask(host->c_lflag, lflag_tbl)); |
944 | 31e31b8a | bellard | target->c_line = host->c_line; |
945 | 31e31b8a | bellard | |
946 | 31e31b8a | bellard | target->c_cc[TARGET_VINTR] = host->c_cc[VINTR]; |
947 | 31e31b8a | bellard | target->c_cc[TARGET_VQUIT] = host->c_cc[VQUIT]; |
948 | 31e31b8a | bellard | target->c_cc[TARGET_VERASE] = host->c_cc[VERASE]; |
949 | 31e31b8a | bellard | target->c_cc[TARGET_VKILL] = host->c_cc[VKILL]; |
950 | 31e31b8a | bellard | target->c_cc[TARGET_VEOF] = host->c_cc[VEOF]; |
951 | 31e31b8a | bellard | target->c_cc[TARGET_VTIME] = host->c_cc[VTIME]; |
952 | 31e31b8a | bellard | target->c_cc[TARGET_VMIN] = host->c_cc[VMIN]; |
953 | 31e31b8a | bellard | target->c_cc[TARGET_VSWTC] = host->c_cc[VSWTC]; |
954 | 31e31b8a | bellard | target->c_cc[TARGET_VSTART] = host->c_cc[VSTART]; |
955 | 31e31b8a | bellard | target->c_cc[TARGET_VSTOP] = host->c_cc[VSTOP]; |
956 | 31e31b8a | bellard | target->c_cc[TARGET_VSUSP] = host->c_cc[VSUSP]; |
957 | 31e31b8a | bellard | target->c_cc[TARGET_VEOL] = host->c_cc[VEOL]; |
958 | 31e31b8a | bellard | target->c_cc[TARGET_VREPRINT] = host->c_cc[VREPRINT]; |
959 | 31e31b8a | bellard | target->c_cc[TARGET_VDISCARD] = host->c_cc[VDISCARD]; |
960 | 31e31b8a | bellard | target->c_cc[TARGET_VWERASE] = host->c_cc[VWERASE]; |
961 | 31e31b8a | bellard | target->c_cc[TARGET_VLNEXT] = host->c_cc[VLNEXT]; |
962 | 31e31b8a | bellard | target->c_cc[TARGET_VEOL2] = host->c_cc[VEOL2]; |
963 | 31e31b8a | bellard | } |
964 | 31e31b8a | bellard | |
965 | 31e31b8a | bellard | StructEntry struct_termios_def = { |
966 | 31e31b8a | bellard | .convert = { host_to_target_termios, target_to_host_termios }, |
967 | 31e31b8a | bellard | .size = { sizeof(struct target_termios), sizeof(struct host_termios) }, |
968 | 31e31b8a | bellard | .align = { __alignof__(struct target_termios), __alignof__(struct host_termios) }, |
969 | 31e31b8a | bellard | }; |
970 | 31e31b8a | bellard | |
971 | 5286db75 | bellard | static bitmask_transtbl mmap_flags_tbl[] = {
|
972 | 5286db75 | bellard | { TARGET_MAP_SHARED, TARGET_MAP_SHARED, MAP_SHARED, MAP_SHARED }, |
973 | 5286db75 | bellard | { TARGET_MAP_PRIVATE, TARGET_MAP_PRIVATE, MAP_PRIVATE, MAP_PRIVATE }, |
974 | 5286db75 | bellard | { TARGET_MAP_FIXED, TARGET_MAP_FIXED, MAP_FIXED, MAP_FIXED }, |
975 | 5286db75 | bellard | { TARGET_MAP_ANONYMOUS, TARGET_MAP_ANONYMOUS, MAP_ANONYMOUS, MAP_ANONYMOUS }, |
976 | 5286db75 | bellard | { TARGET_MAP_GROWSDOWN, TARGET_MAP_GROWSDOWN, MAP_GROWSDOWN, MAP_GROWSDOWN }, |
977 | 5286db75 | bellard | { TARGET_MAP_DENYWRITE, TARGET_MAP_DENYWRITE, MAP_DENYWRITE, MAP_DENYWRITE }, |
978 | 5286db75 | bellard | { TARGET_MAP_EXECUTABLE, TARGET_MAP_EXECUTABLE, MAP_EXECUTABLE, MAP_EXECUTABLE }, |
979 | 5286db75 | bellard | { TARGET_MAP_LOCKED, TARGET_MAP_LOCKED, MAP_LOCKED, MAP_LOCKED }, |
980 | 5286db75 | bellard | { 0, 0, 0, 0 } |
981 | 5286db75 | bellard | }; |
982 | 5286db75 | bellard | |
983 | 2ab83ea7 | bellard | #if defined(TARGET_I386)
|
984 | 6dbad63e | bellard | |
985 | 6dbad63e | bellard | /* NOTE: there is really one LDT for all the threads */
|
986 | 6dbad63e | bellard | uint8_t *ldt_table; |
987 | 6dbad63e | bellard | |
988 | 6dbad63e | bellard | static int read_ldt(void *ptr, unsigned long bytecount) |
989 | 6dbad63e | bellard | { |
990 | 6dbad63e | bellard | int size;
|
991 | 6dbad63e | bellard | |
992 | 6dbad63e | bellard | if (!ldt_table)
|
993 | 6dbad63e | bellard | return 0; |
994 | 6dbad63e | bellard | size = TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE; |
995 | 6dbad63e | bellard | if (size > bytecount)
|
996 | 6dbad63e | bellard | size = bytecount; |
997 | 6dbad63e | bellard | memcpy(ptr, ldt_table, size); |
998 | 6dbad63e | bellard | return size;
|
999 | 6dbad63e | bellard | } |
1000 | 6dbad63e | bellard | |
1001 | 6dbad63e | bellard | /* XXX: add locking support */
|
1002 | 6dbad63e | bellard | static int write_ldt(CPUX86State *env, |
1003 | 6dbad63e | bellard | void *ptr, unsigned long bytecount, int oldmode) |
1004 | 6dbad63e | bellard | { |
1005 | 6dbad63e | bellard | struct target_modify_ldt_ldt_s ldt_info;
|
1006 | 6dbad63e | bellard | int seg_32bit, contents, read_exec_only, limit_in_pages;
|
1007 | 6dbad63e | bellard | int seg_not_present, useable;
|
1008 | 6dbad63e | bellard | uint32_t *lp, entry_1, entry_2; |
1009 | 6dbad63e | bellard | |
1010 | 6dbad63e | bellard | if (bytecount != sizeof(ldt_info)) |
1011 | 6dbad63e | bellard | return -EINVAL;
|
1012 | 6dbad63e | bellard | memcpy(&ldt_info, ptr, sizeof(ldt_info));
|
1013 | 6dbad63e | bellard | tswap32s(&ldt_info.entry_number); |
1014 | 6dbad63e | bellard | tswapls((long *)&ldt_info.base_addr);
|
1015 | 6dbad63e | bellard | tswap32s(&ldt_info.limit); |
1016 | 6dbad63e | bellard | tswap32s(&ldt_info.flags); |
1017 | 6dbad63e | bellard | |
1018 | 6dbad63e | bellard | if (ldt_info.entry_number >= TARGET_LDT_ENTRIES)
|
1019 | 6dbad63e | bellard | return -EINVAL;
|
1020 | 6dbad63e | bellard | seg_32bit = ldt_info.flags & 1;
|
1021 | 6dbad63e | bellard | contents = (ldt_info.flags >> 1) & 3; |
1022 | 6dbad63e | bellard | read_exec_only = (ldt_info.flags >> 3) & 1; |
1023 | 6dbad63e | bellard | limit_in_pages = (ldt_info.flags >> 4) & 1; |
1024 | 6dbad63e | bellard | seg_not_present = (ldt_info.flags >> 5) & 1; |
1025 | 6dbad63e | bellard | useable = (ldt_info.flags >> 6) & 1; |
1026 | 6dbad63e | bellard | |
1027 | 6dbad63e | bellard | if (contents == 3) { |
1028 | 6dbad63e | bellard | if (oldmode)
|
1029 | 6dbad63e | bellard | return -EINVAL;
|
1030 | 6dbad63e | bellard | if (seg_not_present == 0) |
1031 | 6dbad63e | bellard | return -EINVAL;
|
1032 | 6dbad63e | bellard | } |
1033 | 6dbad63e | bellard | /* allocate the LDT */
|
1034 | 6dbad63e | bellard | if (!ldt_table) {
|
1035 | 6dbad63e | bellard | ldt_table = malloc(TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE); |
1036 | 6dbad63e | bellard | if (!ldt_table)
|
1037 | 6dbad63e | bellard | return -ENOMEM;
|
1038 | 6dbad63e | bellard | memset(ldt_table, 0, TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE);
|
1039 | 6dbad63e | bellard | env->ldt.base = ldt_table; |
1040 | 6dbad63e | bellard | env->ldt.limit = 0xffff;
|
1041 | 6dbad63e | bellard | } |
1042 | 6dbad63e | bellard | |
1043 | 6dbad63e | bellard | /* NOTE: same code as Linux kernel */
|
1044 | 6dbad63e | bellard | /* Allow LDTs to be cleared by the user. */
|
1045 | 6dbad63e | bellard | if (ldt_info.base_addr == 0 && ldt_info.limit == 0) { |
1046 | 6dbad63e | bellard | if (oldmode ||
|
1047 | 6dbad63e | bellard | (contents == 0 &&
|
1048 | 6dbad63e | bellard | read_exec_only == 1 &&
|
1049 | 6dbad63e | bellard | seg_32bit == 0 &&
|
1050 | 6dbad63e | bellard | limit_in_pages == 0 &&
|
1051 | 6dbad63e | bellard | seg_not_present == 1 &&
|
1052 | 6dbad63e | bellard | useable == 0 )) {
|
1053 | 6dbad63e | bellard | entry_1 = 0;
|
1054 | 6dbad63e | bellard | entry_2 = 0;
|
1055 | 6dbad63e | bellard | goto install;
|
1056 | 6dbad63e | bellard | } |
1057 | 6dbad63e | bellard | } |
1058 | 6dbad63e | bellard | |
1059 | 6dbad63e | bellard | entry_1 = ((ldt_info.base_addr & 0x0000ffff) << 16) | |
1060 | 6dbad63e | bellard | (ldt_info.limit & 0x0ffff);
|
1061 | 6dbad63e | bellard | entry_2 = (ldt_info.base_addr & 0xff000000) |
|
1062 | 6dbad63e | bellard | ((ldt_info.base_addr & 0x00ff0000) >> 16) | |
1063 | 6dbad63e | bellard | (ldt_info.limit & 0xf0000) |
|
1064 | 6dbad63e | bellard | ((read_exec_only ^ 1) << 9) | |
1065 | 6dbad63e | bellard | (contents << 10) |
|
1066 | 6dbad63e | bellard | ((seg_not_present ^ 1) << 15) | |
1067 | 6dbad63e | bellard | (seg_32bit << 22) |
|
1068 | 6dbad63e | bellard | (limit_in_pages << 23) |
|
1069 | 6dbad63e | bellard | 0x7000;
|
1070 | 6dbad63e | bellard | if (!oldmode)
|
1071 | 6dbad63e | bellard | entry_2 |= (useable << 20);
|
1072 | 14ae3ba7 | bellard | |
1073 | 6dbad63e | bellard | /* Install the new entry ... */
|
1074 | 6dbad63e | bellard | install:
|
1075 | 6dbad63e | bellard | lp = (uint32_t *)(ldt_table + (ldt_info.entry_number << 3));
|
1076 | 6dbad63e | bellard | lp[0] = tswap32(entry_1);
|
1077 | 6dbad63e | bellard | lp[1] = tswap32(entry_2);
|
1078 | 6dbad63e | bellard | return 0; |
1079 | 6dbad63e | bellard | } |
1080 | 6dbad63e | bellard | |
1081 | 6dbad63e | bellard | /* specific and weird i386 syscalls */
|
1082 | 5cd4393b | bellard | int do_modify_ldt(CPUX86State *env, int func, void *ptr, unsigned long bytecount) |
1083 | 6dbad63e | bellard | { |
1084 | 6dbad63e | bellard | int ret = -ENOSYS;
|
1085 | 6dbad63e | bellard | |
1086 | 6dbad63e | bellard | switch (func) {
|
1087 | 6dbad63e | bellard | case 0: |
1088 | 6dbad63e | bellard | ret = read_ldt(ptr, bytecount); |
1089 | 6dbad63e | bellard | break;
|
1090 | 6dbad63e | bellard | case 1: |
1091 | 6dbad63e | bellard | ret = write_ldt(env, ptr, bytecount, 1);
|
1092 | 6dbad63e | bellard | break;
|
1093 | 6dbad63e | bellard | case 0x11: |
1094 | 6dbad63e | bellard | ret = write_ldt(env, ptr, bytecount, 0);
|
1095 | 6dbad63e | bellard | break;
|
1096 | 6dbad63e | bellard | } |
1097 | 6dbad63e | bellard | return ret;
|
1098 | 6dbad63e | bellard | } |
1099 | 1b6b029e | bellard | |
1100 | 2ab83ea7 | bellard | #endif /* defined(TARGET_I386) */ |
1101 | 2ab83ea7 | bellard | |
1102 | 1b6b029e | bellard | /* this stack is the equivalent of the kernel stack associated with a
|
1103 | 1b6b029e | bellard | thread/process */
|
1104 | 1b6b029e | bellard | #define NEW_STACK_SIZE 8192 |
1105 | 1b6b029e | bellard | |
1106 | 1b6b029e | bellard | static int clone_func(void *arg) |
1107 | 1b6b029e | bellard | { |
1108 | 2ab83ea7 | bellard | CPUState *env = arg; |
1109 | 1b6b029e | bellard | cpu_loop(env); |
1110 | 1b6b029e | bellard | /* never exits */
|
1111 | 1b6b029e | bellard | return 0; |
1112 | 1b6b029e | bellard | } |
1113 | 1b6b029e | bellard | |
1114 | 2ab83ea7 | bellard | int do_fork(CPUState *env, unsigned int flags, unsigned long newsp) |
1115 | 1b6b029e | bellard | { |
1116 | 1b6b029e | bellard | int ret;
|
1117 | 5cd4393b | bellard | TaskState *ts; |
1118 | 1b6b029e | bellard | uint8_t *new_stack; |
1119 | 2ab83ea7 | bellard | CPUState *new_env; |
1120 | 1b6b029e | bellard | |
1121 | 1b6b029e | bellard | if (flags & CLONE_VM) {
|
1122 | 5cd4393b | bellard | ts = malloc(sizeof(TaskState) + NEW_STACK_SIZE);
|
1123 | 5cd4393b | bellard | memset(ts, 0, sizeof(TaskState)); |
1124 | 5cd4393b | bellard | new_stack = ts->stack; |
1125 | 5cd4393b | bellard | ts->used = 1;
|
1126 | 5cd4393b | bellard | /* add in task state list */
|
1127 | 5cd4393b | bellard | ts->next = first_task_state; |
1128 | 5cd4393b | bellard | first_task_state = ts; |
1129 | 1b6b029e | bellard | /* we create a new CPU instance. */
|
1130 | 2ab83ea7 | bellard | new_env = cpu_init(); |
1131 | 2ab83ea7 | bellard | memcpy(new_env, env, sizeof(CPUState));
|
1132 | 2ab83ea7 | bellard | #if defined(TARGET_I386)
|
1133 | 2ab83ea7 | bellard | if (!newsp)
|
1134 | 2ab83ea7 | bellard | newsp = env->regs[R_ESP]; |
1135 | 1b6b029e | bellard | new_env->regs[R_ESP] = newsp; |
1136 | 1b6b029e | bellard | new_env->regs[R_EAX] = 0;
|
1137 | 2ab83ea7 | bellard | #elif defined(TARGET_ARM)
|
1138 | 2ab83ea7 | bellard | if (!newsp)
|
1139 | 2ab83ea7 | bellard | newsp = env->regs[13];
|
1140 | 2ab83ea7 | bellard | new_env->regs[13] = newsp;
|
1141 | 2ab83ea7 | bellard | new_env->regs[0] = 0; |
1142 | 2ab83ea7 | bellard | #else
|
1143 | 2ab83ea7 | bellard | #error unsupported target CPU
|
1144 | 2ab83ea7 | bellard | #endif
|
1145 | 5cd4393b | bellard | new_env->opaque = ts; |
1146 | 27725c1d | bellard | #ifdef __ia64__
|
1147 | 27725c1d | bellard | ret = clone2(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env); |
1148 | 27725c1d | bellard | #else
|
1149 | 27725c1d | bellard | ret = clone(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env); |
1150 | 27725c1d | bellard | #endif
|
1151 | 1b6b029e | bellard | } else {
|
1152 | 1b6b029e | bellard | /* if no CLONE_VM, we consider it is a fork */
|
1153 | 1b6b029e | bellard | if ((flags & ~CSIGNAL) != 0) |
1154 | 1b6b029e | bellard | return -EINVAL;
|
1155 | 1b6b029e | bellard | ret = fork(); |
1156 | 1b6b029e | bellard | } |
1157 | 1b6b029e | bellard | return ret;
|
1158 | 1b6b029e | bellard | } |
1159 | 1b6b029e | bellard | |
1160 | 7775e9ec | bellard | static long do_fcntl(int fd, int cmd, unsigned long arg) |
1161 | 7775e9ec | bellard | { |
1162 | 7775e9ec | bellard | struct flock fl;
|
1163 | 7775e9ec | bellard | struct target_flock *target_fl = (void *)arg; |
1164 | 7775e9ec | bellard | long ret;
|
1165 | 7775e9ec | bellard | |
1166 | 7775e9ec | bellard | switch(cmd) {
|
1167 | 7775e9ec | bellard | case TARGET_F_GETLK:
|
1168 | 7775e9ec | bellard | ret = fcntl(fd, cmd, &fl); |
1169 | 7775e9ec | bellard | if (ret == 0) { |
1170 | 7775e9ec | bellard | target_fl->l_type = tswap16(fl.l_type); |
1171 | 7775e9ec | bellard | target_fl->l_whence = tswap16(fl.l_whence); |
1172 | 7775e9ec | bellard | target_fl->l_start = tswapl(fl.l_start); |
1173 | 7775e9ec | bellard | target_fl->l_len = tswapl(fl.l_len); |
1174 | 7775e9ec | bellard | target_fl->l_pid = tswapl(fl.l_pid); |
1175 | 7775e9ec | bellard | } |
1176 | 7775e9ec | bellard | break;
|
1177 | 7775e9ec | bellard | |
1178 | 7775e9ec | bellard | case TARGET_F_SETLK:
|
1179 | 7775e9ec | bellard | case TARGET_F_SETLKW:
|
1180 | 7775e9ec | bellard | fl.l_type = tswap16(target_fl->l_type); |
1181 | 7775e9ec | bellard | fl.l_whence = tswap16(target_fl->l_whence); |
1182 | 7775e9ec | bellard | fl.l_start = tswapl(target_fl->l_start); |
1183 | 7775e9ec | bellard | fl.l_len = tswapl(target_fl->l_len); |
1184 | 7775e9ec | bellard | fl.l_pid = tswapl(target_fl->l_pid); |
1185 | 7775e9ec | bellard | ret = fcntl(fd, cmd, &fl); |
1186 | 7775e9ec | bellard | break;
|
1187 | 7775e9ec | bellard | |
1188 | 7775e9ec | bellard | case TARGET_F_GETLK64:
|
1189 | 7775e9ec | bellard | case TARGET_F_SETLK64:
|
1190 | 7775e9ec | bellard | case TARGET_F_SETLKW64:
|
1191 | 7775e9ec | bellard | ret = -1;
|
1192 | 7775e9ec | bellard | errno = EINVAL; |
1193 | 7775e9ec | bellard | break;
|
1194 | 7775e9ec | bellard | |
1195 | 7775e9ec | bellard | default:
|
1196 | 7775e9ec | bellard | ret = fcntl(fd, cmd, arg); |
1197 | 7775e9ec | bellard | break;
|
1198 | 7775e9ec | bellard | } |
1199 | 7775e9ec | bellard | return ret;
|
1200 | 7775e9ec | bellard | } |
1201 | 7775e9ec | bellard | |
1202 | 7775e9ec | bellard | |
1203 | b03c60f3 | bellard | #define high2lowuid(x) (x)
|
1204 | b03c60f3 | bellard | #define high2lowgid(x) (x)
|
1205 | b03c60f3 | bellard | #define low2highuid(x) (x)
|
1206 | b03c60f3 | bellard | #define low2highgid(x) (x)
|
1207 | 1b6b029e | bellard | |
1208 | 31e31b8a | bellard | void syscall_init(void) |
1209 | 31e31b8a | bellard | { |
1210 | 2ab83ea7 | bellard | IOCTLEntry *ie; |
1211 | 2ab83ea7 | bellard | const argtype *arg_type;
|
1212 | 2ab83ea7 | bellard | int size;
|
1213 | 2ab83ea7 | bellard | |
1214 | 31e31b8a | bellard | #define STRUCT(name, list...) thunk_register_struct(STRUCT_ ## name, #name, struct_ ## name ## _def); |
1215 | 31e31b8a | bellard | #define STRUCT_SPECIAL(name) thunk_register_struct_direct(STRUCT_ ## name, #name, &struct_ ## name ## _def); |
1216 | 31e31b8a | bellard | #include "syscall_types.h" |
1217 | 31e31b8a | bellard | #undef STRUCT
|
1218 | 31e31b8a | bellard | #undef STRUCT_SPECIAL
|
1219 | 2ab83ea7 | bellard | |
1220 | 2ab83ea7 | bellard | /* we patch the ioctl size if necessary. We rely on the fact that
|
1221 | 2ab83ea7 | bellard | no ioctl has all the bits at '1' in the size field */
|
1222 | 2ab83ea7 | bellard | ie = ioctl_entries; |
1223 | 2ab83ea7 | bellard | while (ie->target_cmd != 0) { |
1224 | 2ab83ea7 | bellard | if (((ie->target_cmd >> TARGET_IOC_SIZESHIFT) & TARGET_IOC_SIZEMASK) ==
|
1225 | 2ab83ea7 | bellard | TARGET_IOC_SIZEMASK) { |
1226 | 2ab83ea7 | bellard | arg_type = ie->arg_type; |
1227 | 2ab83ea7 | bellard | if (arg_type[0] != TYPE_PTR) { |
1228 | 2ab83ea7 | bellard | fprintf(stderr, "cannot patch size for ioctl 0x%x\n",
|
1229 | 2ab83ea7 | bellard | ie->target_cmd); |
1230 | 2ab83ea7 | bellard | exit(1);
|
1231 | 2ab83ea7 | bellard | } |
1232 | 2ab83ea7 | bellard | arg_type++; |
1233 | 2ab83ea7 | bellard | size = thunk_type_size(arg_type, 0);
|
1234 | 2ab83ea7 | bellard | ie->target_cmd = (ie->target_cmd & |
1235 | 2ab83ea7 | bellard | ~(TARGET_IOC_SIZEMASK << TARGET_IOC_SIZESHIFT)) | |
1236 | 2ab83ea7 | bellard | (size << TARGET_IOC_SIZESHIFT); |
1237 | 2ab83ea7 | bellard | } |
1238 | 2ab83ea7 | bellard | /* automatic consistency check if same arch */
|
1239 | 2ab83ea7 | bellard | #if defined(__i386__) && defined(TARGET_I386)
|
1240 | 2ab83ea7 | bellard | if (ie->target_cmd != ie->host_cmd) {
|
1241 | 2ab83ea7 | bellard | fprintf(stderr, "ERROR: ioctl: target=0x%x host=0x%x\n",
|
1242 | 2ab83ea7 | bellard | ie->target_cmd, ie->host_cmd); |
1243 | 2ab83ea7 | bellard | } |
1244 | 2ab83ea7 | bellard | #endif
|
1245 | 2ab83ea7 | bellard | ie++; |
1246 | 2ab83ea7 | bellard | } |
1247 | 31e31b8a | bellard | } |
1248 | 31e31b8a | bellard | |
1249 | 6dbad63e | bellard | long do_syscall(void *cpu_env, int num, long arg1, long arg2, long arg3, |
1250 | 31e31b8a | bellard | long arg4, long arg5, long arg6) |
1251 | 31e31b8a | bellard | { |
1252 | 31e31b8a | bellard | long ret;
|
1253 | 31e31b8a | bellard | struct stat st;
|
1254 | 72f03900 | bellard | struct kernel_statfs *stfs;
|
1255 | 31e31b8a | bellard | |
1256 | 72f03900 | bellard | #ifdef DEBUG
|
1257 | 72f03900 | bellard | gemu_log("syscall %d\n", num);
|
1258 | 72f03900 | bellard | #endif
|
1259 | 31e31b8a | bellard | switch(num) {
|
1260 | 31e31b8a | bellard | case TARGET_NR_exit:
|
1261 | 7d13299d | bellard | #ifdef HAVE_GPROF
|
1262 | 7d13299d | bellard | _mcleanup(); |
1263 | 7d13299d | bellard | #endif
|
1264 | 1b6b029e | bellard | /* XXX: should free thread stack and CPU env */
|
1265 | 31e31b8a | bellard | _exit(arg1); |
1266 | 31e31b8a | bellard | ret = 0; /* avoid warning */ |
1267 | 31e31b8a | bellard | break;
|
1268 | 31e31b8a | bellard | case TARGET_NR_read:
|
1269 | 206f0fa7 | bellard | page_unprotect_range((void *)arg2, arg3);
|
1270 | 31e31b8a | bellard | ret = get_errno(read(arg1, (void *)arg2, arg3));
|
1271 | 31e31b8a | bellard | break;
|
1272 | 31e31b8a | bellard | case TARGET_NR_write:
|
1273 | 31e31b8a | bellard | ret = get_errno(write(arg1, (void *)arg2, arg3));
|
1274 | 31e31b8a | bellard | break;
|
1275 | 31e31b8a | bellard | case TARGET_NR_open:
|
1276 | ec86b0fb | bellard | ret = get_errno(open(path((const char *)arg1), arg2, arg3)); |
1277 | 31e31b8a | bellard | break;
|
1278 | 31e31b8a | bellard | case TARGET_NR_close:
|
1279 | 31e31b8a | bellard | ret = get_errno(close(arg1)); |
1280 | 31e31b8a | bellard | break;
|
1281 | 31e31b8a | bellard | case TARGET_NR_brk:
|
1282 | 31e31b8a | bellard | ret = do_brk((char *)arg1);
|
1283 | 31e31b8a | bellard | break;
|
1284 | 31e31b8a | bellard | case TARGET_NR_fork:
|
1285 | 1b6b029e | bellard | ret = get_errno(do_fork(cpu_env, SIGCHLD, 0));
|
1286 | 31e31b8a | bellard | break;
|
1287 | 31e31b8a | bellard | case TARGET_NR_waitpid:
|
1288 | 31e31b8a | bellard | { |
1289 | 31e31b8a | bellard | int *status = (int *)arg2; |
1290 | 31e31b8a | bellard | ret = get_errno(waitpid(arg1, status, arg3)); |
1291 | 31e31b8a | bellard | if (!is_error(ret) && status)
|
1292 | 31e31b8a | bellard | tswapls((long *)&status);
|
1293 | 31e31b8a | bellard | } |
1294 | 31e31b8a | bellard | break;
|
1295 | 31e31b8a | bellard | case TARGET_NR_creat:
|
1296 | 31e31b8a | bellard | ret = get_errno(creat((const char *)arg1, arg2)); |
1297 | 31e31b8a | bellard | break;
|
1298 | 31e31b8a | bellard | case TARGET_NR_link:
|
1299 | 31e31b8a | bellard | ret = get_errno(link((const char *)arg1, (const char *)arg2)); |
1300 | 31e31b8a | bellard | break;
|
1301 | 31e31b8a | bellard | case TARGET_NR_unlink:
|
1302 | 31e31b8a | bellard | ret = get_errno(unlink((const char *)arg1)); |
1303 | 31e31b8a | bellard | break;
|
1304 | 31e31b8a | bellard | case TARGET_NR_execve:
|
1305 | 7854b056 | bellard | { |
1306 | 7854b056 | bellard | char **argp, **envp;
|
1307 | f7341ff4 | bellard | int argc, envc;
|
1308 | 7854b056 | bellard | uint32_t *p; |
1309 | 7854b056 | bellard | char **q;
|
1310 | 7854b056 | bellard | |
1311 | f7341ff4 | bellard | argc = 0;
|
1312 | 7854b056 | bellard | for (p = (void *)arg2; *p; p++) |
1313 | 7854b056 | bellard | argc++; |
1314 | f7341ff4 | bellard | envc = 0;
|
1315 | 7854b056 | bellard | for (p = (void *)arg3; *p; p++) |
1316 | 7854b056 | bellard | envc++; |
1317 | 7854b056 | bellard | |
1318 | f7341ff4 | bellard | argp = alloca((argc + 1) * sizeof(void *)); |
1319 | f7341ff4 | bellard | envp = alloca((envc + 1) * sizeof(void *)); |
1320 | 7854b056 | bellard | |
1321 | 7854b056 | bellard | for (p = (void *)arg2, q = argp; *p; p++, q++) |
1322 | 7854b056 | bellard | *q = (void *)tswap32(*p);
|
1323 | f7341ff4 | bellard | *q = NULL;
|
1324 | f7341ff4 | bellard | |
1325 | 7854b056 | bellard | for (p = (void *)arg3, q = envp; *p; p++, q++) |
1326 | 7854b056 | bellard | *q = (void *)tswap32(*p);
|
1327 | f7341ff4 | bellard | *q = NULL;
|
1328 | 7854b056 | bellard | |
1329 | 7854b056 | bellard | ret = get_errno(execve((const char *)arg1, argp, envp)); |
1330 | 7854b056 | bellard | } |
1331 | 31e31b8a | bellard | break;
|
1332 | 31e31b8a | bellard | case TARGET_NR_chdir:
|
1333 | 31e31b8a | bellard | ret = get_errno(chdir((const char *)arg1)); |
1334 | 31e31b8a | bellard | break;
|
1335 | 31e31b8a | bellard | case TARGET_NR_time:
|
1336 | 31e31b8a | bellard | { |
1337 | 31e31b8a | bellard | int *time_ptr = (int *)arg1; |
1338 | 31e31b8a | bellard | ret = get_errno(time((time_t *)time_ptr)); |
1339 | 31e31b8a | bellard | if (!is_error(ret) && time_ptr)
|
1340 | 31e31b8a | bellard | tswap32s(time_ptr); |
1341 | 31e31b8a | bellard | } |
1342 | 31e31b8a | bellard | break;
|
1343 | 31e31b8a | bellard | case TARGET_NR_mknod:
|
1344 | 31e31b8a | bellard | ret = get_errno(mknod((const char *)arg1, arg2, arg3)); |
1345 | 31e31b8a | bellard | break;
|
1346 | 31e31b8a | bellard | case TARGET_NR_chmod:
|
1347 | 31e31b8a | bellard | ret = get_errno(chmod((const char *)arg1, arg2)); |
1348 | 31e31b8a | bellard | break;
|
1349 | 31e31b8a | bellard | case TARGET_NR_lchown:
|
1350 | 31e31b8a | bellard | ret = get_errno(chown((const char *)arg1, arg2, arg3)); |
1351 | 31e31b8a | bellard | break;
|
1352 | 31e31b8a | bellard | case TARGET_NR_break:
|
1353 | 31e31b8a | bellard | goto unimplemented;
|
1354 | 31e31b8a | bellard | case TARGET_NR_oldstat:
|
1355 | 31e31b8a | bellard | goto unimplemented;
|
1356 | 31e31b8a | bellard | case TARGET_NR_lseek:
|
1357 | 31e31b8a | bellard | ret = get_errno(lseek(arg1, arg2, arg3)); |
1358 | 31e31b8a | bellard | break;
|
1359 | 31e31b8a | bellard | case TARGET_NR_getpid:
|
1360 | 31e31b8a | bellard | ret = get_errno(getpid()); |
1361 | 31e31b8a | bellard | break;
|
1362 | 31e31b8a | bellard | case TARGET_NR_mount:
|
1363 | 31e31b8a | bellard | /* need to look at the data field */
|
1364 | 31e31b8a | bellard | goto unimplemented;
|
1365 | 31e31b8a | bellard | case TARGET_NR_umount:
|
1366 | 31e31b8a | bellard | ret = get_errno(umount((const char *)arg1)); |
1367 | 31e31b8a | bellard | break;
|
1368 | 31e31b8a | bellard | case TARGET_NR_setuid:
|
1369 | b03c60f3 | bellard | ret = get_errno(setuid(low2highuid(arg1))); |
1370 | 31e31b8a | bellard | break;
|
1371 | 31e31b8a | bellard | case TARGET_NR_getuid:
|
1372 | 31e31b8a | bellard | ret = get_errno(getuid()); |
1373 | 31e31b8a | bellard | break;
|
1374 | 31e31b8a | bellard | case TARGET_NR_stime:
|
1375 | 31e31b8a | bellard | { |
1376 | 31e31b8a | bellard | int *time_ptr = (int *)arg1; |
1377 | 31e31b8a | bellard | if (time_ptr)
|
1378 | 31e31b8a | bellard | tswap32s(time_ptr); |
1379 | 31e31b8a | bellard | ret = get_errno(stime((time_t *)time_ptr)); |
1380 | 31e31b8a | bellard | } |
1381 | 31e31b8a | bellard | break;
|
1382 | 31e31b8a | bellard | case TARGET_NR_ptrace:
|
1383 | 31e31b8a | bellard | goto unimplemented;
|
1384 | 31e31b8a | bellard | case TARGET_NR_alarm:
|
1385 | 31e31b8a | bellard | ret = alarm(arg1); |
1386 | 31e31b8a | bellard | break;
|
1387 | 31e31b8a | bellard | case TARGET_NR_oldfstat:
|
1388 | 31e31b8a | bellard | goto unimplemented;
|
1389 | 31e31b8a | bellard | case TARGET_NR_pause:
|
1390 | 31e31b8a | bellard | ret = get_errno(pause()); |
1391 | 31e31b8a | bellard | break;
|
1392 | 31e31b8a | bellard | case TARGET_NR_utime:
|
1393 | 31e31b8a | bellard | goto unimplemented;
|
1394 | 31e31b8a | bellard | case TARGET_NR_stty:
|
1395 | 31e31b8a | bellard | goto unimplemented;
|
1396 | 31e31b8a | bellard | case TARGET_NR_gtty:
|
1397 | 31e31b8a | bellard | goto unimplemented;
|
1398 | 31e31b8a | bellard | case TARGET_NR_access:
|
1399 | 31e31b8a | bellard | ret = get_errno(access((const char *)arg1, arg2)); |
1400 | 31e31b8a | bellard | break;
|
1401 | 31e31b8a | bellard | case TARGET_NR_nice:
|
1402 | 31e31b8a | bellard | ret = get_errno(nice(arg1)); |
1403 | 31e31b8a | bellard | break;
|
1404 | 31e31b8a | bellard | case TARGET_NR_ftime:
|
1405 | 31e31b8a | bellard | goto unimplemented;
|
1406 | 31e31b8a | bellard | case TARGET_NR_sync:
|
1407 | 04369ff2 | bellard | sync(); |
1408 | 04369ff2 | bellard | ret = 0;
|
1409 | 31e31b8a | bellard | break;
|
1410 | 31e31b8a | bellard | case TARGET_NR_kill:
|
1411 | 31e31b8a | bellard | ret = get_errno(kill(arg1, arg2)); |
1412 | 31e31b8a | bellard | break;
|
1413 | 31e31b8a | bellard | case TARGET_NR_rename:
|
1414 | 31e31b8a | bellard | ret = get_errno(rename((const char *)arg1, (const char *)arg2)); |
1415 | 31e31b8a | bellard | break;
|
1416 | 31e31b8a | bellard | case TARGET_NR_mkdir:
|
1417 | 31e31b8a | bellard | ret = get_errno(mkdir((const char *)arg1, arg2)); |
1418 | 31e31b8a | bellard | break;
|
1419 | 31e31b8a | bellard | case TARGET_NR_rmdir:
|
1420 | 31e31b8a | bellard | ret = get_errno(rmdir((const char *)arg1)); |
1421 | 31e31b8a | bellard | break;
|
1422 | 31e31b8a | bellard | case TARGET_NR_dup:
|
1423 | 31e31b8a | bellard | ret = get_errno(dup(arg1)); |
1424 | 31e31b8a | bellard | break;
|
1425 | 31e31b8a | bellard | case TARGET_NR_pipe:
|
1426 | 31e31b8a | bellard | { |
1427 | 31e31b8a | bellard | int *pipe_ptr = (int *)arg1; |
1428 | 31e31b8a | bellard | ret = get_errno(pipe(pipe_ptr)); |
1429 | 31e31b8a | bellard | if (!is_error(ret)) {
|
1430 | 31e31b8a | bellard | tswap32s(&pipe_ptr[0]);
|
1431 | 31e31b8a | bellard | tswap32s(&pipe_ptr[1]);
|
1432 | 31e31b8a | bellard | } |
1433 | 31e31b8a | bellard | } |
1434 | 31e31b8a | bellard | break;
|
1435 | 31e31b8a | bellard | case TARGET_NR_times:
|
1436 | 32f36bce | bellard | { |
1437 | 32f36bce | bellard | struct target_tms *tmsp = (void *)arg1; |
1438 | 32f36bce | bellard | struct tms tms;
|
1439 | 32f36bce | bellard | ret = get_errno(times(&tms)); |
1440 | 32f36bce | bellard | if (tmsp) {
|
1441 | c596ed17 | bellard | tmsp->tms_utime = tswapl(host_to_target_clock_t(tms.tms_utime)); |
1442 | c596ed17 | bellard | tmsp->tms_stime = tswapl(host_to_target_clock_t(tms.tms_stime)); |
1443 | c596ed17 | bellard | tmsp->tms_cutime = tswapl(host_to_target_clock_t(tms.tms_cutime)); |
1444 | c596ed17 | bellard | tmsp->tms_cstime = tswapl(host_to_target_clock_t(tms.tms_cstime)); |
1445 | 32f36bce | bellard | } |
1446 | c596ed17 | bellard | if (!is_error(ret))
|
1447 | c596ed17 | bellard | ret = host_to_target_clock_t(ret); |
1448 | 32f36bce | bellard | } |
1449 | 32f36bce | bellard | break;
|
1450 | 31e31b8a | bellard | case TARGET_NR_prof:
|
1451 | 31e31b8a | bellard | goto unimplemented;
|
1452 | 31e31b8a | bellard | case TARGET_NR_setgid:
|
1453 | b03c60f3 | bellard | ret = get_errno(setgid(low2highgid(arg1))); |
1454 | 31e31b8a | bellard | break;
|
1455 | 31e31b8a | bellard | case TARGET_NR_getgid:
|
1456 | 31e31b8a | bellard | ret = get_errno(getgid()); |
1457 | 31e31b8a | bellard | break;
|
1458 | 31e31b8a | bellard | case TARGET_NR_signal:
|
1459 | 31e31b8a | bellard | goto unimplemented;
|
1460 | 31e31b8a | bellard | case TARGET_NR_geteuid:
|
1461 | 31e31b8a | bellard | ret = get_errno(geteuid()); |
1462 | 31e31b8a | bellard | break;
|
1463 | 31e31b8a | bellard | case TARGET_NR_getegid:
|
1464 | 31e31b8a | bellard | ret = get_errno(getegid()); |
1465 | 31e31b8a | bellard | break;
|
1466 | 31e31b8a | bellard | case TARGET_NR_acct:
|
1467 | 31e31b8a | bellard | goto unimplemented;
|
1468 | 31e31b8a | bellard | case TARGET_NR_umount2:
|
1469 | 31e31b8a | bellard | ret = get_errno(umount2((const char *)arg1, arg2)); |
1470 | 31e31b8a | bellard | break;
|
1471 | 31e31b8a | bellard | case TARGET_NR_lock:
|
1472 | 31e31b8a | bellard | goto unimplemented;
|
1473 | 31e31b8a | bellard | case TARGET_NR_ioctl:
|
1474 | 31e31b8a | bellard | ret = do_ioctl(arg1, arg2, arg3); |
1475 | 31e31b8a | bellard | break;
|
1476 | 31e31b8a | bellard | case TARGET_NR_fcntl:
|
1477 | 7775e9ec | bellard | ret = get_errno(do_fcntl(arg1, arg2, arg3)); |
1478 | 31e31b8a | bellard | break;
|
1479 | 31e31b8a | bellard | case TARGET_NR_mpx:
|
1480 | 31e31b8a | bellard | goto unimplemented;
|
1481 | 31e31b8a | bellard | case TARGET_NR_setpgid:
|
1482 | 31e31b8a | bellard | ret = get_errno(setpgid(arg1, arg2)); |
1483 | 31e31b8a | bellard | break;
|
1484 | 31e31b8a | bellard | case TARGET_NR_ulimit:
|
1485 | 31e31b8a | bellard | goto unimplemented;
|
1486 | 31e31b8a | bellard | case TARGET_NR_oldolduname:
|
1487 | 31e31b8a | bellard | goto unimplemented;
|
1488 | 31e31b8a | bellard | case TARGET_NR_umask:
|
1489 | 31e31b8a | bellard | ret = get_errno(umask(arg1)); |
1490 | 31e31b8a | bellard | break;
|
1491 | 31e31b8a | bellard | case TARGET_NR_chroot:
|
1492 | 31e31b8a | bellard | ret = get_errno(chroot((const char *)arg1)); |
1493 | 31e31b8a | bellard | break;
|
1494 | 31e31b8a | bellard | case TARGET_NR_ustat:
|
1495 | 31e31b8a | bellard | goto unimplemented;
|
1496 | 31e31b8a | bellard | case TARGET_NR_dup2:
|
1497 | 31e31b8a | bellard | ret = get_errno(dup2(arg1, arg2)); |
1498 | 31e31b8a | bellard | break;
|
1499 | 31e31b8a | bellard | case TARGET_NR_getppid:
|
1500 | 31e31b8a | bellard | ret = get_errno(getppid()); |
1501 | 31e31b8a | bellard | break;
|
1502 | 31e31b8a | bellard | case TARGET_NR_getpgrp:
|
1503 | 31e31b8a | bellard | ret = get_errno(getpgrp()); |
1504 | 31e31b8a | bellard | break;
|
1505 | 31e31b8a | bellard | case TARGET_NR_setsid:
|
1506 | 31e31b8a | bellard | ret = get_errno(setsid()); |
1507 | 31e31b8a | bellard | break;
|
1508 | 31e31b8a | bellard | case TARGET_NR_sigaction:
|
1509 | 31e31b8a | bellard | { |
1510 | 66fb9763 | bellard | struct target_old_sigaction *old_act = (void *)arg2; |
1511 | 66fb9763 | bellard | struct target_old_sigaction *old_oact = (void *)arg3; |
1512 | 66fb9763 | bellard | struct target_sigaction act, oact, *pact;
|
1513 | 66fb9763 | bellard | if (old_act) {
|
1514 | 66fb9763 | bellard | act._sa_handler = old_act->_sa_handler; |
1515 | 66fb9763 | bellard | target_siginitset(&act.sa_mask, old_act->sa_mask); |
1516 | 66fb9763 | bellard | act.sa_flags = old_act->sa_flags; |
1517 | 66fb9763 | bellard | act.sa_restorer = old_act->sa_restorer; |
1518 | 66fb9763 | bellard | pact = &act; |
1519 | 66fb9763 | bellard | } else {
|
1520 | 66fb9763 | bellard | pact = NULL;
|
1521 | 66fb9763 | bellard | } |
1522 | 66fb9763 | bellard | ret = get_errno(do_sigaction(arg1, pact, &oact)); |
1523 | 66fb9763 | bellard | if (!is_error(ret) && old_oact) {
|
1524 | 66fb9763 | bellard | old_oact->_sa_handler = oact._sa_handler; |
1525 | 66fb9763 | bellard | old_oact->sa_mask = oact.sa_mask.sig[0];
|
1526 | 66fb9763 | bellard | old_oact->sa_flags = oact.sa_flags; |
1527 | 66fb9763 | bellard | old_oact->sa_restorer = oact.sa_restorer; |
1528 | 66fb9763 | bellard | } |
1529 | 31e31b8a | bellard | } |
1530 | 31e31b8a | bellard | break;
|
1531 | 66fb9763 | bellard | case TARGET_NR_rt_sigaction:
|
1532 | 66fb9763 | bellard | ret = get_errno(do_sigaction(arg1, (void *)arg2, (void *)arg3)); |
1533 | 66fb9763 | bellard | break;
|
1534 | 31e31b8a | bellard | case TARGET_NR_sgetmask:
|
1535 | 66fb9763 | bellard | { |
1536 | 66fb9763 | bellard | sigset_t cur_set; |
1537 | 66fb9763 | bellard | target_ulong target_set; |
1538 | 66fb9763 | bellard | sigprocmask(0, NULL, &cur_set); |
1539 | 66fb9763 | bellard | host_to_target_old_sigset(&target_set, &cur_set); |
1540 | 66fb9763 | bellard | ret = target_set; |
1541 | 66fb9763 | bellard | } |
1542 | 66fb9763 | bellard | break;
|
1543 | 31e31b8a | bellard | case TARGET_NR_ssetmask:
|
1544 | 66fb9763 | bellard | { |
1545 | 66fb9763 | bellard | sigset_t set, oset, cur_set; |
1546 | 66fb9763 | bellard | target_ulong target_set = arg1; |
1547 | 66fb9763 | bellard | sigprocmask(0, NULL, &cur_set); |
1548 | 66fb9763 | bellard | target_to_host_old_sigset(&set, &target_set); |
1549 | 66fb9763 | bellard | sigorset(&set, &set, &cur_set); |
1550 | 66fb9763 | bellard | sigprocmask(SIG_SETMASK, &set, &oset); |
1551 | 66fb9763 | bellard | host_to_target_old_sigset(&target_set, &oset); |
1552 | 66fb9763 | bellard | ret = target_set; |
1553 | 66fb9763 | bellard | } |
1554 | 66fb9763 | bellard | break;
|
1555 | 66fb9763 | bellard | case TARGET_NR_sigprocmask:
|
1556 | 66fb9763 | bellard | { |
1557 | 66fb9763 | bellard | int how = arg1;
|
1558 | 66fb9763 | bellard | sigset_t set, oldset, *set_ptr; |
1559 | 66fb9763 | bellard | target_ulong *pset = (void *)arg2, *poldset = (void *)arg3; |
1560 | 66fb9763 | bellard | |
1561 | 66fb9763 | bellard | if (pset) {
|
1562 | 66fb9763 | bellard | switch(how) {
|
1563 | 66fb9763 | bellard | case TARGET_SIG_BLOCK:
|
1564 | 66fb9763 | bellard | how = SIG_BLOCK; |
1565 | 66fb9763 | bellard | break;
|
1566 | 66fb9763 | bellard | case TARGET_SIG_UNBLOCK:
|
1567 | 66fb9763 | bellard | how = SIG_UNBLOCK; |
1568 | 66fb9763 | bellard | break;
|
1569 | 66fb9763 | bellard | case TARGET_SIG_SETMASK:
|
1570 | 66fb9763 | bellard | how = SIG_SETMASK; |
1571 | 66fb9763 | bellard | break;
|
1572 | 66fb9763 | bellard | default:
|
1573 | 66fb9763 | bellard | ret = -EINVAL; |
1574 | 66fb9763 | bellard | goto fail;
|
1575 | 66fb9763 | bellard | } |
1576 | 66fb9763 | bellard | target_to_host_old_sigset(&set, pset); |
1577 | 66fb9763 | bellard | set_ptr = &set; |
1578 | 66fb9763 | bellard | } else {
|
1579 | 66fb9763 | bellard | how = 0;
|
1580 | 66fb9763 | bellard | set_ptr = NULL;
|
1581 | 66fb9763 | bellard | } |
1582 | 66fb9763 | bellard | ret = get_errno(sigprocmask(arg1, set_ptr, &oldset)); |
1583 | 66fb9763 | bellard | if (!is_error(ret) && poldset) {
|
1584 | 66fb9763 | bellard | host_to_target_old_sigset(poldset, &oldset); |
1585 | 66fb9763 | bellard | } |
1586 | 66fb9763 | bellard | } |
1587 | 66fb9763 | bellard | break;
|
1588 | 66fb9763 | bellard | case TARGET_NR_rt_sigprocmask:
|
1589 | 66fb9763 | bellard | { |
1590 | 66fb9763 | bellard | int how = arg1;
|
1591 | 66fb9763 | bellard | sigset_t set, oldset, *set_ptr; |
1592 | 66fb9763 | bellard | target_sigset_t *pset = (void *)arg2;
|
1593 | 66fb9763 | bellard | target_sigset_t *poldset = (void *)arg3;
|
1594 | 66fb9763 | bellard | |
1595 | 66fb9763 | bellard | if (pset) {
|
1596 | 66fb9763 | bellard | switch(how) {
|
1597 | 66fb9763 | bellard | case TARGET_SIG_BLOCK:
|
1598 | 66fb9763 | bellard | how = SIG_BLOCK; |
1599 | 66fb9763 | bellard | break;
|
1600 | 66fb9763 | bellard | case TARGET_SIG_UNBLOCK:
|
1601 | 66fb9763 | bellard | how = SIG_UNBLOCK; |
1602 | 66fb9763 | bellard | break;
|
1603 | 66fb9763 | bellard | case TARGET_SIG_SETMASK:
|
1604 | 66fb9763 | bellard | how = SIG_SETMASK; |
1605 | 66fb9763 | bellard | break;
|
1606 | 66fb9763 | bellard | default:
|
1607 | 66fb9763 | bellard | ret = -EINVAL; |
1608 | 66fb9763 | bellard | goto fail;
|
1609 | 66fb9763 | bellard | } |
1610 | 66fb9763 | bellard | target_to_host_sigset(&set, pset); |
1611 | 66fb9763 | bellard | set_ptr = &set; |
1612 | 66fb9763 | bellard | } else {
|
1613 | 66fb9763 | bellard | how = 0;
|
1614 | 66fb9763 | bellard | set_ptr = NULL;
|
1615 | 66fb9763 | bellard | } |
1616 | 66fb9763 | bellard | ret = get_errno(sigprocmask(how, set_ptr, &oldset)); |
1617 | 66fb9763 | bellard | if (!is_error(ret) && poldset) {
|
1618 | 66fb9763 | bellard | host_to_target_sigset(poldset, &oldset); |
1619 | 66fb9763 | bellard | } |
1620 | 66fb9763 | bellard | } |
1621 | 66fb9763 | bellard | break;
|
1622 | 66fb9763 | bellard | case TARGET_NR_sigpending:
|
1623 | 66fb9763 | bellard | { |
1624 | 66fb9763 | bellard | sigset_t set; |
1625 | 66fb9763 | bellard | ret = get_errno(sigpending(&set)); |
1626 | 66fb9763 | bellard | if (!is_error(ret)) {
|
1627 | 66fb9763 | bellard | host_to_target_old_sigset((target_ulong *)arg1, &set); |
1628 | 66fb9763 | bellard | } |
1629 | 66fb9763 | bellard | } |
1630 | 66fb9763 | bellard | break;
|
1631 | 66fb9763 | bellard | case TARGET_NR_rt_sigpending:
|
1632 | 66fb9763 | bellard | { |
1633 | 66fb9763 | bellard | sigset_t set; |
1634 | 66fb9763 | bellard | ret = get_errno(sigpending(&set)); |
1635 | 66fb9763 | bellard | if (!is_error(ret)) {
|
1636 | 66fb9763 | bellard | host_to_target_sigset((target_sigset_t *)arg1, &set); |
1637 | 66fb9763 | bellard | } |
1638 | 66fb9763 | bellard | } |
1639 | 66fb9763 | bellard | break;
|
1640 | 66fb9763 | bellard | case TARGET_NR_sigsuspend:
|
1641 | 66fb9763 | bellard | { |
1642 | 66fb9763 | bellard | sigset_t set; |
1643 | 66fb9763 | bellard | target_to_host_old_sigset(&set, (target_ulong *)arg1); |
1644 | 66fb9763 | bellard | ret = get_errno(sigsuspend(&set)); |
1645 | 66fb9763 | bellard | } |
1646 | 66fb9763 | bellard | break;
|
1647 | 66fb9763 | bellard | case TARGET_NR_rt_sigsuspend:
|
1648 | 66fb9763 | bellard | { |
1649 | 66fb9763 | bellard | sigset_t set; |
1650 | 66fb9763 | bellard | target_to_host_sigset(&set, (target_sigset_t *)arg1); |
1651 | 66fb9763 | bellard | ret = get_errno(sigsuspend(&set)); |
1652 | 66fb9763 | bellard | } |
1653 | 66fb9763 | bellard | break;
|
1654 | 66fb9763 | bellard | case TARGET_NR_rt_sigtimedwait:
|
1655 | 66fb9763 | bellard | { |
1656 | 66fb9763 | bellard | target_sigset_t *target_set = (void *)arg1;
|
1657 | 66fb9763 | bellard | target_siginfo_t *target_uinfo = (void *)arg2;
|
1658 | 66fb9763 | bellard | struct target_timespec *target_uts = (void *)arg3; |
1659 | 66fb9763 | bellard | sigset_t set; |
1660 | 66fb9763 | bellard | struct timespec uts, *puts;
|
1661 | 66fb9763 | bellard | siginfo_t uinfo; |
1662 | 66fb9763 | bellard | |
1663 | 66fb9763 | bellard | target_to_host_sigset(&set, target_set); |
1664 | 66fb9763 | bellard | if (target_uts) {
|
1665 | 66fb9763 | bellard | puts = &uts; |
1666 | 66fb9763 | bellard | puts->tv_sec = tswapl(target_uts->tv_sec); |
1667 | 66fb9763 | bellard | puts->tv_nsec = tswapl(target_uts->tv_nsec); |
1668 | 66fb9763 | bellard | } else {
|
1669 | 66fb9763 | bellard | puts = NULL;
|
1670 | 66fb9763 | bellard | } |
1671 | 66fb9763 | bellard | ret = get_errno(sigtimedwait(&set, &uinfo, puts)); |
1672 | 66fb9763 | bellard | if (!is_error(ret) && target_uinfo) {
|
1673 | 66fb9763 | bellard | host_to_target_siginfo(target_uinfo, &uinfo); |
1674 | 66fb9763 | bellard | } |
1675 | 66fb9763 | bellard | } |
1676 | 66fb9763 | bellard | break;
|
1677 | 66fb9763 | bellard | case TARGET_NR_rt_sigqueueinfo:
|
1678 | 66fb9763 | bellard | { |
1679 | 66fb9763 | bellard | siginfo_t uinfo; |
1680 | 66fb9763 | bellard | target_to_host_siginfo(&uinfo, (target_siginfo_t *)arg3); |
1681 | 66fb9763 | bellard | ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, &uinfo)); |
1682 | 66fb9763 | bellard | } |
1683 | 66fb9763 | bellard | break;
|
1684 | 66fb9763 | bellard | case TARGET_NR_sigreturn:
|
1685 | 66fb9763 | bellard | /* NOTE: ret is eax, so not transcoding must be done */
|
1686 | 66fb9763 | bellard | ret = do_sigreturn(cpu_env); |
1687 | 66fb9763 | bellard | break;
|
1688 | 66fb9763 | bellard | case TARGET_NR_rt_sigreturn:
|
1689 | 66fb9763 | bellard | /* NOTE: ret is eax, so not transcoding must be done */
|
1690 | 66fb9763 | bellard | ret = do_rt_sigreturn(cpu_env); |
1691 | 66fb9763 | bellard | break;
|
1692 | 31e31b8a | bellard | case TARGET_NR_setreuid:
|
1693 | 31e31b8a | bellard | ret = get_errno(setreuid(arg1, arg2)); |
1694 | 31e31b8a | bellard | break;
|
1695 | 31e31b8a | bellard | case TARGET_NR_setregid:
|
1696 | 31e31b8a | bellard | ret = get_errno(setregid(arg1, arg2)); |
1697 | 31e31b8a | bellard | break;
|
1698 | 31e31b8a | bellard | case TARGET_NR_sethostname:
|
1699 | 31e31b8a | bellard | ret = get_errno(sethostname((const char *)arg1, arg2)); |
1700 | 31e31b8a | bellard | break;
|
1701 | 31e31b8a | bellard | case TARGET_NR_setrlimit:
|
1702 | 9de5e440 | bellard | { |
1703 | 9de5e440 | bellard | /* XXX: convert resource ? */
|
1704 | 9de5e440 | bellard | int resource = arg1;
|
1705 | 9de5e440 | bellard | struct target_rlimit *target_rlim = (void *)arg2; |
1706 | 9de5e440 | bellard | struct rlimit rlim;
|
1707 | 9de5e440 | bellard | rlim.rlim_cur = tswapl(target_rlim->rlim_cur); |
1708 | 9de5e440 | bellard | rlim.rlim_max = tswapl(target_rlim->rlim_max); |
1709 | 9de5e440 | bellard | ret = get_errno(setrlimit(resource, &rlim)); |
1710 | 9de5e440 | bellard | } |
1711 | 9de5e440 | bellard | break;
|
1712 | 31e31b8a | bellard | case TARGET_NR_getrlimit:
|
1713 | 9de5e440 | bellard | { |
1714 | 9de5e440 | bellard | /* XXX: convert resource ? */
|
1715 | 9de5e440 | bellard | int resource = arg1;
|
1716 | 9de5e440 | bellard | struct target_rlimit *target_rlim = (void *)arg2; |
1717 | 9de5e440 | bellard | struct rlimit rlim;
|
1718 | 9de5e440 | bellard | |
1719 | 9de5e440 | bellard | ret = get_errno(getrlimit(resource, &rlim)); |
1720 | 9de5e440 | bellard | if (!is_error(ret)) {
|
1721 | 9de5e440 | bellard | target_rlim->rlim_cur = tswapl(rlim.rlim_cur); |
1722 | 9de5e440 | bellard | target_rlim->rlim_max = tswapl(rlim.rlim_max); |
1723 | 9de5e440 | bellard | } |
1724 | 9de5e440 | bellard | } |
1725 | 9de5e440 | bellard | break;
|
1726 | 31e31b8a | bellard | case TARGET_NR_getrusage:
|
1727 | b409186b | bellard | { |
1728 | b409186b | bellard | struct rusage rusage;
|
1729 | b409186b | bellard | struct target_rusage *target_rusage = (void *)arg2; |
1730 | b409186b | bellard | ret = get_errno(getrusage(arg1, &rusage)); |
1731 | b409186b | bellard | if (!is_error(ret)) {
|
1732 | b409186b | bellard | host_to_target_rusage(target_rusage, &rusage); |
1733 | b409186b | bellard | } |
1734 | b409186b | bellard | } |
1735 | b409186b | bellard | break;
|
1736 | 31e31b8a | bellard | case TARGET_NR_gettimeofday:
|
1737 | 31e31b8a | bellard | { |
1738 | 31e31b8a | bellard | struct target_timeval *target_tv = (void *)arg1; |
1739 | 31e31b8a | bellard | struct timeval tv;
|
1740 | 31e31b8a | bellard | ret = get_errno(gettimeofday(&tv, NULL));
|
1741 | 31e31b8a | bellard | if (!is_error(ret)) {
|
1742 | 5cd4393b | bellard | host_to_target_timeval(target_tv, &tv); |
1743 | 31e31b8a | bellard | } |
1744 | 31e31b8a | bellard | } |
1745 | 31e31b8a | bellard | break;
|
1746 | 31e31b8a | bellard | case TARGET_NR_settimeofday:
|
1747 | 31e31b8a | bellard | { |
1748 | 31e31b8a | bellard | struct target_timeval *target_tv = (void *)arg1; |
1749 | 31e31b8a | bellard | struct timeval tv;
|
1750 | 5cd4393b | bellard | target_to_host_timeval(&tv, target_tv); |
1751 | 31e31b8a | bellard | ret = get_errno(settimeofday(&tv, NULL));
|
1752 | 31e31b8a | bellard | } |
1753 | 31e31b8a | bellard | break;
|
1754 | 31e31b8a | bellard | case TARGET_NR_getgroups:
|
1755 | 19b84f3c | bellard | { |
1756 | 19b84f3c | bellard | int gidsetsize = arg1;
|
1757 | 19b84f3c | bellard | uint16_t *target_grouplist = (void *)arg2;
|
1758 | 19b84f3c | bellard | gid_t *grouplist; |
1759 | 19b84f3c | bellard | int i;
|
1760 | 19b84f3c | bellard | |
1761 | 19b84f3c | bellard | grouplist = alloca(gidsetsize * sizeof(gid_t));
|
1762 | 19b84f3c | bellard | ret = get_errno(getgroups(gidsetsize, grouplist)); |
1763 | 19b84f3c | bellard | if (!is_error(ret)) {
|
1764 | 19b84f3c | bellard | for(i = 0;i < gidsetsize; i++) |
1765 | 19b84f3c | bellard | target_grouplist[i] = tswap16(grouplist[i]); |
1766 | 19b84f3c | bellard | } |
1767 | 19b84f3c | bellard | } |
1768 | 19b84f3c | bellard | break;
|
1769 | 31e31b8a | bellard | case TARGET_NR_setgroups:
|
1770 | 19b84f3c | bellard | { |
1771 | 19b84f3c | bellard | int gidsetsize = arg1;
|
1772 | 19b84f3c | bellard | uint16_t *target_grouplist = (void *)arg2;
|
1773 | 19b84f3c | bellard | gid_t *grouplist; |
1774 | 19b84f3c | bellard | int i;
|
1775 | 19b84f3c | bellard | |
1776 | 19b84f3c | bellard | grouplist = alloca(gidsetsize * sizeof(gid_t));
|
1777 | 19b84f3c | bellard | for(i = 0;i < gidsetsize; i++) |
1778 | 19b84f3c | bellard | grouplist[i] = tswap16(target_grouplist[i]); |
1779 | 19b84f3c | bellard | ret = get_errno(setgroups(gidsetsize, grouplist)); |
1780 | 19b84f3c | bellard | } |
1781 | 19b84f3c | bellard | break;
|
1782 | 31e31b8a | bellard | case TARGET_NR_select:
|
1783 | f2674e31 | bellard | { |
1784 | f2674e31 | bellard | struct target_sel_arg_struct *sel = (void *)arg1; |
1785 | f2674e31 | bellard | sel->n = tswapl(sel->n); |
1786 | f2674e31 | bellard | sel->inp = tswapl(sel->inp); |
1787 | f2674e31 | bellard | sel->outp = tswapl(sel->outp); |
1788 | f2674e31 | bellard | sel->exp = tswapl(sel->exp); |
1789 | f2674e31 | bellard | sel->tvp = tswapl(sel->tvp); |
1790 | f2674e31 | bellard | ret = do_select(sel->n, (void *)sel->inp, (void *)sel->outp, |
1791 | f2674e31 | bellard | (void *)sel->exp, (void *)sel->tvp); |
1792 | f2674e31 | bellard | } |
1793 | f2674e31 | bellard | break;
|
1794 | 31e31b8a | bellard | case TARGET_NR_symlink:
|
1795 | 31e31b8a | bellard | ret = get_errno(symlink((const char *)arg1, (const char *)arg2)); |
1796 | 31e31b8a | bellard | break;
|
1797 | 31e31b8a | bellard | case TARGET_NR_oldlstat:
|
1798 | 31e31b8a | bellard | goto unimplemented;
|
1799 | 31e31b8a | bellard | case TARGET_NR_readlink:
|
1800 | ec86b0fb | bellard | ret = get_errno(readlink(path((const char *)arg1), (char *)arg2, arg3)); |
1801 | 31e31b8a | bellard | break;
|
1802 | 31e31b8a | bellard | case TARGET_NR_uselib:
|
1803 | 31e31b8a | bellard | goto unimplemented;
|
1804 | 31e31b8a | bellard | case TARGET_NR_swapon:
|
1805 | 31e31b8a | bellard | ret = get_errno(swapon((const char *)arg1, arg2)); |
1806 | 31e31b8a | bellard | break;
|
1807 | 31e31b8a | bellard | case TARGET_NR_reboot:
|
1808 | 31e31b8a | bellard | goto unimplemented;
|
1809 | 31e31b8a | bellard | case TARGET_NR_readdir:
|
1810 | 31e31b8a | bellard | goto unimplemented;
|
1811 | 31e31b8a | bellard | case TARGET_NR_mmap:
|
1812 | 6fb883e8 | bellard | #if defined(TARGET_I386) || defined(TARGET_ARM)
|
1813 | 31e31b8a | bellard | { |
1814 | 31e31b8a | bellard | uint32_t v1, v2, v3, v4, v5, v6, *vptr; |
1815 | 31e31b8a | bellard | vptr = (uint32_t *)arg1; |
1816 | 31e31b8a | bellard | v1 = tswap32(vptr[0]);
|
1817 | 31e31b8a | bellard | v2 = tswap32(vptr[1]);
|
1818 | 31e31b8a | bellard | v3 = tswap32(vptr[2]);
|
1819 | 31e31b8a | bellard | v4 = tswap32(vptr[3]);
|
1820 | 31e31b8a | bellard | v5 = tswap32(vptr[4]);
|
1821 | 31e31b8a | bellard | v6 = tswap32(vptr[5]);
|
1822 | 5286db75 | bellard | ret = get_errno(target_mmap(v1, v2, v3, |
1823 | 5286db75 | bellard | target_to_host_bitmask(v4, mmap_flags_tbl), |
1824 | 5286db75 | bellard | v5, v6)); |
1825 | 31e31b8a | bellard | } |
1826 | 31e31b8a | bellard | #else
|
1827 | 6fb883e8 | bellard | ret = get_errno(target_mmap(arg1, arg2, arg3, |
1828 | 6fb883e8 | bellard | target_to_host_bitmask(arg4, mmap_flags_tbl), |
1829 | 6fb883e8 | bellard | arg5, |
1830 | 6fb883e8 | bellard | arg6)); |
1831 | 31e31b8a | bellard | #endif
|
1832 | 6fb883e8 | bellard | break;
|
1833 | 6fb883e8 | bellard | case TARGET_NR_mmap2:
|
1834 | 5286db75 | bellard | ret = get_errno(target_mmap(arg1, arg2, arg3, |
1835 | 5286db75 | bellard | target_to_host_bitmask(arg4, mmap_flags_tbl), |
1836 | 5286db75 | bellard | arg5, |
1837 | 14ae3ba7 | bellard | arg6 << TARGET_PAGE_BITS)); |
1838 | 31e31b8a | bellard | break;
|
1839 | 31e31b8a | bellard | case TARGET_NR_munmap:
|
1840 | 54936004 | bellard | ret = get_errno(target_munmap(arg1, arg2)); |
1841 | 31e31b8a | bellard | break;
|
1842 | 9de5e440 | bellard | case TARGET_NR_mprotect:
|
1843 | 54936004 | bellard | ret = get_errno(target_mprotect(arg1, arg2, arg3)); |
1844 | 9de5e440 | bellard | break;
|
1845 | 9de5e440 | bellard | case TARGET_NR_mremap:
|
1846 | 54936004 | bellard | ret = get_errno(target_mremap(arg1, arg2, arg3, arg4, arg5)); |
1847 | 9de5e440 | bellard | break;
|
1848 | 9de5e440 | bellard | case TARGET_NR_msync:
|
1849 | 9de5e440 | bellard | ret = get_errno(msync((void *)arg1, arg2, arg3));
|
1850 | 9de5e440 | bellard | break;
|
1851 | 9de5e440 | bellard | case TARGET_NR_mlock:
|
1852 | 9de5e440 | bellard | ret = get_errno(mlock((void *)arg1, arg2));
|
1853 | 9de5e440 | bellard | break;
|
1854 | 9de5e440 | bellard | case TARGET_NR_munlock:
|
1855 | 9de5e440 | bellard | ret = get_errno(munlock((void *)arg1, arg2));
|
1856 | 9de5e440 | bellard | break;
|
1857 | 9de5e440 | bellard | case TARGET_NR_mlockall:
|
1858 | 9de5e440 | bellard | ret = get_errno(mlockall(arg1)); |
1859 | 9de5e440 | bellard | break;
|
1860 | 9de5e440 | bellard | case TARGET_NR_munlockall:
|
1861 | 9de5e440 | bellard | ret = get_errno(munlockall()); |
1862 | 9de5e440 | bellard | break;
|
1863 | 31e31b8a | bellard | case TARGET_NR_truncate:
|
1864 | 31e31b8a | bellard | ret = get_errno(truncate((const char *)arg1, arg2)); |
1865 | 31e31b8a | bellard | break;
|
1866 | 31e31b8a | bellard | case TARGET_NR_ftruncate:
|
1867 | 31e31b8a | bellard | ret = get_errno(ftruncate(arg1, arg2)); |
1868 | 31e31b8a | bellard | break;
|
1869 | 31e31b8a | bellard | case TARGET_NR_fchmod:
|
1870 | 31e31b8a | bellard | ret = get_errno(fchmod(arg1, arg2)); |
1871 | 31e31b8a | bellard | break;
|
1872 | 31e31b8a | bellard | case TARGET_NR_fchown:
|
1873 | 31e31b8a | bellard | ret = get_errno(fchown(arg1, arg2, arg3)); |
1874 | 31e31b8a | bellard | break;
|
1875 | 31e31b8a | bellard | case TARGET_NR_getpriority:
|
1876 | 31e31b8a | bellard | ret = get_errno(getpriority(arg1, arg2)); |
1877 | 31e31b8a | bellard | break;
|
1878 | 31e31b8a | bellard | case TARGET_NR_setpriority:
|
1879 | 31e31b8a | bellard | ret = get_errno(setpriority(arg1, arg2, arg3)); |
1880 | 31e31b8a | bellard | break;
|
1881 | 31e31b8a | bellard | case TARGET_NR_profil:
|
1882 | 31e31b8a | bellard | goto unimplemented;
|
1883 | 31e31b8a | bellard | case TARGET_NR_statfs:
|
1884 | 31e31b8a | bellard | stfs = (void *)arg2;
|
1885 | ec86b0fb | bellard | ret = get_errno(sys_statfs(path((const char *)arg1), stfs)); |
1886 | 31e31b8a | bellard | convert_statfs:
|
1887 | 31e31b8a | bellard | if (!is_error(ret)) {
|
1888 | 31e31b8a | bellard | tswap32s(&stfs->f_type); |
1889 | 31e31b8a | bellard | tswap32s(&stfs->f_bsize); |
1890 | 31e31b8a | bellard | tswap32s(&stfs->f_blocks); |
1891 | 31e31b8a | bellard | tswap32s(&stfs->f_bfree); |
1892 | 31e31b8a | bellard | tswap32s(&stfs->f_bavail); |
1893 | 31e31b8a | bellard | tswap32s(&stfs->f_files); |
1894 | 31e31b8a | bellard | tswap32s(&stfs->f_ffree); |
1895 | 31e31b8a | bellard | tswap32s(&stfs->f_fsid.val[0]);
|
1896 | 31e31b8a | bellard | tswap32s(&stfs->f_fsid.val[1]);
|
1897 | 31e31b8a | bellard | tswap32s(&stfs->f_namelen); |
1898 | 31e31b8a | bellard | } |
1899 | 31e31b8a | bellard | break;
|
1900 | 31e31b8a | bellard | case TARGET_NR_fstatfs:
|
1901 | 31e31b8a | bellard | stfs = (void *)arg2;
|
1902 | 31e31b8a | bellard | ret = get_errno(sys_fstatfs(arg1, stfs)); |
1903 | 31e31b8a | bellard | goto convert_statfs;
|
1904 | 31e31b8a | bellard | case TARGET_NR_ioperm:
|
1905 | 31e31b8a | bellard | goto unimplemented;
|
1906 | 31e31b8a | bellard | case TARGET_NR_socketcall:
|
1907 | 7854b056 | bellard | ret = do_socketcall(arg1, (int32_t *)arg2); |
1908 | 31e31b8a | bellard | break;
|
1909 | 31e31b8a | bellard | case TARGET_NR_syslog:
|
1910 | 31e31b8a | bellard | goto unimplemented;
|
1911 | 31e31b8a | bellard | case TARGET_NR_setitimer:
|
1912 | 66fb9763 | bellard | { |
1913 | 66fb9763 | bellard | struct target_itimerval *target_value = (void *)arg2; |
1914 | 66fb9763 | bellard | struct target_itimerval *target_ovalue = (void *)arg3; |
1915 | 66fb9763 | bellard | struct itimerval value, ovalue, *pvalue;
|
1916 | 66fb9763 | bellard | |
1917 | 66fb9763 | bellard | if (target_value) {
|
1918 | 66fb9763 | bellard | pvalue = &value; |
1919 | 66fb9763 | bellard | target_to_host_timeval(&pvalue->it_interval, |
1920 | 66fb9763 | bellard | &target_value->it_interval); |
1921 | 66fb9763 | bellard | target_to_host_timeval(&pvalue->it_value, |
1922 | 66fb9763 | bellard | &target_value->it_value); |
1923 | 66fb9763 | bellard | } else {
|
1924 | 66fb9763 | bellard | pvalue = NULL;
|
1925 | 66fb9763 | bellard | } |
1926 | 66fb9763 | bellard | ret = get_errno(setitimer(arg1, pvalue, &ovalue)); |
1927 | 66fb9763 | bellard | if (!is_error(ret) && target_ovalue) {
|
1928 | 66fb9763 | bellard | host_to_target_timeval(&target_ovalue->it_interval, |
1929 | 66fb9763 | bellard | &ovalue.it_interval); |
1930 | 66fb9763 | bellard | host_to_target_timeval(&target_ovalue->it_value, |
1931 | 66fb9763 | bellard | &ovalue.it_value); |
1932 | 66fb9763 | bellard | } |
1933 | 66fb9763 | bellard | } |
1934 | 66fb9763 | bellard | break;
|
1935 | 31e31b8a | bellard | case TARGET_NR_getitimer:
|
1936 | 66fb9763 | bellard | { |
1937 | 66fb9763 | bellard | struct target_itimerval *target_value = (void *)arg2; |
1938 | 66fb9763 | bellard | struct itimerval value;
|
1939 | 66fb9763 | bellard | |
1940 | 66fb9763 | bellard | ret = get_errno(getitimer(arg1, &value)); |
1941 | 66fb9763 | bellard | if (!is_error(ret) && target_value) {
|
1942 | 66fb9763 | bellard | host_to_target_timeval(&target_value->it_interval, |
1943 | 66fb9763 | bellard | &value.it_interval); |
1944 | 66fb9763 | bellard | host_to_target_timeval(&target_value->it_value, |
1945 | 66fb9763 | bellard | &value.it_value); |
1946 | 66fb9763 | bellard | } |
1947 | 66fb9763 | bellard | } |
1948 | 66fb9763 | bellard | break;
|
1949 | 31e31b8a | bellard | case TARGET_NR_stat:
|
1950 | ec86b0fb | bellard | ret = get_errno(stat(path((const char *)arg1), &st)); |
1951 | 31e31b8a | bellard | goto do_stat;
|
1952 | 31e31b8a | bellard | case TARGET_NR_lstat:
|
1953 | ec86b0fb | bellard | ret = get_errno(lstat(path((const char *)arg1), &st)); |
1954 | 31e31b8a | bellard | goto do_stat;
|
1955 | 31e31b8a | bellard | case TARGET_NR_fstat:
|
1956 | 31e31b8a | bellard | { |
1957 | 31e31b8a | bellard | ret = get_errno(fstat(arg1, &st)); |
1958 | 31e31b8a | bellard | do_stat:
|
1959 | 31e31b8a | bellard | if (!is_error(ret)) {
|
1960 | 31e31b8a | bellard | struct target_stat *target_st = (void *)arg2; |
1961 | 31e31b8a | bellard | target_st->st_dev = tswap16(st.st_dev); |
1962 | 31e31b8a | bellard | target_st->st_ino = tswapl(st.st_ino); |
1963 | ec86b0fb | bellard | target_st->st_mode = tswap16(st.st_mode); |
1964 | 31e31b8a | bellard | target_st->st_nlink = tswap16(st.st_nlink); |
1965 | 31e31b8a | bellard | target_st->st_uid = tswap16(st.st_uid); |
1966 | 31e31b8a | bellard | target_st->st_gid = tswap16(st.st_gid); |
1967 | 31e31b8a | bellard | target_st->st_rdev = tswap16(st.st_rdev); |
1968 | 31e31b8a | bellard | target_st->st_size = tswapl(st.st_size); |
1969 | 31e31b8a | bellard | target_st->st_blksize = tswapl(st.st_blksize); |
1970 | 31e31b8a | bellard | target_st->st_blocks = tswapl(st.st_blocks); |
1971 | 7854b056 | bellard | target_st->target_st_atime = tswapl(st.st_atime); |
1972 | 7854b056 | bellard | target_st->target_st_mtime = tswapl(st.st_mtime); |
1973 | 7854b056 | bellard | target_st->target_st_ctime = tswapl(st.st_ctime); |
1974 | 31e31b8a | bellard | } |
1975 | 31e31b8a | bellard | } |
1976 | 31e31b8a | bellard | break;
|
1977 | 31e31b8a | bellard | case TARGET_NR_olduname:
|
1978 | 31e31b8a | bellard | goto unimplemented;
|
1979 | 31e31b8a | bellard | case TARGET_NR_iopl:
|
1980 | 31e31b8a | bellard | goto unimplemented;
|
1981 | 31e31b8a | bellard | case TARGET_NR_vhangup:
|
1982 | 31e31b8a | bellard | ret = get_errno(vhangup()); |
1983 | 31e31b8a | bellard | break;
|
1984 | 31e31b8a | bellard | case TARGET_NR_idle:
|
1985 | 31e31b8a | bellard | goto unimplemented;
|
1986 | 31e31b8a | bellard | case TARGET_NR_wait4:
|
1987 | 31e31b8a | bellard | { |
1988 | 31e31b8a | bellard | int status;
|
1989 | 31e31b8a | bellard | target_long *status_ptr = (void *)arg2;
|
1990 | 31e31b8a | bellard | struct rusage rusage, *rusage_ptr;
|
1991 | 31e31b8a | bellard | struct target_rusage *target_rusage = (void *)arg4; |
1992 | 31e31b8a | bellard | if (target_rusage)
|
1993 | 31e31b8a | bellard | rusage_ptr = &rusage; |
1994 | 31e31b8a | bellard | else
|
1995 | 31e31b8a | bellard | rusage_ptr = NULL;
|
1996 | 31e31b8a | bellard | ret = get_errno(wait4(arg1, &status, arg3, rusage_ptr)); |
1997 | 31e31b8a | bellard | if (!is_error(ret)) {
|
1998 | 31e31b8a | bellard | if (status_ptr)
|
1999 | 31e31b8a | bellard | *status_ptr = tswap32(status); |
2000 | 31e31b8a | bellard | if (target_rusage) {
|
2001 | b409186b | bellard | host_to_target_rusage(target_rusage, &rusage); |
2002 | 31e31b8a | bellard | } |
2003 | 31e31b8a | bellard | } |
2004 | 31e31b8a | bellard | } |
2005 | 31e31b8a | bellard | break;
|
2006 | 31e31b8a | bellard | case TARGET_NR_swapoff:
|
2007 | 31e31b8a | bellard | ret = get_errno(swapoff((const char *)arg1)); |
2008 | 31e31b8a | bellard | break;
|
2009 | 31e31b8a | bellard | case TARGET_NR_sysinfo:
|
2010 | 31e31b8a | bellard | goto unimplemented;
|
2011 | 31e31b8a | bellard | case TARGET_NR_ipc:
|
2012 | 31e31b8a | bellard | goto unimplemented;
|
2013 | 31e31b8a | bellard | case TARGET_NR_fsync:
|
2014 | 31e31b8a | bellard | ret = get_errno(fsync(arg1)); |
2015 | 31e31b8a | bellard | break;
|
2016 | 31e31b8a | bellard | case TARGET_NR_clone:
|
2017 | 1b6b029e | bellard | ret = get_errno(do_fork(cpu_env, arg1, arg2)); |
2018 | 1b6b029e | bellard | break;
|
2019 | ec86b0fb | bellard | #ifdef __NR_exit_group
|
2020 | ec86b0fb | bellard | /* new thread calls */
|
2021 | ec86b0fb | bellard | case TARGET_NR_exit_group:
|
2022 | ec86b0fb | bellard | ret = get_errno(exit_group(arg1)); |
2023 | ec86b0fb | bellard | break;
|
2024 | ec86b0fb | bellard | #endif
|
2025 | 31e31b8a | bellard | case TARGET_NR_setdomainname:
|
2026 | 31e31b8a | bellard | ret = get_errno(setdomainname((const char *)arg1, arg2)); |
2027 | 31e31b8a | bellard | break;
|
2028 | 31e31b8a | bellard | case TARGET_NR_uname:
|
2029 | 31e31b8a | bellard | /* no need to transcode because we use the linux syscall */
|
2030 | 31e31b8a | bellard | ret = get_errno(sys_uname((struct new_utsname *)arg1));
|
2031 | 31e31b8a | bellard | break;
|
2032 | 6dbad63e | bellard | #ifdef TARGET_I386
|
2033 | 31e31b8a | bellard | case TARGET_NR_modify_ldt:
|
2034 | 5cd4393b | bellard | ret = get_errno(do_modify_ldt(cpu_env, arg1, (void *)arg2, arg3));
|
2035 | 5cd4393b | bellard | break;
|
2036 | 5cd4393b | bellard | case TARGET_NR_vm86old:
|
2037 | 5cd4393b | bellard | goto unimplemented;
|
2038 | 5cd4393b | bellard | case TARGET_NR_vm86:
|
2039 | 5cd4393b | bellard | ret = do_vm86(cpu_env, arg1, (void *)arg2);
|
2040 | 6dbad63e | bellard | break;
|
2041 | 6dbad63e | bellard | #endif
|
2042 | 31e31b8a | bellard | case TARGET_NR_adjtimex:
|
2043 | 31e31b8a | bellard | goto unimplemented;
|
2044 | 31e31b8a | bellard | case TARGET_NR_create_module:
|
2045 | 31e31b8a | bellard | case TARGET_NR_init_module:
|
2046 | 31e31b8a | bellard | case TARGET_NR_delete_module:
|
2047 | 31e31b8a | bellard | case TARGET_NR_get_kernel_syms:
|
2048 | 31e31b8a | bellard | goto unimplemented;
|
2049 | 31e31b8a | bellard | case TARGET_NR_quotactl:
|
2050 | 31e31b8a | bellard | goto unimplemented;
|
2051 | 31e31b8a | bellard | case TARGET_NR_getpgid:
|
2052 | 31e31b8a | bellard | ret = get_errno(getpgid(arg1)); |
2053 | 31e31b8a | bellard | break;
|
2054 | 31e31b8a | bellard | case TARGET_NR_fchdir:
|
2055 | 31e31b8a | bellard | ret = get_errno(fchdir(arg1)); |
2056 | 31e31b8a | bellard | break;
|
2057 | 31e31b8a | bellard | case TARGET_NR_bdflush:
|
2058 | 31e31b8a | bellard | goto unimplemented;
|
2059 | 31e31b8a | bellard | case TARGET_NR_sysfs:
|
2060 | 31e31b8a | bellard | goto unimplemented;
|
2061 | 31e31b8a | bellard | case TARGET_NR_personality:
|
2062 | 1b6b029e | bellard | ret = get_errno(personality(arg1)); |
2063 | 31e31b8a | bellard | break;
|
2064 | 31e31b8a | bellard | case TARGET_NR_afs_syscall:
|
2065 | 31e31b8a | bellard | goto unimplemented;
|
2066 | 31e31b8a | bellard | case TARGET_NR_setfsuid:
|
2067 | 9de5e440 | bellard | ret = get_errno(setfsuid(arg1)); |
2068 | 9de5e440 | bellard | break;
|
2069 | 31e31b8a | bellard | case TARGET_NR_setfsgid:
|
2070 | 9de5e440 | bellard | ret = get_errno(setfsgid(arg1)); |
2071 | 9de5e440 | bellard | break;
|
2072 | 31e31b8a | bellard | case TARGET_NR__llseek:
|
2073 | 31e31b8a | bellard | { |
2074 | 31e31b8a | bellard | int64_t res; |
2075 | 31e31b8a | bellard | ret = get_errno(_llseek(arg1, arg2, arg3, &res, arg5)); |
2076 | 31e31b8a | bellard | *(int64_t *)arg4 = tswap64(res); |
2077 | 31e31b8a | bellard | } |
2078 | 31e31b8a | bellard | break;
|
2079 | 31e31b8a | bellard | case TARGET_NR_getdents:
|
2080 | 31e31b8a | bellard | #if TARGET_LONG_SIZE != 4 |
2081 | 31e31b8a | bellard | #error not supported
|
2082 | 4add45b4 | bellard | #elif TARGET_LONG_SIZE == 4 && HOST_LONG_SIZE == 8 |
2083 | 4add45b4 | bellard | { |
2084 | 4add45b4 | bellard | struct target_dirent *target_dirp = (void *)arg2; |
2085 | 4add45b4 | bellard | struct dirent *dirp;
|
2086 | 4add45b4 | bellard | long count = arg3;
|
2087 | 4add45b4 | bellard | |
2088 | 4add45b4 | bellard | dirp = malloc(count); |
2089 | 4add45b4 | bellard | if (!dirp)
|
2090 | 4add45b4 | bellard | return -ENOMEM;
|
2091 | 4add45b4 | bellard | |
2092 | 4add45b4 | bellard | ret = get_errno(sys_getdents(arg1, dirp, count)); |
2093 | 4add45b4 | bellard | if (!is_error(ret)) {
|
2094 | 4add45b4 | bellard | struct dirent *de;
|
2095 | 4add45b4 | bellard | struct target_dirent *tde;
|
2096 | 4add45b4 | bellard | int len = ret;
|
2097 | 4add45b4 | bellard | int reclen, treclen;
|
2098 | 4add45b4 | bellard | int count1, tnamelen;
|
2099 | 4add45b4 | bellard | |
2100 | 4add45b4 | bellard | count1 = 0;
|
2101 | 4add45b4 | bellard | de = dirp; |
2102 | 4add45b4 | bellard | tde = target_dirp; |
2103 | 4add45b4 | bellard | while (len > 0) { |
2104 | 4add45b4 | bellard | reclen = de->d_reclen; |
2105 | 4add45b4 | bellard | treclen = reclen - (2 * (sizeof(long) - sizeof(target_long))); |
2106 | 4add45b4 | bellard | tde->d_reclen = tswap16(treclen); |
2107 | 4add45b4 | bellard | tde->d_ino = tswapl(de->d_ino); |
2108 | 4add45b4 | bellard | tde->d_off = tswapl(de->d_off); |
2109 | 4add45b4 | bellard | tnamelen = treclen - (2 * sizeof(target_long) + 2); |
2110 | 4add45b4 | bellard | if (tnamelen > 256) |
2111 | 4add45b4 | bellard | tnamelen = 256;
|
2112 | 4add45b4 | bellard | strncpy(tde->d_name, de->d_name, tnamelen); |
2113 | 4add45b4 | bellard | de = (struct dirent *)((char *)de + reclen); |
2114 | 4add45b4 | bellard | len -= reclen; |
2115 | 4add45b4 | bellard | tde = (struct dirent *)((char *)tde + treclen); |
2116 | 4add45b4 | bellard | count1 += treclen; |
2117 | 4add45b4 | bellard | } |
2118 | 4add45b4 | bellard | ret = count1; |
2119 | 4add45b4 | bellard | } |
2120 | 4add45b4 | bellard | free(dirp); |
2121 | 4add45b4 | bellard | } |
2122 | 4add45b4 | bellard | #else
|
2123 | 31e31b8a | bellard | { |
2124 | 31e31b8a | bellard | struct dirent *dirp = (void *)arg2; |
2125 | 31e31b8a | bellard | long count = arg3;
|
2126 | dab2ed99 | bellard | |
2127 | 72f03900 | bellard | ret = get_errno(sys_getdents(arg1, dirp, count)); |
2128 | 31e31b8a | bellard | if (!is_error(ret)) {
|
2129 | 31e31b8a | bellard | struct dirent *de;
|
2130 | 31e31b8a | bellard | int len = ret;
|
2131 | 31e31b8a | bellard | int reclen;
|
2132 | 31e31b8a | bellard | de = dirp; |
2133 | 31e31b8a | bellard | while (len > 0) { |
2134 | 8083a3e5 | bellard | reclen = de->d_reclen; |
2135 | 31e31b8a | bellard | if (reclen > len)
|
2136 | 31e31b8a | bellard | break;
|
2137 | 8083a3e5 | bellard | de->d_reclen = tswap16(reclen); |
2138 | 31e31b8a | bellard | tswapls(&de->d_ino); |
2139 | 31e31b8a | bellard | tswapls(&de->d_off); |
2140 | 31e31b8a | bellard | de = (struct dirent *)((char *)de + reclen); |
2141 | 31e31b8a | bellard | len -= reclen; |
2142 | 31e31b8a | bellard | } |
2143 | 31e31b8a | bellard | } |
2144 | 31e31b8a | bellard | } |
2145 | 4add45b4 | bellard | #endif
|
2146 | 31e31b8a | bellard | break;
|
2147 | dab2ed99 | bellard | case TARGET_NR_getdents64:
|
2148 | dab2ed99 | bellard | { |
2149 | dab2ed99 | bellard | struct dirent64 *dirp = (void *)arg2; |
2150 | dab2ed99 | bellard | long count = arg3;
|
2151 | dab2ed99 | bellard | ret = get_errno(sys_getdents64(arg1, dirp, count)); |
2152 | dab2ed99 | bellard | if (!is_error(ret)) {
|
2153 | dab2ed99 | bellard | struct dirent64 *de;
|
2154 | dab2ed99 | bellard | int len = ret;
|
2155 | dab2ed99 | bellard | int reclen;
|
2156 | dab2ed99 | bellard | de = dirp; |
2157 | dab2ed99 | bellard | while (len > 0) { |
2158 | 8083a3e5 | bellard | reclen = de->d_reclen; |
2159 | dab2ed99 | bellard | if (reclen > len)
|
2160 | dab2ed99 | bellard | break;
|
2161 | 8083a3e5 | bellard | de->d_reclen = tswap16(reclen); |
2162 | dab2ed99 | bellard | tswap64s(&de->d_ino); |
2163 | dab2ed99 | bellard | tswap64s(&de->d_off); |
2164 | dab2ed99 | bellard | de = (struct dirent64 *)((char *)de + reclen); |
2165 | dab2ed99 | bellard | len -= reclen; |
2166 | dab2ed99 | bellard | } |
2167 | dab2ed99 | bellard | } |
2168 | dab2ed99 | bellard | } |
2169 | dab2ed99 | bellard | break;
|
2170 | 31e31b8a | bellard | case TARGET_NR__newselect:
|
2171 | 31e31b8a | bellard | ret = do_select(arg1, (void *)arg2, (void *)arg3, (void *)arg4, |
2172 | 31e31b8a | bellard | (void *)arg5);
|
2173 | 31e31b8a | bellard | break;
|
2174 | 9de5e440 | bellard | case TARGET_NR_poll:
|
2175 | 9de5e440 | bellard | { |
2176 | 9de5e440 | bellard | struct target_pollfd *target_pfd = (void *)arg1; |
2177 | 9de5e440 | bellard | unsigned int nfds = arg2; |
2178 | 9de5e440 | bellard | int timeout = arg3;
|
2179 | 9de5e440 | bellard | struct pollfd *pfd;
|
2180 | 7854b056 | bellard | unsigned int i; |
2181 | 9de5e440 | bellard | |
2182 | 9de5e440 | bellard | pfd = alloca(sizeof(struct pollfd) * nfds); |
2183 | 9de5e440 | bellard | for(i = 0; i < nfds; i++) { |
2184 | 5cd4393b | bellard | pfd[i].fd = tswap32(target_pfd[i].fd); |
2185 | 5cd4393b | bellard | pfd[i].events = tswap16(target_pfd[i].events); |
2186 | 9de5e440 | bellard | } |
2187 | 9de5e440 | bellard | ret = get_errno(poll(pfd, nfds, timeout)); |
2188 | 9de5e440 | bellard | if (!is_error(ret)) {
|
2189 | 9de5e440 | bellard | for(i = 0; i < nfds; i++) { |
2190 | 5cd4393b | bellard | target_pfd[i].revents = tswap16(pfd[i].revents); |
2191 | 9de5e440 | bellard | } |
2192 | 9de5e440 | bellard | } |
2193 | 9de5e440 | bellard | } |
2194 | 9de5e440 | bellard | break;
|
2195 | 31e31b8a | bellard | case TARGET_NR_flock:
|
2196 | 9de5e440 | bellard | /* NOTE: the flock constant seems to be the same for every
|
2197 | 9de5e440 | bellard | Linux platform */
|
2198 | 9de5e440 | bellard | ret = get_errno(flock(arg1, arg2)); |
2199 | 31e31b8a | bellard | break;
|
2200 | 31e31b8a | bellard | case TARGET_NR_readv:
|
2201 | 31e31b8a | bellard | { |
2202 | 31e31b8a | bellard | int count = arg3;
|
2203 | 31e31b8a | bellard | int i;
|
2204 | 31e31b8a | bellard | struct iovec *vec;
|
2205 | 31e31b8a | bellard | struct target_iovec *target_vec = (void *)arg2; |
2206 | 31e31b8a | bellard | |
2207 | 31e31b8a | bellard | vec = alloca(count * sizeof(struct iovec)); |
2208 | 31e31b8a | bellard | for(i = 0;i < count; i++) { |
2209 | 31e31b8a | bellard | vec[i].iov_base = (void *)tswapl(target_vec[i].iov_base);
|
2210 | 31e31b8a | bellard | vec[i].iov_len = tswapl(target_vec[i].iov_len); |
2211 | 31e31b8a | bellard | } |
2212 | 31e31b8a | bellard | ret = get_errno(readv(arg1, vec, count)); |
2213 | 31e31b8a | bellard | } |
2214 | 31e31b8a | bellard | break;
|
2215 | 31e31b8a | bellard | case TARGET_NR_writev:
|
2216 | 31e31b8a | bellard | { |
2217 | 31e31b8a | bellard | int count = arg3;
|
2218 | 31e31b8a | bellard | int i;
|
2219 | 31e31b8a | bellard | struct iovec *vec;
|
2220 | 31e31b8a | bellard | struct target_iovec *target_vec = (void *)arg2; |
2221 | 31e31b8a | bellard | |
2222 | 31e31b8a | bellard | vec = alloca(count * sizeof(struct iovec)); |
2223 | 31e31b8a | bellard | for(i = 0;i < count; i++) { |
2224 | 31e31b8a | bellard | vec[i].iov_base = (void *)tswapl(target_vec[i].iov_base);
|
2225 | 31e31b8a | bellard | vec[i].iov_len = tswapl(target_vec[i].iov_len); |
2226 | 31e31b8a | bellard | } |
2227 | 31e31b8a | bellard | ret = get_errno(writev(arg1, vec, count)); |
2228 | 31e31b8a | bellard | } |
2229 | 31e31b8a | bellard | break;
|
2230 | 31e31b8a | bellard | case TARGET_NR_getsid:
|
2231 | 31e31b8a | bellard | ret = get_errno(getsid(arg1)); |
2232 | 31e31b8a | bellard | break;
|
2233 | 31e31b8a | bellard | case TARGET_NR_fdatasync:
|
2234 | 5cd4393b | bellard | ret = get_errno(fdatasync(arg1)); |
2235 | 5cd4393b | bellard | break;
|
2236 | 31e31b8a | bellard | case TARGET_NR__sysctl:
|
2237 | 31e31b8a | bellard | goto unimplemented;
|
2238 | 31e31b8a | bellard | case TARGET_NR_sched_setparam:
|
2239 | 5cd4393b | bellard | { |
2240 | 5cd4393b | bellard | struct sched_param *target_schp = (void *)arg2; |
2241 | 5cd4393b | bellard | struct sched_param schp;
|
2242 | 5cd4393b | bellard | schp.sched_priority = tswap32(target_schp->sched_priority); |
2243 | 5cd4393b | bellard | ret = get_errno(sched_setparam(arg1, &schp)); |
2244 | 5cd4393b | bellard | } |
2245 | 5cd4393b | bellard | break;
|
2246 | 31e31b8a | bellard | case TARGET_NR_sched_getparam:
|
2247 | 5cd4393b | bellard | { |
2248 | 5cd4393b | bellard | struct sched_param *target_schp = (void *)arg2; |
2249 | 5cd4393b | bellard | struct sched_param schp;
|
2250 | 5cd4393b | bellard | ret = get_errno(sched_getparam(arg1, &schp)); |
2251 | 5cd4393b | bellard | if (!is_error(ret)) {
|
2252 | 5cd4393b | bellard | target_schp->sched_priority = tswap32(schp.sched_priority); |
2253 | 5cd4393b | bellard | } |
2254 | 5cd4393b | bellard | } |
2255 | 5cd4393b | bellard | break;
|
2256 | 31e31b8a | bellard | case TARGET_NR_sched_setscheduler:
|
2257 | 5cd4393b | bellard | { |
2258 | 5cd4393b | bellard | struct sched_param *target_schp = (void *)arg3; |
2259 | 5cd4393b | bellard | struct sched_param schp;
|
2260 | 5cd4393b | bellard | schp.sched_priority = tswap32(target_schp->sched_priority); |
2261 | 5cd4393b | bellard | ret = get_errno(sched_setscheduler(arg1, arg2, &schp)); |
2262 | 5cd4393b | bellard | } |
2263 | 5cd4393b | bellard | break;
|
2264 | 31e31b8a | bellard | case TARGET_NR_sched_getscheduler:
|
2265 | 5cd4393b | bellard | ret = get_errno(sched_getscheduler(arg1)); |
2266 | 5cd4393b | bellard | break;
|
2267 | 31e31b8a | bellard | case TARGET_NR_sched_yield:
|
2268 | 31e31b8a | bellard | ret = get_errno(sched_yield()); |
2269 | 31e31b8a | bellard | break;
|
2270 | 31e31b8a | bellard | case TARGET_NR_sched_get_priority_max:
|
2271 | 5cd4393b | bellard | ret = get_errno(sched_get_priority_max(arg1)); |
2272 | 5cd4393b | bellard | break;
|
2273 | 31e31b8a | bellard | case TARGET_NR_sched_get_priority_min:
|
2274 | 5cd4393b | bellard | ret = get_errno(sched_get_priority_min(arg1)); |
2275 | 5cd4393b | bellard | break;
|
2276 | 31e31b8a | bellard | case TARGET_NR_sched_rr_get_interval:
|
2277 | 5cd4393b | bellard | { |
2278 | 5cd4393b | bellard | struct target_timespec *target_ts = (void *)arg2; |
2279 | 5cd4393b | bellard | struct timespec ts;
|
2280 | 5cd4393b | bellard | ret = get_errno(sched_rr_get_interval(arg1, &ts)); |
2281 | 5cd4393b | bellard | if (!is_error(ret)) {
|
2282 | 5cd4393b | bellard | target_ts->tv_sec = tswapl(ts.tv_sec); |
2283 | 5cd4393b | bellard | target_ts->tv_nsec = tswapl(ts.tv_nsec); |
2284 | 5cd4393b | bellard | } |
2285 | 5cd4393b | bellard | } |
2286 | 5cd4393b | bellard | break;
|
2287 | 31e31b8a | bellard | case TARGET_NR_nanosleep:
|
2288 | 1b6b029e | bellard | { |
2289 | 1b6b029e | bellard | struct target_timespec *target_req = (void *)arg1; |
2290 | 1b6b029e | bellard | struct target_timespec *target_rem = (void *)arg2; |
2291 | 1b6b029e | bellard | struct timespec req, rem;
|
2292 | 1b6b029e | bellard | req.tv_sec = tswapl(target_req->tv_sec); |
2293 | 1b6b029e | bellard | req.tv_nsec = tswapl(target_req->tv_nsec); |
2294 | 1b6b029e | bellard | ret = get_errno(nanosleep(&req, &rem)); |
2295 | 1b6b029e | bellard | if (target_rem) {
|
2296 | 1b6b029e | bellard | target_rem->tv_sec = tswapl(rem.tv_sec); |
2297 | 1b6b029e | bellard | target_rem->tv_nsec = tswapl(rem.tv_nsec); |
2298 | 1b6b029e | bellard | } |
2299 | 1b6b029e | bellard | } |
2300 | 1b6b029e | bellard | break;
|
2301 | 31e31b8a | bellard | case TARGET_NR_setresuid:
|
2302 | b03c60f3 | bellard | ret = get_errno(setresuid(low2highuid(arg1), |
2303 | b03c60f3 | bellard | low2highuid(arg2), |
2304 | b03c60f3 | bellard | low2highuid(arg3))); |
2305 | b03c60f3 | bellard | break;
|
2306 | 31e31b8a | bellard | case TARGET_NR_getresuid:
|
2307 | b03c60f3 | bellard | { |
2308 | b03c60f3 | bellard | int ruid, euid, suid;
|
2309 | b03c60f3 | bellard | ret = get_errno(getresuid(&ruid, &euid, &suid)); |
2310 | b03c60f3 | bellard | if (!is_error(ret)) {
|
2311 | b03c60f3 | bellard | *(uint16_t *)arg1 = tswap16(high2lowuid(ruid)); |
2312 | b03c60f3 | bellard | *(uint16_t *)arg2 = tswap16(high2lowuid(euid)); |
2313 | b03c60f3 | bellard | *(uint16_t *)arg3 = tswap16(high2lowuid(suid)); |
2314 | b03c60f3 | bellard | } |
2315 | b03c60f3 | bellard | } |
2316 | b03c60f3 | bellard | break;
|
2317 | b03c60f3 | bellard | case TARGET_NR_setresgid:
|
2318 | b03c60f3 | bellard | ret = get_errno(setresgid(low2highgid(arg1), |
2319 | b03c60f3 | bellard | low2highgid(arg2), |
2320 | b03c60f3 | bellard | low2highgid(arg3))); |
2321 | b03c60f3 | bellard | break;
|
2322 | b03c60f3 | bellard | case TARGET_NR_getresgid:
|
2323 | b03c60f3 | bellard | { |
2324 | b03c60f3 | bellard | int rgid, egid, sgid;
|
2325 | b03c60f3 | bellard | ret = get_errno(getresgid(&rgid, &egid, &sgid)); |
2326 | b03c60f3 | bellard | if (!is_error(ret)) {
|
2327 | b03c60f3 | bellard | *(uint16_t *)arg1 = high2lowgid(tswap16(rgid)); |
2328 | b03c60f3 | bellard | *(uint16_t *)arg2 = high2lowgid(tswap16(egid)); |
2329 | b03c60f3 | bellard | *(uint16_t *)arg3 = high2lowgid(tswap16(sgid)); |
2330 | b03c60f3 | bellard | } |
2331 | b03c60f3 | bellard | } |
2332 | b03c60f3 | bellard | break;
|
2333 | 31e31b8a | bellard | case TARGET_NR_query_module:
|
2334 | 5cd4393b | bellard | goto unimplemented;
|
2335 | 31e31b8a | bellard | case TARGET_NR_nfsservctl:
|
2336 | 5cd4393b | bellard | goto unimplemented;
|
2337 | 31e31b8a | bellard | case TARGET_NR_prctl:
|
2338 | 5cd4393b | bellard | goto unimplemented;
|
2339 | 31e31b8a | bellard | case TARGET_NR_pread:
|
2340 | 206f0fa7 | bellard | page_unprotect_range((void *)arg2, arg3);
|
2341 | 206f0fa7 | bellard | ret = get_errno(pread(arg1, (void *)arg2, arg3, arg4));
|
2342 | 206f0fa7 | bellard | break;
|
2343 | 31e31b8a | bellard | case TARGET_NR_pwrite:
|
2344 | 206f0fa7 | bellard | ret = get_errno(pwrite(arg1, (void *)arg2, arg3, arg4));
|
2345 | 206f0fa7 | bellard | break;
|
2346 | 31e31b8a | bellard | case TARGET_NR_chown:
|
2347 | 31e31b8a | bellard | ret = get_errno(chown((const char *)arg1, arg2, arg3)); |
2348 | 31e31b8a | bellard | break;
|
2349 | 31e31b8a | bellard | case TARGET_NR_getcwd:
|
2350 | 72f03900 | bellard | ret = get_errno(sys_getcwd1((char *)arg1, arg2));
|
2351 | 31e31b8a | bellard | break;
|
2352 | 31e31b8a | bellard | case TARGET_NR_capget:
|
2353 | 5cd4393b | bellard | goto unimplemented;
|
2354 | 31e31b8a | bellard | case TARGET_NR_capset:
|
2355 | 5cd4393b | bellard | goto unimplemented;
|
2356 | 31e31b8a | bellard | case TARGET_NR_sigaltstack:
|
2357 | 5cd4393b | bellard | goto unimplemented;
|
2358 | 31e31b8a | bellard | case TARGET_NR_sendfile:
|
2359 | 5cd4393b | bellard | goto unimplemented;
|
2360 | 31e31b8a | bellard | case TARGET_NR_getpmsg:
|
2361 | 5cd4393b | bellard | goto unimplemented;
|
2362 | 31e31b8a | bellard | case TARGET_NR_putpmsg:
|
2363 | 5cd4393b | bellard | goto unimplemented;
|
2364 | 31e31b8a | bellard | case TARGET_NR_vfork:
|
2365 | 1b6b029e | bellard | ret = get_errno(do_fork(cpu_env, CLONE_VFORK | CLONE_VM | SIGCHLD, 0));
|
2366 | 31e31b8a | bellard | break;
|
2367 | 31e31b8a | bellard | case TARGET_NR_ugetrlimit:
|
2368 | 728584be | bellard | { |
2369 | 728584be | bellard | struct rlimit rlim;
|
2370 | 728584be | bellard | ret = get_errno(getrlimit(arg1, &rlim)); |
2371 | 728584be | bellard | if (!is_error(ret)) {
|
2372 | 728584be | bellard | struct target_rlimit *target_rlim = (void *)arg2; |
2373 | 728584be | bellard | target_rlim->rlim_cur = tswapl(rlim.rlim_cur); |
2374 | 728584be | bellard | target_rlim->rlim_max = tswapl(rlim.rlim_max); |
2375 | 728584be | bellard | } |
2376 | 728584be | bellard | break;
|
2377 | 728584be | bellard | } |
2378 | 31e31b8a | bellard | case TARGET_NR_truncate64:
|
2379 | 5cd4393b | bellard | goto unimplemented;
|
2380 | 31e31b8a | bellard | case TARGET_NR_ftruncate64:
|
2381 | 60cd49d5 | bellard | goto unimplemented;
|
2382 | 31e31b8a | bellard | case TARGET_NR_stat64:
|
2383 | ec86b0fb | bellard | ret = get_errno(stat(path((const char *)arg1), &st)); |
2384 | 60cd49d5 | bellard | goto do_stat64;
|
2385 | 31e31b8a | bellard | case TARGET_NR_lstat64:
|
2386 | ec86b0fb | bellard | ret = get_errno(lstat(path((const char *)arg1), &st)); |
2387 | 60cd49d5 | bellard | goto do_stat64;
|
2388 | 31e31b8a | bellard | case TARGET_NR_fstat64:
|
2389 | 60cd49d5 | bellard | { |
2390 | 60cd49d5 | bellard | ret = get_errno(fstat(arg1, &st)); |
2391 | 60cd49d5 | bellard | do_stat64:
|
2392 | 60cd49d5 | bellard | if (!is_error(ret)) {
|
2393 | 60cd49d5 | bellard | struct target_stat64 *target_st = (void *)arg2; |
2394 | ec86b0fb | bellard | memset(target_st, 0, sizeof(struct target_stat64)); |
2395 | 60cd49d5 | bellard | target_st->st_dev = tswap16(st.st_dev); |
2396 | 728584be | bellard | target_st->st_ino = tswap64(st.st_ino); |
2397 | ec86b0fb | bellard | #ifdef TARGET_STAT64_HAS_BROKEN_ST_INO
|
2398 | ec86b0fb | bellard | target_st->__st_ino = tswapl(st.st_ino); |
2399 | ec86b0fb | bellard | #endif
|
2400 | 9af9eaaa | bellard | target_st->st_mode = tswap32(st.st_mode); |
2401 | ec86b0fb | bellard | target_st->st_nlink = tswap32(st.st_nlink); |
2402 | ec86b0fb | bellard | target_st->st_uid = tswapl(st.st_uid); |
2403 | ec86b0fb | bellard | target_st->st_gid = tswapl(st.st_gid); |
2404 | 60cd49d5 | bellard | target_st->st_rdev = tswap16(st.st_rdev); |
2405 | 60cd49d5 | bellard | /* XXX: better use of kernel struct */
|
2406 | ec86b0fb | bellard | target_st->st_size = tswap64(st.st_size); |
2407 | 60cd49d5 | bellard | target_st->st_blksize = tswapl(st.st_blksize); |
2408 | 60cd49d5 | bellard | target_st->st_blocks = tswapl(st.st_blocks); |
2409 | 7854b056 | bellard | target_st->target_st_atime = tswapl(st.st_atime); |
2410 | 7854b056 | bellard | target_st->target_st_mtime = tswapl(st.st_mtime); |
2411 | 7854b056 | bellard | target_st->target_st_ctime = tswapl(st.st_ctime); |
2412 | 60cd49d5 | bellard | } |
2413 | 60cd49d5 | bellard | } |
2414 | 60cd49d5 | bellard | break;
|
2415 | 60cd49d5 | bellard | |
2416 | 31e31b8a | bellard | case TARGET_NR_lchown32:
|
2417 | b03c60f3 | bellard | ret = get_errno(lchown((const char *)arg1, arg2, arg3)); |
2418 | b03c60f3 | bellard | break;
|
2419 | 31e31b8a | bellard | case TARGET_NR_getuid32:
|
2420 | b03c60f3 | bellard | ret = get_errno(getuid()); |
2421 | b03c60f3 | bellard | break;
|
2422 | 31e31b8a | bellard | case TARGET_NR_getgid32:
|
2423 | b03c60f3 | bellard | ret = get_errno(getgid()); |
2424 | b03c60f3 | bellard | break;
|
2425 | 31e31b8a | bellard | case TARGET_NR_geteuid32:
|
2426 | b03c60f3 | bellard | ret = get_errno(geteuid()); |
2427 | b03c60f3 | bellard | break;
|
2428 | 31e31b8a | bellard | case TARGET_NR_getegid32:
|
2429 | b03c60f3 | bellard | ret = get_errno(getegid()); |
2430 | b03c60f3 | bellard | break;
|
2431 | 31e31b8a | bellard | case TARGET_NR_setreuid32:
|
2432 | b03c60f3 | bellard | ret = get_errno(setreuid(arg1, arg2)); |
2433 | b03c60f3 | bellard | break;
|
2434 | 31e31b8a | bellard | case TARGET_NR_setregid32:
|
2435 | b03c60f3 | bellard | ret = get_errno(setregid(arg1, arg2)); |
2436 | b03c60f3 | bellard | break;
|
2437 | 31e31b8a | bellard | case TARGET_NR_getgroups32:
|
2438 | b03c60f3 | bellard | goto unimplemented;
|
2439 | 31e31b8a | bellard | case TARGET_NR_setgroups32:
|
2440 | b03c60f3 | bellard | goto unimplemented;
|
2441 | 31e31b8a | bellard | case TARGET_NR_fchown32:
|
2442 | b03c60f3 | bellard | ret = get_errno(fchown(arg1, arg2, arg3)); |
2443 | b03c60f3 | bellard | break;
|
2444 | 31e31b8a | bellard | case TARGET_NR_setresuid32:
|
2445 | b03c60f3 | bellard | ret = get_errno(setresuid(arg1, arg2, arg3)); |
2446 | b03c60f3 | bellard | break;
|
2447 | 31e31b8a | bellard | case TARGET_NR_getresuid32:
|
2448 | b03c60f3 | bellard | { |
2449 | b03c60f3 | bellard | int ruid, euid, suid;
|
2450 | b03c60f3 | bellard | ret = get_errno(getresuid(&ruid, &euid, &suid)); |
2451 | b03c60f3 | bellard | if (!is_error(ret)) {
|
2452 | b03c60f3 | bellard | *(uint32_t *)arg1 = tswap32(ruid); |
2453 | b03c60f3 | bellard | *(uint32_t *)arg2 = tswap32(euid); |
2454 | b03c60f3 | bellard | *(uint32_t *)arg3 = tswap32(suid); |
2455 | b03c60f3 | bellard | } |
2456 | b03c60f3 | bellard | } |
2457 | b03c60f3 | bellard | break;
|
2458 | 31e31b8a | bellard | case TARGET_NR_setresgid32:
|
2459 | b03c60f3 | bellard | ret = get_errno(setresgid(arg1, arg2, arg3)); |
2460 | b03c60f3 | bellard | break;
|
2461 | 31e31b8a | bellard | case TARGET_NR_getresgid32:
|
2462 | b03c60f3 | bellard | { |
2463 | b03c60f3 | bellard | int rgid, egid, sgid;
|
2464 | b03c60f3 | bellard | ret = get_errno(getresgid(&rgid, &egid, &sgid)); |
2465 | b03c60f3 | bellard | if (!is_error(ret)) {
|
2466 | b03c60f3 | bellard | *(uint32_t *)arg1 = tswap32(rgid); |
2467 | b03c60f3 | bellard | *(uint32_t *)arg2 = tswap32(egid); |
2468 | b03c60f3 | bellard | *(uint32_t *)arg3 = tswap32(sgid); |
2469 | b03c60f3 | bellard | } |
2470 | b03c60f3 | bellard | } |
2471 | b03c60f3 | bellard | break;
|
2472 | 31e31b8a | bellard | case TARGET_NR_chown32:
|
2473 | b03c60f3 | bellard | ret = get_errno(chown((const char *)arg1, arg2, arg3)); |
2474 | b03c60f3 | bellard | break;
|
2475 | 31e31b8a | bellard | case TARGET_NR_setuid32:
|
2476 | b03c60f3 | bellard | ret = get_errno(setuid(arg1)); |
2477 | b03c60f3 | bellard | break;
|
2478 | 31e31b8a | bellard | case TARGET_NR_setgid32:
|
2479 | b03c60f3 | bellard | ret = get_errno(setgid(arg1)); |
2480 | b03c60f3 | bellard | break;
|
2481 | 31e31b8a | bellard | case TARGET_NR_setfsuid32:
|
2482 | b03c60f3 | bellard | ret = get_errno(setfsuid(arg1)); |
2483 | b03c60f3 | bellard | break;
|
2484 | 31e31b8a | bellard | case TARGET_NR_setfsgid32:
|
2485 | b03c60f3 | bellard | ret = get_errno(setfsgid(arg1)); |
2486 | b03c60f3 | bellard | break;
|
2487 | 31e31b8a | bellard | case TARGET_NR_pivot_root:
|
2488 | b03c60f3 | bellard | goto unimplemented;
|
2489 | 31e31b8a | bellard | case TARGET_NR_mincore:
|
2490 | b03c60f3 | bellard | goto unimplemented;
|
2491 | 31e31b8a | bellard | case TARGET_NR_madvise:
|
2492 | 60cd49d5 | bellard | goto unimplemented;
|
2493 | 60cd49d5 | bellard | #if TARGET_LONG_BITS == 32 |
2494 | 31e31b8a | bellard | case TARGET_NR_fcntl64:
|
2495 | 77e4672d | bellard | { |
2496 | 77e4672d | bellard | struct flock64 fl;
|
2497 | 77e4672d | bellard | struct target_flock64 *target_fl = (void *)arg3; |
2498 | 77e4672d | bellard | |
2499 | 60cd49d5 | bellard | switch(arg2) {
|
2500 | 60cd49d5 | bellard | case F_GETLK64:
|
2501 | 77e4672d | bellard | ret = get_errno(fcntl(arg1, arg2, &fl)); |
2502 | 77e4672d | bellard | if (ret == 0) { |
2503 | 77e4672d | bellard | target_fl->l_type = tswap16(fl.l_type); |
2504 | 77e4672d | bellard | target_fl->l_whence = tswap16(fl.l_whence); |
2505 | 77e4672d | bellard | target_fl->l_start = tswap64(fl.l_start); |
2506 | 77e4672d | bellard | target_fl->l_len = tswap64(fl.l_len); |
2507 | 77e4672d | bellard | target_fl->l_pid = tswapl(fl.l_pid); |
2508 | 77e4672d | bellard | } |
2509 | 77e4672d | bellard | break;
|
2510 | 77e4672d | bellard | |
2511 | 60cd49d5 | bellard | case F_SETLK64:
|
2512 | 60cd49d5 | bellard | case F_SETLKW64:
|
2513 | 77e4672d | bellard | fl.l_type = tswap16(target_fl->l_type); |
2514 | 77e4672d | bellard | fl.l_whence = tswap16(target_fl->l_whence); |
2515 | 77e4672d | bellard | fl.l_start = tswap64(target_fl->l_start); |
2516 | 77e4672d | bellard | fl.l_len = tswap64(target_fl->l_len); |
2517 | 77e4672d | bellard | fl.l_pid = tswapl(target_fl->l_pid); |
2518 | 77e4672d | bellard | ret = get_errno(fcntl(arg1, arg2, &fl)); |
2519 | 77e4672d | bellard | break;
|
2520 | 60cd49d5 | bellard | default:
|
2521 | 7775e9ec | bellard | ret = get_errno(do_fcntl(arg1, arg2, arg3)); |
2522 | 60cd49d5 | bellard | break;
|
2523 | 60cd49d5 | bellard | } |
2524 | 77e4672d | bellard | break;
|
2525 | 77e4672d | bellard | } |
2526 | 60cd49d5 | bellard | #endif
|
2527 | 31e31b8a | bellard | case TARGET_NR_security:
|
2528 | 31e31b8a | bellard | goto unimplemented;
|
2529 | 31e31b8a | bellard | case TARGET_NR_gettid:
|
2530 | 31e31b8a | bellard | ret = get_errno(gettid()); |
2531 | 31e31b8a | bellard | break;
|
2532 | 31e31b8a | bellard | case TARGET_NR_readahead:
|
2533 | 5cd4393b | bellard | goto unimplemented;
|
2534 | 31e31b8a | bellard | case TARGET_NR_setxattr:
|
2535 | 31e31b8a | bellard | case TARGET_NR_lsetxattr:
|
2536 | 31e31b8a | bellard | case TARGET_NR_fsetxattr:
|
2537 | 31e31b8a | bellard | case TARGET_NR_getxattr:
|
2538 | 31e31b8a | bellard | case TARGET_NR_lgetxattr:
|
2539 | 31e31b8a | bellard | case TARGET_NR_fgetxattr:
|
2540 | 31e31b8a | bellard | case TARGET_NR_listxattr:
|
2541 | 31e31b8a | bellard | case TARGET_NR_llistxattr:
|
2542 | 31e31b8a | bellard | case TARGET_NR_flistxattr:
|
2543 | 31e31b8a | bellard | case TARGET_NR_removexattr:
|
2544 | 31e31b8a | bellard | case TARGET_NR_lremovexattr:
|
2545 | 31e31b8a | bellard | case TARGET_NR_fremovexattr:
|
2546 | 5cd4393b | bellard | goto unimplemented_nowarn;
|
2547 | 5cd4393b | bellard | case TARGET_NR_set_thread_area:
|
2548 | 5cd4393b | bellard | case TARGET_NR_get_thread_area:
|
2549 | 5cd4393b | bellard | goto unimplemented_nowarn;
|
2550 | 31e31b8a | bellard | default:
|
2551 | 31e31b8a | bellard | unimplemented:
|
2552 | 5cd4393b | bellard | gemu_log("qemu: Unsupported syscall: %d\n", num);
|
2553 | 5cd4393b | bellard | unimplemented_nowarn:
|
2554 | 31e31b8a | bellard | ret = -ENOSYS; |
2555 | 31e31b8a | bellard | break;
|
2556 | 31e31b8a | bellard | } |
2557 | 31e31b8a | bellard | fail:
|
2558 | 31e31b8a | bellard | return ret;
|
2559 | 31e31b8a | bellard | } |