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