Skip to contentSkip to conversation

Pending linux-user patches

PATCH In review [email protected] 2 participants 22 messages Jan 31, 2012

lore
Share & tools
lore
#0 lore raw

cover Pending linux-user patches

From: Riku Voipio <[email protected]>

The collection of simpler linux-user patches submitted since release of 1.0. To be sent as pull request later this week unless bugs found.

Patches are also available in the git repository at:
git://git.linaro.org/people/rikuvoipio/qemu.git linux-user-for-upstream

Akos PASZTORY (1):
linux-user: add SO_PEERCRED support for getsockopt

Alexander Graf (7):
linux-user: save auxv length
linux-user: add open() hijack infrastructure
linux-user: fake /proc/self/maps
linux-user: fake /proc/self/stat
linux-user: fake /proc/self/auxv
linux-user: fix QEMU_STRACE=1 segfault
linux-user: fix wait* syscall status returns

Andreas Färber (5):
linux-user: Add default-configs for mipsn32[el]
linux-user: Add default configs for mips64[el]
linux-user: Define TARGET_QEMU_ESIGRETURN for mipsn32
linux-user: Define TARGET_QEMU_ESIGRETURN for mips64
linux-user: Fix sa_flags byte swaps for mips

Peter Maydell (4):
linux-user/strace.c: Correct errno printing for mmap etc
linux-user: Allow NULL value pointer in setxattr and getxattr linux-user/syscall.c: Implement f and l versions of
set/get/removexattr
linux-user: Implement *listxattr syscalls

Riku Voipio (1):
linux-user: stack_base is now mandatory on all targets

陳韋任 (1):
linux-user/main.c: Add option to user-mode emulation so that user can
specify log file name

 default-configs/mips64-linux-user.mak    |    1 +
 default-configs/mips64el-linux-user.mak  |    1 +
 default-configs/mipsn32-linux-user.mak   |    1 +
 default-configs/mipsn32el-linux-user.mak |    1 +
 linux-user/elfload.c                     |   15 +-
 linux-user/main.c                        |    7 +
 linux-user/mips64/syscall.h              |    3 +
 linux-user/mipsn32/syscall.h             |    3 +
 linux-user/qemu.h                        |    3 +-
 linux-user/signal.c                      |    8 +
 linux-user/strace.c                      |   19 ++-
 linux-user/syscall.c                     |  303 +++++++++++++++++++++++++++---
 linux-user/syscall_defs.h                |    6 +
 13 files changed, 332 insertions(+), 39 deletions(-)
 create mode 100644 default-configs/mips64-linux-user.mak
 create mode 100644 default-configs/mips64el-linux-user.mak
 create mode 100644 default-configs/mipsn32-linux-user.mak
 create mode 100644 default-configs/mipsn32el-linux-user.mak
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH 1/19 linux-user: stack_base is now mandatory on all targets

From: Riku Voipio <[email protected]>

---
 linux-user/qemu.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
