~ubuntu-branches/ubuntu/trusty/qemu/trusty

« back to all changes in this revision

Viewing changes to linux-user/syscall.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2013-10-22 22:47:07 UTC
  • mfrom: (1.8.3) (10.1.42 sid)
  • Revision ID: package-import@ubuntu.com-20131022224707-1lya34fw3k3f24tv
Tags: 1.6.0+dfsg-2ubuntu1
* Merge 1.6.0~rc0+dfsg-2exp from debian experimental.  Remaining changes:
  - debian/control
    * update maintainer
    * remove libiscsi, usb-redir, vde, vnc-jpeg, and libssh2-1-dev
      from build-deps
    * enable rbd
    * add qemu-system and qemu-common B/R to qemu-keymaps
    * add D:udev, R:qemu, R:qemu-common and B:qemu-common to
      qemu-system-common
    * qemu-system-arm, qemu-system-ppc, qemu-system-sparc:
      - add qemu-kvm to Provides
      - add qemu-common, qemu-kvm, kvm to B/R
      - remove openbios-sparc from qemu-system-sparc D
      - drop openbios-ppc and openhackware Depends to Suggests (for now)
    * qemu-system-x86:
      - add qemu-common to Breaks/Replaces.
      - add cpu-checker to Recommends.
    * qemu-user: add B/R:qemu-kvm
    * qemu-kvm:
      - add armhf armel powerpc sparc to Architecture
      - C/R/P: qemu-kvm-spice
    * add qemu-common package
    * drop qemu-slof which is not packaged in ubuntu
  - add qemu-system-common.links for tap ifup/down scripts and OVMF link.
  - qemu-system-x86.links:
    * remove pxe rom links which are in kvm-ipxe
    * add symlink for kvm.1 manpage
  - debian/rules
    * add kvm-spice symlink to qemu-kvm
    * call dh_installmodules for qemu-system-x86
    * update dh_installinit to install upstart script
    * run dh_installman (Closes: #709241) (cherrypicked from 1.5.0+dfsg-2)
  - Add qemu-utils.links for kvm-* symlinks.
  - Add qemu-system-x86.qemu-kvm.upstart and .default
  - Add qemu-system-x86.modprobe to set nesting=1
  - Add qemu-system-common.preinst to add kvm group
  - qemu-system-common.postinst: remove bad group acl if there, then have
    udev relabel /dev/kvm.
  - New linaro patches from qemu-linaro rebasing branch
  - Dropped patches:
    * xen-simplify-xen_enabled.patch
    * sparc-linux-user-fix-missing-symbols-in-.rel-.rela.plt-sections.patch
    * main_loop-do-not-set-nonblocking-if-xen_enabled.patch
    * xen_machine_pv-do-not-create-a-dummy-CPU-in-machine-.patch
    * virtio-rng-fix-crash
  - Kept patches:
    * expose_vms_qemu64cpu.patch - updated
    * linaro arm patches from qemu-linaro rebasing branch
  - New patches:
    * fix-pci-add: change CONFIG variable in ifdef to make sure that
      pci_add is defined.
* Add linaro patches
* Add experimental mach-virt patches for arm virtualization.
* qemu-system-common.install: add debian/tmp/usr/lib to install the
  qemu-bridge-helper

Show diffs side-by-side

added added

removed removed

Lines of Context:
105
105
#include <linux/vt.h>
106
106
#include <linux/dm-ioctl.h>
107
107
#include <linux/reboot.h>
 
108
#include <linux/route.h>
108
109
#include "linux_loop.h"
109
110
#include "cpu-uname.h"
110
111
 
111
112
#include "qemu.h"
112
113
 
113
 
#if defined(CONFIG_USE_NPTL)
114
114
#define CLONE_NPTL_FLAGS2 (CLONE_SETTLS | \
115
115
    CLONE_PARENT_SETTID | CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID)
116
 
#else
117
 
/* XXX: Hardcode the above values.  */
118
 
#define CLONE_NPTL_FLAGS2 0
119
 
#endif
120
116
 
121
117
//#define DEBUG
122
118
 
181
177
 
182
178
 
183
179
#define __NR_sys_uname __NR_uname
184
 
#define __NR_sys_faccessat __NR_faccessat
185
 
#define __NR_sys_fchmodat __NR_fchmodat
186
 
#define __NR_sys_fchownat __NR_fchownat
187
 
#define __NR_sys_fstatat64 __NR_fstatat64
188
 
#define __NR_sys_futimesat __NR_futimesat
189
180
#define __NR_sys_getcwd1 __NR_getcwd
190
181
#define __NR_sys_getdents __NR_getdents
191
182
#define __NR_sys_getdents64 __NR_getdents64
192
183
#define __NR_sys_getpriority __NR_getpriority
193
 
#define __NR_sys_linkat __NR_linkat
194
 
#define __NR_sys_mkdirat __NR_mkdirat
195
 
#define __NR_sys_mknodat __NR_mknodat
196
 
#define __NR_sys_newfstatat __NR_newfstatat
197
 
#define __NR_sys_openat __NR_openat
198
 
#define __NR_sys_readlinkat __NR_readlinkat
199
 
#define __NR_sys_renameat __NR_renameat
200
184
#define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
201
 
#define __NR_sys_symlinkat __NR_symlinkat
202
185
#define __NR_sys_syslog __NR_syslog
203
186
#define __NR_sys_tgkill __NR_tgkill
204
187
#define __NR_sys_tkill __NR_tkill
205
 
#define __NR_sys_unlinkat __NR_unlinkat
206
 
#define __NR_sys_utimensat __NR_utimensat
207
188
#define __NR_sys_futex __NR_futex
208
189
#define __NR_sys_inotify_init __NR_inotify_init
209
190
#define __NR_sys_inotify_add_watch __NR_inotify_add_watch
223
204
    return -ENOSYS;
224
205
}
225
206
#endif
 
207
#ifdef __NR_getdents
226
208
_syscall3(int, sys_getdents, uint, fd, struct linux_dirent *, dirp, uint, count);
227
 
#if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
 
209
#endif
 
210
#if !defined(__NR_getdents) || \
 
211
    (defined(TARGET_NR_getdents64) && defined(__NR_getdents64))
228
212
_syscall3(int, sys_getdents64, uint, fd, struct linux_dirent64 *, dirp, uint, count);
229
213
#endif
230
214
#if defined(TARGET_NR__llseek) && defined(__NR_llseek)
245
229
#if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
246
230
_syscall1(int,set_tid_address,int *,tidptr)
247
231
#endif
248
 
#if defined(CONFIG_USE_NPTL)
249
232
#if defined(TARGET_NR_futex) && defined(__NR_futex)
250
233
_syscall6(int,sys_futex,int *,uaddr,int,op,int,val,
251
234
          const struct timespec *,timeout,int *,uaddr2,int,val3)
