Statistics
| Branch: | Revision:

root / darwin-user / syscall.c @ 5fafdf24

History | View | Annotate | Download (48.3 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 831b7825 ths
 *  along with this program; if not, write to the Free Software
19 831b7825 ths
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 831b7825 ths
 */
21 831b7825 ths
#include <fcntl.h>
22 831b7825 ths
#include <stdio.h>
23 831b7825 ths
#include <stdlib.h>
24 831b7825 ths
#include <errno.h>
25 831b7825 ths
26 263466f5 bellard
#include <mach/host_info.h>
27 831b7825 ths
#include <mach/mach.h>
28 831b7825 ths
#include <mach/mach_time.h>
29 263466f5 bellard
#include <mach/message.h>
30 831b7825 ths
31 831b7825 ths
#include <pthread.h>
32 831b7825 ths
#include <dirent.h>
33 831b7825 ths
34 831b7825 ths
#include <sys/stat.h>
35 831b7825 ths
#include <sys/syscall.h>
36 831b7825 ths
#include <sys/sysctl.h>
37 831b7825 ths
#include <sys/types.h>
38 831b7825 ths
#include <unistd.h>
39 831b7825 ths
#include <sys/ioctl.h>
40 831b7825 ths
#include <sys/mman.h>
41 831b7825 ths
#include <sys/types.h>
42 831b7825 ths
#include <sys/dirent.h>
43 831b7825 ths
#include <sys/uio.h>
44 831b7825 ths
#include <sys/termios.h>
45 831b7825 ths
#include <sys/ptrace.h>
46 831b7825 ths
#include <net/if.h>
47 831b7825 ths
48 831b7825 ths
#include <sys/param.h>
49 831b7825 ths
#include <sys/mount.h>
50 831b7825 ths
51 831b7825 ths
#include <sys/attr.h>
52 831b7825 ths
53 831b7825 ths
#include <mach/ndr.h>
54 831b7825 ths
#include <mach/mig_errors.h>
55 831b7825 ths
56 ee999a88 ths
#include <sys/xattr.h>
57 ee999a88 ths
58 831b7825 ths
#include "qemu.h"
59 831b7825 ths
60 831b7825 ths
//#define DEBUG_SYSCALL
61 831b7825 ths
62 831b7825 ths
#ifdef DEBUG_SYSCALL
63 831b7825 ths
# define DEBUG_FORCE_ENABLE_LOCAL() int __DEBUG_qemu_user_force_enable = 1
64 831b7825 ths
# define DEBUG_BEGIN_ENABLE  __DEBUG_qemu_user_force_enable = 1;
65 831b7825 ths
# define DEBUG_END_ENABLE  __DEBUG_qemu_user_force_enable = 0;
66 831b7825 ths
67 831b7825 ths
# define DEBUG_DISABLE_ALL() static int __DEBUG_qemu_user_force_enable = 0
68 831b7825 ths
# define DEBUG_ENABLE_ALL()  static int __DEBUG_qemu_user_force_enable = 1
69 831b7825 ths
    DEBUG_ENABLE_ALL();
70 831b7825 ths
71 831b7825 ths
# define DPRINTF(...) do { if(loglevel) fprintf(logfile, __VA_ARGS__); \
72 831b7825 ths
                           if(__DEBUG_qemu_user_force_enable) fprintf(stderr, __VA_ARGS__); \
73 831b7825 ths
                         } while(0)