linux-user/qemu.h +1 -1
index 55ad9d8..30e2abd 100644
@@ -123,10 +123,10 @@ typedef struct TaskState {
 #endif
 #if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32)
     /* Extra fields for semihosted binaries.  */
-    uint32_t stack_base;
     uint32_t heap_base;
     uint32_t heap_limit;
 #endif
+    uint32_t stack_base;
     int used; /* non zero if used */
     struct image_info *info;
     struct linux_binprm *bprm;
Signature · 1 line
1.7.5.4
#2 lore raw

Re: [Qemu-devel] [PATCH 01/19] linux-user: stack_base is now mandatory on all targets

Am 31.01.2012 10:29, schrieb [email protected]:

Quoted 2 lines

From: Riku Voipio <[email protected]>

SoB missing.

Andreas

Quoted 20 lines
---
 linux-user/qemu.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
linux-user/qemu.h +1 -1
index 55ad9d8..30e2abd 100644
@@ -123,10 +123,10 @@ typedef struct TaskState {
 #endif
 #if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32)
     /* Extra fields for semihosted binaries.  */
-    uint32_t stack_base;
     uint32_t heap_base;
     uint32_t heap_limit;
 #endif
+    uint32_t stack_base;
     int used; /* non zero if used */
     struct image_info *info;
     struct linux_binprm *bprm;
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw

PATCH 2/19 linux-user: save auxv length

In reply to [email protected]

From: Alexander Graf <[email protected]>

We create our own AUXV segment on stack and save a pointer to it. However we don't save the length of it, so any code that wants to do anything useful with it later on has to walk it again.

Instead, let's remember the length of our AUXV segment. This simplifies later uses by a lot.

(edited by Riku to apply to qemu HEAD)

---
 linux-user/elfload.c |   15 ++++-----------
 linux-user/qemu.h    |    1 +
 2 files changed, 5 insertions(+), 11 deletions(-)
linux-user/elfload.c +4 -11
index 845be8b..2fd4a93 100644
@@ -1245,6 +1245,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
                                    struct image_info *interp_info)
 {
     abi_ulong sp;
+    abi_ulong sp_auxv;
     int size;
     int i;
     abi_ulong u_rand_bytes;
@@ -1316,6 +1317,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
         sp -= n; put_user_ual(id, sp);          \
     } while(0)
 
+    sp_auxv = sp;
     NEW_AUX_ENT (AT_NULL, 0);
 
     /* There must be exactly DLINFO_ITEMS entries here.  */
@@ -1346,6 +1348,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
 #undef NEW_AUX_ENT
 
     info->saved_auxv = sp;
+    info->auxv_len = sp_auxv - sp;
 
     sp = loader_build_argptr(envc, argc, sp, p, 0);
     return sp;
@@ -2326,9 +2329,8 @@ 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;
+    int len = ts->info->auxv_len;
 
     /*
      * Auxiliary vector is stored in target process stack.  It contains
@@ -2336,15 +2338,6 @@ static void fill_auxv_note(struct memelfnote *note, const TaskState *ts)
      * strictly necessary but we do it here for sake of completeness.
      */
 
-    /* find out length 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) {
linux-user/qemu.h +1 -0
index 30e2abd..308dbc0 100644
@@ -48,6 +48,7 @@ struct image_info {
         abi_ulong       code_offset;
         abi_ulong       data_offset;
         abi_ulong       saved_auxv;
+        abi_ulong       auxv_len;
         abi_ulong       arg_start;
         abi_ulong       arg_end;
 	int		personality;
Signature · 1 line
1.7.5.4
#4 lore raw

PATCH 3/19 linux-user: add open() hijack infrastructure

In reply to [email protected]

From: Alexander Graf <[email protected]>

There are a number of files in /proc that expose host information to the guest program. This patch adds infrastructure to override the open() syscall for guest programs to enable us to on the fly generate guest sensible files.

---
 linux-user/syscall.c |   52 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 49 insertions(+), 3 deletions(-)
linux-user/syscall.c +49 -3
index 2bf9e7e..e100025 100644
@@ -4600,6 +4600,52 @@ int get_osversion(void)
     return osversion;
 }
 
+static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
+{
+    struct fake_open {
+        const char *filename;
+        int (*fill)(void *cpu_env, int fd);
+    };
+    const struct fake_open *fake_open;
+    static const struct fake_open fakes[] = {
+        { NULL, NULL }
+    };
+
+    for (fake_open = fakes; fake_open->filename; fake_open++) {
+        if (!strncmp(pathname, fake_open->filename,
+                     strlen(fake_open->filename))) {
+            break;
+        }
+    }
+
+    if (fake_open->filename) {
+        const char *tmpdir;
+        char filename[PATH_MAX];
+        int fd, r;
+
+        /* create temporary file to map stat to */
+        tmpdir = getenv("TMPDIR");
+        if (!tmpdir)
+            tmpdir = "/tmp";
+        snprintf(filename, sizeof(filename), "%s/qemu-open.XXXXXX", tmpdir);
+        fd = mkstemp(filename);
+        if (fd < 0) {
+            return fd;
+        }
+        unlink(filename);
+
+        if ((r = fake_open->fill(cpu_env, fd))) {
+            close(fd);
+            return r;
+        }
+        lseek(fd, 0, SEEK_SET);
+
+        return fd;
+    }
+
+    return get_errno(open(path(pathname), flags, mode));
+}
+
 /* do_syscall() should always have a single exit point at the end so
    that actions, such as logging of syscall results, can be performed.
    All errnos that do_syscall() returns must be -TARGET_<errcode>. */
@@ -4685,9 +4731,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_open:
         if (!(p = lock_user_string(arg1)))
             goto efault;
-        ret = get_errno(open(path(p),
-                             target_to_host_bitmask(arg2, fcntl_flags_tbl),
-                             arg3));
+        ret = get_errno(do_open(cpu_env, p,
+                                target_to_host_bitmask(arg2, fcntl_flags_tbl),
+                                arg3));
         unlock_user(p, arg1, 0);
         break;
 #if defined(TARGET_NR_openat) && defined(__NR_openat)
Signature · 1 line
1.7.5.4
#5 lore raw

PATCH 4/19 linux-user: fake /proc/self/maps

In reply to [email protected]

