Skip to contentSkip to conversation

linux-user: Add more syscalls, enhance tracing & logging enhancements

PATCH Superseded Helge Deller 2 participants 21 messages Aug 26, 2022 – Aug 29, 2022

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover linux-user: Add more syscalls, enhance tracing & logging enhancements

Here is a bunch of patches for linux-user, all of them for qemu-v7.2.

Most of them add missing syscalls and enhance the tracing/logging. Some of the patches are target-hppa specific.
I've tested those on productive hppa debian buildd servers (running qemu-user).

Please check.

Thanks!
Helge

Helge Deller (13):
linux-user: Add missing signals in strace output
linux-user: Add missing clock_gettime64() syscall strace
linux-user: Add faccessat2() syscall
linux-user: Add pidfd_open(), pidfd_send_signal() and pidfd_getfd()
syscalls
linux-user: Log failing executable in EXCP_DUMP() linux-user/hppa: Use EXCP_DUMP() to show enhanced debug info linux-user/hppa: Dump IIR on register dump
linux-user: Fix strace of chmod() if mode == 0 linux-user/hppa: Set TASK_UNMAPPED_BASE to 0xfa000000 for hppa arch
linux-user: Add strace for clock_nanosleep()
linux-user: Show timespec on strace for futex()
linux-user: Add close_range() syscall
linux-user: Add parameters of getrandom() syscall for strace

 linux-user/cpu_loop-common.h |   2 +
 linux-user/hppa/cpu_loop.c   |   6 +-
 linux-user/mmap.c            |   4 +
 linux-user/signal-common.h   |  46 +++++++++++
 linux-user/signal.c          |  37 +--------
 linux-user/strace.c          | 144 +++++++++++++++++++++++++++++------
 linux-user/strace.list       |  24 +++++-
 linux-user/syscall.c         |  58 ++++++++++++++
 target/hppa/helper.c         |   6 +-
 9 files changed, 266 insertions(+), 61 deletions(-)

--
2.37.1

#1 lore raw

PATCH 1/13 linux-user: Add missing signals in strace output

Some of the guest signal numbers are currently not converted to their representative names in the strace output, e.g. SIGVTALRM.

This patch introduces a smart way to generate and keep in sync the host-to-guest and guest-to-host signal conversion tables for usage in the qemu signal and strace code. This ensures that any signals will now show up in both tables.

There is no functional change in this patch - with the exception that yet missing signal names now show up in the strace code too.

---
 linux-user/signal-common.h | 46 ++++++++++++++++++++++++++++++++++++++
 linux-user/signal.c        | 37 +++---------------------------
 linux-user/strace.c        | 31 +++++++++----------------
 3 files changed, 60 insertions(+), 54 deletions(-)
linux-user/signal-common.h +46 -0
index 6a7e4a93fc..c2549bcd3e 100644
@@ -118,4 +118,50 @@ static inline void finish_sigsuspend_mask(int ret)
     }
 }
 
+#ifdef SIGSTKFLT
+#define MAKE_SIG_ENTRY_SIGSTKFLT        MAKE_SIG_ENTRY(SIGSTKFLT)
+#else
+#define MAKE_SIG_ENTRY_SIGSTKFLT
+#endif
+
+#ifdef SIGIOT
+#define MAKE_SIG_ENTRY_SIGIOT           MAKE_SIG_ENTRY(SIGIOT)
+#else
+#define MAKE_SIG_ENTRY_SIGIOT
+#endif
+
+#define MAKE_SIGNAL_LIST \
+	MAKE_SIG_ENTRY(SIGHUP) \
+	MAKE_SIG_ENTRY(SIGINT) \
+	MAKE_SIG_ENTRY(SIGQUIT) \
+	MAKE_SIG_ENTRY(SIGILL) \
+	MAKE_SIG_ENTRY(SIGTRAP) \
+	MAKE_SIG_ENTRY(SIGABRT) \
+	MAKE_SIG_ENTRY(SIGBUS) \
+	MAKE_SIG_ENTRY(SIGFPE) \
+	MAKE_SIG_ENTRY(SIGKILL) \
+	MAKE_SIG_ENTRY(SIGUSR1) \
+	MAKE_SIG_ENTRY(SIGSEGV) \
+	MAKE_SIG_ENTRY(SIGUSR2) \
+	MAKE_SIG_ENTRY(SIGPIPE) \
+	MAKE_SIG_ENTRY(SIGALRM) \
+	MAKE_SIG_ENTRY(SIGTERM) \
+	MAKE_SIG_ENTRY(SIGCHLD) \
+	MAKE_SIG_ENTRY(SIGCONT) \
+	MAKE_SIG_ENTRY(SIGSTOP) \
+	MAKE_SIG_ENTRY(SIGTSTP) \
+	MAKE_SIG_ENTRY(SIGTTIN) \
+	MAKE_SIG_ENTRY(SIGTTOU) \
+	MAKE_SIG_ENTRY(SIGURG) \
+	MAKE_SIG_ENTRY(SIGXCPU) \
+	MAKE_SIG_ENTRY(SIGXFSZ) \
+	MAKE_SIG_ENTRY(SIGVTALRM) \
+	MAKE_SIG_ENTRY(SIGPROF) \
+	MAKE_SIG_ENTRY(SIGWINCH) \
+	MAKE_SIG_ENTRY(SIGIO) \
+	MAKE_SIG_ENTRY(SIGPWR) \
+	MAKE_SIG_ENTRY(SIGSYS) \
+	MAKE_SIG_ENTRY_SIGSTKFLT \
+	MAKE_SIG_ENTRY_SIGIOT
+
 #endif
