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