From: Alexander Graf <[email protected]>

glibc's pthread_attr_getstack tries to find the stack range from /proc/self/maps. Unfortunately, /proc is usually the host's /proc which means linux-user guests see qemu's stack there.

Fake the file with a constructed maps entry that exposes the guest's stack range.

---
 linux-user/syscall.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
linux-user/syscall.c +15 -0
index e100025..1864d7f 100644
@@ -4600,6 +4600,20 @@ int get_osversion(void)
     return osversion;
 }
 
+
+static int open_self_maps(void *cpu_env, int fd)
+{
+    TaskState *ts = ((CPUState *)cpu_env)->opaque;
+
+    dprintf(fd, "%08llx-%08llx rw-p %08llx 00:00 0          [stack]\n",
+                (unsigned long long)ts->info->stack_limit,
+                (unsigned long long)(ts->stack_base + (TARGET_PAGE_SIZE - 1))
+                                     & TARGET_PAGE_MASK,
+                (unsigned long long)ts->stack_base);
+
+    return 0;
+}
+
 static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
 {
     struct fake_open {
@@ -4608,6 +4622,7 @@ static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
     };
     const struct fake_open *fake_open;
     static const struct fake_open fakes[] = {
+        { "/proc/self/maps", open_self_maps },
         { NULL, NULL }
     };
 
Signature · 1 line
1.7.5.4
#6 lore raw

PATCH 5/19 linux-user: fake /proc/self/stat

In reply to [email protected]

From: Alexander Graf <[email protected]>

The boehm gc finds the program's stack starting pointer by checking /proc/self/stat. Unfortunately, so far it reads qemu's stack pointer which clearly is wrong.

So let's instead fake the file so the guest program sees the right address.

---
 linux-user/syscall.c |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
linux-user/syscall.c +26 -0
index 1864d7f..5a5fdac 100644
@@ -4614,6 +4614,31 @@ static int open_self_maps(void *cpu_env, int fd)
     return 0;
 }
 
+static int open_self_stat(void *cpu_env, int fd)
+{
+    TaskState *ts = ((CPUState *)cpu_env)->opaque;
+    abi_ulong start_stack = ts->info->start_stack;
+    int i;
+
+    for (i = 0; i < 44; i++) {
+      char buf[128];
+      int len;
+      uint64_t val = 0;
+
+      if (i == 27) {
+          /* stack bottom */
+          val = start_stack;
+      }
+      snprintf(buf, sizeof(buf), "%"PRId64 "%c", val, i == 43 ? '\n' : ' ');
+      len = strlen(buf);
+      if (write(fd, buf, len) != len) {
+          return -1;
+      }
+    }
+
+    return 0;
+}
+
 static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
 {
     struct fake_open {
@@ -4623,6 +4648,7 @@ static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
     const struct fake_open *fake_open;
     static const struct fake_open fakes[] = {
         { "/proc/self/maps", open_self_maps },
+        { "/proc/self/stat", open_self_stat },
         { NULL, NULL }
     };
 
Signature · 1 line
1.7.5.4
#7 lore raw

PATCH 6/19 linux-user: fake /proc/self/auxv

In reply to [email protected]

From: Alexander Graf <[email protected]>

Gtk tries to read /proc/self/auxv to find its auxv table instead of taking it from its own program memory space.

However, when running with linux-user, we see the host's auxv which clearly exposes wrong information. so let's instead expose the guest memory backed auxv tables via /proc/self/auxv as well.

---
 linux-user/syscall.c |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)
linux-user/syscall.c +30 -0
index 5a5fdac..c6bfcd8 100644
@@ -4639,6 +4639,35 @@ static int open_self_stat(void *cpu_env, int fd)
     return 0;
 }
 