252
235
#endif
253
 
#endif
254
236
#define __NR_sys_sched_getaffinity __NR_sched_getaffinity
255
237
_syscall3(int, sys_sched_getaffinity, pid_t, pid, unsigned int, len,
256
238
          unsigned long *, user_mask_ptr);
336
318
  return strlen(buf)+1;
337
319
}
338
320
 
339
 
#ifdef CONFIG_ATFILE
340
 
/*
341
 
 * Host system seems to have atfile syscall stubs available.  We
342
 
 * now enable them one by one as specified by target syscall_nr.h.
343
 
 */
344
 
 
345
 
#ifdef TARGET_NR_faccessat
346
 
static int sys_faccessat(int dirfd, const char *pathname, int mode)
347
 
{
348
 
  return (faccessat(dirfd, pathname, mode, 0));
349
 
}
350
 
#endif
351
 
#ifdef TARGET_NR_fchmodat
352
 
static int sys_fchmodat(int dirfd, const char *pathname, mode_t mode)
353
 
{
354
 
  return (fchmodat(dirfd, pathname, mode, 0));
355
 
}
356
 
#endif
357
 
#if defined(TARGET_NR_fchownat)
358
 
static int sys_fchownat(int dirfd, const char *pathname, uid_t owner,
359
 
    gid_t group, int flags)
360
 
{
361
 
  return (fchownat(dirfd, pathname, owner, group, flags));
362
 
}
363
 
#endif
364
 
#ifdef __NR_fstatat64
365
 
static int sys_fstatat64(int dirfd, const char *pathname, struct stat *buf,
366
 
    int flags)
367
 
{
368
 
  return (fstatat(dirfd, pathname, buf, flags));
369
 
}
370
 
#endif
371
 
#ifdef __NR_newfstatat
372
 
static int sys_newfstatat(int dirfd, const char *pathname, struct stat *buf,
373
 
    int flags)
374
 
{
375
 
  return (fstatat(dirfd, pathname, buf, flags));
376
 
}
377
 
#endif
378
 
#ifdef TARGET_NR_futimesat
379
 
static int sys_futimesat(int dirfd, const char *pathname,
380
 
    const struct timeval times[2])
381
 
{
382
 
  return (futimesat(dirfd, pathname, times));
383
 
}
384
 
#endif
385
 
#ifdef TARGET_NR_linkat
386
 
static int sys_linkat(int olddirfd, const char *oldpath,
387
 
    int newdirfd, const char *newpath, int flags)
388
 
{
389
 
  return (linkat(olddirfd, oldpath, newdirfd, newpath, flags));
390
 
}
391
 
#endif
392
 
#ifdef TARGET_NR_mkdirat
393
 
static int sys_mkdirat(int dirfd, const char *pathname, mode_t mode)
394
 
{
395
 
  return (mkdirat(dirfd, pathname, mode));
396
 
}
397
 
#endif
398
 
#ifdef TARGET_NR_mknodat
399
 
static int sys_mknodat(int dirfd, const char *pathname, mode_t mode,
400
 
    dev_t dev)
401
 
{
402
 
  return (mknodat(dirfd, pathname, mode, dev));
403
 
}
404
 
#endif
405
321
#ifdef TARGET_NR_openat
406
322
static int sys_openat(int dirfd, const char *pathname, int flags, mode_t mode)
407
323
{
415
331
  return (openat(dirfd, pathname, flags));
416
332
}
417
333
#endif
418
 
#ifdef TARGET_NR_readlinkat
419
 
static int sys_readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz)
420
 
{
421
 
  return (readlinkat(dirfd, pathname, buf, bufsiz));
422
 
}
423
 
#endif
424
 
#ifdef TARGET_NR_renameat
425
 
static int sys_renameat(int olddirfd, const char *oldpath,
426
 
    int newdirfd, const char *newpath)
427
 
{
428
 
  return (renameat(olddirfd, oldpath, newdirfd, newpath));
429
 
}
430
 
#endif
431
 
#ifdef TARGET_NR_symlinkat
432
 
static int sys_symlinkat(const char *oldpath, int newdirfd, const char *newpath)
433
 
{
434
 
  return (symlinkat(oldpath, newdirfd, newpath));
435
 
}
436
 
#endif
437
 
#ifdef TARGET_NR_unlinkat
438
 
static int sys_unlinkat(int dirfd, const char *pathname, int flags)
439
 
{
440
 
  return (unlinkat(dirfd, pathname, flags));
441
 
}
442
 
#endif
443
 
#else /* !CONFIG_ATFILE */
444
 
 
445
 
/*
446
 
 * Try direct syscalls instead
447
 
 */
448
 
#if defined(TARGET_NR_faccessat) && defined(__NR_faccessat)
449
 
_syscall3(int,sys_faccessat,int,dirfd,const char *,pathname,int,mode)
450
 
#endif
451
 
#if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
452
 
_syscall3(int,sys_fchmodat,int,dirfd,const char *,pathname, mode_t,mode)
453
 
#endif
454
 
#if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
455
 
_syscall5(int,sys_fchownat,int,dirfd,const char *,pathname,
456
 
          uid_t,owner,gid_t,group,int,flags)
457
 
#endif
458
 
#if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \
459
 
        defined(__NR_fstatat64)
460
 
_syscall4(int,sys_fstatat64,int,dirfd,const char *,pathname,
461
 
          struct stat *,buf,int,flags)
462
 
#endif
463
 
#if defined(TARGET_NR_futimesat) && defined(__NR_futimesat)
464
 
_syscall3(int,sys_futimesat,int,dirfd,const char *,pathname,
465
 
         const struct timeval *,times)
466
 
#endif
467
 
#if (defined(TARGET_NR_newfstatat) || defined(TARGET_NR_fstatat64) ) && \
468
 
        defined(__NR_newfstatat)
469
 
_syscall4(int,sys_newfstatat,int,dirfd,const char *,pathname,
470
 
          struct stat *,buf,int,flags)
471
 
#endif
472
 
#if defined(TARGET_NR_linkat) && defined(__NR_linkat)
473
 
_syscall5(int,sys_linkat,int,olddirfd,const char *,oldpath,
474
 
      int,newdirfd,const char *,newpath,int,flags)
475
 
#endif
476
 
#if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
477
 
_syscall3(int,sys_mkdirat,int,dirfd,const char *,pathname,mode_t,mode)
478
 
#endif
479
 
#if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
480
 
_syscall4(int,sys_mknodat,int,dirfd,const char *,pathname,
481
 
          mode_t,mode,dev_t,dev)
482
 
#endif
483
 
#if defined(TARGET_NR_openat) && defined(__NR_openat)
484
 
