All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 00/21] Pending linux-user patches
@ 2009-06-12 13:50 riku.voipio
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 01/21] export mmap_find_vma for shmat riku.voipio
                   ` (21 more replies)
  0 siblings, 22 replies; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Riku Voipio <riku.voipio@iki.fi>

All the things in linux-user tree at the moment:

https://git.maemo.org/projects/qemu/gitweb?p=qemu;a=shortlog;h=refs/heads/linux-user-for-upstream

Since the maemo git hosting regrettably only provides https
transport, you can download the git tree faster if you already
have a git tree:

git clone git://git.sv.gnu.org/qemu.git
cd qemu
git remote add maemo https://git.maemo.org/projects/qemu
git fetch maemo
git checkout -b linux-user maemo/linux-user-for-upstream

This tree is constantly rebased against upstream git HEAD, so avoid basing your
work on this branch.

Arnaud Patard (2):
  Fix struct termios host - target translation
  Return EOPNOTSUPP instead of ENOSYS for *xattr* syscalls

Arnaud Patard (Rtp) (1):
  RFC: fix fcntl support in linux-user - new try

Eduardo Habkost (1):
  linux-user/syscall.c: define _ATFILE_SOURCE

Laurent Vivier (1):
  linux-user: remove duplicate tswap32() from do_getsockopt()

Lionel Landwerlin (2):
  linux-user: Added IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP flags to
    setsockopt
  linux-user: Added IP_(UN)BLOCK_SOURCE/IP_(ADD|DROP)_SOURCE_MEMBERSHIP
    flags to setsockopt

Martin Mohring (2):
  linux-user: include linux/fs.h
  linux-user: support private futexes

Mika Westerberg (4):
  linux-user: implemented ELF coredump support for ARM target
  linux-user: added x86 and x86_64 support for ELF coredump
  linux-user: strace now handles guest strings correctly [v2]
  Revived GUEST_BASE support for usermode emulation targets [v5]

Nathan Froyd (1):
  linux-user: initialize mmap_mutex properly

Riku Voipio (6):
  export mmap_find_vma for shmat
  Implement shm* syscalls and fix 64/32bit errors
  linux-user: fix utimensat
  add futex wake op
  linux-user: update syscall list
  linux-user: implement pipe2 [v3]

vibisreenivasan (1):
  linux-user: add tee, splice and vmsplice

 configure                       |   75 +++
 cpu-all.h                       |    9 +-
 elf.h                           |   19 +-
 exec.c                          |   69 ++-
 linux-user/arm/syscall_nr.h     |    9 +
 linux-user/elfload.c            | 1033 +++++++++++++++++++++++++++++++++++++-
 linux-user/i386/syscall_nr.h    |    8 +
 linux-user/linuxload.c          |   50 +-
 linux-user/m68k/syscall_nr.h    |    8 +
 linux-user/main.c               |  101 ++++-
 linux-user/mips/syscall_nr.h    |    9 +
 linux-user/mips64/syscall_nr.h  |    9 +
 linux-user/mipsn32/syscall_nr.h |    9 +
 linux-user/mmap.c               |    4 +-
 linux-user/ppc/syscall_nr.h     |    9 +
 linux-user/qemu.h               |   17 +-
 linux-user/sh4/syscall_nr.h     |    8 +
 linux-user/signal.c             |   40 ++-
 linux-user/sparc/syscall_nr.h   |    9 +
 linux-user/sparc64/syscall_nr.h |    9 +
 linux-user/strace.c             | 1072 ++++++++++++++++++++++++++++++++++++++-
 linux-user/strace.list          |  111 +++--
 linux-user/syscall.c            |  595 +++++++++++++++++-----
 linux-user/syscall_defs.h       |   41 ++-
 linux-user/x86_64/syscall_nr.h  |    9 +
 tcg/i386/tcg-target.c           |   36 +-
 tcg/x86_64/tcg-target.c         |   30 +-
 27 files changed, 3110 insertions(+), 288 deletions(-)

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 01/21] export mmap_find_vma for shmat
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 02/21] Implement shm* syscalls and fix 64/32bit errors riku.voipio
                   ` (20 subsequent siblings)
  21 siblings, 0 replies; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Riku Voipio <riku.voipio@nokia.com>


Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 linux-user/mmap.c |    2 +-
 linux-user/qemu.h |    1 +
 2 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 6f300a0..aa5813f 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -281,7 +281,7 @@ unsigned long last_brk;
 */
 /* page_init() marks pages used by the host as reserved to be sure not
    to use them. */
