[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 7/8] linux-user: Lock log around strace
From: |
Richard Henderson |
Subject: |
[PATCH 7/8] linux-user: Lock log around strace |
Date: |
Sun, 28 Aug 2022 19:10:05 -0700 |
Do not allow syscall arguments to be interleaved between threads.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/strace.c | 65 ++++++++++++++++++++++++++++++++-------------
1 file changed, 46 insertions(+), 19 deletions(-)
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 8eadbed39e..c47d91bb3d 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -3773,26 +3773,37 @@ print_syscall(CPUArchState *cpu_env, int num,
abi_long arg4, abi_long arg5, abi_long arg6)
{
int i;
- const char *format="%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ","
TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ","
TARGET_ABI_FMT_ld ")";
+ FILE *f;
+ const char *format = "%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ","
+ TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ","
+ TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")";
- qemu_log("%d ", getpid());
+ f = qemu_log_trylock();
+ if (!f) {
+ return;
+ }
+ fprintf(f, "%d ", getpid());
- for(i=0;i<nsyscalls;i++)
- if( scnames[i].nr == num ) {
- if( scnames[i].call != NULL ) {
- scnames[i].call(
- cpu_env, &scnames[i], arg1, arg2, arg3, arg4, arg5, arg6);
+ for (i = 0; i < nsyscalls; i++) {
+ if (scnames[i].nr == num) {
+ if (scnames[i].call != NULL) {
+ scnames[i].call(cpu_env, &scnames[i], arg1, arg2, arg3,
+ arg4, arg5, arg6);
} else {
/* XXX: this format system is broken because it uses
host types and host pointers for strings */
- if( scnames[i].format != NULL )
+ if (scnames[i].format != NULL) {
format = scnames[i].format;
- qemu_log(format,
- scnames[i].name, arg1, arg2, arg3, arg4, arg5, arg6);
+ }
+ fprintf(f, format, scnames[i].name, arg1, arg2,
+ arg3, arg4, arg5, arg6);
}
+ qemu_log_unlock(f);
return;
}
- qemu_log("Unknown syscall %d\n", num);
+ }
+ fprintf(f, "Unknown syscall %d\n", num);
+ qemu_log_unlock(f);
}
@@ -3802,21 +3813,29 @@ print_syscall_ret(CPUArchState *cpu_env, int num,
abi_long ret,
abi_long arg4, abi_long arg5, abi_long arg6)
{
int i;
+ FILE *f;
- for(i=0;i<nsyscalls;i++)
- if( scnames[i].nr == num ) {
- if( scnames[i].result != NULL ) {
+ f = qemu_log_trylock();
+ if (!f) {
+ return;
+ }
+
+ for (i = 0; i < nsyscalls; i++) {
+ if (scnames[i].nr == num) {
+ if (scnames[i].result != NULL) {
scnames[i].result(cpu_env, &scnames[i], ret,
arg1, arg2, arg3,
arg4, arg5, arg6);
} else {
if (!print_syscall_err(ret)) {
- qemu_log(TARGET_ABI_FMT_ld, ret);
+ fprintf(f, TARGET_ABI_FMT_ld, ret);
}
- qemu_log("\n");
+ fprintf(f, "\n");
}
break;
}
+ }
+ qemu_log_unlock(f);
}
void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
@@ -3824,9 +3843,17 @@ void print_taken_signal(int target_signum, const
target_siginfo_t *tinfo)
/* Print the strace output for a signal being taken:
* --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
*/
- qemu_log("--- ");
+ FILE *f;
+
+ f = qemu_log_trylock();
+ if (!f) {
+ return;
+ }
+
+ fprintf(f, "--- ");
print_signal(target_signum, 1);
- qemu_log(" ");
+ fprintf(f, " ");
print_siginfo(tinfo);
- qemu_log(" ---\n");
+ fprintf(f, " ---\n");
+ qemu_log_unlock(f);
}
--
2.34.1
- [PATCH 0/8] linux-user: Futex improvements, Richard Henderson, 2022/08/28
- [PATCH 1/8] linux-user: Combine do_futex and do_futex_time64, Richard Henderson, 2022/08/28
- [PATCH 2/8] linux-user: Sink call to do_safe_futex, Richard Henderson, 2022/08/28
- [PATCH 3/8] linux-user: Implement FUTEX_WAKE_BITSET, Richard Henderson, 2022/08/28
- [PATCH 4/8] linux-user: Convert signal number for FUTEX_FD, Richard Henderson, 2022/08/28
- [PATCH 7/8] linux-user: Lock log around strace,
Richard Henderson <=
- [PATCH 5/8] linux-user: Implement PI futexes, Richard Henderson, 2022/08/28
- [PATCH 6/8] linux-user: Update print_futex_op, Richard Henderson, 2022/08/28
- [PATCH 8/8] linux-user: Log tid for strace, Richard Henderson, 2022/08/28