_syscall4(int,sys_openat,int,dirfd,const char *,pathname,int,flags,mode_t,mode)
485
 
#endif
486
 
#if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
487
 
_syscall4(int,sys_readlinkat,int,dirfd,const char *,pathname,
488
 
          char *,buf,size_t,bufsize)
489
 
#endif
490
 
#if defined(TARGET_NR_renameat) && defined(__NR_renameat)
491
 
_syscall4(int,sys_renameat,int,olddirfd,const char *,oldpath,
492
 
          int,newdirfd,const char *,newpath)
493
 
#endif
494
 
#if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
495
 
_syscall3(int,sys_symlinkat,const char *,oldpath,
496
 
          int,newdirfd,const char *,newpath)
497
 
#endif
498
 
#if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
499
 
_syscall3(int,sys_unlinkat,int,dirfd,const char *,pathname,int,flags)
500
 
#endif
501
 
 
502
 
#endif /* CONFIG_ATFILE */
503
 
 
 
334
 
 
335
#ifdef TARGET_NR_utimensat
504
336
#ifdef CONFIG_UTIMENSAT
505
337
static int sys_utimensat(int dirfd, const char *pathname,
506
338
    const struct timespec times[2], int flags)
510
342
    else
511
343
        return utimensat(dirfd, pathname, times, flags);
512
344
}
513
 
#else
514
 
#if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
 
345
#elif defined(__NR_utimensat)
 
346
#define __NR_sys_utimensat __NR_utimensat
515
347
_syscall4(int,sys_utimensat,int,dirfd,const char *,pathname,
516
348
          const struct timespec *,tsp,int,flags)
 
349
#else
 
350
static int sys_utimensat(int dirfd, const char *pathname,
 
351
                         const struct timespec times[2], int flags)
 
352
{
 
353
    errno = ENOSYS;
 
354
    return -1;
 
355
}
517
356
#endif
518
 
#endif /* CONFIG_UTIMENSAT  */
 
357
#endif /* TARGET_NR_utimensat */
519
358
 
520
359
#ifdef CONFIG_INOTIFY
521
360
#include <sys/inotify.h>
1193
1032
#elif defined(TARGET_SH4)
1194
1033
        ((CPUSH4State*)cpu_env)->gregs[1] = host_pipe[1];
1195
1034
        return host_pipe[0];
 
1035
#elif defined(TARGET_SPARC)
 
1036
        ((CPUSPARCState*)cpu_env)->regwptr[1] = host_pipe[1];
 
1037
        return host_pipe[0];
1196
1038
#endif
1197
1039
    }
1198
1040
 
1859
1701
    free(vec);
1860
1702
}
1861
1703
 
 
1704
static inline void target_to_host_sock_type(int *type)
 
1705
{
 
1706
    int host_type = 0;
 
1707
    int target_type = *type;
 
1708
 
 
1709
    switch (target_type & TARGET_SOCK_TYPE_MASK) {
 
1710
    case TARGET_SOCK_DGRAM:
 
1711
        host_type = SOCK_DGRAM;
 
1712
        break;
 
1713
    case TARGET_SOCK_STREAM:
 
1714
        host_type = SOCK_STREAM;
 
1715
        break;
 
1716
    default:
 
1717
        host_type = target_type & TARGET_SOCK_TYPE_MASK;
 
1718
        break;
 
1719
    }
 
1720
    if (target_type & TARGET_SOCK_CLOEXEC) {
 
1721
        host_type |= SOCK_CLOEXEC;
 
1722
    }
 
1723
    if (target_type & TARGET_SOCK_NONBLOCK) {
 
1724
        host_type |= SOCK_NONBLOCK;
 
1725
    }
 
1726
    *type = host_type;
 
1727
}
 
1728
 