-static abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size)
+abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size)
 {
     abi_ulong addr, addr1, addr_start;
     int prot;
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 9454e66..d83a2a4 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -229,6 +229,7 @@ int target_msync(abi_ulong start, abi_ulong len, int flags);
 extern unsigned long last_brk;
 void mmap_lock(void);
 void mmap_unlock(void);
+abi_ulong mmap_find_vma(abi_ulong, abi_ulong);
 void cpu_list_lock(void);
 void cpu_list_unlock(void);
 #if defined(USE_NPTL)
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 02/21] Implement shm* syscalls and fix 64/32bit errors
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 01/21] export mmap_find_vma for shmat riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 03/21] linux-user: implemented ELF coredump support for ARM target riku.voipio
                   ` (19 subsequent siblings)
  21 siblings, 0 replies; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Riku Voipio <riku.voipio@iki.fi>

Verified with ltp shm* tests. Following test still
fails

shmt09      3  FAIL

No regressions were observed on either 64bit or 32bit
IA hosts.

Patch based on original patches by:
  Kirill A. Shutemov <kirill@shutemov.name>
  - Implement shm* syscalls
  - Fix and cleanup IPCOP_shm* ipc calls handling

Depends on "Rewrite mmap_find_vma()" patch.

Various whitespace uglifications applied to minimize
patch size.

Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 linux-user/syscall.c |  299 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 250 insertions(+), 49 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 59c91f8..47d03f7 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1924,14 +1924,12 @@ static abi_long do_socketcall(int num, abi_ulong vptr)
 }
 #endif
 
-#ifdef TARGET_NR_ipc
 #define N_SHM_REGIONS	32
 
 static struct shm_region {
     abi_ulong	start;
     abi_ulong	size;
 } shm_regions[N_SHM_REGIONS];
-#endif
 
 struct target_ipc_perm
 {
@@ -2424,6 +2422,224 @@ end:
     return ret;
 }
 
+struct target_shmid_ds
+{
+    struct target_ipc_perm shm_perm;
+    abi_ulong shm_segsz;
+    abi_ulong shm_atime;
+#if TARGET_ABI_BITS == 32
+    abi_ulong __unused1;
+#endif
+    abi_ulong shm_dtime;
+#if TARGET_ABI_BITS == 32
+    abi_ulong __unused2;
+#endif
+    abi_ulong shm_ctime;
+#if TARGET_ABI_BITS == 32
+    abi_ulong __unused3;
+#endif
+    int shm_cpid;
+    int shm_lpid;
+    abi_ulong shm_nattch;
+    unsigned long int __unused4;
+    unsigned long int __unused5;
+};
+
+static inline abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd,
+                                               abi_ulong target_addr)
+{
+    struct target_shmid_ds *target_sd;
+
+    if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1))
+        return -TARGET_EFAULT;
+    if (target_to_host_ipc_perm(&(host_sd->shm_perm), target_addr))
+        return -TARGET_EFAULT;
+    __get_user(host_sd->shm_segsz, &target_sd->shm_segsz);
+    __get_user(host_sd->shm_atime, &target_sd->shm_atime);
+    __get_user(host_sd->shm_dtime, &target_sd->shm_dtime);
+    __get_user(host_sd->shm_ctime, &target_sd->shm_ctime);
+    __get_user(host_sd->shm_cpid, &target_sd->shm_cpid);
+    __get_user(host_sd->shm_lpid, &target_sd->shm_lpid);
+    __get_user(host_sd->shm_nattch, &target_sd->shm_nattch);
+    unlock_user_struct(target_sd, target_addr, 0);
+    return 0;
+}
+
+static inline abi_long host_to_target_shmid_ds(abi_ulong target_addr,
+                                               struct shmid_ds *host_sd)
+{
+    struct target_shmid_ds *target_sd;
+
+    if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0))
+        return -TARGET_EFAULT;
+    if (host_to_target_ipc_perm(target_addr, &(host_sd->shm_perm)))
+        return -TARGET_EFAULT;
+    __put_user(host_sd->shm_segsz, &target_sd->shm_segsz);
+    __put_user(host_sd->shm_atime, &target_sd->shm_atime);
+    __put_user(host_sd->shm_dtime, &target_sd->shm_dtime);
+    __put_user(host_sd->shm_ctime, &target_sd->shm_ctime);
+    __put_user(host_sd->shm_cpid, &target_sd->shm_cpid);
+    __put_user(host_sd->shm_lpid, &target_sd->shm_lpid);
+    __put_user(host_sd->shm_nattch, &target_sd->shm_nattch);
+    unlock_user_struct(target_sd, target_addr, 1);
+    return 0;
+}
+
+struct  target_shminfo {
+    abi_ulong shmmax;
+    abi_ulong shmmin;
+    abi_ulong shmmni;
+    abi_ulong shmseg;
+    abi_ulong shmall;
+};
+
+static inline abi_long host_to_target_shminfo(abi_ulong target_addr,
+                                              struct shminfo *host_shminfo)
+{
+    struct target_shminfo *target_shminfo;
+    if (!lock_user_struct(VERIFY_WRITE, target_shminfo, target_addr, 0))
+        return -TARGET_EFAULT;
+    __put_user(host_shminfo->shmmax, &target_shminfo->shmmax);
+    __put_user(host_shminfo->shmmin, &target_shminfo->shmmin);
+    __put_user(host_shminfo->shmmni, &target_shminfo->shmmni);
+    __put_user(host_shminfo->shmseg, &target_shminfo->shmseg);
+    __put_user(host_shminfo->shmall, &target_shminfo->shmall);
+    unlock_user_struct(target_shminfo, target_addr, 1);
+    return 0;
+}
+
+struct target_shm_info {
+    int used_ids;
+    abi_ulong shm_tot;
+    abi_ulong shm_rss;
+    abi_ulong shm_swp;
+    abi_ulong swap_attempts;
+    abi_ulong swap_successes;
+};
+
+static inline abi_long host_to_target_shm_info(abi_ulong target_addr,
+                                               struct shm_info *host_shm_info)
+{
+    struct target_shm_info *target_shm_info;
+    if (!lock_user_struct(VERIFY_WRITE, target_shm_info, target_addr, 0))
+        return -TARGET_EFAULT;
+    __put_user(host_shm_info->used_ids, &target_shm_info->used_ids);
+    __put_user(host_shm_info->shm_tot, &target_shm_info->shm_tot);
+    __put_user(host_shm_info->shm_rss, &target_shm_info->shm_rss);
+    __put_user(host_shm_info->shm_swp, &target_shm_info->shm_swp);
+    __put_user(host_shm_info->swap_attempts, &target_shm_info->swap_attempts);
+    __put_user(host_shm_info->swap_successes, &target_shm_info->swap_successes);
+    unlock_user_struct(target_shm_info, target_addr, 1);
+    return 0;
+}
+
+static inline abi_long do_shmctl(int shmid, int cmd, abi_long buf)
+{
+    struct shmid_ds dsarg;
+    struct shminfo shminfo;
+    struct shm_info shm_info;
+    abi_long ret = -TARGET_EINVAL;
+
+    cmd &= 0xff;
+
+    switch(cmd) {
+    case IPC_STAT:
+    case IPC_SET:
+    case SHM_STAT:
+        if (target_to_host_shmid_ds(&dsarg, buf))
+            return -TARGET_EFAULT;
+        ret = get_errno(shmctl(shmid, cmd, &dsarg));
+        if (host_to_target_shmid_ds(buf, &dsarg))
+            return -TARGET_EFAULT;
+        break;
+    case IPC_INFO:
+        ret = get_errno(shmctl(shmid, cmd, (struct shmid_ds *)&shminfo));
+        if (host_to_target_shminfo(buf, &shminfo))
+            return -TARGET_EFAULT;
+        break;
+    case SHM_INFO:
+        ret = get_errno(shmctl(shmid, cmd, (struct shmid_ds *)&shm_info));
+        if (host_to_target_shm_info(buf, &shm_info))
+            return -TARGET_EFAULT;
+        break;
+    case IPC_RMID:
+    case SHM_LOCK:
+    case SHM_UNLOCK:
+        ret = get_errno(shmctl(shmid, cmd, NULL));
+        break;
+    }
+
+    return ret;
+}
+
+static inline abi_ulong do_shmat(int shmid, abi_ulong shmaddr, int shmflg)
+{
+    abi_long raddr;
+    void *host_raddr;
+    struct shmid_ds shm_info;
+    int i,ret;
+
+    /* find out the length of the shared memory segment */
+    ret = get_errno(shmctl(shmid, IPC_STAT, &shm_info));
+    if (is_error(ret)) {
+        /* can't get length, bail out */
+        return ret;
+    }
+
+    mmap_lock();
+
+    if (shmaddr)
+        host_raddr = shmat(shmid, (void *)g2h(shmaddr), shmflg);
+    else {
+        abi_ulong mmap_start;
+
+        mmap_start = mmap_find_vma(0, shm_info.shm_segsz);
+
+        if (mmap_start == -1) {
+            errno = ENOMEM;
+            host_raddr = (void *)-1;
+        } else
+            host_raddr = shmat(shmid, g2h(mmap_start), shmflg | SHM_REMAP);
+    }
+
+    if (host_raddr == (void *)-1) {
+        mmap_unlock();
+        return get_errno((long)host_raddr);
+    }
+    raddr=h2g((unsigned long)host_raddr);
+
+    page_set_flags(raddr, raddr + shm_info.shm_segsz,
+                   PAGE_VALID | PAGE_READ |
+                   ((shmflg & SHM_RDONLY)? 0 : PAGE_WRITE));
+
+    for (i = 0; i < N_SHM_REGIONS; i++) {
+        if (shm_regions[i].start == 0) {
+            shm_regions[i].start = raddr;
+            shm_regions[i].size = shm_info.shm_segsz;
+            break;
+        }
+    }
+
+    mmap_unlock();
+    return raddr;
+
+}
+
+static inline abi_long do_shmdt(abi_ulong shmaddr)
+{
+    int i;
+
+    for (i = 0; i < N_SHM_REGIONS; ++i) {
+        if (shm_regions[i].start == shmaddr) {
+            shm_regions[i].start = 0;
+            page_set_flags(shmaddr, shm_regions[i].size, 0);
+            break;
+        }
+    }
+
+    return get_errno(shmdt(g2h(shmaddr)));
+}
+
 #ifdef TARGET_NR_ipc
 /* ??? This only works with linear mappings.  */
 /* do_ipc() must return target values and target errnos. */
@@ -2433,8 +2649,6 @@ static abi_long do_ipc(unsigned int call, int first,
 {
     int version;
     abi_long ret = 0;
-    struct shmid_ds shm_info;
-    int i;
 
     version = call >> 16;
     call &= 0xffff;
@@ -2489,48 +2703,24 @@ static abi_long do_ipc(unsigned int call, int first,
         break;
 
     case IPCOP_shmat:
+        switch (version) {
+        default:
         {
             abi_ulong raddr;
-            void *host_addr;
-            /* SHM_* flags are the same on all linux platforms */
-            host_addr = shmat(first, (void *)g2h(ptr), second);
-            if (host_addr == (void *)-1) {
-                ret = get_errno((long)host_addr);
-                break;
-            }
-            raddr = h2g((unsigned long)host_addr);
-            /* find out the length of the shared memory segment */
-            
-            ret = get_errno(shmctl(first, IPC_STAT, &shm_info));
-            if (is_error(ret)) {
-                /* can't get length, bail out */
-                shmdt(host_addr);
-                break;
-            }
-            page_set_flags(raddr, raddr + shm_info.shm_segsz,
-                           PAGE_VALID | PAGE_READ |
-                           ((second & SHM_RDONLY)? 0: PAGE_WRITE));
-            for (i = 0; i < N_SHM_REGIONS; ++i) {
-                if (shm_regions[i].start == 0) {
-                    shm_regions[i].start = raddr;
-                    shm_regions[i].size = shm_info.shm_segsz;
-                    break;
-                }
-            }
+            raddr = do_shmat(first, ptr, second);
+            if (is_error(raddr))
+                return get_errno(raddr);
             if (put_user_ual(raddr, third))
                 return -TARGET_EFAULT;
-            ret = 0;
+            break;
+        }
+        case 1:
+            ret = -TARGET_EINVAL;
+            break;
         }
 	break;
     case IPCOP_shmdt:
-	for (i = 0; i < N_SHM_REGIONS; ++i) {
-	    if (shm_regions[i].start == ptr) {
-		shm_regions[i].start = 0;
-		page_set_flags(ptr, shm_regions[i].size, 0);
-		break;
-	    }
-	}
-	ret = get_errno(shmdt((void *)g2h(ptr)));
+        ret = do_shmdt(ptr);
 	break;
 
     case IPCOP_shmget:
@@ -2540,18 +2730,9 @@ static abi_long do_ipc(unsigned int call, int first,
 
 	/* IPC_* and SHM_* command values are the same on all linux platforms */
     case IPCOP_shmctl:
-        switch(second) {
-        case IPC_RMID:
-        case SHM_LOCK:
-        case SHM_UNLOCK:
-            ret = get_errno(shmctl(first, second, NULL));
-            break;
-        default:
-            goto unimplemented;
-        }
+        ret = do_shmctl(first, second, third);
         break;
     default:
-    unimplemented:
 	gemu_log("Unsupported ipc call: %d (version %d)\n", call, version);
 	ret = -TARGET_ENOSYS;
 	break;
@@ -5312,6 +5493,26 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_msgsnd(arg1, arg2, arg3, arg4);
         break;
 #endif
+#ifdef TARGET_NR_shmget
+    case TARGET_NR_shmget:
+        ret = get_errno(shmget(arg1, arg2, arg3));
+        break;
+#endif
+#ifdef TARGET_NR_shmctl
+    case TARGET_NR_shmctl:
+        ret = do_shmctl(arg1, arg2, arg3);
+        break;
+#endif
+#ifdef TARGET_NR_shmat
+    case TARGET_NR_shmat:
+        ret = do_shmat(arg1, arg2, arg3);
+        break;
+#endif
+#ifdef TARGET_NR_shmdt
+    case TARGET_NR_shmdt:
+        ret = do_shmdt(arg1);
+        break;
+#endif
     case TARGET_NR_fsync:
         ret = get_errno(fsync(arg1));
         break;
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 03/21] linux-user: implemented ELF coredump support for ARM target
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 01/21] export mmap_find_vma for shmat riku.voipio
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 02/21] Implement shm* syscalls and fix 64/32bit errors riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-14 15:16   ` Blue Swirl
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 04/21] linux-user: added x86 and x86_64 support for ELF coredump riku.voipio
                   ` (18 subsequent siblings)
  21 siblings, 1 reply; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Mika Westerberg <mika.westerberg@iki.fi>

When target process is killed with signal (such signal that
should dump core) a coredump file is created.  This file is
similar than coredump generated by Linux (there are few exceptions
though).

Riku Voipio: added support for rlimit

From: Mika Westerberg <mika.westerberg@iki.fi>
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 cpu-all.h              |    2 +
 elf.h                  |   19 +-
 exec.c                 |   69 +++--
 linux-user/elfload.c   |  928 +++++++++++++++++++++++++++++++++++++++++++++++-
 linux-user/linuxload.c |   50 ++--
 linux-user/main.c      |   42 ++-
 linux-user/qemu.h      |   13 +-
 linux-user/signal.c    |   40 ++-
 linux-user/syscall.c   |    6 +
 9 files changed, 1101 insertions(+), 68 deletions(-)

diff --git a/cpu-all.h b/cpu-all.h
index dc9b034..8f078c4 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -735,6 +735,8 @@ extern unsigned long qemu_host_page_mask;
 #define PAGE_RESERVED  0x0020
 
 void page_dump(FILE *f);
+int walk_memory_regions(void *,
+    int (*fn)(void *, unsigned long, unsigned long, unsigned long));
 int page_get_flags(target_ulong address);
 void page_set_flags(target_ulong start, target_ulong end, int flags);
 int page_check_range(target_ulong start, target_ulong len, int flags);
diff --git a/elf.h b/elf.h
index 182cad9..f8dea7c 100644
--- a/elf.h
+++ b/elf.h
@@ -1081,7 +1081,23 @@ typedef struct elf64_shdr {
 #define	EI_CLASS	4
 #define	EI_DATA		5
 #define	EI_VERSION	6
-#define	EI_PAD		7
+#define EI_OSABI	7
+#define	EI_PAD		8
+
+#define ELFOSABI_NONE           0       /* UNIX System V ABI */
+#define ELFOSABI_SYSV           0       /* Alias.  */
+#define ELFOSABI_HPUX           1       /* HP-UX */
+#define ELFOSABI_NETBSD         2       /* NetBSD.  */
+#define ELFOSABI_LINUX          3       /* Linux.  */
+#define ELFOSABI_SOLARIS        6       /* Sun Solaris.  */
+#define ELFOSABI_AIX            7       /* IBM AIX.  */
+#define ELFOSABI_IRIX           8       /* SGI Irix.  */
+#define ELFOSABI_FREEBSD        9       /* FreeBSD.  */
+#define ELFOSABI_TRU64          10      /* Compaq TRU64 UNIX.  */
+#define ELFOSABI_MODESTO        11      /* Novell Modesto.  */
+#define ELFOSABI_OPENBSD        12      /* OpenBSD.  */
+#define ELFOSABI_ARM            97      /* ARM */
+#define ELFOSABI_STANDALONE     255     /* Standalone (embedded) application */
 
 #define	ELFMAG0		0x7f		/* EI_MAG */
 #define	ELFMAG1		'E'
@@ -1108,6 +1124,7 @@ typedef struct elf64_shdr {
 #define NT_PRFPREG	2
 #define NT_PRPSINFO	3
 #define NT_TASKSTRUCT	4
+#define NT_AUXV		6
 #define NT_PRXFPREG     0x46e62b7f      /* copied from gdb5.1/include/elf/common.h */
 
 
diff --git a/exec.c b/exec.c
index 52f4e89..9e7d66a 100644
--- a/exec.c
+++ b/exec.c
@@ -2131,36 +2131,36 @@ int tlb_set_page_exec(CPUState *env, target_ulong vaddr,
     return 0;
 }
 
-/* dump memory mappings */
-void page_dump(FILE *f)
+/*
+ * Walks guest process memory "regions" one by one
+ * and calls callback function 'fn' for each region.
+ */
+int walk_memory_regions(void *priv,
+    int (*fn)(void *, unsigned long, unsigned long, unsigned long))
 {
     unsigned long start, end;
+    PageDesc *p = NULL;
     int i, j, prot, prot1;
-    PageDesc *p;
+    int rc = 0;
 
-    fprintf(f, "%-8s %-8s %-8s %s\n",
-            "start", "end", "size", "prot");
-    start = -1;
-    end = -1;
+    start = end = -1;
     prot = 0;
-    for(i = 0; i <= L1_SIZE; i++) {
-        if (i < L1_SIZE)
-            p = l1_map[i];
-        else
-            p = NULL;
-        for(j = 0;j < L2_SIZE; j++) {
-            if (!p)
-                prot1 = 0;
-            else
-                prot1 = p[j].flags;
+
+    for (i = 0; i <= L1_SIZE; i++) {
+        p = (i < L1_SIZE) ? l1_map[i] : NULL;
+        for (j = 0; j < L2_SIZE; j++) {
+            prot1 = (p == NULL) ? 0 : p[j].flags;
+            /*
+             * "region" is one continuous chunk of memory
+             * that has same protection flags set.
+             */
             if (prot1 != prot) {
                 end = (i << (32 - L1_BITS)) | (j << TARGET_PAGE_BITS);
                 if (start != -1) {
-                    fprintf(f, "%08lx-%08lx %08lx %c%c%c\n",
-                            start, end, end - start,
-                            prot & PAGE_READ ? 'r' : '-',
-                            prot & PAGE_WRITE ? 'w' : '-',
-                            prot & PAGE_EXEC ? 'x' : '-');
+                    rc = (*fn)(priv, start, end, prot);
+                    /* callback can stop iteration by returning != 0 */
+                    if (rc != 0)
+                        return (rc);
                 }
                 if (prot1 != 0)
                     start = end;
@@ -2168,10 +2168,33 @@ void page_dump(FILE *f)
                     start = -1;
                 prot = prot1;
             }
-            if (!p)
+            if (p == NULL)
                 break;
         }
     }
+    return (rc);
+}
+
+static int dump_region(void *priv, unsigned long start,
+    unsigned long end, unsigned long prot)
+{
+    FILE *f = (FILE *)priv;
+
+    (void) fprintf(f, "%08lx-%08lx %08lx %c%c%c\n",
+        start, end, end - start,
+        ((prot & PAGE_READ) ? 'r' : '-'),
+        ((prot & PAGE_WRITE) ? 'w' : '-'),
+        ((prot & PAGE_EXEC) ? 'x' : '-'));
+
+    return (0);
+}
+
+/* dump memory mappings */
+void page_dump(FILE *f)
+{
+    (void) fprintf(f, "%-8s %-8s %-8s %s\n",
+            "start", "end", "size", "prot");
+    walk_memory_regions(f, dump_region);
 }
 
 int page_get_flags(target_ulong address)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 190ad14..c9e8bc1 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1,4 +1,6 @@
 /* This is the Linux kernel elf-loading code, ported into user space */
+#include <sys/time.h>
+#include <sys/param.h>
 
 #include <stdio.h>
 #include <sys/types.h>
@@ -6,8 +8,10 @@
 #include <errno.h>
 #include <unistd.h>
 #include <sys/mman.h>
+#include <sys/resource.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 
 #include "qemu.h"
 #include "disas.h"
@@ -21,6 +25,8 @@
 #undef ELF_ARCH
 #endif
 
+#define ELF_OSABI   ELFOSABI_SYSV
+
 /* from personality.h */
 
 /*
@@ -160,7 +166,6 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 }
 #endif
 
-#define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE	4096
 
 #endif
@@ -198,6 +203,37 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
     regs->ARM_r10 = infop->start_data;
 }
 
+typedef uint32_t elf_greg_t;
+typedef uint16_t target_uid_t;
+typedef uint16_t target_gid_t;
+typedef int32_t  target_pid_t;
+
+#define ELF_NREG    18
+typedef elf_greg_t  elf_gregset_t[ELF_NREG];
+
+static void elf_core_copy_regs(elf_gregset_t *regs, const CPUState *env)
+{
+    (*regs)[0] = env->regs[0];
+    (*regs)[1] = env->regs[1];
+    (*regs)[2] = env->regs[2];
+    (*regs)[3] = env->regs[3]; 
+    (*regs)[4] = env->regs[4];
+    (*regs)[5] = env->regs[5];
+    (*regs)[6] = env->regs[6];
+    (*regs)[7] = env->regs[7];
+    (*regs)[8] = env->regs[8];
+    (*regs)[9] = env->regs[9];
+    (*regs)[10] = env->regs[10];
+    (*regs)[11] = env->regs[11];
+    (*regs)[12] = env->regs[12];
+    (*regs)[13] = env->regs[13]; 
+    (*regs)[14] = env->regs[14];
+    (*regs)[15] = env->regs[15];
+
+    (*regs)[16] = cpsr_read((CPUState *)env);
+    (*regs)[17] = env->regs[0]; /* XXX */
+}
+
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE	4096
 
@@ -418,7 +454,6 @@ static inline void init_thread(struct target_pt_regs *_regs, struct image_info *
     _regs->gpr[5] = pos;
 }
 
-#define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE	4096
 
 #endif
@@ -448,7 +483,6 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
     regs->regs[29] = infop->start_stack;
 }
 
-#define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
 #endif /* TARGET_MIPS */
@@ -470,7 +504,6 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 
 }
 
-#define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
 #endif /* TARGET_MICROBLAZE */
@@ -492,7 +525,6 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
   regs->regs[15] = infop->start_stack;
 }
 
-#define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
 #endif
@@ -512,7 +544,6 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
   regs->erp = infop->entry;
 }
 
-#define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        8192
 
 #endif
@@ -537,7 +568,6 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
     regs->pc = infop->entry;
 }
 
-#define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE	8192
 
 #endif
@@ -562,7 +592,6 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
            regs->unique, infop->start_data);
 }
 
-#define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        8192
 
 #endif /* TARGET_ALPHA */
@@ -680,6 +709,20 @@ static void bswap_sym(struct elf_sym *sym)
 }
 #endif
 
+#ifdef USE_ELF_CORE_DUMP
+static int elf_core_dump(int, const CPUState *);
+
+#ifdef BSWAP_NEEDED
+static void bswap_note(struct elf_note *en)
+{
+    bswaptls(&en->n_namesz);
+    bswaptls(&en->n_descsz);
+    bswaptls(&en->n_type);
+}
+#endif /* BSWAP_NEEDED */
+
+#endif /* USE_ELF_CORE_DUMP */
+
 /*
  * 'copy_elf_strings()' copies argument/envelope strings from user
  * memory to free pages in kernel mem. These are in a format ready
@@ -904,6 +947,8 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
 #endif
 #undef NEW_AUX_ENT
 
+        info->saved_auxv = sp;
+
         sp = loader_build_argptr(envc, argc, sp, p, !ibcs);
         return sp;
 }
@@ -1586,9 +1631,876 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
 
     info->entry = elf_entry;
 
+#ifdef USE_ELF_CORE_DUMP
+    bprm->core_dump = &elf_core_dump;
+#endif
+
     return 0;
 }
 
+#ifdef USE_ELF_CORE_DUMP
+
+/*
+ * Definitions to generate Intel SVR4-like core files.
+ * These mostly have the same names as the SVR4 types with "elf_"
+ * tacked on the front to prevent clashes with linux definitions,
+ * and the typedef forms have been avoided.  This is mostly like
+ * the SVR4 structure, but more Linuxy, with things that Linux does
+ * not support and which gdb doesn't really use excluded.
+ *
+ * Fields we don't dump (their contents is zero) in linux-user qemu
+ * are marked with XXX.
+ *
+ * Core dump code is copied from linux kernel (fs/binfmt_elf.c).
+ *
+ * Porting ELF coredump for target is (quite) simple process.  First you
+ * define ELF_USE_CORE_DUMP in target ELF code (where init_thread() for
+ * the target resides):
+ *
+ * #define USE_ELF_CORE_DUMP
+ *
+ * Next you define type of register set used for dumping.  ELF specification
+ * says that it needs to be array of elf_greg_t that has size of ELF_NREG.
+ *
+ * typedef <target_regtype> elf_greg_t;
+ * #define ELF_NREG <number of registers>
+ * typedef elf_greg_t elf_gregset_t[ELF_NREG];
+ *
+ * Then define following types to match target types.  Actual types can
+ * be found from linux kernel (arch/<ARCH>/include/asm/posix_types.h):
+ *
+ * typedef <target_uid_type> target_uid_t;
+ * typedef <target_gid_type> target_gid_t;
+ * typedef <target_pid_type> target_pid_t;
+ *
+ * Last step is to implement target specific function that copies registers
+ * from given cpu into just specified register set.  Prototype is:
+ *
+ * static void elf_core_copy_regs(elf_gregset_t *regs, const CPUState *env);
+ *
+ * Parameters:
+ *     regs - copy register values into here (allocated and zeroed by caller)
+ *     env - copy registers from here
+ *
+ * Example for ARM target is provided in this file.
+ */
+
+/* An ELF note in memory */
+struct memelfnote {
+    const char *name;
+    size_t     namesz;
+    size_t     namesz_rounded;
+    int        type;
+    size_t     datasz;
+    void       *data;
+    size_t     notesz;
+};
+
+struct elf_siginfo {
+    int  si_signo; /* signal number */
+    int  si_code;  /* extra code */
+    int  si_errno; /* errno */
+};
+
+struct elf_prstatus {
+    struct elf_siginfo pr_info;      /* Info associated with signal */
+    short              pr_cursig;    /* Current signal */
+    target_ulong       pr_sigpend;   /* XXX */
+    target_ulong       pr_sighold;   /* XXX */
+    target_pid_t       pr_pid;
+    target_pid_t       pr_ppid;
+    target_pid_t       pr_pgrp;
+    target_pid_t       pr_sid;
+    struct target_timeval pr_utime;  /* XXX User time */
+    struct target_timeval pr_stime;  /* XXX System time */
+    struct target_timeval pr_cutime; /* XXX Cumulative user time */
+    struct target_timeval pr_cstime; /* XXX Cumulative system time */
+    elf_gregset_t      pr_reg;       /* GP registers */
+    int                pr_fpvalid;   /* XXX */
+};
+
+#define ELF_PRARGSZ     (80) /* Number of chars for args */
+
+struct elf_prpsinfo {
+    char         pr_state;       /* numeric process state */
+    char         pr_sname;       /* char for pr_state */
+    char         pr_zomb;        /* zombie */
+    char         pr_nice;        /* nice val */
+    target_ulong pr_flag;        /* flags */
+    target_uid_t pr_uid;
+    target_gid_t pr_gid;
+    target_pid_t pr_pid, pr_ppid, pr_pgrp, pr_sid;
+    /* Lots missing */
+    char    pr_fname[16];           /* filename of executable */
+    char    pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */
+};
+
+/* Here is the structure in which status of each thread is captured. */
+struct elf_thread_status {
+    TAILQ_ENTRY(elf_thread_status)  ets_link;
+    struct elf_prstatus prstatus;   /* NT_PRSTATUS */
+#if 0
+    elf_fpregset_t fpu;             /* NT_PRFPREG */
+    struct task_struct *thread;
+    elf_fpxregset_t xfpu;           /* ELF_CORE_XFPREG_TYPE */
+#endif
+    struct memelfnote notes[1];
+    int num_notes;
+};
+
+struct elf_note_info {
+    struct memelfnote   *notes;
+    struct elf_prstatus *prstatus;  /* NT_PRSTATUS */
+    struct elf_prpsinfo *psinfo;    /* NT_PRPSINFO */
+
+    TAILQ_HEAD(thread_list_head, elf_thread_status) thread_list;
+#if 0
+    /*
+     * Current version of ELF coredump doesn't support
+     * dumping fp regs etc.
+     */
+    elf_fpregset_t *fpu;
+    elf_fpxregset_t *xfpu;
+    int thread_status_size;
+#endif
+    int notes_size;
+    int numnote;
+};
+
+struct vm_area_struct {
+    abi_ulong   vma_start;  /* start vaddr of memory region */
+    abi_ulong   vma_end;    /* end vaddr of memory region */
+    abi_ulong   vma_flags;  /* protection etc. flags for the region */
+    TAILQ_ENTRY(vm_area_struct) vma_link;
+};
+
+struct mm_struct {
+    TAILQ_HEAD(, vm_area_struct) mm_mmap;
+    int mm_count;           /* number of mappings */
+};
+
+static struct mm_struct *vma_init(void);
+static void vma_delete(struct mm_struct *);
+static int vma_add_mapping(struct mm_struct *, abi_ulong,
+    abi_ulong, abi_ulong);
+static int vma_get_mapping_count(const struct mm_struct *);
+static struct vm_area_struct *vma_first(const struct mm_struct *);
+static struct vm_area_struct *vma_next(struct vm_area_struct *);
+static abi_ulong vma_dump_size(const struct vm_area_struct *);
+static int vma_walker(void *priv, unsigned long start, unsigned long end,
+    unsigned long flags);
+
+static void fill_elf_header(struct elfhdr *, int, uint16_t, uint32_t);
+static void fill_note(struct memelfnote *, const char *, int,
+    unsigned int, void *);
+static void fill_prstatus(struct elf_prstatus *, const TaskState *, int);
+static int fill_psinfo(struct elf_prpsinfo *, const TaskState *);
+static void fill_auxv_note(struct memelfnote *, const TaskState *);
+static void fill_elf_note_phdr(struct elf_phdr *, int, off_t);
+static size_t note_size(const struct memelfnote *);
+static void free_note_info(struct elf_note_info *);
+static int fill_note_info(struct elf_note_info *, long, const CPUState *);
+static void fill_thread_info(struct elf_note_info *, const CPUState *);
+static int core_dump_filename(const TaskState *, char *, size_t);
+
+static int dump_write(int, const void *, size_t);
+static int write_note(struct memelfnote *, int);
+static int write_note_info(struct elf_note_info *, int);
+
+#ifdef BSWAP_NEEDED
+static void bswap_prstatus(struct elf_prstatus *);
+static void bswap_psinfo(struct elf_prpsinfo *);
+
+static void bswap_prstatus(struct elf_prstatus *prstatus)
+{
+    prstatus->pr_info.si_signo = tswapl(prstatus->pr_info.si_signo);
+    prstatus->pr_info.si_code = tswapl(prstatus->pr_info.si_code);
+    prstatus->pr_info.si_errno = tswapl(prstatus->pr_info.si_errno);
+    prstatus->pr_cursig = tswap16(prstatus->pr_cursig);
+    prstatus->pr_sigpend = tswapl(prstatus->pr_sigpend);
+    prstatus->pr_sighold = tswapl(prstatus->pr_sighold);
+    prstatus->pr_pid = tswap32(prstatus->pr_pid);
+    prstatus->pr_ppid = tswap32(prstatus->pr_ppid);
+    prstatus->pr_pgrp = tswap32(prstatus->pr_pgrp);
+    prstatus->pr_sid = tswap32(prstatus->pr_sid);
+    /* cpu times are not filled, so we skip them */
+    /* regs should be in correct format already */
+    prstatus->pr_fpvalid = tswap32(prstatus->pr_fpvalid);
+}
+
+static void bswap_psinfo(struct elf_prpsinfo *psinfo)
+{
+    psinfo->pr_flag = tswapl(psinfo->pr_flag);
+    psinfo->pr_uid = tswap16(psinfo->pr_uid);
+    psinfo->pr_gid = tswap16(psinfo->pr_gid);
+    psinfo->pr_pid = tswap32(psinfo->pr_pid);
+    psinfo->pr_ppid = tswap32(psinfo->pr_ppid);
+    psinfo->pr_pgrp = tswap32(psinfo->pr_pgrp);
+    psinfo->pr_sid = tswap32(psinfo->pr_sid);
+}
+#endif /* BSWAP_NEEDED */
+
+/*
+ * Minimal support for linux memory regions.  These are needed
+ * when we are finding out what memory exactly belongs to
+ * emulated process.  No locks needed here, as long as
+ * thread that received the signal is stopped.
+ */
+
+static struct mm_struct *vma_init(void)
+{
+    struct mm_struct *mm;
+
+    if ((mm = qemu_malloc(sizeof (*mm))) == NULL)
+        return (NULL);
+
+    mm->mm_count = 0;
+    TAILQ_INIT(&mm->mm_mmap);
+
+    return (mm);
+}
+
+static void vma_delete(struct mm_struct *mm)
+{
+    struct vm_area_struct *vma;
+
+    while ((vma = vma_first(mm)) != NULL) {
+        TAILQ_REMOVE(&mm->mm_mmap, vma, vma_link);
+        qemu_free(vma);
+    }
+    qemu_free(mm);
+}
+
+static int vma_add_mapping(struct mm_struct *mm, abi_ulong start,
+    abi_ulong end, abi_ulong flags)
+{
+    struct vm_area_struct *vma;
+
+    if ((vma = qemu_mallocz(sizeof (*vma))) == NULL)
+        return (-1);
+
+    vma->vma_start = start;
+    vma->vma_end = end;
+    vma->vma_flags = flags;
+
+    TAILQ_INSERT_TAIL(&mm->mm_mmap, vma, vma_link);
+    mm->mm_count++;
+
+    return (0);
+}
+
+static struct vm_area_struct *vma_first(const struct mm_struct *mm)
+{
+    return (TAILQ_FIRST(&mm->mm_mmap));
+}
+
+static struct vm_area_struct *vma_next(struct vm_area_struct *vma)
+{
+    return (TAILQ_NEXT(vma, vma_link));
+}
+
+static int vma_get_mapping_count(const struct mm_struct *mm)
+{
+    return (mm->mm_count);
+}
+
+/*
+ * Calculate file (dump) size of given memory region.
+ */
+static abi_ulong vma_dump_size(const struct vm_area_struct *vma)
+{
+    /* if we cannot even read the first page, skip it */
+    if (!access_ok(VERIFY_READ, vma->vma_start, TARGET_PAGE_SIZE))
+        return (0);
+
+    /*
+     * Usually we don't dump executable pages as they contain
+     * non-writable code that debugger can read directly from
+     * target library etc.  However, thread stacks are marked
+     * also executable so we read in first page of given region
+     * and check whether it contains elf header.  If there is
+     * no elf header, we dump it.
+     */
+    if (vma->vma_flags & PROT_EXEC) {
+        char page[TARGET_PAGE_SIZE];
+
+        copy_from_user(page, vma->vma_start, sizeof (page));
+        if ((page[EI_MAG0] == ELFMAG0) &&
+            (page[EI_MAG1] == ELFMAG1) &&
+            (page[EI_MAG2] == ELFMAG2) &&
+            (page[EI_MAG3] == ELFMAG3)) {
+            /*
+             * Mappings are possibly from ELF binary.  Don't dump
+             * them.
+             */
+            return (0);
+        }
+    }
+
+    return (vma->vma_end - vma->vma_start);
+}
+
+static int vma_walker(void *priv, unsigned long start, unsigned long end,
+    unsigned long flags)
+{
+    struct mm_struct *mm = (struct mm_struct *)priv;
+
+    /*
+     * Don't dump anything that qemu has reserved for internal use.
+     */
+    if (flags & PAGE_RESERVED)
+        return (0);
+
+    vma_add_mapping(mm, start, end, flags);
+    return (0);
+}
+
+static void fill_note(struct memelfnote *note, const char *name, int type,
+    unsigned int sz, void *data)
+{
+    unsigned int namesz;
+
+    namesz = strlen(name) + 1;
+    note->name = name;
+    note->namesz = namesz;
+    note->namesz_rounded = roundup(namesz, sizeof (int32_t));
+    note->type = type;
+    note->datasz = roundup(sz, sizeof (int32_t));;
+    note->data = data;
+
+    /*
+     * We calculate rounded up note size here as specified by
+     * ELF document.
+     */
+    note->notesz = sizeof (struct elf_note) +
+        note->namesz_rounded + note->datasz;
+}
+
+static void fill_elf_header(struct elfhdr *elf, int segs, uint16_t machine,
+    uint32_t flags)
+{
+    (void) memset(elf, 0, sizeof(*elf));
+
+    (void) memcpy(elf->e_ident, ELFMAG, SELFMAG);
+    elf->e_ident[EI_CLASS] = ELF_CLASS;
+    elf->e_ident[EI_DATA] = ELF_DATA;
+    elf->e_ident[EI_VERSION] = EV_CURRENT;
+    elf->e_ident[EI_OSABI] = ELF_OSABI;
+
+    elf->e_type = ET_CORE;
+    elf->e_machine = machine;
+    elf->e_version = EV_CURRENT;
+    elf->e_phoff = sizeof(struct elfhdr);
+    elf->e_flags = flags;
+    elf->e_ehsize = sizeof(struct elfhdr);
+    elf->e_phentsize = sizeof(struct elf_phdr);
+    elf->e_phnum = segs;
+
+#ifdef BSWAP_NEEDED
+    bswap_ehdr(elf);
+#endif
+}
+
+static void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, off_t offset)
+{
+    phdr->p_type = PT_NOTE;
+    phdr->p_offset = offset;
+    phdr->p_vaddr = 0;
+    phdr->p_paddr = 0;
+    phdr->p_filesz = sz;
+    phdr->p_memsz = 0;
+    phdr->p_flags = 0;
+    phdr->p_align = 0;
+
+#ifdef BSWAP_NEEDED
+    bswap_phdr(phdr);
+#endif
+}
+
+static size_t note_size(const struct memelfnote *note)
+{
+    return (note->notesz);
+}
+
+static void fill_prstatus(struct elf_prstatus *prstatus,
+    const TaskState *ts, int signr)
+{
+    (void) memset(prstatus, 0, sizeof (*prstatus));
+    prstatus->pr_info.si_signo = prstatus->pr_cursig = signr;
+    prstatus->pr_pid = ts->ts_tid;
+    prstatus->pr_ppid = getppid();
+    prstatus->pr_pgrp = getpgrp();
+    prstatus->pr_sid = getsid(0);
+
+#ifdef BSWAP_NEEDED
+    bswap_prstatus(prstatus);
+#endif
+}
+
+static int fill_psinfo(struct elf_prpsinfo *psinfo, const TaskState *ts)
+{
+    char *filename, *base_filename;
+    unsigned int i, len;
+
+    (void) memset(psinfo, 0, sizeof (*psinfo));
+
+    len = ts->info->arg_end - ts->info->arg_start;
+    if (len >= ELF_PRARGSZ)
+        len = ELF_PRARGSZ - 1;
+    if (copy_from_user(&psinfo->pr_psargs, ts->info->arg_start, len))
+        return -EFAULT;
+    for (i = 0; i < len; i++)
+        if (psinfo->pr_psargs[i] == 0)
+            psinfo->pr_psargs[i] = ' ';
+    psinfo->pr_psargs[len] = 0;
+
+    psinfo->pr_pid = getpid();
+    psinfo->pr_ppid = getppid();
+    psinfo->pr_pgrp = getpgrp();
+    psinfo->pr_sid = getsid(0);
+    psinfo->pr_uid = getuid();
+    psinfo->pr_gid = getgid();
+
+    filename = strdup(ts->bprm->filename);
+    base_filename = strdup(basename(filename));
+    (void) strncpy(psinfo->pr_fname, base_filename,
+        sizeof(psinfo->pr_fname));
+    free(base_filename);
+    free(filename);
+
+#ifdef BSWAP_NEEDED
+    bswap_psinfo(psinfo);
+#endif
+    return (0);
+}
+
+static void fill_auxv_note(struct memelfnote *note, const TaskState *ts)
+{
+    elf_addr_t auxv = (elf_addr_t)ts->info->saved_auxv;
+    elf_addr_t orig_auxv = auxv;
+    abi_ulong val;
+    void *ptr;
+    int i, len;
+
+    /*
+     * Auxiliary vector is stored in target process stack.  It contains
+     * {type, value} pairs that we need to dump into note.  This is not
+     * strictly necessary but we do it here for sake of completeness.
+     */
+
+    /* find out lenght of the vector, AT_NULL is terminator */
+    i = len = 0;
+    do {
+        get_user_ual(val, auxv);
+        i += 2;
+        auxv += 2 * sizeof (elf_addr_t);
+    } while (val != AT_NULL);
+    len = i * sizeof (elf_addr_t);
+
+    /* read in whole auxv vector and copy it to memelfnote */
+    ptr = lock_user(VERIFY_READ, orig_auxv, len, 0);
+    if (ptr != NULL) {
+        fill_note(note, "CORE", NT_AUXV, len, ptr);
+        unlock_user(ptr, auxv, len);
+    }
+}
+
+/*
+ * Constructs name of coredump file.  We have following convention
+ * for the name:
+ *     qemu_<basename-of-target-binary>_<date>-<time>_<pid>.core
+ *
+ * Returns 0 in case of success, -1 otherwise (errno is set).
+ */
+static int core_dump_filename(const TaskState *ts, char *buf,
+    size_t bufsize)
+{
+    char timestamp[64];
+    char *filename = NULL;
+    char *base_filename = NULL;
+    struct timeval tv;
+    struct tm tm;
+
+    assert(bufsize >= PATH_MAX);
+
+    if (gettimeofday(&tv, NULL) < 0) {
+        (void) fprintf(stderr, "unable to get current timestamp: %s",
+            strerror(errno));
+        return (-1);
+    }
+
+    filename = strdup(ts->bprm->filename);
+    base_filename = strdup(basename(filename));
+    (void) strftime(timestamp, sizeof (timestamp), "%Y%m%d-%H%M%S",
+        localtime_r(&tv.tv_sec, &tm));
+    (void) snprintf(buf, bufsize, "qemu_%s_%s_%d.core",
+        base_filename, timestamp, (int)getpid());
+    free(base_filename);
+    free(filename);
+
+    return (0);
+}
+
+static int dump_write(int fd, const void *ptr, size_t size)
+{
+    const char *bufp = (const char *)ptr;
+    ssize_t bytes_written, bytes_left;
+    struct rlimit dumpsize;
+    off_t pos;
+
+    bytes_written = 0;
+    getrlimit(RLIMIT_CORE, &dumpsize);
+    if ((pos = lseek(fd, 0, SEEK_CUR))==-1) {
+        if (errno == ESPIPE) { /* not a seekable stream */
+            bytes_left = size;
+        } else {
+            return pos;
+        }
+    } else {
+        if (dumpsize.rlim_cur <= pos) {
+            return -1;
+        } else if (dumpsize.rlim_cur == RLIM_INFINITY) {
+            bytes_left = size;
+        } else {
+            size_t limit_left=dumpsize.rlim_cur - pos;
+            bytes_left = limit_left >= size ? size : limit_left ;
+        }
+    }
+
+    /*
+     * In normal conditions, single write(2) should do but
+     * in case of socket etc. this mechanism is more portable.
+     */
+    do {
+        bytes_written = write(fd, bufp, bytes_left);
+        if (bytes_written < 0) {
+            if (errno == EINTR)
+                continue;
+            return (-1);
+        } else if (bytes_written == 0) { /* eof */
+            return (-1);
+        }
+        bufp += bytes_written;
+        bytes_left -= bytes_written;
+    } while (bytes_left > 0);
+
+    return (0);
+}
+
+static int write_note(struct memelfnote *men, int fd)
+{
+    struct elf_note en;
+
+    en.n_namesz = men->namesz;
+    en.n_type = men->type;
+    en.n_descsz = men->datasz;
+
+#ifdef BSWAP_NEEDED
+    bswap_note(&en);
+#endif
+
+    if (dump_write(fd, &en, sizeof(en)) != 0)
+        return (-1);
+    if (dump_write(fd, men->name, men->namesz_rounded) != 0)
+        return (-1);
+    if (dump_write(fd, men->data, men->datasz) != 0)
+        return (-1);
+
+    return (0);
+}
+
+static void fill_thread_info(struct elf_note_info *info, const CPUState *env)
+{
+    TaskState *ts = (TaskState *)env->opaque;
+    struct elf_thread_status *ets;
+
+    ets = qemu_mallocz(sizeof (*ets));
+    ets->num_notes = 1; /* only prstatus is dumped */
+    fill_prstatus(&ets->prstatus, ts, 0);
+    elf_core_copy_regs(&ets->prstatus.pr_reg, env);
+    fill_note(&ets->notes[0], "CORE", NT_PRSTATUS, sizeof (ets->prstatus),
+        &ets->prstatus);
+
+    TAILQ_INSERT_TAIL(&info->thread_list, ets, ets_link);
+
+    info->notes_size += note_size(&ets->notes[0]);
+}
+
+static int fill_note_info(struct elf_note_info *info,
+    long signr, const CPUState *env)
+{
+#define NUMNOTES 3
+    CPUState *cpu = NULL;
+    TaskState *ts = (TaskState *)env->opaque;
+    int i;
+
+    (void) memset(info, 0, sizeof (*info));
+
+    TAILQ_INIT(&info->thread_list);
+
+    info->notes = qemu_mallocz(NUMNOTES * sizeof (struct memelfnote));
+    if (info->notes == NULL)
+        return (-ENOMEM);
+    info->prstatus = qemu_mallocz(sizeof (*info->prstatus));
+    if (info->prstatus == NULL)
+        return (-ENOMEM);
+    info->psinfo = qemu_mallocz(sizeof (*info->psinfo));
+    if (info->prstatus == NULL)
+        return (-ENOMEM);
+
+    /*
+     * First fill in status (and registers) of current thread
+     * including process info & aux vector.
+     */
+    fill_prstatus(info->prstatus, ts, signr);
+    elf_core_copy_regs(&info->prstatus->pr_reg, env);
+    fill_note(&info->notes[0], "CORE", NT_PRSTATUS,
+        sizeof (*info->prstatus), info->prstatus);
+    fill_psinfo(info->psinfo, ts);
+    fill_note(&info->notes[1], "CORE", NT_PRPSINFO,
+        sizeof (*info->psinfo), info->psinfo);
+    fill_auxv_note(&info->notes[2], ts);
+    info->numnote = 3;
+
+    info->notes_size = 0;
+    for (i = 0; i < info->numnote; i++)
+        info->notes_size += note_size(&info->notes[i]);
+
+    /* read and fill status of all threads */
+    cpu_list_lock();
+    for (cpu = first_cpu; cpu != NULL; cpu = cpu->next_cpu) {
+        if (cpu == thread_env)
+            continue;
+        fill_thread_info(info, cpu);
+    }
+    cpu_list_unlock();
+
+    return (0);
+}
+
+static void free_note_info(struct elf_note_info *info)
+{
+    struct elf_thread_status *ets;
+
+    while (!TAILQ_EMPTY(&info->thread_list)) {
+        ets = TAILQ_FIRST(&info->thread_list);
+        TAILQ_REMOVE(&info->thread_list, ets, ets_link);
+        qemu_free(ets);
+    }
+
+    qemu_free(info->prstatus);
+    qemu_free(info->psinfo);
+    qemu_free(info->notes);
+}
+
+static int write_note_info(struct elf_note_info *info, int fd)
+{
+    struct elf_thread_status *ets;
+    int i, error = 0;
+
+    /* write prstatus, psinfo and auxv for current thread */
+    for (i = 0; i < info->numnote; i++)
+        if ((error = write_note(&info->notes[i], fd)) != 0)
+            return (error);
+
+    /* write prstatus for each thread */
+    for (ets = info->thread_list.tqh_first; ets != NULL;
+        ets = ets->ets_link.tqe_next) {
+        if ((error = write_note(&ets->notes[0], fd)) != 0)
+            return (error);
+    }
+
+    return (0);
+}
+
+/*
+ * Write out ELF coredump.
+ *
+ * See documentation of ELF object file format in:
+ * http://www.caldera.com/developers/devspecs/gabi41.pdf
+ *
+ * Coredump format in linux is following:
+ *
+ * 0   +----------------------+         \
+ *     | ELF header           | ET_CORE  |
+ *     +----------------------+          |
+ *     | ELF program headers  |          |--- headers
+ *     | - NOTE section       |          |
+ *     | - PT_LOAD sections   |          |
+ *     +----------------------+         /
+ *     | NOTEs:               |
+ *     | - NT_PRSTATUS        |
+ *     | - NT_PRSINFO         |
+ *     | - NT_AUXV            |
+ *     +----------------------+ <-- aligned to target page
+ *     | Process memory dump  |
+ *     :                      :
+ *     .                      .
+ *     :                      :
+ *     |                      |
+ *     +----------------------+
+ *
+ * NT_PRSTATUS -> struct elf_prstatus (per thread)
+ * NT_PRSINFO  -> struct elf_prpsinfo
+ * NT_AUXV is array of { type, value } pairs (see fill_auxv_note()).
+ *
+ * Format follows System V format as close as possible.  Current
+ * version limitations are as follows:
+ *     - no floating point registers are dumped
+ *
+ * Function returns 0 in case of success, negative errno otherwise.
+ *
+ * TODO: make this work also during runtime: it should be
+ * possible to force coredump from running process and then
+ * continue processing.  For example qemu could set up SIGUSR2
+ * handler (provided that target process haven't registered
+ * handler for that) that does the dump when signal is received.
+ */
+static int elf_core_dump(int signr, const CPUState *env)
+{
+    const TaskState *ts = (const TaskState *)env->opaque;
+    struct vm_area_struct *vma = NULL;
+    char corefile[PATH_MAX];
+    struct elf_note_info info;
+    struct elfhdr elf;
+    struct elf_phdr phdr;
+    struct rlimit dumpsize;
+    struct mm_struct *mm = NULL;
+    off_t offset = 0, data_offset = 0;
+    int segs = 0;
+    int fd = -1;
+
+    errno = 0;
+    getrlimit(RLIMIT_CORE, &dumpsize);
+    if (dumpsize.rlim_cur == 0)
+       return 0;
+
+    if (core_dump_filename(ts, corefile, sizeof (corefile)) < 0)
+        return (-errno);
+
+    if ((fd = open(corefile, O_WRONLY | O_CREAT,
+        S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0)
+        return (-errno);
+
+    /*
+     * Walk through target process memory mappings and
+     * set up structure containing this information.  After
+     * this point vma_xxx functions can be used.
+     */
+    if ((mm = vma_init()) == NULL)
+        goto out;
+
+    walk_memory_regions(mm, vma_walker);
+    segs = vma_get_mapping_count(mm);
+
+    /*
+     * Construct valid coredump ELF header.  We also
+     * add one more segment for notes.
+     */
+    fill_elf_header(&elf, segs + 1, ELF_MACHINE, 0);
+    if (dump_write(fd, &elf, sizeof (elf)) != 0)
+        goto out;
+
+    /* fill in in-memory version of notes */
+    if (fill_note_info(&info, signr, env) < 0)
+        goto out;
+
+    offset += sizeof (elf);                             /* elf header */
+    offset += (segs + 1) * sizeof (struct elf_phdr);    /* program headers */
+
+    /* write out notes program header */
+    fill_elf_note_phdr(&phdr, info.notes_size, offset);
+
+    offset += info.notes_size;
+    if (dump_write(fd, &phdr, sizeof (phdr)) != 0)
+        goto out;
+
+    /*
+     * ELF specification wants data to start at page boundary so
+     * we align it here.
+     */
+    offset = roundup(offset, ELF_EXEC_PAGESIZE);
+
+    /*
+     * Write program headers for memory regions mapped in
+     * the target process.
+     */
+    for (vma = vma_first(mm); vma != NULL; vma = vma_next(vma)) {
+        (void) memset(&phdr, 0, sizeof (phdr));
+
+        phdr.p_type = PT_LOAD;
+        phdr.p_offset = offset;
+        phdr.p_vaddr = vma->vma_start;
+        phdr.p_paddr = 0;
+        phdr.p_filesz = vma_dump_size(vma);
+        offset += phdr.p_filesz;
+        phdr.p_memsz = vma->vma_end - vma->vma_start;
+        phdr.p_flags = vma->vma_flags & PROT_READ ? PF_R : 0;
+        if (vma->vma_flags & PROT_WRITE)
+            phdr.p_flags |= PF_W;
+        if (vma->vma_flags & PROT_EXEC)
+            phdr.p_flags |= PF_X;
+        phdr.p_align = ELF_EXEC_PAGESIZE;
+
+        dump_write(fd, &phdr, sizeof (phdr));
+    }
+
+    /*
+     * Next we write notes just after program headers.  No
+     * alignment needed here.
+     */
+    if (write_note_info(&info, fd) < 0)
+        goto out;
+
+    /* align data to page boundary */
+    data_offset = lseek(fd, 0, SEEK_CUR);
+    data_offset = TARGET_PAGE_ALIGN(data_offset);
+    if (lseek(fd, data_offset, SEEK_SET) != data_offset)
+        goto out;
+
+    /*
+     * Finally we can dump process memory into corefile as well.
+     */
+    for (vma = vma_first(mm); vma != NULL; vma = vma_next(vma)) {
+        abi_ulong addr;
+        abi_ulong end;
+
+        end = vma->vma_start + vma_dump_size(vma);
+
+        for (addr = vma->vma_start; addr < end;
+            addr += TARGET_PAGE_SIZE) {
+            char page[TARGET_PAGE_SIZE];
+            int error;
+
+            /*
+             *  Read in page from target process memory and
+             *  write it to coredump file.
+             */
+            error = copy_from_user(page, addr, sizeof (page));
+            if (error != 0) {
+                (void) fprintf(stderr, "unable to dump " TARGET_FMT_lx "\n",
+                    addr);
+                errno = -error;
+                goto out;
+            }
+            if (dump_write(fd, page, TARGET_PAGE_SIZE) < 0)
+                goto out;
+        }
+    }
+
+out:
+    free_note_info(&info);
+    if (mm != NULL)
+        vma_delete(mm);
+    (void) close(fd);
+
+    if (errno != 0)
+        return (-errno);
+    return (0);
+}
+
+#endif /* USE_ELF_CORE_DUMP */
+
 static int load_aout_interp(void * exptr, int interp_fd)
 {
     printf("a.out interpreter not yet supported\n");
diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c
index ada7c69..14c433e 100644
--- a/linux-user/linuxload.c
+++ b/linux-user/linuxload.c
@@ -115,6 +115,7 @@ static int prepare_binprm(struct linux_binprm *bprm)
 abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
                               abi_ulong stringp, int push_ptr)
 {
+    TaskState *ts = (TaskState *)thread_env->opaque;
     int n = sizeof(abi_ulong);
     abi_ulong envp;
     abi_ulong argv;
@@ -133,13 +134,14 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
     sp -= n;
     /* FIXME - handle put_user() failures */
     put_user_ual(argc, sp);
-
+    ts->info->arg_start = stringp;
     while (argc-- > 0) {
         /* FIXME - handle put_user() failures */
         put_user_ual(stringp, argv);
         argv += n;
         stringp += target_strlen(stringp) + 1;
     }
+    ts->info->arg_end = stringp;
     /* FIXME - handle put_user() failures */
     put_user_ual(0, argv);
     while (envc-- > 0) {
@@ -155,45 +157,45 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
 }
 
 int loader_exec(const char * filename, char ** argv, char ** envp,
-             struct target_pt_regs * regs, struct image_info *infop)
+             struct target_pt_regs * regs, struct image_info *infop,
+             struct linux_binprm *bprm)
 {
-    struct linux_binprm bprm;
     int retval;
     int i;
 
-    bprm.p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int);
+    bprm->p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int);
     for (i=0 ; i<MAX_ARG_PAGES ; i++)       /* clear page-table */
-            bprm.page[i] = 0;
+            bprm->page[i] = 0;
     retval = open(filename, O_RDONLY);
     if (retval < 0)
         return retval;
-    bprm.fd = retval;
-    bprm.filename = (char *)filename;
-    bprm.argc = count(argv);
-    bprm.argv = argv;
-    bprm.envc = count(envp);
-    bprm.envp = envp;
+    bprm->fd = retval;
+    bprm->filename = (char *)filename;
+    bprm->argc = count(argv);
+    bprm->argv = argv;
+    bprm->envc = count(envp);
+    bprm->envp = envp;
 
-    retval = prepare_binprm(&bprm);
+    retval = prepare_binprm(bprm);
 
     infop->host_argv = argv;
 
     if(retval>=0) {
-        if (bprm.buf[0] == 0x7f
-                && bprm.buf[1] == 'E'
-                && bprm.buf[2] == 'L'
-                && bprm.buf[3] == 'F') {
+        if (bprm->buf[0] == 0x7f
+                && bprm->buf[1] == 'E'
+                && bprm->buf[2] == 'L'
+                && bprm->buf[3] == 'F') {
 #ifndef TARGET_HAS_ELFLOAD32
-            retval = load_elf_binary(&bprm,regs,infop);
+            retval = load_elf_binary(bprm,regs,infop);
 #else
-            retval = load_elf_binary_multi(&bprm, regs, infop);
+            retval = load_elf_binary_multi(bprm, regs, infop);
 #endif
 #if defined(TARGET_HAS_BFLT)
-        } else if (bprm.buf[0] == 'b'
-                && bprm.buf[1] == 'F'
-                && bprm.buf[2] == 'L'
-                && bprm.buf[3] == 'T') {
-            retval = load_flt_binary(&bprm,regs,infop);
+        } else if (bprm->buf[0] == 'b'
+                && bprm->buf[1] == 'F'
+                && bprm->buf[2] == 'L'
+                && bprm->buf[3] == 'T') {
+            retval = load_flt_binary(bprm,regs,infop);
 #endif
         } else {
             fprintf(stderr, "Unknown binary format\n");
@@ -209,7 +211,7 @@ int loader_exec(const char * filename, char ** argv, char ** envp,
 
     /* Something went wrong, return the inode and free the argument pages*/
     for (i=0 ; i<MAX_ARG_PAGES ; i++) {
-        free(bprm.page[i]);
+        free(bprm->page[i]);
     }
     return(retval);
 }
diff --git a/linux-user/main.c b/linux-user/main.c
index 4832d3f..7eabd0c 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -25,6 +25,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <sys/mman.h>
+#include <sys/syscall.h>
 
 #include "qemu.h"
 #include "qemu-common.h"
@@ -2319,6 +2320,27 @@ static void usage(void)
 
 THREAD CPUState *thread_env;
 
+void task_settid(TaskState *ts)
+{
+    if (ts->ts_tid == 0) {
+#ifdef USE_NPTL
+        ts->ts_tid = (pid_t)syscall(SYS_gettid);
+#else
+        /* when no threads are used, tid becomes pid */
+        ts->ts_tid = getpid();
+#endif
+    }
+}
+
+void stop_all_tasks(void)
+{
+    /*
+     * We trust that when using NPTL, start_exclusive()
+     * handles thread stopping correctly.
+     */
+    start_exclusive();
+}
+
 /* Assumes contents are already zeroed.  */
 void init_task_state(TaskState *ts)
 {
@@ -2338,6 +2360,7 @@ int main(int argc, char **argv, char **envp)
     const char *cpu_model;
     struct target_pt_regs regs1, *regs = &regs1;
     struct image_info info1, *info = &info1;
+    struct linux_binprm bprm;
     TaskState ts1, *ts = &ts1;
     CPUState *env;
     int optind;
@@ -2467,6 +2490,8 @@ int main(int argc, char **argv, char **envp)
     /* Zero out image_info */
     memset(info, 0, sizeof(struct image_info));
 
+    memset(&bprm, 0, sizeof (bprm));
+
     /* Scan interp_prefix dir for replacement files. */
     init_paths(interp_prefix);
 
@@ -2543,7 +2568,16 @@ int main(int argc, char **argv, char **envp)
     }
     target_argv[target_argc] = NULL;
 
-    if (loader_exec(filename, target_argv, target_environ, regs, info) != 0) {
+    memset(ts, 0, sizeof(TaskState));
+    init_task_state(ts);
+    /* build Task State */
+    ts->info = info;
+    ts->bprm = &bprm;
+    env->opaque = ts;
+    task_settid(ts);
+
+    if (loader_exec(filename, target_argv, target_environ, regs,
+        info, &bprm) != 0) {
         printf("Error loading %s\n", filename);
         _exit(1);
     }
@@ -2579,12 +2613,6 @@ int main(int argc, char **argv, char **envp)
     syscall_init();
     signal_init();
 
-    /* build Task State */
-    memset(ts, 0, sizeof(TaskState));
-    init_task_state(ts);
-    ts->info = info;
-    env->opaque = ts;
-
 #if defined(TARGET_I386)
     cpu_x86_set_cpl(env, 3);
 
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index d83a2a4..e04a31c 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -18,6 +18,7 @@
 #include "syscall.h"
 #include "target_signal.h"
 #include "gdbstub.h"
+#include "sys-queue.h"
 
 #if defined(USE_NPTL)
 #define THREAD __thread
@@ -44,6 +45,9 @@ struct image_info {
         abi_ulong       entry;
         abi_ulong       code_offset;
         abi_ulong       data_offset;
+        abi_ulong       saved_auxv;
+        abi_ulong       arg_start;
+        abi_ulong       arg_end;
         char            **host_argv;
 	int		personality;
 };
@@ -87,7 +91,7 @@ struct emulated_sigtable {
 /* NOTE: we force a big alignment so that the stack stored after is
    aligned too */
 typedef struct TaskState {
-    struct TaskState *next;
+    pid_t ts_tid;     /* tid (or pid) of this task */
 #ifdef TARGET_ARM
     /* FPA state */
     FPA11 fpa;
@@ -114,6 +118,7 @@ typedef struct TaskState {
 #endif
     int used; /* non zero if used */
     struct image_info *info;
+    struct linux_binprm *bprm;
 
     struct emulated_sigtable sigtab[TARGET_NSIG];
     struct sigqueue sigqueue_table[MAX_SIGQUEUE_SIZE]; /* siginfo queue */
@@ -125,6 +130,8 @@ typedef struct TaskState {
 
 extern char *exec_path;
 void init_task_state(TaskState *ts);
+void task_settid(TaskState *);
+void stop_all_tasks(void);
 extern const char *qemu_uname_release;
 
 /* ??? See if we can avoid exposing so much of the loader internals.  */
@@ -149,13 +156,15 @@ struct linux_binprm {
         char **argv;
         char **envp;
         char * filename;        /* Name of binary */
+        int (*core_dump)(int, const CPUState *); /* coredump routine */
 };
 
 void do_init_thread(struct target_pt_regs *regs, struct image_info *infop);
 abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
                               abi_ulong stringp, int push_ptr);
 int loader_exec(const char * filename, char ** argv, char ** envp,
-             struct target_pt_regs * regs, struct image_info *infop);
+             struct target_pt_regs * regs, struct image_info *infop,
+             struct linux_binprm *);
 
 int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
                     struct image_info * info);
diff --git a/linux-user/signal.c b/linux-user/signal.c
index 371927e..6a34171 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -27,6 +27,7 @@
 #include <errno.h>
 #include <assert.h>
 #include <sys/ucontext.h>
+#include <sys/resource.h>
 
 #include "qemu.h"
 #include "qemu-common.h"
@@ -287,6 +288,23 @@ static int fatal_signal (int sig)
     }
 }
 
+/* returns 1 if given signal should dump core if not handled */
+static int core_dump_signal(int sig)
+{
+    switch (sig) {
+    case TARGET_SIGABRT:
+    case TARGET_SIGFPE:
+    case TARGET_SIGILL:
+    case TARGET_SIGQUIT:
+    case TARGET_SIGSEGV:
+    case TARGET_SIGTRAP:
+    case TARGET_SIGBUS:
+        return (1);
+    default:
+        return (0);
+    }
+}
+
 void signal_init(void)
 {
     struct sigaction act;
@@ -352,13 +370,29 @@ static inline void free_sigqueue(CPUState *env, struct sigqueue *q)
 /* abort execution with signal */
 static void QEMU_NORETURN force_sig(int sig)
 {
-    int host_sig;
+    TaskState *ts = (TaskState *)thread_env->opaque;
+    int host_sig, core_dumped = 0;
     struct sigaction act;
     host_sig = target_to_host_signal(sig);
-    fprintf(stderr, "qemu: uncaught target signal %d (%s) - exiting\n",
-            sig, strsignal(host_sig));
     gdb_signalled(thread_env, sig);
 
+    /* dump core if supported by target binary format */
+    if (core_dump_signal(sig) && (ts->bprm->core_dump != NULL)) {
+        stop_all_tasks();
+        core_dumped =
+            ((*ts->bprm->core_dump)(sig, thread_env) == 0);
+    }
+    if (core_dumped) {
+        /* we already dumped the core of target process, we don't want
+         * a coredump of qemu itself */
+        struct rlimit nodump;
+        getrlimit(RLIMIT_CORE, &nodump);
+        nodump.rlim_cur=0;
+        setrlimit(RLIMIT_CORE, &nodump);
+        (void) fprintf(stderr, "qemu: uncaught target signal %d (%s) - %s\n",
+            sig, strsignal(host_sig), "core dumped" );
+    }
+
     /* The proper exit code for dieing from an uncaught signal is
      * -<signal>.  The kernel doesn't allow exit() or _exit() to pass
      * a negative value.  To get the proper exit code we need to
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 47d03f7..56f2a3f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3379,11 +3379,14 @@ static void *clone_func(void *arg)
 {
     new_thread_info *info = arg;
     CPUState *env;
+    TaskState *ts;
 
     env = info->env;
     thread_env = env;
+    ts = (TaskState *)thread_env->opaque;
     info->tid = gettid();
     env->host_tid = info->tid;
+    task_settid(ts);
     if (info->child_tidptr)
         put_user_u32(info->tid, info->child_tidptr);
     if (info->parent_tidptr)
@@ -3435,6 +3438,7 @@ static int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp,
         flags &= ~(CLONE_VFORK | CLONE_VM);
 
     if (flags & CLONE_VM) {
+        TaskState *parent_ts = (TaskState *)env->opaque;
 #if defined(USE_NPTL)
         new_thread_info info;
         pthread_attr_t attr;
@@ -3447,6 +3451,8 @@ static int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp,
         /* Init regs that differ from the parent.  */
         cpu_clone_regs(new_env, newsp);
         new_env->opaque = ts;
+        ts->bprm = parent_ts->bprm;
+        ts->info = parent_ts->info;
 #if defined(USE_NPTL)
         nptl_flags = flags;
         flags &= ~CLONE_NPTL_FLAGS2;
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 04/21] linux-user: added x86 and x86_64 support for ELF coredump
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (2 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 03/21] linux-user: implemented ELF coredump support for ARM target riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-14 15:21   ` Blue Swirl
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 05/21] linux-user: strace now handles guest strings correctly [v2] riku.voipio
                   ` (17 subsequent siblings)
  21 siblings, 1 reply; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Mika Westerberg <mika.westerberg@iki.fi>


From: Mika Westerberg <mika.westerberg@iki.fi>
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 linux-user/elfload.c |   83 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 83 insertions(+), 0 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index c9e8bc1..1839337 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -134,6 +134,52 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
     regs->rip = infop->entry;
 }
 
+typedef target_ulong    elf_greg_t;
+typedef uint32_t        target_uid_t;
+typedef uint32_t        target_gid_t;
+typedef int32_t         target_pid_t;
+
+#define ELF_NREG    27
+typedef elf_greg_t  elf_gregset_t[ELF_NREG];
+
+/*
+ * Note that ELF_NREG should be 29 as there should be place for
+ * TRAPNO and ERR "registers" as well but linux doesn't dump
+ * those.
+ *
+ * See linux kernel: arch/x86/include/asm/elf.h
+ */ 
+static void elf_core_copy_regs(elf_gregset_t *regs, const CPUState *env)
+{
+    (*regs)[0] = env->regs[15];
+    (*regs)[1] = env->regs[14];
+    (*regs)[2] = env->regs[13];
+    (*regs)[3] = env->regs[12];
+    (*regs)[4] = env->regs[R_EBP];
+    (*regs)[5] = env->regs[R_EBX];
+    (*regs)[6] = env->regs[11];
+    (*regs)[7] = env->regs[10];
+    (*regs)[8] = env->regs[9];
+    (*regs)[9] = env->regs[8];
+    (*regs)[10] = env->regs[R_EAX];
+    (*regs)[11] = env->regs[R_ECX];
+    (*regs)[12] = env->regs[R_EDX];
+    (*regs)[13] = env->regs[R_ESI];
+    (*regs)[14] = env->regs[R_EDI];
+    (*regs)[15] = env->regs[R_EAX]; /* XXX */
+    (*regs)[16] = env->eip;
+    (*regs)[17] = env->segs[R_CS].selector & 0xffff;
+    (*regs)[18] = env->eflags;
+    (*regs)[19] = env->regs[R_ESP];
+    (*regs)[20] = env->segs[R_SS].selector & 0xffff;
+    (*regs)[21] = env->segs[R_FS].selector & 0xffff;
+    (*regs)[22] = env->segs[R_GS].selector & 0xffff;
+    (*regs)[23] = env->segs[R_DS].selector & 0xffff;
+    (*regs)[24] = env->segs[R_ES].selector & 0xffff;
+    (*regs)[25] = env->segs[R_FS].selector & 0xffff;
+    (*regs)[26] = env->segs[R_GS].selector & 0xffff;
+}
+
 #else
 
 #define ELF_START_MMAP 0x80000000
@@ -164,8 +210,45 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
        A value of 0 tells we have no such handler.  */
     regs->edx = 0;
 }
+
+typedef target_ulong    elf_greg_t;
+typedef uint16_t        target_uid_t;
+typedef uint16_t        target_gid_t;
+typedef int32_t         target_pid_t;
+
+#define ELF_NREG    17
+typedef elf_greg_t  elf_gregset_t[ELF_NREG];
+
+/*
+ * Note that ELF_NREG should be 19 as there should be place for
+ * TRAPNO and ERR "registers" as well but linux doesn't dump
+ * those.
+ *
+ * See linux kernel: arch/x86/include/asm/elf.h
+ */ 
+static void elf_core_copy_regs(elf_gregset_t *regs, const CPUState *env)
+{
+    (*regs)[0] = env->regs[R_EBX];
+    (*regs)[1] = env->regs[R_ECX];
+    (*regs)[2] = env->regs[R_EDX];
+    (*regs)[3] = env->regs[R_ESI];
+    (*regs)[4] = env->regs[R_EDI];
+    (*regs)[5] = env->regs[R_EBP];
+    (*regs)[6] = env->regs[R_EAX];
+    (*regs)[7] = env->segs[R_DS].selector & 0xffff;
+    (*regs)[8] = env->segs[R_ES].selector & 0xffff;
+    (*regs)[9] = env->segs[R_FS].selector & 0xffff;
+    (*regs)[10] = env->segs[R_GS].selector & 0xffff;
+    (*regs)[11] = env->regs[R_EAX]; /* XXX */
+    (*regs)[12] = env->eip;
+    (*regs)[13] = env->segs[R_CS].selector & 0xffff;
+    (*regs)[14] = env->eflags;
+    (*regs)[15] = env->regs[R_ESP];
+    (*regs)[16] = env->segs[R_SS].selector & 0xffff;
+}
 #endif
 
+#define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE	4096
 
 #endif
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 05/21] linux-user: strace now handles guest strings correctly [v2]
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (3 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 04/21] linux-user: added x86 and x86_64 support for ELF coredump riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-14 15:17   ` Blue Swirl
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 06/21] Revived GUEST_BASE support for usermode emulation targets [v5] riku.voipio
                   ` (16 subsequent siblings)
  21 siblings, 1 reply; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Mika Westerberg <mika.westerberg@iki.fi>

- to not to break strace with GUEST_BASE is set:
- Strace now can load and print guest strings correctly.
- Added printing support for commonly used flags in some syscalls
  (e.g open, creat, mmap etc.)

v2:
- fix strace.c build on etch
- add futex print to strace

From: Mika Westerberg <mika.westerberg@iki.fi>
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 linux-user/strace.c       | 1072 ++++++++++++++++++++++++++++++++++++++++++++-
 linux-user/strace.list    |  111 +++---
 linux-user/syscall.c      |    6 -
 linux-user/syscall_defs.h |    6 +
 4 files changed, 1118 insertions(+), 77 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index b4caffe..5ea9acb 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -6,6 +6,9 @@
 #include <sys/shm.h>
 #include <sys/select.h>
 #include <sys/types.h>
+#include <sys/mount.h>
+#include <sys/mman.h>
+#include <linux/futex.h>
 #include <unistd.h>
 #include "qemu.h"
 
@@ -21,6 +24,47 @@ struct syscallname {
     void (*result)(const struct syscallname *, abi_long);
 };
 
+#ifdef __GNUC__
+/*
+ * It is possible that target doesn't have syscall that uses
+ * following flags but we don't want the compiler to warn
+ * us about them being unused.  Same applies to utility print
+ * functions.  It is ok to keep them while not used.
+ */
+#define UNUSED __attribute__ ((unused))
+#else
+#define UNUSED
+#endif
+
+/*
+ * Structure used to translate flag values into strings.  This is
+ * similar that is in the actual strace tool.
+ */
+struct flags {
+    abi_long    f_value;  /* flag */
+    const char  *f_string; /* stringified flag */
+};
+
+/* common flags for all architectures */
+#define FLAG_GENERIC(name) { name, #name }
+/* target specific flags (syscall_defs.h has TARGET_<flag>) */
+#define FLAG_TARGET(name)  { TARGET_ ## name, #name }
+/* end of flags array */
+#define FLAG_END           { 0, NULL }
+
+UNUSED static const char *get_comma(int);
+UNUSED static void print_pointer(abi_long, int);
+UNUSED static void print_flags(const struct flags *, abi_long, int);
+UNUSED static void print_at_dirfd(abi_long, int);
+UNUSED static void print_file_mode(abi_long, int);
+UNUSED static void print_open_flags(abi_long, int);
+UNUSED static void print_syscall_prologue(const struct syscallname *);
+UNUSED static void print_syscall_epilogue(const struct syscallname *);
+UNUSED static void print_string(abi_long, int);
+UNUSED static void print_raw_param(const char *, abi_long, int);
+UNUSED static void print_timeval(abi_ulong, int);
+UNUSED static void print_number(abi_long, int);
+
 /*
  * Utility functions
  */
@@ -100,22 +144,6 @@ print_fdset(int n, abi_ulong target_fds_addr)
     }
     gemu_log("]");
 }
-
-static void
-print_timeval(abi_ulong tv_addr)
-{
-    if( tv_addr ) {
-        struct target_timeval *tv;
-
-        tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
-        if (!tv)
-            return;
-        gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}",
-        	 tv->tv_sec, tv->tv_usec);
-        unlock_user(tv, tv_addr, 0);
-    } else
-        gemu_log("NULL");
-}
 #endif
 
 /*
@@ -142,7 +170,7 @@ print_newselect(const struct syscallname *name,
     gemu_log(",");
     print_fdset(arg1, arg4);
     gemu_log(",");
-    print_timeval(arg5);
+    print_timeval(arg5, 1);
     gemu_log(")");
 
     /* save for use in the return output function below */
@@ -250,11 +278,1019 @@ print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
     gemu_log(",");
     print_fdset(newselect_arg1,newselect_arg4);
     gemu_log(",");
-    print_timeval(newselect_arg5);
+    print_timeval(newselect_arg5, 1);
     gemu_log(")\n");
 }
 #endif
 
+UNUSED static struct flags access_flags[] = {
+    FLAG_GENERIC(F_OK),
+    FLAG_GENERIC(R_OK),
+    FLAG_GENERIC(W_OK),
+    FLAG_GENERIC(X_OK),
+    FLAG_END,
+};
+
+UNUSED static struct flags at_file_flags[] = {
+#ifdef AT_EACCESS
+    FLAG_GENERIC(AT_EACCESS),
+#endif
+#ifdef AT_SYMLINK_NOFOLLOW
+    FLAG_GENERIC(AT_SYMLINK_NOFOLLOW),
+#endif
+    FLAG_END,
+};
+
+UNUSED static struct flags unlinkat_flags[] = {
+#ifdef AT_REMOVEDIR
+    FLAG_GENERIC(AT_REMOVEDIR),
+#endif
+    FLAG_END,
+};
+
+UNUSED static struct flags mode_flags[] = {
+    FLAG_GENERIC(S_IFSOCK),
+    FLAG_GENERIC(S_IFLNK),
+    FLAG_GENERIC(S_IFREG),
+    FLAG_GENERIC(S_IFBLK),
+    FLAG_GENERIC(S_IFDIR),
+    FLAG_GENERIC(S_IFCHR),
+    FLAG_GENERIC(S_IFIFO),
+    FLAG_END,
+};
+
+UNUSED static struct flags open_access_flags[] = {
+    FLAG_TARGET(O_RDONLY),
+    FLAG_TARGET(O_WRONLY),
+    FLAG_TARGET(O_RDWR),
+    FLAG_END,
+};
+
+UNUSED static struct flags open_flags[] = {
+    FLAG_TARGET(O_APPEND),
+    FLAG_TARGET(O_CREAT),
+    FLAG_TARGET(O_DIRECTORY),
+    FLAG_TARGET(O_EXCL),
+    FLAG_TARGET(O_LARGEFILE),
+    FLAG_TARGET(O_NOCTTY),
+    FLAG_TARGET(O_NOFOLLOW),
+    FLAG_TARGET(O_NONBLOCK),      /* also O_NDELAY */
+    FLAG_TARGET(O_SYNC),
+    FLAG_TARGET(O_TRUNC),
+#ifdef O_DIRECT
+    FLAG_TARGET(O_DIRECT),
+#endif
+    FLAG_END,
+};
+
+UNUSED static struct flags mount_flags[] = {
+#ifdef MS_BIND
+    FLAG_GENERIC(MS_BIND),
+#endif
+#ifdef MS_DIRSYNC
+    FLAG_GENERIC(MS_DIRSYNC),
+#endif
+    FLAG_GENERIC(MS_MANDLOCK),
+#ifdef MS_MOVE
+    FLAG_GENERIC(MS_MOVE),
+#endif
+    FLAG_GENERIC(MS_NOATIME),
+    FLAG_GENERIC(MS_NODEV),
+    FLAG_GENERIC(MS_NODIRATIME),
+    FLAG_GENERIC(MS_NOEXEC),
+    FLAG_GENERIC(MS_NOSUID),
+    FLAG_GENERIC(MS_RDONLY),
+#ifdef MS_RELATIME
+    FLAG_GENERIC(MS_RELATIME),
+#endif
+    FLAG_GENERIC(MS_REMOUNT),
+    FLAG_GENERIC(MS_SYNCHRONOUS),
+    FLAG_END,
+};
+
+UNUSED static struct flags umount2_flags[] = {
+#ifdef MNT_FORCE
+    FLAG_GENERIC(MNT_FORCE),
+#endif
+#ifdef MNT_DETACH
+    FLAG_GENERIC(MNT_DETACH),
+#endif
+#ifdef MNT_EXPIRE
+    FLAG_GENERIC(MNT_EXPIRE),
+#endif
+    FLAG_END,
+};
+
+UNUSED static struct flags mmap_prot_flags[] = {
+    FLAG_GENERIC(PROT_NONE),
+    FLAG_GENERIC(PROT_EXEC),
+    FLAG_GENERIC(PROT_READ),
+    FLAG_GENERIC(PROT_WRITE),
+    FLAG_END,
+};
+
+UNUSED static struct flags mmap_flags[] = {
+    FLAG_TARGET(MAP_SHARED),
+    FLAG_TARGET(MAP_PRIVATE),
+    FLAG_TARGET(MAP_ANONYMOUS),
+    FLAG_TARGET(MAP_DENYWRITE),
+    FLAG_TARGET(MAP_FIXED),
+    FLAG_TARGET(MAP_GROWSDOWN),
+#ifdef MAP_LOCKED
+    FLAG_TARGET(MAP_LOCKED),
+#endif
+#ifdef MAP_NONBLOCK
+    FLAG_TARGET(MAP_NONBLOCK),
+#endif
+    FLAG_TARGET(MAP_NORESERVE),
+#ifdef MAP_POPULATE
+    FLAG_TARGET(MAP_POPULATE),
+#endif
+    FLAG_END,
+};
+
+UNUSED static struct flags fcntl_flags[] = {
+    FLAG_TARGET(F_DUPFD),
+    FLAG_TARGET(F_GETFD),
+    FLAG_TARGET(F_SETFD),
+    FLAG_TARGET(F_GETFL),
+    FLAG_TARGET(F_SETFL),
+    FLAG_TARGET(F_GETLK),
+    FLAG_TARGET(F_SETLK),
+    FLAG_TARGET(F_SETLKW),
+    FLAG_END,
+};
+
+/*
+ * print_xxx utility functions.  These are used to print syscall
+ * parameters in certain format.  All of these have parameter
+ * named 'last'.  This parameter is used to add comma to output
+ * when last == 0.
+ */
+
+static const char *
+get_comma(int last)
+{
+    return ((last) ? "" : ",");
+}
+
+static void
+print_flags(const struct flags *f, abi_long tflags, int last)
+{
+    const char *sep = "";
+    int flags;
+    int n;
+
+    flags = (int)tswap32(tflags);
+
+    if ((flags == 0) && (f->f_value == 0)) {
+        gemu_log("%s%s", f->f_string, get_comma(last));
+        return;
+    }
+    for (n = 0; f->f_string != NULL; f++) {
+        if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
+            gemu_log("%s%s", sep, f->f_string);
+            flags &= ~f->f_value;
+            sep = "|";
+            n++;
+        }
+    }
+
+    if (n > 0) {
+        /* print rest of the flags as numeric */
+        if (flags != 0) {
+            gemu_log("%s%#x%s", sep, flags, get_comma(last));
+        } else {
+            gemu_log("%s", get_comma(last));
+        }
+    } else {
+        /* no string version of flags found, print them in hex then */
+        gemu_log("%#x%s", flags, get_comma(last));
+    }
+}
+
+static void
+print_at_dirfd(abi_long tdirfd, int last)
+{
+    int dirfd = tswap32(tdirfd);
+
+#ifdef AT_FDCWD
+    if (dirfd == AT_FDCWD) {
+        gemu_log("AT_FDCWD%s", get_comma(last));
+        return;
+    }
+#endif
+    gemu_log("%d%s", dirfd, get_comma(last));
+}
+
+static void
+print_file_mode(abi_long tmode, int last)
+{
+    const char *sep = "";
+    const struct flags *m;
+    mode_t mode = (mode_t)tswap32(tmode);
+
+    for (m = &mode_flags[0]; m->f_string != NULL; m++) {
+        if ((m->f_value & mode) == m->f_value) {
+            gemu_log("%s%s", m->f_string, sep);
+            sep = "|";
+            mode &= ~m->f_value;
+            break;
+        }
+    }
+
+    mode &= ~S_IFMT;
+    /* print rest of the mode as octal */
+    if (mode != 0)
+        gemu_log("%s%#o", sep, mode);
+
+    gemu_log("%s", get_comma(last));
+}
+
+static void
+print_open_flags(abi_long tflags, int last)
+{
+    int flags = tswap32(tflags);
+
+    print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
+    flags &= ~TARGET_O_ACCMODE;
+    if (flags == 0) {
+        gemu_log("%s", get_comma(last));
+        return;
+    }
+    gemu_log("|");
+    print_flags(open_flags, flags, last);
+}
+
+static void
+print_syscall_prologue(const struct syscallname *sc)
+{
+    gemu_log("%s(", sc->name);
+}
+
+/*ARGSUSED*/
+static void
+print_syscall_epilogue(const struct syscallname *sc)
+{
+    (void)sc;
+    gemu_log(")");
+}
+
+static void
+print_string(abi_long addr, int last)
+{
+    char *s;
+
+    if ((s = lock_user_string(addr)) != NULL) {
+        gemu_log("\"%s\"%s", s, get_comma(last));
+        unlock_user(s, addr, 0);
+    } else {
+        /* can't get string out of it, so print it as pointer */
+        print_pointer(addr, last);
+    }
+}
+
+/*
+ * Prints out raw parameter using given format.  Caller needs
+ * to do byte swapping if needed.
+ */
+static void
+print_raw_param(const char *fmt, abi_long param, int last)
+{
+    char format[64];
+
+    (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
+    gemu_log(format, param);
+}
+
+static void
+print_pointer(abi_long p, int last)
+{
+    if (p == 0)
+        gemu_log("NULL%s", get_comma(last));
+    else
+        gemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
+}
+
+/*
+ * Reads 32-bit (int) number from guest address space from
+ * address 'addr' and prints it.
+ */
+static void
+print_number(abi_long addr, int last)
+{
+    if (addr == 0) {
+        gemu_log("NULL%s", get_comma(last));
+    } else {
+        int num;
+
+        get_user_s32(num, addr);
+        gemu_log("[%d]%s", num, get_comma(last));
+    }
+}
+
+static void
+print_timeval(abi_ulong tv_addr, int last)
+{
+    if( tv_addr ) {
+        struct target_timeval *tv;
+
+        tv = lock_user(VERIFY_READ, tv_addr, sizeof(*tv), 1);
+        if (!tv)
+            return;
+        gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
+            tv->tv_sec, tv->tv_usec, get_comma(last));
+        unlock_user(tv, tv_addr, 0);
+    } else
+        gemu_log("NULL%s", get_comma(last));
+}
+
+#undef UNUSED
+
+#ifdef TARGET_NR_accept
+static void
+print_accept(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_raw_param("%d", tswap32(arg0), 0);
+    print_pointer(arg1, 0);
+    print_number(arg2, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_access
+static void
+print_access(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_flags(access_flags, arg1, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_brk
+static void
+print_brk(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_pointer(arg0, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_chdir
+static void
+print_chdir(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_chmod
+static void
+print_chmod(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_file_mode(arg1, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_creat
+static void
+print_creat(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_file_mode(arg1, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_execv
+static void
+print_execv(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_raw_param("0x" TARGET_ABI_FMT_lx, tswapl(arg1), 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_faccessat
+static void
+print_faccessat(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_at_dirfd(arg0, 0);
+    print_string(arg1, 0);
+    print_flags(access_flags, arg2, 0);
+    print_flags(at_file_flags, arg3, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_fchmodat
+static void
+print_fchmodat(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_at_dirfd(arg0, 0);
+    print_string(arg1, 0);
+    print_file_mode(arg2, 0);
+    print_flags(at_file_flags, arg3, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_fchownat
+static void
+print_fchownat(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_at_dirfd(arg0, 0);
+    print_string(arg1, 0);
+#ifdef USE_UID16
+    print_raw_param("%d", tswap16(arg2), 0);
+    print_raw_param("%d", tswap16(arg3), 0);
+#else
+    print_raw_param("%d", tswap32(arg2), 0);
+    print_raw_param("%d", tswap32(arg3), 0);
+#endif
+    print_flags(at_file_flags, arg4, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#if defined(TARGET_NR_fcntl) || defined(TARGET_NR_fcntl64)
+static void
+print_fcntl(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_raw_param("%d", tswap32(arg0), 0);
+    print_flags(fcntl_flags, arg1, 0);
+    /*
+     * TODO: check flags and print following argument only
+     *       when needed.
+     */
+    print_pointer(arg2, 1);
+    print_syscall_epilogue(name);
+}
+#define print_fcntl64   print_fcntl
+#endif
+
+
+#ifdef TARGET_NR_futimesat
+static void
+print_futimesat(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_at_dirfd(arg0, 0);
+    print_string(arg1, 0);
+    print_timeval(arg2, 0);
+    print_timeval(arg2 + sizeof (struct target_timeval), 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_link
+static void
+print_link(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_string(arg1, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_linkat
+static void
+print_linkat(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_at_dirfd(arg0, 0);
+    print_string(arg1, 0);
+    print_at_dirfd(arg2, 0);
+    print_string(arg3, 0);
+    print_flags(at_file_flags, arg4, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
+    defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
+static void
+print_stat(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_pointer(arg1, 1);
+    print_syscall_epilogue(name);
+}
+#define print_lstat     print_stat
+#define print_stat64	print_stat
+#define print_lstat64   print_stat
+#endif
+
+#if defined(TARGET_NR_fstat) || defined(TARGET_NR_fstat64)
+static void
+print_fstat(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_raw_param("%d", tswap32(arg0), 0);
+    print_pointer(arg1, 1);
+    print_syscall_epilogue(name);
+}
+#define print_fstat64     print_fstat
+#endif
+
+#ifdef TARGET_NR_mkdir
+static void
+print_mkdir(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_file_mode(arg1, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_mkdirat
+static void
+print_mkdirat(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_at_dirfd(arg0, 0);
+    print_string(arg1, 0);
+    print_file_mode(arg2, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_mknod
+static void
+print_mknod(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    int hasdev = (tswapl(arg1) & (S_IFCHR|S_IFBLK));
+
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_file_mode(arg1, (hasdev == 0));
+    if (hasdev) {
+        print_raw_param("makedev(%d", major(tswapl(arg2)), 0);
+        print_raw_param("%d)", minor(tswapl(arg2)), 1);
+    }
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_mknodat
+static void
+print_mknodat(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    int hasdev = (tswapl(arg2) & (S_IFCHR|S_IFBLK));
+
+    print_syscall_prologue(name);
+    print_at_dirfd(arg0, 0);
+    print_string(arg1, 0);
+    print_file_mode(arg2, (hasdev == 0));
+    if (hasdev) {
+        print_raw_param("makedev(%d", major(tswapl(arg3)), 0);
+        print_raw_param("%d)", minor(tswapl(arg3)), 1);
+    }
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_mq_open
+static void
+print_mq_open(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    int is_creat = (tswapl(arg1) & TARGET_O_CREAT);
+
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_open_flags(arg1, (is_creat == 0));
+    if (is_creat) {
+        print_file_mode(arg2, 0);
+        print_pointer(arg3, 1);
+    }
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_open
+static void
+print_open(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    int is_creat = (tswap32(arg1) & TARGET_O_CREAT);
+
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_open_flags(arg1, (is_creat == 0));
+    if (is_creat)
+        print_file_mode(arg2, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_openat
+static void
+print_openat(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    int is_creat = (tswap32(arg2) & TARGET_O_CREAT);
+
+    print_syscall_prologue(name);
+    print_at_dirfd(arg0, 0);
+    print_string(arg1, 0);
+    print_open_flags(arg2, (is_creat == 0));
+    if (is_creat)
+        print_file_mode(arg3, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_mq_unlink
+static void
+print_mq_unlink(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#if defined(TARGET_NR_fstatat64) || defined(TARGET_NR_newfstatat)
+static void
+print_fstatat64(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_at_dirfd(arg0, 0);
+    print_string(arg1, 0);
+    print_pointer(arg2, 0);
+    print_flags(at_file_flags, arg3, 1);
+    print_syscall_epilogue(name);
+}
+#define print_newfstatat    print_fstatat64
+#endif
+
+#ifdef TARGET_NR_readlink
+static void
+print_readlink(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_pointer(arg1, 0);
+    print_raw_param("%u", tswapl(arg2), 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_readlinkat
+static void
+print_readlinkat(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_at_dirfd(arg0, 0);
+    print_string(arg1, 0);
+    print_pointer(arg2, 0);
+    print_raw_param("%u", tswapl(arg3), 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_rename
+static void
+print_rename(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_string(arg1, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_renameat
+static void
+print_renameat(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_at_dirfd(arg0, 0);
+    print_string(arg1, 0);
+    print_at_dirfd(arg2, 0);
+    print_string(arg3, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_statfs
+static void
+print_statfs(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_pointer(arg1, 1);
+    print_syscall_epilogue(name);
+}
+#define print_statfs64  print_statfs
+#endif
+
+#ifdef TARGET_NR_symlink
+static void
+print_symlink(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_string(arg1, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_symlinkat
+static void
+print_symlinkat(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_at_dirfd(arg1, 0);
+    print_string(arg2, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_mount
+static void
+print_mount(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_string(arg1, 0);
+    print_string(arg2, 0);
+    print_flags(mount_flags, arg3, 0);
+    print_pointer(arg4, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_umount
+static void
+print_umount(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_umount2
+static void
+print_umount2(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_flags(umount2_flags, arg1, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_unlink
+static void
+print_unlink(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_unlinkat
+static void
+print_unlinkat(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_at_dirfd(arg0, 0);
+    print_string(arg1, 0);
+    print_flags(unlinkat_flags, arg2, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_utime
+static void
+print_utime(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_pointer(arg1, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_utimes
+static void
+print_utimes(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_string(arg0, 0);
+    print_pointer(arg1, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_utimensat
+static void
+print_utimensat(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_at_dirfd(arg0, 0);
+    print_string(arg1, 0);
+    print_pointer(arg2, 0);
+    print_flags(at_file_flags, arg3, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_mmap
+static void
+print_mmap(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_pointer(arg0, 0);
+    print_raw_param("%d", tswapl(arg1), 0);
+    print_flags(mmap_prot_flags, arg2, 0);
+    print_flags(mmap_flags, arg3, 0);
+    print_raw_param("%d", tswapl(arg4), 0);
+    print_raw_param("%#x", tswapl(arg5), 1);
+    print_syscall_epilogue(name);
+}
+#define print_mmap2     print_mmap
+#endif
+
+#ifdef TARGET_NR_mprotect
+static void
+print_mprotect(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_pointer(arg0, 0);
+    print_raw_param("%d", tswapl(arg1), 0);
+    print_flags(mmap_prot_flags, arg2, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_munmap
+static void
+print_munmap(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_pointer(arg0, 0);
+    print_raw_param("%d", tswapl(arg1), 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_futex
+static void print_futex_op(abi_long tflag, int last)
+{
+#define print_op(val) \
+if( cmd == val ) { \
+    gemu_log(#val); \
+    return; \
+}
+
+    int cmd = (int)tswap32(tflag);
+#ifdef FUTEX_PRIVATE_FLAG
+    if (cmd == FUTEX_PRIVATE_FLAG)
+        gemu_log("FUTEX_PRIVATE_FLAG|");
+#endif
+    print_op(FUTEX_WAIT)
+    print_op(FUTEX_WAKE)
+    print_op(FUTEX_FD)
+    print_op(FUTEX_REQUEUE)
+    print_op(FUTEX_CMP_REQUEUE)
+    print_op(FUTEX_WAKE_OP)
+    print_op(FUTEX_LOCK_PI)
+    print_op(FUTEX_UNLOCK_PI)
+    print_op(FUTEX_TRYLOCK_PI)
+#ifdef FUTEX_WAIT_BITSET
+    print_op(FUTEX_WAIT_BITSET)
+#endif
+#ifdef FUTEX_WAKE_BITSET
+    print_op(FUTEX_WAKE_BITSET)
+#endif
+    /* unknown values */
+    gemu_log("%d",cmd);
+}
+
+static void
+print_futex(const struct syscallname *name,
+    abi_long arg0, abi_long arg1, abi_long arg2,
+    abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    print_syscall_prologue(name);
+    print_pointer(arg0, 0);
+    print_futex_op(arg1, 0);
+    print_raw_param(",%d", tswapl(arg2), 0);
+    print_pointer(arg3, 0); /* struct timespec */
+    print_pointer(arg4, 0);
+    print_raw_param("%d", tswapl(arg4), 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
 /*
  * An array of all of the syscalls we know about
  */
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 3f688db..97b7f76 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1,8 +1,13 @@
+/*
+ * Note that if you change format strings in these, check also
+ * that corresponding print functions are able to handle string
+ * locking correctly (see strace.c).
+ */
 #ifdef TARGET_NR_accept
-{ TARGET_NR_accept, "accept" , "%s(%d,%#x,%#x)", NULL, NULL },
+{ TARGET_NR_accept, "accept" , NULL, print_accept, NULL },
 #endif
 #ifdef TARGET_NR_access
-{ TARGET_NR_access, "access" , "%s(\"%s\",%#o)", NULL, NULL },
+{ TARGET_NR_access, "access" , NULL, print_access, NULL },
 #endif
 #ifdef TARGET_NR_acct
 { TARGET_NR_acct, "acct" , NULL, NULL, NULL },
@@ -38,7 +43,7 @@
 { TARGET_NR_break, "break" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_brk
-{ TARGET_NR_brk, "brk" , NULL, NULL, print_syscall_ret_addr },
+{ TARGET_NR_brk, "brk" , NULL, print_brk, print_syscall_ret_addr },
 #endif
 #ifdef TARGET_NR_cachectl
 { TARGET_NR_cachectl, "cachectl" , NULL, NULL, NULL },
@@ -53,10 +58,10 @@
 { TARGET_NR_capset, "capset" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_chdir
-{ TARGET_NR_chdir, "chdir" , "%s(\"%s\")", NULL, NULL },
+{ TARGET_NR_chdir, "chdir" , NULL, print_chdir, NULL },
 #endif
 #ifdef TARGET_NR_chmod
-{ TARGET_NR_chmod, "chmod" , "%s(\"%s\",%#o)", NULL, NULL },
+{ TARGET_NR_chmod, "chmod" , NULL, print_chmod, NULL },
 #endif
 #ifdef TARGET_NR_chown
 { TARGET_NR_chown, "chown" , NULL, NULL, NULL },
@@ -89,7 +94,7 @@
 { TARGET_NR_connect, "connect" , "%s(%d,%#x,%d)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_creat
-{ TARGET_NR_creat, "creat" , "%s(\"%s\",%#o)", NULL, NULL },
+{ TARGET_NR_creat, "creat" , NULL, print_creat, NULL },
 #endif
 #ifdef TARGET_NR_create_module
 { TARGET_NR_create_module, "create_module" , NULL, NULL, NULL },
@@ -122,7 +127,7 @@
 { TARGET_NR_epoll_wait_old, "epoll_wait_old" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_execv
-{ TARGET_NR_execv, "execv" , "%s(\"%s\",%ld,%ld,%ld,%ld,%ld)\n", NULL, NULL },
+{ TARGET_NR_execv, "execv" , NULL, print_execv, NULL },
 #endif
 #ifdef TARGET_NR_execve
 { TARGET_NR_execve, "execve" , NULL, print_execve, NULL },
@@ -140,7 +145,7 @@
 { TARGET_NR_exit_group, "exit_group" , "%s(%d)\n", NULL, NULL },
 #endif
 #ifdef TARGET_NR_faccessat
-{ TARGET_NR_faccessat, "faccessat" , "%s(%d,\"%s\",%#o,%#x)", NULL, NULL },
+{ TARGET_NR_faccessat, "faccessat" , NULL, print_faccessat, NULL },
 #endif
 #ifdef TARGET_NR_fadvise64
 { TARGET_NR_fadvise64, "fadvise64" , NULL, NULL, NULL },
@@ -155,22 +160,22 @@
 { TARGET_NR_fchmod, "fchmod" , "%s(%d,%#o)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_fchmodat
-{ TARGET_NR_fchmodat, "fchmodat" , "%s(%d,\"%s\",%#o,%#x)", NULL, NULL },
+{ TARGET_NR_fchmodat, "fchmodat" , NULL, print_fchmodat, NULL },
 #endif
 #ifdef TARGET_NR_fchown
-{ TARGET_NR_fchown, "fchown" , "%s(\"%s\",%d,%d)", NULL, NULL },
+{ TARGET_NR_fchown, "fchown" , "%s(%d,%d,%d)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_fchown32
 { TARGET_NR_fchown32, "fchown32" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_fchownat
-{ TARGET_NR_fchownat, "fchownat" , "%s(%d,\"%s\",%d,%d,%#x)", NULL, NULL },
+{ TARGET_NR_fchownat, "fchownat" , NULL, print_fchownat, NULL },
 #endif
 #ifdef TARGET_NR_fcntl
-{ TARGET_NR_fcntl, "fcntl" , NULL, NULL, NULL },
+{ TARGET_NR_fcntl, "fcntl" , NULL, print_fcntl, NULL },
 #endif
 #ifdef TARGET_NR_fcntl64
-{ TARGET_NR_fcntl64, "fcntl64" , NULL, NULL, NULL },
+{ TARGET_NR_fcntl64, "fcntl64" , NULL, print_fcntl64, NULL },
 #endif
 #ifdef TARGET_NR_fdatasync
 { TARGET_NR_fdatasync, "fdatasync" , NULL, NULL, NULL },
@@ -194,10 +199,10 @@
 { TARGET_NR_fsetxattr, "fsetxattr" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_fstat
-{ TARGET_NR_fstat, "fstat" , "%s(%d,%p)", NULL, NULL },
+{ TARGET_NR_fstat, "fstat" , NULL, print_fstat, NULL },
 #endif
 #ifdef TARGET_NR_fstat64
-{ TARGET_NR_fstat64, "fstat64" , "%s(%d,%p)", NULL, NULL },
+{ TARGET_NR_fstat64, "fstat64" , NULL, print_fstat64, NULL },
 #endif
 #ifdef TARGET_NR_fstatfs
 { TARGET_NR_fstatfs, "fstatfs" , "%s(%d,%p)", NULL, NULL },
@@ -218,10 +223,10 @@
 { TARGET_NR_ftruncate64, "ftruncate64" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_futex
-{ TARGET_NR_futex, "futex" , NULL, NULL, NULL },
+{ TARGET_NR_futex, "futex" , NULL, print_futex, NULL },
 #endif
 #ifdef TARGET_NR_futimesat
-{ TARGET_NR_futimesat, "futimesat" , "%s(%d,\"%s\",%p)", NULL, NULL },
+{ TARGET_NR_futimesat, "futimesat" , NULL, print_futimesat, NULL },
 #endif
 #ifdef TARGET_NR_getcwd
 { TARGET_NR_getcwd, "getcwd" , "%s(%p,%d)", NULL, NULL },
@@ -425,10 +430,10 @@
 { TARGET_NR_lgetxattr, "lgetxattr" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_link
-{ TARGET_NR_link, "link" , "%s(\"%s\",\"%s\")", NULL, NULL },
+{ TARGET_NR_link, "link" , NULL, print_link, NULL },
 #endif
 #ifdef TARGET_NR_linkat
-{ TARGET_NR_linkat, "linkat" , "%s(%d,\"%s\",%d,\"%s\",%#x)", NULL, NULL },
+{ TARGET_NR_linkat, "linkat" , NULL, print_linkat, NULL },
 #endif
 #ifdef TARGET_NR_Linux
 { TARGET_NR_Linux, "Linux" , NULL, NULL, NULL },
@@ -461,10 +466,10 @@
 { TARGET_NR_lsetxattr, "lsetxattr" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_lstat
-{ TARGET_NR_lstat, "lstat" , "%s(\"%s\",%p)", NULL, NULL },
+{ TARGET_NR_lstat, "lstat" , NULL, print_lstat, NULL },
 #endif
 #ifdef TARGET_NR_lstat64
-{ TARGET_NR_lstat64, "lstat64" , "%s(\"%s\",%p)", NULL, NULL },
+{ TARGET_NR_lstat64, "lstat64" , NULL, print_lstat64, NULL },
 #endif
 #ifdef TARGET_NR_madvise
 { TARGET_NR_madvise, "madvise" , NULL, NULL, NULL },
@@ -485,16 +490,16 @@
 { TARGET_NR_mincore, "mincore" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_mkdir
-{ TARGET_NR_mkdir, "mkdir" , "%s(\"%s\",%#o)", NULL, NULL },
+{ TARGET_NR_mkdir, "mkdir" , NULL, print_mkdir, NULL },
 #endif
 #ifdef TARGET_NR_mkdirat
-{ TARGET_NR_mkdirat, "mkdirat" , "%s(%d,\"%s\",%#o)", NULL, NULL },
+{ TARGET_NR_mkdirat, "mkdirat" , NULL, print_mkdirat, NULL },
 #endif
 #ifdef TARGET_NR_mknod
-{ TARGET_NR_mknod, "mknod" , "%s(\"%s\",%#o,%#x)", NULL, NULL },
+{ TARGET_NR_mknod, "mknod" , NULL, print_mknod, NULL },
 #endif
 #ifdef TARGET_NR_mknodat
-{ TARGET_NR_mknodat, "mknodat" , "%s(%d,\"%s\",%#o,%#x)", NULL, NULL },
+{ TARGET_NR_mknodat, "mknodat" , NULL, print_mknodat, NULL },
 #endif
 #ifdef TARGET_NR_mlock
 { TARGET_NR_mlock, "mlock" , NULL, NULL, NULL },
@@ -503,22 +508,22 @@
 { TARGET_NR_mlockall, "mlockall" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_mmap
-{ TARGET_NR_mmap, "mmap" , NULL, NULL, print_syscall_ret_addr },
+{ TARGET_NR_mmap, "mmap" , NULL, print_mmap, print_syscall_ret_addr },
 #endif
 #ifdef TARGET_NR_mmap2
-{ TARGET_NR_mmap2, "mmap2" , NULL, NULL, print_syscall_ret_addr },
+{ TARGET_NR_mmap2, "mmap2" , NULL, print_mmap2, print_syscall_ret_addr },
 #endif
 #ifdef TARGET_NR_modify_ldt
 { TARGET_NR_modify_ldt, "modify_ldt" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_mount
-{ TARGET_NR_mount, "mount" , NULL, NULL, NULL },
+{ TARGET_NR_mount, "mount" , NULL, print_mount, NULL },
 #endif
 #ifdef TARGET_NR_move_pages
 { TARGET_NR_move_pages, "move_pages" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_mprotect
-{ TARGET_NR_mprotect, "mprotect" , NULL, NULL, NULL },
+{ TARGET_NR_mprotect, "mprotect" , NULL, print_mprotect, NULL },
 #endif
 #ifdef TARGET_NR_mpx
 { TARGET_NR_mpx, "mpx" , NULL, NULL, NULL },
@@ -530,7 +535,7 @@
 { TARGET_NR_mq_notify, "mq_notify" , "%s(%d,%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_mq_open
-{ TARGET_NR_mq_open, "mq_open" , "%s(\"/%s\",%#x,%#o,%p)", NULL, NULL },
+{ TARGET_NR_mq_open, "mq_open" , NULL, print_mq_open, NULL },
 #endif
 #ifdef TARGET_NR_mq_timedreceive
 { TARGET_NR_mq_timedreceive, "mq_timedreceive" , "%s(%d,%p,%d,%u,%p)", NULL, NULL },
@@ -539,7 +544,7 @@
 { TARGET_NR_mq_timedsend, "mq_timedsend" , "%s(%d,%p,%d,%u,%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_mq_unlink
-{ TARGET_NR_mq_unlink, "mq_unlink" , "%s(%s)", NULL, NULL },
+{ TARGET_NR_mq_unlink, "mq_unlink" , NULL, print_mq_unlink, NULL },
 #endif
 #ifdef TARGET_NR_mremap
 { TARGET_NR_mremap, "mremap" , NULL, NULL, NULL },
@@ -569,16 +574,16 @@
 { TARGET_NR_munlockall, "munlockall" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_munmap
-{ TARGET_NR_munmap, "munmap" , "%s(%p,%d)", NULL, NULL },
+{ TARGET_NR_munmap, "munmap" , NULL, print_munmap, NULL },
 #endif
 #ifdef TARGET_NR_nanosleep
 { TARGET_NR_nanosleep, "nanosleep" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_fstatat64
-{ TARGET_NR_fstatat64, "fstatat64" , "%s(%d,\"%s\",%p,%#x)", NULL, NULL },
+{ TARGET_NR_fstatat64, "fstatat64" , NULL, print_fstatat64, NULL },
 #endif
 #ifdef TARGET_NR_newfstatat
-{ TARGET_NR_newfstatat, "newfstatat" , "%s(%d,\"%s\",%p,%#x)", NULL, NULL },
+{ TARGET_NR_newfstatat, "newfstatat" , NULL, print_newfstatat, NULL },
 #endif
 #ifdef TARGET_NR__newselect
 { TARGET_NR__newselect, "_newselect" , NULL, print_newselect, print_syscall_ret_newselect },
@@ -611,10 +616,10 @@
 { TARGET_NR_olduname, "olduname" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_open
-{ TARGET_NR_open, "open" , "%s(\"%s\",%#x,%#o)", NULL, NULL },
+{ TARGET_NR_open, "open" , NULL, print_open, NULL },
 #endif
 #ifdef TARGET_NR_openat
-{ TARGET_NR_openat, "openat" , "%s(%d,\"%s\",%#x,%#o)", NULL, NULL },
+{ TARGET_NR_openat, "openat" , NULL, print_openat, NULL },
 #endif
 #ifdef TARGET_NR_osf_adjtime
 { TARGET_NR_osf_adjtime, "osf_adjtime" , NULL, NULL, NULL },
@@ -1007,10 +1012,10 @@
 { TARGET_NR_readdir, "readdir" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_readlink
-{ TARGET_NR_readlink, "readlink" , "%s(\"%s\",%p,%d)", NULL, NULL },
+{ TARGET_NR_readlink, "readlink" , NULL, print_readlink, NULL },
 #endif
 #ifdef TARGET_NR_readlinkat
-{ TARGET_NR_readlinkat, "readlinkat" , "%s(%d,\"%s\",%p,%d)", NULL, NULL },
+{ TARGET_NR_readlinkat, "readlinkat" , NULL, print_readlinkat, NULL },
 #endif
 #ifdef TARGET_NR_readv
 { TARGET_NR_readv, "readv" , NULL, NULL, NULL },
@@ -1034,10 +1039,10 @@
 { TARGET_NR_removexattr, "removexattr" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_rename
-{ TARGET_NR_rename, "rename" , "%s(\"%s\",\"%s\")", NULL, NULL },
+{ TARGET_NR_rename, "rename" , NULL, print_rename, NULL },
 #endif
 #ifdef TARGET_NR_renameat
-{ TARGET_NR_renameat, "renameat" , "%s(%d,\"%s\",%d,\"%s\")", NULL, NULL },
+{ TARGET_NR_renameat, "renameat" , NULL, print_renameat, NULL },
 #endif
 #ifdef TARGET_NR_request_key
 { TARGET_NR_request_key, "request_key" , NULL, NULL, NULL },
@@ -1301,16 +1306,16 @@
 { TARGET_NR_ssetmask, "ssetmask" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_stat
-{ TARGET_NR_stat, "stat" , "%s(\"%s\",%p)", NULL, NULL },
+{ TARGET_NR_stat, "stat" , NULL, print_stat, NULL },
 #endif
 #ifdef TARGET_NR_stat64
-{ TARGET_NR_stat64, "stat64" , "%s(\"%s\",%p)", NULL, NULL },
+{ TARGET_NR_stat64, "stat64" , NULL, print_stat64, NULL },
 #endif
 #ifdef TARGET_NR_statfs
-{ TARGET_NR_statfs, "statfs" , "%s(\"%s\",%p)", NULL, NULL },
+{ TARGET_NR_statfs, "statfs" , NULL, print_statfs, NULL },
 #endif
 #ifdef TARGET_NR_statfs64
-{ TARGET_NR_statfs64, "statfs64" , "%s(\"%s\",%p)", NULL, NULL },
+{ TARGET_NR_statfs64, "statfs64" , NULL, print_statfs64, NULL },
 #endif
 #ifdef TARGET_NR_stime
 { TARGET_NR_stime, "stime" , NULL, NULL, NULL },
@@ -1334,10 +1339,10 @@
 { TARGET_NR_swapon, "swapon" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_symlink
-{ TARGET_NR_symlink, "symlink" , "%s(\"%s\",\"%s\")", NULL, NULL },
+{ TARGET_NR_symlink, "symlink" , NULL, print_symlink, NULL },
 #endif
 #ifdef TARGET_NR_symlinkat
-{ TARGET_NR_symlinkat, "symlinkat" , "%s(\"%s\",%d,\"%s\")", NULL, NULL },
+{ TARGET_NR_symlinkat, "symlinkat", NULL, print_symlinkat, NULL },
 #endif
 #ifdef TARGET_NR_sync
 { TARGET_NR_sync, "sync" , NULL, NULL, NULL },
@@ -1427,19 +1432,19 @@
 { TARGET_NR_umask, "umask" , "%s(%#o)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_umount
-{ TARGET_NR_umount, "umount" , "%s(\"%s\",\"%s\",\"%s\",%#x,%p)", NULL, NULL },
+{ TARGET_NR_umount, "umount" , NULL, print_umount, NULL },
 #endif
 #ifdef TARGET_NR_umount2
-{ TARGET_NR_umount2, "umount2" , NULL, NULL, NULL },
+{ TARGET_NR_umount2, "umount2" , NULL, print_umount2, NULL },
 #endif
 #ifdef TARGET_NR_uname
 { TARGET_NR_uname, "uname" , "%s(%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_unlink
-{ TARGET_NR_unlink, "unlink" , "%s(\"%s\")", NULL, NULL },
+{ TARGET_NR_unlink, "unlink" , NULL, print_unlink, NULL },
 #endif
 #ifdef TARGET_NR_unlinkat
-{ TARGET_NR_unlinkat, "unlinkat" , "%s(%d,\"%s\",%#x)", NULL, NULL },
+{ TARGET_NR_unlinkat, "unlinkat" , NULL, print_unlinkat, NULL },
 #endif
 #ifdef TARGET_NR_unshare
 { TARGET_NR_unshare, "unshare" , NULL, NULL, NULL },
@@ -1469,10 +1474,10 @@
 { TARGET_NR_ustat, "ustat" , "%s(%#x,%p)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_utime
-{ TARGET_NR_utime, "utime" , "%s(\"%s\",%p)", NULL, NULL },
+{ TARGET_NR_utime, "utime" , NULL, print_utime, NULL },
 #endif
 #ifdef TARGET_NR_utimes
-{ TARGET_NR_utimes, "utimes" , NULL, NULL, NULL },
+{ TARGET_NR_utimes, "utimes" , NULL, print_utimes, NULL },
 #endif
 #ifdef TARGET_NR_utrap_install
 { TARGET_NR_utrap_install, "utrap_install" , NULL, NULL, NULL },
@@ -1511,5 +1516,5 @@
 { TARGET_NR_writev, "writev" , "%s(%d,%p,%#x)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_utimensat
-{ TARGET_NR_utimensat, "utimensat", "%s(%d,\"%s\",%p,%#x)", NULL, NULL },
+{ TARGET_NR_utimensat, "utimensat", NULL, print_utimensat, NULL },
 #endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 56f2a3f..056581d 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -93,12 +93,6 @@
 
 //#define DEBUG
 
-#if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC) \
-    || defined(TARGET_M68K) || defined(TARGET_SH4) || defined(TARGET_CRIS)
-/* 16 bit uid wrappers emulation */
-#define USE_UID16
-#endif
-
 //#include <linux/msdos_fs.h>
 #define	VFAT_IOCTL_READDIR_BOTH		_IOR('r', 1, struct linux_dirent [2])
 #define	VFAT_IOCTL_READDIR_SHORT	_IOR('r', 2, struct linux_dirent [2])
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index e2ba0bb..b79d2df 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -48,6 +48,12 @@
 #define TARGET_IOC_NRBITS	8
 #define TARGET_IOC_TYPEBITS	8
 
+#if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC) \
+    || defined(TARGET_M68K) || defined(TARGET_SH4) || defined(TARGET_CRIS)
+    /* 16 bit uid wrappers emulation */
+#define USE_UID16
+#endif
+
 #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SH4) \
     || defined(TARGET_M68K) || defined(TARGET_CRIS)
 
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 06/21] Revived GUEST_BASE support for usermode emulation targets [v5]
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (4 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 05/21] linux-user: strace now handles guest strings correctly [v2] riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-14 15:28   ` Blue Swirl
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 07/21] linux-user: fix utimensat riku.voipio
                   ` (15 subsequent siblings)
  21 siblings, 1 reply; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Mika Westerberg <mika.westerberg@iki.fi>

From: Mika Westerberg <mika.westerberg@iki.fi>

- Now GUEST_BASE is dynamic and can be set from command line.
- Qemu checks /proc/sys/vm/mmap_min_addr and sets GUEST_BASE
  if needed.
- Code generation supports GUEST_BASE for i386 and x86_64 hosts.

[v3]: implemented GUEST_BASE with offset mods

Using malc's advice, instead of a mov or lea, just adjust
the offset parameter of tcg_out_modrm_offset(). - Riku

[v5]: set a GUEST_BASE_MAX instead of supporting moving
to arbitary ranges

From: Mika Westerberg <mika.westerberg@iki.fi>
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 configure               |    9 +++++++
 cpu-all.h               |    7 ++++-
 linux-user/elfload.c    |   24 +++++++++++++++++++
 linux-user/main.c       |   59 +++++++++++++++++++++++++++++++++++++++++++++++
 linux-user/qemu.h       |    3 ++
 tcg/i386/tcg-target.c   |   36 ++++++++++++++++------------
 tcg/x86_64/tcg-target.c |   30 +++++++++++++----------
 7 files changed, 138 insertions(+), 30 deletions(-)

diff --git a/configure b/configure
index 89e7f53..11501c6 100755
--- a/configure
+++ b/configure
@@ -181,6 +181,7 @@ linux_user="no"
 darwin_user="no"
 bsd_user="no"
 build_docs="yes"
+guest_base="no"
 uname_release=""
 curses="yes"
 curl="yes"
@@ -465,6 +466,8 @@ for opt do
   ;;
   --enable-bsd-user) bsd_user="yes"
   ;;
+  --enable-guest-base) guest_base="yes"
+  ;;
   --enable-uname-release=*) uname_release="$optarg"
   ;;
   --sparc_cpu=*)
@@ -628,6 +631,8 @@ echo "  --enable-darwin-user     enable all darwin usermode emulation targets"
 echo "  --disable-darwin-user    disable all darwin usermode emulation targets"
 echo "  --enable-bsd-user        enable all BSD usermode emulation targets"
 echo "  --disable-bsd-user       disable all BSD usermode emulation targets"
+echo "  --enable-guest-base      enable GUEST_BASE support for usermode"
+echo "                           emulation targets"
 echo "  --fmod-lib               path to FMOD library"
 echo "  --fmod-inc               path to FMOD includes"
 echo "  --oss-lib                path to OSS library"
@@ -1375,6 +1380,7 @@ echo "Documentation     $build_docs"
 [ ! -z "$uname_release" ] && \
 echo "uname -r          $uname_release"
 echo "NPTL support      $nptl"
+echo "GUEST_BASE        $guest_base"
 echo "vde support       $vde"
 echo "AIO support       $aio"
 echo "IO thread         $io_thread"
@@ -2127,6 +2133,9 @@ if test "$target_user_only" = "yes" -a "$elfload32" = "yes"; then
   echo "TARGET_HAS_ELFLOAD32=yes" >> $config_mak
   echo "#define TARGET_HAS_ELFLOAD32 1" >> $config_h
 fi
+if test "$target_user_only" = "yes" -a "$guest_base" = "yes"; then
+  echo "#define CONFIG_USE_GUEST_BASE 1" >> $config_h
+fi
 if test "$target_bsd_user" = "yes" ; then
   echo "CONFIG_BSD_USER=yes" >> $config_mak
   echo "#define CONFIG_BSD_USER 1" >> $config_h
diff --git a/cpu-all.h b/cpu-all.h
index 8f078c4..d8603ae 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -625,8 +625,13 @@ static inline void stfq_be_p(void *ptr, float64 v)
 /* On some host systems the guest address space is reserved on the host.
  * This allows the guest address space to be offset to a convenient location.
  */
-//#define GUEST_BASE 0x20000000
+#if defined(CONFIG_USE_GUEST_BASE)
+#define GUEST_BASE_MAX 0x38000000
+extern unsigned long guest_base;
+#define GUEST_BASE guest_base
+#else
 #define GUEST_BASE 0
+#endif
 
 /* All direct uses of g2h and h2g need to go away for usermode softmmu.  */
 #define g2h(x) ((void *)((unsigned long)(x) + GUEST_BASE))
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 1839337..1a22042 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1545,6 +1545,30 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
     info->mmap = 0;
     elf_entry = (abi_ulong) elf_ex.e_entry;
 
+#if defined(CONFIG_USE_GUEST_BASE)
+    /*
+     * In case where user has not explicitly set the guest_base, we
+     * probe here that should we set it automatically.
+     */
+    if (guest_base == 0) {
+        /*
+         * Go through ELF program header table and find out whether
+	 * any of the segments drop below our current mmap_min_addr and
+         * in that case set guest_base to corresponding address.
+         */
+        for (i = 0, elf_ppnt = elf_phdata; i < elf_ex.e_phnum;
+            i++, elf_ppnt++) {
+            if (elf_ppnt->p_type != PT_LOAD)
+                continue;
+            if (HOST_PAGE_ALIGN(elf_ppnt->p_vaddr) < mmap_min_addr) {
+                guest_base = HOST_PAGE_ALIGN(mmap_min_addr);
+                qemu_log("setting guest_base=0x%lx\n", guest_base);
+                break;
+            }
+        }
+    }
+#endif /* CONFIG_USE_GUEST_BASE */
+
     /* Do this so that we can load the interpreter, if need be.  We will
        change some of these later */
     info->rss = 0;
diff --git a/linux-user/main.c b/linux-user/main.c
index 7eabd0c..0395549 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -41,6 +41,10 @@
 char *exec_path;
 
 int singlestep;
+#if defined(CONFIG_USE_GUEST_BASE)
+unsigned long mmap_min_addr = 0;
+unsigned long guest_base = 0;
+#endif
 
 static const char *interp_prefix = CONFIG_QEMU_PREFIX;
 const char *qemu_uname_release = CONFIG_UNAME_RELEASE;
@@ -2294,6 +2298,9 @@ static void usage(void)
            "-E var=value      sets/modifies targets environment variable(s)\n"
            "-U var            unsets targets environment variable(s)\n"
            "-0 argv0          forces target process argv[0] to be argv0\n"
+#if defined(CONFIG_USE_GUEST_BASE)
+           "-B address        set guest_base address to address\n"
+#endif
            "\n"
            "Debug options:\n"
            "-d options   activate log (logfile=%s)\n"
@@ -2468,6 +2475,10 @@ int main(int argc, char **argv, char **envp)
 #endif
                 exit(1);
             }
+#if defined(CONFIG_USE_GUEST_BASE)
+        } else if (!strcmp(r, "B")) {
+           guest_base = strtol(argv[optind++], NULL, 0);
+#endif
         } else if (!strcmp(r, "drop-ld-preload")) {
             (void) envlist_unsetenv(envlist, "LD_PRELOAD");
         } else if (!strcmp(r, "singlestep")) {
@@ -2545,6 +2556,41 @@ int main(int argc, char **argv, char **envp)
     target_environ = envlist_to_environ(envlist, NULL);
     envlist_free(envlist);
 
+#if defined(CONFIG_USE_GUEST_BASE)
+    /*
+     * Now that page sizes are configured in cpu_init() we can do
+     * proper page alignment for guest_base.
+     */
+    guest_base = HOST_PAGE_ALIGN(guest_base);
+
+    /*
+     * Read in mmap_min_addr kernel parameter and check
+     * whether it is set to some value > 0.  This value is used
+     * later on when doing mmap(2)s to calculate where guest_base
+     * is to set, if needed.
+     *
+     * When user has explicitly set the quest base, we skip this
+     * test.
+     */
+    if (guest_base == 0) {
+        FILE *fp;
+
+        if ((fp = fopen("/proc/sys/vm/mmap_min_addr", "r")) != NULL) {
+            unsigned long tmp;
+            if (fscanf(fp, "%lu", &tmp) == 1) {
+                mmap_min_addr = tmp;
+                qemu_log("kernel mmap_min_addr=%lu\n", mmap_min_addr);
+            }
+            fclose(fp);
+        }
+    }
+    if (guest_base >= GUEST_BASE_MAX) {
+        fprintf(stderr, "guest base %lu is larger than GUEST_BASE_MAX: %d \n",
+                guest_base, GUEST_BASE_MAX);
+        exit(1);
+    }
+#endif /* CONFIG_USE_GUEST_BASE */
+
     /*
      * Prepare copy of argv vector for target.
      */
@@ -2594,6 +2640,19 @@ int main(int argc, char **argv, char **envp)
     free(target_environ);
 
     if (qemu_log_enabled()) {
+#if defined(CONFIG_USE_GUEST_BASE)
+        if (guest_base > 0) {
+            qemu_log("guest_base is set to 0x%lx\n", guest_base);
+            qemu_log(
+                "==========================================================\n"
+                "Note that all target addresses below are given in target\n"
+                "address space which is different from host by guest_base.\n"
+                "For example: target address 0x" TARGET_ABI_FMT_lx " becomes\n"
+		"%p and so on.\n"
+                "==========================================================\n",
+                (abi_ulong)0x8000, g2h(0x8000));
+        }
+#endif
         log_page_dump();
 
         qemu_log("start_brk   0x" TARGET_ABI_FMT_lx "\n", info->start_brk);
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index e04a31c..4028953 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -133,6 +133,9 @@ void init_task_state(TaskState *ts);
 void task_settid(TaskState *);
 void stop_all_tasks(void);
 extern const char *qemu_uname_release;
+#if defined(CONFIG_USE_GUEST_BASE)
+extern unsigned long mmap_min_addr;
+#endif
 
 /* ??? See if we can avoid exposing so much of the loader internals.  */
 /*
diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c
index e0fd434..aaec3c7 100644
--- a/tcg/i386/tcg-target.c
+++ b/tcg/i386/tcg-target.c
@@ -22,6 +22,10 @@
  * THE SOFTWARE.
  */
 
+#ifndef CONFIG_USE_GUEST_BASE
+#define GUEST_BASE 0
+#endif
+
 #ifndef NDEBUG
 static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
     "%eax",
@@ -572,15 +576,15 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
     switch(opc) {
     case 0:
         /* movzbl */
-        tcg_out_modrm_offset(s, 0xb6 | P_EXT, data_reg, r0, 0);
+        tcg_out_modrm_offset(s, 0xb6 | P_EXT, data_reg, r0, GUEST_BASE);
         break;
     case 0 | 4:
         /* movsbl */
-        tcg_out_modrm_offset(s, 0xbe | P_EXT, data_reg, r0, 0);
+        tcg_out_modrm_offset(s, 0xbe | P_EXT, data_reg, r0, GUEST_BASE);
         break;
     case 1:
         /* movzwl */
-        tcg_out_modrm_offset(s, 0xb7 | P_EXT, data_reg, r0, 0);
+        tcg_out_modrm_offset(s, 0xb7 | P_EXT, data_reg, r0, GUEST_BASE);
         if (bswap) {
             /* rolw $8, data_reg */
             tcg_out8(s, 0x66); 
@@ -590,7 +594,7 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
         break;
     case 1 | 4:
         /* movswl */
-        tcg_out_modrm_offset(s, 0xbf | P_EXT, data_reg, r0, 0);
+        tcg_out_modrm_offset(s, 0xbf | P_EXT, data_reg, r0, GUEST_BASE);
         if (bswap) {
             /* rolw $8, data_reg */
             tcg_out8(s, 0x66); 
@@ -603,7 +607,7 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
         break;
     case 2:
         /* movl (r0), data_reg */
-        tcg_out_modrm_offset(s, 0x8b, data_reg, r0, 0);
+        tcg_out_modrm_offset(s, 0x8b, data_reg, r0, GUEST_BASE);
         if (bswap) {
             /* bswap */
             tcg_out_opc(s, (0xc8 + data_reg) | P_EXT);
@@ -619,13 +623,13 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
             r0 = r1;
         }
         if (!bswap) {
-            tcg_out_modrm_offset(s, 0x8b, data_reg, r0, 0);
-            tcg_out_modrm_offset(s, 0x8b, data_reg2, r0, 4);
+            tcg_out_modrm_offset(s, 0x8b, data_reg, r0, GUEST_BASE);
+            tcg_out_modrm_offset(s, 0x8b, data_reg2, r0, GUEST_BASE + 4);
         } else {
-            tcg_out_modrm_offset(s, 0x8b, data_reg, r0, 4);
+            tcg_out_modrm_offset(s, 0x8b, data_reg, r0, GUEST_BASE + 4);
             tcg_out_opc(s, (0xc8 + data_reg) | P_EXT);
 
-            tcg_out_modrm_offset(s, 0x8b, data_reg2, r0, 0);
+            tcg_out_modrm_offset(s, 0x8b, data_reg2, r0, GUEST_BASE);
             /* bswap */
             tcg_out_opc(s, (0xc8 + data_reg2) | P_EXT);
         }
@@ -806,7 +810,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
     switch(opc) {
     case 0:
         /* movb */
-        tcg_out_modrm_offset(s, 0x88, data_reg, r0, 0);
+        tcg_out_modrm_offset(s, 0x88, data_reg, r0, GUEST_BASE);
         break;
     case 1:
         if (bswap) {
@@ -818,7 +822,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
         }
         /* movw */
         tcg_out8(s, 0x66);
-        tcg_out_modrm_offset(s, 0x89, data_reg, r0, 0);
+        tcg_out_modrm_offset(s, 0x89, data_reg, r0, GUEST_BASE);
         break;
     case 2:
         if (bswap) {
@@ -828,21 +832,21 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
             data_reg = r1;
         }
         /* movl */
-        tcg_out_modrm_offset(s, 0x89, data_reg, r0, 0);
+        tcg_out_modrm_offset(s, 0x89, data_reg, r0, GUEST_BASE);
         break;
     case 3:
         if (bswap) {
             tcg_out_mov(s, r1, data_reg2);
             /* bswap data_reg */
             tcg_out_opc(s, (0xc8 + r1) | P_EXT);
-            tcg_out_modrm_offset(s, 0x89, r1, r0, 0);
+            tcg_out_modrm_offset(s, 0x89, r1, r0, GUEST_BASE);
             tcg_out_mov(s, r1, data_reg);
             /* bswap data_reg */
             tcg_out_opc(s, (0xc8 + r1) | P_EXT);
-            tcg_out_modrm_offset(s, 0x89, r1, r0, 4);
+            tcg_out_modrm_offset(s, 0x89, r1, r0, GUEST_BASE + 4);
         } else {
-            tcg_out_modrm_offset(s, 0x89, data_reg, r0, 0);
-            tcg_out_modrm_offset(s, 0x89, data_reg2, r0, 4);
+            tcg_out_modrm_offset(s, 0x89, data_reg, r0, GUEST_BASE);
+            tcg_out_modrm_offset(s, 0x89, data_reg2, r0, GUEST_BASE + 4);
         }
         break;
     default:
diff --git a/tcg/x86_64/tcg-target.c b/tcg/x86_64/tcg-target.c
index 5378e85..6015bb5 100644
--- a/tcg/x86_64/tcg-target.c
+++ b/tcg/x86_64/tcg-target.c
@@ -22,6 +22,10 @@
  * THE SOFTWARE.
  */
 
+#ifndef CONFIG_USE_GUEST_BASE
+#define GUEST_BASE 0
+#endif
+
 #ifndef NDEBUG
 static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
     "%rax",
@@ -616,15 +620,15 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
     switch(opc) {
     case 0:
         /* movzbl */
-        tcg_out_modrm_offset(s, 0xb6 | P_EXT, data_reg, r0, 0);
+        tcg_out_modrm_offset(s, 0xb6 | P_EXT, data_reg, r0, GUEST_BASE);
         break;
     case 0 | 4:
         /* movsbX */
-        tcg_out_modrm_offset(s, 0xbe | P_EXT | rexw, data_reg, r0, 0);
+        tcg_out_modrm_offset(s, 0xbe | P_EXT | rexw, data_reg, r0, GUEST_BASE);
         break;
     case 1:
         /* movzwl */
-        tcg_out_modrm_offset(s, 0xb7 | P_EXT, data_reg, r0, 0);
+        tcg_out_modrm_offset(s, 0xb7 | P_EXT, data_reg, r0, GUEST_BASE);
         if (bswap) {
             /* rolw $8, data_reg */
             tcg_out8(s, 0x66); 
@@ -635,7 +639,7 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
     case 1 | 4:
         if (bswap) {
             /* movzwl */
-            tcg_out_modrm_offset(s, 0xb7 | P_EXT, data_reg, r0, 0);
+            tcg_out_modrm_offset(s, 0xb7 | P_EXT, data_reg, r0, GUEST_BASE);
             /* rolw $8, data_reg */
             tcg_out8(s, 0x66); 
             tcg_out_modrm(s, 0xc1, 0, data_reg);
@@ -645,12 +649,12 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
             tcg_out_modrm(s, 0xbf | P_EXT | rexw, data_reg, data_reg);
         } else {
             /* movswX */
-            tcg_out_modrm_offset(s, 0xbf | P_EXT | rexw, data_reg, r0, 0);
+            tcg_out_modrm_offset(s, 0xbf | P_EXT | rexw, data_reg, r0, GUEST_BASE);
         }
         break;
     case 2:
         /* movl (r0), data_reg */
-        tcg_out_modrm_offset(s, 0x8b, data_reg, r0, 0);
+        tcg_out_modrm_offset(s, 0x8b, data_reg, r0, GUEST_BASE);
         if (bswap) {
             /* bswap */
             tcg_out_opc(s, (0xc8 + (data_reg & 7)) | P_EXT, 0, data_reg, 0);
@@ -659,19 +663,19 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
     case 2 | 4:
         if (bswap) {
             /* movl (r0), data_reg */
-            tcg_out_modrm_offset(s, 0x8b, data_reg, r0, 0);
+            tcg_out_modrm_offset(s, 0x8b, data_reg, r0, GUEST_BASE);
             /* bswap */
             tcg_out_opc(s, (0xc8 + (data_reg & 7)) | P_EXT, 0, data_reg, 0);
             /* movslq */
             tcg_out_modrm(s, 0x63 | P_REXW, data_reg, data_reg);
         } else {
             /* movslq */
-            tcg_out_modrm_offset(s, 0x63 | P_REXW, data_reg, r0, 0);
+            tcg_out_modrm_offset(s, 0x63 | P_REXW, data_reg, r0, GUEST_BASE);
         }
         break;
     case 3:
         /* movq (r0), data_reg */
-        tcg_out_modrm_offset(s, 0x8b | P_REXW, data_reg, r0, 0);
+        tcg_out_modrm_offset(s, 0x8b | P_REXW, data_reg, r0, GUEST_BASE);
         if (bswap) {
             /* bswap */
             tcg_out_opc(s, (0xc8 + (data_reg & 7)) | P_EXT | P_REXW, 0, data_reg, 0);
@@ -787,7 +791,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
     switch(opc) {
     case 0:
         /* movb */
-        tcg_out_modrm_offset(s, 0x88 | P_REXB, data_reg, r0, 0);
+        tcg_out_modrm_offset(s, 0x88 | P_REXB, data_reg, r0, GUEST_BASE);
         break;
     case 1:
         if (bswap) {
@@ -799,7 +803,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
         }
         /* movw */
         tcg_out8(s, 0x66);
-        tcg_out_modrm_offset(s, 0x89, data_reg, r0, 0);
+        tcg_out_modrm_offset(s, 0x89, data_reg, r0, GUEST_BASE);
         break;
     case 2:
         if (bswap) {
@@ -809,7 +813,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
             data_reg = r1;
         }
         /* movl */
-        tcg_out_modrm_offset(s, 0x89, data_reg, r0, 0);
+        tcg_out_modrm_offset(s, 0x89, data_reg, r0, GUEST_BASE);
         break;
     case 3:
         if (bswap) {
@@ -819,7 +823,7 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
             data_reg = r1;
         }
         /* movq */
-        tcg_out_modrm_offset(s, 0x89 | P_REXW, data_reg, r0, 0);
+        tcg_out_modrm_offset(s, 0x89 | P_REXW, data_reg, r0, GUEST_BASE);
         break;
     default:
         tcg_abort();
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 07/21] linux-user: fix utimensat
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (5 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 06/21] Revived GUEST_BASE support for usermode emulation targets [v5] riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 08/21] Fix struct termios host - target translation riku.voipio
                   ` (14 subsequent siblings)
  21 siblings, 0 replies; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Riku Voipio <riku.voipio@nokia.com>

