Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Include XSTATE note in x86 core dumps



details:   https://anonhg.NetBSD.org/src/rev/0d25378773ec
branches:  trunk
changeset: 466989:0d25378773ec
user:      mgorny <mgorny%NetBSD.org@localhost>
date:      Wed Jan 08 17:21:38 2020 +0000

description:
Include XSTATE note in x86 core dumps

Introduce a simple COREDUMP_MACHDEP_LWP_NOTES logic to provide machdep
API for injecting per-LWP notes into coredumps, and use it to append
PT_GETXSTATE note.

Since the XSTATE block uses the same format on i386 and amd64, the code
does not have to conditionalize between 32-bit and 64-bit ELF format
on that.  However, it does need to distinguish between 32-bit and 64-bit
PT_* values.  In order to do that, it reuses PT32_* constant already
present for ptrace(), and adds a matching PT64_GETXSTATE to satisfy
the cpp logic.

diffstat:

 sys/arch/amd64/include/ptrace.h |  18 +++++++++++++++++-
 sys/arch/i386/include/ptrace.h  |  14 +++++++++++++-
 sys/kern/core_elf32.c           |  10 +++++++---
 3 files changed, 37 insertions(+), 5 deletions(-)

diffs (91 lines):

diff -r 631689929c15 -r 0d25378773ec sys/arch/amd64/include/ptrace.h
--- a/sys/arch/amd64/include/ptrace.h   Wed Jan 08 16:21:34 2020 +0000
+++ b/sys/arch/amd64/include/ptrace.h   Wed Jan 08 17:21:38 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptrace.h,v 1.20 2019/12/02 19:17:27 kamil Exp $        */
+/*     $NetBSD: ptrace.h,v 1.21 2020/01/08 17:21:38 mgorny Exp $       */
 
 /*
  * Copyright (c) 1993 Christopher G. Demetriou
@@ -105,6 +105,22 @@
 MODULE_HOOK(netbsd32_process_doxmmregs_hook, int,
     (struct lwp *, struct lwp *, void *, bool));
 
+#ifdef EXEC_ELF32
+#include <machine/netbsd32_machdep.h>
+#endif
+#define PT64_GETXSTATE         PT_GETXSTATE
+#define COREDUMP_MACHDEP_LWP_NOTES(l, ns, name)                                \
+{                                                                      \
+       struct xstate xstate;                                           \
+       memset(&xstate, 0, sizeof(xstate));                             \
+       if (!process_read_xstate(l, &xstate))                           \
+       {                                                               \
+               ELFNAMEEND(coredump_savenote)(ns,                       \
+                   CONCAT(CONCAT(PT, ELFSIZE), _GETXSTATE), name,      \
+                   &xstate, sizeof(xstate));                           \
+       }                                                               \
+}
+
 #endif /* _KERNEL */
 
 #ifdef _KERNEL_OPT
diff -r 631689929c15 -r 0d25378773ec sys/arch/i386/include/ptrace.h
--- a/sys/arch/i386/include/ptrace.h    Wed Jan 08 16:21:34 2020 +0000
+++ b/sys/arch/i386/include/ptrace.h    Wed Jan 08 17:21:38 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptrace.h,v 1.23 2019/06/26 12:30:12 mgorny Exp $       */
+/*     $NetBSD: ptrace.h,v 1.24 2020/01/08 17:21:38 mgorny Exp $       */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -159,6 +159,18 @@
        { DT_REG, N("xmmregs"), Pmachdep_xmmregs,                       \
          procfs_machdep_validxmmregs },
 
+#define COREDUMP_MACHDEP_LWP_NOTES(l, ns, name)                                \
+{                                                                      \
+       struct xstate xstate;                                           \
+       memset(&xstate, 0, sizeof(xstate));                             \
+       if (!process_read_xstate(l, &xstate))                           \
+       {                                                               \
+               ELFNAMEEND(coredump_savenote)(ns,                       \
+                   CONCAT(CONCAT(PT, ELFSIZE), _GETXSTATE), name,      \
+                   &xstate, sizeof(xstate));                           \
+       }                                                               \
+}
+
 struct xmmregs;
 
 /* Functions used by both ptrace(2) and procfs. */
diff -r 631689929c15 -r 0d25378773ec sys/kern/core_elf32.c
--- a/sys/kern/core_elf32.c     Wed Jan 08 16:21:34 2020 +0000
+++ b/sys/kern/core_elf32.c     Wed Jan 08 17:21:38 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: core_elf32.c,v 1.61 2019/12/24 14:50:59 kamil Exp $    */
+/*     $NetBSD: core_elf32.c,v 1.62 2020/01/08 17:21:38 mgorny Exp $   */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.61 2019/12/24 14:50:59 kamil Exp $");
+__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.62 2020/01/08 17:21:38 mgorny Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd32.h"
@@ -513,7 +513,11 @@
 
        ELFNAMEEND(coredump_savenote)(ns, PT_GETFPREGS, name, &freg, freglen);
 #endif
-       /* XXX Add hook for machdep per-LWP notes. */
+
+#ifdef COREDUMP_MACHDEP_LWP_NOTES
+       COREDUMP_MACHDEP_LWP_NOTES(l, ns, name);
+#endif
+
        return (0);
 }
 



Home | Main Index | Thread Index | Old Index