1862
1729
/* do_socket() Must return target values and target errnos. */
1863
1730
static abi_long do_socket(int domain, int type, int protocol)
1864
1731
{
1865
 
#if defined(TARGET_MIPS)
1866
 
    switch(type) {
1867
 
    case TARGET_SOCK_DGRAM:
1868
 
        type = SOCK_DGRAM;
1869
 
        break;
1870
 
    case TARGET_SOCK_STREAM:
1871
 
        type = SOCK_STREAM;
1872
 
        break;
1873
 
    case TARGET_SOCK_RAW:
1874
 
        type = SOCK_RAW;
1875
 
        break;
1876
 
    case TARGET_SOCK_RDM:
1877
 
        type = SOCK_RDM;
1878
 
        break;
1879
 
    case TARGET_SOCK_SEQPACKET:
1880
 
        type = SOCK_SEQPACKET;
1881
 
        break;
1882
 
    case TARGET_SOCK_PACKET:
1883
 
        type = SOCK_PACKET;
1884
 
        break;
1885
 
    }
1886
 
#endif
 
1732
    target_to_host_sock_type(&type);
 
1733
 
1887
1734
    if (domain == PF_NETLINK)
1888
1735
        return -EAFNOSUPPORT; /* do not NETLINK socket connections possible */
1889
1736
    return get_errno(socket(domain, type, protocol));
2116
1963
    int tab[2];
2117
1964
    abi_long ret;
2118
1965
 
 
1966
    target_to_host_sock_type(&type);
 
1967
 
2119
1968
    ret = get_errno(socketpair(domain, type, protocol, tab));
2120
1969
    if (!is_error(ret)) {
2121
1970
        if (put_user_s32(tab[0], target_tab_addr)
3714
3563
    return ret;
3715
3564
}
3716
3565
 
 
3566
static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp,
 
3567
                                int fd, abi_long cmd, abi_long arg)
 
3568
{
 
3569
    const argtype *arg_type = ie->arg_type;
 
3570
    const StructEntry *se;
 
3571
    const argtype *field_types;
 
3572
    const int *dst_offsets, *src_offsets;
 
3573
    int target_size;
 
3574
    void *argptr;
 
3575
    abi_ulong *target_rt_dev_ptr;
 
3576
    unsigned long *host_rt_dev_ptr;
 
3577
    abi_long ret;
 
3578
    int i;
 
3579
 
 
3580
    assert(ie->access == IOC_W);
 
3581
    assert(*arg_type == TYPE_PTR);
 
3582
    arg_type++;
 
3583
    assert(*arg_type == TYPE_STRUCT);
 
3584
    target_size = thunk_type_size(arg_type, 0);
 
3585
    argptr = lock_user(VERIFY_READ, arg, target_size, 1);
 
3586
    if (!argptr) {
 
3587
        return -TARGET_EFAULT;
 
3588
    }
 
3589
    arg_type++;
 
3590
    assert(*arg_type == (int)STRUCT_rtentry);
 
3591
    se = struct_entries + *arg_type++;
 
3592
    assert(se->convert[0] == NULL);
 
3593
    /* convert struct here to be able to catch rt_dev string */
 
3594
    field_types = se->field_types;
 
3595
    dst_offsets = se->field_offsets[THUNK_HOST];
 
3596
    src_offsets = se->field_offsets[THUNK_TARGET];
 
3597
    for (i = 0; i < se->nb_fields; i++) {
 
3598
        if (dst_offsets[i] == offsetof(struct rtentry, rt_dev)) {
 
3599
            assert(*field_types == TYPE_PTRVOID);
 
3600
            target_rt_dev_ptr = (abi_ulong *)(argptr + src_offsets[i]);
 
3601
            host_rt_dev_ptr = (unsigned long *)(buf_temp + dst_offsets[i]);
 
3602
            if (*target_rt_dev_ptr != 0) {
 
3603
                *host_rt_dev_ptr = (unsigned long)lock_user_string(
 
3604
                                                  tswapal(*target_rt_dev_ptr));
 
3605
                if (!*host_rt_dev_ptr) {
 
3606
                    unlock_user(argptr, arg, 0);
 
3607
                    return -TARGET_EFAULT;
 
3608
                }
 
3609
            } else {
 
3610
                *host_rt_dev_ptr = 0;
 
3611
            }
 
3612
            field_types++;
 
3613
            continue;
 
3614
        }
 
3615
        field_types = thunk_convert(buf_temp + dst_offsets[i],
 
3616
                                    argptr + src_offsets[i],
 
3617
                                    field_types, THUNK_HOST);
 
3618
    }
 
3619
    unlock_user(argptr, arg, 0);
 
3620
 
 
3621
    ret = get_errno(ioctl(fd, ie->host_cmd, buf_temp));
 
3622
    if (*host_rt_dev_ptr != 0) {
 
3623
        unlock_user((void *)*host_rt_dev_ptr,
 
3624
                    *target_rt_dev_ptr, 0);
 
3625
    }
 
3626
    return ret;
 
3627
}
 
3628
 
3717
3629
static IOCTLEntry ioctl_entries[] = {
3718
3630
#define IOCTL(cmd, access, ...) \
3719
3631
    { TARGET_ ## cmd, cmd, #cmd, access, 0, {  __VA_ARGS__ } },
4139
4051
}
4140
4052
 
4141
4053
#if defined(TARGET_I386) && defined(TARGET_ABI32)
4142
 
static abi_long do_set_thread_area(CPUX86State *env, abi_ulong ptr)
 
4054
abi_long do_set_thread_area(CPUX86State *env, abi_ulong ptr)
4143
4055
{
4144
4056
    uint64_t *gdt_table = g2h(env->gdt.base);
4145
4057
    struct target_modify_ldt_ldt_s ldt_info;
4273
4185
#endif /* TARGET_I386 && TARGET_ABI32 */
4274
4186
 
4275
4187
#ifndef TARGET_ABI32
4276
 
static abi_long do_arch_prctl(CPUX86State *env, int code, abi_ulong addr)
 
4188
abi_long do_arch_prctl(CPUX86State *env, int code, abi_ulong addr)
4277
4189
{
4278
4190
    abi_long ret = 0;
4279
4191
    abi_ulong val;
4311
4223
 
4312
4224
#define NEW_STACK_SIZE 0x40000
4313
4225
 
4314
 
#if defined(CONFIG_USE_NPTL)
4315
4226
 
4316
4227
static pthread_mutex_t clone_lock = PTHREAD_MUTEX_INITIALIZER;
4317
4228
typedef struct {
4334
4245
 
4335
4246
    env = info->env;
4336
4247
    cpu = ENV_GET_CPU(env);
4337
 
    thread_env = env;
4338
 
    ts = (TaskState *)thread_env->opaque;
 
4248
    thread_cpu = cpu;
 
4249
    ts = (TaskState *)env->opaque;
4339
4250
    info->tid = gettid();
4340
4251
    cpu->host_tid = info->tid;
4341
4252
    task_settid(ts);
4356
4267
    /* never exits */
4357
4268
    return NULL;
4358
4269
}
4359
 
#else
4360
 
 
4361
 
static int clone_func(void *arg)
4362
 
{
4363
 
    CPUArchState *env = arg;
4364
 
    cpu_loop(env);
4365
 
    /* never exits */
4366
 
    return 0;
4367
 
}
4368
 
#endif
4369
4270
 
4370
4271
/* do_fork() Must return host values and target errnos (unlike most
4371
4272
   do_*() functions). */
4376
4277
    int ret;
4377
4278
    TaskState *ts;
4378
4279
    CPUArchState *new_env;
4379
 
#if defined(CONFIG_USE_NPTL)
4380
4280
    unsigned int nptl_flags;
4381
4281
    sigset_t sigmask;
4382
 
#else
4383
 
    uint8_t *new_stack;
4384
 
#endif
4385
4282
 
4386
4283
    /* Emulate vfork() with fork() */
4387
4284
    if (flags & CLONE_VFORK)
4389
4286
 
4390
4287
    if (flags & CLONE_VM) {
4391
4288
        TaskState *parent_ts = (TaskState *)env->opaque;
4392
 
#if defined(CONFIG_USE_NPTL)
4393
4289
        new_thread_info info;
4394
4290
        pthread_attr_t attr;
4395
 
#endif
 
4291
 
4396
4292
        ts = g_malloc0(sizeof(TaskState));
4397
4293
        init_task_state(ts);
4398
4294
        /* we create a new CPU instance. */
4399
4295
        new_env = cpu_copy(env);
4400
 
#if defined(TARGET_I386) || defined(TARGET_SPARC) || defined(TARGET_PPC)
4401
 
        cpu_reset(ENV_GET_CPU(new_env));
4402
 
#endif
4403
4296
        /* Init regs that differ from the parent.  */
4404
4297
        cpu_clone_regs(new_env, newsp);
4405
4298
        new_env->opaque = ts;
4406
4299
        ts->bprm = parent_ts->bprm;
4407
4300
        ts->info = parent_ts->info;
4408
 
#if defined(CONFIG_USE_NPTL)
4409
4301
        nptl_flags = flags;
4410
4302
        flags &= ~CLONE_NPTL_FLAGS2;
4411
4303
 
4455
4347
        pthread_cond_destroy(&info.cond);
4456
4348
        pthread_mutex_destroy(&info.mutex);
4457
4349
        pthread_mutex_unlock(&clone_lock);
4458
 
#else
4459
 
        if (flags & CLONE_NPTL_FLAGS2)
4460
 
            return -EINVAL;
4461
 
        /* This is probably going to die very quickly, but do it anyway.  */
4462
 
        new_stack = g_malloc0 (NEW_STACK_SIZE);
4463
 
#ifdef __ia64__
4464
 
        ret = __clone2(clone_func, new_stack, NEW_STACK_SIZE, flags, new_env);
4465
 
#else
4466
 
        ret = clone(clone_func, new_stack + NEW_STACK_SIZE, flags, new_env);
4467
 
#endif
4468
 
#endif
4469
4350
    } else {
4470
4351
        /* if no CLONE_VM, we consider it is a fork */
4471
4352
        if ((flags & ~(CSIGNAL | CLONE_NPTL_FLAGS2)) != 0)
4476
4357
            /* Child Process.  */
4477
4358
            cpu_clone_regs(env, newsp);
4478
4359
            fork_end(1);
4479
 
#if defined(CONFIG_USE_NPTL)
4480
4360
            /* There is a race condition here.  The parent process could
4481
4361
               theoretically read the TID in the child process before the child
4482
4362
               tid is set.  This would require using either ptrace
4492
4372
                cpu_set_tls (env, newtls);
4493
4373
            if (flags & CLONE_CHILD_CLEARTID)
4494
4374
                ts->child_tidptr = child_tidptr;
4495
 
#endif
4496
4375
        } else {
4497
4376
            fork_end(0);
4498
4377
        }
4918
4797
}
4919
4798
#endif
4920
4799
 
4921
 
#if defined(CONFIG_USE_NPTL)
4922
4800
/* ??? Using host futex calls even when target atomic operations
4923
4801
   are not really atomic probably breaks things.  However implementing
4924
4802
   futexes locally would make futexes shared between multiple processes
4970
4848
        return -TARGET_ENOSYS;
4971
4849
    }
4972
4850
}
4973
 
#endif
4974
4851
 
4975
4852
/* Map host to target signal numbers for the wait family of syscalls.
4976
4853
   Assume all other status bits are the same.  */
5050
4927
        }
5051
4928
        if (h2g_valid(min) && h2g_valid(max)) {
5052
4929
            dprintf(fd, TARGET_ABI_FMT_lx "-" TARGET_ABI_FMT_lx
5053
 
                    " %c%c%c%c %08" PRIx64 " %02x:%02x %d%s%s\n",
 
4930
                    " %c%c%c%c %08" PRIx64 " %02x:%02x %d %s%s\n",
5054
4931
                    h2g(min), h2g(max), flag_r, flag_w,
5055
4932
                    flag_x, flag_p, offset, dev_maj, dev_min, inode,
5056
 
                    path[0] ? "          " : "", path);
 
4933
                    path[0] ? "         " : "", path);
5057
4934
        }
5058
4935
    }
5059
4936
 
5136
5013
    return 0;
5137
5014
}
5138
5015
 
 
5016
static int is_proc_myself(const char *filename, const char *entry)
 
5017
{
 
5018
    if (!strncmp(filename, "/proc/", strlen("/proc/"))) {
 
5019
        filename += strlen("/proc/");
 
5020
        if (!strncmp(filename, "self/", strlen("self/"))) {
 
5021
            filename += strlen("self/");
 
5022
        } else if (*filename >= '1' && *filename <= '9') {
 
5023
            char myself[80];
 
5024
            snprintf(myself, sizeof(myself), "%d/", getpid());
 
5025
            if (!strncmp(filename, myself, strlen(myself))) {
 
5026
                filename += strlen(myself);
 
5027
            } else {
 
5028
                return 0;
 
5029
            }
 
5030
        } else {
 
5031
            return 0;
 
5032
        }
 
5033
        if (!strcmp(filename, entry)) {
 
5034
            return 1;
 
5035
        }
 
5036
    }
 
5037
    return 0;
 
5038
}
 
5039
 
5139
5040
static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
5140
5041
{
5141
5042
    struct fake_open {
5144
5045
    };
5145
5046
    const struct fake_open *fake_open;
5146
5047
    static const struct fake_open fakes[] = {
5147
 
        { "/proc/self/maps", open_self_maps },
5148
 
        { "/proc/self/stat", open_self_stat },
5149
 
        { "/proc/self/auxv", open_self_auxv },
 
5048
        { "maps", open_self_maps },
 
5049
        { "stat", open_self_stat },
 
5050
        { "auxv", open_self_auxv },
5150
5051
        { NULL, NULL }
5151
5052
    };
5152
5053
 
5153
5054
    for (fake_open = fakes; fake_open->filename; fake_open++) {
5154
 
        if (!strncmp(pathname, fake_open->filename,
5155
 
                     strlen(fake_open->filename))) {
 
5055
        if (is_proc_myself(pathname, fake_open->filename)) {
5156
5056
            break;
5157
5057
        }
5158
5058
    }
5193
5093
                    abi_long arg5, abi_long arg6, abi_long arg7,
5194
5094
                    abi_long arg8)
5195
5095
{
 
5096
    CPUState *cpu = ENV_GET_CPU(cpu_env);
5196
5097
    abi_long ret;
5197
5098
    struct stat st;
5198
5099
    struct statfs stfs;
5206
5107
 
5207
5108
    switch(num) {
5208
5109
    case TARGET_NR_exit:
5209
 
#ifdef CONFIG_USE_NPTL
5210
 
      /* In old applications this may be used to implement _exit(2).
5211
 
         However in threaded applictions it is used for thread termination,
5212
 
         and _exit_group is used for application termination.
5213
 
         Do thread termination if we have more then one thread.  */
5214
 
      /* FIXME: This probably breaks if a signal arrives.  We should probably
5215
 
         be disabling signals.  */
5216
 
      if (first_cpu->next_cpu) {
5217
 
          TaskState *ts;
5218
 
          CPUArchState **lastp;
5219
 
          CPUArchState *p;
 
5110
        /* In old applications this may be used to implement _exit(2).
 
5111
           However in threaded applictions it is used for thread termination,
 
5112
           and _exit_group is used for application termination.
 
5113
           Do thread termination if we have more then one thread.  */
 
5114
        /* FIXME: This probably breaks if a signal arrives.  We should probably
 
5115
           be disabling signals.  */
 
5116
        if (first_cpu->next_cpu) {
 
5117
            TaskState *ts;
 
5118
            CPUState **lastp;
 
5119
            CPUState *p;
5220
5120
 
5221
 
          cpu_list_lock();
5222
 
          lastp = &first_cpu;
5223
 
          p = first_cpu;
5224
 
          while (p && p != (CPUArchState *)cpu_env) {
5225
 
              lastp = &p->next_cpu;
5226
 
              p = p->next_cpu;
5227
 
          }
5228
 
          /* If we didn't find the CPU for this thread then something is
5229
 
             horribly wrong.  */
5230
 
          if (!p)
5231
 
              abort();
5232
 
          /* Remove the CPU from the list.  */
5233
 
          *lastp = p->next_cpu;
5234
 
          cpu_list_unlock();
5235
 
          ts = ((CPUArchState *)cpu_env)->opaque;
5236
 
          if (ts->child_tidptr) {
5237
 
              put_user_u32(0, ts->child_tidptr);
5238
 
              sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,
5239
 
                        NULL, NULL, 0);
5240
 
          }
5241
 
          thread_env = NULL;
5242
 
          object_unref(OBJECT(ENV_GET_CPU(cpu_env)));
5243
 
          g_free(ts);
5244
 
          pthread_exit(NULL);
5245
 
      }
5246
 
#endif
 
5121
            cpu_list_lock();
 
5122
            lastp = &first_cpu;
 
5123
            p = first_cpu;
 
5124
            while (p && p != cpu) {
 
5125
                lastp = &p->next_cpu;
 
5126
                p = p->next_cpu;
 
5127
            }
 
5128
            /* If we didn't find the CPU for this thread then something is
 
5129
               horribly wrong.  */
 
5130
            if (!p) {
 
5131
                abort();
 
5132
            }
 
5133
            /* Remove the CPU from the list.  */
 
5134
            *lastp = p->next_cpu;
 
5135
            cpu_list_unlock();
 
5136
            ts = ((CPUArchState *)cpu_env)->opaque;
 
5137
            if (ts->child_tidptr) {
 
5138
                put_user_u32(0, ts->child_tidptr);
 
5139
                sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,
 
5140
                          NULL, NULL, 0);
 
5141
            }
 
5142
            thread_cpu = NULL;
 
5143
            object_unref(OBJECT(ENV_GET_CPU(cpu_env)));
 
5144
            g_free(ts);
 
5145
            pthread_exit(NULL);
 
5146
        }
5247
5147
#ifdef TARGET_GPROF
5248
5148
        _mcleanup();
5249
5149
#endif
5342
5242
            unlock_user(p, arg1, 0);
5343
5243
        }
5344
5244
        break;
5345
 
#if defined(TARGET_NR_linkat) && defined(__NR_linkat)
 
5245
#if defined(TARGET_NR_linkat)
5346
5246
    case TARGET_NR_linkat:
5347
5247
        {
5348
5248
            void * p2 = NULL;
5353
5253
            if (!p || !p2)
5354
5254
                ret = -TARGET_EFAULT;
5355
5255
            else
5356
 
                ret = get_errno(sys_linkat(arg1, p, arg3, p2, arg5));
 
5256
                ret = get_errno(linkat(arg1, p, arg3, p2, arg5));
5357
5257
            unlock_user(p, arg2, 0);
5358
5258
            unlock_user(p2, arg4, 0);
5359
5259
        }
5365
5265
        ret = get_errno(unlink(p));
5366
5266
        unlock_user(p, arg1, 0);
5367
5267
        break;
5368
 
#if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
 
5268
#if defined(TARGET_NR_unlinkat)
5369
5269
    case TARGET_NR_unlinkat:
5370
5270
        if (!(p = lock_user_string(arg2)))
5371
5271
            goto efault;
5372
 
        ret = get_errno(sys_unlinkat(arg1, p, arg3));
 
5272
        ret = get_errno(unlinkat(arg1, p, arg3));
5373
5273
        unlock_user(p, arg2, 0);
5374
5274
        break;
5375
5275
#endif
5487
5387
        ret = get_errno(mknod(p, arg2, arg3));
5488
5388
        unlock_user(p, arg1, 0);
5489
5389
        break;
5490
 
#if defined(TARGET_NR_mknodat) && defined(__NR_mknodat)
 
5390
#if defined(TARGET_NR_mknodat)
5491
5391
    case TARGET_NR_mknodat:
5492
5392
        if (!(p = lock_user_string(arg2)))
5493
5393
            goto efault;
5494
 
        ret = get_errno(sys_mknodat(arg1, p, arg3, arg4));
 
5394
        ret = get_errno(mknodat(arg1, p, arg3, arg4));
5495
5395
        unlock_user(p, arg2, 0);
5496
5396
        break;
5497
5397
#endif
5622
5522
            unlock_user(p, arg1, 0);
5623
5523
        }
