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