From: Matt Turner <[email protected]>

Define HAVE_ELF_CORE_DUMP and target_elf_gregset_t in target_elf.h,
mirroring the kernel's elf_gregset_t (ELF_NGREG = 66): r0-r31
[0..31], f0-f31 [32..63], pc [64], unique [65].  Implement
elf_core_copy_regs() in elfload.c to populate the gregset from
CPUAlphaState.

Without this, bprm->core_dump is NULL for Alpha 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-alpha process instead of an Alpha guest core.

v2: Store thread unique field, same as in Linux kernel. Added by Helge &
suggested by Richard.

Signed-off-by: Matt Turner <[email protected]>
Signed-off-by: Helge Deller <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
(cherry picked from commit 9db18ed0631d09f349057c22f7872b2c45275d0c)
(Mjt: for 10.0.x, move everything to linux-user/elfload.c:
  v10.1.0-36-g58afe4cfe93 "linux-user: Create target/elfload.c files",
 use USE_ELF_CORE_DUMP define instead of HAVE_ELF_CORE_DUMP:
  v10.1.0-115-gbb130c17588 "linux-user: Rename USE_ELF_CORE_DUMP to 
HAVE_ELF_CORE_DUMP")
Signed-off-by: Michael Tokarev <[email protected]>

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index fdc84de4bad..35b7ea23880 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1728,6 +1728,29 @@ static inline void init_thread(struct target_pt_regs 
*regs,
     regs->usp = infop->start_stack;
 }
 
+/*
+ * Matches the kernel's elf_gregset_t (ELF_NGREG = 33):
+ *   r0-r30 at indices 0-30, pc at 31, ps at 32.
+ * r31 (hardwired zero) is not stored; pc occupies index 31.
+ */
+typedef struct target_elf_gregset_t {
+    abi_ulong regs[31];  /* integer registers r0-r30  [0..30] */
+    abi_ulong pc;        /* program counter           [31]    */
+    abi_ulong unique;    /* thread's UNIQUE field     [32]    */
+} target_elf_gregset_t;
+
+static void elf_core_copy_regs(target_elf_gregset_t *r, const CPUAlphaState 
*env)
+{
+    int i;
+
+    for (i = 0; i < 31; i++) {
+        r->regs[i] = tswap64(env->ir[i]);
+    }
+    r->pc = tswap64(env->pc);
+    r->unique = tswap64(env->unique);
+}
+
+#define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        8192
 
 #endif /* TARGET_ALPHA */
-- 
2.47.3


Reply via email to