5624
5524
        break;
5625
 
#if defined(TARGET_NR_futimesat) && defined(__NR_futimesat)
 
5525
#if defined(TARGET_NR_futimesat)
5626
5526
    case TARGET_NR_futimesat:
5627
5527
        {
5628
5528
            struct timeval *tvp, tv[2];
5637
5537
            }
5638
5538
            if (!(p = lock_user_string(arg2)))
5639
5539
                goto efault;
5640
 
            ret = get_errno(sys_futimesat(arg1, path(p), tvp));
 
5540
            ret = get_errno(futimesat(arg1, path(p), tvp));
5641
5541
            unlock_user(p, arg2, 0);
5642
5542
        }
5643
5543
        break;
5660
5560
    case TARGET_NR_faccessat:
5661
5561
        if (!(p = lock_user_string(arg2)))
5662
5562
            goto efault;
5663
 
        ret = get_errno(sys_faccessat(arg1, p, arg3));
 
5563
        ret = get_errno(faccessat(arg1, p, arg3, 0));
5664
5564
        unlock_user(p, arg2, 0);
5665
5565
        break;
5666
5566
#endif
5693
5593
            unlock_user(p, arg1, 0);
5694
5594
        }
5695
5595
        break;
5696
 
#if defined(TARGET_NR_renameat) && defined(__NR_renameat)
 
