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