linux-user/signal.c +3 -34
index 8d29bfaa6b..03b4d5e6ee 100644
@@ -53,40 +53,9 @@ abi_ulong default_rt_sigreturn;
 QEMU_BUILD_BUG_ON(__SIGRTMAX + 1 != _NSIG);
 #endif
 static uint8_t host_to_target_signal_table[_NSIG] = {
-    [SIGHUP] = TARGET_SIGHUP,
-    [SIGINT] = TARGET_SIGINT,
-    [SIGQUIT] = TARGET_SIGQUIT,
-    [SIGILL] = TARGET_SIGILL,
-    [SIGTRAP] = TARGET_SIGTRAP,
-    [SIGABRT] = TARGET_SIGABRT,
-/*    [SIGIOT] = TARGET_SIGIOT,*/
-    [SIGBUS] = TARGET_SIGBUS,
-    [SIGFPE] = TARGET_SIGFPE,
-    [SIGKILL] = TARGET_SIGKILL,
-    [SIGUSR1] = TARGET_SIGUSR1,
-    [SIGSEGV] = TARGET_SIGSEGV,
-    [SIGUSR2] = TARGET_SIGUSR2,
-    [SIGPIPE] = TARGET_SIGPIPE,
-    [SIGALRM] = TARGET_SIGALRM,
-    [SIGTERM] = TARGET_SIGTERM,
-#ifdef SIGSTKFLT
-    [SIGSTKFLT] = TARGET_SIGSTKFLT,
-#endif
-    [SIGCHLD] = TARGET_SIGCHLD,
-    [SIGCONT] = TARGET_SIGCONT,
-    [SIGSTOP] = TARGET_SIGSTOP,
-    [SIGTSTP] = TARGET_SIGTSTP,
-    [SIGTTIN] = TARGET_SIGTTIN,
-    [SIGTTOU] = TARGET_SIGTTOU,
-    [SIGURG] = TARGET_SIGURG,
-    [SIGXCPU] = TARGET_SIGXCPU,
-    [SIGXFSZ] = TARGET_SIGXFSZ,
-    [SIGVTALRM] = TARGET_SIGVTALRM,
-    [SIGPROF] = TARGET_SIGPROF,
-    [SIGWINCH] = TARGET_SIGWINCH,
-    [SIGIO] = TARGET_SIGIO,
-    [SIGPWR] = TARGET_SIGPWR,
-    [SIGSYS] = TARGET_SIGSYS,
+#define MAKE_SIG_ENTRY(sig)     [sig] = TARGET_##sig,
+	MAKE_SIGNAL_LIST
+#undef MAKE_SIG_ENTRY
     /* next signals stay the same */
 };
 
linux-user/strace.c +11 -20
index 7d882526da..a217c1025a 100644
@@ -17,6 +17,7 @@
 #include "qemu.h"
 #include "user-internals.h"
 #include "strace.h"