5596
#if defined(TARGET_NR_renameat)
5697
5597
    case TARGET_NR_renameat:
5698
5598
        {
5699
5599
            void *p2;
5702
5602
            if (!p || !p2)
5703
5603
                ret = -TARGET_EFAULT;
5704
5604
            else
5705
 
                ret = get_errno(sys_renameat(arg1, p, arg3, p2));
 
5605
                ret = get_errno(renameat(arg1, p, arg3, p2));
5706
5606
            unlock_user(p2, arg4, 0);
5707
5607
            unlock_user(p, arg2, 0);
5708
5608
        }
5714
5614
        ret = get_errno(mkdir(p, arg2));
5715
5615
        unlock_user(p, arg1, 0);
5716
5616
        break;
5717
 
#if defined(TARGET_NR_mkdirat) && defined(__NR_mkdirat)
 
5617
#if defined(TARGET_NR_mkdirat)
5718
5618
    case TARGET_NR_mkdirat:
5719
5619
        if (!(p = lock_user_string(arg2)))
5720
5620
            goto efault;
5721
 
        ret = get_errno(sys_mkdirat(arg1, p, arg3));
 
5621
        ret = get_errno(mkdirat(arg1, p, arg3));
5722
5622
        unlock_user(p, arg2, 0);
5723
5623
        break;