The glibc function for utimensat glibc returns -EINVAL when the path is null
which is a different behaviour with the syscall.

path can be null because internally the glibc is using utimensat with
path null when implmenting futimens. If path is null, call futimes
instead.

don't try to copy timespec from user if is NULL.

Add configure check for older systems

Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 configure            |   22 ++++++++++++++++++++++
 linux-user/syscall.c |   38 ++++++++++++++++++++++++--------------
 2 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/configure b/configure
index 11501c6..ecea67c 100755
--- a/configure
+++ b/configure
@@ -1281,6 +1281,25 @@ EOF
   fi
 fi
 
+# check if utimensat and futimens are supported
+utimens=no
+cat > $TMPC << EOF
+#define _ATFILE_SOURCE
+#define _GNU_SOURCE
+#include <stddef.h>
+#include <fcntl.h>
+
+int main(void)
+{
+    utimensat(AT_FDCWD, "foo", NULL, 0);
+    futimens(0, NULL);
+    return 0;
+}
+EOF
+if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
+  utimens=yes
+fi
+
 # Check if tools are available to build documentation.
 if test "$build_docs" = "yes" -a \( ! -x "`which texi2html 2>/dev/null`" -o ! -x "`which pod2man 2>/dev/null`" \) ; then
   build_docs="no"