+#include "signal-common.h"
 
 struct syscallname {
     int nr;
@@ -141,30 +142,20 @@ if( cmd == val ) { \
     qemu_log("%d", cmd);
 }
 
+static const char *target_signal_to_host_signal_table[_NSIG] = {
+#define MAKE_SIG_ENTRY(sig)     [TARGET_##sig] = #sig,
+        MAKE_SIGNAL_LIST
+#undef MAKE_SIG_ENTRY
+};
+
 static void
 print_signal(abi_ulong arg, int last)
 {
     const char *signal_name = NULL;
-    switch(arg) {
-    case TARGET_SIGHUP: signal_name = "SIGHUP"; break;
-    case TARGET_SIGINT: signal_name = "SIGINT"; break;
-    case TARGET_SIGQUIT: signal_name = "SIGQUIT"; break;
-    case TARGET_SIGILL: signal_name = "SIGILL"; break;
-    case TARGET_SIGABRT: signal_name = "SIGABRT"; break;
-    case TARGET_SIGFPE: signal_name = "SIGFPE"; break;
-    case TARGET_SIGKILL: signal_name = "SIGKILL"; break;
-    case TARGET_SIGSEGV: signal_name = "SIGSEGV"; break;
-    case TARGET_SIGPIPE: signal_name = "SIGPIPE"; break;
-    case TARGET_SIGALRM: signal_name = "SIGALRM"; break;
-    case TARGET_SIGTERM: signal_name = "SIGTERM"; break;
-    case TARGET_SIGUSR1: signal_name = "SIGUSR1"; break;
-    case TARGET_SIGUSR2: signal_name = "SIGUSR2"; break;
-    case TARGET_SIGCHLD: signal_name = "SIGCHLD"; break;
-    case TARGET_SIGCONT: signal_name = "SIGCONT"; break;
-    case TARGET_SIGSTOP: signal_name = "SIGSTOP"; break;
-    case TARGET_SIGTTIN: signal_name = "SIGTTIN"; break;
-    case TARGET_SIGTTOU: signal_name = "SIGTTOU"; break;
-    }
+
+    if (arg < _NSIG)
+        signal_name = target_signal_to_host_signal_table[arg];
+
     if (signal_name == NULL) {
         print_raw_param("%ld", arg, last);
         return;

--
2.37.1

#2 lore raw

Re: [PATCH 01/13] linux-user: Add missing signals in strace output

Quoted 1 line · Helge Deller

+static const char *target_signal_to_host_signal_table[_NSIG] = {

(1) static const char * const
(2) target_signal_name -- there's no "host" about this.

r~

#3 lore raw

Re: [PATCH 01/13] linux-user: Add missing signals in strace output

In reply to Helge Deller

linux-user/strace.c if( cmd == val ) { \ · line 157

Quoted 2 lines · Helge Deller
linux-user/strace.c +2 -0
+    if (arg < _NSIG)
+        signal_name = target_signal_to_host_signal_table[arg];

Oh, and _NSIG is a host thing. Leave the array as [] and then bound the lookup with ARRAY_SIZE(target_signal_name). Also, missing {}.

r~

#4 lore raw

Re: [PATCH 01/13] linux-user: Add missing signals in strace output

* Richard Henderson <[email protected]>:

Quoted 9 lines · Helge Deller

Review

Quoted 2 lines
(quoted diff) +2 -0
+    if (arg < _NSIG)
+        signal_name = target_signal_to_host_signal_table[arg];

(1) static const char * const
(2) target_signal_name -- there's no "host" about this.

Oh, and _NSIG is a host thing. Leave the array as [] and then bound the lookup with ARRAY_SIZE(target_signal_name). Also, missing {}.

Thanks for the review!

I've addressed your feedback in the patch below. Additionally I fixed the indenting in the table.

All patches (including this one) is available in the git repo at:
https://github.com/hdeller/qemu-hppa/tree/publish1

Helge

From ff8e95709d2d6f9a7d8e452671aea16ed60c5114 Mon Sep 17 00:00:00 2001
From: Helge Deller <[email protected]>
Date: Wed, 27 Jul 2022 16:44:05 +0200
Subject: [PATCH] linux-user: Add missing signals in strace output

Some of the guest signal numbers are currently not converted to their representative names in the strace output, e.g. SIGVTALRM.

This patch introduces a smart way to generate and keep in sync the host-to-guest and guest-to-host signal conversion tables for usage in the qemu signal and strace code. This ensures that any signals will now show up in both tables.

There is no functional change in this patch - with the exception that yet missing signal names now show up in the strace code too.

linux-user/signal-common.h +46 -0
index 6a7e4a93fc..0faf533b47 100644
@@ -118,4 +118,50 @@ static inline void finish_sigsuspend_mask(int ret)
     }
 }
 
+#ifdef SIGSTKFLT
+#define MAKE_SIG_ENTRY_SIGSTKFLT        MAKE_SIG_ENTRY(SIGSTKFLT)
+#else
+#define MAKE_SIG_ENTRY_SIGSTKFLT
+#endif
+
+#ifdef SIGIOT
+#define MAKE_SIG_ENTRY_SIGIOT           MAKE_SIG_ENTRY(SIGIOT)
+#else
+#define MAKE_SIG_ENTRY_SIGIOT
+#endif
+
+#define MAKE_SIGNAL_LIST \
+        MAKE_SIG_ENTRY(SIGHUP) \
+        MAKE_SIG_ENTRY(SIGINT) \
+        MAKE_SIG_ENTRY(SIGQUIT) \
+        MAKE_SIG_ENTRY(SIGILL) \
+        MAKE_SIG_ENTRY(SIGTRAP) \
+        MAKE_SIG_ENTRY(SIGABRT) \
+        MAKE_SIG_ENTRY(SIGBUS) \
+        MAKE_SIG_ENTRY(SIGFPE) \
+        MAKE_SIG_ENTRY(SIGKILL) \
+        MAKE_SIG_ENTRY(SIGUSR1) \
+        MAKE_SIG_ENTRY(SIGSEGV) \
+        MAKE_SIG_ENTRY(SIGUSR2) \
+        MAKE_SIG_ENTRY(SIGPIPE) \
+        MAKE_SIG_ENTRY(SIGALRM) \
+        MAKE_SIG_ENTRY(SIGTERM) \
+        MAKE_SIG_ENTRY(SIGCHLD) \
+        MAKE_SIG_ENTRY(SIGCONT) \
+        MAKE_SIG_ENTRY(SIGSTOP) \
+        MAKE_SIG_ENTRY(SIGTSTP) \
+        MAKE_SIG_ENTRY(SIGTTIN) \
+        MAKE_SIG_ENTRY(SIGTTOU) \
+        MAKE_SIG_ENTRY(SIGURG) \
+        MAKE_SIG_ENTRY(SIGXCPU) \
+        MAKE_SIG_ENTRY(SIGXFSZ) \
+        MAKE_SIG_ENTRY(SIGVTALRM) \
+        MAKE_SIG_ENTRY(SIGPROF) \
+        MAKE_SIG_ENTRY(SIGWINCH) \
+        MAKE_SIG_ENTRY(SIGIO) \
+        MAKE_SIG_ENTRY(SIGPWR) \
+        MAKE_SIG_ENTRY(SIGSYS) \
+        MAKE_SIG_ENTRY_SIGSTKFLT \
+        MAKE_SIG_ENTRY_SIGIOT
+
 #endif
linux-user/signal.c +3 -34
index 8d29bfaa6b..61c6fa3fcf 100644
@@ -53,40 +53,9 @@ abi_ulong default_rt_sigreturn;
 QEMU_BUILD_BUG_ON(__SIGRTMAX + 1 != _NSIG);
 #endif
 static uint8_t host_to_target_signal_table[_NSIG] = {
-    [SIGHUP] = TARGET_SIGHUP,
-    [SIGINT] = TARGET_SIGINT,
-    [SIGQUIT] = TARGET_SIGQUIT,
-    [SIGILL] = TARGET_SIGILL,
-    [SIGTRAP] = TARGET_SIGTRAP,
-    [SIGABRT] = TARGET_SIGABRT,
-/*    [SIGIOT] = TARGET_SIGIOT,*/
-    [SIGBUS] = TARGET_SIGBUS,
-    [SIGFPE] = TARGET_SIGFPE,
-    [SIGKILL] = TARGET_SIGKILL,
-    [SIGUSR1] = TARGET_SIGUSR1,
-    [SIGSEGV] = TARGET_SIGSEGV,
-    [SIGUSR2] = TARGET_SIGUSR2,
-    [SIGPIPE] = TARGET_SIGPIPE,
-    [SIGALRM] = TARGET_SIGALRM,
-    [SIGTERM] = TARGET_SIGTERM,
-#ifdef SIGSTKFLT
-    [SIGSTKFLT] = TARGET_SIGSTKFLT,
-#endif
-    [SIGCHLD] = TARGET_SIGCHLD,
-    [SIGCONT] = TARGET_SIGCONT,
-    [SIGSTOP] = TARGET_SIGSTOP,
-    [SIGTSTP] = TARGET_SIGTSTP,
-    [SIGTTIN] = TARGET_SIGTTIN,
-    [SIGTTOU] = TARGET_SIGTTOU,
-    [SIGURG] = TARGET_SIGURG,
-    [SIGXCPU] = TARGET_SIGXCPU,
-    [SIGXFSZ] = TARGET_SIGXFSZ,
-    [SIGVTALRM] = TARGET_SIGVTALRM,
-    [SIGPROF] = TARGET_SIGPROF,
-    [SIGWINCH] = TARGET_SIGWINCH,
-    [SIGIO] = TARGET_SIGIO,
-    [SIGPWR] = TARGET_SIGPWR,
-    [SIGSYS] = TARGET_SIGSYS,
+#define MAKE_SIG_ENTRY(sig)     [sig] = TARGET_##sig,
+        MAKE_SIGNAL_LIST
+#undef MAKE_SIG_ENTRY
     /* next signals stay the same */
 };
 
linux-user/strace.c +11 -19
index 7d882526da..ae4444a6ca 100644
@@ -17,6 +17,7 @@
 #include "qemu.h"
 #include "user-internals.h"
 #include "strace.h"
+#include "signal-common.h"
 
 struct syscallname {
     int nr;
@@ -141,30 +142,21 @@ if( cmd == val ) { \
     qemu_log("%d", cmd);
 }
 
+static const char * const target_signal_name[] = {
+#define MAKE_SIG_ENTRY(sig)     [TARGET_##sig] = #sig,
+        MAKE_SIGNAL_LIST
+#undef MAKE_SIG_ENTRY
+};
+
 static void
 print_signal(abi_ulong arg, int last)
 {
     const char *signal_name = NULL;
-    switch(arg) {
-    case TARGET_SIGHUP: signal_name = "SIGHUP"; break;
-    case TARGET_SIGINT: signal_name = "SIGINT"; break;
-    case TARGET_SIGQUIT: signal_name = "SIGQUIT"; break;
-    case TARGET_SIGILL: signal_name = "SIGILL"; break;
-    case TARGET_SIGABRT: signal_name = "SIGABRT"; break;
-    case TARGET_SIGFPE: signal_name = "SIGFPE"; break;
-    case TARGET_SIGKILL: signal_name = "SIGKILL"; break;
-    case TARGET_SIGSEGV: signal_name = "SIGSEGV"; break;
-    case TARGET_SIGPIPE: signal_name = "SIGPIPE"; break;
-    case TARGET_SIGALRM: signal_name = "SIGALRM"; break;
-    case TARGET_SIGTERM: signal_name = "SIGTERM"; break;
-    case TARGET_SIGUSR1: signal_name = "SIGUSR1"; break;
-    case TARGET_SIGUSR2: signal_name = "SIGUSR2"; break;
-    case TARGET_SIGCHLD: signal_name = "SIGCHLD"; break;
-    case TARGET_SIGCONT: signal_name = "SIGCONT"; break;
-    case TARGET_SIGSTOP: signal_name = "SIGSTOP"; break;
-    case TARGET_SIGTTIN: signal_name = "SIGTTIN"; break;
-    case TARGET_SIGTTOU: signal_name = "SIGTTOU"; break;
+
+    if (arg < ARRAY_SIZE(target_signal_name)) {
+        signal_name = target_signal_name[arg];
     }
+
     if (signal_name == NULL) {
         print_raw_param("%ld", arg, last);
         return;
#5 lore raw

Re: [PATCH 01/13] linux-user: Add missing signals in strace output

In reply to Helge Deller
Quoted 27 lines · Helge Deller

Some of the guest signal numbers are currently not converted to their representative names in the strace output, e.g. SIGVTALRM.

This patch introduces a smart way to generate and keep in sync the host-to-guest and guest-to-host signal conversion tables for usage in the qemu signal and strace code. This ensures that any signals will now show up in both tables.

There is no functional change in this patch - with the exception that yet missing signal names now show up in the strace code too.

---
  linux-user/signal-common.h | 46 ++++++++++++++++++++++++++++++++++++++
  linux-user/signal.c        | 37 +++---------------------------
  linux-user/strace.c        | 31 +++++++++----------------
  3 files changed, 60 insertions(+), 54 deletions(-)
linux-user/signal-common.h +1 -0
index 6a7e4a93fc..c2549bcd3e 100644
@@ -118,4 +118,50 @@ static inline void finish_sigsuspend_mask(int ret)
      }
  }
 
+#ifdef SIGSTKFLT

linux-user/signal-common.h static inline void finish_sigsuspend_mask(int ret) · line 131

Quoted 10 lines
linux-user/signal-common.h +10 -0
+#define MAKE_SIG_ENTRY_SIGSTKFLT        MAKE_SIG_ENTRY(SIGSTKFLT)
+#else
+#define MAKE_SIG_ENTRY_SIGSTKFLT
+#endif
+
+#ifdef SIGIOT
+#define MAKE_SIG_ENTRY_SIGIOT           MAKE_SIG_ENTRY(SIGIOT)
+#else
+#define MAKE_SIG_ENTRY_SIGIOT
+#endif

This doesn't compile when TARGET_SIGIOT does not exist, e.g. qemu-arm.

r~

#6 lore raw

PATCH 2/13 linux-user: Add missing clock_gettime64() syscall strace

In reply to Helge Deller

Allow linux-user to strace the clock_gettime64() syscall. This syscall is used a lot on 32-bit guest architectures which use newer glibc versions.

---
 linux-user/strace.c    | 53 ++++++++++++++++++++++++++++++++++++++++++
 linux-user/strace.list |  4 ++++
 2 files changed, 57 insertions(+)
linux-user/strace.c +53 -0
index a217c1025a..27309f1106 100644
@@ -82,6 +82,7 @@ UNUSED static void print_buf(abi_long addr, abi_long len, int last);
 UNUSED static void print_raw_param(const char *, abi_long, int);
 UNUSED static void print_timeval(abi_ulong, int);
 UNUSED static void print_timespec(abi_ulong, int);
+UNUSED static void print_timespec64(abi_ulong, int);
 UNUSED static void print_timezone(abi_ulong, int);
 UNUSED static void print_itimerval(abi_ulong, int);
 UNUSED static void print_number(abi_long, int);
@@ -794,6 +795,24 @@ print_syscall_ret_clock_gettime(CPUArchState *cpu_env, const struct syscallname
 #define print_syscall_ret_clock_getres     print_syscall_ret_clock_gettime
 #endif
 
+#if defined(TARGET_NR_clock_gettime64)
+static void
+print_syscall_ret_clock_gettime64(CPUArchState *cpu_env, const struct syscallname *name,
+                                abi_long ret, abi_long arg0, abi_long arg1,
+                                abi_long arg2, abi_long arg3, abi_long arg4,
+                                abi_long arg5)
+{
+    if (!print_syscall_err(ret)) {
+        qemu_log(TARGET_ABI_FMT_ld, ret);
+        qemu_log(" (");
+        print_timespec64(arg1, 1);
+        qemu_log(")");
+    }
+
+    qemu_log("\n");
+}
+#endif
+
 #ifdef TARGET_NR_gettimeofday
 static void
 print_syscall_ret_gettimeofday(CPUArchState *cpu_env, const struct syscallname *name,
@@ -1651,6 +1670,27 @@ print_timespec(abi_ulong ts_addr, int last)
     }
 }
 
+static void
+print_timespec64(abi_ulong ts_addr, int last)
+{
+    if (ts_addr) {
+        struct target__kernel_timespec *ts;
+
+        ts = lock_user(VERIFY_READ, ts_addr, sizeof(*ts), 1);
+        if (!ts) {
+            print_pointer(ts_addr, last);
+            return;
+        }
+        qemu_log("{tv_sec = %lld"
+                 ",tv_nsec = %lld}%s",
+                 (long long)tswap64(ts->tv_sec), (long long)tswap64(ts->tv_nsec),
+                 get_comma(last));
+        unlock_user(ts, ts_addr, 0);
+    } else {
+        qemu_log("NULL%s", get_comma(last));
+    }
+}
+
 static void
 print_timezone(abi_ulong tz_addr, int last)
 {
@@ -2266,6 +2306,19 @@ print_clock_gettime(CPUArchState *cpu_env, const struct syscallname *name,
 #define print_clock_getres     print_clock_gettime
 #endif
 
+#if defined(TARGET_NR_clock_gettime64)
+static void
+print_clock_gettime64(CPUArchState *cpu_env, 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_enums(clockids, arg0, 0);
+    print_pointer(arg1, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_clock_settime
 static void
 print_clock_settime(CPUArchState *cpu_env, const struct syscallname *name,
linux-user/strace.list +4 -0
index 72e17b1acf..a78cdf3cdf 100644
@@ -1676,3 +1676,7 @@
 #ifdef TARGET_NR_copy_file_range
 { TARGET_NR_copy_file_range, "copy_file_range", "%s(%d,%p,%d,%p,"TARGET_ABI_FMT_lu",%u)", NULL, NULL },
 #endif
+#ifdef TARGET_NR_clock_gettime64
+{ TARGET_NR_clock_gettime64, "clock_gettime64" , NULL, print_clock_gettime64,
+                           print_syscall_ret_clock_gettime64 },
+#endif

--
2.37.1

#7 lore raw

PATCH 3/13 linux-user: Add faccessat2() syscall

In reply to Helge Deller

Add implementation and strace output for faccessat2().

---
 linux-user/strace.c    |  2 +-
 linux-user/strace.list |  3 +++
 linux-user/syscall.c   | 12 ++++++++++++
 3 files changed, 16 insertions(+), 1 deletion(-)
linux-user/strace.c +1 -1
index 27309f1106..e8c63aa4c2 100644
@@ -1962,7 +1962,7 @@ print_execv(CPUArchState *cpu_env, const struct syscallname *name,
 }
 #endif
 
-#ifdef TARGET_NR_faccessat
+#if defined(TARGET_NR_faccessat) || defined(TARGET_NR_faccessat2)
 static void
 print_faccessat(CPUArchState *cpu_env, const struct syscallname *name,
                 abi_long arg0, abi_long arg1, abi_long arg2,
linux-user/strace.list +3 -0
index a78cdf3cdf..6e88da7fad 100644
@@ -177,6 +177,9 @@
 #ifdef TARGET_NR_faccessat
 { TARGET_NR_faccessat, "faccessat" , NULL, print_faccessat, NULL },
 #endif
+#ifdef TARGET_NR_faccessat2
+{ TARGET_NR_faccessat2, "faccessat2" , NULL, print_faccessat, NULL },
+#endif
 #ifdef TARGET_NR_fadvise64
 { TARGET_NR_fadvise64, "fadvise64" , NULL, NULL, NULL },
 #endif
linux-user/syscall.c +12 -0
index f409121202..f51c4fbabd 100644
@@ -399,6 +399,9 @@ _syscall3(int, ioprio_set, int, which, int, who, int, ioprio)
 #if defined(TARGET_NR_getrandom) && defined(__NR_getrandom)
 _syscall3(int, getrandom, void *, buf, size_t, buflen, unsigned int, flags)
 #endif
+#if defined(TARGET_NR_faccessat2) && defined(__NR_faccessat2)
+_syscall4(int, faccessat2, int, dirfd, char *, pathname, int, mode, int, flags)
+#endif
 
 #if defined(TARGET_NR_kcmp) && defined(__NR_kcmp)
 _syscall5(int, kcmp, pid_t, pid1, pid_t, pid2, int, type,
@@ -9098,6 +9101,15 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
         unlock_user(p, arg2, 0);
         return ret;
 #endif
+#if defined(TARGET_NR_faccessat2) && defined(__NR_faccessat2)
+    case TARGET_NR_faccessat2:
+        if (!(p = lock_user_string(arg2))) {
+            return -TARGET_EFAULT;
+        }
+        ret = get_errno(faccessat2(arg1, p, arg3, arg4));
+        unlock_user(p, arg2, 0);
+        return ret;
+#endif
 #ifdef TARGET_NR_nice /* not on alpha */
     case TARGET_NR_nice:
         return get_errno(nice(arg1));

--
2.37.1

#8 lore raw

Re: [PATCH 03/13] linux-user: Add faccessat2() syscall

Quoted 8 lines · Helge Deller

Add implementation and strace output for faccessat2().

---
  linux-user/strace.c    |  2 +-
  linux-user/strace.list |  3 +++
  linux-user/syscall.c   | 12 ++++++++++++
  3 files changed, 16 insertions(+), 1 deletion(-)

I've done this one, and cleaned up the code a bit too:

https://lore.kernel.org/qemu-devel/[email protected]/

r~

Quoted 61 lines
linux-user/strace.c +1 -1
index 27309f1106..e8c63aa4c2 100644
@@ -1962,7 +1962,7 @@ print_execv(CPUArchState *cpu_env, const struct syscallname *name,
  }
  #endif
 
-#ifdef TARGET_NR_faccessat
+#if defined(TARGET_NR_faccessat) || defined(TARGET_NR_faccessat2)
  static void
  print_faccessat(CPUArchState *cpu_env, const struct syscallname *name,
                  abi_long arg0, abi_long arg1, abi_long arg2,
linux-user/strace.list +3 -0
index a78cdf3cdf..6e88da7fad 100644
@@ -177,6 +177,9 @@
  #ifdef TARGET_NR_faccessat
  { TARGET_NR_faccessat, "faccessat" , NULL, print_faccessat, NULL },
  #endif
+#ifdef TARGET_NR_faccessat2
+{ TARGET_NR_faccessat2, "faccessat2" , NULL, print_faccessat, NULL },
+#endif
  #ifdef TARGET_NR_fadvise64
  { TARGET_NR_fadvise64, "fadvise64" , NULL, NULL, NULL },
  #endif
linux-user/syscall.c +12 -1
index f409121202..f51c4fbabd 100644
@@ -399,6 +399,9 @@ _syscall3(int, ioprio_set, int, which, int, who, int, ioprio)
  #if defined(TARGET_NR_getrandom) && defined(__NR_getrandom)
  _syscall3(int, getrandom, void *, buf, size_t, buflen, unsigned int, flags)
  #endif
+#if defined(TARGET_NR_faccessat2) && defined(__NR_faccessat2)
+_syscall4(int, faccessat2, int, dirfd, char *, pathname, int, mode, int, flags)
+#endif
 
  #if defined(TARGET_NR_kcmp) && defined(__NR_kcmp)
  _syscall5(int, kcmp, pid_t, pid1, pid_t, pid2, int, type,
@@ -9098,6 +9101,15 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
          unlock_user(p, arg2, 0);
          return ret;
  #endif
+#if defined(TARGET_NR_faccessat2) && defined(__NR_faccessat2)
+    case TARGET_NR_faccessat2:
+        if (!(p = lock_user_string(arg2))) {
+            return -TARGET_EFAULT;
+        }
+        ret = get_errno(faccessat2(arg1, p, arg3, arg4));
+        unlock_user(p, arg2, 0);
+        return ret;
+#endif
  #ifdef TARGET_NR_nice /* not on alpha */
      case TARGET_NR_nice:
          return get_errno(nice(arg1));
--

2.37.1

#9 lore raw

Re: [PATCH 03/13] linux-user: Add faccessat2() syscall

Quoted 10 lines · Richard Henderson
Quoted 8 lines · Helge Deller

Add implementation and strace output for faccessat2().

---
  linux-user/strace.c    |  2 +-
  linux-user/strace.list |  3 +++
  linux-user/syscall.c   | 12 ++++++++++++

  3 files changed, 16 insertions(+), 1 deletion(-)
Quoted 3 lines

I've done this one, and cleaned up the code a bit too:

https://lore.kernel.org/qemu-devel/[email protected]/

Btw, your patch is missing the strace parts.

Furthermore, IMHO I think it's a bad idea to replace userspace-requested syscalls with other (emulated) syscalls - UNLESS(!!) we have to.

I'm debugging frequenty failures with qemu-user which happen building debian packages. For that I often compare native strace output with qemu QEMU_STRACE=1 output. If you replace syscalls with others it makes comparing differences harder.

And, with your patch, if the target has TARGET_NR_faccessat2, but the host hasn't (and as such emulate it via the host libc), a configure check in the guest would return success. I think it's better to let the guest then fall back, not the host.

I think we should really just emulate the syscalls the host kernel provides.

Anyway, I'm still ok to drop my patch if you want.

Helge

Quoted 66 lines

r~

Quoted 61 lines
linux-user/strace.c +1 -1
index 27309f1106..e8c63aa4c2 100644
@@ -1962,7 +1962,7 @@ print_execv(CPUArchState *cpu_env, const struct syscallname *name,
   }
   #endif
 
-#ifdef TARGET_NR_faccessat
+#if defined(TARGET_NR_faccessat) || defined(TARGET_NR_faccessat2)

  static void
  print_faccessat(CPUArchState *cpu_env, const struct syscallname *name, abi_long arg0, abi_long arg1, abi_long arg2,

linux-user/strace.list +3 -0
index a78cdf3cdf..6e88da7fad 100644
@@ -177,6 +177,9 @@
   #ifdef TARGET_NR_faccessat
   { TARGET_NR_faccessat, "faccessat" , NULL, print_faccessat, NULL },
   #endif
+#ifdef TARGET_NR_faccessat2
+{ TARGET_NR_faccessat2, "faccessat2" , NULL, print_faccessat, NULL },
+#endif
   #ifdef TARGET_NR_fadvise64
   { TARGET_NR_fadvise64, "fadvise64" , NULL, NULL, NULL },
   #endif
linux-user/syscall.c +12 -0
index f409121202..f51c4fbabd 100644
@@ -399,6 +399,9 @@ _syscall3(int, ioprio_set, int, which, int, who, int, ioprio)
   #if defined(TARGET_NR_getrandom) && defined(__NR_getrandom)
   _syscall3(int, getrandom, void *, buf, size_t, buflen, unsigned int, flags)
   #endif
+#if defined(TARGET_NR_faccessat2) && defined(__NR_faccessat2)
+_syscall4(int, faccessat2, int, dirfd, char *, pathname, int, mode, int, flags)
+#endif
 
   #if defined(TARGET_NR_kcmp) && defined(__NR_kcmp)
   _syscall5(int, kcmp, pid_t, pid1, pid_t, pid2, int, type,
@@ -9098,6 +9101,15 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
           unlock_user(p, arg2, 0);
           return ret;
   #endif
+#if defined(TARGET_NR_faccessat2) && defined(__NR_faccessat2)
+    case TARGET_NR_faccessat2:
+        if (!(p = lock_user_string(arg2))) {
+            return -TARGET_EFAULT;
+        }
+        ret = get_errno(faccessat2(arg1, p, arg3, arg4));
+        unlock_user(p, arg2, 0);
+        return ret;
+#endif
   #ifdef TARGET_NR_nice /* not on alpha */

      case TARGET_NR_nice:
          return get_errno(nice(arg1));
--
2.37.1

#10 lore raw

PATCH 4/13 linux-user: Add pidfd_open(), pidfd_send_signal() and pidfd_getfd() syscalls

In reply to Helge Deller

I noticed those were missing when running the glib2.0 testsuite. Add the syscalls including the strace output.

---
 linux-user/strace.c    | 28 ++++++++++++++++++++++++++++
 linux-user/strace.list |  9 +++++++++
 linux-user/syscall.c   | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+)
linux-user/strace.c +28 -0
index e8c63aa4c2..86b2034c81 100644
@@ -3316,6 +3316,34 @@ print_openat(CPUArchState *cpu_env, const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_pidfd_send_signal
+static void
+print_pidfd_send_signal(CPUArchState *cpu_env, const struct syscallname *name,
+                abi_long arg0, abi_long arg1, abi_long arg2,
+                abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    void *p;
+    target_siginfo_t uinfo;
+
+    print_syscall_prologue(name);
+    print_raw_param("%d", arg0, 0);
+    print_signal(arg1, 0);
+
+    p = lock_user(VERIFY_READ, arg2, sizeof(target_siginfo_t), 1);
+    if (p) {
+        get_target_siginfo(&uinfo, p);
+        print_siginfo(&uinfo);
+
+        unlock_user(p, arg2, 0);
+    } else {
+        print_pointer(arg2, 1);
+    }
+
+    print_raw_param("%u", arg3, 0);
+    print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_mq_unlink
 static void
 print_mq_unlink(CPUArchState *cpu_env, const struct syscallname *name,
linux-user/strace.list +9 -0
index 6e88da7fad..7a69152db7 100644
@@ -1667,6 +1667,15 @@
 #ifdef TARGET_NR_pipe2
 { TARGET_NR_pipe2, "pipe2", NULL, NULL, NULL },
 #endif
+#ifdef TARGET_NR_pidfd_open
+{ TARGET_NR_pidfd_open, "pidfd_open", "%s(%d,%u)", NULL, NULL },
+#endif
+#ifdef TARGET_NR_pidfd_send_signal
+{ TARGET_NR_pidfd_send_signal, "pidfd_send_signal", NULL, print_pidfd_send_signal, NULL },
+#endif
+#ifdef TARGET_NR_pidfd_getfd
+{ TARGET_NR_pidfd_getfd, "pidfd_getfd", "%s(%d,%d,%u)", NULL, NULL },
+#endif
 #ifdef TARGET_NR_atomic_cmpxchg_32
 { TARGET_NR_atomic_cmpxchg_32, "atomic_cmpxchg_32", NULL, NULL, NULL },
 #endif
linux-user/syscall.c +34 -0
index f51c4fbabd..a1e6d4ad53 100644
@@ -346,6 +346,16 @@ _syscall6(int,sys_futex,int *,uaddr,int,op,int,val,
 _syscall6(int,sys_futex_time64,int *,uaddr,int,op,int,val,
           const struct timespec *,timeout,int *,uaddr2,int,val3)
 #endif
+#if defined(__NR_pidfd_open)
+_syscall2(int, pidfd_open, pid_t, pid, unsigned int, flags);
+#endif
+#if defined(__NR_pidfd_send_signal)
+_syscall4(int, pidfd_send_signal, int, pidfd, int, sig, siginfo_t *, info,
+                             unsigned int, flags);
+#endif
+#if defined(__NR_pidfd_getfd)
+_syscall3(int, pidfd_getfd, int, pidfd, int, targetfd, unsigned int, flags);
+#endif
 #define __NR_sys_sched_getaffinity __NR_sched_getaffinity
 _syscall3(int, sys_sched_getaffinity, pid_t, pid, unsigned int, len,
           unsigned long *, user_mask_ptr);
@@ -8686,6 +8696,30 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
         ret = do_open_by_handle_at(arg1, arg2, arg3);
         fd_trans_unregister(ret);
         return ret;
+#endif
+#if defined(TARGET_NR_pidfd_open)
+    case TARGET_NR_pidfd_open:
+        return get_errno(pidfd_open(arg1, arg2));
+#endif
+#if defined(TARGET_NR_pidfd_send_signal)
+    case TARGET_NR_pidfd_send_signal:
+        {
+            siginfo_t uinfo;
+
+            p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1);
+            if (!p) {
+                return -TARGET_EFAULT;
+            }
+            target_to_host_siginfo(&uinfo, p);
+            unlock_user(p, arg3, 0);
+            ret = get_errno(pidfd_send_signal(arg1, target_to_host_signal(arg2),
+                &uinfo, arg4));
+        }
+        return ret;
+#endif
+#if defined(TARGET_NR_pidfd_getfd)
+    case TARGET_NR_pidfd_getfd:
+        return get_errno(pidfd_getfd(arg1, arg2, arg3));
 #endif
     case TARGET_NR_close:
         fd_trans_unregister(arg1);

--
2.37.1

#11 lore raw

PATCH 5/13 linux-user: Log failing executable in EXCP_DUMP()

In reply to Helge Deller

Enhance the EXCP_DUMP() macro to print out the failing program too. During debugging it's sometimes hard to track down the actual failing program if you are e.g. building a whole debian package.

---
 linux-user/cpu_loop-common.h | 2 ++
 1 file changed, 2 insertions(+)
linux-user/cpu_loop-common.h +2 -0
index dc0042e4de..36ff5b14f2 100644
@@ -27,9 +27,11 @@
 do {                                                                    \
     CPUState *cs = env_cpu(env);                                        \
     fprintf(stderr, fmt , ## __VA_ARGS__);                              \
+    fprintf(stderr, "Failing executable: %s\n", exec_path);             \
     cpu_dump_state(cs, stderr, 0);                                      \
     if (qemu_log_separate()) {                                          \
         qemu_log(fmt, ## __VA_ARGS__);                                  \
+        qemu_log("Failing executable: %s\n", exec_path);                \
         log_cpu_state(cs, 0);                                           \
     }                                                                   \
 } while (0)

--
2.37.1

#12 lore raw

PATCH 6/13 linux-user/hppa: Use EXCP_DUMP() to show enhanced debug info

In reply to Helge Deller

Enhance the hppa linux-user cpu_loop() to show more debugging info on hard errors.

---
 linux-user/hppa/cpu_loop.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
linux-user/hppa/cpu_loop.c +5 -1
index 64263c3dc4..1ef3b46191 100644
@@ -147,12 +147,15 @@ void cpu_loop(CPUHPPAState *env)
             force_sig_fault(TARGET_SIGSEGV, TARGET_SEGV_MAPERR, env->iaoq_f);
             break;
         case EXCP_ILL:
+            EXCP_DUMP(env, "qemu: got CPU exception 0x%x - aborting\n", trapnr);
             force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->iaoq_f);
             break;
         case EXCP_PRIV_OPR:
+            EXCP_DUMP(env, "qemu: got CPU exception 0x%x - aborting\n", trapnr);
             force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVOPC, env->iaoq_f);
             break;
         case EXCP_PRIV_REG:
+            EXCP_DUMP(env, "qemu: got CPU exception 0x%x - aborting\n", trapnr);
             force_sig_fault(TARGET_SIGILL, TARGET_ILL_PRVREG, env->iaoq_f);
             break;
         case EXCP_OVERFLOW:
@@ -171,7 +174,8 @@ void cpu_loop(CPUHPPAState *env)
             /* just indicate that signals should be handled asap */
             break;
         default:
-            g_assert_not_reached();
+            EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\n", trapnr);
+            abort();
         }
         process_pending_signals(env);
     }

--
2.37.1

#13 lore raw

PATCH 7/13 linux-user/hppa: Dump IIR on register dump

In reply to Helge Deller

Include the IIR register (which holds the opcode of the failing instruction) when dumping the hppa registers.

---
 target/hppa/helper.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
target/hppa/helper.c +4 -2
index e2758d8df3..74b8747083 100644
@@ -85,9 +85,11 @@ void hppa_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     char psw_c[20];
     int i;
 
-    qemu_fprintf(f, "IA_F " TARGET_FMT_lx " IA_B " TARGET_FMT_lx "\n",
+    qemu_fprintf(f, "IA_F " TARGET_FMT_lx " IA_B " TARGET_FMT_lx
+                 " IIR " TREG_FMT_lx  "\n",
                  hppa_form_gva_psw(psw, env->iasq_f, env->iaoq_f),
-                 hppa_form_gva_psw(psw, env->iasq_b, env->iaoq_b));
+                 hppa_form_gva_psw(psw, env->iasq_b, env->iaoq_b),
+                 env->cr[CR_IIR]);
 
     psw_c[0]  = (psw & PSW_W ? 'W' : '-');
     psw_c[1]  = (psw & PSW_E ? 'E' : '-');

--
2.37.1

#14 lore raw

PATCH 8/13 linux-user: Fix strace of chmod() if mode == 0

In reply to Helge Deller

If the mode parameter of chmod() is zero, this value isn't shown when stracing a program:

    chmod("filename",)
This patch fixes it up to show the zero-value as well:
    chmod("filename",000)
---
 linux-user/strace.c | 5 +++++
 1 file changed, 5 insertions(+)
linux-user/strace.c +5 -0
index 86b2034c81..d1afa0e12a 100644
@@ -1504,6 +1504,11 @@ print_file_mode(abi_long mode, int last)
     const char *sep = "";
     const struct flags *m;
 
+    if (mode == 0) {
+        qemu_log("000%s", get_comma(last));
+        return;
+    }
+
     for (m = &mode_flags[0]; m->f_string != NULL; m++) {
         if ((m->f_value & mode) == m->f_value) {
             qemu_log("%s%s", m->f_string, sep);

--
2.37.1

#15 lore raw

PATCH 9/13 linux-user/hppa: Set TASK_UNMAPPED_BASE to 0xfa000000 for hppa arch

In reply to Helge Deller

On the parisc architecture the stack grows upwards.
Move the TASK_UNMAPPED_BASE to high memory area as it's done by the kernel on physical machines.

---
 linux-user/mmap.c | 4 ++++
 1 file changed, 4 insertions(+)
linux-user/mmap.c +4 -0
index 048c4135af..dba6823668 100644
@@ -251,8 +251,12 @@ static int mmap_frag(abi_ulong real_start,
 # define TASK_UNMAPPED_BASE  (1ul << 38)
 #endif
 #else
+#ifdef TARGET_HPPA
+# define TASK_UNMAPPED_BASE  0xfa000000
+#else
 # define TASK_UNMAPPED_BASE  0x40000000
 #endif
+#endif
 abi_ulong mmap_next_start = TASK_UNMAPPED_BASE;
 
 unsigned long last_brk;

--
2.37.1

#16 lore raw

PATCH 10/13 linux-user: Add strace for clock_nanosleep()

In reply to Helge Deller
---
 linux-user/strace.c    | 15 +++++++++++++++
 linux-user/strace.list |  3 ++-
 2 files changed, 17 insertions(+), 1 deletion(-)
linux-user/strace.c +15 -0
index d1afa0e12a..bac47748bc 100644
@@ -3566,6 +3566,21 @@ print_unshare(CPUArchState *cpu_env, const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_clock_nanosleep
+static void
+print_clock_nanosleep(CPUArchState *cpu_env, 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_enums(clockids, arg0, 0);
+    print_raw_param("%d", arg1, 0);
+    print_timespec(arg2, 0);
+    print_timespec(arg3, 1);
+    print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_utime
 static void
 print_utime(CPUArchState *cpu_env, const struct syscallname *name,
linux-user/strace.list +2 -1
index 7a69152db7..0463415902 100644
@@ -91,7 +91,8 @@
                            print_syscall_ret_clock_gettime },
 #endif
 #ifdef TARGET_NR_clock_nanosleep
-{ TARGET_NR_clock_nanosleep, "clock_nanosleep" , NULL, NULL, NULL },
+{ TARGET_NR_clock_nanosleep, "clock_nanosleep" , NULL, print_clock_nanosleep,
+                            NULL },
 #endif
 #ifdef TARGET_NR_clock_settime
 { TARGET_NR_clock_settime, "clock_settime" , NULL, print_clock_settime, NULL },

--
2.37.1

#17 lore raw

PATCH 11/13 linux-user: Show timespec on strace for futex()

In reply to Helge Deller
---
 linux-user/strace.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
linux-user/strace.c +9 -1
index bac47748bc..a90e719681 100644
@@ -3713,11 +3713,19 @@ print_futex(CPUArchState *cpu_env, const struct syscallname *name,
             abi_long arg0, abi_long arg1, abi_long arg2,
             abi_long arg3, abi_long arg4, abi_long arg5)
 {
+#ifdef FUTEX_CMD_MASK
+    abi_long op = arg1 & FUTEX_CMD_MASK;
+#else
+    abi_long op = arg1;
+#endif
     print_syscall_prologue(name);
     print_pointer(arg0, 0);
     print_futex_op(arg1, 0);
     print_raw_param(",%d", arg2, 0);
-    print_pointer(arg3, 0); /* struct timespec */
+    if (op == FUTEX_WAIT || op == FUTEX_WAIT_BITSET)
+        print_timespec(arg3, 0);
+    else
+        print_pointer(arg3, 0); /* struct timespec */
     print_pointer(arg4, 0);
     print_raw_param("%d", arg4, 1);
     print_syscall_epilogue(name);

--
2.37.1

#18 lore raw

Re: [PATCH 11/13] linux-user: Show timespec on strace for futex()

Quoted 10 lines · Helge Deller
---
  linux-user/strace.c | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
linux-user/strace.c +0 -0
index bac47748bc..a90e719681 100644

linux-user/strace.c print_futex(CPUArchState *cpu_env, const struct syscallname *name, · line 3720

Quoted 8 lines
linux-user/strace.c +5 -0
@@ -3713,11 +3713,19 @@ print_futex(CPUArchState *cpu_env, const struct syscallname *name,
              abi_long arg0, abi_long arg1, abi_long arg2,
              abi_long arg3, abi_long arg4, abi_long arg5)
  {
+#ifdef FUTEX_CMD_MASK
+    abi_long op = arg1 & FUTEX_CMD_MASK;
+#else
+    abi_long op = arg1;
+#endif

FUTEX_CMD_MASK is defined in syscall_def.h, so never undefined.

linux-user/strace.c print_futex(CPUArchState *cpu_env, const struct syscallname *name, · line 3728

Quoted 4 lines
linux-user/strace.c +4 -0
+    if (op == FUTEX_WAIT || op == FUTEX_WAIT_BITSET)
+        print_timespec(arg3, 0);
+    else
+        print_pointer(arg3, 0); /* struct timespec */

The else isn't quite correct -- the ops not listed, which actually use this parameter, treat it as uint32_t val2. Anyway, make this a switch, because I've implemented the other missing futex_ops, and several more treat use timespec.

r~

#19 lore raw

PATCH 12/13 linux-user: Add close_range() syscall

In reply to Helge Deller
---
 linux-user/strace.list |  3 +++
 linux-user/syscall.c   | 12 ++++++++++++
 2 files changed, 15 insertions(+)
linux-user/strace.list +3 -0
index 0463415902..4560a01d88 100644
@@ -103,6 +103,9 @@
 #ifdef TARGET_NR_close
 { TARGET_NR_close, "close" , "%s(%d)", NULL, NULL },
 #endif
+#ifdef TARGET_NR_close_range
+{ TARGET_NR_close_range, "close_range" , "%s(%d,%d,%d)", NULL, NULL },
+#endif
 #ifdef TARGET_NR_connect
 { TARGET_NR_connect, "connect" , "%s(%d,%#x,%d)", NULL, NULL },
 #endif
linux-user/syscall.c +12 -0
index a1e6d4ad53..0becaad74c 100644
@@ -8724,6 +8724,18 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
     case TARGET_NR_close:
         fd_trans_unregister(arg1);
         return get_errno(close(arg1));
+#ifdef TARGET_NR_close_range
+    case TARGET_NR_close_range:
+        {
+            abi_long fd;
+            abi_long maxfd = (arg2 == (abi_long)-1) ? target_fd_max : arg2;
+
+            for (fd = arg1; fd <= maxfd; fd++) {
+                fd_trans_unregister(fd);
+            }
+        }
+        return get_errno(close_range(arg1, arg2, arg3));
+#endif
 
     case TARGET_NR_brk:
         return do_brk(arg1);

--
2.37.1

#20 lore raw

PATCH 13/13 linux-user: Add parameters of getrandom() syscall for strace

In reply to Helge Deller
---
 linux-user/strace.list | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/strace.list +1 -1
index 4560a01d88..da8c1bf34e 100644
@@ -358,7 +358,7 @@
 { TARGET_NR_getpriority, "getpriority", "%s(%#x,%#x)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_getrandom
-{ TARGET_NR_getrandom, "getrandom", NULL, NULL, NULL },
+{ TARGET_NR_getrandom, "getrandom", "%s(%p,%u,%d)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_getresgid
 { TARGET_NR_getresgid, "getresgid" , NULL, NULL, NULL },

--
2.37.1