5724
5624
#endif
6404
6304
            unlock_user(p, arg1, 0);
6405
6305
        }
6406
6306
        break;
6407
 
#if defined(TARGET_NR_symlinkat) && defined(__NR_symlinkat)
 
6307
#if defined(TARGET_NR_symlinkat)
6408
6308
    case TARGET_NR_symlinkat:
6409
6309
        {
6410
6310
            void *p2;
6413
6313
            if (!p || !p2)
6414
6314
                ret = -TARGET_EFAULT;
6415
6315
            else
6416
 
                ret = get_errno(sys_symlinkat(p, arg2, p2));
 
6316
                ret = get_errno(symlinkat(p, arg2, p2));
6417
6317
            unlock_user(p2, arg3, 0);
6418
6318
            unlock_user(p, arg1, 0);
6419
6319
        }
6425
6325
#endif
6426
6326
    case TARGET_NR_readlink:
6427
6327
        {
6428
 
            void *p2, *temp;
 
6328
            void *p2;
6429
6329
            p = lock_user_string(arg1);
6430
6330
            p2 = lock_user(VERIFY_WRITE, arg2, arg3, 0);
6431
 
            if (!p || !p2)
 
6331
            if (!p || !p2) {
6432
6332
                ret = -TARGET_EFAULT;
6433
 
            else {
6434
 
                if (strncmp((const char *)p, "/proc/self/exe", 14) == 0) {
6435
 
                    char real[PATH_MAX];
6436
 
                    temp = realpath(exec_path,real);
6437
 
                    ret = (temp==NULL) ? get_errno(-1) : strlen(real) ;
6438
 
                    snprintf((char *)p2, arg3, "%s", real);
6439
 
                    }
6440
 
                else
6441
 
                    ret = get_errno(readlink(path(p), p2, arg3));
 
6333
            } else if (is_proc_myself((const char *)p, "exe")) {
 
6334
                char real[PATH_MAX], *temp;
 
6335
                temp = realpath(exec_path, real);
 
6336
                ret = temp == NULL ? get_errno(-1) : strlen(real) ;
 
6337
                snprintf((char *)p2, arg3, "%s", real);
 
6338
            } else {
 
6339
                ret = get_errno(readlink(path(p), p2, arg3));
6442
6340
            }
6443
6341
            unlock_user(p2, arg2, ret);
6444
6342
            unlock_user(p, arg1, 0);
6445
6343
        }
6446
6344
        break;
6447
 
#if defined(TARGET_NR_readlinkat) && defined(__NR_readlinkat)
 
6345
#if defined(TARGET_NR_readlinkat)
6448
6346
    case TARGET_NR_readlinkat:
6449
6347
        {
6450
6348
            void *p2;
6451
6349
            p  = lock_user_string(arg2);
6452
6350
            p2 = lock_user(VERIFY_WRITE, arg3, arg4, 0);
6453
 
            if (!p || !p2)
6454
 
                ret = -TARGET_EFAULT;
6455
 
            else
6456
 
                ret = get_errno(sys_readlinkat(arg1, path(p), p2, arg4));
 
6351
            if (!p || !p2) {
 
6352
                ret = -TARGET_EFAULT;
 
6353
            } else if (is_proc_myself((const char *)p, "exe")) {
 
6354
                char real[PATH_MAX], *temp;
 
6355
                temp = realpath(exec_path, real);
 
6356
                ret = temp == NULL ? get_errno(-1) : strlen(real) ;
 
6357
                snprintf((char *)p2, arg4, "%s", real);
 
6358
            } else {
 
6359
                ret = get_errno(readlinkat(arg1, path(p), p2, arg4));
 
6360
            }
6457
6361
            unlock_user(p2, arg3, ret);
6458
6362
            unlock_user(p, arg2, 0);
6459
6363
        }
6588
6492
    case TARGET_NR_fchmod:
6589
6493
        ret = get_errno(fchmod(arg1, arg2));
6590
6494
        break;
6591
 
#if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
 
6495
#if defined(TARGET_NR_fchmodat)
6592
6496
    case TARGET_NR_fchmodat:
6593
6497
        if (!(p = lock_user_string(arg2)))
6594
6498
            goto efault;
6595
 
        ret = get_errno(sys_fchmodat(arg1, p, arg3));
 
6499
        ret = get_errno(fchmodat(arg1, p, arg3, 0));
6596
6500
        unlock_user(p, arg2, 0);
6597
6501
        break;
6598
6502
#endif
7009
6913
        ret = get_errno(fsync(arg1));
7010
6914
        break;
7011
6915
    case TARGET_NR_clone:
7012
 
#if defined(TARGET_SH4) || defined(TARGET_ALPHA)
7013
 
        ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg5, arg4));
7014
 
#elif defined(TARGET_CRIS)
7015
 
        ret = get_errno(do_fork(cpu_env, arg2, arg1, arg3, arg4, arg5));
7016
 
#elif defined(TARGET_MICROBLAZE)
 
6916
        /* Linux manages to have three different orderings for its
 
6917
         * arguments to clone(); the BACKWARDS and BACKWARDS2 defines
 
6918
         * match the kernel's CONFIG_CLONE_* settings.
 
6919
         * Microblaze is further special in that it uses a sixth
 
6920
         * implicit argument to clone for the TLS pointer.
 
6921
         */
 
6922
#if defined(TARGET_MICROBLAZE)
7017
6923
        ret = get_errno(do_fork(cpu_env, arg1, arg2, arg4, arg6, arg5));
7018
 
#elif defined(TARGET_S390X)
 
6924
#elif defined(TARGET_CLONE_BACKWARDS)
 
6925
        ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg4, arg5));
 
6926
#elif defined(TARGET_CLONE_BACKWARDS2)
7019
6927
        ret = get_errno(do_fork(cpu_env, arg2, arg1, arg3, arg5, arg4));
7020
6928
#else
7021
 
        ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg4, arg5));
 
6929
        ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg5, arg4));
7022
6930
#endif
7023
6931
        break;
7024
6932
#ifdef __NR_exit_group
7123
7031
        break;
7124
7032
#endif
7125
7033
    case TARGET_NR_getdents:
 
7034
#ifdef __NR_getdents
7126
7035
#if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64
7127
7036
        {
7128
7037
            struct target_dirent *target_dirp;
7195
7104
            unlock_user(dirp, arg2, ret);
7196
7105
        }
7197
7106
#endif
 
7107
#else
 
7108
        /* Implement getdents in terms of getdents64 */
 