@@ -1679,6 +1698,9 @@ fi
 if test "$atfile" = "yes" ; then
   echo "#define CONFIG_ATFILE 1" >> $config_h
 fi
+if test "$utimens" = "yes" ; then
+  echo "#define CONFIG_UTIMENSAT 1" >> $config_h
+fi
 if test "$inotify" = "yes" ; then
   echo "#define CONFIG_INOTIFY 1" >> $config_h
 fi
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 056581d..9e4e061 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -406,13 +406,6 @@ static int sys_unlinkat(int dirfd, const char *pathname, int flags)
   return (unlinkat(dirfd, pathname, flags));
 }
 #endif
-#ifdef TARGET_NR_utimensat
-static int sys_utimensat(int dirfd, const char *pathname,
-    const struct timespec times[2], int flags)
-{
-  return (utimensat(dirfd, pathname, times, flags));
-}
-#endif
 #else /* !CONFIG_ATFILE */
 
 /*
@@ -471,12 +464,24 @@ _syscall3(int,sys_symlinkat,const char *,oldpath,
 #if defined(TARGET_NR_unlinkat) && defined(__NR_unlinkat)
 _syscall3(int,sys_unlinkat,int,dirfd,const char *,pathname,int,flags)
 #endif
+
+#endif /* CONFIG_ATFILE */
+
+#ifdef CONFIG_UTIMENSAT
+static int sys_utimensat(int dirfd, const char *pathname,
+    const struct timespec times[2], int flags)
+{
+    if (pathname == NULL)
+        return futimens(dirfd, times);
+    else
+        return utimensat(dirfd, pathname, times, flags);
+}
+#else
 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
 _syscall4(int,sys_utimensat,int,dirfd,const char *,pathname,
           const struct timespec *,tsp,int,flags)
 #endif