+static int open_self_auxv(void *cpu_env, int fd)
+{
+    TaskState *ts = ((CPUState *)cpu_env)->opaque;
+    abi_ulong auxv = ts->info->saved_auxv;
+    abi_ulong len = ts->info->auxv_len;
+    char *ptr;
+
+    /*
+     * Auxiliary vector is stored in target process stack.
+     * read in whole auxv vector and copy it to file
+     */
+    ptr = lock_user(VERIFY_READ, auxv, len, 0);
+    if (ptr != NULL) {
+        while (len > 0) {
+            ssize_t r;
+            r = write(fd, ptr, len);
+            if (r <= 0) {
+                break;
+            }
+            len -= r;
+            ptr += r;
+        }
+        lseek(fd, 0, SEEK_SET);
+        unlock_user(ptr, auxv, len);
+    }
+
+    return 0;
+}
+
 static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
 {
     struct fake_open {
@@ -4649,6 +4678,7 @@ static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
     static const struct fake_open fakes[] = {
         { "/proc/self/maps", open_self_maps },
         { "/proc/self/stat", open_self_stat },
+        { "/proc/self/auxv", open_self_auxv },
         { NULL, NULL }
     };
 
Signature · 1 line
1.7.5.4
#8 lore raw

PATCH 7/19 linux-user/main.c: Add option to user-mode emulation so that user can specify log file name

In reply to [email protected]

From: 陳韋任 <[email protected]>

QEMU linux user-mode's default log file name is "/tmp/qemu.log". In order to
change the log file name, user need to modify the source code then recompile QEMU. This patch allow user use "-D logfile" option to specify the log file name.

---
 linux-user/main.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
linux-user/main.c +7 -0
index 64d2208..14bf5f0 100644
@@ -2945,6 +2945,11 @@ static void handle_arg_log(const char *arg)
     cpu_set_log(mask);
 }
 
+static void handle_arg_log_filename(const char *arg)
+{
+    cpu_set_log_filename(arg);
+}
+
 static void handle_arg_set_env(const char *arg)
 {
     char *r, *p, *token;
@@ -3125,6 +3130,8 @@ struct qemu_argument arg_table[] = {
 #endif
     {"d",          "QEMU_LOG",         true,  handle_arg_log,
      "options",    "activate log"},
+    {"D",          "QEMU_LOG_FILENAME", true, handle_arg_log_filename,
+     "logfile",     "override default logfile location"},
     {"p",          "QEMU_PAGESIZE",    true,  handle_arg_pagesize,
      "pagesize",   "set the host page size to 'pagesize'"},
     {"singlestep", "QEMU_SINGLESTEP",  false, handle_arg_singlestep,
Signature · 1 line
1.7.5.4
#9 lore raw

PATCH 8/19 linux-user: add SO_PEERCRED support for getsockopt

In reply to [email protected]

From: Akos PASZTORY <[email protected]>

---
 linux-user/syscall.c      |   34 +++++++++++++++++++++++++++++++++-
 linux-user/syscall_defs.h |    6 ++++++
 2 files changed, 39 insertions(+), 1 deletions(-)
linux-user/syscall.c +33 -1
index c6bfcd8..15b8b22 100644
@@ -1530,9 +1530,41 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
         case TARGET_SO_LINGER:
         case TARGET_SO_RCVTIMEO:
         case TARGET_SO_SNDTIMEO:
-        case TARGET_SO_PEERCRED:
         case TARGET_SO_PEERNAME:
             goto unimplemented;
+        case TARGET_SO_PEERCRED: {
+            struct ucred cr;
+            socklen_t crlen;
+            struct target_ucred *tcr;
+
+            if (get_user_u32(len, optlen)) {
+                return -TARGET_EFAULT;
+            }
+            if (len < 0) {
+                return -TARGET_EINVAL;
+            }
+
+            crlen = sizeof(cr);
+            ret = get_errno(getsockopt(sockfd, level, SO_PEERCRED,
+                                       &cr, &crlen));
+            if (ret < 0) {
+                return ret;
+            }
+            if (len > crlen) {
+                len = crlen;
+            }
+            if (!lock_user_struct(VERIFY_WRITE, tcr, optval_addr, 0)) {
+                return -TARGET_EFAULT;
+            }
+            __put_user(cr.pid, &tcr->pid);
+            __put_user(cr.uid, &tcr->uid);
+            __put_user(cr.gid, &tcr->gid);
+            unlock_user_struct(tcr, optval_addr, 1);
+            if (put_user_u32(len, optlen)) {
+                return -TARGET_EFAULT;
+            }
+            break;
+        }
         /* Options with 'int' argument.  */
         case TARGET_SO_DEBUG:
             optname = SO_DEBUG;
linux-user/syscall_defs.h +6 -0
index 2857805..41f0ff8 100644
@@ -2336,3 +2336,9 @@ struct target_rlimit64 {
     uint64_t rlim_cur;
     uint64_t rlim_max;
 };
+
+struct target_ucred {
+    uint32_t pid;
+    uint32_t uid;
+    uint32_t gid;
+};
Signature · 1 line
1.7.5.4
#10 lore raw

PATCH 9/19 linux-user: fix QEMU_STRACE=1 segfault

In reply to [email protected]

From: Alexander Graf <[email protected]>

While debugging some issues with QEMU_STRACE I stumbled over segmentation faults that were pretty reproducible. Turns out we tried to treat a normal return value as errno, resulting in an access over array boundaries for the resolution.

Fix this by allowing failure to resolve invalid errnos into strings.

---
 linux-user/strace.c  |   18 ++++++++++++++----
 linux-user/syscall.c |    3 +++
 2 files changed, 17 insertions(+), 4 deletions(-)
linux-user/strace.c +14 -4
index 90027a1..269481e 100644
@@ -284,8 +284,13 @@ print_ipc(const struct syscallname *name,
 static void
 print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
 {
-if( ret == -1 ) {
-        gemu_log(" = -1 errno=%d (%s)\n", errno, target_strerror(errno));
+    char *errstr = NULL;
+
+    if (ret == -1) {
+        errstr = target_strerror(errno);
+    }
+    if ((ret == -1) && errstr) {
+        gemu_log(" = -1 errno=%d (%s)\n", errno, errstr);
     } else {
         gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
     }
@@ -1515,14 +1520,19 @@ void
 print_syscall_ret(int num, abi_long ret)
 {
     int i;
+    char *errstr = NULL;
 
     for(i=0;i<nsyscalls;i++)
         if( scnames[i].nr == num ) {
             if( scnames[i].result != NULL ) {
                 scnames[i].result(&scnames[i],ret);
             } else {
-                if( ret < 0 ) {
-                    gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n", -ret, target_strerror(-ret));
+                if (ret < 0) {
+                    errstr = target_strerror(-ret);
+                }
+                if (errstr) {
+                    gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n",
+                             -ret, errstr);
                 } else {
                     gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
                 }
linux-user/syscall.c +3 -0
index 15b8b22..29d92c4 100644
@@ -731,6 +731,9 @@ static inline int is_error(abi_long ret)
 
 char *target_strerror(int err)
 {
+    if ((err >= ERRNO_TABLE_SIZE) || (err < 0)) {
+        return NULL;
+    }
     return strerror(target_to_host_errno(err));
 }
 
Signature · 1 line
1.7.5.4
#11 lore raw

PATCH 10/19 linux-user/strace.c: Correct errno printing for mmap etc

In reply to [email protected]

From: Peter Maydell <[email protected]>

Correct the printing of errnos for syscalls which are handled via print_syscall_ret_addr (mmap, mmap2, brk, shmat): errnos are returned as negative returned values at this level, not via the host 'errno' variable.

---
 linux-user/strace.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
linux-user/strace.c +4 -5
index 269481e..05a0d3e 100644
@@ -1,5 +1,4 @@
 #include <stdio.h>
-#include <errno.h>
 #include <sys/ipc.h>
 #include <sys/msg.h>
 #include <sys/sem.h>
@@ -286,11 +285,11 @@ print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
 {
     char *errstr = NULL;
 
-    if (ret == -1) {
-        errstr = target_strerror(errno);
+    if (ret < 0) {
+        errstr = target_strerror(-ret);
     }
-    if ((ret == -1) && errstr) {
-        gemu_log(" = -1 errno=%d (%s)\n", errno, errstr);
+    if (errstr) {
+        gemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
     } else {
         gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
     }
Signature · 1 line
1.7.5.4
#12 lore raw

PATCH 11/19 linux-user: fix wait* syscall status returns

In reply to [email protected]

From: Alexander Graf <[email protected]>

When calling wait4 or waitpid with a status pointer and WNOHANG, the syscall can potentially not modify the status pointer input. Now if we have guest code like:

  int status = 0;
  waitpid(pid, &status, WNOHANG);
  if (status)
     <breakage>

then we have to make sure that in case status did not change we actually return the guest's initialized status variable instead of our own uninitialized. We fail to do so today, as we proxy everything through an uninitialized status variable which for me ended up always containing the last error code.

This patch fixes some test cases when building yast2-core in OBS for ARM.

---
 linux-user/syscall.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
linux-user/syscall.c +2 -2
index 29d92c4..06b19e0 100644
@@ -4867,7 +4867,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         {
             int status;
             ret = get_errno(waitpid(arg1, &status, arg3));
-            if (!is_error(ret) && arg2
+            if (!is_error(ret) && arg2 && ret
                 && put_user_s32(host_to_target_waitstatus(status), arg2))
                 goto efault;
         }
@@ -6423,7 +6423,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
                 rusage_ptr = NULL;
             ret = get_errno(wait4(arg1, &status, arg3, rusage_ptr));
             if (!is_error(ret)) {
-                if (status_ptr) {
+                if (status_ptr && ret) {
                     status = host_to_target_waitstatus(status);
                     if (put_user_s32(status, status_ptr))
                         goto efault;
Signature · 1 line
1.7.5.4
#13 lore raw

PATCH 12/19 linux-user: Allow NULL value pointer in setxattr and getxattr

In reply to [email protected]

From: Peter Maydell <[email protected]>

It's valid to pass a NULL value pointer to setxattr, so don't fail this case EFAULT.

---
 linux-user/syscall.c |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)
linux-user/syscall.c +18 -6
index 06b19e0..0a78a18 100644
@@ -7809,11 +7809,17 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
     case TARGET_NR_setxattr:
         {
-            void *p, *n, *v;
+            void *p, *n, *v = 0;
+            if (arg3) {
+                v = lock_user(VERIFY_READ, arg3, arg4, 1);
+                if (!v) {
+                    ret = -TARGET_EFAULT;
+                    break;
+                }
+            }
             p = lock_user_string(arg1);
             n = lock_user_string(arg2);
-            v = lock_user(VERIFY_READ, arg3, arg4, 1);
-            if (p && n && v) {
+            if (p && n) {
                 ret = get_errno(setxattr(p, n, v, arg4, arg5));
             } else {
                 ret = -TARGET_EFAULT;
@@ -7825,11 +7831,17 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
     case TARGET_NR_getxattr:
         {
-            void *p, *n, *v;
+            void *p, *n, *v = 0;
+            if (arg3) {
+                v = lock_user(VERIFY_WRITE, arg3, arg4, 0);
+                if (!v) {
+                    ret = -TARGET_EFAULT;
+                    break;
+                }
+            }
             p = lock_user_string(arg1);
             n = lock_user_string(arg2);
-            v = lock_user(VERIFY_WRITE, arg3, arg4, 0);
-            if (p && n && v) {
+            if (p && n) {
                 ret = get_errno(getxattr(p, n, v, arg4));
             } else {
                 ret = -TARGET_EFAULT;
Signature · 1 line
1.7.5.4
#14 lore raw

PATCH 13/19 linux-user/syscall.c: Implement f and l versions of set/get/removexattr

In reply to [email protected]

From: Peter Maydell <[email protected]>

Implement the f and l versions (operate on fd, don't follow links) of the setxattr, getxattr and removexattr syscalls.

---
 linux-user/syscall.c |   79 ++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 70 insertions(+), 9 deletions(-)
linux-user/syscall.c +70 -9
index 0a78a18..762115b 100644
@@ -7796,18 +7796,13 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 #endif
 #ifdef CONFIG_ATTR
 #ifdef TARGET_NR_setxattr
-    case TARGET_NR_lsetxattr:
-    case TARGET_NR_fsetxattr:
-    case TARGET_NR_lgetxattr:
-    case TARGET_NR_fgetxattr:
     case TARGET_NR_listxattr:
     case TARGET_NR_llistxattr:
     case TARGET_NR_flistxattr:
-    case TARGET_NR_lremovexattr:
-    case TARGET_NR_fremovexattr:
         ret = -TARGET_EOPNOTSUPP;
         break;
     case TARGET_NR_setxattr:
+    case TARGET_NR_lsetxattr:
         {
             void *p, *n, *v = 0;
             if (arg3) {
@@ -7820,7 +7815,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             p = lock_user_string(arg1);
             n = lock_user_string(arg2);
             if (p && n) {
-                ret = get_errno(setxattr(p, n, v, arg4, arg5));
+                if (num == TARGET_NR_setxattr) {
+                    ret = get_errno(setxattr(p, n, v, arg4, arg5));
+                } else {
+                    ret = get_errno(lsetxattr(p, n, v, arg4, arg5));
+                }
             } else {
                 ret = -TARGET_EFAULT;
             }
@@ -7829,7 +7828,28 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             unlock_user(v, arg3, 0);
         }
         break;
+    case TARGET_NR_fsetxattr:
+        {
+            void *n, *v = 0;
+            if (arg3) {
+                v = lock_user(VERIFY_READ, arg3, arg4, 1);
+                if (!v) {
+                    ret = -TARGET_EFAULT;
+                    break;
+                }
+            }
+            n = lock_user_string(arg2);
+            if (n) {
+                ret = get_errno(fsetxattr(arg1, n, v, arg4, arg5));
+            } else {
+                ret = -TARGET_EFAULT;
+            }
+            unlock_user(n, arg2, 0);
+            unlock_user(v, arg3, 0);
+        }
+        break;
     case TARGET_NR_getxattr:
+    case TARGET_NR_lgetxattr:
         {
             void *p, *n, *v = 0;
             if (arg3) {
@@ -7842,7 +7862,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             p = lock_user_string(arg1);
             n = lock_user_string(arg2);
             if (p && n) {
-                ret = get_errno(getxattr(p, n, v, arg4));
+                if (num == TARGET_NR_getxattr) {
+                    ret = get_errno(getxattr(p, n, v, arg4));
+                } else {
+                    ret = get_errno(lgetxattr(p, n, v, arg4));
+                }
             } else {
                 ret = -TARGET_EFAULT;
             }
@@ -7851,13 +7875,38 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             unlock_user(v, arg3, arg4);
         }
         break;
+    case TARGET_NR_fgetxattr:
+        {
+            void *n, *v = 0;
+            if (arg3) {
+                v = lock_user(VERIFY_WRITE, arg3, arg4, 0);
+                if (!v) {
+                    ret = -TARGET_EFAULT;
+                    break;
+                }
+            }
+            n = lock_user_string(arg2);
+            if (n) {
+                ret = get_errno(fgetxattr(arg1, n, v, arg4));
+            } else {
+                ret = -TARGET_EFAULT;
+            }
+            unlock_user(n, arg2, 0);
+            unlock_user(v, arg3, arg4);
+        }
+        break;
     case TARGET_NR_removexattr:
+    case TARGET_NR_lremovexattr:
         {
             void *p, *n;
             p = lock_user_string(arg1);
             n = lock_user_string(arg2);
             if (p && n) {
-                ret = get_errno(removexattr(p, n));
+                if (num == TARGET_NR_removexattr) {
+                    ret = get_errno(removexattr(p, n));
+                } else {
+                    ret = get_errno(lremovexattr(p, n));
+                }
             } else {
                 ret = -TARGET_EFAULT;
             }
@@ -7865,6 +7914,18 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             unlock_user(n, arg2, 0);
         }
         break;
+    case TARGET_NR_fremovexattr:
+        {
+            void *n;
+            n = lock_user_string(arg2);
+            if (n) {
+                ret = get_errno(fremovexattr(arg1, n));
+            } else {
+                ret = -TARGET_EFAULT;
+            }
+            unlock_user(n, arg2, 0);
+        }
+        break;
 #endif
 #endif /* CONFIG_ATTR */
 #ifdef TARGET_NR_set_thread_area
Signature · 1 line
1.7.5.4
#15 lore raw

PATCH 14/19 linux-user: Implement *listxattr syscalls

In reply to [email protected]

From: Peter Maydell <[email protected]>

Implement listxattr, flistxattr and llistxattr syscalls.

---
 linux-user/syscall.c |   36 +++++++++++++++++++++++++++++++++++-
 1 files changed, 35 insertions(+), 1 deletions(-)
linux-user/syscall.c +35 -1
index 762115b..ee8899e 100644
@@ -7798,9 +7798,43 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 #ifdef TARGET_NR_setxattr
     case TARGET_NR_listxattr:
     case TARGET_NR_llistxattr:
+    {
+        void *p, *b = 0;
+        if (arg2) {
+            b = lock_user(VERIFY_WRITE, arg2, arg3, 0);
+            if (!b) {
+                ret = -TARGET_EFAULT;
+                break;
+            }
+        }
+        p = lock_user_string(arg1);
+        if (p) {
+            if (num == TARGET_NR_listxattr) {
+                ret = get_errno(listxattr(p, b, arg3));
+            } else {
+                ret = get_errno(llistxattr(p, b, arg3));
+            }
+        } else {
+            ret = -TARGET_EFAULT;
+        }
+        unlock_user(p, arg1, 0);
+        unlock_user(b, arg2, arg3);
+        break;
+    }
     case TARGET_NR_flistxattr:
-        ret = -TARGET_EOPNOTSUPP;
+    {
+        void *b = 0;
+        if (arg2) {
+            b = lock_user(VERIFY_WRITE, arg2, arg3, 0);
+            if (!b) {
+                ret = -TARGET_EFAULT;
+                break;
+            }
+        }
+        ret = get_errno(flistxattr(arg1, b, arg3));
+        unlock_user(b, arg2, arg3);
         break;
+    }
     case TARGET_NR_setxattr:
     case TARGET_NR_lsetxattr:
         {
Signature · 1 line
1.7.5.4
#16 lore raw

PATCH 15/19 linux-user: Add default-configs for mipsn32[el]

In reply to [email protected]

From: Andreas Färber <[email protected]>

Prepares for mipsn32[el]-linux-user targets.

---
 default-configs/mipsn32-linux-user.mak   |    1 +
 default-configs/mipsn32el-linux-user.mak |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 default-configs/mipsn32-linux-user.mak
 create mode 100644 default-configs/mipsn32el-linux-user.mak
default-configs/mipsn32-linux-user.mak new file +1 -0
new file mode 100644
index 0000000..5b97919
@@ -0,0 +1 @@
+# Default configuration for mipsn32-linux-user
default-configs/mipsn32el-linux-user.mak new file +1 -0
new file mode 100644
index 0000000..d6367ff
@@ -0,0 +1 @@
+# Default configuration for mipsn32el-linux-user
Signature · 1 line
1.7.5.4
#17 lore raw

PATCH 16/19 linux-user: Add default configs for mips64[el]

In reply to [email protected]

From: Andreas Färber <[email protected]>

Prepares for mips64[el]-linux-user targets.

---
 default-configs/mips64-linux-user.mak   |    1 +
 default-configs/mips64el-linux-user.mak |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 default-configs/mips64-linux-user.mak
 create mode 100644 default-configs/mips64el-linux-user.mak
default-configs/mips64-linux-user.mak new file +1 -0
new file mode 100644
index 0000000..1598bfc
@@ -0,0 +1 @@
+# Default configuration for mips64-linux-user
default-configs/mips64el-linux-user.mak new file +1 -0
new file mode 100644
index 0000000..629f084
@@ -0,0 +1 @@
+# Default configuration for mips64el-linux-user
Signature · 1 line
1.7.5.4
#18 lore raw

PATCH 17/19 linux-user: Define TARGET_QEMU_ESIGRETURN for mipsn32

In reply to [email protected]

From: Andreas Färber <[email protected]>

Copied from mips/syscall.h.

---
 linux-user/mipsn32/syscall.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
linux-user/mipsn32/syscall.h +3 -0
index 4ec506c..ebe98f2 100644
@@ -218,4 +218,7 @@ struct target_pt_regs {
 
 
 
+/* Nasty hack: define a fake errno value for use by sigreturn. */
+#define TARGET_QEMU_ESIGRETURN 255
+
 #define UNAME_MACHINE "mips64"
Signature · 1 line
1.7.5.4
#19 lore raw

PATCH 18/19 linux-user: Define TARGET_QEMU_ESIGRETURN for mips64

In reply to [email protected]

From: Andreas Färber <[email protected]>

Copied from mips/syscall.h.

---
 linux-user/mips64/syscall.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
linux-user/mips64/syscall.h +3 -0
index 668a2b9..e436ea5 100644
@@ -218,4 +218,7 @@ struct target_pt_regs {
 
 
 
+/* Nasty hack: define a fake errno value for use by sigreturn. */
+#define TARGET_QEMU_ESIGRETURN 255
+
 #define UNAME_MACHINE "mips64"
Signature · 1 line
1.7.5.4
#20 lore raw

PATCH 19/19 linux-user: Fix sa_flags byte swaps for mips

In reply to [email protected]

From: Andreas Färber <[email protected]>

sa_flags is uint32_t for mips{,n32,64}, so don't use tswapal().

edited by Riku Voipio: likewise on alpha

---
 linux-user/signal.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
linux-user/signal.c +8 -0
index ded12ca..79a39dc 100644
@@ -587,7 +587,11 @@ int do_sigaction(int sig, const struct target_sigaction *act,
 #endif
     if (oact) {
         oact->_sa_handler = tswapal(k->_sa_handler);
+#if defined(TARGET_MIPS) || defined (TARGET_ALPHA)
+        oact->sa_flags = bswap32(k->sa_flags);
+#else
         oact->sa_flags = tswapal(k->sa_flags);
+#endif
 #if !defined(TARGET_MIPS)
         oact->sa_restorer = tswapal(k->sa_restorer);
 #endif
@@ -596,7 +600,11 @@ int do_sigaction(int sig, const struct target_sigaction *act,
     if (act) {
         /* FIXME: This is not threadsafe.  */
         k->_sa_handler = tswapal(act->_sa_handler);
+#if defined(TARGET_MIPS) || defined (TARGET_ALPHA)
+        k->sa_flags = bswap32(act->sa_flags);
+#else
         k->sa_flags = tswapal(act->sa_flags);
+#endif
 #if !defined(TARGET_MIPS)
         k->sa_restorer = tswapal(act->sa_restorer);
 #endif
Signature · 1 line
1.7.5.4
#21 lore raw
In reply to [email protected]

Riku,

Am 31.01.2012 10:29, schrieb [email protected]:

Quoted 4 lines

From: Riku Voipio <[email protected]>

The collection of simpler linux-user patches submitted since release of 1.0. To be sent as pull request later this week unless bugs found.

What about this one?

http://patchwork.ozlabs.org/patch/117176/

It might also be a place for Laurent to pass -cpu for his use case, no?

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg