Skip to contentSkip to conversation

linux-user: Split do_syscall

PATCH Superseded Richard Henderson 3 participants 15 messages Dec 19, 2018 – Jan 14, 2019

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover linux-user: Split do_syscall

Version 4 was back in August:
https://lists.gnu.org/archive/html/qemu-devel/2018-08/msg03745.html

Version 5 continues the file split via inclusion. This incorporates Laurent's suggestion to have a "def" file that is included twice to generate both SyscallDef structures and fill in syscall_table's switch.

Again, this just converts a few syscalls as proof of concept.

r~

Richard Henderson (8):
linux-user: Setup split syscall infrastructure
linux-user: Split out some simple file syscalls
linux-user: Reduce regpairs_aligned & target_offset64 ifdefs
linux-user: Split out preadv, pwritev, readv, writev, pread64,
pwrite64
linux-user: Split out name_to_handle_at, open_by_handle_at
linux-user: Split out ipc syscalls
linux-user: Split out memory syscalls
linux-user: Split out some process syscalls

 linux-user/syscall-defs.h     |  231 +++
 linux-user/syscall.h          |   93 ++
 linux-user/strace.c           |  567 ++++----
 linux-user/syscall-file.inc.c |  638 +++++++++
 linux-user/syscall-ipc.inc.c  | 1086 ++++++++++++++
 linux-user/syscall-mem.inc.c  |  154 ++
 linux-user/syscall-proc.inc.c |  861 ++++++++++++
 linux-user/syscall.c          | 2500 ++-------------------------------
 linux-user/strace.list        |  243 ----
 9 files changed, 3499 insertions(+), 2874 deletions(-)
 create mode 100644 linux-user/syscall-defs.h
 create mode 100644 linux-user/syscall.h
 create mode 100644 linux-user/syscall-file.inc.c
 create mode 100644 linux-user/syscall-ipc.inc.c
 create mode 100644 linux-user/syscall-mem.inc.c
 create mode 100644 linux-user/syscall-proc.inc.c
Signature · 1 line
2.17.2
#1 lore raw

PATCH v5 1/8 linux-user: Setup split syscall infrastructure

Defines a unified structure for implementation and strace.

---
 linux-user/syscall.h |  89 ++++++++++
 linux-user/strace.c  | 388 +++++++++++++++++++++++++++++++------------
 linux-user/syscall.c | 107 +++++++++++-
 3 files changed, 471 insertions(+), 113 deletions(-)
 create mode 100644 linux-user/syscall.h
linux-user/syscall.h new file +89 -0
new file mode 100644
index 0000000000..43b5dc0684
@@ -0,0 +1,89 @@
+/*
+ *  Linux syscalls internals
+ *  Copyright (c) 2018 Linaro, Limited.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LINUX_USER_SYSCALL_H
+#define LINUX_USER_SYSCALL_H 1
+
+typedef struct SyscallDef SyscallDef;
+
+/*
+ * This hook extracts max 6 arguments from max 8 input registers.
+ * In the process, register pairs that store 64-bit arguments are merged.
+ * Finally, syscalls are demultipliexed; e.g. the hook for socketcall will
+ * return the SyscallDef for bind, listen, etc.  In the process the hook
+ * may need to read from guest memory, or otherwise validate operands.
+ * On failure, set errno (to a host value) and return NULL;
+ * the (target adjusted) errno will be returned to the guest.
+ */
+typedef const SyscallDef *SyscallArgsFn(const SyscallDef *, int64_t out[6],
+                                        abi_long in[8]);
+
+/* This hook implements the syscall.  */
+typedef abi_long SyscallImplFn(CPUArchState *, int64_t, int64_t, int64_t,
+                               int64_t, int64_t, int64_t);
+
+/* This hook prints the arguments to the syscall for strace.  */
+typedef void SyscallPrintFn(const SyscallDef *, int64_t arg[6]);
+
+/* This hook print the return value from the syscall for strace.  */
+typedef void SyscallPrintRetFn(const SyscallDef *, abi_long);
+
+/*
+ * These flags describe the arguments for the generic fallback to
+ * SyscallPrintFn.  ARG_NONE indicates that the argument is not present.
+ */
+typedef enum {
+    ARG_NONE = 0,
+
+    /* These print as numbers of abi_long.  */
+    ARG_DEC,
+    ARG_HEX,
+    ARG_OCT,
+
+    /* These print as sets of flags.  */
+    ARG_ATDIRFD,
+    ARG_MODEFLAG,
+    ARG_OPENFLAG,
+
+    /* These are interpreted as pointers.  */
+    ARG_PTR,
+    ARG_STR,
+    ARG_BUF,
+
+    /* For a 32-bit host, force printing as a 64-bit operand.  */
+#if TARGET_ABI_BITS == 32
+    ARG_DEC64,
+#else
+    ARG_DEC64 = ARG_DEC,
+#endif
+} SyscallArgType;
+
+struct SyscallDef {
+    const char *name;
+    SyscallArgsFn *args;
+    SyscallImplFn *impl;
+    SyscallPrintFn *print;
+    SyscallPrintRetFn *print_ret;
+    SyscallArgType arg_type[6];
+};
+
+void print_syscall_def(const SyscallDef *def, int64_t args[6]);
+void print_syscall_def_ret(const SyscallDef *def, abi_long ret);
+void print_syscall_ptr_ret(const SyscallDef *def, abi_long ret);
+
+#endif
linux-user/strace.c +283 -105

484 lines not on this page · raw message

linux-user/syscall.c +99 -8

133 lines not on this page · raw message

Signature · 1 line
2.17.2
#2 lore raw

PATCH v5 2/8 linux-user: Split out some simple file syscalls

In reply to Richard Henderson

This includes close, open, openat, read, readlink, readlinkat, write.

---
 linux-user/syscall-defs.h     |  31 +++
 linux-user/syscall-file.inc.c | 433 ++++++++++++++++++++++++++++++++++
 linux-user/syscall.c          | 376 +----------------------------
 3 files changed, 468 insertions(+), 372 deletions(-)
 create mode 100644 linux-user/syscall-defs.h
 create mode 100644 linux-user/syscall-file.inc.c
