tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[PATCH v5 1/4] 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.
---
sys/arch/amd64/include/ptrace.h | 16 ++++++++++++++++
sys/arch/i386/include/ptrace.h | 12 ++++++++++++
sys/kern/core_elf32.c | 6 +++++-
3 files changed, 33 insertions(+), 1 deletion(-)
Changes in v5:
- used roundup() in patch 2
diff --git a/sys/arch/amd64/include/ptrace.h b/sys/arch/amd64/include/ptrace.h
index f9a98a63c2b1..987a13923b85 100644
--- a/sys/arch/amd64/include/ptrace.h
+++ b/sys/arch/amd64/include/ptrace.h
@@ -105,6 +105,22 @@ int process_machdep_validfpu(struct proc *);
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 --git a/sys/arch/i386/include/ptrace.h b/sys/arch/i386/include/ptrace.h
index 41ad7a119f0b..561be6440ac0 100644
--- a/sys/arch/i386/include/ptrace.h
+++ b/sys/arch/i386/include/ptrace.h
@@ -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 --git a/sys/kern/core_elf32.c b/sys/kern/core_elf32.c
index 7db43d0cc10b..95e5658053c8 100644
--- a/sys/kern/core_elf32.c
+++ b/sys/kern/core_elf32.c
@@ -506,7 +506,11 @@ ELFNAMEEND(coredump_note)(struct lwp *l, struct note_state *ns)
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);
}
--
2.24.1
Home |
Main Index |
Thread Index |
Old Index