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