linux-user/syscall-defs.h new file +31 -0
new file mode 100644
index 0000000000..b031de1375
@@ -0,0 +1,31 @@
+/*
+ *  Linux syscall definitions
+ *  Copyright (c) 2003 Fabrice Bellard
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+SYSCALL_DEF(close, ARG_DEC);
+#ifdef TARGET_NR_open
+SYSCALL_DEF(open, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
+#endif
+SYSCALL_DEF(openat, ARG_ATDIRFD, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
+SYSCALL_DEF(read, ARG_DEC, ARG_PTR, ARG_DEC);
+#ifdef TARGET_NR_readlink
+SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC);
+#endif
+#ifdef TARGET_NR_readlinkat
+SYSCALL_DEF(readlinkat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_DEC);
+#endif
+SYSCALL_DEF(write, ARG_DEC, ARG_PTR, ARG_DEC);
linux-user/syscall-file.inc.c new file +433 -0

433 lines not on this page · raw message

linux-user/syscall.c +4 -372

418 lines not on this page · raw message

Signature · 1 line
2.17.2
#3 lore raw

PATCH v5 3/8 linux-user: Reduce regpairs_aligned & target_offset64 ifdefs

In reply to Richard Henderson
---
 linux-user/syscall.c | 54 ++++++++++++++++++++------------------------
 1 file changed, 25 insertions(+), 29 deletions(-)
linux-user/syscall.c +25 -29
index 7118f07441..d4c11c3e93 100644
@@ -474,37 +474,38 @@ static inline int next_free_host_timer(void)
 }
 #endif
 
-/* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */
+/*
+ * Returns true if syscall NUM expects 64bit types aligned even
+ * on pairs of registers.
+ */
+static inline bool regpairs_aligned(void *cpu_env, int num)
+{
 #ifdef TARGET_ARM
-static inline int regpairs_aligned(void *cpu_env, int num)
-{
-    return ((((CPUARMState *)cpu_env)->eabi) == 1) ;
-}
-#elif defined(TARGET_MIPS) && (TARGET_ABI_BITS == 32)
-static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
+    return ((CPUARMState *)cpu_env)->eabi;
+#elif defined(TARGET_MIPS) && TARGET_ABI_BITS == 32
+    return true;
 #elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
-/* SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even pairs
- * of registers which translates to the same as ARM/MIPS, because we start with
- * r3 as arg1 */
-static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
+    /*
+     * SysV AVI for PPC32 expects 64bit parameters to be passed on
+     * odd/even pairs of registers which translates to the same as
+     * we start with r3 as arg1.
+     */
+    return true;
 #elif defined(TARGET_SH4)
-/* SH4 doesn't align register pairs, except for p{read,write}64 */
-static inline int regpairs_aligned(void *cpu_env, int num)
-{
+    /* SH4 doesn't align register pairs, except for p{read,write}64.  */
     switch (num) {
     case TARGET_NR_pread64:
     case TARGET_NR_pwrite64:
-        return 1;
-
+        return true;
     default:
-        return 0;
+        return false;
     }
-}
 #elif defined(TARGET_XTENSA)
-static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
+    return true;
 #else
-static inline int regpairs_aligned(void *cpu_env, int num) { return 0; }
+    return false;
 #endif
+}
 
 #define ERRNO_TABLE_SIZE 1200
 
@@ -6066,21 +6067,16 @@ void syscall_init(void)
     }
 }
 
-#if TARGET_ABI_BITS == 32
-static inline uint64_t target_offset64(uint32_t word0, uint32_t word1)
+static inline uint64_t target_offset64(abi_ulong word0, abi_ulong word1)
 {
-#ifdef TARGET_WORDS_BIGENDIAN
+#if TARGET_ABI_BITS == 64
+    return word0;
+#elif defined(TARGET_WORDS_BIGENDIAN)
     return ((uint64_t)word0 << 32) | word1;
 #else
     return ((uint64_t)word1 << 32) | word0;
 #endif
 }
-#else /* TARGET_ABI_BITS == 32 */
-static inline uint64_t target_offset64(uint64_t word0, uint64_t word1)
-{
-    return word0;
-}
-#endif /* TARGET_ABI_BITS != 32 */
 
 #ifdef TARGET_NR_truncate64
 static inline abi_long target_truncate64(void *cpu_env, const char *arg1,
Signature · 1 line
2.17.2
#4 lore raw

PATCH v5 4/8 linux-user: Split out preadv, pwritev, readv, writev, pread64, pwrite64

In reply to Richard Henderson
---
 linux-user/syscall-defs.h     |  14 ++++
 linux-user/syscall-file.inc.c | 124 ++++++++++++++++++++++++++++++++++
 linux-user/syscall.c          |  93 -------------------------
 linux-user/strace.list        |  18 -----
 4 files changed, 138 insertions(+), 111 deletions(-)
linux-user/syscall-defs.h +14 -0
index b031de1375..ae89be0e87 100644
@@ -21,6 +21,18 @@ SYSCALL_DEF(close, ARG_DEC);
 SYSCALL_DEF(open, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
 #endif
 SYSCALL_DEF(openat, ARG_ATDIRFD, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
+SYSCALL_DEF_FULL(pread64, .impl = impl_pread64,
+                 .args = args_pread64_pwrite64,
+                 .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });
+SYSCALL_DEF_FULL(pwrite64, .impl = impl_pwrite64,
+                 .args = args_pread64_pwrite64,
+                 .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });
+SYSCALL_DEF_FULL(preadv, .impl = impl_preadv,
+                 .args = args_preadv_pwritev,
+                 .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });
+SYSCALL_DEF_FULL(pwritev, .impl = impl_pwritev,
+                 .args = args_preadv_pwritev,
+                 .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });
 SYSCALL_DEF(read, ARG_DEC, ARG_PTR, ARG_DEC);
 #ifdef TARGET_NR_readlink
 SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC);
@@ -28,4 +40,6 @@ SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC);
 #ifdef TARGET_NR_readlinkat
 SYSCALL_DEF(readlinkat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_DEC);
 #endif
+SYSCALL_DEF(readv, ARG_DEC, ARG_PTR, ARG_DEC);
 SYSCALL_DEF(write, ARG_DEC, ARG_PTR, ARG_DEC);
+SYSCALL_DEF(writev, ARG_DEC, ARG_PTR, ARG_DEC);
linux-user/syscall-file.inc.c +124 -0

139 lines not on this page · raw message

linux-user/syscall.c +0 -93

111 lines not on this page · raw message