74 831b7825 ths
#else
75 831b7825 ths
# define DEBUG_FORCE_ENABLE_LOCAL()
76 831b7825 ths
# define DEBUG_BEGIN_ENABLE
77 831b7825 ths
# define DEBUG_END_ENABLE
78 831b7825 ths
79 831b7825 ths
# define DPRINTF(...) do { if(loglevel) fprintf(logfile, __VA_ARGS__); } while(0)
80 831b7825 ths
#endif
81 831b7825 ths
82 831b7825 ths
enum {
83 831b7825 ths
    bswap_out = 0,
84 831b7825 ths
    bswap_in = 1
85 831b7825 ths
};
86 831b7825 ths
87 831b7825 ths
extern const char *interp_prefix;
88 831b7825 ths
89 831b7825 ths
static inline long get_errno(long ret)
90 831b7825 ths
{
91 831b7825 ths
    if (ret == -1)
92 831b7825 ths
        return -errno;
93 831b7825 ths
    else
94 831b7825 ths
        return ret;
95 831b7825 ths
}
96 831b7825 ths
97 831b7825 ths
static inline int is_error(long ret)
98 831b7825 ths
{
99 831b7825 ths
    return (unsigned long)ret >= (unsigned long)(-4096);
100 831b7825 ths
}
101 831b7825 ths
102 831b7825 ths
/* ------------------------------------------------------------
103 831b7825 ths
   Mach syscall handling
104 831b7825 ths
*/
105 831b7825 ths
106 831b7825 ths
void static inline print_description_msg_header(mach_msg_header_t *hdr)
107 831b7825 ths
{
108 831b7825 ths
    char *name = NULL;
109 831b7825 ths
    int i;
110 831b7825 ths
    struct { int number; char *name; } msg_name[] =
111 831b7825 ths
    {
112 831b7825 ths
        /* see http://fxr.watson.org/fxr/source/compat/mach/mach_namemap.c?v=NETBSD */
113 831b7825 ths
        { 200,      "host_info" },
114 831b7825 ths
        { 202,      "host_page_size" },
115 831b7825 ths
        { 206,      "host_get_clock_service" },
116 831b7825 ths
        { 206,      "host_get_clock_service" },
117 831b7825 ths
        { 206,      "host_get_clock_service" },
118 831b7825 ths
        { 306,      "host_get_clock_service" },
119 831b7825 ths
        { 3204,     "mach_port_allocate" },
120 831b7825 ths
        { 3206,     "mach_port_deallocate" },
121 831b7825 ths
        { 3404,     "mach_ports_lookup" },
122 831b7825 ths
        { 3409,     "mach_task_get_special_port" },
123 831b7825 ths
        { 3414,     "mach_task_get_exception_ports" },
124 831b7825 ths
        { 3418,     "mach_semaphore_create" },
125 831b7825 ths
        { 3504,     "mach_semaphore_create" },
126 831b7825 ths
        { 3509,     "mach_semaphore_create" },
127 831b7825 ths
        { 3518,     "semaphore_create" },
128 831b7825 ths
        { 3616,     "thread_policy" },
129 831b7825 ths
        { 3801,     "vm_allocate" },
130 831b7825 ths
        { 3802,     "vm_deallocate" },
131 831b7825 ths
        { 3802,     "vm_deallocate" },
132 831b7825 ths
        { 3803,     "vm_protect" },
133 831b7825 ths
        { 3812,     "vm_map" },
134 831b7825 ths
        { 4241776,  "lu_message_send_id" },  /* lookupd */
135 831b7825 ths
        { 4241876,  "lu_message_reply_id" }, /* lookupd */
136 831b7825 ths
    };
137 831b7825 ths
138 831b7825 ths
    for(i = 0; i < sizeof(msg_name)/sizeof(msg_name[0]); i++) {
139 831b7825 ths
        if(msg_name[i].number == hdr->msgh_id)
140 831b7825 ths
        {
141 831b7825 ths
            name = msg_name[i].name;
142 831b7825 ths
            break;
143 831b7825 ths
        }
144 831b7825 ths
    }
145 831b7825 ths
    if(!name)
146 831b7825 ths
        DPRINTF("unknown mach msg %d 0x%x\n", hdr->msgh_id, hdr->msgh_id);
147 831b7825 ths
    else
148 831b7825 ths
        DPRINTF("%s\n", name);
149 831b7825 ths
#if 0
150 831b7825 ths
    DPRINTF("Bits: %8x\n", hdr->msgh_bits);
151 831b7825 ths
    DPRINTF("Size: %8x\n", hdr->msgh_size);
152 831b7825 ths
    DPRINTF("Rmte: %8x\n", hdr->msgh_remote_port);
153 831b7825 ths
    DPRINTF("Locl: %8x\n", hdr->msgh_local_port);
154 831b7825 ths
    DPRINTF("Rsrv: %8x\n", hdr->msgh_reserved);
155 831b7825 ths

156 831b7825 ths
    DPRINTF("Id  : %8x\n", hdr->msgh_id);
157 831b7825 ths

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