-
-#endif /* CONFIG_ATFILE */
+#endif /* CONFIG_UTIMENSAT  */
 
 #ifdef CONFIG_INOTIFY
 #include <sys/inotify.h>
@@ -6669,17 +6674,22 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 #if defined(TARGET_NR_utimensat) && defined(__NR_utimensat)
     case TARGET_NR_utimensat:
         {
-            struct timespec ts[2];
-            target_to_host_timespec(ts, arg3);
-            target_to_host_timespec(ts+1, arg3+sizeof(struct target_timespec));
+            struct timespec *tsp, ts[2];
+            if (!arg3) {
+                tsp = NULL;
+            } else {
+                target_to_host_timespec(ts, arg3);
+                target_to_host_timespec(ts+1, arg3+sizeof(struct target_timespec));
+                tsp = ts;
+            }
             if (!arg2)
-                ret = get_errno(sys_utimensat(arg1, NULL, ts, arg4));
+                ret = get_errno(sys_utimensat(arg1, NULL, tsp, arg4));
             else {
                 if (!(p = lock_user_string(arg2))) {
                     ret = -TARGET_EFAULT;
                     goto fail;
                 }
-                ret = get_errno(sys_utimensat(arg1, path(p), ts, arg4));
+                ret = get_errno(sys_utimensat(arg1, path(p), tsp, arg4));
                 unlock_user(p, arg2, 0);
             }
         }
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 08/21] Fix struct termios host - target translation
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (6 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 07/21] linux-user: fix utimensat riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-14 15:22   ` Blue Swirl
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 09/21] Return EOPNOTSUPP instead of ENOSYS for *xattr* syscalls riku.voipio
                   ` (13 subsequent siblings)
  21 siblings, 1 reply; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Arnaud Patard <arnaud.patard@rtp-net.org>