linux-user/strace.list +0 -18
index ff8bb19f5f..8f96b7a105 100644
@@ -1034,12 +1034,6 @@
 #ifdef TARGET_NR_prctl
 { TARGET_NR_prctl, "prctl" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_pread64
-{ TARGET_NR_pread64, "pread64" , NULL, NULL, NULL },
-#endif
-#ifdef TARGET_NR_preadv
-{ TARGET_NR_preadv, "preadv" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_prlimit64
 { TARGET_NR_prlimit64, "prlimit64" , NULL, NULL, NULL },
 #endif
@@ -1064,12 +1058,6 @@
 #ifdef TARGET_NR_putpmsg
 { TARGET_NR_putpmsg, "putpmsg" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_pwrite64
-{ TARGET_NR_pwrite64, "pwrite64" , NULL, NULL, NULL },
-#endif
-#ifdef TARGET_NR_pwritev
-{ TARGET_NR_pwritev, "pwritev" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_query_module
 { TARGET_NR_query_module, "query_module" , NULL, NULL, NULL },
 #endif
@@ -1091,9 +1079,6 @@
 #ifdef TARGET_NR_readlinkat
 { TARGET_NR_readlinkat, "readlinkat" , NULL, print_readlinkat, NULL },
 #endif
-#ifdef TARGET_NR_readv
-{ TARGET_NR_readv, "readv" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_reboot
 { TARGET_NR_reboot, "reboot" , NULL, NULL, NULL },
 #endif
@@ -1629,9 +1614,6 @@
 #ifdef TARGET_NR_write
 { TARGET_NR_write, "write" , "%s(%d,%#x,%d)", NULL, NULL },
 #endif
-#ifdef TARGET_NR_writev
-{ TARGET_NR_writev, "writev" , "%s(%d,%p,%#x)", NULL, NULL },
-#endif
 #ifdef TARGET_NR_utimensat
 { TARGET_NR_utimensat, "utimensat", NULL, print_utimensat, NULL },
 #endif
Signature · 1 line
2.17.2
#5 lore raw

Re: [Qemu-devel] [PATCH v5 4/8] linux-user: Split out preadv, pwritev, readv, writev, pread64, pwrite64

Quoted 8 lines · Richard Henderson
---
 linux-user/syscall-defs.h     |  14 ++++
 linux-user/syscall-file.inc.c | 124 ++++++++++++++++++++++++++++++++++
 linux-user/syscall.c          |  93 -------------------------
 linux-user/strace.list        |  18 -----
 4 files changed, 138 insertions(+), 111 deletions(-)

...

Quoted 5 lines
linux-user/syscall-file.inc.c +0 -0
index 11e75044c1..410a763eee 100644
@@ -315,6 +315,104 @@ SYSCALL_IMPL(openat)

...

Quoted 14 lines
linux-user/syscall-file.inc.c +14 -0
+
+/*
+ * Both preadv and pwritev merge args 4/5 into a 64-bit offset.
+ * Moreover, the parts are *always* in little-endian order.
+ */
+#if TARGET_ABI_BITS == 32
+SYSCALL_ARGS(preadv_pwritev)
+{
+    /* We have already assigned out[0-2].  */
+    abi_ulong lo = in[3], hi = in[4];
+    out[3] = ((hi << (TARGET_ABI_BITS - 1)) << 1) | lo;
+    return def;
+}
+#else

linux-user/syscall-file.inc.c SYSCALL_IMPL(openat) · line 382

Quoted 10 lines
linux-user/syscall-file.inc.c +10 -0
+#define args_preadv_pwritev NULL
+#endif
+
+/* Perform the inverse operation for the host.  */
+static inline void host_offset64_low_high(unsigned long *l, unsigned long *h,
+                                          uint64_t off)
+{
+    *l = off;
+    *h = (off >> (HOST_LONG_BITS - 1)) >> 1;
+}

I have an error with preadv() on a 32bit target (powerpc, LTP test preadv02).

It works if I use:

static inline void host_offset64_low_high(unsigned long *hlow,
unsigned long *hhigh, abi_ulong tlow, abi_ulong thigh)

{
    uint64_t off = tlow |
                   ((unsigned long long)thigh << TARGET_LONG_BITS / 2) <<
                   TARGET_LONG_BITS / 2;
    
    *hlow = off;
    *hhigh = (off >> HOST_LONG_BITS / 2) >> HOST_LONG_BITS / 2;
}
Quoted 15 lines
linux-user/syscall-file.inc.c +15 -0
+
+SYSCALL_IMPL(preadv)
+{
+    struct iovec *vec = lock_iovec(VERIFY_WRITE, arg2, arg3, 0);
+    unsigned long lo, hi;
+    abi_long ret;
+
+    if (vec == NULL) {
+        return -host_to_target_errno(errno);
+    }
+
+    host_offset64_low_high(&lo, &hi, arg4);
+    ret = get_errno(safe_preadv(arg1, vec, arg3, lo, hi));
+    unlock_iovec(vec, arg2, arg3, 1);
+    return ret;

linux-user/syscall-file.inc.c SYSCALL_IMPL(openat) · line 407

Quoted 10 lines
linux-user/syscall-file.inc.c +10 -0
+}
+
+SYSCALL_IMPL(pwritev)
+{
+    struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);
+    unsigned long lo, hi;
+    abi_long ret;
+
+    if (vec == NULL) {
+        ret = -host_to_target_errno(errno);
           return -host_to_target_errno(errno);
Quoted 11 lines
linux-user/syscall-file.inc.c +8 -0
+    }
+
+    host_offset64_low_high(&lo, &hi, arg4);
+    ret = get_errno(safe_pwritev(arg1, vec, arg3, lo, hi));
+    unlock_iovec(vec, arg2, arg3, 0);
+    return ret;
+}
+
 SYSCALL_IMPL(read)
 {
     abi_long ret;
#6 lore raw

Re: [Qemu-devel] [PATCH v5 4/8] linux-user: Split out preadv, pwritev, readv, writev, pread64, pwrite64

Quoted 50 lines · Laurent Vivier
Quoted 8 lines · Richard Henderson
---
 linux-user/syscall-defs.h     |  14 ++++
 linux-user/syscall-file.inc.c | 124 ++++++++++++++++++++++++++++++++++
 linux-user/syscall.c          |  93 -------------------------
 linux-user/strace.list        |  18 -----
 4 files changed, 138 insertions(+), 111 deletions(-)

...

Quoted 5 lines
linux-user/syscall-file.inc.c +0 -0
index 11e75044c1..410a763eee 100644
@@ -315,6 +315,104 @@ SYSCALL_IMPL(openat)

...

Quoted 14 lines
linux-user/syscall-file.inc.c +14 -0
+
+/*
+ * Both preadv and pwritev merge args 4/5 into a 64-bit offset.
+ * Moreover, the parts are *always* in little-endian order.
+ */
+#if TARGET_ABI_BITS == 32
+SYSCALL_ARGS(preadv_pwritev)
+{
+    /* We have already assigned out[0-2].  */
+    abi_ulong lo = in[3], hi = in[4];
+    out[3] = ((hi << (TARGET_ABI_BITS - 1)) << 1) | lo;
+    return def;
+}
+#else

linux-user/syscall-file.inc.c SYSCALL_IMPL(openat) · line 382

Quoted 10 lines
linux-user/syscall-file.inc.c +10 -0
+#define args_preadv_pwritev NULL
+#endif
+
+/* Perform the inverse operation for the host.  */
+static inline void host_offset64_low_high(unsigned long *l, unsigned long *h,
+                                          uint64_t off)
+{
+    *l = off;
+    *h = (off >> (HOST_LONG_BITS - 1)) >> 1;
+}

I have an error with preadv() on a 32bit target (powerpc, LTP test preadv02).

It works if I use:

static inline void host_offset64_low_high(unsigned long *hlow,
unsigned long *hhigh, abi_ulong tlow, abi_ulong thigh)

Quoted 8 lines
{
    uint64_t off = tlow |
                   ((unsigned long long)thigh << TARGET_LONG_BITS / 2) <<
                   TARGET_LONG_BITS / 2;
    
    *hlow = off;
    *hhigh = (off >> HOST_LONG_BITS / 2) >> HOST_LONG_BITS / 2;
}

This doesn't make any sense. Where are "tlow" and "thigh" coming from?

I think the bug will be

SYSCALL_ARGS(preadv_pwritev)

 {
     /* We have already assigned out[0-2].  */
     abi_ulong lo = in[3], hi = in[4];
-    out[3] = ((hi << (TARGET_ABI_BITS - 1)) << 1) | lo;
+    out[3] = (((uint64_t)hi << (TARGET_ABI_BITS - 1)) << 1) | lo;
     return def;

}

r~

#7 lore raw

Re: [Qemu-devel] [PATCH v5 4/8] linux-user: Split out preadv, pwritev, readv, writev, pread64, pwrite64

Quoted 68 lines · Richard Henderson
Quoted 50 lines · Laurent Vivier
Quoted 8 lines · Richard Henderson
---
  linux-user/syscall-defs.h     |  14 ++++
  linux-user/syscall-file.inc.c | 124 ++++++++++++++++++++++++++++++++++
  linux-user/syscall.c          |  93 -------------------------
  linux-user/strace.list        |  18 -----
  4 files changed, 138 insertions(+), 111 deletions(-)

...

Quoted 5 lines
linux-user/syscall-file.inc.c +0 -0
index 11e75044c1..410a763eee 100644
@@ -315,6 +315,104 @@ SYSCALL_IMPL(openat)

...

Quoted 14 lines
linux-user/syscall-file.inc.c +14 -0
+
+/*
+ * Both preadv and pwritev merge args 4/5 into a 64-bit offset.
+ * Moreover, the parts are *always* in little-endian order.
+ */
+#if TARGET_ABI_BITS == 32
+SYSCALL_ARGS(preadv_pwritev)
+{
+    /* We have already assigned out[0-2].  */
+    abi_ulong lo = in[3], hi = in[4];
+    out[3] = ((hi << (TARGET_ABI_BITS - 1)) << 1) | lo;
+    return def;
+}
+#else

linux-user/syscall-file.inc.c SYSCALL_IMPL(openat) · line 382

Quoted 10 lines
linux-user/syscall-file.inc.c +10 -0
+#define args_preadv_pwritev NULL
+#endif
+
+/* Perform the inverse operation for the host.  */
+static inline void host_offset64_low_high(unsigned long *l, unsigned long *h,
+                                          uint64_t off)
+{
+    *l = off;
+    *h = (off >> (HOST_LONG_BITS - 1)) >> 1;
+}

I have an error with preadv() on a 32bit target (powerpc, LTP test preadv02).

It works if I use:

static inline void host_offset64_low_high(unsigned long *hlow,
unsigned long *hhigh, abi_ulong tlow, abi_ulong thigh)

Quoted 8 lines
{
     uint64_t off = tlow |
                    ((unsigned long long)thigh << TARGET_LONG_BITS / 2) <<
                    TARGET_LONG_BITS / 2;
     
     *hlow = off;
     *hhigh = (off >> HOST_LONG_BITS / 2) >> HOST_LONG_BITS / 2;
}

This doesn't make any sense. Where are "tlow" and "thigh" coming from?

I think the bug will be

  SYSCALL_ARGS(preadv_pwritev)
  {
      /* We have already assigned out[0-2].  */
      abi_ulong lo = in[3], hi = in[4];

Review

Quoted 4 lines
(quoted diff) +1 -1
-    out[3] = ((hi << (TARGET_ABI_BITS - 1)) << 1) | lo;
+    out[3] = (((uint64_t)hi << (TARGET_ABI_BITS - 1)) << 1) | lo;
      return def;
  }

Yes, this change fixes the problem.

Thanks,
Laurent

#8 lore raw

PATCH v5 5/8 linux-user: Split out name_to_handle_at, open_by_handle_at

In reply to Richard Henderson
---
 linux-user/syscall-defs.h     |   3 +
 linux-user/syscall.h          |   1 +
 linux-user/strace.c           |   5 +-
 linux-user/syscall-file.inc.c |  81 +++++++++++++++++++++++++++
 linux-user/syscall.c          | 102 ++--------------------------------
 linux-user/strace.list        |   3 -
 6 files changed, 93 insertions(+), 102 deletions(-)
linux-user/syscall-defs.h +3 -0
index ae89be0e87..3d52835216 100644
@@ -21,6 +21,9 @@ SYSCALL_DEF(close, ARG_DEC);
 SYSCALL_DEF(open, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
 #endif
 SYSCALL_DEF(openat, ARG_ATDIRFD, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
+SYSCALL_DEF(name_to_handle_at,
+            ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_PTR, ARG_ATFLAG);
+SYSCALL_DEF(open_by_handle_at, ARG_DEC, ARG_PTR, ARG_OPENFLAG);
 SYSCALL_DEF_FULL(pread64, .impl = impl_pread64,
                  .args = args_pread64_pwrite64,
                  .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });
linux-user/syscall.h +1 -0
index 43b5dc0684..83f602f8e7 100644
@@ -57,6 +57,7 @@ typedef enum {
 
     /* These print as sets of flags.  */
     ARG_ATDIRFD,
+    ARG_ATFLAG,
     ARG_MODEFLAG,
     ARG_OPENFLAG,
 
linux-user/strace.c +4 -1
index 0d9e1dc483..661e5de7f7 100644
@@ -780,7 +780,7 @@ UNUSED static struct flags access_flags[] = {
     FLAG_END,
 };
 
-UNUSED static struct flags at_file_flags[] = {
+static struct flags const at_file_flags[] = {
 #ifdef AT_EACCESS
     FLAG_GENERIC(AT_EACCESS),
 #endif
@@ -2745,6 +2745,9 @@ static void print_syscall_def1(const SyscallDef *def, int64_t args[6])
         case ARG_ATDIRFD:
             len = add_atdirfd(b, rest, arg);
             break;
+        case ARG_ATFLAG:
+            len = add_flags(b, rest, at_file_flags, arg, false);
+            break;
         case ARG_MODEFLAG:
             len = add_flags(b, rest, mode_flags, arg, true);
             break;
linux-user/syscall-file.inc.c +81 -0

87 lines not on this page · raw message

linux-user/syscall.c +4 -98

120 lines not on this page · raw message

linux-user/strace.list +0 -3
index 8f96b7a105..c61b3b9d09 100644
@@ -638,9 +638,6 @@
 #ifdef TARGET_NR_munmap
 { TARGET_NR_munmap, "munmap" , NULL, print_munmap, NULL },
 #endif
-#ifdef TARGET_NR_name_to_handle_at
-{ TARGET_NR_name_to_handle_at, "name_to_handle_at" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_nanosleep
 { TARGET_NR_nanosleep, "nanosleep" , NULL, NULL, NULL },
 #endif
Signature · 1 line
2.17.2
#9 lore raw

PATCH v5 6/8 linux-user: Split out ipc syscalls

In reply to Richard Henderson
---
 linux-user/syscall-defs.h    |   38 ++
 linux-user/strace.c          |   83 ---
 linux-user/syscall-ipc.inc.c | 1086 ++++++++++++++++++++++++++++++++++
 linux-user/syscall.c         |  972 +-----------------------------
 linux-user/strace.list       |   42 --
 5 files changed, 1127 insertions(+), 1094 deletions(-)
 create mode 100644 linux-user/syscall-ipc.inc.c
linux-user/syscall-defs.h +38 -0
index 3d52835216..2712867228 100644
@@ -17,6 +17,21 @@
  */
 
 SYSCALL_DEF(close, ARG_DEC);
+#ifdef TARGET_NR_ipc
+SYSCALL_DEF_ARGS(ipc, ARG_HEX, ARG_DEC, ARG_DEC, ARG_HEX, ARG_PTR, ARG_HEX);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_msgctl)
+SYSCALL_DEF(msgctl, ARG_DEC, ARG_DEC, ARG_PTR);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_msgget)
+SYSCALL_DEF(msgget, ARG_DEC, ARG_DEC);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_msgrcv)
+SYSCALL_DEF(msgrcv, ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC, ARG_HEX);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_msgsnd)
+SYSCALL_DEF(msgsnd, ARG_DEC, ARG_PTR, ARG_DEC, ARG_HEX);
+#endif
 #ifdef TARGET_NR_open
 SYSCALL_DEF(open, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
 #endif
@@ -44,5 +59,28 @@ SYSCALL_DEF(readlink, ARG_STR, ARG_PTR, ARG_DEC);
 SYSCALL_DEF(readlinkat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_DEC);
 #endif
 SYSCALL_DEF(readv, ARG_DEC, ARG_PTR, ARG_DEC);
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_semctl)
+SYSCALL_DEF(semctl, ARG_DEC, ARG_DEC, ARG_DEC, ARG_HEX);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_semget)
+SYSCALL_DEF(semget, ARG_DEC, ARG_DEC, ARG_HEX);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_semop)
+SYSCALL_DEF(semop, ARG_DEC, ARG_PTR, ARG_DEC);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_shmat)
+SYSCALL_DEF_FULL(shmat, .impl = impl_shmat,
+                 .print_ret = print_syscall_ptr_ret,
+                 .arg_type = { ARG_DEC, ARG_PTR, ARG_HEX });
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_shmctl)
+SYSCALL_DEF(shmctl, ARG_DEC, ARG_DEC, ARG_PTR);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_shmdt)
+SYSCALL_DEF(shmdt, ARG_PTR);
+#endif
+#if !defined(SYSCALL_TABLE) || defined(TARGET_NR_shmget)
+SYSCALL_DEF(shmget, ARG_DEC, ARG_DEC, ARG_HEX);
+#endif
 SYSCALL_DEF(write, ARG_DEC, ARG_PTR, ARG_DEC);
 SYSCALL_DEF(writev, ARG_DEC, ARG_PTR, ARG_DEC);
linux-user/strace.c +0 -83

105 lines not on this page · raw message

linux-user/syscall-ipc.inc.c new file +1086 -0

1,086 lines not on this page · raw message

linux-user/syscall.c +3 -969

1,008 lines not on this page · raw message

linux-user/strace.list +0 -42

72 lines not on this page · raw message

Signature · 1 line
2.17.2
#10 lore raw

PATCH v5 7/8 linux-user: Split out memory syscalls

In reply to Richard Henderson

This includes mmap, mmap2, munmap, mlock, mlockall, munlock, munlockall, mprotect, mremap, msync.

---
 linux-user/syscall-defs.h    |  24 ++++++
 linux-user/syscall.h         |   2 +
 linux-user/strace.c          |  55 ++-----------
 linux-user/syscall-mem.inc.c | 154 +++++++++++++++++++++++++++++++++++
 linux-user/syscall.c         | 119 +--------------------------
 linux-user/strace.list       |  33 --------
 6 files changed, 189 insertions(+), 198 deletions(-)
 create mode 100644 linux-user/syscall-mem.inc.c
linux-user/syscall-defs.h +24 -0
index 2712867228..a057aa9150 100644
@@ -20,6 +20,26 @@ SYSCALL_DEF(close, ARG_DEC);
 #ifdef TARGET_NR_ipc
 SYSCALL_DEF_ARGS(ipc, ARG_HEX, ARG_DEC, ARG_DEC, ARG_HEX, ARG_PTR, ARG_HEX);
 #endif
+SYSCALL_DEF(mlock, ARG_PTR, ARG_DEC);
+SYSCALL_DEF(mlockall, ARG_HEX);
+#ifdef TARGET_NR_mmap
+SYSCALL_DEF_FULL(mmap, .impl = impl_mmap,
+                 .args = args_mmap,
+                 .print_ret = print_syscall_ptr_ret,
+                 .arg_type = { ARG_PTR, ARG_DEC, ARG_MMAPPROT,
+                               ARG_MMAPFLAG, ARG_DEC, ARG_DEC });
+#endif
+#ifdef TARGET_NR_mmap2
+SYSCALL_DEF_FULL(mmap2, .impl = impl_mmap,
+                 .args = args_mmap2,
+                 .print_ret = print_syscall_ptr_ret,
+                 .arg_type = { ARG_PTR, ARG_DEC, ARG_MMAPPROT,
+                               ARG_MMAPFLAG, ARG_DEC, ARG_DEC64 });
+#endif
+SYSCALL_DEF(mprotect, ARG_PTR, ARG_DEC, ARG_MMAPPROT);
+SYSCALL_DEF_FULL(mremap, .impl = impl_mremap,
+                 .print_ret = print_syscall_ptr_ret,
+                 .arg_type = { ARG_PTR, ARG_DEC, ARG_DEC, ARG_HEX, ARG_PTR });
 #if !defined(SYSCALL_TABLE) || defined(TARGET_NR_msgctl)
 SYSCALL_DEF(msgctl, ARG_DEC, ARG_DEC, ARG_PTR);
 #endif
@@ -32,6 +52,10 @@ SYSCALL_DEF(msgrcv, ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC, ARG_HEX);
 #if !defined(SYSCALL_TABLE) || defined(TARGET_NR_msgsnd)
 SYSCALL_DEF(msgsnd, ARG_DEC, ARG_PTR, ARG_DEC, ARG_HEX);
 #endif
+SYSCALL_DEF(msync, ARG_PTR, ARG_DEC, ARG_HEX);
+SYSCALL_DEF(munlock, ARG_PTR, ARG_DEC);
+SYSCALL_DEF(munlockall);
+SYSCALL_DEF(munmap, ARG_PTR, ARG_DEC);
 #ifdef TARGET_NR_open
 SYSCALL_DEF(open, ARG_STR, ARG_OPENFLAG, ARG_MODEFLAG);
 #endif
linux-user/syscall.h +2 -0
index 83f602f8e7..8175de4c31 100644
@@ -58,6 +58,8 @@ typedef enum {
     /* These print as sets of flags.  */
     ARG_ATDIRFD,
     ARG_ATFLAG,
+    ARG_MMAPFLAG,
+    ARG_MMAPPROT,
     ARG_MODEFLAG,
     ARG_OPENFLAG,
 
linux-user/strace.c +8 -47

79 lines not on this page · raw message

linux-user/syscall-mem.inc.c new file +154 -0

154 lines not on this page · raw message

linux-user/syscall.c +1 -118

143 lines not on this page · raw message

linux-user/strace.list +0 -33
index 9385ea3dd1..ac7cf77021 100644
@@ -557,21 +557,6 @@
 #ifdef TARGET_NR_mknodat
 { TARGET_NR_mknodat, "mknodat" , NULL, print_mknodat, NULL },
 #endif
-#ifdef TARGET_NR_mlock
-{ TARGET_NR_mlock, "mlock" , NULL, NULL, NULL },
-#endif
-#ifdef TARGET_NR_mlock2
-{ TARGET_NR_mlock2, "mlock2" , NULL, NULL, NULL },
-#endif
-#ifdef TARGET_NR_mlockall
-{ TARGET_NR_mlockall, "mlockall" , NULL, NULL, NULL },
-#endif
-#ifdef TARGET_NR_mmap
-{ TARGET_NR_mmap, "mmap" , NULL, print_mmap, print_syscall_ret_addr },
-#endif
-#ifdef TARGET_NR_mmap2
-{ 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
@@ -581,9 +566,6 @@
 #ifdef TARGET_NR_move_pages
 { TARGET_NR_move_pages, "move_pages" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_mprotect
-{ TARGET_NR_mprotect, "mprotect" , NULL, print_mprotect, NULL },
-#endif
 #ifdef TARGET_NR_mpx
 { TARGET_NR_mpx, "mpx" , NULL, NULL, NULL },
 #endif
@@ -605,24 +587,9 @@
 #ifdef TARGET_NR_mq_unlink
 { TARGET_NR_mq_unlink, "mq_unlink" , NULL, print_mq_unlink, NULL },
 #endif
-#ifdef TARGET_NR_mremap
-{ TARGET_NR_mremap, "mremap" , NULL, NULL, NULL },
-#endif
-#ifdef TARGET_NR_msync
-{ TARGET_NR_msync, "msync" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_multiplexer
 { TARGET_NR_multiplexer, "multiplexer" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_munlock
-{ TARGET_NR_munlock, "munlock" , NULL, NULL, NULL },
-#endif
-#ifdef TARGET_NR_munlockall
-{ TARGET_NR_munlockall, "munlockall" , NULL, NULL, NULL },
-#endif
-#ifdef TARGET_NR_munmap
-{ TARGET_NR_munmap, "munmap" , NULL, print_munmap, NULL },
-#endif
 #ifdef TARGET_NR_nanosleep
 { TARGET_NR_nanosleep, "nanosleep" , NULL, NULL, NULL },
 #endif
Signature · 1 line
2.17.2
#11 lore raw

PATCH v5 8/8 linux-user: Split out some process syscalls

In reply to Richard Henderson

This includes clone, getgroups, gettid, setfsgid, setfsuid, setgroups, setsid, setuid, fork, getegid, getegid32, geteuid, geteuid32, getgid, getgid32, getgroups32, getpgrp, getpid, getppid, getresgid, getresgid32, getresuid, getresuid32, getuid, getuid32, getxgid, getxpid, getxuid, setfsgid32, setgsuid32, setgid32, setgroups32, setregid, setregid32, setresgid, setresgid32, setresuid, setresuid32, setreuid, setreuid32, setuid32, vfork.

---
 linux-user/syscall-defs.h     | 121 +++++
 linux-user/syscall.h          |   1 +
 linux-user/strace.c           |  36 +-
 linux-user/syscall-proc.inc.c | 861 ++++++++++++++++++++++++++++++++++
 linux-user/syscall.c          | 677 +-------------------------
 linux-user/strace.list        | 147 ------
 6 files changed, 988 insertions(+), 855 deletions(-)
 create mode 100644 linux-user/syscall-proc.inc.c
linux-user/syscall-defs.h +121 -0
index a057aa9150..a7f78793fd 100644
@@ -16,7 +16,80 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+SYSCALL_DEF_ARGS(clone, ARG_CLONEFLAG, ARG_PTR, ARG_PTR, ARG_PTR, ARG_PTR);
 SYSCALL_DEF(close, ARG_DEC);
+#ifdef TARGET_NR_fork
+SYSCALL_DEF(fork);
+#endif
+#ifdef TARGET_NR_getegid
+SYSCALL_DEF(getegid);
+#endif
+#ifdef TARGET_NR_getegid32
+SYSCALL_DEF(getegid32);
+#endif
+#ifdef TARGET_NR_geteuid
+SYSCALL_DEF(geteuid);
+#endif
+#ifdef TARGET_NR_geteuid32
+SYSCALL_DEF(geteuid32);
+#endif
+#ifdef TARGET_NR_getgid
+SYSCALL_DEF(getgid);
+#endif
+#ifdef TARGET_NR_getgid32
+SYSCALL_DEF(getgid32);
+#endif
+SYSCALL_DEF(getgroups, ARG_DEC, ARG_PTR);
+#ifdef TARGET_NR_getgroups32
+SYSCALL_DEF(getgroups32, ARG_DEC, ARG_PTR);
+#endif
+#ifdef TARGET_NR_getresgid
+SYSCALL_DEF(getresgid, ARG_PTR, ARG_PTR, ARG_PTR);
+#endif
+#ifdef TARGET_NR_getresgid32
+SYSCALL_DEF(getresgid32, ARG_PTR, ARG_PTR, ARG_PTR);
+#endif
+#ifdef TARGET_NR_getresuid
+SYSCALL_DEF(getresuid, ARG_PTR, ARG_PTR, ARG_PTR);
+#endif
+#ifdef TARGET_NR_getresuid32
+SYSCALL_DEF(getresuid32, ARG_PTR, ARG_PTR, ARG_PTR);
+#endif
+#ifdef TARGET_NR_getpgrp
+SYSCALL_DEF(getpgrp);
+#endif
+#ifdef TARGET_NR_getpid
+SYSCALL_DEF(getpid);
+#endif
+#ifdef TARGET_NR_getppid
+SYSCALL_DEF(getppid);
+#endif
+SYSCALL_DEF(gettid);
+#ifdef TARGET_NR_getuid
+SYSCALL_DEF(getuid);
+#endif
+#ifdef TARGET_NR_getuid32
+SYSCALL_DEF(getuid32);
+#endif
+#ifdef TARGET_NR_getxgid
+SYSCALL_DEF(getxgid);
+#endif
+#ifdef TARGET_NR_getxpid
+SYSCALL_DEF(getxpid);
+#endif
+#ifdef TARGET_NR_getxuid
+SYSCALL_DEF(getxuid);
+#endif
+#ifdef TARGET_NR_get_thread_area
+# if defined(TARGET_I386) && defined(TARGET_ABI32)
+SYSCALL_DEF_FULL(get_thread_area, .impl = impl_get_thread_area,
+                 .print_ret = print_syscall_ptr_ret,
+                 .arg_type = { ARG_PTR });
+# else
+SYSCALL_DEF_FULL(get_thread_area, .impl = impl_get_thread_area,
+                 .print_ret = print_syscall_ptr_ret);
+# endif
+#endif
 #ifdef TARGET_NR_ipc
 SYSCALL_DEF_ARGS(ipc, ARG_HEX, ARG_DEC, ARG_DEC, ARG_HEX, ARG_PTR, ARG_HEX);
 #endif
@@ -92,6 +165,51 @@ SYSCALL_DEF(semget, ARG_DEC, ARG_DEC, ARG_HEX);
 #if !defined(SYSCALL_TABLE) || defined(TARGET_NR_semop)
 SYSCALL_DEF(semop, ARG_DEC, ARG_PTR, ARG_DEC);
 #endif
+SYSCALL_DEF(setfsgid, ARG_DEC);
+#ifdef TARGET_NR_setfsgid32
+SYSCALL_DEF(setfsgid32, ARG_DEC);
+#endif
+SYSCALL_DEF(setfsuid, ARG_DEC);
+#ifdef TARGET_NR_setfsuid32
+SYSCALL_DEF(setfsuid32, ARG_DEC);
+#endif
+SYSCALL_DEF(setgid, ARG_DEC);
+#ifdef TARGET_NR_setgid32
+SYSCALL_DEF(setgid32, ARG_DEC);
+#endif
+SYSCALL_DEF(setgroups, ARG_DEC, ARG_PTR);
+#ifdef TARGET_NR_setgroups32
+SYSCALL_DEF(setgroups32, ARG_DEC, ARG_PTR);
+#endif
+SYSCALL_DEF(setregid, ARG_DEC, ARG_DEC);
+#ifdef TARGET_NR_setregid32
+SYSCALL_DEF(setregid32, ARG_DEC, ARG_DEC);
+#endif
+#ifdef TARGET_NR_setresgid
+SYSCALL_DEF(setresgid, ARG_DEC, ARG_DEC, ARG_DEC);
+#endif
+#ifdef TARGET_NR_setresgid32
+SYSCALL_DEF(setresgid32, ARG_DEC, ARG_DEC, ARG_DEC);
+#endif
+#ifdef TARGET_NR_setresuid
+SYSCALL_DEF(setresuid, ARG_DEC, ARG_DEC, ARG_DEC);
+#endif
+#ifdef TARGET_NR_setresuid32
+SYSCALL_DEF(setresuid32, ARG_DEC, ARG_DEC, ARG_DEC);
+#endif
+SYSCALL_DEF(setreuid, ARG_DEC, ARG_DEC);
+#ifdef TARGET_NR_setreuid32
+SYSCALL_DEF(setreuid32, ARG_DEC, ARG_DEC);
+#endif
+SYSCALL_DEF(setsid);
+SYSCALL_DEF(setuid, ARG_DEC);
+#ifdef TARGET_NR_setuid32
+SYSCALL_DEF(setuid32, ARG_DEC);
+#endif
+#ifdef TARGET_NR_set_thread_area
+SYSCALL_DEF(set_thread_area, ARG_PTR);
+#endif
+SYSCALL_DEF(set_tid_address, ARG_PTR);
 #if !defined(SYSCALL_TABLE) || defined(TARGET_NR_shmat)
 SYSCALL_DEF_FULL(shmat, .impl = impl_shmat,
                  .print_ret = print_syscall_ptr_ret,
@@ -108,3 +226,6 @@ SYSCALL_DEF(shmget, ARG_DEC, ARG_DEC, ARG_HEX);
 #endif
 SYSCALL_DEF(write, ARG_DEC, ARG_PTR, ARG_DEC);
 SYSCALL_DEF(writev, ARG_DEC, ARG_PTR, ARG_DEC);
+#ifdef TARGET_NR_vfork
+SYSCALL_DEF(vfork);
+#endif
linux-user/syscall.h +1 -0
index 8175de4c31..f75cd3ddd0 100644
@@ -58,6 +58,7 @@ typedef enum {
     /* These print as sets of flags.  */
     ARG_ATDIRFD,
     ARG_ATFLAG,
+    ARG_CLONEFLAG,
     ARG_MMAPFLAG,
     ARG_MMAPPROT,
     ARG_MODEFLAG,
linux-user/strace.c +4 -32
index 8bc7338af8..19b0403d74 100644
@@ -836,7 +836,7 @@ static struct flags const mmap_flags[] = {
     FLAG_END,
 };
 
-UNUSED static struct flags clone_flags[] = {
+static struct flags const clone_flags[] = {
     FLAG_GENERIC(CLONE_VM),
     FLAG_GENERIC(CLONE_FS),
     FLAG_GENERIC(CLONE_FILES),
@@ -1218,37 +1218,6 @@ print_clock_adjtime(const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_clone
-static void do_print_clone(unsigned int flags, abi_ulong newsp,
-                           abi_ulong parent_tidptr, target_ulong newtls,
-                           abi_ulong child_tidptr)
-{
-    print_flags(clone_flags, flags, 0);
-    print_raw_param("child_stack=0x" TARGET_ABI_FMT_lx, newsp, 0);
-    print_raw_param("parent_tidptr=0x" TARGET_ABI_FMT_lx, parent_tidptr, 0);
-    print_raw_param("tls=0x" TARGET_ABI_FMT_lx, newtls, 0);
-    print_raw_param("child_tidptr=0x" TARGET_ABI_FMT_lx, child_tidptr, 1);
-}
-
-static void
-print_clone(const struct syscallname *name,
-    abi_long arg1, abi_long arg2, abi_long arg3,
-    abi_long arg4, abi_long arg5, abi_long arg6)
-{
-    print_syscall_prologue(name);
-#if defined(TARGET_MICROBLAZE)
-    do_print_clone(arg1, arg2, arg4, arg6, arg5);
-#elif defined(TARGET_CLONE_BACKWARDS)
-    do_print_clone(arg1, arg2, arg3, arg4, arg5);
-#elif defined(TARGET_CLONE_BACKWARDS2)
-    do_print_clone(arg2, arg1, arg3, arg5, arg4);
-#else
-    do_print_clone(arg1, arg2, arg3, arg5, arg4);
-#endif
-    print_syscall_epilogue(name);
-}
-#endif
-
 #ifdef TARGET_NR_creat
 static void
 print_creat(const struct syscallname *name,
@@ -2620,6 +2589,9 @@ static void print_syscall_def1(const SyscallDef *def, int64_t args[6])
         case ARG_ATFLAG:
             len = add_flags(b, rest, at_file_flags, arg, false);
             break;
+        case ARG_CLONEFLAG:
+            len = add_flags(b, rest, clone_flags, arg, false);
+            break;
         case ARG_MMAPFLAG:
             len = add_flags(b, rest, mmap_flags, arg, false);
             break;
linux-user/syscall-proc.inc.c new file +861 -0

861 lines not on this page · raw message

linux-user/syscall.c +1 -676

807 lines not on this page · raw message

linux-user/strace.list +0 -147

237 lines not on this page · raw message

Signature · 1 line
2.17.2
#12 lore raw

Re: [Qemu-devel] [PATCH v5 8/8] linux-user: Split out some process syscalls

Quoted 8 lines · Richard Henderson

This includes clone, getgroups, gettid, setfsgid, setfsuid, setgroups, setsid, setuid, fork, getegid, getegid32, geteuid, geteuid32, getgid, getgid32, getgroups32, getpgrp, getpid, getppid, getresgid, getresgid32, getresuid, getresuid32, getuid, getuid32, getxgid, getxpid, getxuid, setfsgid32, setgsuid32, setgid32, setgroups32, setregid, setregid32, setresgid, setresgid32, setresuid, setresuid32, setreuid, setreuid32, setuid32, vfork.

I have errors with getgroups.

Quoted 10 lines
---
 linux-user/syscall-defs.h     | 121 +++++
 linux-user/syscall.h          |   1 +
 linux-user/strace.c           |  36 +-
 linux-user/syscall-proc.inc.c | 861 ++++++++++++++++++++++++++++++++++
 linux-user/syscall.c          | 677 +-------------------------
 linux-user/strace.list        | 147 ------
 6 files changed, 988 insertions(+), 855 deletions(-)
 create mode 100644 linux-user/syscall-proc.inc.c

...

Quoted 5 lines
linux-user/syscall-proc.inc.c new file +0 -0
new file mode 100644
index 0000000000..dee441b4ff

...

linux-user/syscall-proc.inc.c line 410

Quoted 7 lines
linux-user/syscall-proc.inc.c new file +7 -0
+
+SYSCALL_IMPL(getgroups)
+{
+    int gidsetsize = arg1;
+    gid_t *grouplist;
+    abi_long ret;
+

kernel checks for gidsetsize < 0 and returns EINVAL in this case

linux-user/syscall-proc.inc.c line 414

Quoted 4 lines
linux-user/syscall-proc.inc.c new file +4 -0
+    grouplist = g_try_new(gid_t, gidsetsize);
+    if (!grouplist) {
+        return -TARGET_ENOMEM;
+    }

gidsetsize == 0 is a valid case (see man) but it fails with g_try_new(). Moreover, ENOMEM is not a valid error value for getgroups().

Quoted 12 lines
linux-user/syscall-proc.inc.c new file +12 -0
+    ret = get_errno(getgroups(gidsetsize, grouplist));
+
+    if (!is_error(ret) && gidsetsize != 0) {
+        size_t target_grouplist_size = gidsetsize * sizeof(target_id);
+        target_id *target_grouplist
+            = lock_user(VERIFY_WRITE, arg2, target_grouplist_size, 0);
+        if (target_grouplist) {
+            int i;
+            for (i = 0; i < ret; i++) {
+                target_grouplist[i] = tswapid(high2lowgid(grouplist[i]));
+            }
+            unlock_user(target_grouplist, arg2, target_grouplist_size);

linux-user/syscall-proc.inc.c line 436

Quoted 10 lines
linux-user/syscall-proc.inc.c new file +10 -0
+        } else {
+            ret = -TARGET_EFAULT;
+        }
+    }
+    g_free(grouplist);
+    return ret;
+}
+
+#ifdef TARGET_NR_getgroups32
+SYSCALL_IMPL(getgroups32)

likewise.

Thanks,
Laurent

#13 lore raw
In reply to Richard Henderson
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Message-id: [email protected]
Type: series
Subject: [Qemu-devel] [PATCH v5 0/8] linux-user: Split do_syscall

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
f3bfd9f linux-user: Split out some process syscalls
d97db89 linux-user: Split out memory syscalls
cb634c4 linux-user: Split out ipc syscalls
5659cc8 linux-user: Split out name_to_handle_at, open_by_handle_at 67a51d4 linux-user: Split out preadv, pwritev, readv, writev, pread64, pwrite64 677dbe4 linux-user: Reduce regpairs_aligned & target_offset64 ifdefs caa6f94 linux-user: Split out some simple file syscalls
b9d74dd linux-user: Setup split syscall infrastructure

=== OUTPUT BEGIN ===
Checking PATCH 1/8: linux-user: Setup split syscall infrastructure...
ERROR: Macros with complex values should be enclosed in parenthesis #568: FILE: linux-user/syscall.c:11530:
+#define SYSCALL_DEF(NAME, ...) case TARGET_NR_##NAME: return &def_##NAME

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #647:
new file mode 100644

total: 1 errors, 1 warnings, 706 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Checking PATCH 2/8: linux-user: Split out some simple file syscalls...
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #12:
new file mode 100644

total: 0 errors, 1 warnings, 882 lines checked

Your patch has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
Checking PATCH 3/8: linux-user: Reduce regpairs_aligned & target_offset64 ifdefs... Checking PATCH 4/8: linux-user: Split out preadv, pwritev, readv, writev, pread64, pwrite64... Checking PATCH 5/8: linux-user: Split out name_to_handle_at, open_by_handle_at... Checking PATCH 6/8: linux-user: Split out ipc syscalls...
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#259:
new file mode 100644

WARNING: architecture specific defines should be avoided #283: FILE: linux-user/syscall-ipc.inc.c:20:
+#ifdef __NR_msgsnd

total: 0 errors, 2 warnings, 2320 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 7/8: linux-user: Split out memory syscalls...
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #203:
new file mode 100644

total: 0 errors, 1 warnings, 474 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 8/8: linux-user: Split out some process syscalls...
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #476:
new file mode 100644

WARNING: architecture specific defines should be avoided #509: FILE: linux-user/syscall-proc.inc.c:29:
+#ifdef __NR_setuid32

WARNING: architecture specific defines should be avoided #514: FILE: linux-user/syscall-proc.inc.c:34:
+#ifdef __NR_setgid32

WARNING: architecture specific defines should be avoided #519: FILE: linux-user/syscall-proc.inc.c:39:
+#ifdef __NR_setresuid32

WARNING: architecture specific defines should be avoided #524: FILE: linux-user/syscall-proc.inc.c:44:
+#ifdef __NR_setresgid32

WARNING: architecture specific defines should be avoided #535: FILE: linux-user/syscall-proc.inc.c:55:
+#ifndef __NR_gettid

WARNING: architecture specific defines should be avoided #540: FILE: linux-user/syscall-proc.inc.c:60:
+#ifndef __NR_set_tid_address

total: 0 errors, 7 warnings, 2103 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

#14 lore raw
In reply to Richard Henderson
Quoted 8 lines · Richard Henderson

Version 4 was back in August:
https://lists.gnu.org/archive/html/qemu-devel/2018-08/msg03745.html

Version 5 continues the file split via inclusion. This incorporates Laurent's suggestion to have a "def" file that is included twice to generate both SyscallDef structures and fill in syscall_table's switch.

Again, this just converts a few syscalls as proof of concept.

This series breaks on all targets LTP tests: getgroups01, pwritev02, pwritev02_64, and fixes: semop02.

It also breaks more tests only with arm target.

I will bisect and review...

Thanks,
Laurent

Quoted 33 lines

r~

Richard Henderson (8):
linux-user: Setup split syscall infrastructure
linux-user: Split out some simple file syscalls
linux-user: Reduce regpairs_aligned & target_offset64 ifdefs
linux-user: Split out preadv, pwritev, readv, writev, pread64,
pwrite64
linux-user: Split out name_to_handle_at, open_by_handle_at
linux-user: Split out ipc syscalls
linux-user: Split out memory syscalls
linux-user: Split out some process syscalls

 linux-user/syscall-defs.h     |  231 +++
 linux-user/syscall.h          |   93 ++
 linux-user/strace.c           |  567 ++++----
 linux-user/syscall-file.inc.c |  638 +++++++++
 linux-user/syscall-ipc.inc.c  | 1086 ++++++++++++++
 linux-user/syscall-mem.inc.c  |  154 ++
 linux-user/syscall-proc.inc.c |  861 ++++++++++++
 linux-user/syscall.c          | 2500 ++-------------------------------
 linux-user/strace.list        |  243 ----
 9 files changed, 3499 insertions(+), 2874 deletions(-)
 create mode 100644 linux-user/syscall-defs.h
 create mode 100644 linux-user/syscall.h
 create mode 100644 linux-user/syscall-file.inc.c
 create mode 100644 linux-user/syscall-ipc.inc.c
 create mode 100644 linux-user/syscall-mem.inc.c
 create mode 100644 linux-user/syscall-proc.inc.c