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