When converting the termios structure between host and target in
target_to_host_termios and host_to_target_termios, the c_cc[] array is
never initialised.
Calling memset() before using it allows to run successfully "stty echo /
stty -echo" on arm-linux-user target (host being x86 and mips).

From: Arnaud Patard <arnaud.patard@rtp-net.org>
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 linux-user/syscall.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 9e4e061..8a95349 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2977,6 +2977,7 @@ static void target_to_host_termios (void *dst, const void *src)
         target_to_host_bitmask(tswap32(target->c_lflag), lflag_tbl);
     host->c_line = target->c_line;
 
+    memset(host->c_cc, 0, sizeof(host->c_cc));
     host->c_cc[VINTR] = target->c_cc[TARGET_VINTR];
     host->c_cc[VQUIT] = target->c_cc[TARGET_VQUIT];
     host->c_cc[VERASE] = target->c_cc[TARGET_VERASE];
@@ -3011,6 +3012,7 @@ static void host_to_target_termios (void *dst, const void *src)
         tswap32(host_to_target_bitmask(host->c_lflag, lflag_tbl));
     target->c_line = host->c_line;
 
+    memset(target->c_cc, 0, sizeof(target->c_cc));
     target->c_cc[TARGET_VINTR] = host->c_cc[VINTR];
     target->c_cc[TARGET_VQUIT] = host->c_cc[VQUIT];
     target->c_cc[TARGET_VERASE] = host->c_cc[VERASE];
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 09/21] Return EOPNOTSUPP instead of ENOSYS for *xattr* syscalls
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (7 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 08/21] Fix struct termios host - target translation riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 10/21] linux-user: Added IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP flags to setsockopt riku.voipio
                   ` (12 subsequent siblings)
  21 siblings, 0 replies; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Arnaud Patard <arnaud.patard@rtp-net.org>

In current code, we're sending ENOSYS to target when a syscall for the
xattrs is done. This makes applications like ls complain loudly about
that and breaks scripts parsing the output. Moreover, iirc, implemented
features of filesystems are are sending EOPNOTSUPP (I've not checked so
I may be a little bit wrong on that...).
So, I'm proposing to return -EOPNOTSUPP and make ls happy

From: Arnaud Patard <arnaud.patard@rtp-net.org>
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 linux-user/syscall.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8a95349..d1febff 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6579,7 +6579,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_removexattr:
     case TARGET_NR_lremovexattr:
     case TARGET_NR_fremovexattr:
-        goto unimplemented_nowarn;
+        ret = -TARGET_EOPNOTSUPP;
+        break;
 #endif
 #ifdef TARGET_NR_set_thread_area
     case TARGET_NR_set_thread_area:
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 10/21] linux-user: Added IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP flags to setsockopt
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (8 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 09/21] Return EOPNOTSUPP instead of ENOSYS for *xattr* syscalls riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 11/21] linux-user: Added IP_(UN)BLOCK_SOURCE/IP_(ADD|DROP)_SOURCE_MEMBERSHIP " riku.voipio
                   ` (11 subsequent siblings)
  21 siblings, 0 replies; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Lionel Landwerlin <lionel.landwerlin@openwide.fr>

linux-user: Added IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP flags to setsockopt

From: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
Signed-off-by: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 linux-user/syscall.c      |   30 ++++++++++++++++++++++++++++++
 linux-user/syscall_defs.h |   15 +++++++++++++++
 2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index d1febff..7648126 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -943,6 +943,24 @@ static abi_long do_select(int n,
     return ret;
 }
 
+static inline abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn,
+                                              abi_ulong target_addr,
+                                              socklen_t len)
+{
+    struct target_ip_mreqn *target_smreqn;
+
+    target_smreqn = lock_user(VERIFY_READ, target_addr, len, 1);
+    if (!target_smreqn)
+        return -TARGET_EFAULT;
+    mreqn->imr_multiaddr.s_addr = target_smreqn->imr_multiaddr.s_addr;
+    mreqn->imr_address.s_addr = target_smreqn->imr_address.s_addr;
+    if (len == sizeof(struct target_ip_mreqn))
+        mreqn->imr_ifindex = tswapl(target_smreqn->imr_ifindex);
+    unlock_user(target_smreqn, target_addr, 0);
+
+    return 0;
+}
+
 static inline abi_long target_to_host_sockaddr(struct sockaddr *addr,
                                                abi_ulong target_addr,
                                                socklen_t len)
@@ -1118,6 +1136,7 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
 {
     abi_long ret;
     int val;
+    struct ip_mreqn *ip_mreq;
 
     switch(level) {
     case SOL_TCP:
@@ -1156,6 +1175,17 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
             }
             ret = get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val)));
             break;
+        case IP_ADD_MEMBERSHIP:
+        case IP_DROP_MEMBERSHIP:
+            if (optlen < sizeof (struct target_ip_mreq) ||
+                optlen > sizeof (struct target_ip_mreqn))
+                return -TARGET_EINVAL;
+
+            ip_mreq = (struct ip_mreqn *) alloca(optlen);
+            target_to_host_ip_mreq(ip_mreq, optval_addr, optlen);
+            ret = get_errno(setsockopt(sockfd, level, optname, ip_mreq, optlen));
+            break;
+
         default:
             goto unimplemented;
         }
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index b79d2df..6e68c91 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -111,6 +111,21 @@ struct target_sockaddr {
     uint8_t sa_data[14];
 };
 
+struct target_in_addr {
+    uint32_t s_addr; /* big endian */
+};
+
+struct target_ip_mreq {
+    struct target_in_addr imr_multiaddr;
+    struct target_in_addr imr_address;
+};
+
+struct target_ip_mreqn {
+    struct target_in_addr imr_multiaddr;
+    struct target_in_addr imr_address;
+    abi_long imr_ifindex;
+};
+
 struct target_timeval {
     abi_long tv_sec;
     abi_long tv_usec;
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 11/21] linux-user: Added IP_(UN)BLOCK_SOURCE/IP_(ADD|DROP)_SOURCE_MEMBERSHIP flags to setsockopt
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (9 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 10/21] linux-user: Added IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP flags to setsockopt riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 12/21] linux-user: include linux/fs.h riku.voipio
                   ` (10 subsequent siblings)
  21 siblings, 0 replies; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Lionel Landwerlin <lionel.landwerlin@openwide.fr>

linux-user: Added IP_(UN)BLOCK_SOURCE/IP_(ADD|DROP)_SOURCE_MEMBERSHIP flags to setsockopt

From: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
Signed-off-by: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 linux-user/syscall.c      |   13 +++++++++++++
 linux-user/syscall_defs.h |    7 +++++++
 2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 7648126..674942c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1137,6 +1137,7 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
     abi_long ret;
     int val;
     struct ip_mreqn *ip_mreq;
+    struct ip_mreq_source *ip_mreq_source;
 
     switch(level) {
     case SOL_TCP:
@@ -1186,6 +1187,18 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
             ret = get_errno(setsockopt(sockfd, level, optname, ip_mreq, optlen));
             break;
 
+        case IP_BLOCK_SOURCE:
+        case IP_UNBLOCK_SOURCE:
+        case IP_ADD_SOURCE_MEMBERSHIP:
+        case IP_DROP_SOURCE_MEMBERSHIP:
+            if (optlen != sizeof (struct target_ip_mreq_source))
+                return -TARGET_EINVAL;
+
+            ip_mreq_source = lock_user(VERIFY_READ, optval_addr, optlen, 1);
+            ret = get_errno(setsockopt(sockfd, level, optname, ip_mreq_source, optlen));
+            unlock_user (ip_mreq_source, optval_addr, 0);
+            break;
+
         default:
             goto unimplemented;
         }
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 6e68c91..89b73b8 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -126,6 +126,13 @@ struct target_ip_mreqn {
     abi_long imr_ifindex;
 };
 
+struct target_ip_mreq_source {
+    /* big endian */
+    uint32_t imr_multiaddr;
+    uint32_t imr_interface;
+    uint32_t imr_sourceaddr;
+};
+
 struct target_timeval {
     abi_long tv_sec;
     abi_long tv_usec;
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 12/21] linux-user: include linux/fs.h
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (10 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 11/21] linux-user: Added IP_(UN)BLOCK_SOURCE/IP_(ADD|DROP)_SOURCE_MEMBERSHIP " riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 13/21] linux-user: support private futexes riku.voipio
                   ` (9 subsequent siblings)
  21 siblings, 0 replies; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Martin Mohring <martin.mohring@opensuse.org>

defines FIGETBSZ FIBMAP, allowing the respective ioctl's to
be implemented.

From: Martin Mohring <martin.mohring@opensuse.org>
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 linux-user/syscall.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 674942c..0c7ce51 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -77,6 +77,7 @@
 #include <linux/soundcard.h>
 #include <linux/kd.h>
 #include <linux/mtio.h>
+#include <linux/fs.h>
 #include "linux_loop.h"
 
 #include "qemu.h"
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 13/21] linux-user: support private futexes
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (11 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 12/21] linux-user: include linux/fs.h riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 14/21] add futex wake op riku.voipio
                   ` (8 subsequent siblings)
  21 siblings, 0 replies; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Martin Mohring <martin.mohring@opensuse.org>

Implemented the same way as in the kernel.

From: Martin Mohring <martin.mohring@opensuse.org>
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 linux-user/syscall.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 0c7ce51..59c8558 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3926,7 +3926,11 @@ static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout,
 
     /* ??? We assume FUTEX_* constants are the same on both host
        and target.  */
+#ifdef FUTEX_CMD_MASK
+    switch ((op&FUTEX_CMD_MASK)) {
+#else
     switch (op) {
+#endif
     case FUTEX_WAIT:
         if (timeout) {
             pts = &ts;
@@ -3934,17 +3938,17 @@ static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout,
         } else {
             pts = NULL;
         }
-        return get_errno(sys_futex(g2h(uaddr), FUTEX_WAIT, tswap32(val),
+        return get_errno(sys_futex(g2h(uaddr), op, tswap32(val),
                          pts, NULL, 0));
     case FUTEX_WAKE:
-        return get_errno(sys_futex(g2h(uaddr), FUTEX_WAKE, val, NULL, NULL, 0));
+        return get_errno(sys_futex(g2h(uaddr), op, val, NULL, NULL, 0));
     case FUTEX_FD:
-        return get_errno(sys_futex(g2h(uaddr), FUTEX_FD, val, NULL, NULL, 0));
+        return get_errno(sys_futex(g2h(uaddr), op, val, NULL, NULL, 0));
     case FUTEX_REQUEUE:
-        return get_errno(sys_futex(g2h(uaddr), FUTEX_REQUEUE, val,
+        return get_errno(sys_futex(g2h(uaddr), op, val,
                          NULL, g2h(uaddr2), 0));
     case FUTEX_CMP_REQUEUE:
-        return get_errno(sys_futex(g2h(uaddr), FUTEX_CMP_REQUEUE, val,
+        return get_errno(sys_futex(g2h(uaddr), op, val,
                          NULL, g2h(uaddr2), tswap32(val3)));
     default:
         return -TARGET_ENOSYS;
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 14/21] add futex wake op
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (12 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 13/21] linux-user: support private futexes riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 15/21] linux-user: update syscall list riku.voipio
                   ` (7 subsequent siblings)
  21 siblings, 0 replies; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Riku Voipio <riku.voipio@nokia.com>


Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 linux-user/syscall.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 59c8558..3fc6cbc 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3942,6 +3942,8 @@ static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout,
                          pts, NULL, 0));
     case FUTEX_WAKE:
         return get_errno(sys_futex(g2h(uaddr), op, val, NULL, NULL, 0));
