root / darwin-user / syscall.c @ 73f5e313
History | View | Annotate | Download (48.2 kB)
1 | 831b7825 | ths | /*
|
---|---|---|---|
2 | 831b7825 | ths | * Darwin syscalls
|
3 | 831b7825 | ths | *
|
4 | 831b7825 | ths | * Copyright (c) 2003 Fabrice Bellard
|
5 | 831b7825 | ths | * Copyright (c) 2006 Pierre d'Herbemont
|
6 | 831b7825 | ths | *
|
7 | 831b7825 | ths | * This program is free software; you can redistribute it and/or modify
|
8 | 831b7825 | ths | * it under the terms of the GNU General Public License as published by
|
9 | 831b7825 | ths | * the Free Software Foundation; either version 2 of the License, or
|
10 | 831b7825 | ths | * (at your option) any later version.
|
11 | 831b7825 | ths | *
|
12 | 831b7825 | ths | * This program is distributed in the hope that it will be useful,
|
13 | 831b7825 | ths | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 | 831b7825 | ths | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 | 831b7825 | ths | * GNU General Public License for more details.
|
16 | 831b7825 | ths | *
|
17 | 831b7825 | ths | * You should have received a copy of the GNU General Public License
|
18 | 8167ee88 | Blue Swirl | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
19 | 831b7825 | ths | */
|
20 | 831b7825 | ths | #include <fcntl.h> |
21 | 831b7825 | ths | #include <stdio.h> |
22 | 831b7825 | ths | #include <stdlib.h> |
23 | 831b7825 | ths | #include <errno.h> |
24 | 831b7825 | ths | |
25 | 263466f5 | bellard | #include <mach/host_info.h> |
26 | 831b7825 | ths | #include <mach/mach.h> |
27 | 831b7825 | ths | #include <mach/mach_time.h> |
28 | 263466f5 | bellard | #include <mach/message.h> |
29 | 831b7825 | ths | |
30 | 831b7825 | ths | #include <pthread.h> |
31 | 831b7825 | ths | #include <dirent.h> |
32 | 831b7825 | ths | |
33 | 831b7825 | ths | #include <sys/stat.h> |
34 | 831b7825 | ths | #include <sys/syscall.h> |
35 | 831b7825 | ths | #include <sys/sysctl.h> |
36 | 831b7825 | ths | #include <sys/types.h> |
37 | 831b7825 | ths | #include <unistd.h> |
38 | 831b7825 | ths | #include <sys/ioctl.h> |
39 | 831b7825 | ths | #include <sys/mman.h> |
40 | 831b7825 | ths | #include <sys/types.h> |
41 | 831b7825 | ths | #include <sys/dirent.h> |
42 | 831b7825 | ths | #include <sys/uio.h> |
43 | 831b7825 | ths | #include <sys/termios.h> |
44 | 831b7825 | ths | #include <sys/ptrace.h> |
45 | 831b7825 | ths | #include <net/if.h> |
46 | 831b7825 | ths | |
47 | 831b7825 | ths | #include <sys/param.h> |
48 | 831b7825 | ths | #include <sys/mount.h> |
49 | 831b7825 | ths | |
50 | 831b7825 | ths | #include <sys/attr.h> |
51 | 831b7825 | ths | |
52 | 831b7825 | ths | #include <mach/ndr.h> |
53 | 831b7825 | ths | #include <mach/mig_errors.h> |
54 | 831b7825 | ths | |
55 | ee999a88 | ths | #include <sys/xattr.h> |
56 | ee999a88 | ths | |
57 | 831b7825 | ths | #include "qemu.h" |
58 | 831b7825 | ths | |
59 | 831b7825 | ths | //#define DEBUG_SYSCALL
|
60 | 831b7825 | ths | |
61 | 831b7825 | ths | #ifdef DEBUG_SYSCALL
|
62 | 831b7825 | ths | # define DEBUG_FORCE_ENABLE_LOCAL() int __DEBUG_qemu_user_force_enable = 1 |
63 | 831b7825 | ths | # define DEBUG_BEGIN_ENABLE __DEBUG_qemu_user_force_enable = 1; |
64 | 831b7825 | ths | # define DEBUG_END_ENABLE __DEBUG_qemu_user_force_enable = 0; |
65 | 831b7825 | ths | |
66 | 831b7825 | ths | # define DEBUG_DISABLE_ALL() static int __DEBUG_qemu_user_force_enable = 0 |
67 | 831b7825 | ths | # define DEBUG_ENABLE_ALL() static int __DEBUG_qemu_user_force_enable = 1 |
68 | 831b7825 | ths | DEBUG_ENABLE_ALL(); |
69 | 831b7825 | ths | |
70 | 93fcfe39 | aliguori | # define DPRINTF(...) do { qemu_log(__VA_ARGS__); \ |
71 | 831b7825 | ths | if(__DEBUG_qemu_user_force_enable) fprintf(stderr, __VA_ARGS__); \
|
72 | 831b7825 | ths | } while(0) |
73 | 831b7825 | ths | #else
|
74 | 831b7825 | ths | # define DEBUG_FORCE_ENABLE_LOCAL()
|
75 | 831b7825 | ths | # define DEBUG_BEGIN_ENABLE
|
76 | 831b7825 | ths | # define DEBUG_END_ENABLE
|
77 | 831b7825 | ths | |
78 | 93fcfe39 | aliguori | # define DPRINTF(...) do { qemu_log(__VA_ARGS__); } while(0) |
79 | 831b7825 | ths | #endif
|
80 | 831b7825 | ths | |
81 | 831b7825 | ths | enum {
|
82 | 831b7825 | ths | bswap_out = 0,
|
83 | 831b7825 | ths | bswap_in = 1
|
84 | 831b7825 | ths | }; |
85 | 831b7825 | ths | |
86 | 831b7825 | ths | extern const char *interp_prefix; |
87 | 831b7825 | ths | |
88 | 831b7825 | ths | static inline long get_errno(long ret) |
89 | 831b7825 | ths | { |
90 | 831b7825 | ths | if (ret == -1) |
91 | 831b7825 | ths | return -errno;
|
92 | 831b7825 | ths | else
|
93 | 831b7825 | ths | return ret;
|
94 | 831b7825 | ths | } |
95 | 831b7825 | ths | |
96 | 831b7825 | ths | static inline int is_error(long ret) |
97 | 831b7825 | ths | { |
98 | 831b7825 | ths | return (unsigned long)ret >= (unsigned long)(-4096); |
99 | 831b7825 | ths | } |
100 | 831b7825 | ths | |
101 | 831b7825 | ths | /* ------------------------------------------------------------
|
102 | 831b7825 | ths | Mach syscall handling
|
103 | 831b7825 | ths | */
|
104 | 831b7825 | ths | |
105 | 831b7825 | ths | void static inline print_description_msg_header(mach_msg_header_t *hdr) |
106 | 831b7825 | ths | { |
107 | 831b7825 | ths | char *name = NULL; |
108 | 831b7825 | ths | int i;
|
109 | 831b7825 | ths | struct { int number; char *name; } msg_name[] = |
110 | 831b7825 | ths | { |
111 | 831b7825 | ths | /* see http://fxr.watson.org/fxr/source/compat/mach/mach_namemap.c?v=NETBSD */
|
112 | 831b7825 | ths | { 200, "host_info" }, |
113 | 831b7825 | ths | { 202, "host_page_size" }, |
114 | 831b7825 | ths | { 206, "host_get_clock_service" }, |
115 | 831b7825 | ths | { 206, "host_get_clock_service" }, |
116 | 831b7825 | ths | { 206, "host_get_clock_service" }, |
117 | 831b7825 | ths | { 306, "host_get_clock_service" }, |
118 | 831b7825 | ths | { 3204, "mach_port_allocate" }, |
119 | 831b7825 | ths | { 3206, "mach_port_deallocate" }, |
120 | 831b7825 | ths | { 3404, "mach_ports_lookup" }, |
121 | 831b7825 | ths | { 3409, "mach_task_get_special_port" }, |
122 | 831b7825 | ths | { 3414, "mach_task_get_exception_ports" }, |
123 | 831b7825 | ths | { 3418, "mach_semaphore_create" }, |
124 | 831b7825 | ths | { 3504, "mach_semaphore_create" }, |
125 | 831b7825 | ths | { 3509, "mach_semaphore_create" }, |
126 | 831b7825 | ths | { 3518, "semaphore_create" }, |
127 | 831b7825 | ths | { 3616, "thread_policy" }, |
128 | 831b7825 | ths | { 3801, "vm_allocate" }, |
129 | 831b7825 | ths | { 3802, "vm_deallocate" }, |
130 | 831b7825 | ths | { 3802, "vm_deallocate" }, |
131 | 831b7825 | ths | { 3803, "vm_protect" }, |
132 | 831b7825 | ths | { 3812, "vm_map" }, |
133 | 831b7825 | ths | { 4241776, "lu_message_send_id" }, /* lookupd */ |
134 | 831b7825 | ths | { 4241876, "lu_message_reply_id" }, /* lookupd */ |
135 | 831b7825 | ths | }; |
136 | 831b7825 | ths | |
137 | b1503cda | malc | for(i = 0; i < ARRAY_SIZE(msg_name); i++) { |
138 | 831b7825 | ths | if(msg_name[i].number == hdr->msgh_id)
|
139 | 831b7825 | ths | { |
140 | 831b7825 | ths | name = msg_name[i].name; |
141 | 831b7825 | ths | break;
|
142 | 831b7825 | ths | } |
143 | 831b7825 | ths | } |
144 | 831b7825 | ths | if(!name)
|
145 | 831b7825 | ths | DPRINTF("unknown mach msg %d 0x%x\n", hdr->msgh_id, hdr->msgh_id);
|
146 | 831b7825 | ths | else
|
147 | 831b7825 | ths | DPRINTF("%s\n", name);
|
148 | 831b7825 | ths | #if 0
|
149 | 831b7825 | ths | DPRINTF("Bits: %8x\n", hdr->msgh_bits);
|
150 | 831b7825 | ths | DPRINTF("Size: %8x\n", hdr->msgh_size);
|
151 | 831b7825 | ths | DPRINTF("Rmte: %8x\n", hdr->msgh_remote_port);
|
152 | 831b7825 | ths | DPRINTF("Locl: %8x\n", hdr->msgh_local_port);
|
153 | 831b7825 | ths | DPRINTF("Rsrv: %8x\n", hdr->msgh_reserved);
|
154 | 831b7825 | ths | |
155 | 831b7825 | ths | DPRINTF("Id : %8x\n", hdr->msgh_id);
|
156 | 831b7825 | ths | |
157 | 831b7825 | ths | NDR_record_t *ndr = (NDR_record_t *)(hdr + 1);
|
158 | 831b7825 | ths | DPRINTF("hdr = %p, sizeof(hdr) = %x, NDR = %p\n", hdr, (unsigned int)sizeof(mach_msg_header_t), ndr);
|
159 | 831b7825 | ths | DPRINTF("%d %d %d %d %d %d %d %d\n",
|
160 | 831b7825 | ths | ndr->mig_vers, ndr->if_vers, ndr->reserved1, ndr->mig_encoding,
|
161 | 831b7825 | ths | ndr->int_rep, ndr->char_rep, ndr->float_rep, ndr->reserved2);
|
162 | 831b7825 | ths | #endif
|
163 | 831b7825 | ths | } |
164 | 831b7825 | ths | |
165 | 831b7825 | ths | static inline void print_mach_msg_return(mach_msg_return_t ret) |
166 | 831b7825 | ths | { |
167 | 831b7825 | ths | int i, found = 0; |
168 | 831b7825 | ths | #define MACH_MSG_RET(msg) { msg, #msg } |
169 | 831b7825 | ths | struct { int code; char *name; } msg_name[] = |
170 | 831b7825 | ths | { |
171 | 831b7825 | ths | /* ref: http://darwinsource.opendarwin.org/10.4.2/xnu-792.2.4/osfmk/man/mach_msg.html */
|
172 | 831b7825 | ths | /* send message */
|
173 | 831b7825 | ths | MACH_MSG_RET(MACH_SEND_MSG_TOO_SMALL), |
174 | 831b7825 | ths | MACH_MSG_RET(MACH_SEND_NO_BUFFER), |
175 | 831b7825 | ths | MACH_MSG_RET(MACH_SEND_INVALID_DATA), |
176 | 831b7825 | ths | MACH_MSG_RET(MACH_SEND_INVALID_HEADER), |
177 | 831b7825 | ths | MACH_MSG_RET(MACH_SEND_INVALID_DEST), |
178 | 831b7825 | ths | MACH_MSG_RET(MACH_SEND_INVALID_NOTIFY), |
179 | 831b7825 | ths | MACH_MSG_RET(MACH_SEND_INVALID_REPLY), |
180 | 831b7825 | ths | MACH_MSG_RET(MACH_SEND_INVALID_TRAILER), |
181 | 831b7825 | ths | MACH_MSG_RET(MACH_SEND_INVALID_MEMORY), |
182 | 831b7825 | ths | MACH_MSG_RET(MACH_SEND_INVALID_RIGHT), |
183 | 831b7825 | ths | MACH_MSG_RET(MACH_SEND_INVALID_TYPE), |
184 | 831b7825 | ths | MACH_MSG_RET(MACH_SEND_INTERRUPTED), |
185 | 831b7825 | ths | MACH_MSG_RET(MACH_SEND_TIMED_OUT), |
186 | 831b7825 | ths | |
187 | 831b7825 | ths | MACH_MSG_RET(MACH_RCV_BODY_ERROR), |
188 | 831b7825 | ths | MACH_MSG_RET(MACH_RCV_HEADER_ERROR), |
189 | 831b7825 | ths | |
190 | 831b7825 | ths | MACH_MSG_RET(MACH_RCV_IN_SET), |
191 | 831b7825 | ths | MACH_MSG_RET(MACH_RCV_INTERRUPTED), |
192 | 831b7825 | ths | |
193 | 831b7825 | ths | MACH_MSG_RET(MACH_RCV_INVALID_DATA), |
194 | 831b7825 | ths | MACH_MSG_RET(MACH_RCV_INVALID_NAME), |
195 | 831b7825 | ths | MACH_MSG_RET(MACH_RCV_INVALID_NOTIFY), |
196 | 831b7825 | ths | MACH_MSG_RET(MACH_RCV_INVALID_TRAILER), |
197 | 831b7825 | ths | MACH_MSG_RET(MACH_RCV_INVALID_TYPE), |
198 | 831b7825 | ths | |
199 | 831b7825 | ths | MACH_MSG_RET(MACH_RCV_PORT_CHANGED), |
200 | 831b7825 | ths | MACH_MSG_RET(MACH_RCV_PORT_DIED), |
201 | 831b7825 | ths | |
202 | 831b7825 | ths | MACH_MSG_RET(MACH_RCV_SCATTER_SMALL), |
203 | 831b7825 | ths | MACH_MSG_RET(MACH_RCV_TIMED_OUT), |
204 | 831b7825 | ths | MACH_MSG_RET(MACH_RCV_TOO_LARGE) |
205 | 831b7825 | ths | }; |
206 | 831b7825 | ths | #undef MACH_MSG_RET
|
207 | 831b7825 | ths | |
208 | 831b7825 | ths | if( ret == MACH_MSG_SUCCESS)
|
209 | 831b7825 | ths | DPRINTF("MACH_MSG_SUCCESS\n");
|
210 | 831b7825 | ths | else
|
211 | 831b7825 | ths | { |
212 | b1503cda | malc | for( i = 0; i < ARRAY_SIZE(msg_name); i++) { |
213 | 263466f5 | bellard | if(msg_name[i].code == ret) {
|
214 | 263466f5 | bellard | DPRINTF("%s\n", msg_name[i].name);
|
215 | 831b7825 | ths | found = 1;
|
216 | 263466f5 | bellard | break;
|
217 | 831b7825 | ths | } |
218 | 831b7825 | ths | } |
219 | 831b7825 | ths | if(!found)
|
220 | 831b7825 | ths | qerror("unknow mach message ret code %d\n", ret);
|
221 | 831b7825 | ths | } |
222 | 831b7825 | ths | } |
223 | 831b7825 | ths | |
224 | 831b7825 | ths | static inline void swap_mach_msg_header(mach_msg_header_t *hdr) |
225 | 831b7825 | ths | { |
226 | 831b7825 | ths | hdr->msgh_bits = tswap32(hdr->msgh_bits); |
227 | 831b7825 | ths | hdr->msgh_size = tswap32(hdr->msgh_size); |
228 | 831b7825 | ths | hdr->msgh_remote_port = tswap32(hdr->msgh_remote_port); |
229 | 831b7825 | ths | hdr->msgh_local_port = tswap32(hdr->msgh_local_port); |
230 | 831b7825 | ths | hdr->msgh_reserved = tswap32(hdr->msgh_reserved); |
231 | 831b7825 | ths | hdr->msgh_id = tswap32(hdr->msgh_id); |
232 | 831b7825 | ths | } |
233 | 831b7825 | ths | |
234 | 831b7825 | ths | struct complex_msg {
|
235 | 831b7825 | ths | mach_msg_header_t hdr; |
236 | 831b7825 | ths | mach_msg_body_t body; |
237 | 831b7825 | ths | }; |
238 | 831b7825 | ths | |
239 | 263466f5 | bellard | static inline void swap_mach_msg_body(struct complex_msg *complex_msg, int bswap) |
240 | 831b7825 | ths | { |
241 | 831b7825 | ths | mach_msg_port_descriptor_t *descr = (mach_msg_port_descriptor_t *)(complex_msg+1);
|
242 | 831b7825 | ths | int i,j;
|
243 | 831b7825 | ths | |
244 | 831b7825 | ths | if(bswap == bswap_in)
|
245 | 831b7825 | ths | tswap32s(&complex_msg->body.msgh_descriptor_count); |
246 | 831b7825 | ths | |
247 | 831b7825 | ths | DPRINTF("body.msgh_descriptor_count %d\n", complex_msg->body.msgh_descriptor_count);
|
248 | 831b7825 | ths | |
249 | 831b7825 | ths | for(i = 0; i < complex_msg->body.msgh_descriptor_count; i++) { |
250 | 831b7825 | ths | switch(descr->type)
|
251 | 831b7825 | ths | { |
252 | 831b7825 | ths | case MACH_MSG_PORT_DESCRIPTOR:
|
253 | 831b7825 | ths | tswap32s(&descr->name); |
254 | 831b7825 | ths | descr++; |
255 | 831b7825 | ths | break;
|
256 | 831b7825 | ths | case MACH_MSG_OOL_DESCRIPTOR:
|
257 | 831b7825 | ths | { |
258 | 831b7825 | ths | mach_msg_ool_descriptor_t *ool = (void *)descr;
|
259 | 831b7825 | ths | tswap32s((uint32_t *)&ool->address); |
260 | 831b7825 | ths | tswap32s(&ool->size); |
261 | 831b7825 | ths | |
262 | 831b7825 | ths | descr = (mach_msg_port_descriptor_t *)(ool+1);
|
263 | 831b7825 | ths | break;
|
264 | 831b7825 | ths | } |
265 | 831b7825 | ths | case MACH_MSG_OOL_PORTS_DESCRIPTOR:
|
266 | 831b7825 | ths | { |
267 | 831b7825 | ths | mach_msg_ool_ports_descriptor_t *ool_ports = (void *)descr;
|
268 | 831b7825 | ths | mach_port_name_t * port_names; |
269 | 831b7825 | ths | |
270 | 831b7825 | ths | if(bswap == bswap_in)
|
271 | 831b7825 | ths | { |
272 | 831b7825 | ths | tswap32s((uint32_t *)&ool_ports->address); |
273 | 831b7825 | ths | tswap32s(&ool_ports->count); |
274 | 831b7825 | ths | } |
275 | 831b7825 | ths | |
276 | 831b7825 | ths | port_names = ool_ports->address; |
277 | 831b7825 | ths | |
278 | 831b7825 | ths | for(j = 0; j < ool_ports->count; j++) |
279 | 831b7825 | ths | tswap32s(&port_names[j]); |
280 | 831b7825 | ths | |
281 | 831b7825 | ths | if(bswap == bswap_out)
|
282 | 831b7825 | ths | { |
283 | 831b7825 | ths | tswap32s((uint32_t *)&ool_ports->address); |
284 | 831b7825 | ths | tswap32s(&ool_ports->count); |
285 | 831b7825 | ths | } |
286 | 831b7825 | ths | |
287 | 831b7825 | ths | descr = (mach_msg_port_descriptor_t *)(ool_ports+1);
|
288 | 831b7825 | ths | break;
|
289 | 831b7825 | ths | } |
290 | 831b7825 | ths | default: qerror("unknow mach msg descriptor type %x\n", descr->type); |
291 | 831b7825 | ths | } |
292 | 831b7825 | ths | } |
293 | 831b7825 | ths | if(bswap == bswap_out)
|
294 | 831b7825 | ths | tswap32s(&complex_msg->body.msgh_descriptor_count); |
295 | 263466f5 | bellard | } |
296 | 263466f5 | bellard | |
297 | 263466f5 | bellard | static inline void swap_mach_msg(mach_msg_header_t *hdr, int bswap) |
298 | 263466f5 | bellard | { |
299 | 263466f5 | bellard | if (bswap == bswap_out && hdr->msgh_bits & MACH_MSGH_BITS_COMPLEX)
|
300 | 263466f5 | bellard | swap_mach_msg_body((struct complex_msg *)hdr, bswap);
|
301 | 263466f5 | bellard | |
302 | 263466f5 | bellard | swap_mach_msg_header(hdr); |
303 | 263466f5 | bellard | |
304 | 263466f5 | bellard | if (bswap == bswap_in && hdr->msgh_bits & MACH_MSGH_BITS_COMPLEX)
|
305 | 263466f5 | bellard | swap_mach_msg_body((struct complex_msg *)hdr, bswap);
|
306 | 831b7825 | ths | } |
307 | 831b7825 | ths | |
308 | 831b7825 | ths | static inline uint32_t target_mach_msg_trap( |
309 | 831b7825 | ths | mach_msg_header_t *hdr, uint32_t options, uint32_t send_size, |
310 | 263466f5 | bellard | uint32_t rcv_size, uint32_t rcv_name, uint32_t time_out, uint32_t notify) |
311 | 831b7825 | ths | { |
312 | 263466f5 | bellard | extern int mach_msg_trap(mach_msg_header_t *, mach_msg_option_t, |
313 | 263466f5 | bellard | mach_msg_size_t, mach_msg_size_t, mach_port_t, |
314 | 263466f5 | bellard | mach_msg_timeout_t, mach_port_t); |
315 | 831b7825 | ths | mach_msg_audit_trailer_t *trailer; |
316 | 831b7825 | ths | mach_msg_id_t msg_id; |
317 | 831b7825 | ths | uint32_t ret = 0;
|
318 | 831b7825 | ths | int i;
|
319 | 831b7825 | ths | |
320 | 263466f5 | bellard | swap_mach_msg(hdr, bswap_in); |
321 | 831b7825 | ths | |
322 | 831b7825 | ths | msg_id = hdr->msgh_id; |
323 | 831b7825 | ths | |
324 | 263466f5 | bellard | print_description_msg_header(hdr); |
325 | 831b7825 | ths | |
326 | 831b7825 | ths | ret = mach_msg_trap(hdr, options, send_size, rcv_size, rcv_name, time_out, notify); |
327 | 831b7825 | ths | |
328 | 831b7825 | ths | print_mach_msg_return(ret); |
329 | 831b7825 | ths | |
330 | 831b7825 | ths | if( (options & MACH_RCV_MSG) && (REQUESTED_TRAILER_SIZE(options) > 0) ) |
331 | 831b7825 | ths | { |
332 | 831b7825 | ths | /* XXX: the kernel always return the full trailer with MACH_SEND_MSG, so we should
|
333 | 831b7825 | ths | probably always bswap it */
|
334 | 831b7825 | ths | /* warning: according to Mac OS X Internals (the book) msg_size might be expressed in
|
335 | 831b7825 | ths | natural_t units but according to xnu/osfmk/mach/message.h: "The size of
|
336 | 831b7825 | ths | the message must be specified in bytes" */
|
337 | 831b7825 | ths | trailer = (mach_msg_audit_trailer_t *)((uint8_t *)hdr + hdr->msgh_size); |
338 | 831b7825 | ths | /* XXX: Should probably do that based on the option asked by the sender, but dealing
|
339 | 831b7825 | ths | with kernel answer seems more sound */
|
340 | 831b7825 | ths | switch(trailer->msgh_trailer_size)
|
341 | 831b7825 | ths | { |
342 | 831b7825 | ths | case sizeof(mach_msg_audit_trailer_t): |
343 | 831b7825 | ths | for(i = 0; i < 8; i++) |
344 | 831b7825 | ths | tswap32s(&trailer->msgh_audit.val[i]); |
345 | 831b7825 | ths | /* Fall in mach_msg_security_trailer_t case */
|
346 | 831b7825 | ths | case sizeof(mach_msg_security_trailer_t): |
347 | 831b7825 | ths | tswap32s(&trailer->msgh_sender.val[0]);
|
348 | 831b7825 | ths | tswap32s(&trailer->msgh_sender.val[1]);
|
349 | 831b7825 | ths | /* Fall in mach_msg_seqno_trailer_t case */
|
350 | 831b7825 | ths | case sizeof(mach_msg_seqno_trailer_t): |
351 | 831b7825 | ths | tswap32s(&trailer->msgh_seqno); |
352 | 831b7825 | ths | /* Fall in mach_msg_trailer_t case */
|
353 | 831b7825 | ths | case sizeof(mach_msg_trailer_t): |
354 | 831b7825 | ths | tswap32s(&trailer->msgh_trailer_type); |
355 | 831b7825 | ths | tswap32s(&trailer->msgh_trailer_size); |
356 | 831b7825 | ths | break;
|
357 | 831b7825 | ths | case 0: |
358 | 831b7825 | ths | /* Safer not to byteswap, but probably wrong */
|
359 | 831b7825 | ths | break;
|
360 | 831b7825 | ths | default:
|
361 | 831b7825 | ths | qerror("unknow trailer type given its size %d\n", trailer->msgh_trailer_size);
|
362 | 831b7825 | ths | break;
|
363 | 831b7825 | ths | } |
364 | 831b7825 | ths | } |
365 | 831b7825 | ths | |
366 | 831b7825 | ths | /* Special message handling */
|
367 | 831b7825 | ths | switch (msg_id) {
|
368 | 831b7825 | ths | case 200: /* host_info */ |
369 | 831b7825 | ths | { |
370 | 831b7825 | ths | mig_reply_error_t *err = (mig_reply_error_t *)hdr; |
371 | 7ed40acf | ths | struct {
|
372 | 7ed40acf | ths | uint32_t unknow1; |
373 | 7ed40acf | ths | uint32_t max_cpus; |
374 | 7ed40acf | ths | uint32_t avail_cpus; |
375 | 7ed40acf | ths | uint32_t memory_size; |
376 | 7ed40acf | ths | uint32_t cpu_type; |
377 | 7ed40acf | ths | uint32_t cpu_subtype; |
378 | 7ed40acf | ths | } *data = (void *)(err+1); |
379 | 263466f5 | bellard | |
380 | 263466f5 | bellard | DPRINTF("maxcpu = 0x%x\n", data->max_cpus);
|
381 | 263466f5 | bellard | DPRINTF("numcpu = 0x%x\n", data->avail_cpus);
|
382 | 263466f5 | bellard | DPRINTF("memsize = 0x%x\n", data->memory_size);
|
383 | 831b7825 | ths | |
384 | 831b7825 | ths | #if defined(TARGET_I386)
|
385 | 831b7825 | ths | data->cpu_type = CPU_TYPE_I386; |
386 | 831b7825 | ths | DPRINTF("cpu_type changed to 0x%x(i386)\n", data->cpu_type);
|
387 | 831b7825 | ths | data->cpu_subtype = CPU_SUBTYPE_PENT; |
388 | 831b7825 | ths | DPRINTF("cpu_subtype changed to 0x%x(i386_pent)\n", data->cpu_subtype);
|
389 | 831b7825 | ths | #elif defined(TARGET_PPC)
|
390 | 263466f5 | bellard | data->cpu_type = CPU_TYPE_POWERPC; |
391 | 263466f5 | bellard | DPRINTF("cpu_type changed to 0x%x(ppc)\n", data->cpu_type);
|
392 | 831b7825 | ths | data->cpu_subtype = CPU_SUBTYPE_POWERPC_750; |
393 | 831b7825 | ths | DPRINTF("cpu_subtype changed to 0x%x(ppc_all)\n", data->cpu_subtype);
|
394 | 831b7825 | ths | #else
|
395 | 831b7825 | ths | # error target not supported
|
396 | 831b7825 | ths | #endif
|
397 | 831b7825 | ths | break;
|
398 | 831b7825 | ths | } |
399 | 831b7825 | ths | case 202: /* host_page_size */ |
400 | 831b7825 | ths | { |
401 | 831b7825 | ths | mig_reply_error_t *err = (mig_reply_error_t *)hdr; |
402 | 831b7825 | ths | uint32_t *pagesize = (uint32_t *)(err+1);
|
403 | 831b7825 | ths | |
404 | 831b7825 | ths | DPRINTF("pagesize = %d\n", *pagesize);
|
405 | 831b7825 | ths | break;
|
406 | 831b7825 | ths | } |
407 | 831b7825 | ths | default: break; |
408 | 831b7825 | ths | } |
409 | 831b7825 | ths | |
410 | 263466f5 | bellard | swap_mach_msg(hdr, bswap_out); |
411 | 831b7825 | ths | |
412 | 831b7825 | ths | return ret;
|
413 | 831b7825 | ths | } |
414 | 831b7825 | ths | |
415 | 831b7825 | ths | long do_mach_syscall(void *cpu_env, int num, uint32_t arg1, uint32_t arg2, uint32_t arg3, |
416 | 831b7825 | ths | uint32_t arg4, uint32_t arg5, uint32_t arg6, uint32_t arg7, |
417 | 831b7825 | ths | uint32_t arg8) |
418 | 831b7825 | ths | { |
419 | 3f47aa8c | blueswir1 | extern uint32_t mach_reply_port(void); |
420 | 831b7825 | ths | |
421 | 831b7825 | ths | long ret = 0; |
422 | 831b7825 | ths | |
423 | 831b7825 | ths | arg1 = tswap32(arg1); |
424 | 831b7825 | ths | arg2 = tswap32(arg2); |
425 | 831b7825 | ths | arg3 = tswap32(arg3); |
426 | 831b7825 | ths | arg4 = tswap32(arg4); |
427 | 831b7825 | ths | arg5 = tswap32(arg5); |
428 | 831b7825 | ths | arg6 = tswap32(arg6); |
429 | 831b7825 | ths | arg7 = tswap32(arg7); |
430 | 831b7825 | ths | arg8 = tswap32(arg8); |
431 | 831b7825 | ths | |
432 | 831b7825 | ths | DPRINTF("mach syscall %d : " , num);
|
433 | 831b7825 | ths | |
434 | 831b7825 | ths | switch(num) {
|
435 | 831b7825 | ths | /* see xnu/osfmk/mach/syscall_sw.h */
|
436 | 831b7825 | ths | case -26: |
437 | 831b7825 | ths | DPRINTF("mach_reply_port()\n");
|
438 | 831b7825 | ths | ret = mach_reply_port(); |
439 | 831b7825 | ths | break;
|
440 | 831b7825 | ths | case -27: |
441 | 831b7825 | ths | DPRINTF("mach_thread_self()\n");
|
442 | 831b7825 | ths | ret = mach_thread_self(); |
443 | 831b7825 | ths | break;
|
444 | 831b7825 | ths | case -28: |
445 | 831b7825 | ths | DPRINTF("mach_task_self()\n");
|
446 | 831b7825 | ths | ret = mach_task_self(); |
447 | 831b7825 | ths | break;
|
448 | 831b7825 | ths | case -29: |
449 | 831b7825 | ths | DPRINTF("mach_host_self()\n");
|
450 | 831b7825 | ths | ret = mach_host_self(); |
451 | 831b7825 | ths | break;
|
452 | 831b7825 | ths | case -31: |
453 | 831b7825 | ths | DPRINTF("mach_msg_trap(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n",
|
454 | 831b7825 | ths | arg1, arg2, arg3, arg4, arg5, arg6, arg7); |
455 | 831b7825 | ths | ret = target_mach_msg_trap((mach_msg_header_t *)arg1, arg2, arg3, arg4, arg5, arg6, arg7); |
456 | 831b7825 | ths | break;
|
457 | ee999a88 | ths | /* may need more translation if target arch is different from host */
|
458 | ee999a88 | ths | #if (defined(TARGET_I386) && defined(__i386__)) || (defined(TARGET_PPC) && defined(__ppc__))
|
459 | ee999a88 | ths | case -33: |
460 | ee999a88 | ths | DPRINTF("semaphore_signal_trap(0x%x)\n", arg1);
|
461 | ee999a88 | ths | ret = semaphore_signal_trap(arg1); |
462 | ee999a88 | ths | break;
|
463 | ee999a88 | ths | case -34: |
464 | ee999a88 | ths | DPRINTF("semaphore_signal_all_trap(0x%x)\n", arg1);
|
465 | ee999a88 | ths | ret = semaphore_signal_all_trap(arg1); |
466 | ee999a88 | ths | break;
|
467 | ee999a88 | ths | case -35: |
468 | ee999a88 | ths | DPRINTF("semaphore_signal_thread_trap(0x%x)\n", arg1, arg2);
|
469 | ee999a88 | ths | ret = semaphore_signal_thread_trap(arg1,arg2); |
470 | ee999a88 | ths | break;
|
471 | ee999a88 | ths | #endif
|
472 | 831b7825 | ths | case -36: |
473 | 831b7825 | ths | DPRINTF("semaphore_wait_trap(0x%x)\n", arg1);
|
474 | 831b7825 | ths | extern int semaphore_wait_trap(int); // XXX: is there any header for that? |
475 | 831b7825 | ths | ret = semaphore_wait_trap(arg1); |
476 | 831b7825 | ths | break;
|
477 | ee999a88 | ths | /* may need more translation if target arch is different from host */
|
478 | ee999a88 | ths | #if (defined(TARGET_I386) && defined(__i386__)) || (defined(TARGET_PPC) && defined(__ppc__))
|
479 | ee999a88 | ths | case -37: |
480 | ee999a88 | ths | DPRINTF("semaphore_wait_signal_trap(0x%x, 0x%x)\n", arg1, arg2);
|
481 | ee999a88 | ths | ret = semaphore_wait_signal_trap(arg1,arg2); |
482 | ee999a88 | ths | break;
|
483 | ee999a88 | ths | #endif
|
484 | 831b7825 | ths | case -43: |
485 | 831b7825 | ths | DPRINTF("map_fd(0x%x, 0x%x, 0x%x, 0x%x, 0x%x)\n",
|
486 | 831b7825 | ths | arg1, arg2, arg3, arg4, arg5); |
487 | 831b7825 | ths | ret = map_fd(arg1, arg2, (void*)arg3, arg4, arg5);
|
488 | 831b7825 | ths | tswap32s((uint32_t*)arg3); |
489 | 831b7825 | ths | break;
|
490 | ee999a88 | ths | /* may need more translation if target arch is different from host */
|
491 | ee999a88 | ths | #if (defined(TARGET_I386) && defined(__i386__)) || (defined(TARGET_PPC) && defined(__ppc__))
|
492 | ee999a88 | ths | case -61: |
493 | ee999a88 | ths | DPRINTF("syscall_thread_switch(0x%x, 0x%x, 0x%x)\n",
|
494 | ee999a88 | ths | arg1, arg2, arg3); |
495 | ee999a88 | ths | ret = syscall_thread_switch(arg1, arg2, arg3); // just a hint to the scheduler; can drop?
|
496 | ee999a88 | ths | break;
|
497 | ee999a88 | ths | #endif
|
498 | 831b7825 | ths | case -89: |
499 | 831b7825 | ths | DPRINTF("mach_timebase_info(0x%x)\n", arg1);
|
500 | 831b7825 | ths | struct mach_timebase_info info;
|
501 | 831b7825 | ths | ret = mach_timebase_info(&info); |
502 | 831b7825 | ths | if(!is_error(ret))
|
503 | 831b7825 | ths | { |
504 | 831b7825 | ths | struct mach_timebase_info *outInfo = (void*)arg1; |
505 | 831b7825 | ths | outInfo->numer = tswap32(info.numer); |
506 | 831b7825 | ths | outInfo->denom = tswap32(info.denom); |
507 | 831b7825 | ths | } |
508 | 831b7825 | ths | break;
|
509 | 831b7825 | ths | case -90: |
510 | 831b7825 | ths | DPRINTF("mach_wait_until()\n");
|
511 | 831b7825 | ths | extern int mach_wait_until(uint64_t); // XXX: is there any header for that? |
512 | 831b7825 | ths | ret = mach_wait_until(((uint64_t)arg2<<32) | (uint64_t)arg1);
|
513 | 831b7825 | ths | break;
|
514 | 831b7825 | ths | case -91: |
515 | 831b7825 | ths | DPRINTF("mk_timer_create()\n");
|
516 | 831b7825 | ths | extern int mk_timer_create(); // XXX: is there any header for that? |
517 | 831b7825 | ths | ret = mk_timer_create(); |
518 | 831b7825 | ths | break;
|
519 | 831b7825 | ths | case -92: |
520 | 831b7825 | ths | DPRINTF("mk_timer_destroy()\n");
|
521 | 831b7825 | ths | extern int mk_timer_destroy(int); // XXX: is there any header for that? |
522 | 831b7825 | ths | ret = mk_timer_destroy(arg1); |
523 | 831b7825 | ths | break;
|
524 | 831b7825 | ths | case -93: |
525 | 831b7825 | ths | DPRINTF("mk_timer_create()\n");
|
526 | 831b7825 | ths | extern int mk_timer_arm(int, uint64_t); // XXX: is there any header for that? |
527 | 831b7825 | ths | ret = mk_timer_arm(arg1, ((uint64_t)arg3<<32) | (uint64_t)arg2);
|
528 | 831b7825 | ths | break;
|
529 | 831b7825 | ths | case -94: |
530 | 831b7825 | ths | DPRINTF("mk_timer_cancel()\n");
|
531 | 831b7825 | ths | extern int mk_timer_cancel(int, uint64_t *); // XXX: is there any header for that? |
532 | 831b7825 | ths | ret = mk_timer_cancel(arg1, (uint64_t *)arg2); |
533 | 831b7825 | ths | if((!is_error(ret)) && arg2)
|
534 | 831b7825 | ths | tswap64s((uint64_t *)arg2); |
535 | 831b7825 | ths | break;
|
536 | 831b7825 | ths | default:
|
537 | 831b7825 | ths | gemu_log("qemu: Unsupported mach syscall: %d(0x%x)\n", num, num);
|
538 | 831b7825 | ths | gdb_handlesig (cpu_env, SIGTRAP); |
539 | 831b7825 | ths | exit(0);
|
540 | 831b7825 | ths | break;
|
541 | 831b7825 | ths | } |
542 | 831b7825 | ths | return ret;
|
543 | 831b7825 | ths | } |
544 | 831b7825 | ths | |
545 | 831b7825 | ths | /* ------------------------------------------------------------
|
546 | 831b7825 | ths | thread type syscall handling
|
547 | 831b7825 | ths | */
|
548 | 831b7825 | ths | long do_thread_syscall(void *cpu_env, int num, uint32_t arg1, uint32_t arg2, uint32_t arg3, |
549 | 831b7825 | ths | uint32_t arg4, uint32_t arg5, uint32_t arg6, uint32_t arg7, |
550 | 831b7825 | ths | uint32_t arg8) |
551 | 831b7825 | ths | { |
552 | 831b7825 | ths | extern uint32_t cthread_set_self(uint32_t);
|
553 | 3f47aa8c | blueswir1 | extern uint32_t processor_facilities_used(void); |
554 | 831b7825 | ths | long ret = 0; |
555 | 831b7825 | ths | |
556 | 831b7825 | ths | arg1 = tswap32(arg1); |
557 | 831b7825 | ths | arg2 = tswap32(arg2); |
558 | 831b7825 | ths | arg3 = tswap32(arg3); |
559 | 831b7825 | ths | arg4 = tswap32(arg4); |
560 | 831b7825 | ths | arg5 = tswap32(arg5); |
561 | 831b7825 | ths | arg6 = tswap32(arg6); |
562 | 831b7825 | ths | arg7 = tswap32(arg7); |
563 | 831b7825 | ths | arg8 = tswap32(arg8); |
564 | 831b7825 | ths | |
565 | 831b7825 | ths | DPRINTF("thread syscall %d : " , num);
|
566 | 831b7825 | ths | |
567 | 831b7825 | ths | switch(num) {
|
568 | 831b7825 | ths | #ifdef TARGET_I386
|
569 | 831b7825 | ths | case 0x3: |
570 | 831b7825 | ths | #endif
|
571 | 831b7825 | ths | case 0x7FF1: /* cthread_set_self */ |
572 | 831b7825 | ths | DPRINTF("cthread_set_self(0x%x)\n", (unsigned int)arg1); |
573 | 831b7825 | ths | ret = cthread_set_self(arg1); |
574 | 831b7825 | ths | #ifdef TARGET_I386
|
575 | 831b7825 | ths | /* we need to update the LDT with the address of the thread */
|
576 | 831b7825 | ths | write_dt((void *)(((CPUX86State *) cpu_env)->ldt.base + (4 * sizeof(uint64_t))), arg1, 1, |
577 | 831b7825 | ths | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | |
578 | 831b7825 | ths | (3 << DESC_DPL_SHIFT) | (0x2 << DESC_TYPE_SHIFT)); |
579 | 831b7825 | ths | /* New i386 convention, %gs should be set to our this LDT entry */
|
580 | 831b7825 | ths | cpu_x86_load_seg(cpu_env, R_GS, 0x27);
|
581 | 831b7825 | ths | /* Old i386 convention, the kernel returns the selector for the cthread (pre-10.4.8?)*/
|
582 | 831b7825 | ths | ret = 0x27;
|
583 | 831b7825 | ths | #endif
|
584 | 831b7825 | ths | break;
|
585 | 831b7825 | ths | case 0x7FF2: /* Called the super-fast pthread_self handler by the apple guys */ |
586 | 831b7825 | ths | DPRINTF("pthread_self()\n");
|
587 | 831b7825 | ths | ret = (uint32_t)pthread_self(); |
588 | 831b7825 | ths | break;
|
589 | 831b7825 | ths | case 0x7FF3: |
590 | 831b7825 | ths | DPRINTF("processor_facilities_used()\n");
|
591 | 831b7825 | ths | #ifdef __i386__
|
592 | 831b7825 | ths | qerror("processor_facilities_used: not implemented!\n");
|
593 | 831b7825 | ths | #else
|
594 | 831b7825 | ths | ret = (uint32_t)processor_facilities_used(); |
595 | 831b7825 | ths | #endif
|
596 | 831b7825 | ths | break;
|
597 | 831b7825 | ths | default:
|
598 | 831b7825 | ths | gemu_log("qemu: Unsupported thread syscall: %d(0x%x)\n", num, num);
|
599 | 831b7825 | ths | gdb_handlesig (cpu_env, SIGTRAP); |
600 | 831b7825 | ths | exit(0);
|
601 | 831b7825 | ths | break;
|
602 | 831b7825 | ths | } |
603 | 831b7825 | ths | return ret;
|
604 | 831b7825 | ths | } |
605 | 831b7825 | ths | |
606 | 831b7825 | ths | /* ------------------------------------------------------------
|
607 | 831b7825 | ths | ioctl handling
|
608 | 831b7825 | ths | */
|
609 | 831b7825 | ths | static inline void byteswap_termios(struct termios *t) |
610 | 831b7825 | ths | { |
611 | 831b7825 | ths | tswap32s((uint32_t*)&t->c_iflag); |
612 | 831b7825 | ths | tswap32s((uint32_t*)&t->c_oflag); |
613 | 831b7825 | ths | tswap32s((uint32_t*)&t->c_cflag); |
614 | 831b7825 | ths | tswap32s((uint32_t*)&t->c_lflag); |
615 | 831b7825 | ths | /* 20 (char) bytes then */
|
616 | 831b7825 | ths | tswap32s((uint32_t*)&t->c_ispeed); |
617 | 831b7825 | ths | tswap32s((uint32_t*)&t->c_ospeed); |
618 | 831b7825 | ths | } |
619 | 831b7825 | ths | |
620 | 831b7825 | ths | static inline void byteswap_winsize(struct winsize *w) |
621 | 831b7825 | ths | { |
622 | 831b7825 | ths | tswap16s(&w->ws_row); |
623 | 831b7825 | ths | tswap16s(&w->ws_col); |
624 | 831b7825 | ths | tswap16s(&w->ws_xpixel); |
625 | 831b7825 | ths | tswap16s(&w->ws_ypixel); |
626 | 831b7825 | ths | } |
627 | 831b7825 | ths | |
628 | 001faf32 | Blue Swirl | #define STRUCT(name, ...) STRUCT_ ## name, |
629 | 831b7825 | ths | #define STRUCT_SPECIAL(name) STRUCT_ ## name, |
630 | 831b7825 | ths | enum {
|
631 | 831b7825 | ths | #include "ioctls_types.h" |
632 | 831b7825 | ths | }; |
633 | 831b7825 | ths | #undef STRUCT
|
634 | 831b7825 | ths | #undef STRUCT_SPECIAL
|
635 | 831b7825 | ths | |
636 | 001faf32 | Blue Swirl | #define STRUCT(name, ...) const argtype struct_ ## name ## _def[] = { __VA_ARGS__, TYPE_NULL }; |
637 | 831b7825 | ths | #define STRUCT_SPECIAL(name)
|
638 | 831b7825 | ths | #include "ioctls_types.h" |
639 | 831b7825 | ths | #undef STRUCT
|
640 | 831b7825 | ths | #undef STRUCT_SPECIAL
|
641 | 831b7825 | ths | |
642 | 831b7825 | ths | typedef struct IOCTLEntry { |
643 | 831b7825 | ths | unsigned int target_cmd; |
644 | 831b7825 | ths | unsigned int host_cmd; |
645 | 831b7825 | ths | const char *name; |
646 | 831b7825 | ths | int access;
|
647 | 831b7825 | ths | const argtype arg_type[5]; |
648 | 831b7825 | ths | } IOCTLEntry; |
649 | 831b7825 | ths | |
650 | 831b7825 | ths | #define IOC_R 0x0001 |
651 | 831b7825 | ths | #define IOC_W 0x0002 |
652 | 831b7825 | ths | #define IOC_RW (IOC_R | IOC_W)
|
653 | 831b7825 | ths | |
654 | 831b7825 | ths | #define MAX_STRUCT_SIZE 4096 |
655 | 831b7825 | ths | |
656 | 9f106a75 | blueswir1 | static IOCTLEntry ioctl_entries[] = {
|
657 | 001faf32 | Blue Swirl | #define IOCTL(cmd, access, ...) \
|
658 | 001faf32 | Blue Swirl | { cmd, cmd, #cmd, access, { __VA_ARGS__ } },
|
659 | 831b7825 | ths | #include "ioctls.h" |
660 | 831b7825 | ths | { 0, 0, }, |
661 | 831b7825 | ths | }; |
662 | 831b7825 | ths | |
663 | 831b7825 | ths | /* ??? Implement proper locking for ioctls. */
|
664 | 831b7825 | ths | static long do_ioctl(long fd, long cmd, long arg) |
665 | 831b7825 | ths | { |
666 | 831b7825 | ths | const IOCTLEntry *ie;
|
667 | 831b7825 | ths | const argtype *arg_type;
|
668 | 831b7825 | ths | int ret;
|
669 | 831b7825 | ths | uint8_t buf_temp[MAX_STRUCT_SIZE]; |
670 | 831b7825 | ths | int target_size;
|
671 | 831b7825 | ths | void *argptr;
|
672 | 831b7825 | ths | |
673 | 831b7825 | ths | ie = ioctl_entries; |
674 | 831b7825 | ths | for(;;) {
|
675 | 831b7825 | ths | if (ie->target_cmd == 0) { |
676 | 831b7825 | ths | gemu_log("Unsupported ioctl: cmd=0x%04lx\n", cmd);
|
677 | 831b7825 | ths | return -ENOSYS;
|
678 | 831b7825 | ths | } |
679 | 831b7825 | ths | if (ie->target_cmd == cmd)
|
680 | 831b7825 | ths | break;
|
681 | 831b7825 | ths | ie++; |
682 | 831b7825 | ths | } |
683 | 831b7825 | ths | arg_type = ie->arg_type; |
684 | 831b7825 | ths | #if defined(DEBUG)
|
685 | 831b7825 | ths | gemu_log("ioctl: cmd=0x%04lx (%s)\n", cmd, ie->name);
|
686 | 831b7825 | ths | #endif
|
687 | 831b7825 | ths | switch(arg_type[0]) { |
688 | 831b7825 | ths | case TYPE_NULL:
|
689 | 831b7825 | ths | /* no argument */
|
690 | 831b7825 | ths | ret = get_errno(ioctl(fd, ie->host_cmd)); |
691 | 831b7825 | ths | break;
|
692 | 831b7825 | ths | case TYPE_PTRVOID:
|
693 | 831b7825 | ths | case TYPE_INT:
|
694 | 831b7825 | ths | /* int argment */
|
695 | 831b7825 | ths | ret = get_errno(ioctl(fd, ie->host_cmd, arg)); |
696 | 831b7825 | ths | break;
|
697 | 831b7825 | ths | case TYPE_PTR:
|
698 | 831b7825 | ths | arg_type++; |
699 | 831b7825 | ths | target_size = thunk_type_size(arg_type, 0);
|
700 | 831b7825 | ths | switch(ie->access) {
|
701 | 831b7825 | ths | case IOC_R:
|
702 | 831b7825 | ths | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
703 | 831b7825 | ths | if (!is_error(ret)) {
|
704 | 831b7825 | ths | argptr = lock_user(arg, target_size, 0);
|
705 | 831b7825 | ths | thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); |
706 | 831b7825 | ths | unlock_user(argptr, arg, target_size); |
707 | 831b7825 | ths | } |
708 | 831b7825 | ths | break;
|
709 | 831b7825 | ths | case IOC_W:
|
710 | 831b7825 | ths | argptr = lock_user(arg, target_size, 1);
|
711 | 831b7825 | ths | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
712 | 831b7825 | ths | unlock_user(argptr, arg, 0);
|
713 | 831b7825 | ths | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
714 | 831b7825 | ths | break;
|
715 | 831b7825 | ths | default:
|
716 | 831b7825 | ths | case IOC_RW:
|
717 | 831b7825 | ths | argptr = lock_user(arg, target_size, 1);
|
718 | 831b7825 | ths | thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); |
719 | 831b7825 | ths | unlock_user(argptr, arg, 0);
|
720 | 831b7825 | ths | ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp)); |
721 | 831b7825 | ths | if (!is_error(ret)) {
|
722 | 831b7825 | ths | argptr = lock_user(arg, target_size, 0);
|
723 | 831b7825 | ths | thunk_convert(argptr, buf_temp, arg_type, THUNK_TARGET); |
724 | 831b7825 | ths | unlock_user(argptr, arg, target_size); |
725 | 831b7825 | ths | } |
726 | 831b7825 | ths | break;
|
727 | 831b7825 | ths | } |
728 | 831b7825 | ths | break;
|
729 | 831b7825 | ths | default:
|
730 | 831b7825 | ths | gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n", cmd, arg_type[0]); |
731 | 831b7825 | ths | ret = -ENOSYS; |
732 | 831b7825 | ths | break;
|
733 | 831b7825 | ths | } |
734 | 831b7825 | ths | return ret;
|
735 | 831b7825 | ths | } |
736 | 831b7825 | ths | |
737 | 831b7825 | ths | /* ------------------------------------------------------------
|
738 | 831b7825 | ths | Unix syscall handling
|
739 | 831b7825 | ths | */
|
740 | 831b7825 | ths | |
741 | 831b7825 | ths | static inline void byteswap_attrlist(struct attrlist *a) |
742 | 831b7825 | ths | { |
743 | 831b7825 | ths | tswap16s(&a->bitmapcount); |
744 | 831b7825 | ths | tswap16s(&a->reserved); |
745 | 831b7825 | ths | tswap32s(&a->commonattr); |
746 | 831b7825 | ths | tswap32s(&a->volattr); |
747 | 831b7825 | ths | tswap32s(&a->dirattr); |
748 | 831b7825 | ths | tswap32s(&a->fileattr); |
749 | 831b7825 | ths | tswap32s(&a->forkattr); |
750 | 831b7825 | ths | } |
751 | 831b7825 | ths | |
752 | 831b7825 | ths | struct attrbuf_header {
|
753 | 831b7825 | ths | unsigned long length; |
754 | 831b7825 | ths | }; |
755 | 831b7825 | ths | |
756 | 831b7825 | ths | static inline void byteswap_attrbuf(struct attrbuf_header *attrbuf, struct attrlist *attrlist) |
757 | 831b7825 | ths | { |
758 | bcb15d9c | Dong Xu Wang | DPRINTF("attrBuf.length %lx\n", attrbuf->length);
|
759 | 831b7825 | ths | } |
760 | 831b7825 | ths | |
761 | 831b7825 | ths | static inline void byteswap_statfs(struct statfs *s) |
762 | 831b7825 | ths | { |
763 | 831b7825 | ths | tswap16s((uint16_t*)&s->f_otype); |
764 | 831b7825 | ths | tswap16s((uint16_t*)&s->f_oflags); |
765 | 831b7825 | ths | tswap32s((uint32_t*)&s->f_bsize); |
766 | 831b7825 | ths | tswap32s((uint32_t*)&s->f_iosize); |
767 | 831b7825 | ths | tswap32s((uint32_t*)&s->f_blocks); |
768 | 831b7825 | ths | tswap32s((uint32_t*)&s->f_bfree); |
769 | 831b7825 | ths | tswap32s((uint32_t*)&s->f_bavail); |
770 | 831b7825 | ths | tswap32s((uint32_t*)&s->f_files); |
771 | 831b7825 | ths | tswap32s((uint32_t*)&s->f_ffree); |
772 | 831b7825 | ths | tswap32s((uint32_t*)&s->f_fsid.val[0]);
|
773 | 831b7825 | ths | tswap32s((uint32_t*)&s->f_fsid.val[1]);
|
774 | 831b7825 | ths | tswap16s((uint16_t*)&s->f_reserved1); |
775 | 831b7825 | ths | tswap16s((uint16_t*)&s->f_type); |
776 | 831b7825 | ths | tswap32s((uint32_t*)&s->f_flags); |
777 | 831b7825 | ths | } |
778 | 831b7825 | ths | |
779 | 831b7825 | ths | static inline void byteswap_stat(struct stat *s) |
780 | 831b7825 | ths | { |
781 | 831b7825 | ths | tswap32s((uint32_t*)&s->st_dev); |
782 | 831b7825 | ths | tswap32s(&s->st_ino); |
783 | 831b7825 | ths | tswap16s(&s->st_mode); |
784 | 831b7825 | ths | tswap16s(&s->st_nlink); |
785 | 831b7825 | ths | tswap32s(&s->st_uid); |
786 | 831b7825 | ths | tswap32s(&s->st_gid); |
787 | 831b7825 | ths | tswap32s((uint32_t*)&s->st_rdev); |
788 | 831b7825 | ths | tswap32s((uint32_t*)&s->st_atimespec.tv_sec); |
789 | 831b7825 | ths | tswap32s((uint32_t*)&s->st_atimespec.tv_nsec); |
790 | 831b7825 | ths | tswap32s((uint32_t*)&s->st_mtimespec.tv_sec); |
791 | 831b7825 | ths | tswap32s((uint32_t*)&s->st_mtimespec.tv_nsec); |
792 | 831b7825 | ths | tswap32s((uint32_t*)&s->st_ctimespec.tv_sec); |
793 | 831b7825 | ths | tswap32s((uint32_t*)&s->st_ctimespec.tv_nsec); |
794 | 831b7825 | ths | tswap64s((uint64_t*)&s->st_size); |
795 | 831b7825 | ths | tswap64s((uint64_t*)&s->st_blocks); |
796 | 831b7825 | ths | tswap32s((uint32_t*)&s->st_blksize); |
797 | 831b7825 | ths | tswap32s(&s->st_flags); |
798 | 831b7825 | ths | tswap32s(&s->st_gen); |
799 | 831b7825 | ths | } |
800 | 831b7825 | ths | |
801 | 831b7825 | ths | static inline void byteswap_dirents(struct dirent *d, int bytes) |
802 | 831b7825 | ths | { |
803 | 831b7825 | ths | char *b;
|
804 | 831b7825 | ths | for( b = (char*)d; (int)b < (int)d+bytes; ) |
805 | 831b7825 | ths | { |
806 | 831b7825 | ths | unsigned short s = ((struct dirent *)b)->d_reclen; |
807 | 831b7825 | ths | tswap32s(&((struct dirent *)b)->d_ino);
|
808 | 831b7825 | ths | tswap16s(&((struct dirent *)b)->d_reclen);
|
809 | 831b7825 | ths | if(s<=0) |
810 | 831b7825 | ths | break;
|
811 | 831b7825 | ths | b += s; |
812 | 831b7825 | ths | } |
813 | 831b7825 | ths | } |
814 | 831b7825 | ths | |
815 | 831b7825 | ths | static inline void byteswap_iovec(struct iovec *v, int n) |
816 | 831b7825 | ths | { |
817 | 831b7825 | ths | int i;
|
818 | 831b7825 | ths | for(i = 0; i < n; i++) |
819 | 831b7825 | ths | { |
820 | 831b7825 | ths | tswap32s((uint32_t*)&v[i].iov_base); |
821 | 831b7825 | ths | tswap32s((uint32_t*)&v[i].iov_len); |
822 | 831b7825 | ths | } |
823 | 831b7825 | ths | } |
824 | 831b7825 | ths | |
825 | 831b7825 | ths | static inline void byteswap_timeval(struct timeval *t) |
826 | 831b7825 | ths | { |
827 | 831b7825 | ths | tswap32s((uint32_t*)&t->tv_sec); |
828 | 831b7825 | ths | tswap32s((uint32_t*)&t->tv_usec); |
829 | 831b7825 | ths | } |
830 | 831b7825 | ths | |
831 | 831b7825 | ths | long do_unix_syscall_indirect(void *cpu_env, int num); |
832 | 3f47aa8c | blueswir1 | long do_sync(void); |
833 | 831b7825 | ths | long do_exit(uint32_t arg1);
|
834 | 831b7825 | ths | long do_getlogin(char *out, uint32_t size); |
835 | 831b7825 | ths | long do_open(char * arg1, uint32_t arg2, uint32_t arg3); |
836 | 831b7825 | ths | long do_getfsstat(struct statfs * arg1, uint32_t arg2, uint32_t arg3); |
837 | 831b7825 | ths | long do_sigprocmask(uint32_t arg1, uint32_t * arg2, uint32_t * arg3);
|
838 | 831b7825 | ths | long do_execve(char* arg1, char ** arg2, char ** arg3); |
839 | 831b7825 | ths | long do_getgroups(uint32_t arg1, gid_t * arg2);
|
840 | 831b7825 | ths | long do_gettimeofday(struct timeval * arg1, void * arg2); |
841 | 831b7825 | ths | long do_readv(uint32_t arg1, struct iovec * arg2, uint32_t arg3); |
842 | 831b7825 | ths | long do_writev(uint32_t arg1, struct iovec * arg2, uint32_t arg3); |
843 | 831b7825 | ths | long do_utimes(char * arg1, struct timeval * arg2); |
844 | 831b7825 | ths | long do_futimes(uint32_t arg1, struct timeval * arg2); |
845 | 831b7825 | ths | long do_statfs(char * arg1, struct statfs * arg2); |
846 | 831b7825 | ths | long do_fstatfs(uint32_t arg1, struct statfs * arg2); |
847 | 831b7825 | ths | long do_stat(char * arg1, struct stat * arg2); |
848 | 831b7825 | ths | long do_fstat(uint32_t arg1, struct stat * arg2); |
849 | 831b7825 | ths | long do_lstat(char * arg1, struct stat * arg2); |
850 | 831b7825 | ths | long do_getdirentries(uint32_t arg1, void* arg2, uint32_t arg3, void* arg4); |
851 | 831b7825 | ths | long do_lseek(void *cpu_env, int num); |
852 | 263466f5 | bellard | long do___sysctl(int * name, uint32_t namelen, void * oldp, size_t * oldlenp, void * newp, size_t newlen /* ignored */); |
853 | 831b7825 | ths | long do_getattrlist(void * arg1, void * arg2, void * arg3, uint32_t arg4, uint32_t arg5); |
854 | 831b7825 | ths | long do_getdirentriesattr(uint32_t arg1, void * arg2, void * arg3, size_t arg4, void * arg5, void * arg6, void* arg7, uint32_t arg8); |
855 | 263466f5 | bellard | long do_fcntl(int fd, int cmd, int arg); |
856 | 831b7825 | ths | |
857 | 831b7825 | ths | long no_syscall(void *cpu_env, int num); |
858 | 831b7825 | ths | |
859 | 831b7825 | ths | long do_pread(uint32_t arg1, void * arg2, size_t arg3, off_t arg4) |
860 | 831b7825 | ths | { |
861 | 0bfcd599 | Blue Swirl | DPRINTF("0x%x, %p, 0x%lx, 0x%" PRIx64 "\n", arg1, arg2, arg3, arg4); |
862 | 263466f5 | bellard | long ret = pread(arg1, arg2, arg3, arg4);
|
863 | 263466f5 | bellard | return ret;
|
864 | 263466f5 | bellard | } |
865 | 263466f5 | bellard | |
866 | 263466f5 | bellard | long do_read(int d, void *buf, size_t nbytes) |
867 | 263466f5 | bellard | { |
868 | 263466f5 | bellard | DPRINTF("0x%x, %p, 0x%lx\n", d, buf, nbytes);
|
869 | 263466f5 | bellard | long ret = get_errno(read(d, buf, nbytes));
|
870 | 263466f5 | bellard | if(!is_error(ret))
|
871 | 263466f5 | bellard | DPRINTF("%x\n", *(uint32_t*)buf);
|
872 | 831b7825 | ths | return ret;
|
873 | 831b7825 | ths | } |
874 | 263466f5 | bellard | |
875 | 831b7825 | ths | long unimpl_unix_syscall(void *cpu_env, int num); |
876 | 831b7825 | ths | |
877 | 831b7825 | ths | typedef long (*syscall_function_t)(void *cpu_env, int num); |
878 | 831b7825 | ths | |
879 | 831b7825 | ths | |
880 | 831b7825 | ths | /* define a table that will handle the syscall number->function association */
|
881 | 831b7825 | ths | #define VOID void |
882 | 831b7825 | ths | #define INT (uint32_t)get_int_arg(&i, cpu_env)
|
883 | 831b7825 | ths | #define INT64 (uint64_t)get_int64_arg(&i, cpu_env)
|
884 | 831b7825 | ths | #define UINT (unsigned int)INT |
885 | 831b7825 | ths | #define PTR (void*)INT |
886 | 831b7825 | ths | |
887 | 831b7825 | ths | #define SIZE INT
|
888 | 831b7825 | ths | #define OFFSET INT64
|
889 | 831b7825 | ths | |
890 | 831b7825 | ths | #define WRAPPER_CALL_DIRECT_0(function, args) long __qemu_##function(void *cpu_env) { return (long)function(); } |
891 | 831b7825 | ths | #define WRAPPER_CALL_DIRECT_1(function, _arg1) long __qemu_##function(void *cpu_env) { int i = 0; typeof(_arg1) arg1 = _arg1; return (long)function(arg1); } |
892 | 831b7825 | ths | #define WRAPPER_CALL_DIRECT_2(function, _arg1, _arg2) long __qemu_##function(void *cpu_env) { int i = 0; typeof(_arg1) arg1 = _arg1; typeof(_arg2) arg2 = _arg2; return (long)function(arg1, arg2); } |
893 | 831b7825 | ths | #define WRAPPER_CALL_DIRECT_3(function, _arg1, _arg2, _arg3) long __qemu_##function(void *cpu_env) { int i = 0; typeof(_arg1) arg1 = _arg1; typeof(_arg2) arg2 = _arg2; typeof(_arg3) arg3 = _arg3; return (long)function(arg1, arg2, arg3); } |
894 | 831b7825 | ths | #define WRAPPER_CALL_DIRECT_4(function, _arg1, _arg2, _arg3, _arg4) long __qemu_##function(void *cpu_env) { int i = 0; typeof(_arg1) arg1 = _arg1; typeof(_arg2) arg2 = _arg2; typeof(_arg3) arg3 = _arg3; typeof(_arg4) arg4 = _arg4; return (long)function(arg1, arg2, arg3, arg4); } |
895 | 831b7825 | ths | #define WRAPPER_CALL_DIRECT_5(function, _arg1, _arg2, _arg3, _arg4, _arg5) long __qemu_##function(void *cpu_env) { int i = 0; typeof(_arg1) arg1 = _arg1; typeof(_arg2) arg2 = _arg2; typeof(_arg3) arg3 = _arg3; typeof(_arg4) arg4 = _arg4; typeof(_arg5) arg5 = _arg5; return (long)function(arg1, arg2, arg3, arg4, arg5); } |
896 | 831b7825 | ths | #define WRAPPER_CALL_DIRECT_6(function, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6) long __qemu_##function(void *cpu_env) { int i = 0; typeof(_arg1) arg1 = _arg1; typeof(_arg2) arg2 = _arg2; typeof(_arg3) arg3 = _arg3; typeof(_arg4) arg4 = _arg4; typeof(_arg5) arg5 = _arg5; typeof(_arg6) arg6 = _arg6; return (long)function(arg1, arg2, arg3, arg4, arg5, arg6); } |
897 | 831b7825 | ths | #define WRAPPER_CALL_DIRECT_7(function, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7) long __qemu_##function(void *cpu_env) { int i = 0; typeof(_arg1) arg1 = _arg1; typeof(_arg2) arg2 = _arg2; typeof(_arg3) arg3 = _arg3; typeof(_arg4) arg4 = _arg4; typeof(_arg5) arg5 = _arg5; typeof(_arg6) arg6 = _arg6; typeof(_arg7) arg7 = _arg7; return (long)function(arg1, arg2, arg3, arg4, arg5, arg6, arg7); } |
898 | 831b7825 | ths | #define WRAPPER_CALL_DIRECT_8(function, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8) long __qemu_##function(void *cpu_env) { int i = 0; typeof(_arg1) arg1 = _arg1; typeof(_arg2) arg2 = _arg2; typeof(_arg3) arg3 = _arg3; typeof(_arg4) arg4 = _arg4; typeof(_arg5) arg5 = _arg5; typeof(_arg6) arg6 = _arg6; typeof(_arg7) arg7 = _arg7; typeof(_arg8) arg8 = _arg8; return (long)function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); } |
899 | 001faf32 | Blue Swirl | #define WRAPPER_CALL_DIRECT(function, nargs, ...) WRAPPER_CALL_DIRECT_##nargs(function, __VA_ARGS__) |
900 | 001faf32 | Blue Swirl | #define WRAPPER_CALL_NOERRNO(function, nargs, ...) WRAPPER_CALL_DIRECT(function, nargs, __VA_ARGS__)
|
901 | 001faf32 | Blue Swirl | #define WRAPPER_CALL_INDIRECT(function, nargs, ...)
|
902 | 001faf32 | Blue Swirl | #define ENTRY(name, number, function, nargs, call_type, ...) WRAPPER_##call_type(function, nargs, __VA_ARGS__) |
903 | 831b7825 | ths | |
904 | 831b7825 | ths | #include "syscalls.h" |
905 | 831b7825 | ths | |
906 | 831b7825 | ths | #undef ENTRY
|
907 | 831b7825 | ths | #undef WRAPPER_CALL_DIRECT
|
908 | 831b7825 | ths | #undef WRAPPER_CALL_NOERRNO
|
909 | 831b7825 | ths | #undef WRAPPER_CALL_INDIRECT
|
910 | 831b7825 | ths | #undef OFFSET
|
911 | 831b7825 | ths | #undef SIZE
|
912 | 831b7825 | ths | #undef INT
|
913 | 831b7825 | ths | #undef PTR
|
914 | 831b7825 | ths | #undef INT64
|
915 | 831b7825 | ths | |
916 | 831b7825 | ths | #define _ENTRY(name, number, function, nargs, call_type) [number] = {\
|
917 | 831b7825 | ths | name, \ |
918 | 831b7825 | ths | number, \ |
919 | 831b7825 | ths | (syscall_function_t)function, \ |
920 | 831b7825 | ths | nargs, \ |
921 | 831b7825 | ths | call_type \ |
922 | 831b7825 | ths | }, |
923 | 831b7825 | ths | |
924 | 831b7825 | ths | #define ENTRY_CALL_DIRECT(name, number, function, nargs, call_type) _ENTRY(name, number, __qemu_##function, nargs, call_type) |
925 | 831b7825 | ths | #define ENTRY_CALL_NOERRNO(name, number, function, nargs, call_type) ENTRY_CALL_DIRECT(name, number, function, nargs, call_type)
|
926 | 831b7825 | ths | #define ENTRY_CALL_INDIRECT(name, number, function, nargs, call_type) _ENTRY(name, number, function, nargs, call_type)
|
927 | 001faf32 | Blue Swirl | #define ENTRY(name, number, function, nargs, call_type, ...) ENTRY_##call_type(name, number, function, nargs, call_type) |
928 | 831b7825 | ths | |
929 | 831b7825 | ths | #define CALL_DIRECT 1 |
930 | 831b7825 | ths | #define CALL_INDIRECT 2 |
931 | 831b7825 | ths | #define CALL_NOERRNO (CALL_DIRECT | 4 /* = 5 */) |
932 | 831b7825 | ths | |
933 | 831b7825 | ths | struct unix_syscall {
|
934 | 831b7825 | ths | char * name;
|
935 | 831b7825 | ths | int number;
|
936 | 831b7825 | ths | syscall_function_t function; |
937 | 831b7825 | ths | int nargs;
|
938 | 831b7825 | ths | int call_type;
|
939 | 831b7825 | ths | } unix_syscall_table[SYS_MAXSYSCALL] = { |
940 | 831b7825 | ths | #include "syscalls.h" |
941 | 831b7825 | ths | }; |
942 | 831b7825 | ths | |
943 | 831b7825 | ths | #undef ENTRY
|
944 | 831b7825 | ths | #undef _ENTRY
|
945 | 831b7825 | ths | #undef ENTRY_CALL_DIRECT
|
946 | 831b7825 | ths | #undef ENTRY_CALL_INDIRECT
|
947 | 831b7825 | ths | #undef ENTRY_CALL_NOERRNO
|
948 | 831b7825 | ths | |
949 | 831b7825 | ths | /* Actual syscalls implementation */
|
950 | 831b7825 | ths | |
951 | 831b7825 | ths | long do_unix_syscall_indirect(void *cpu_env, int num) |
952 | 831b7825 | ths | { |
953 | 831b7825 | ths | long ret;
|
954 | 831b7825 | ths | int new_num;
|
955 | 831b7825 | ths | int i = 0; |
956 | 831b7825 | ths | |
957 | 831b7825 | ths | new_num = get_int_arg(&i, cpu_env); |
958 | 831b7825 | ths | #ifdef TARGET_I386
|
959 | 831b7825 | ths | ((CPUX86State*)cpu_env)->regs[R_ESP] += 4;
|
960 | 831b7825 | ths | /* XXX: not necessary */
|
961 | 831b7825 | ths | ((CPUX86State*)cpu_env)->regs[R_EAX] = new_num; |
962 | 831b7825 | ths | #elif TARGET_PPC
|
963 | 831b7825 | ths | { |
964 | 831b7825 | ths | int i;
|
965 | 831b7825 | ths | uint32_t **regs = ((CPUPPCState*)cpu_env)->gpr; |
966 | 831b7825 | ths | for(i = 3; i < 11; i++) |
967 | 831b7825 | ths | *regs[i] = *regs[i+1];
|
968 | 831b7825 | ths | /* XXX: not necessary */
|
969 | 831b7825 | ths | *regs[0] = new_num;
|
970 | 831b7825 | ths | } |
971 | 831b7825 | ths | #endif
|
972 | 831b7825 | ths | ret = do_unix_syscall(cpu_env, new_num); |
973 | 831b7825 | ths | #ifdef TARGET_I386
|
974 | 831b7825 | ths | ((CPUX86State*)cpu_env)->regs[R_ESP] -= 4;
|
975 | 831b7825 | ths | /* XXX: not necessary */
|
976 | 831b7825 | ths | ((CPUX86State*)cpu_env)->regs[R_EAX] = num; |
977 | 831b7825 | ths | #elif TARGET_PPC
|
978 | 831b7825 | ths | { |
979 | 831b7825 | ths | int i;
|
980 | 5225d669 | Stefan Weil | /* XXX: not really needed those regs are volatile across calls */
|
981 | 831b7825 | ths | uint32_t **regs = ((CPUPPCState*)cpu_env)->gpr; |
982 | 831b7825 | ths | for(i = 11; i > 3; i--) |
983 | 831b7825 | ths | *regs[i] = *regs[i-1];
|
984 | 831b7825 | ths | regs[3] = new_num;
|
985 | 831b7825 | ths | *regs[0] = num;
|
986 | 831b7825 | ths | } |
987 | 831b7825 | ths | #endif
|
988 | 831b7825 | ths | return ret;
|
989 | 831b7825 | ths | } |
990 | 831b7825 | ths | |
991 | 831b7825 | ths | long do_exit(uint32_t arg1)
|
992 | 831b7825 | ths | { |
993 | 831b7825 | ths | exit(arg1); |
994 | 831b7825 | ths | /* not reached */
|
995 | 831b7825 | ths | return -1; |
996 | 831b7825 | ths | } |
997 | 831b7825 | ths | |
998 | 3f47aa8c | blueswir1 | long do_sync(void) |
999 | 831b7825 | ths | { |
1000 | 831b7825 | ths | sync(); |
1001 | 831b7825 | ths | return 0; |
1002 | 831b7825 | ths | } |
1003 | 831b7825 | ths | |
1004 | 831b7825 | ths | long do_getlogin(char *out, uint32_t size) |
1005 | 831b7825 | ths | { |
1006 | 831b7825 | ths | char *login = getlogin();
|
1007 | 831b7825 | ths | if(!login)
|
1008 | 831b7825 | ths | return -1; |
1009 | 831b7825 | ths | memcpy(out, login, size); |
1010 | 831b7825 | ths | return 0; |
1011 | 831b7825 | ths | } |
1012 | 831b7825 | ths | long do_open(char * arg1, uint32_t arg2, uint32_t arg3) |
1013 | 831b7825 | ths | { |
1014 | 831b7825 | ths | /* XXX: don't let the %s stay in there */
|
1015 | 831b7825 | ths | DPRINTF("open(%s, 0x%x, 0x%x)\n", arg1, arg2, arg3);
|
1016 | 831b7825 | ths | return get_errno(open(arg1, arg2, arg3));
|
1017 | 831b7825 | ths | } |
1018 | 831b7825 | ths | |
1019 | 831b7825 | ths | long do_getfsstat(struct statfs * arg1, uint32_t arg2, uint32_t arg3) |
1020 | 831b7825 | ths | { |
1021 | 831b7825 | ths | long ret;
|
1022 | 831b7825 | ths | DPRINTF("getfsstat(%p, 0x%x, 0x%x)\n", arg1, arg2, arg3);
|
1023 | 831b7825 | ths | ret = get_errno(getfsstat(arg1, arg2, arg3)); |
1024 | 831b7825 | ths | if((!is_error(ret)) && arg1)
|
1025 | 831b7825 | ths | byteswap_statfs(arg1); |
1026 | 831b7825 | ths | return ret;
|
1027 | 831b7825 | ths | } |
1028 | 831b7825 | ths | |
1029 | 831b7825 | ths | long do_sigprocmask(uint32_t arg1, uint32_t * arg2, uint32_t * arg3)
|
1030 | 831b7825 | ths | { |
1031 | 831b7825 | ths | long ret;
|
1032 | 831b7825 | ths | DPRINTF("sigprocmask(%d, %p, %p)\n", arg1, arg2, arg3);
|
1033 | 831b7825 | ths | gemu_log("XXX: sigprocmask not tested (%d, %p, %p)\n", arg1, arg2, arg3);
|
1034 | 831b7825 | ths | if(arg2)
|
1035 | 831b7825 | ths | tswap32s(arg2); |
1036 | 831b7825 | ths | ret = get_errno(sigprocmask(arg1, (void *)arg2, (void *)arg3)); |
1037 | 831b7825 | ths | if((!is_error(ret)) && arg3)
|
1038 | 831b7825 | ths | tswap32s(arg3); |
1039 | 831b7825 | ths | if(arg2)
|
1040 | 831b7825 | ths | tswap32s(arg2); |
1041 | 831b7825 | ths | return ret;
|
1042 | 831b7825 | ths | } |
1043 | 831b7825 | ths | |
1044 | 831b7825 | ths | long do_execve(char* arg1, char ** arg2, char ** arg3) |
1045 | 831b7825 | ths | { |
1046 | 831b7825 | ths | long ret;
|
1047 | 831b7825 | ths | char **argv = arg2;
|
1048 | 831b7825 | ths | char **envp = arg3;
|
1049 | 831b7825 | ths | int argc;
|
1050 | 831b7825 | ths | int envc;
|
1051 | 831b7825 | ths | |
1052 | 831b7825 | ths | /* XXX: don't let the %s stay in here */
|
1053 | 831b7825 | ths | DPRINTF("execve(%s, %p, %p)\n", arg1, arg2, arg3);
|
1054 | 831b7825 | ths | |
1055 | 831b7825 | ths | for(argc = 0; argv[argc]; argc++); |
1056 | 831b7825 | ths | for(envc = 0; envp[envc]; envc++); |
1057 | 831b7825 | ths | |
1058 | 831b7825 | ths | argv = (char**)malloc(sizeof(char*)*argc); |
1059 | 831b7825 | ths | envp = (char**)malloc(sizeof(char*)*envc); |
1060 | 831b7825 | ths | |
1061 | 831b7825 | ths | for(; argc >= 0; argc--) |
1062 | 831b7825 | ths | argv[argc] = (char*)tswap32((uint32_t)(arg2)[argc]);
|
1063 | 831b7825 | ths | |
1064 | 831b7825 | ths | for(; envc >= 0; envc--) |
1065 | 831b7825 | ths | envp[envc] = (char*)tswap32((uint32_t)(arg3)[envc]);
|
1066 | 831b7825 | ths | |
1067 | 831b7825 | ths | ret = get_errno(execve(arg1, argv, envp)); |
1068 | 831b7825 | ths | free(argv); |
1069 | 831b7825 | ths | free(envp); |
1070 | 831b7825 | ths | return ret;
|
1071 | 831b7825 | ths | } |
1072 | 831b7825 | ths | |
1073 | 831b7825 | ths | long do_getgroups(uint32_t arg1, gid_t * arg2)
|
1074 | 831b7825 | ths | { |
1075 | 831b7825 | ths | long ret;
|
1076 | 831b7825 | ths | int i;
|
1077 | 831b7825 | ths | DPRINTF("getgroups(0x%x, %p)\n", arg1, arg2);
|
1078 | 831b7825 | ths | ret = get_errno(getgroups(arg1, arg2)); |
1079 | 831b7825 | ths | if(ret > 0) |
1080 | 831b7825 | ths | for(i = 0; i < arg1; i++) |
1081 | 831b7825 | ths | tswap32s(&arg2[i]); |
1082 | 831b7825 | ths | return ret;
|
1083 | 831b7825 | ths | } |
1084 | 831b7825 | ths | |
1085 | 831b7825 | ths | long do_gettimeofday(struct timeval * arg1, void * arg2) |
1086 | 831b7825 | ths | { |
1087 | 831b7825 | ths | long ret;
|
1088 | 831b7825 | ths | DPRINTF("gettimeofday(%p, %p)\n",
|
1089 | 831b7825 | ths | arg1, arg2); |
1090 | 831b7825 | ths | ret = get_errno(gettimeofday(arg1, arg2)); |
1091 | 831b7825 | ths | if(!is_error(ret))
|
1092 | 831b7825 | ths | { |
1093 | 831b7825 | ths | /* timezone no longer used according to the manpage, so don't bother with it */
|
1094 | 831b7825 | ths | byteswap_timeval(arg1); |
1095 | 831b7825 | ths | } |
1096 | 831b7825 | ths | return ret;
|
1097 | 831b7825 | ths | } |
1098 | 831b7825 | ths | |
1099 | 831b7825 | ths | long do_readv(uint32_t arg1, struct iovec * arg2, uint32_t arg3) |
1100 | 831b7825 | ths | { |
1101 | 831b7825 | ths | long ret;
|
1102 | 831b7825 | ths | DPRINTF("readv(0x%x, %p, 0x%x)\n", arg1, arg2, arg3);
|
1103 | 831b7825 | ths | if(arg2)
|
1104 | 831b7825 | ths | byteswap_iovec(arg2, arg3); |
1105 | 831b7825 | ths | ret = get_errno(readv(arg1, arg2, arg3)); |
1106 | 831b7825 | ths | if((!is_error(ret)) && arg2)
|
1107 | 831b7825 | ths | byteswap_iovec(arg2, arg3); |
1108 | 831b7825 | ths | return ret;
|
1109 | 831b7825 | ths | } |
1110 | 831b7825 | ths | |
1111 | 831b7825 | ths | long do_writev(uint32_t arg1, struct iovec * arg2, uint32_t arg3) |
1112 | 831b7825 | ths | { |
1113 | 831b7825 | ths | long ret;
|
1114 | 831b7825 | ths | DPRINTF("writev(0x%x, %p, 0x%x)\n", arg1, arg2, arg3);
|
1115 | 831b7825 | ths | if(arg2)
|
1116 | 831b7825 | ths | byteswap_iovec(arg2, arg3); |
1117 | 831b7825 | ths | ret = get_errno(writev(arg1, arg2, arg3)); |
1118 | 831b7825 | ths | if((!is_error(ret)) && arg2)
|
1119 | 831b7825 | ths | byteswap_iovec(arg2, arg3); |
1120 | 831b7825 | ths | return ret;
|
1121 | 831b7825 | ths | } |
1122 | 831b7825 | ths | |
1123 | 831b7825 | ths | long do_utimes(char * arg1, struct timeval * arg2) |
1124 | 831b7825 | ths | { |
1125 | 831b7825 | ths | DPRINTF("utimes(%p, %p)\n", arg1, arg2);
|
1126 | 831b7825 | ths | if(arg2)
|
1127 | 831b7825 | ths | { |
1128 | 831b7825 | ths | byteswap_timeval(arg2); |
1129 | 831b7825 | ths | byteswap_timeval(arg2+1);
|
1130 | 831b7825 | ths | } |
1131 | 831b7825 | ths | return get_errno(utimes(arg1, arg2));
|
1132 | 831b7825 | ths | } |
1133 | 831b7825 | ths | |
1134 | 831b7825 | ths | long do_futimes(uint32_t arg1, struct timeval * arg2) |
1135 | 831b7825 | ths | { |
1136 | 831b7825 | ths | DPRINTF("futimes(0x%x, %p)\n", arg1, arg2);
|
1137 | 831b7825 | ths | if(arg2)
|
1138 | 831b7825 | ths | { |
1139 | 831b7825 | ths | byteswap_timeval(arg2); |
1140 | 831b7825 | ths | byteswap_timeval(arg2+1);
|
1141 | 831b7825 | ths | } |
1142 | 831b7825 | ths | return get_errno(futimes(arg1, arg2));
|
1143 | 831b7825 | ths | } |
1144 | 831b7825 | ths | |
1145 | 831b7825 | ths | long do_statfs(char * arg1, struct statfs * arg2) |
1146 | 831b7825 | ths | { |
1147 | 831b7825 | ths | long ret;
|
1148 | 831b7825 | ths | DPRINTF("statfs(%p, %p)\n", arg1, arg2);
|
1149 | 831b7825 | ths | ret = get_errno(statfs(arg1, arg2)); |
1150 | 831b7825 | ths | if(!is_error(ret))
|
1151 | 831b7825 | ths | byteswap_statfs(arg2); |
1152 | 831b7825 | ths | return ret;
|
1153 | 831b7825 | ths | } |
1154 | 831b7825 | ths | |
1155 | 831b7825 | ths | long do_fstatfs(uint32_t arg1, struct statfs* arg2) |
1156 | 831b7825 | ths | { |
1157 | 831b7825 | ths | long ret;
|
1158 | 831b7825 | ths | DPRINTF("fstatfs(0x%x, %p)\n",
|
1159 | 831b7825 | ths | arg1, arg2); |
1160 | 831b7825 | ths | ret = get_errno(fstatfs(arg1, arg2)); |
1161 | 831b7825 | ths | if(!is_error(ret))
|
1162 | 831b7825 | ths | byteswap_statfs(arg2); |
1163 | 831b7825 | ths | |
1164 | 831b7825 | ths | return ret;
|
1165 | 831b7825 | ths | } |
1166 | 831b7825 | ths | |
1167 | 831b7825 | ths | long do_stat(char * arg1, struct stat * arg2) |
1168 | 831b7825 | ths | { |
1169 | 831b7825 | ths | long ret;
|
1170 | 831b7825 | ths | /* XXX: don't let the %s stay in there */
|
1171 | 831b7825 | ths | DPRINTF("stat(%s, %p)\n", arg1, arg2);
|
1172 | 831b7825 | ths | ret = get_errno(stat(arg1, arg2)); |
1173 | 831b7825 | ths | if(!is_error(ret))
|
1174 | 831b7825 | ths | byteswap_stat(arg2); |
1175 | 831b7825 | ths | return ret;
|
1176 | 831b7825 | ths | } |
1177 | 831b7825 | ths | |
1178 | 831b7825 | ths | long do_fstat(uint32_t arg1, struct stat * arg2) |
1179 | 831b7825 | ths | { |
1180 | 831b7825 | ths | long ret;
|
1181 | 831b7825 | ths | DPRINTF("fstat(0x%x, %p)\n", arg1, arg2);
|
1182 | 831b7825 | ths | ret = get_errno(fstat(arg1, arg2)); |
1183 | 831b7825 | ths | if(!is_error(ret))
|
1184 | 831b7825 | ths | byteswap_stat(arg2); |
1185 | 831b7825 | ths | return ret;
|
1186 | 831b7825 | ths | } |
1187 | 831b7825 | ths | |
1188 | 831b7825 | ths | long do_lstat(char * arg1, struct stat * arg2) |
1189 | 831b7825 | ths | { |
1190 | 831b7825 | ths | long ret;
|
1191 | 831b7825 | ths | /* XXX: don't let the %s stay in there */
|
1192 | 831b7825 | ths | DPRINTF("lstat(%s, %p)\n", (const char *)arg1, arg2); |
1193 | 831b7825 | ths | ret = get_errno(lstat(arg1, arg2)); |
1194 | 831b7825 | ths | if(!is_error(ret))
|
1195 | 831b7825 | ths | byteswap_stat(arg2); |
1196 | 831b7825 | ths | return ret;
|
1197 | 831b7825 | ths | } |
1198 | 831b7825 | ths | |
1199 | 831b7825 | ths | long do_getdirentries(uint32_t arg1, void* arg2, uint32_t arg3, void* arg4) |
1200 | 831b7825 | ths | { |
1201 | 831b7825 | ths | long ret;
|
1202 | 831b7825 | ths | DPRINTF("getdirentries(0x%x, %p, 0x%x, %p)\n", arg1, arg2, arg3, arg4);
|
1203 | 831b7825 | ths | if(arg4)
|
1204 | 831b7825 | ths | tswap32s((uint32_t *)arg4); |
1205 | 831b7825 | ths | ret = get_errno(getdirentries(arg1, arg2, arg3, arg4)); |
1206 | 831b7825 | ths | if(arg4)
|
1207 | 831b7825 | ths | tswap32s((uint32_t *)arg4); |
1208 | 831b7825 | ths | if(!is_error(ret))
|
1209 | 831b7825 | ths | byteswap_dirents(arg2, ret); |
1210 | 831b7825 | ths | return ret;
|
1211 | 831b7825 | ths | } |
1212 | 831b7825 | ths | |
1213 | 831b7825 | ths | long do_lseek(void *cpu_env, int num) |
1214 | 831b7825 | ths | { |
1215 | 831b7825 | ths | long ret;
|
1216 | 831b7825 | ths | int i = 0; |
1217 | 831b7825 | ths | uint32_t arg1 = get_int_arg(&i, cpu_env); |
1218 | 831b7825 | ths | uint64_t offset = get_int64_arg(&i, cpu_env); |
1219 | 831b7825 | ths | uint32_t arg3 = get_int_arg(&i, cpu_env); |
1220 | 831b7825 | ths | uint64_t r = lseek(arg1, offset, arg3); |
1221 | 831b7825 | ths | #ifdef TARGET_I386
|
1222 | 831b7825 | ths | /* lowest word in eax, highest in edx */
|
1223 | 831b7825 | ths | ret = r & 0xffffffff; /* will be set to eax after do_unix_syscall exit */ |
1224 | 831b7825 | ths | ((CPUX86State *)cpu_env)->regs[R_EDX] = (uint32_t)((r >> 32) & 0xffffffff) ; |
1225 | 831b7825 | ths | #elif defined TARGET_PPC
|
1226 | 831b7825 | ths | ret = r & 0xffffffff; /* will be set to r3 after do_unix_syscall exit */ |
1227 | 831b7825 | ths | ((CPUPPCState *)cpu_env)->gpr[4] = (uint32_t)((r >> 32) & 0xffffffff) ; |
1228 | 831b7825 | ths | #else
|
1229 | 831b7825 | ths | qerror("64 bit ret value on your arch?");
|
1230 | 831b7825 | ths | #endif
|
1231 | 831b7825 | ths | return get_errno(ret);
|
1232 | 831b7825 | ths | } |
1233 | 831b7825 | ths | |
1234 | 263466f5 | bellard | void no_swap(void * oldp, int size) |
1235 | 263466f5 | bellard | { |
1236 | 263466f5 | bellard | } |
1237 | 263466f5 | bellard | |
1238 | 263466f5 | bellard | void sysctl_tswap32s(void * oldp, int size) |
1239 | 263466f5 | bellard | { |
1240 | 263466f5 | bellard | tswap32s(oldp); |
1241 | 263466f5 | bellard | } |
1242 | 263466f5 | bellard | |
1243 | 263466f5 | bellard | void bswap_oid(uint32_t * oldp, int size) |
1244 | 263466f5 | bellard | { |
1245 | 263466f5 | bellard | int count = size / sizeof(int); |
1246 | 263466f5 | bellard | int i = 0; |
1247 | 263466f5 | bellard | do { tswap32s(oldp + i); } while (++i < count); |
1248 | 263466f5 | bellard | } |
1249 | 263466f5 | bellard | |
1250 | 263466f5 | bellard | void sysctl_usrstack(uint32_t * oldp, int size) |
1251 | 263466f5 | bellard | { |
1252 | 263466f5 | bellard | DPRINTF("sysctl_usrstack: 0x%x\n", *oldp);
|
1253 | 263466f5 | bellard | tswap32s(oldp); |
1254 | 263466f5 | bellard | } |
1255 | 263466f5 | bellard | |
1256 | 263466f5 | bellard | void sysctl_ncpu(uint32_t * ncpu, int size) |
1257 | 263466f5 | bellard | { |
1258 | 263466f5 | bellard | *ncpu = 0x1;
|
1259 | 263466f5 | bellard | DPRINTF("sysctl_ncpu: 0x%x\n", *ncpu);
|
1260 | 263466f5 | bellard | tswap32s(ncpu); |
1261 | 263466f5 | bellard | } |
1262 | 263466f5 | bellard | |
1263 | 263466f5 | bellard | void sysctl_exec(char * exec, int size) |
1264 | 263466f5 | bellard | { |
1265 | 263466f5 | bellard | DPRINTF("sysctl_exec: %s\n", exec);
|
1266 | 263466f5 | bellard | } |
1267 | 263466f5 | bellard | |
1268 | 263466f5 | bellard | void sysctl_translate(char * exec, int size) |
1269 | 263466f5 | bellard | { |
1270 | 263466f5 | bellard | DPRINTF("sysctl_translate: %s\n", exec);
|
1271 | 263466f5 | bellard | } |
1272 | 263466f5 | bellard | |
1273 | 263466f5 | bellard | struct sysctl_dir {
|
1274 | 263466f5 | bellard | int num;
|
1275 | 263466f5 | bellard | const char * name; |
1276 | 263466f5 | bellard | void (*swap_func)(void *, int); |
1277 | 263466f5 | bellard | struct sysctl_dir *childs;
|
1278 | 263466f5 | bellard | }; |
1279 | 263466f5 | bellard | |
1280 | 263466f5 | bellard | #define ENTRYD(num, name, childs) { num, name, NULL, childs } |
1281 | 263466f5 | bellard | #define ENTRYE(num, name, func) { num, name, (void (*)(void *, int))func, NULL } |
1282 | 263466f5 | bellard | struct sysctl_dir sysctls_unspec[] = {
|
1283 | 263466f5 | bellard | ENTRYE(3, "oip", bswap_oid), |
1284 | 263466f5 | bellard | { 0, NULL, NULL, NULL } |
1285 | 263466f5 | bellard | }; |
1286 | 263466f5 | bellard | |
1287 | 263466f5 | bellard | struct sysctl_dir sysctls_kern[] = {
|
1288 | 263466f5 | bellard | ENTRYE(KERN_TRANSLATE, "translate", sysctl_translate), /* 44 */ |
1289 | 263466f5 | bellard | ENTRYE(KERN_EXEC, "exec", sysctl_exec), /* 45 */ |
1290 | 263466f5 | bellard | ENTRYE(KERN_USRSTACK32, "KERN_USRSTACK32", sysctl_usrstack), /* 35 */ |
1291 | 263466f5 | bellard | ENTRYE(KERN_SHREG_PRIVATIZABLE, "KERN_SHREG_PRIVATIZABLE", sysctl_tswap32s), /* 54 */ |
1292 | 263466f5 | bellard | { 0, NULL, NULL, NULL } |
1293 | 263466f5 | bellard | }; |
1294 | 263466f5 | bellard | |
1295 | 263466f5 | bellard | struct sysctl_dir sysctls_hw[] = {
|
1296 | 263466f5 | bellard | ENTRYE(HW_NCPU, "ncpud", sysctl_tswap32s),
|
1297 | 263466f5 | bellard | ENTRYE(104, "104", no_swap), |
1298 | 263466f5 | bellard | ENTRYE(105, "105", no_swap), |
1299 | 263466f5 | bellard | { 0, NULL, NULL, NULL } |
1300 | 263466f5 | bellard | }; |
1301 | 263466f5 | bellard | |
1302 | 263466f5 | bellard | struct sysctl_dir sysctls[] = {
|
1303 | 263466f5 | bellard | ENTRYD(CTL_UNSPEC, "unspec", sysctls_unspec),
|
1304 | 263466f5 | bellard | ENTRYD(CTL_KERN, "kern", sysctls_kern),
|
1305 | 263466f5 | bellard | ENTRYD(CTL_HW, "hw", sysctls_hw ),
|
1306 | 263466f5 | bellard | { 0, NULL, NULL, NULL } |
1307 | 263466f5 | bellard | }; |
1308 | 263466f5 | bellard | |
1309 | 263466f5 | bellard | #undef ENTRYE
|
1310 | 263466f5 | bellard | #undef ENTRYD
|
1311 | 263466f5 | bellard | |
1312 | 263466f5 | bellard | static inline struct sysctl_dir * get_sysctl_entry_for_mib(int mib, struct sysctl_dir * sysctl_elmt) |
1313 | 263466f5 | bellard | { |
1314 | 263466f5 | bellard | if(!sysctl_elmt)
|
1315 | 263466f5 | bellard | return NULL; |
1316 | 263466f5 | bellard | for(; sysctl_elmt->name != NULL ; sysctl_elmt++) { |
1317 | 263466f5 | bellard | if(sysctl_elmt->num == mib)
|
1318 | 263466f5 | bellard | return sysctl_elmt;
|
1319 | 263466f5 | bellard | } |
1320 | 263466f5 | bellard | return NULL; |
1321 | 263466f5 | bellard | } |
1322 | 263466f5 | bellard | |
1323 | 263466f5 | bellard | static inline long bswap_syctl(int * mib, int count, void *buf, int size) |
1324 | 263466f5 | bellard | { |
1325 | 263466f5 | bellard | int i;
|
1326 | 263466f5 | bellard | struct sysctl_dir * sysctl = sysctls;
|
1327 | 263466f5 | bellard | struct sysctl_dir * ret = NULL; |
1328 | 263466f5 | bellard | |
1329 | 263466f5 | bellard | for(i = 0; i < count; i++) { |
1330 | 263466f5 | bellard | |
1331 | 263466f5 | bellard | if(!(ret = sysctl = get_sysctl_entry_for_mib(mib[i], sysctl))) {
|
1332 | 263466f5 | bellard | gemu_log("bswap_syctl: can't find mib %d\n", mib[i]);
|
1333 | 263466f5 | bellard | return -ENOTDIR;
|
1334 | 263466f5 | bellard | } |
1335 | 263466f5 | bellard | if(!(sysctl = sysctl->childs))
|
1336 | 263466f5 | bellard | break;
|
1337 | 263466f5 | bellard | } |
1338 | 3b46e624 | ths | |
1339 | 263466f5 | bellard | if(ret->childs)
|
1340 | 263466f5 | bellard | qerror("we shouldn't have a directory element\n");
|
1341 | 263466f5 | bellard | |
1342 | 263466f5 | bellard | ret->swap_func(buf, size); |
1343 | 263466f5 | bellard | return 0; |
1344 | 263466f5 | bellard | } |
1345 | 263466f5 | bellard | |
1346 | 263466f5 | bellard | static inline void print_syctl(int * mib, int count) |
1347 | 263466f5 | bellard | { |
1348 | 263466f5 | bellard | int i;
|
1349 | 263466f5 | bellard | struct sysctl_dir * sysctl = sysctls;
|
1350 | 263466f5 | bellard | struct sysctl_dir * ret = NULL; |
1351 | 263466f5 | bellard | |
1352 | 263466f5 | bellard | for(i = 0; i < count; i++) { |
1353 | 263466f5 | bellard | if(!(ret = sysctl = get_sysctl_entry_for_mib(mib[i], sysctl))){
|
1354 | 263466f5 | bellard | gemu_log("print_syctl: can't find mib %d\n", mib[i]);
|
1355 | 263466f5 | bellard | return;
|
1356 | 263466f5 | bellard | } |
1357 | 263466f5 | bellard | DPRINTF("%s.", sysctl->name);
|
1358 | 263466f5 | bellard | if(!(sysctl = sysctl->childs))
|
1359 | 263466f5 | bellard | break;
|
1360 | 263466f5 | bellard | } |
1361 | 263466f5 | bellard | DPRINTF("\n");
|
1362 | 263466f5 | bellard | } |
1363 | 263466f5 | bellard | |
1364 | 263466f5 | bellard | long do___sysctl(int * name, uint32_t namelen, void * oldp, size_t * oldlenp, void * newp, size_t newlen /* ignored */) |
1365 | 831b7825 | ths | { |
1366 | 831b7825 | ths | long ret = 0; |
1367 | 831b7825 | ths | int i;
|
1368 | 831b7825 | ths | DPRINTF("sysctl(%p, 0x%x, %p, %p, %p, 0x%lx)\n",
|
1369 | 263466f5 | bellard | name, namelen, oldp, oldlenp, newp, newlen); |
1370 | 263466f5 | bellard | if(name) {
|
1371 | 831b7825 | ths | i = 0;
|
1372 | 263466f5 | bellard | do { tswap32s( name + i); } while (++i < namelen); |
1373 | 263466f5 | bellard | print_syctl(name, namelen); |
1374 | 263466f5 | bellard | //bswap_syctl(name, namelen, newp, newlen);
|
1375 | 263466f5 | bellard | tswap32s((uint32_t*)oldlenp); |
1376 | 831b7825 | ths | } |
1377 | 3b46e624 | ths | |
1378 | 263466f5 | bellard | if(name) /* Sometimes sysctl is called with no arg1, ignore */ |
1379 | 263466f5 | bellard | ret = get_errno(sysctl(name, namelen, oldp, oldlenp, newp, newlen)); |
1380 | 831b7825 | ths | |
1381 | 7ed40acf | ths | #if defined(TARGET_I386) ^ defined(__i386__) || defined(TARGET_PPC) ^ defined(__ppc__)
|
1382 | 263466f5 | bellard | if (!is_error(ret) && bswap_syctl(name, namelen, oldp, *oldlenp) != 0) { |
1383 | 263466f5 | bellard | return -ENOTDIR;
|
1384 | 831b7825 | ths | } |
1385 | 7ed40acf | ths | #endif
|
1386 | 7ed40acf | ths | |
1387 | 263466f5 | bellard | if(name) {
|
1388 | 263466f5 | bellard | //bswap_syctl(name, namelen, newp, newlen);
|
1389 | 263466f5 | bellard | tswap32s((uint32_t*)oldlenp); |
1390 | 831b7825 | ths | |
1391 | 263466f5 | bellard | i = 0;
|
1392 | 263466f5 | bellard | do { tswap32s( name + i); } while (++i < namelen); |
1393 | 263466f5 | bellard | } |
1394 | 831b7825 | ths | return ret;
|
1395 | 831b7825 | ths | } |
1396 | 831b7825 | ths | |
1397 | 831b7825 | ths | long do_getattrlist(void * arg1, void * arg2, void * arg3, uint32_t arg4, uint32_t arg5) |
1398 | 831b7825 | ths | { |
1399 | 831b7825 | ths | struct attrlist * attrlist = (void *)arg2; |
1400 | 831b7825 | ths | long ret;
|
1401 | 831b7825 | ths | |
1402 | 831b7825 | ths | #if defined(TARGET_I386) ^ defined(__i386__) || defined(TARGET_PPC) ^ defined(__ppc__)
|
1403 | 263466f5 | bellard | gemu_log("SYS_getdirentriesattr unimplemented\n");
|
1404 | 263466f5 | bellard | return -ENOTSUP;
|
1405 | 831b7825 | ths | #endif
|
1406 | 831b7825 | ths | /* XXX: don't let the %s stay in there */
|
1407 | 831b7825 | ths | DPRINTF("getattrlist(%s, %p, %p, 0x%x, 0x%x)\n",
|
1408 | 831b7825 | ths | (char *)arg1, arg2, arg3, arg4, arg5);
|
1409 | 831b7825 | ths | |
1410 | 831b7825 | ths | if(arg2) /* XXX: We should handle that in a copy especially |
1411 | 831b7825 | ths | if the structure is not writable */
|
1412 | 831b7825 | ths | byteswap_attrlist(attrlist); |
1413 | 831b7825 | ths | |
1414 | 831b7825 | ths | ret = get_errno(getattrlist((const char* )arg1, attrlist, (void *)arg3, arg4, arg5)); |
1415 | 831b7825 | ths | |
1416 | 831b7825 | ths | if(!is_error(ret))
|
1417 | 831b7825 | ths | { |
1418 | 831b7825 | ths | byteswap_attrbuf((void *)arg3, attrlist);
|
1419 | 831b7825 | ths | byteswap_attrlist(attrlist); |
1420 | 831b7825 | ths | } |
1421 | 831b7825 | ths | return ret;
|
1422 | 831b7825 | ths | } |
1423 | 831b7825 | ths | |
1424 | 831b7825 | ths | long do_getdirentriesattr(uint32_t arg1, void * arg2, void * arg3, size_t arg4, void * arg5, void * arg6, void* arg7, uint32_t arg8) |
1425 | 831b7825 | ths | { |
1426 | 831b7825 | ths | DPRINTF("getdirentriesattr(0x%x, %p, %p, 0x%lx, %p, %p, %p, 0x%x)\n",
|
1427 | 831b7825 | ths | arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); |
1428 | 831b7825 | ths | #if defined(TARGET_I386) ^ defined(__i386__) || defined(TARGET_PPC) ^ defined(__ppc__)
|
1429 | 831b7825 | ths | qerror("SYS_getdirentriesattr unimplemented\n");
|
1430 | 831b7825 | ths | #endif
|
1431 | 831b7825 | ths | |
1432 | 831b7825 | ths | return get_errno(getdirentriesattr( arg1, (struct attrlist * )arg2, (void *)arg3, arg4, |
1433 | 831b7825 | ths | (unsigned long *)arg5, (unsigned long *)arg6, |
1434 | 831b7825 | ths | (unsigned long *)arg7, arg8)); |
1435 | 831b7825 | ths | } |
1436 | 831b7825 | ths | |
1437 | 263466f5 | bellard | static inline void bswap_flock(struct flock *f) |
1438 | 263466f5 | bellard | { |
1439 | 263466f5 | bellard | tswap64s(&f->l_start); |
1440 | 263466f5 | bellard | tswap64s(&f->l_len); |
1441 | 263466f5 | bellard | tswap32s(&f->l_pid); |
1442 | 263466f5 | bellard | tswap16s(&f->l_type); |
1443 | 263466f5 | bellard | tswap16s(&f->l_whence); |
1444 | 263466f5 | bellard | } |
1445 | 263466f5 | bellard | |
1446 | 263466f5 | bellard | static inline void bswap_fstore(struct fstore *f) |
1447 | 263466f5 | bellard | { |
1448 | 263466f5 | bellard | tswap32s(&f->fst_flags); |
1449 | 263466f5 | bellard | tswap32s(&f->fst_posmode); |
1450 | 263466f5 | bellard | tswap64s(&f->fst_offset); |
1451 | 263466f5 | bellard | tswap64s(&f->fst_length); |
1452 | 263466f5 | bellard | tswap64s(&f->fst_bytesalloc); |
1453 | 263466f5 | bellard | } |
1454 | 263466f5 | bellard | |
1455 | 263466f5 | bellard | static inline void bswap_radvisory(struct radvisory *f) |
1456 | 263466f5 | bellard | { |
1457 | 263466f5 | bellard | tswap64s(&f->ra_offset); |
1458 | 263466f5 | bellard | tswap32s(&f->ra_count); |
1459 | 263466f5 | bellard | } |
1460 | 263466f5 | bellard | |
1461 | 263466f5 | bellard | static inline void bswap_fbootstraptransfer(struct fbootstraptransfer *f) |
1462 | 263466f5 | bellard | { |
1463 | 263466f5 | bellard | tswap64s(&f->fbt_offset); |
1464 | 263466f5 | bellard | tswap32s((uint32_t*)&f->fbt_length); |
1465 | 263466f5 | bellard | tswap32s((uint32_t*)&f->fbt_buffer); /* XXX: this is a ptr */
|
1466 | 263466f5 | bellard | } |
1467 | 263466f5 | bellard | |
1468 | 263466f5 | bellard | static inline void bswap_log2phys(struct log2phys *f) |
1469 | 263466f5 | bellard | { |
1470 | 263466f5 | bellard | tswap32s(&f->l2p_flags); |
1471 | 263466f5 | bellard | tswap64s(&f->l2p_contigbytes); |
1472 | 263466f5 | bellard | tswap64s(&f->l2p_devoffset); |
1473 | 263466f5 | bellard | } |
1474 | 263466f5 | bellard | |
1475 | 263466f5 | bellard | static inline void bswap_fcntl_arg(int cmd, void * arg) |
1476 | 263466f5 | bellard | { |
1477 | 263466f5 | bellard | switch(cmd)
|
1478 | 263466f5 | bellard | { |
1479 | 263466f5 | bellard | case F_DUPFD:
|
1480 | 263466f5 | bellard | case F_GETFD:
|
1481 | 263466f5 | bellard | case F_SETFD:
|
1482 | 263466f5 | bellard | case F_GETFL:
|
1483 | 263466f5 | bellard | case F_SETFL:
|
1484 | 263466f5 | bellard | case F_GETOWN:
|
1485 | 263466f5 | bellard | case F_SETOWN:
|
1486 | 263466f5 | bellard | case F_SETSIZE:
|
1487 | 263466f5 | bellard | case F_RDAHEAD:
|
1488 | 263466f5 | bellard | case F_FULLFSYNC:
|
1489 | 263466f5 | bellard | break;
|
1490 | 263466f5 | bellard | case F_GETLK:
|
1491 | 263466f5 | bellard | case F_SETLK:
|
1492 | 263466f5 | bellard | case F_SETLKW:
|
1493 | 263466f5 | bellard | bswap_flock(arg); |
1494 | 263466f5 | bellard | break;
|
1495 | 263466f5 | bellard | case F_PREALLOCATE:
|
1496 | 263466f5 | bellard | bswap_fstore(arg); |
1497 | 263466f5 | bellard | break;
|
1498 | 263466f5 | bellard | case F_RDADVISE:
|
1499 | 263466f5 | bellard | bswap_radvisory(arg); |
1500 | 263466f5 | bellard | break;
|
1501 | 263466f5 | bellard | case F_READBOOTSTRAP:
|
1502 | 263466f5 | bellard | case F_WRITEBOOTSTRAP:
|
1503 | 263466f5 | bellard | bswap_fbootstraptransfer(arg); |
1504 | 263466f5 | bellard | break;
|
1505 | 263466f5 | bellard | case F_LOG2PHYS:
|
1506 | 263466f5 | bellard | bswap_log2phys(arg); |
1507 | 263466f5 | bellard | break;
|
1508 | 263466f5 | bellard | default:
|
1509 | 263466f5 | bellard | gemu_log("unknow cmd in fcntl\n");
|
1510 | 263466f5 | bellard | } |
1511 | 263466f5 | bellard | } |
1512 | 263466f5 | bellard | |
1513 | 263466f5 | bellard | long do_fcntl(int fd, int cmd, int arg) |
1514 | 263466f5 | bellard | { |
1515 | 263466f5 | bellard | long ret;
|
1516 | 263466f5 | bellard | bswap_fcntl_arg(cmd, (void *)arg);
|
1517 | 263466f5 | bellard | ret = get_errno(fcntl(fd, cmd, arg)); |
1518 | 263466f5 | bellard | if(!is_error(ret))
|
1519 | 263466f5 | bellard | bswap_fcntl_arg(cmd, (void *)arg);
|
1520 | 263466f5 | bellard | return ret;
|
1521 | 263466f5 | bellard | } |
1522 | 831b7825 | ths | |
1523 | 831b7825 | ths | long no_syscall(void *cpu_env, int num) |
1524 | 831b7825 | ths | { |
1525 | 831b7825 | ths | /* XXX: We should probably fordward it to the host kernel */
|
1526 | 831b7825 | ths | qerror("no unix syscall %d\n", num);
|
1527 | 831b7825 | ths | /* not reached */
|
1528 | 831b7825 | ths | return -1; |
1529 | 831b7825 | ths | } |
1530 | 831b7825 | ths | |
1531 | 831b7825 | ths | long unimpl_unix_syscall(void *cpu_env, int num) |
1532 | 831b7825 | ths | { |
1533 | 831b7825 | ths | if( (num < 0) || (num > SYS_MAXSYSCALL-1) ) |
1534 | 831b7825 | ths | qerror("unix syscall %d is out of unix syscall bounds (0-%d) " , num, SYS_MAXSYSCALL-1); |
1535 | 831b7825 | ths | |
1536 | 831b7825 | ths | gemu_log("qemu: Unsupported unix syscall %s %d\n", unix_syscall_table[num].name , num);
|
1537 | 831b7825 | ths | gdb_handlesig (cpu_env, SIGTRAP); |
1538 | 831b7825 | ths | exit(-1);
|
1539 | 831b7825 | ths | } |
1540 | 831b7825 | ths | |
1541 | 831b7825 | ths | long do_unix_syscall(void *cpu_env, int num) |
1542 | 831b7825 | ths | { |
1543 | 831b7825 | ths | long ret = 0; |
1544 | 831b7825 | ths | |
1545 | 831b7825 | ths | DPRINTF("unix syscall %d: " , num);
|
1546 | 831b7825 | ths | |
1547 | 831b7825 | ths | if( (num < 0) || (num > SYS_MAXSYSCALL-1) ) |
1548 | 831b7825 | ths | qerror("unix syscall %d is out of unix syscall bounds (0-%d) " , num, SYS_MAXSYSCALL-1); |
1549 | 831b7825 | ths | |
1550 | 831b7825 | ths | DPRINTF("%s [%s]", unix_syscall_table[num].name, unix_syscall_table[num].call_type & CALL_DIRECT ? "direct" : "indirect" ); |
1551 | 831b7825 | ths | ret = unix_syscall_table[num].function(cpu_env, num); |
1552 | 831b7825 | ths | |
1553 | 831b7825 | ths | if(!(unix_syscall_table[num].call_type & CALL_NOERRNO))
|
1554 | 831b7825 | ths | ret = get_errno(ret); |
1555 | 831b7825 | ths | |
1556 | 831b7825 | ths | DPRINTF("[returned 0x%x(%d)]\n", (int)ret, (int)ret); |
1557 | 831b7825 | ths | return ret;
|
1558 | 831b7825 | ths | } |
1559 | 831b7825 | ths | |
1560 | 831b7825 | ths | /* ------------------------------------------------------------
|
1561 | 831b7825 | ths | syscall_init
|
1562 | 831b7825 | ths | */
|
1563 | 831b7825 | ths | void syscall_init(void) |
1564 | 831b7825 | ths | { |
1565 | 831b7825 | ths | /* Nothing yet */
|
1566 | 831b7825 | ths | } |