All of lore.kernel.org
 help / color / mirror / Atom feed
From: Helge Deller <deller@kernel.org>
To: qemu-devel@nongnu.org
Cc: "Matt Turner" <mattst88@gmail.com>,
	"Helge Deller" <deller@gmx.de>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Laurent Vivier" <laurent@vivier.eu>,
	"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>
Subject: [PULL 5/6] linux-user/riscv: add coredump support
Date: Sun, 24 May 2026 15:19:07 +0200	[thread overview]
Message-ID: <20260524131909.162990-6-deller@kernel.org> (raw)
In-Reply-To: <20260524131909.162990-1-deller@kernel.org>

From: Matt Turner <mattst88@gmail.com>

Define HAVE_ELF_CORE_DUMP and target_elf_gregset_t in target_elf.h,
mirroring struct user_regs_struct: pc followed by x1 (ra) through
x31 (t6).  Implement elf_core_copy_regs() in elfload.c to populate
the gregset from CPURISCVState.

Without this, bprm->core_dump is NULL for RISC-V targets.  When a
guest signal goes unhandled, dump_core_and_abort() skips the core
write and falls through to die_with_signal(), which re-raises the
signal to the host.  The host kernel then writes an x86-64 core file
for the qemu-riscv64 process instead of a RISC-V guest core.

Signed-off-by: Matt Turner <mattst88@gmail.com>
Signed-off-by: Helge Deller <deller@gmx.de>
---
 linux-user/riscv/elfload.c    | 9 +++++++++
 linux-user/riscv/target_elf.h | 7 +++++++
 2 files changed, 16 insertions(+)

diff --git a/linux-user/riscv/elfload.c b/linux-user/riscv/elfload.c
index 2e7d622232..afe103a631 100644
--- a/linux-user/riscv/elfload.c
+++ b/linux-user/riscv/elfload.c
@@ -3,6 +3,7 @@
 #include "qemu/osdep.h"
 #include "qemu.h"
 #include "loader.h"
+#include "target_elf.h"
 
 
 const char *get_elf_cpu_model(uint32_t eflags)
@@ -10,6 +11,14 @@ const char *get_elf_cpu_model(uint32_t eflags)
     return "max";
 }
 
+void elf_core_copy_regs(target_elf_gregset_t *r, const CPURISCVState *env)
+{
+    r->pc = tswapal(env->pc);
+    for (int i = 0; i < 31; i++) {
+        r->regs[i] = tswapal(env->gpr[i + 1]);
+    }
+}
+
 abi_ulong get_elf_hwcap(CPUState *cs)
 {
 #define MISA_BIT(EXT) (1 << (EXT - 'A'))
diff --git a/linux-user/riscv/target_elf.h b/linux-user/riscv/target_elf.h
index dbbfdf54d3..859f726578 100644
--- a/linux-user/riscv/target_elf.h
+++ b/linux-user/riscv/target_elf.h
@@ -19,5 +19,12 @@
 #endif
 
 #define HAVE_ELF_HWCAP          1
+#define HAVE_ELF_CORE_DUMP      1
+
+/* Mirrors struct user_regs_struct: pc followed by x1 (ra) .. x31 (t6). */
+typedef struct target_elf_gregset_t {
+    abi_ulong pc;
+    abi_ulong regs[31];
+} target_elf_gregset_t;
 
 #endif
-- 
2.54.0



  parent reply	other threads:[~2026-05-24 13:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-24 13:19 [PULL 0/6] Linux user next patches Helge Deller
2026-05-24 13:19 ` [PULL 1/6] linux-user/hppa: add coredump support Helge Deller
2026-05-24 13:19 ` [PULL 2/6] linux-user/mips64: fix elf_core_copy_regs register layout in core files Helge Deller
2026-05-24 13:19 ` [PULL 3/6] linux-user/mips64: fix mipsn32 elf_core_copy_regs entry width Helge Deller
2026-05-24 13:19 ` [PULL 4/6] linux-user/mips: use tswap32 in elf_core_copy_regs Helge Deller
2026-05-24 13:19 ` Helge Deller [this message]
2026-05-24 13:19 ` [PULL 6/6] linux-user/sh4: add VDSO support for sh4 and sh4eb Helge Deller
2026-05-26 14:59 ` [PULL 0/6] Linux user next patches Stefan Hajnoczi

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=20260524131909.162990-6-deller@kernel.org \
    --to=deller@kernel.org \
    --cc=deller@gmx.de \
    --cc=laurent@vivier.eu \
    --cc=mattst88@gmail.com \
    --cc=philmd@linaro.org \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-devel@nongnu.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.