+    case FUTEX_WAKE_OP:
+        return get_errno(sys_futex(g2h(uaddr), op, val, NULL, g2h(uaddr2), val3 ));
     case FUTEX_FD:
         return get_errno(sys_futex(g2h(uaddr), op, val, NULL, NULL, 0));
     case FUTEX_REQUEUE:
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 15/21] linux-user: update syscall list
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (13 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 14/21] add futex wake op riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 16/21] linux-user: implement pipe2 [v3] riku.voipio
                   ` (6 subsequent siblings)
  21 siblings, 0 replies; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Riku Voipio <riku.voipio@iki.fi>

In preparation for supporting pipe2()

Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 linux-user/arm/syscall_nr.h     |    9 +++++++++
 linux-user/i386/syscall_nr.h    |    8 ++++++++
 linux-user/m68k/syscall_nr.h    |    8 ++++++++
 linux-user/mips/syscall_nr.h    |    9 +++++++++
 linux-user/mips64/syscall_nr.h  |    9 +++++++++
 linux-user/mipsn32/syscall_nr.h |    9 +++++++++
 linux-user/ppc/syscall_nr.h     |    9 +++++++++
 linux-user/sh4/syscall_nr.h     |    8 ++++++++
 linux-user/sparc/syscall_nr.h   |    9 +++++++++
 linux-user/sparc64/syscall_nr.h |    9 +++++++++
 linux-user/x86_64/syscall_nr.h  |    9 +++++++++
 11 files changed, 96 insertions(+), 0 deletions(-)

diff --git a/linux-user/arm/syscall_nr.h b/linux-user/arm/syscall_nr.h
index 9ca3a5d..b1db341 100644
--- a/linux-user/arm/syscall_nr.h
+++ b/linux-user/arm/syscall_nr.h
@@ -356,3 +356,12 @@
 #define TARGET_NR_signalfd			(349)
 #define TARGET_NR_timerfd			(350)
 #define TARGET_NR_eventfd			(351)
+#define TARGET_NR_fallocate			(352)
+#define TARGET_NR_timerfd_settime		(353)
+#define TARGET_NR_timerfd_gettime		(354)
+#define TARGET_NR_signalfd4			(355)
+#define TARGET_NR_eventfd2			(356)
+#define TARGET_NR_epoll_create1		(357)
+#define TARGET_NR_dup3				(358)
+#define TARGET_NR_pipe2			(359)
+#define TARGET_NR_inotify_init1		(360)
diff --git a/linux-user/i386/syscall_nr.h b/linux-user/i386/syscall_nr.h
index 62662cc..3ef71ce 100644
--- a/linux-user/i386/syscall_nr.h
+++ b/linux-user/i386/syscall_nr.h
@@ -327,3 +327,11 @@
 #define TARGET_NR_timerfd		322
 #define TARGET_NR_eventfd		323
 #define TARGET_NR_fallocate		324
+#define TARGET_NR_timerfd_settime	325
+#define TARGET_NR_timerfd_gettime	326
+#define TARGET_NR_signalfd4		327
+#define TARGET_NR_eventfd2		328
+#define TARGET_NR_epoll_create1	329
+#define TARGET_NR_dup3			330
+#define TARGET_NR_pipe2		331
+#define TARGET_NR_inotify_init1	332
diff --git a/linux-user/m68k/syscall_nr.h b/linux-user/m68k/syscall_nr.h
index 0a802f4..1c0ba07 100644
--- a/linux-user/m68k/syscall_nr.h
+++ b/linux-user/m68k/syscall_nr.h
@@ -320,3 +320,11 @@
 #define TARGET_NR_timerfd		318
 #define TARGET_NR_eventfd		319
 #define TARGET_NR_fallocate		320
+#define TARGET_NR_timerfd_settime	321
+#define TARGET_NR_timerfd_gettime	322
+#define TARGET_NR_signalfd4		323
+#define TARGET_NR_eventfd2		324
+#define TARGET_NR_epoll_create1	325
+#define TARGET_NR_dup3			326
+#define TARGET_NR_pipe2		327
+#define TARGET_NR_inotify_init1	328
diff --git a/linux-user/mips/syscall_nr.h b/linux-user/mips/syscall_nr.h
index f900ae2..8228616 100644
--- a/linux-user/mips/syscall_nr.h
+++ b/linux-user/mips/syscall_nr.h
@@ -323,3 +323,12 @@
 #define TARGET_NR_timerfd		(TARGET_NR_Linux + 318)
 #define TARGET_NR_eventfd		(TARGET_NR_Linux + 319)
 #define TARGET_NR_fallocate		(TARGET_NR_Linux + 320)
+#define TARGET_NR_timerfd_create	(TARGET_NR_Linux + 321)
+#define TARGET_NR_timerfd_gettime	(TARGET_NR_Linux + 322)
+#define TARGET_NR_timerfd_settime	(TARGET_NR_Linux + 323)
+#define TARGET_NR_signalfd4		(TARGET_NR_Linux + 324)
+#define TARGET_NR_eventfd2		(TARGET_NR_Linux + 325)
+#define TARGET_NR_epoll_create1	(TARGET_NR_Linux + 326)
+#define TARGET_NR_dup3			(TARGET_NR_Linux + 327)
+#define TARGET_NR_pipe2		(TARGET_NR_Linux + 328)
+#define TARGET_NR_inotify_init1	(TARGET_NR_Linux + 329)
diff --git a/linux-user/mips64/syscall_nr.h b/linux-user/mips64/syscall_nr.h
index 28e1883..ee1d134 100644
--- a/linux-user/mips64/syscall_nr.h
+++ b/linux-user/mips64/syscall_nr.h
@@ -282,3 +282,12 @@
 #define TARGET_NR_timerfd			(TARGET_NR_Linux + 277)
 #define TARGET_NR_eventfd			(TARGET_NR_Linux + 278)
 #define TARGET_NR_fallocate			(TARGET_NR_Linux + 279)
+#define TARGET_NR_timerfd_create		(TARGET_NR_Linux + 280)
+#define TARGET_NR_timerfd_gettime		(TARGET_NR_Linux + 281)
+#define TARGET_NR_timerfd_settime		(TARGET_NR_Linux + 282)
+#define TARGET_NR_signalfd4			(TARGET_NR_Linux + 283)
+#define TARGET_NR_eventfd2			(TARGET_NR_Linux + 284)
+#define TARGET_NR_epoll_create1		(TARGET_NR_Linux + 285)
+#define TARGET_NR_dup3				(TARGET_NR_Linux + 286)
+#define TARGET_NR_pipe2			(TARGET_NR_Linux + 287)
+#define TARGET_NR_inotify_init1		(TARGET_NR_Linux + 288)
diff --git a/linux-user/mipsn32/syscall_nr.h b/linux-user/mipsn32/syscall_nr.h
index a83c4c9..60a99dd 100644
--- a/linux-user/mipsn32/syscall_nr.h
+++ b/linux-user/mipsn32/syscall_nr.h
@@ -286,3 +286,12 @@
 #define TARGET_NR_timerfd			(TARGET_NR_Linux + 281)
 #define TARGET_NR_eventfd			(TARGET_NR_Linux + 282)
 #define TARGET_NR_fallocate			(TARGET_NR_Linux + 283)
+#define TARGET_NR_timerfd_create		(TARGET_NR_Linux + 284)
+#define TARGET_NR_timerfd_gettime		(TARGET_NR_Linux + 285)
+#define TARGET_NR_timerfd_settime		(TARGET_NR_Linux + 286)
+#define TARGET_NR_signalfd4			(TARGET_NR_Linux + 287)
+#define TARGET_NR_eventfd2			(TARGET_NR_Linux + 288)
+#define TARGET_NR_epoll_create1		(TARGET_NR_Linux + 289)
+#define TARGET_NR_dup3				(TARGET_NR_Linux + 290)
+#define TARGET_NR_pipe2			(TARGET_NR_Linux + 291)
+#define TARGET_NR_inotify_init1		(TARGET_NR_Linux + 292)
diff --git a/linux-user/ppc/syscall_nr.h b/linux-user/ppc/syscall_nr.h
index 8fa5bef..f54276b 100644
--- a/linux-user/ppc/syscall_nr.h
+++ b/linux-user/ppc/syscall_nr.h
@@ -323,3 +323,12 @@
 #define TARGET_NR_eventfd		307
 #define TARGET_NR_sync_file_range2	308
 #define TARGET_NR_fallocate		309
+#define TARGET_NR_subpage_prot		310
+#define TARGET_NR_timerfd_settime	311
+#define TARGET_NR_timerfd_gettime	312
+#define TARGET_NR_signalfd4		313
+#define TARGET_NR_eventfd2		314
+#define TARGET_NR_epoll_create1	315
+#define TARGET_NR_dup3			316
+#define TARGET_NR_pipe2		317
+#define TARGET_NR_inotify_init1	318
diff --git a/linux-user/sh4/syscall_nr.h b/linux-user/sh4/syscall_nr.h
index b29705c..262b236 100644
--- a/linux-user/sh4/syscall_nr.h
+++ b/linux-user/sh4/syscall_nr.h
@@ -326,3 +326,11 @@
 #define TARGET_NR_timerfd		322
 #define TARGET_NR_eventfd		323
 #define TARGET_NR_fallocate		324
+#define TARGET_NR_timerfd_settime	325
+#define TARGET_NR_timerfd_gettime	326
+#define TARGET_NR_signalfd4		327
+#define TARGET_NR_eventfd2		328
+#define TARGET_NR_epoll_create1	329
+#define TARGET_NR_dup3			330
+#define TARGET_NR_pipe2		331
+#define TARGET_NR_inotify_init1	332
diff --git a/linux-user/sparc/syscall_nr.h b/linux-user/sparc/syscall_nr.h
index 6419570..5d1ac21 100644
--- a/linux-user/sparc/syscall_nr.h
+++ b/linux-user/sparc/syscall_nr.h
@@ -276,3 +276,12 @@
 #define TARGET_NR_timerfd		312
 #define TARGET_NR_eventfd		313
 #define TARGET_NR_fallocate		314
+#define TARGET_NR_timerfd_settime	315
+#define TARGET_NR_timerfd_gettime	316
+#define TARGET_NR_signalfd4		317
+#define TARGET_NR_eventfd2		318
+#define TARGET_NR_epoll_create1	319
+#define TARGET_NR_dup3			320
+#define TARGET_NR_pipe2		321
+#define TARGET_NR_inotify_init1	322
+#define TARGET_NR_accept4		323
diff --git a/linux-user/sparc64/syscall_nr.h b/linux-user/sparc64/syscall_nr.h
index 70bee80..bdca2a7 100644
--- a/linux-user/sparc64/syscall_nr.h
+++ b/linux-user/sparc64/syscall_nr.h
@@ -313,3 +313,12 @@
 #define TARGET_NR_timerfd		312
 #define TARGET_NR_eventfd		313
 #define TARGET_NR_fallocate		314
+#define TARGET_NR_timerfd_settime	315
+#define TARGET_NR_timerfd_gettime	316
+#define TARGET_NR_signalfd4		317
+#define TARGET_NR_eventfd2		318
+#define TARGET_NR_epoll_create1	319
+#define TARGET_NR_dup3			320
+#define TARGET_NR_pipe2		321
+#define TARGET_NR_inotify_init1	322
+#define TARGET_NR_accept4		323
diff --git a/linux-user/x86_64/syscall_nr.h b/linux-user/x86_64/syscall_nr.h
index e6a4c27..568a901 100644
--- a/linux-user/x86_64/syscall_nr.h
+++ b/linux-user/x86_64/syscall_nr.h
@@ -284,3 +284,12 @@
 #define TARGET_NR_timerfd		283
 #define TARGET_NR_eventfd		284
 #define TARGET_NR_fallocate		285
+#define TARGET_NR_timerfd_settime	286
+#define TARGET_NR_timerfd_gettime	287
+#define TARGET_NR_accept4		288
+#define TARGET_NR_signalfd4		289
+#define TARGET_NR_eventfd2		290
+#define TARGET_NR_epoll_create1	291
+#define TARGET_NR_dup3			292
+#define TARGET_NR_pipe2		293
+#define TARGET_NR_inotify_init1	294
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 16/21] linux-user: implement pipe2 [v3]
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (14 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 15/21] linux-user: update syscall list riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-16 21:44   ` Stuart Brady
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 17/21] linux-user: add tee, splice and vmsplice riku.voipio
                   ` (5 subsequent siblings)
  21 siblings, 1 reply; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Riku Voipio <riku.voipio@iki.fi>

implement pipe2 syscall.

[v2] fix do_pipe on mips and sh4
[v3] use pipe2 to ensure atomicity, but only when it is available.

Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 configure            |   21 +++++++++++++++++++
 linux-user/syscall.c |   55 +++++++++++++++++++++++++++++++++----------------
 2 files changed, 58 insertions(+), 18 deletions(-)

diff --git a/configure b/configure
index ecea67c..4187eb2 100755
--- a/configure
+++ b/configure
@@ -1300,6 +1300,24 @@ if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
   utimens=yes
 fi
 
+# check if pipe2 is there
+pipe2=no
+cat > $TMPC << EOF
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <fcntl.h>
+
+int main(void)
+{
+    int pipefd[2];
+    pipe2(pipefd, O_CLOEXEC);
+    return 0;
+}
+EOF
+if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
+  pipe2=yes
+fi
+
 # Check if tools are available to build documentation.
 if test "$build_docs" = "yes" -a \( ! -x "`which texi2html 2>/dev/null`" -o ! -x "`which pod2man 2>/dev/null`" \) ; then
   build_docs="no"
@@ -1701,6 +1719,9 @@ fi
 if test "$utimens" = "yes" ; then
   echo "#define CONFIG_UTIMENSAT 1" >> $config_h
 fi
+if test "$pipe2" = "yes" ; then
+  echo "#define CONFIG_PIPE2 1" >> $config_h
+fi
 if test "$inotify" = "yes" ; then
   echo "#define CONFIG_INOTIFY 1" >> $config_h
 fi
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3fc6cbc..36eb9f5 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -944,6 +944,37 @@ static abi_long do_select(int n,
     return ret;
 }
 
+static abi_long do_pipe2(int host_pipe[], int flags)
+{
+#ifdef CONFIG_PIPE2
+    return pipe2(host_pipe, flags);
+#else
+    return -ENOSYS;
+#endif
+}
+
+static abi_long do_pipe(void *cpu_env, int pipedes, int flags)
+{
+    int host_pipe[2];
+    abi_long ret;
+    ret = flags ? do_pipe2(host_pipe, flags) : pipe(host_pipe);
+
+    if (is_error(ret))
+        return get_errno(ret);
+#if defined(TARGET_MIPS)
+    ((CPUMIPSState*)cpu_env)->active_tc.gpr[3] = host_pipe[1];
+    ret = host_pipe[0];
+#elif defined(TARGET_SH4)
+    ((CPUSH4State*)cpu_env)->gregs[1] = host_pipe[1];
+    ret = host_pipe[0];
+#else
+    if (put_user_s32(host_pipe[0], pipedes)
+        || put_user_s32(host_pipe[1], pipedes + sizeof(host_pipe[0])))
+        return -TARGET_EFAULT;
+#endif
+    return get_errno(ret);
+}
+
 static inline abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn,
                                               abi_ulong target_addr,
                                               socklen_t len)
@@ -4529,25 +4560,13 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = get_errno(dup(arg1));
         break;
     case TARGET_NR_pipe:
-        {
-            int host_pipe[2];
-            ret = get_errno(pipe(host_pipe));
-            if (!is_error(ret)) {
-#if defined(TARGET_MIPS)
-                CPUMIPSState *env = (CPUMIPSState*)cpu_env;
-		env->active_tc.gpr[3] = host_pipe[1];
-		ret = host_pipe[0];
-#elif defined(TARGET_SH4)
-		((CPUSH4State*)cpu_env)->gregs[1] = host_pipe[1];
-		ret = host_pipe[0];
-#else
-                if (put_user_s32(host_pipe[0], arg1)
-                    || put_user_s32(host_pipe[1], arg1 + sizeof(host_pipe[0])))
-                    goto efault;
-#endif
-            }
-        }
+        ret = do_pipe(cpu_env, arg1, 0);
+        break;
+#ifdef TARGET_NR_pipe2
+    case TARGET_NR_pipe2:
+        ret = do_pipe(cpu_env, arg1, arg2);
         break;
+#endif
     case TARGET_NR_times:
         {
             struct target_tms *tmsp;
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 17/21] linux-user: add tee, splice and vmsplice
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (15 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 16/21] linux-user: implement pipe2 [v3] riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-14 15:25   ` Blue Swirl
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 18/21] RFC: fix fcntl support in linux-user - new try riku.voipio
                   ` (4 subsequent siblings)
  21 siblings, 1 reply; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: vibisreenivasan <vibi_sreenivasan@cms.com>

Add support for tee, splice and vmsplice.

Originally from: vibi sreenivasan <vibi_sreenivasan@cms.com>

Riku: squashed patches together and added a test to configure

From: vibisreenivasan <vibi_sreenivasan@cms.com>
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 configure            |   23 +++++++++++++++++++++++
 linux-user/syscall.c |   40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/configure b/configure
index 4187eb2..cbcae1f 100755
--- a/configure
+++ b/configure
@@ -1318,6 +1318,26 @@ if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
   pipe2=yes
 fi
 
+# check if tee/splice is there. vmsplice was added same time.
+splice=no
+cat > $TMPC << EOF
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <fcntl.h>
+#include <limits.h>
+
+int main(void)
+{
+    int len, fd;
+    len = tee(STDIN_FILENO, STDOUT_FILENO, INT_MAX, SPLICE_F_NONBLOCK);
+    splice(STDIN_FILENO, NULL, fd, NULL, len, SPLICE_F_MOVE);
+    return 0;
+}
+EOF
+if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
+  splice=yes
+fi
+
 # Check if tools are available to build documentation.
 if test "$build_docs" = "yes" -a \( ! -x "`which texi2html 2>/dev/null`" -o ! -x "`which pod2man 2>/dev/null`" \) ; then
   build_docs="no"
@@ -1722,6 +1742,9 @@ fi
 if test "$pipe2" = "yes" ; then
   echo "#define CONFIG_PIPE2 1" >> $config_h
 fi
+if test "$splice" = "yes" ; then
+  echo "#define CONFIG_SPLICE 1" >> $config_h
+fi
 if test "$inotify" = "yes" ; then
   echo "#define CONFIG_INOTIFY 1" >> $config_h
 fi
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 36eb9f5..ff35881 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6865,6 +6865,46 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 
+#ifdef CONFIG_SPLICE
+#ifdef TARGET_NR_tee
+    case TARGET_NR_tee:
+        {
+            ret = get_errno(tee(arg1,arg2,arg3,arg4));
+        }
+        break;
+#endif
+#ifdef TARGET_NR_splice
+    case TARGET_NR_splice:
+        {
+            long long int loff_in, loff_out;
+            long long int *ploff_in = NULL, *ploff_out = NULL;
+            if(arg2) {
+                get_user_u64(loff_in, arg2);
+                ploff_in = &loff_in;
+            }
+            if(arg4) {
+                get_user_u64(loff_out, arg2);
+                ploff_out = &loff_out;
+            }
+            ret = get_errno(splice(arg1, ploff_in, arg3, ploff_out, arg5, arg6));
+        }
+        break;
+#endif
+#ifdef TARGET_NR_vmsplice
+	case TARGET_NR_vmsplice:
+        {
+            int count = arg3;
+            struct iovec *vec;
+
+            vec = alloca(count * sizeof(struct iovec));
+            if (lock_iovec(VERIFY_READ, vec, arg2, count, 1) < 0)
+                goto efault;
+            ret = get_errno(vmsplice(arg1, vec, count, arg4));
+            unlock_iovec(vec, arg2, count, 0);
+        }
+        break;
+#endif
+#endif /* CONFIG_SPLICE */
     default:
     unimplemented:
         gemu_log("qemu: Unsupported syscall: %d\n", num);
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 18/21] RFC: fix fcntl support in linux-user - new try
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (16 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 17/21] linux-user: add tee, splice and vmsplice riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-14 15:15   ` Blue Swirl
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 19/21] linux-user: initialize mmap_mutex properly riku.voipio
                   ` (3 subsequent siblings)
  21 siblings, 1 reply; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Arnaud Patard (Rtp) <arnaud.patard@rtp-net.org>

Hi,

This is a new try to fix the fcntl support in linux-user. I tried to
adress all comments but as the previous version is several weeks old,
it's possible that I've missed some.

This patch doesn't handle linux specific fcntl flags. My plan is to get
this version of the patch reviewed/fixed and then, add them if wanted.

Thanks,
Arnaud

From: Arnaud Patard (Rtp) <arnaud.patard@rtp-net.org>
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 linux-user/syscall.c      |   84 ++++++++++++++++++++++++++++++++------------
 linux-user/syscall_defs.h |   13 ++++++-
 2 files changed, 73 insertions(+), 24 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ff35881..6124751 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3622,6 +3622,44 @@ static int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp,
     return ret;
 }
 
+/* warning : doesn't handle linux specific flags... */
+static int target_to_host_fcntl_cmd(int cmd)
+{
+    switch(cmd) {
+	case TARGET_F_DUPFD:
+	case TARGET_F_GETFD:
+	case TARGET_F_SETFD:
+	case TARGET_F_GETFL:
+	case TARGET_F_SETFL:
+            return cmd;
+        case TARGET_F_GETLK:
+	    return F_GETLK;
+	case TARGET_F_SETLK:
+	    return F_SETLK;
+	case TARGET_F_SETLKW:
+	    return F_SETLKW;
+	case TARGET_F_GETOWN:
+	    return F_GETOWN;
+	case TARGET_F_SETOWN:
+	    return F_SETOWN;
+	case TARGET_F_GETSIG:
+	    return F_GETSIG;
+	case TARGET_F_SETSIG:
+	    return F_SETSIG;
+#if TARGET_ABI_BITS == 32
+        case TARGET_F_GETLK64:
+	    return F_GETLK64;
+	case TARGET_F_SETLK64:
+	    return F_SETLK64;
+	case TARGET_F_SETLKW64:
+	    return F_SETLKW64;
+#endif
+	default:
+            return -TARGET_EINVAL;
+    }
+    return -TARGET_EINVAL;
+}
+
 static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
 {
     struct flock fl;
@@ -3629,6 +3667,10 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
     struct flock64 fl64;
     struct target_flock64 *target_fl64;
     abi_long ret;
+    int host_cmd = target_to_host_fcntl_cmd(cmd);
+
+    if (host_cmd == -TARGET_EINVAL)
+	    return host_cmd;
 
     switch(cmd) {
     case TARGET_F_GETLK:
@@ -3640,7 +3682,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
         fl.l_len = tswapl(target_fl->l_len);
         fl.l_pid = tswapl(target_fl->l_pid);
         unlock_user_struct(target_fl, arg, 0);
-        ret = get_errno(fcntl(fd, cmd, &fl));
+        ret = get_errno(fcntl(fd, host_cmd, &fl));
         if (ret == 0) {
             if (!lock_user_struct(VERIFY_WRITE, target_fl, arg, 0))
                 return -TARGET_EFAULT;
@@ -3663,7 +3705,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
         fl.l_len = tswapl(target_fl->l_len);
         fl.l_pid = tswapl(target_fl->l_pid);
         unlock_user_struct(target_fl, arg, 0);
-        ret = get_errno(fcntl(fd, cmd, &fl));
+        ret = get_errno(fcntl(fd, host_cmd, &fl));
         break;
 
     case TARGET_F_GETLK64:
@@ -3675,7 +3717,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
         fl64.l_len = tswapl(target_fl64->l_len);
         fl64.l_pid = tswap16(target_fl64->l_pid);
         unlock_user_struct(target_fl64, arg, 0);
-        ret = get_errno(fcntl(fd, cmd >> 1, &fl64));
+        ret = get_errno(fcntl(fd, host_cmd, &fl64));
         if (ret == 0) {
             if (!lock_user_struct(VERIFY_WRITE, target_fl64, arg, 0))
                 return -TARGET_EFAULT;
@@ -3697,18 +3739,25 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
         fl64.l_len = tswapl(target_fl64->l_len);
         fl64.l_pid = tswap16(target_fl64->l_pid);
         unlock_user_struct(target_fl64, arg, 0);
-        ret = get_errno(fcntl(fd, cmd >> 1, &fl64));
+        ret = get_errno(fcntl(fd, host_cmd, &fl64));
         break;
 
-    case F_GETFL:
-        ret = get_errno(fcntl(fd, cmd, arg));
+    case TARGET_F_GETFL:
+        ret = get_errno(fcntl(fd, host_cmd, arg));
         if (ret >= 0) {
             ret = host_to_target_bitmask(ret, fcntl_flags_tbl);
         }
         break;
 
-    case F_SETFL:
-        ret = get_errno(fcntl(fd, cmd, target_to_host_bitmask(arg, fcntl_flags_tbl)));
+    case TARGET_F_SETFL:
+        ret = get_errno(fcntl(fd, host_cmd, target_to_host_bitmask(arg, fcntl_flags_tbl)));
+        break;
+
+    case TARGET_F_SETOWN:
+    case TARGET_F_GETOWN:
+    case TARGET_F_SETSIG:
+    case TARGET_F_GETSIG:
+        ret = get_errno(fcntl(fd, host_cmd, arg));
         break;
 
     default:
@@ -6501,20 +6550,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 	struct target_eabi_flock64 *target_efl;
 #endif
 
-        switch(arg2){
-        case TARGET_F_GETLK64:
-            cmd = F_GETLK64;
-            break;
-        case TARGET_F_SETLK64:
-            cmd = F_SETLK64;
-            break;
-        case TARGET_F_SETLKW64:
-            cmd = F_SETLK64;
-            break;
-        default:
-            cmd = arg2;
-            break;
-        }
+	cmd = target_to_host_fcntl_cmd(arg2);
+	if (cmd == -TARGET_EINVAL)
+		return cmd;
 
         switch(arg2) {
         case TARGET_F_GETLK64:
@@ -6594,7 +6632,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             ret = get_errno(fcntl(arg1, cmd, &fl));
 	    break;
         default:
-            ret = do_fcntl(arg1, cmd, arg3);
+            ret = do_fcntl(arg1, arg2, arg3);
             break;
         }
 	break;
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 89b73b8..24217e4 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -1745,6 +1745,12 @@ struct target_statfs64 {
 #define TARGET_F_SETLKW        9
 #define TARGET_F_SETOWN        5       /*  for sockets. */
 #define TARGET_F_GETOWN        6       /*  for sockets. */
+#elif defined(TARGET_MIPS)
+#define TARGET_F_GETLK         14
+#define TARGET_F_SETLK         6
+#define TARGET_F_SETLKW        7
+#define TARGET_F_SETOWN        24       /*  for sockets. */
+#define TARGET_F_GETOWN        25       /*  for sockets. */
 #else
 #define TARGET_F_GETLK         5
 #define TARGET_F_SETLK         6
@@ -1756,10 +1762,15 @@ struct target_statfs64 {
 #define TARGET_F_SETSIG        10      /*  for sockets. */
 #define TARGET_F_GETSIG        11      /*  for sockets. */
 
+#if defined(TARGET_MIPS)
+#define TARGET_F_GETLK64       33      /*  using 'struct flock64' */
+#define TARGET_F_SETLK64       34
+#define TARGET_F_SETLKW64      35
+#else
 #define TARGET_F_GETLK64       12      /*  using 'struct flock64' */
 #define TARGET_F_SETLK64       13
 #define TARGET_F_SETLKW64      14
-
+#endif
 #if defined (TARGET_ARM)
 #define TARGET_O_ACCMODE          0003
 #define TARGET_O_RDONLY             00
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 19/21] linux-user: initialize mmap_mutex properly
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (17 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 18/21] RFC: fix fcntl support in linux-user - new try riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 20/21] linux-user/syscall.c: define _ATFILE_SOURCE riku.voipio
                   ` (2 subsequent siblings)
  21 siblings, 0 replies; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Nathan Froyd <froydnj@codesourcery.com>

We initialize mmap_mutex in any child threads/processes, but we need to
correctly statically initialize it for the original process.

From: Nathan Froyd <froydnj@codesourcery.com>
Signed-off-by: Nathan Froyd <froydnj@codesourcery.com>
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 linux-user/mmap.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index aa5813f..aa22006 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -36,7 +36,7 @@
 //#define DEBUG_MMAP
 
 #if defined(USE_NPTL)
-pthread_mutex_t mmap_mutex;
+pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER;
 static int __thread mmap_lock_count;
 
 void mmap_lock(void)
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 20/21] linux-user/syscall.c: define _ATFILE_SOURCE
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (18 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 19/21] linux-user: initialize mmap_mutex properly riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 21/21] linux-user: remove duplicate tswap32() from do_getsockopt() riku.voipio
  2009-06-14 15:12 ` [Qemu-devel] [PATCH 00/21] Pending linux-user patches Blue Swirl
  21 siblings, 0 replies; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Eduardo Habkost <ehabkost@redhat.com>

Needed to make sure the xxxat() functions are available.

From: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 linux-user/syscall.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 6124751..2939de8 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -18,6 +18,7 @@
  *  Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  *  MA 02110-1301, USA.
  */
+#define _ATFILE_SOURCE
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [Qemu-devel] [PATCH 21/21] linux-user: remove duplicate tswap32() from do_getsockopt()
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (19 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 20/21] linux-user/syscall.c: define _ATFILE_SOURCE riku.voipio
@ 2009-06-12 13:50 ` riku.voipio
  2009-06-14 15:12 ` [Qemu-devel] [PATCH 00/21] Pending linux-user patches Blue Swirl
  21 siblings, 0 replies; 40+ messages in thread
From: riku.voipio @ 2009-06-12 13:50 UTC (permalink / raw)
  To: qemu-devel

From: Laurent Vivier <laurent@vivier.eu>

This issue has been detected with tests/linux-tests.c:

linux-test.c:330: getsockopt

327     len = sizeof(val);
328     chk_error(getsockopt(server_fd, SOL_SOCKET, SO_TYPE, &val, &len));
329     if (val != SOCK_STREAM)
330         error("getsockopt");

In linux-user/syscall.c:do_getsockopt(), we have:
...
        val = tswap32(val);
...
            if (put_user_u32(val, optval_addr))
...

whereas "put_user_u32" calls in the end "__put_user" which uses "tswap32".

So the "val = tswap32(val);" is useless and wrong.

This patch removes it.

From: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
 linux-user/syscall.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 2939de8..f82dd82 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1348,7 +1348,6 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
         ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
         if (ret < 0)
             return ret;
-        val = tswap32(val);
         if (len > lv)
             len = lv;
         if (len == 4) {
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 00/21] Pending linux-user patches
  2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
                   ` (20 preceding siblings ...)
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 21/21] linux-user: remove duplicate tswap32() from do_getsockopt() riku.voipio
@ 2009-06-14 15:12 ` Blue Swirl
  2009-06-15 15:10   ` Riku Voipio
  21 siblings, 1 reply; 40+ messages in thread
From: Blue Swirl @ 2009-06-14 15:12 UTC (permalink / raw)
  To: riku.voipio; +Cc: qemu-devel

On 6/12/09, riku.voipio@iki.fi <riku.voipio@iki.fi> wrote:
> From: Riku Voipio <riku.voipio@iki.fi>
>
>  All the things in linux-user tree at the moment:
>
>  https://git.maemo.org/projects/qemu/gitweb?p=qemu;a=shortlog;h=refs/heads/linux-user-for-upstream
>
>  Since the maemo git hosting regrettably only provides https
>  transport, you can download the git tree faster if you already
>  have a git tree:
>
>  git clone git://git.sv.gnu.org/qemu.git
>  cd qemu
>  git remote add maemo https://git.maemo.org/projects/qemu
>  git fetch maemo
>  git checkout -b linux-user maemo/linux-user-for-upstream
>
>  This tree is constantly rebased against upstream git HEAD, so avoid basing your
>  work on this branch.

Constantly? It's already three days old. :-)

Anyway, I pulled the patches with the intention of possibly committing
them. But it looks some of them are not ready yet.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 18/21] RFC: fix fcntl support in linux-user - new try
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 18/21] RFC: fix fcntl support in linux-user - new try riku.voipio
@ 2009-06-14 15:15   ` Blue Swirl
  0 siblings, 0 replies; 40+ messages in thread
From: Blue Swirl @ 2009-06-14 15:15 UTC (permalink / raw)
  To: riku.voipio; +Cc: qemu-devel

On 6/12/09, riku.voipio@iki.fi <riku.voipio@iki.fi> wrote:
> From: Arnaud Patard (Rtp) <arnaud.patard@rtp-net.org>
>
>  Hi,
>
>  This is a new try to fix the fcntl support in linux-user. I tried to
>  adress all comments but as the previous version is several weeks old,
>  it's possible that I've missed some.
>
>  This patch doesn't handle linux specific fcntl flags. My plan is to get
>  this version of the patch reviewed/fixed and then, add them if wanted.
>
>  Thanks,
>  Arnaud
>
>  From: Arnaud Patard (Rtp) <arnaud.patard@rtp-net.org>
>  Signed-off-by: Riku Voipio <riku.voipio@iki.fi>

I think SOB: Arnaud Patard is what is needed here.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 03/21] linux-user: implemented ELF coredump support for ARM target
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 03/21] linux-user: implemented ELF coredump support for ARM target riku.voipio
@ 2009-06-14 15:16   ` Blue Swirl
  0 siblings, 0 replies; 40+ messages in thread
From: Blue Swirl @ 2009-06-14 15:16 UTC (permalink / raw)
  To: riku.voipio; +Cc: qemu-devel

On 6/12/09, riku.voipio@iki.fi <riku.voipio@iki.fi> wrote:
> From: Mika Westerberg <mika.westerberg@iki.fi>
>
>  When target process is killed with signal (such signal that
>  should dump core) a coredump file is created.  This file is
>  similar than coredump generated by Linux (there are few exceptions
>  though).
>
>  Riku Voipio: added support for rlimit
>
>  From: Mika Westerberg <mika.westerberg@iki.fi>
>  Signed-off-by: Riku Voipio <riku.voipio@iki.fi>

>From != SOB.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 05/21] linux-user: strace now handles guest strings correctly [v2]
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 05/21] linux-user: strace now handles guest strings correctly [v2] riku.voipio
@ 2009-06-14 15:17   ` Blue Swirl
  0 siblings, 0 replies; 40+ messages in thread
From: Blue Swirl @ 2009-06-14 15:17 UTC (permalink / raw)
  To: riku.voipio; +Cc: qemu-devel

On 6/12/09, riku.voipio@iki.fi <riku.voipio@iki.fi> wrote:
> From: Mika Westerberg <mika.westerberg@iki.fi>
>
>  - to not to break strace with GUEST_BASE is set:
>  - Strace now can load and print guest strings correctly.
>  - Added printing support for commonly used flags in some syscalls
>   (e.g open, creat, mmap etc.)
>
>  v2:
>  - fix strace.c build on etch
>  - add futex print to strace
>
>  From: Mika Westerberg <mika.westerberg@iki.fi>
>  Signed-off-by: Riku Voipio <riku.voipio@iki.fi>

>From != SOB.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 04/21] linux-user: added x86 and x86_64 support for ELF coredump
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 04/21] linux-user: added x86 and x86_64 support for ELF coredump riku.voipio
@ 2009-06-14 15:21   ` Blue Swirl
  0 siblings, 0 replies; 40+ messages in thread
