Skip to content
Permalink
Browse files

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.
  • Loading branch information
mgorny committed Jan 8, 2020
1 parent d719475 commit 6f2ba9aaf76666968f900ef32bcc3924d9a2f05a
Showing with 37 additions and 5 deletions.
  1. +17 −1 sys/arch/amd64/include/ptrace.h
  2. +13 −1 sys/arch/i386/include/ptrace.h
  3. +7 −3 sys/kern/core_elf32.c
@@ -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 @@ 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
@@ -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. */
@@ -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_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);
}

0 comments on commit 6f2ba9a

Please sign in to comment.
You can’t perform that action at this time.