From: deller@kernel.org
To: qemu-devel@nongnu.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
"Warner Losh" <imp@bsdimp.com>,
"Laurent Vivier" <laurent@vivier.eu>,
"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
"Helge Deller" <deller@gmx.de>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Kyle Evans" <kevans@freebsd.org>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [PATCH 03/12] linux-user/strace: fix printing of file offsets
Date: Sat, 7 Mar 2026 20:52:34 +0100 [thread overview]
Message-ID: <20260307195243.8813-4-deller@kernel.org> (raw)
In-Reply-To: <20260307195243.8813-1-deller@kernel.org>
From: Jean-Christian CÎRSTEA <jean.christian.cirstea@gmail.com>
Previously, 64-bit file offsets (loff_t) were printed using `print_raw_param()`
function, which led to silent truncation of the upper part. This commit fixes
this issue by adding two helper functions:
1. print_file_offset32(): prints 32-bit file offsets (off_t)
2. print_file_offset64(): prints 64-bit file offsets (loff_t)
Changelog v2:
1. Make `print_file_offset32()` static.
2. Use `last` parameter in `print_file_offset32()`.
3. Rename `low` and `high` parameters of `print_file_offset64()` to `word0`,
`word1` respectively
4. Convert `last` to bool for `print_file_offset[32,64]()`
5. Use `PRId64` instead of `PRIu64` for `print_file_offset64()`
6. Fix `print__llseek()`
Signed-off-by: Jean-Christian CÎRSTEA <jean.christian.cirstea@gmail.com>
Reviewed-by: Helge Deller <deller@gmx.de>
Signed-off-by: Helge Deller <deller@gmx.de>
---
linux-user/strace.c | 43 +++++++++++++++++++++++++++++++------------
1 file changed, 31 insertions(+), 12 deletions(-)
diff --git a/linux-user/strace.c b/linux-user/strace.c
index ca67cfd09d..d253b522bf 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -85,6 +85,10 @@ UNUSED static void print_enums(const struct enums *, abi_long, int);
UNUSED static void print_at_dirfd(abi_long, int);
UNUSED static void print_file_mode(abi_long, int);
UNUSED static void print_open_flags(abi_long, int);
+UNUSED static void print_file_offset32(abi_long offset, bool last);
+UNUSED static void print_file_offset64(abi_long word0,
+ abi_long word1,
+ bool last);
UNUSED static void print_syscall_prologue(const struct syscallname *);
UNUSED static void print_syscall_epilogue(const struct syscallname *);
UNUSED static void print_string(abi_long, int);
@@ -1664,6 +1668,20 @@ print_open_flags(abi_long flags, int last)
print_flags(open_flags, flags, last);
}
+/* Prints 32-bit file offset (off_t) */
+static void
+print_file_offset32(abi_long offset, bool last)
+{
+ print_raw_param(TARGET_ABI_FMT_ld, offset, last);
+}
+
+/* Prints 64-bit file offset (loff_t) */
+static void
+print_file_offset64(abi_long word0, abi_long word1, bool last)
+{
+ print_raw_param64("%" PRId64, target_offset64(word0, word1), last);
+}
+
static void
print_syscall_prologue(const struct syscallname *sc)
{
@@ -2256,11 +2274,13 @@ print_fallocate(CPUArchState *cpu_env, const struct syscallname *name,
print_raw_param("%d", arg0, 0);
print_flags(falloc_flags, arg1, 0);
#if TARGET_ABI_BITS == 32
- print_raw_param("%" PRIu64, target_offset64(arg2, arg3), 0);
- print_raw_param("%" PRIu64, target_offset64(arg4, arg5), 1);
+ /* On 32-bit targets, two registers are used for `loff_t` */
+ print_file_offset64(arg2, arg3, false);
+ print_file_offset64(arg4, arg5, true);
#else
- print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
- print_raw_param(TARGET_ABI_FMT_ld, arg3, 1);
+ /* On 64-bit targets, one register is used for `loff_t` */
+ print_file_offset64(arg2, 0, false);
+ print_file_offset64(arg3, 0, true);
#endif
print_syscall_epilogue(name);
}
@@ -2666,8 +2686,7 @@ print__llseek(CPUArchState *cpu_env, const struct syscallname *name,
const char *whence = "UNKNOWN";
print_syscall_prologue(name);
print_raw_param("%d", arg0, 0);
- print_raw_param("%ld", arg1, 0);
- print_raw_param("%ld", arg2, 0);
+ print_file_offset64(arg1, arg2, false);
print_pointer(arg3, 0);
switch(arg4) {
case SEEK_SET: whence = "SEEK_SET"; break;
@@ -2688,7 +2707,7 @@ print_lseek(CPUArchState *cpu_env, const struct syscallname *name,
{
print_syscall_prologue(name);
print_raw_param("%d", arg0, 0);
- print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
+ print_file_offset32(arg1, false);
switch (arg2) {
case SEEK_SET:
qemu_log("SEEK_SET"); break;
@@ -2719,7 +2738,7 @@ print_truncate(CPUArchState *cpu_env, const struct syscallname *name,
{
print_syscall_prologue(name);
print_string(arg0, 0);
- print_raw_param(TARGET_ABI_FMT_ld, arg1, 1);
+ print_file_offset32(arg1, true);
print_syscall_epilogue(name);
}
#endif
@@ -2736,7 +2755,7 @@ print_truncate64(CPUArchState *cpu_env, const struct syscallname *name,
arg1 = arg2;
arg2 = arg3;
}
- print_raw_param("%" PRIu64, target_offset64(arg1, arg2), 1);
+ print_file_offset64(arg1, arg2, true);
print_syscall_epilogue(name);
}
#endif
@@ -2753,7 +2772,7 @@ print_ftruncate64(CPUArchState *cpu_env, const struct syscallname *name,
arg1 = arg2;
arg2 = arg3;
}
- print_raw_param("%" PRIu64, target_offset64(arg1, arg2), 1);
+ print_file_offset64(arg1, arg2, true);
print_syscall_epilogue(name);
}
#endif
@@ -3308,7 +3327,7 @@ print_stat(CPUArchState *cpu_env, const struct syscallname *name,
print_syscall_epilogue(name);
}
#define print_lstat print_stat
-#define print_stat64 print_stat
+#define print_stat64 print_stat
#define print_lstat64 print_stat
#endif
@@ -4302,7 +4321,7 @@ print_pread64(CPUArchState *cpu_env, const struct syscallname *name,
print_raw_param("%d", arg0, 0);
print_pointer(arg1, 0);
print_raw_param("%d", arg2, 0);
- print_raw_param("%" PRIu64, target_offset64(arg3, arg4), 1);
+ print_file_offset64(arg3, arg4, true);
print_syscall_epilogue(name);
}
#endif
--
2.53.0
next prev parent reply other threads:[~2026-03-07 19:53 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-07 19:52 [PATCH 00/12] linux-user and hppa patches deller
2026-03-07 19:52 ` [PATCH 01/12] hw/hppa: Avoid leaking a diva-gsp device deller
2026-03-07 19:52 ` [PATCH 02/12] hw/char: Drop disable property of Diva GSP card deller
2026-03-07 19:52 ` deller [this message]
2026-03-07 19:52 ` [PATCH 04/12] linux-user: properly check flags in openat2 deller
2026-03-07 19:52 ` [PATCH 05/12] linux-user: Check if RESOLVE_CACHED flag is defined before using it deller
2026-03-07 19:52 ` [PATCH 06/12] linux-user: fix matching ioctl numbers in print_ioctl deller
2026-03-07 19:52 ` [PATCH 07/12] linux-user: fix TIOCGSID ioctl deller
2026-03-07 19:52 ` [PATCH 08/12] linux-user: Deal with mmap where start > reserved_va deller
2026-03-07 19:52 ` [PATCH 09/12] bsd-user: " deller
2026-03-07 19:52 ` [PATCH 10/12] tests/tcg/multiarch/test-mmap: Print more details deller
2026-03-07 20:53 ` Pierrick Bouvier
2026-03-07 19:52 ` [PATCH 11/12] tests/tcg/multiarch/test-mmap: Check mmaps beyond reserved_va deller
2026-03-07 20:54 ` Pierrick Bouvier
2026-03-07 19:52 ` [PATCH 12/12] linux-user: Improve formatting for mremap() deller
2026-03-07 20:54 ` Pierrick Bouvier
2026-03-08 21:50 ` [PATCH 00/12] linux-user and hppa patches Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260307195243.8813-4-deller@kernel.org \
--to=deller@kernel.org \
--cc=alex.bennee@linaro.org \
--cc=deller@gmx.de \
--cc=imp@bsdimp.com \
--cc=kevans@freebsd.org \
--cc=laurent@vivier.eu \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.