From: Blue Swirl @ 2009-06-14 15:21 UTC (permalink / raw)
  To: riku.voipio; +Cc: qemu-devel

On 6/12/09, riku.voipio@iki.fi <riku.voipio@iki.fi> wrote:
> From: Mika Westerberg <mika.westerberg@iki.fi>
>
>
>  From: Mika Westerberg <mika.westerberg@iki.fi>
>  Signed-off-by: Riku Voipio <riku.voipio@iki.fi>

>From != SOB.

Maybe it would be useful to get a core dump from a running emulated
process. Since we have no monitor for user emulators, a GDB command
could be used.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 08/21] Fix struct termios host - target translation
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 08/21] Fix struct termios host - target translation riku.voipio
@ 2009-06-14 15:22   ` Blue Swirl
  2009-06-15 15:36     ` Riku Voipio
  0 siblings, 1 reply; 40+ messages in thread
From: Blue Swirl @ 2009-06-14 15:22 UTC (permalink / raw)
  To: riku.voipio; +Cc: qemu-devel

On 6/12/09, riku.voipio@iki.fi <riku.voipio@iki.fi> wrote:
> From: Arnaud Patard <arnaud.patard@rtp-net.org>
>
>  When converting the termios structure between host and target in
>  target_to_host_termios and host_to_target_termios, the c_cc[] array is
>  never initialised.
>  Calling memset() before using it allows to run successfully "stty echo /
>  stty -echo" on arm-linux-user target (host being x86 and mips).
>
>  From: Arnaud Patard <arnaud.patard@rtp-net.org>
>  Signed-off-by: Riku Voipio <riku.voipio@iki.fi>

>From != SOB.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 17/21] linux-user: add tee, splice and vmsplice
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 17/21] linux-user: add tee, splice and vmsplice riku.voipio
@ 2009-06-14 15:25   ` Blue Swirl
  0 siblings, 0 replies; 40+ messages in thread
From: Blue Swirl @ 2009-06-14 15:25 UTC (permalink / raw)
  To: riku.voipio; +Cc: qemu-devel

On 6/12/09, riku.voipio@iki.fi <riku.voipio@iki.fi> wrote:
> From: vibisreenivasan <vibi_sreenivasan@cms.com>
>
>  Add support for tee, splice and vmsplice.
>
>  Originally from: vibi sreenivasan <vibi_sreenivasan@cms.com>
>
>  Riku: squashed patches together and added a test to configure
>
>  From: vibisreenivasan <vibi_sreenivasan@cms.com>
>  Signed-off-by: Riku Voipio <riku.voipio@iki.fi>

>From != SOB.

Also, I get this warning (which is now an error):
  CC    i386-linux-user/syscall.o
cc1: warnings being treated as errors
/src/qemu/linux-user/syscall.c: In function 'do_syscall':
/src/qemu/linux-user/syscall.c:6927: error: passing argument 2 of
'splice' from incompatible pointer type
/src/qemu/linux-user/syscall.c:6927: error: passing argument 4 of
'splice' from incompatible pointer type
make[1]: *** [syscall.o] Error 1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 06/21] Revived GUEST_BASE support for usermode emulation targets [v5]
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 06/21] Revived GUEST_BASE support for usermode emulation targets [v5] riku.voipio
@ 2009-06-14 15:28   ` Blue Swirl
  0 siblings, 0 replies; 40+ messages in thread
From: Blue Swirl @ 2009-06-14 15:28 UTC (permalink / raw)
  To: riku.voipio; +Cc: qemu-devel

On 6/12/09, riku.voipio@iki.fi <riku.voipio@iki.fi> wrote:
> From: Mika Westerberg <mika.westerberg@iki.fi>
>
>  From: Mika Westerberg <mika.westerberg@iki.fi>
>
>  - Now GUEST_BASE is dynamic and can be set from command line.
>  - Qemu checks /proc/sys/vm/mmap_min_addr and sets GUEST_BASE
>   if needed.
>  - Code generation supports GUEST_BASE for i386 and x86_64 hosts.
>
>  [v3]: implemented GUEST_BASE with offset mods
>
>  Using malc's advice, instead of a mov or lea, just adjust
>  the offset parameter of tcg_out_modrm_offset(). - Riku
>
>  [v5]: set a GUEST_BASE_MAX instead of supporting moving
>  to arbitary ranges
>
>  From: Mika Westerberg <mika.westerberg@iki.fi>
>  Signed-off-by: Riku Voipio <riku.voipio@iki.fi>

>From != SOB.

There are two From lines in the beginning, I don't know if Git eats all of them.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 00/21] Pending linux-user patches
  2009-06-14 15:12 ` [Qemu-devel] [PATCH 00/21] Pending linux-user patches Blue Swirl
@ 2009-06-15 15:10   ` Riku Voipio
  2009-06-16 16:30     ` Martin Mohring
  0 siblings, 1 reply; 40+ messages in thread
From: Riku Voipio @ 2009-06-15 15:10 UTC (permalink / raw)
  To: Blue Swirl; +Cc: qemu-devel

On Sun, Jun 14, 2009 at 06:12:06PM +0300, Blue Swirl wrote:
> On 6/12/09, riku.voipio@iki.fi <riku.voipio@iki.fi> wrote:
> > From: Riku Voipio <riku.voipio@iki.fi>
> >
> >  All the things in linux-user tree at the moment:
> >
> >  https://git.maemo.org/projects/qemu/gitweb?p=qemu;a=shortlog;h=refs/heads/linux-user-for-upstream
> >
> >  Since the maemo git hosting regrettably only provides https
> >  transport, you can download the git tree faster if you already
> >  have a git tree:
> >
> >  git clone git://git.sv.gnu.org/qemu.git
> >  cd qemu
> >  git remote add maemo https://git.maemo.org/projects/qemu
> >  git fetch maemo
> >  git checkout -b linux-user maemo/linux-user-for-upstream
> >
> >  This tree is constantly rebased against upstream git HEAD, so avoid basing your
> >  work on this branch.

> Constantly? It's already three days old. :-)

More accurate would be "whenever there is updates in the upstream linux-user/
subdir that require rebasing", but that might give some people the impression
that it is actually rabased quite rarely ;-)

> Anyway, I pulled the patches with the intention of possibly committing
> them. But it looks some of them are not ready yet.

The "From:" fields were not intended as signed-off-by replacements, but rather
to ensure that the authorship info is not lost. With the current mailer setup
the email header "From:" on the patches sent to the mailing list shows my address,
and I don't want to take anyones credit away.

I'll have the look at the compiler warning, I didn't see any warnings on my build
env(s) before mailing.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 08/21] Fix struct termios host - target translation
  2009-06-14 15:22   ` Blue Swirl
@ 2009-06-15 15:36     ` Riku Voipio
  2009-06-16  8:28       ` Arnaud Patard
  0 siblings, 1 reply; 40+ messages in thread
From: Riku Voipio @ 2009-06-15 15:36 UTC (permalink / raw)
  To: Blue Swirl; +Cc: qemu-devel, arnaud.patard

On Sun, Jun 14, 2009 at 06:22:36PM +0300, Blue Swirl wrote:
> On 6/12/09, riku.voipio@iki.fi <riku.voipio@iki.fi> wrote:
> > From: Arnaud Patard <arnaud.patard@rtp-net.org>

> >  When converting the termios structure between host and target in
> >  target_to_host_termios and host_to_target_termios, the c_cc[] array is
> >  never initialised.
> >  Calling memset() before using it allows to run successfully "stty echo /
> >  stty -echo" on arm-linux-user target (host being x86 and mips).
> >
> >  From: Arnaud Patard <arnaud.patard@rtp-net.org>
> >  Signed-off-by: Riku Voipio <riku.voipio@iki.fi>

> >From != SOB.

Arnaud, can you send your Signed-Off-By: for the patches you have sent?

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 08/21] Fix struct termios host - target translation
  2009-06-15 15:36     ` Riku Voipio
@ 2009-06-16  8:28       ` Arnaud Patard
  2009-06-16  9:34         ` Riku Voipio
  0 siblings, 1 reply; 40+ messages in thread
From: Arnaud Patard @ 2009-06-16  8:28 UTC (permalink / raw)
  To: Riku Voipio; +Cc: Blue Swirl, qemu-devel

Riku Voipio <riku.voipio@iki.fi> writes:
Hi,

> On Sun, Jun 14, 2009 at 06:22:36PM +0300, Blue Swirl wrote:
>> On 6/12/09, riku.voipio@iki.fi <riku.voipio@iki.fi> wrote:
>> > From: Arnaud Patard <arnaud.patard@rtp-net.org>
>
>> >  When converting the termios structure between host and target in
>> >  target_to_host_termios and host_to_target_termios, the c_cc[] array is
>> >  never initialised.
>> >  Calling memset() before using it allows to run successfully "stty echo /
>> >  stty -echo" on arm-linux-user target (host being x86 and mips).
>> >
>> >  From: Arnaud Patard <arnaud.patard@rtp-net.org>
>> >  Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
>
>> >From != SOB.
>
> Arnaud, can you send your Signed-Off-By: for the patches you have sent?

Signed-off-by: Arnaud Patard <arnaud.patard@rtp-net.org>


Also, do you want me to reply to all your mails with the patches I've
sent or adding my SOB here is enough for all ?

Arnaud

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 08/21] Fix struct termios host - target translation
  2009-06-16  8:28       ` Arnaud Patard
@ 2009-06-16  9:34         ` Riku Voipio
  2009-06-16 10:01           ` Arnaud Patard
  0 siblings, 1 reply; 40+ messages in thread
From: Riku Voipio @ 2009-06-16  9:34 UTC (permalink / raw)
  To: Arnaud Patard; +Cc: Blue Swirl, qemu-devel

On Tue, Jun 16, 2009 at 10:28:43AM +0200, Arnaud Patard wrote:
> Riku Voipio <riku.voipio@iki.fi> writes:
> Hi,
> 
> > On Sun, Jun 14, 2009 at 06:22:36PM +0300, Blue Swirl wrote:
> >> On 6/12/09, riku.voipio@iki.fi <riku.voipio@iki.fi> wrote:
> >> > From: Arnaud Patard <arnaud.patard@rtp-net.org>
> >
> >> >  When converting the termios structure between host and target in
> >> >  target_to_host_termios and host_to_target_termios, the c_cc[] array is
> >> >  never initialised.
> >> >  Calling memset() before using it allows to run successfully "stty echo /
> >> >  stty -echo" on arm-linux-user target (host being x86 and mips).
> >> >
> >> >  From: Arnaud Patard <arnaud.patard@rtp-net.org>
> >> >  Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
> >
> >> >From != SOB.
> >
> > Arnaud, can you send your Signed-Off-By: for the patches you have sent?

> Signed-off-by: Arnaud Patard <arnaud.patard@rtp-net.org>

> Also, do you want me to reply to all your mails with the patches I've
> sent or adding my SOB here is enough for all ?

If you say this Signed-off-by: is covers all the patches in the series,
it is enough for me. If you want to be pedantic, you can reply to all of
them.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 08/21] Fix struct termios host - target translation
  2009-06-16  9:34         ` Riku Voipio
@ 2009-06-16 10:01           ` Arnaud Patard
  0 siblings, 0 replies; 40+ messages in thread
From: Arnaud Patard @ 2009-06-16 10:01 UTC (permalink / raw)
  To: Riku Voipio; +Cc: Blue Swirl, qemu-devel

Riku Voipio <riku.voipio@iki.fi> writes:

> On Tue, Jun 16, 2009 at 10:28:43AM +0200, Arnaud Patard wrote:
>> Riku Voipio <riku.voipio@iki.fi> writes:
>> Hi,
>> 
>> > On Sun, Jun 14, 2009 at 06:22:36PM +0300, Blue Swirl wrote:
>> >> On 6/12/09, riku.voipio@iki.fi <riku.voipio@iki.fi> wrote:
>> >> > From: Arnaud Patard <arnaud.patard@rtp-net.org>
>> >
>> >> >  When converting the termios structure between host and target in
>> >> >  target_to_host_termios and host_to_target_termios, the c_cc[] array is
>> >> >  never initialised.
>> >> >  Calling memset() before using it allows to run successfully "stty echo /
>> >> >  stty -echo" on arm-linux-user target (host being x86 and mips).
>> >> >
>> >> >  From: Arnaud Patard <arnaud.patard@rtp-net.org>
>> >> >  Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
>> >
>> >> >From != SOB.
>> >
>> > Arnaud, can you send your Signed-Off-By: for the patches you have sent?
>
>> Signed-off-by: Arnaud Patard <arnaud.patard@rtp-net.org>
>
>> Also, do you want me to reply to all your mails with the patches I've
>> sent or adding my SOB here is enough for all ?
>
> If you say this Signed-off-by: is covers all the patches in the series,
> it is enough for me. If you want to be pedantic, you can reply to all of
> them.

well, I wanted to avoid going through the mails and replying to them so
if saying that is enough, well... it's ok. This SOB applies to all of
them :)


Arnaud

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 00/21] Pending linux-user patches
  2009-06-15 15:10   ` Riku Voipio
@ 2009-06-16 16:30     ` Martin Mohring
  2009-06-16 16:45       ` Blue Swirl
  0 siblings, 1 reply; 40+ messages in thread
From: Martin Mohring @ 2009-06-16 16:30 UTC (permalink / raw)
  To: Riku Voipio; +Cc: Blue Swirl, qemu-devel

Riku Voipio wrote:
> On Sun, Jun 14, 2009 at 06:12:06PM +0300, Blue Swirl wrote:
>   
>> On 6/12/09, riku.voipio@iki.fi <riku.voipio@iki.fi> wrote:
>>     
>>> From: Riku Voipio <riku.voipio@iki.fi>
>>>
>>>  All the things in linux-user tree at the moment:
>>>
>>>  https://git.maemo.org/projects/qemu/gitweb?p=qemu;a=shortlog;h=refs/heads/linux-user-for-upstream
>>>
>>>  Since the maemo git hosting regrettably only provides https
>>>  transport, you can download the git tree faster if you already
>>>  have a git tree:
>>>
>>>  git clone git://git.sv.gnu.org/qemu.git
>>>  cd qemu
>>>  git remote add maemo https://git.maemo.org/projects/qemu
>>>  git fetch maemo
>>>  git checkout -b linux-user maemo/linux-user-for-upstream
>>>
>>>  This tree is constantly rebased against upstream git HEAD, so avoid basing your
>>>  work on this branch.
>>>       
>
>   
>> Constantly? It's already three days old. :-)
>>     
>
> More accurate would be "whenever there is updates in the upstream linux-user/
> subdir that require rebasing", but that might give some people the impression
> that it is actually rabased quite rarely ;-)
>
>   
>> Anyway, I pulled the patches with the intention of possibly committing
>> them. But it looks some of them are not ready yet.
>>     
>
> The "From:" fields were not intended as signed-off-by replacements, but rather
> to ensure that the authorship info is not lost. With the current mailer setup
> the email header "From:" on the patches sent to the mailing list shows my address,
> and I don't want to take anyones credit away.
>
> I'll have the look at the compiler warning, I didn't see any warnings on my build
> env(s) before mailing.
>   
Is there any chance to accept the bunch of these changes or any reason
to reject them? I was told by some maintainers that currently there is
no maintainer for user mode anymore. Is this true, and is this the
reason? Or is the user mode support "officially" dropped / running out?

I am just a bit confused about the slow acceptance of the user mode patches.

To sum it up: due to changes in the host linux systems, currently you
cannot run binaries anymore - even for ARM (e.g. because address 0 is
not mapped anymore in the host). Also, to run more recent glibc code,
the pending updates are needed to run these binaries in user mode.

Martin

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 00/21] Pending linux-user patches
  2009-06-16 16:30     ` Martin Mohring
@ 2009-06-16 16:45       ` Blue Swirl
  2009-06-16 17:03         ` Riku Voipio
  0 siblings, 1 reply; 40+ messages in thread
From: Blue Swirl @ 2009-06-16 16:45 UTC (permalink / raw)
  To: Martin Mohring; +Cc: Riku Voipio, qemu-devel

On 6/16/09, Martin Mohring <martin.mohring@opensuse.org> wrote:
> Riku Voipio wrote:
>  > On Sun, Jun 14, 2009 at 06:12:06PM +0300, Blue Swirl wrote:
>  >
>  >> On 6/12/09, riku.voipio@iki.fi <riku.voipio@iki.fi> wrote:
>  >>
>  >>> From: Riku Voipio <riku.voipio@iki.fi>
>  >>>
>  >>>  All the things in linux-user tree at the moment:
>  >>>
>  >>>  https://git.maemo.org/projects/qemu/gitweb?p=qemu;a=shortlog;h=refs/heads/linux-user-for-upstream
>  >>>
>  >>>  Since the maemo git hosting regrettably only provides https
>  >>>  transport, you can download the git tree faster if you already
>  >>>  have a git tree:
>  >>>
>  >>>  git clone git://git.sv.gnu.org/qemu.git
>  >>>  cd qemu
>  >>>  git remote add maemo https://git.maemo.org/projects/qemu
>  >>>  git fetch maemo
>  >>>  git checkout -b linux-user maemo/linux-user-for-upstream
>  >>>
>  >>>  This tree is constantly rebased against upstream git HEAD, so avoid basing your
>  >>>  work on this branch.
>  >>>
>  >
>  >
>  >> Constantly? It's already three days old. :-)
>  >>
>  >
>  > More accurate would be "whenever there is updates in the upstream linux-user/
>  > subdir that require rebasing", but that might give some people the impression
>  > that it is actually rabased quite rarely ;-)
>  >
>  >
>  >> Anyway, I pulled the patches with the intention of possibly committing
>  >> them. But it looks some of them are not ready yet.
>  >>
>  >
>  > The "From:" fields were not intended as signed-off-by replacements, but rather
>  > to ensure that the authorship info is not lost. With the current mailer setup
>  > the email header "From:" on the patches sent to the mailing list shows my address,
>  > and I don't want to take anyones credit away.
>  >
>  > I'll have the look at the compiler warning, I didn't see any warnings on my build
>  > env(s) before mailing.
>  >
>
> Is there any chance to accept the bunch of these changes or any reason
>  to reject them? I was told by some maintainers that currently there is
>  no maintainer for user mode anymore. Is this true, and is this the
>  reason? Or is the user mode support "officially" dropped / running out?

After the problems are fixed, I'll commit the fixed ones unless there
are objections.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 00/21] Pending linux-user patches
  2009-06-16 16:45       ` Blue Swirl
@ 2009-06-16 17:03         ` Riku Voipio
  0 siblings, 0 replies; 40+ messages in thread
From: Riku Voipio @ 2009-06-16 17:03 UTC (permalink / raw)
  To: Blue Swirl; +Cc: Martin Mohring, qemu-devel

On Tue, Jun 16, 2009 at 07:45:16PM +0300, Blue Swirl wrote:
> On 6/16/09, Martin Mohring <martin.mohring@opensuse.org> wrote:
> > Is there any chance to accept the bunch of these changes or any reason
> >  to reject them? I was told by some maintainers that currently there is
> >  no maintainer for user mode anymore. Is this true, and is this the
> >  reason? Or is the user mode support "officially" dropped / running out?

> After the problems are fixed, I'll commit the fixed ones unless there
> are objections.

I've collected the Signed-off-by:s and fixed the compiler warning. I also
decided to drop the guest_base patch to a separate branch, as it touches
TCG files. Although it is the "most wanted" patch, it should still be commited
by someone more closer to tcg in general.

The updated tree is available at the same place[1], after I have tested that
the refreshing hasn't broken anything, I'll send a pull request to the list.
Meanwhile, if you have any concerns on the individual patches, please comment
on this thread. The only functionally changed patch is splice/tee/vmsplice
patch.

[1] https://git.maemo.org/projects/qemu/gitweb?p=qemu;a=shortlog;h=refs/heads/linux-user-for-upstream

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 16/21] linux-user: implement pipe2 [v3]
  2009-06-12 13:50 ` [Qemu-devel] [PATCH 16/21] linux-user: implement pipe2 [v3] riku.voipio
@ 2009-06-16 21:44   ` Stuart Brady
  2009-06-17  2:31     ` Jamie Lokier
  0 siblings, 1 reply; 40+ messages in thread
From: Stuart Brady @ 2009-06-16 21:44 UTC (permalink / raw)
  To: qemu-devel

On Fri, Jun 12, 2009 at 04:50:26PM +0300, riku.voipio@iki.fi wrote:
> +static abi_long do_pipe2(int host_pipe[], int flags)
> +{
> +#ifdef CONFIG_PIPE2
> +    return pipe2(host_pipe, flags);
> +#else
> +    return -ENOSYS;
> +#endif
> +}
> +
> +static abi_long do_pipe(void *cpu_env, int pipedes, int flags)
> +{
> +    int host_pipe[2];
> +    abi_long ret;
> +    ret = flags ? do_pipe2(host_pipe, flags) : pipe(host_pipe);

This worries me slightly -- surely syscalls should be consistently
supported / not supported (where feasible), regardless of the precise
arguments that are supplied?  (Otherwise, any run-time check for pipe2
would get tricked if that check specifies 0 for flags.)

OTOH, I'm not sure what behaviour the library would provide for the
pipe2() function, if the pipe2 syscall is not available.  One could
that the pipe2() function is another matter entirely, and that QEMU
shouldn't be too concerned with its implementation, though.

Cheers,
-- 
Stuart Brady

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [Qemu-devel] [PATCH 16/21] linux-user: implement pipe2 [v3]
  2009-06-16 21:44   ` Stuart Brady
@ 2009-06-17  2:31     ` Jamie Lokier
  0 siblings, 0 replies; 40+ messages in thread
From: Jamie Lokier @ 2009-06-17  2:31 UTC (permalink / raw)
  To: Stuart Brady; +Cc: qemu-devel

Stuart Brady wrote:
> On Fri, Jun 12, 2009 at 04:50:26PM +0300, riku.voipio@iki.fi wrote:
> > +static abi_long do_pipe2(int host_pipe[], int flags)
> > +{
> > +#ifdef CONFIG_PIPE2
> > +    return pipe2(host_pipe, flags);
> > +#else
> > +    return -ENOSYS;
> > +#endif
> > +}
> > +
> > +static abi_long do_pipe(void *cpu_env, int pipedes, int flags)
> > +{
> > +    int host_pipe[2];
> > +    abi_long ret;
> > +    ret = flags ? do_pipe2(host_pipe, flags) : pipe(host_pipe);
> 
> This worries me slightly -- surely syscalls should be consistently
> supported / not supported (where feasible), regardless of the precise
> arguments that are supplied?  (Otherwise, any run-time check for pipe2
> would get tricked if that check specifies 0 for flags.)
> 
> OTOH, I'm not sure what behaviour the library would provide for the
> pipe2() function, if the pipe2 syscall is not available.  One could
> that the pipe2() function is another matter entirely, and that QEMU
> shouldn't be too concerned with its implementation, though.

As I've explained elsewhere, it is possible to emulate pipe2() and all
the other tricksy *CLOEXEC syscalls, but it must be done carefully to
provide the expected guarantees.

-- Jamie

^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2009-06-17  2:31 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-12 13:50 [Qemu-devel] [PATCH 00/21] Pending linux-user patches riku.voipio
2009-06-12 13:50 ` [Qemu-devel] [PATCH 01/21] export mmap_find_vma for shmat riku.voipio
2009-06-12 13:50 ` [Qemu-devel] [PATCH 02/21] Implement shm* syscalls and fix 64/32bit errors riku.voipio
2009-06-12 13:50 ` [Qemu-devel] [PATCH 03/21] linux-user: implemented ELF coredump support for ARM target riku.voipio
2009-06-14 15:16   ` Blue Swirl
2009-06-12 13:50 ` [Qemu-devel] [PATCH 04/21] linux-user: added x86 and x86_64 support for ELF coredump riku.voipio
2009-06-14 15:21   ` Blue Swirl
2009-06-12 13:50 ` [Qemu-devel] [PATCH 05/21] linux-user: strace now handles guest strings correctly [v2] riku.voipio
2009-06-14 15:17   ` Blue Swirl
2009-06-12 13:50 ` [Qemu-devel] [PATCH 06/21] Revived GUEST_BASE support for usermode emulation targets [v5] riku.voipio
2009-06-14 15:28   ` Blue Swirl
2009-06-12 13:50 ` [Qemu-devel] [PATCH 07/21] linux-user: fix utimensat riku.voipio
2009-06-12 13:50 ` [Qemu-devel] [PATCH 08/21] Fix struct termios host - target translation riku.voipio
2009-06-14 15:22   ` Blue Swirl
2009-06-15 15:36     ` Riku Voipio
2009-06-16  8:28       ` Arnaud Patard
2009-06-16  9:34         ` Riku Voipio
2009-06-16 10:01           ` Arnaud Patard
2009-06-12 13:50 ` [Qemu-devel] [PATCH 09/21] Return EOPNOTSUPP instead of ENOSYS for *xattr* syscalls riku.voipio
2009-06-12 13:50 ` [Qemu-devel] [PATCH 10/21] linux-user: Added IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP flags to setsockopt riku.voipio
2009-06-12 13:50 ` [Qemu-devel] [PATCH 11/21] linux-user: Added IP_(UN)BLOCK_SOURCE/IP_(ADD|DROP)_SOURCE_MEMBERSHIP " riku.voipio
2009-06-12 13:50 ` [Qemu-devel] [PATCH 12/21] linux-user: include linux/fs.h riku.voipio
2009-06-12 13:50 ` [Qemu-devel] [PATCH 13/21] linux-user: support private futexes riku.voipio
2009-06-12 13:50 ` [Qemu-devel] [PATCH 14/21] add futex wake op riku.voipio
2009-06-12 13:50 ` [Qemu-devel] [PATCH 15/21] linux-user: update syscall list riku.voipio
2009-06-12 13:50 ` [Qemu-devel] [PATCH 16/21] linux-user: implement pipe2 [v3] riku.voipio
2009-06-16 21:44   ` Stuart Brady
2009-06-17  2:31     ` Jamie Lokier
2009-06-12 13:50 ` [Qemu-devel] [PATCH 17/21] linux-user: add tee, splice and vmsplice riku.voipio
2009-06-14 15:25   ` Blue Swirl
2009-06-12 13:50 ` [Qemu-devel] [PATCH 18/21] RFC: fix fcntl support in linux-user - new try riku.voipio
2009-06-14 15:15   ` Blue Swirl
2009-06-12 13:50 ` [Qemu-devel] [PATCH 19/21] linux-user: initialize mmap_mutex properly riku.voipio
2009-06-12 13:50 ` [Qemu-devel] [PATCH 20/21] linux-user/syscall.c: define _ATFILE_SOURCE riku.voipio
2009-06-12 13:50 ` [Qemu-devel] [PATCH 21/21] linux-user: remove duplicate tswap32() from do_getsockopt() riku.voipio
2009-06-14 15:12 ` [Qemu-devel] [PATCH 00/21] Pending linux-user patches Blue Swirl
2009-06-15 15:10   ` Riku Voipio
2009-06-16 16:30     ` Martin Mohring
2009-06-16 16:45       ` Blue Swirl
2009-06-16 17:03         ` Riku Voipio

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.