Statistics
| Branch: | Revision:

root / darwin-user / syscall.c @ 0497d2f4

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

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

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