7109
        {
 
7110
            struct linux_dirent64 *dirp;
 
7111
            abi_long count = arg3;
 
7112
 
 
7113
            dirp = lock_user(VERIFY_WRITE, arg2, count, 0);
 
7114
            if (!dirp) {
 
7115
                goto efault;
 
7116
            }
 
7117
            ret = get_errno(sys_getdents64(arg1, dirp, count));
 
7118
            if (!is_error(ret)) {
 
7119
                /* Convert the dirent64 structs to target dirent.  We do this
 
7120
                 * in-place, since we can guarantee that a target_dirent is no
 
7121
                 * larger than a dirent64; however this means we have to be
 
7122
                 * careful to read everything before writing in the new format.
 
7123
                 */
 
7124
                struct linux_dirent64 *de;
 
7125
                struct target_dirent *tde;
 
7126
                int len = ret;
 
7127
                int tlen = 0;
 
7128
 
 
7129
                de = dirp;
 
7130
                tde = (struct target_dirent *)dirp;
 
7131
                while (len > 0) {
 
7132
                    int namelen, treclen;
 
7133
                    int reclen = de->d_reclen;
 
7134
                    uint64_t ino = de->d_ino;
 
7135
                    int64_t off = de->d_off;
 
7136
                    uint8_t type = de->d_type;
 
7137
 
 
7138
                    namelen = strlen(de->d_name);
 
7139
                    treclen = offsetof(struct target_dirent, d_name)
 
7140
                        + namelen + 2;
 
7141
                    treclen = QEMU_ALIGN_UP(treclen, sizeof(abi_long));
 
7142
 
 
7143
                    memmove(tde->d_name, de->d_name, namelen + 1);
 
7144
                    tde->d_ino = tswapal(ino);
 
7145
                    tde->d_off = tswapal(off);
 
7146
                    tde->d_reclen = tswap16(treclen);
 
7147
                    /* The target_dirent type is in what was formerly a padding
 
7148
                     * byte at the end of the structure:
 
7149
                     */
 
7150
                    *(((char *)tde) + treclen - 1) = type;
 
7151
 
 
7152
                    de = (struct linux_dirent64 *)((char *)de + reclen);
 
7153
                    tde = (struct target_dirent *)((char *)tde + treclen);
 
7154
                    len -= reclen;
 
7155
                    tlen += treclen;
 
7156
                }
 
7157
                ret = tlen;
 
7158
            }
 
7159
            unlock_user(dirp, arg2, ret);
 
7160
        }
 
7161
#endif
7198
7162
        break;
7199
7163
#if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
7200
7164
    case TARGET_NR_getdents64:
7680
7644
            ret = host_to_target_stat64(cpu_env, arg2, &st);
7681
7645
        break;
7682
7646
#endif
7683
 
#if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)) && \
7684
 
        (defined(__NR_fstatat64) || defined(__NR_newfstatat))
 
7647
#if (defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat))
7685
7648
#ifdef TARGET_NR_fstatat64
7686
7649
    case TARGET_NR_fstatat64:
7687
7650
#endif
7690
7653
#endif
7691
7654
        if (!(p = lock_user_string(arg2)))
7692
7655
            goto efault;
7693
 
#ifdef __NR_fstatat64
7694
 
        ret = get_errno(sys_fstatat64(arg1, path(p), &st, arg4));
7695
 
#else
7696
 
        ret = get_errno(sys_newfstatat(arg1, path(p), &st, arg4));
7697
 
#endif
 
7656
        ret = get_errno(fstatat(arg1, path(p), &st, arg4));
7698
7657
        if (!is_error(ret))
7699
7658
            ret = host_to_target_stat64(cpu_env, arg3, &st);
7700
7659
        break;
7776
7735
    case TARGET_NR_fchown:
7777
7736
        ret = get_errno(fchown(arg1, low2highuid(arg2), low2highgid(arg3)));
7778
7737
        break;
7779
 
#if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
 
7738
#if defined(TARGET_NR_fchownat)
7780
7739
    case TARGET_NR_fchownat:
7781
7740
        if (!(p = lock_user_string(arg2))) 
7782
7741
            goto efault;
7783
 
        ret = get_errno(sys_fchownat(arg1, p, low2highuid(arg3), low2highgid(arg4), arg5));
 
7742
        ret = get_errno(fchownat(arg1, p, low2highuid(arg3),
 
7743
                                 low2highgid(arg4), arg5));
7784
7744
        unlock_user(p, arg2, 0);
7785
7745
        break;
7786
7746
#endif
8236
8196
#ifdef TARGET_NR_madvise
8237
8197
    case TARGET_NR_madvise:
8238
8198
        /* A straight passthrough may not be safe because qemu sometimes
8239
 
           turns private flie-backed mappings into anonymous mappings.
 
8199
           turns private file-backed mappings into anonymous mappings.
8240
8200
           This will break MADV_DONTNEED.
8241
8201
           This is a hint, so ignoring and returning success is ok.  */
8242
8202
        ret = get_errno(0);
8559
8519
#elif defined(TARGET_I386) && defined(TARGET_ABI32)
8560
8520
      ret = do_set_thread_area(cpu_env, arg1);
8561
8521
      break;
 
8522
#elif defined(TARGET_M68K)
 
8523
      {
 
8524
          TaskState *ts = ((CPUArchState *)cpu_env)->opaque;
 
8525
          ts->tp_value = arg1;
 
8526
          ret = 0;
 
8527
          break;
 
8528
      }
8562
8529
#else
8563
8530
      goto unimplemented_nowarn;
8564
8531
#endif
8567
8534
    case TARGET_NR_get_thread_area:
8568
8535
#if defined(TARGET_I386) && defined(TARGET_ABI32)
8569
8536
        ret = do_get_thread_area(cpu_env, arg1);
 
8537
        break;
 
8538
#elif defined(TARGET_M68K)
 
8539
        {
 
8540
            TaskState *ts = ((CPUArchState *)cpu_env)->opaque;
 
8541
            ret = ts->tp_value;
 
8542
            break;
 
8543
        }
8570
8544
#else
8571
8545
        goto unimplemented_nowarn;
8572
8546
#endif
8647
8621
        goto unimplemented_nowarn;
8648
8622
#endif
8649
8623
 
8650
 
#if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
 
8624
#if defined(TARGET_NR_utimensat)
8651
8625
    case TARGET_NR_utimensat:
8652
8626
        {
8653
8627
            struct timespec *tsp, ts[2];
8671
8645
        }
8672
8646
        break;
8673
8647
#endif
8674
 
#if defined(CONFIG_USE_NPTL)
8675
8648
    case TARGET_NR_futex:
8676
8649
        ret = do_futex(arg1, arg2, arg3, arg4, arg5, arg6);
8677
8650
        break;
8678
 
#endif
8679
8651
#if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
8680
8652
    case TARGET_NR_inotify_init:
8681
8653
        ret = get_errno(sys_inotify_init());