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