diff --git a/sys/arch/amd64/conf/MODULAR b/sys/arch/amd64/conf/MODULAR index 848172f92785..129b3acde59e 100644 --- a/sys/arch/amd64/conf/MODULAR +++ b/sys/arch/amd64/conf/MODULAR @@ -1,11 +1,9 @@ -# $NetBSD: MODULAR,v 1.17 2020/09/27 13:48:49 roy Exp $ +# $NetBSD: MODULAR,v 1.18 2020/10/19 19:33:01 christos Exp $ # # Try to exclude all the drivers in GENERIC that have been modularized # XXX: incomplete include "arch/amd64/conf/GENERIC" -options MODULAR # new style module(7) framework -options MODULAR_DEFAULT_AUTOLOAD -no acpicpu* at cpu? -no est0 at cpu0 @@ -85,6 +83,9 @@ options MODULAR_DEFAULT_AUTOLOAD -no options AIO +-no options PTRACE +-no options COREDUMP + -no acpiacad* at acpi? # ACPI AC Adapter -no acpibat* at acpi? # ACPI Battery -no acpibut* at acpi? # ACPI Button diff --git a/sys/arch/amd64/conf/files.amd64 b/sys/arch/amd64/conf/files.amd64 index 82cda467701a..3229087651d0 100644 --- a/sys/arch/amd64/conf/files.amd64 +++ b/sys/arch/amd64/conf/files.amd64 @@ -1,4 +1,4 @@ -# $NetBSD: files.amd64,v 1.117 2020/10/15 17:40:13 mgorny Exp $ +# $NetBSD: files.amd64,v 1.118 2020/10/19 19:33:01 christos Exp $ # # new style config file for amd64 architecture # @@ -47,7 +47,7 @@ file kern/subr_disk_mbr.c disk file arch/amd64/amd64/gdt.c machdep file arch/amd64/amd64/machdep.c machdep file arch/amd64/amd64/prekern.c kaslr -file arch/amd64/amd64/process_machdep.c machdep +file arch/amd64/amd64/process_machdep.c machdep & ptrace file arch/amd64/amd64/trap.c machdep file arch/x86/x86/fpu.c machdep file arch/x86/x86/dbregs.c machdep diff --git a/sys/kern/compat_stub.c b/sys/kern/compat_stub.c index 23d50887c4fa..9dafb6c1d3db 100644 --- a/sys/kern/compat_stub.c +++ b/sys/kern/compat_stub.c @@ -1,4 +1,4 @@ -/* $NetBSD: compat_stub.c,v 1.19 2019/11/20 19:37:53 pgoyette Exp $ */ +/* $NetBSD: compat_stub.c,v 1.20 2020/10/19 19:33:02 christos Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -280,6 +280,8 @@ struct coredump_hook_t coredump_hook; struct coredump_offset_hook_t coredump_offset_hook; struct coredump_write_hook_t coredump_write_hook; struct coredump_netbsd_hook_t coredump_netbsd_hook; +struct coredump_elf32_hook_t coredump_elf32_hook; +struct coredump_elf64_hook_t coredump_elf64_hook; struct uvm_coredump_walkmap_hook_t uvm_coredump_walkmap_hook; struct uvm_coredump_count_segs_hook_t uvm_coredump_count_segs_hook; diff --git a/sys/kern/core_elf32.c b/sys/kern/core_elf32.c index 892dc3e91161..af46b332d7c9 100644 --- a/sys/kern/core_elf32.c +++ b/sys/kern/core_elf32.c @@ -1,4 +1,4 @@ -/* $NetBSD: core_elf32.c,v 1.65 2020/10/10 00:10:06 rin Exp $ */ +/* $NetBSD: core_elf32.c,v 1.66 2020/10/19 19:33:02 christos Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -40,7 +40,7 @@ */ #include -__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.65 2020/10/10 00:10:06 rin Exp $"); +__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.66 2020/10/19 19:33:02 christos Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd32.h" @@ -109,7 +109,7 @@ static int ELFNAMEEND(coredump_note)(struct lwp *, struct note_state *); #define elf_fpreg CONCAT(process_fpreg, ELFSIZE) int -ELFNAMEEND(coredump)(struct lwp *l, struct coredump_iostate *cookie) +ELFNAMEEND(real_coredump)(struct lwp *l, struct coredump_iostate *cookie) { Elf_Ehdr ehdr; Elf_Shdr shdr; diff --git a/sys/kern/files.kern b/sys/kern/files.kern index 553cb77ee3fb..b9bb766d72a5 100644 --- a/sys/kern/files.kern +++ b/sys/kern/files.kern @@ -1,4 +1,4 @@ -# $NetBSD: files.kern,v 1.52 2020/09/07 03:50:41 thorpej Exp $ +# $NetBSD: files.kern,v 1.53 2020/10/19 19:33:02 christos Exp $ # # kernel sources @@ -16,8 +16,8 @@ file kern/bufq_fcfs.c bufq_fcfs file kern/bufq_priocscan.c bufq_priocscan file kern/bufq_readprio.c bufq_readprio | new_bufq_strategy file kern/compat_stub.c kern -file kern/core_elf32.c exec_elf32 -file kern/core_elf64.c exec_elf64 +file kern/core_elf32.c exec_elf32 & coredump +file kern/core_elf64.c exec_elf64 & coredump file kern/core_netbsd.c coredump file kern/cnmagic.c kern file kern/exec_aout.c exec_aout diff --git a/sys/kern/kern_core.c b/sys/kern/kern_core.c index 24a7f643e0f6..5264f38c9789 100644 --- a/sys/kern/kern_core.c +++ b/sys/kern/kern_core.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_core.c,v 1.30 2020/05/23 23:42:43 ad Exp $ */ +/* $NetBSD: kern_core.c,v 1.31 2020/10/19 19:33:02 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1991, 1993 @@ -37,7 +37,11 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_core.c,v 1.30 2020/05/23 23:42:43 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_core.c,v 1.31 2020/10/19 19:33:02 christos Exp $"); + +#ifdef _KERNEL_OPT +#include "opt_compat_netbsd32.h" +#endif #include #include @@ -51,8 +55,15 @@ __KERNEL_RCSID(0, "$NetBSD: kern_core.c,v 1.30 2020/05/23 23:42:43 ad Exp $"); #include #include #include +#include -MODULE(MODULE_CLASS_MISC, coredump, NULL); +#ifdef COMPAT_NETBSD32 +#define COREDUMP_MODULE_DEP "compat_netbsd32_ptrace" +#else +#define COREDUMP_MODULE_DEP NULL +#endif + +MODULE(MODULE_CLASS_MISC, coredump, COREDUMP_MODULE_DEP); struct coredump_iostate { struct lwp *io_lwp; @@ -77,6 +88,10 @@ coredump_modcmd(modcmd_t cmd, void *arg) MODULE_HOOK_SET(coredump_write_hook, coredump_write); MODULE_HOOK_SET(coredump_offset_hook, coredump_offset); MODULE_HOOK_SET(coredump_netbsd_hook, real_coredump_netbsd); + MODULE_HOOK_SET(coredump_elf32_hook, real_coredump_elf32); +#ifdef _LP64 + MODULE_HOOK_SET(coredump_elf64_hook, real_coredump_elf64); +#endif MODULE_HOOK_SET(uvm_coredump_walkmap_hook, uvm_coredump_walkmap); MODULE_HOOK_SET(uvm_coredump_count_segs_hook, @@ -85,6 +100,10 @@ coredump_modcmd(modcmd_t cmd, void *arg) case MODULE_CMD_FINI: MODULE_HOOK_UNSET(uvm_coredump_count_segs_hook); MODULE_HOOK_UNSET(uvm_coredump_walkmap_hook); +#ifdef _LP64 + MODULE_HOOK_UNSET(coredump_elf64_hook); +#endif + MODULE_HOOK_UNSET(coredump_elf32_hook); MODULE_HOOK_UNSET(coredump_netbsd_hook); MODULE_HOOK_UNSET(coredump_offset_hook); MODULE_HOOK_UNSET(coredump_write_hook); diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 1e4c4449bb49..232a0b931611 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_sig.c,v 1.390 2020/05/23 23:42:43 ad Exp $ */ +/* $NetBSD: kern_sig.c,v 1.391 2020/10/19 19:33:02 christos Exp $ */ /*- * Copyright (c) 2006, 2007, 2008, 2019 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.390 2020/05/23 23:42:43 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.391 2020/10/19 19:33:02 christos Exp $"); #include "opt_ptrace.h" #include "opt_dtrace.h" @@ -100,6 +100,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.390 2020/05/23 23:42:43 ad Exp $"); #include #include #include +#include #include #ifdef PAX_SEGVGUARD @@ -2343,12 +2344,9 @@ sigexit(struct lwp *l, int signo) } /* - * Many emulations have a common coredump_netbsd() established as their - * dump routine. Since the "real" code may (or may not) be present in - * loadable module, we provide a routine here which calls the module - * hook. + * Since the "real" code may (or may not) be present in loadable module, + * we provide routines here which calls the module hooks. */ - int coredump_netbsd(struct lwp *l, struct coredump_iostate *iocookie) { @@ -2358,6 +2356,26 @@ coredump_netbsd(struct lwp *l, struct coredump_iostate *iocookie) return retval; } +int +coredump_elf32(struct lwp *l, struct coredump_iostate *iocookie) +{ + int retval; + + MODULE_HOOK_CALL(coredump_elf32_hook, (l, iocookie), ENOSYS, retval); + return retval; +} + +#ifdef _LP64 +int +coredump_elf64(struct lwp *l, struct coredump_iostate *iocookie) +{ + int retval; + + MODULE_HOOK_CALL(coredump_elf64_hook, (l, iocookie), ENOSYS, retval); + return retval; +} +#endif + /* * Put process 'p' into the stopped state and optionally, notify the parent. */ diff --git a/sys/modules/coredump/Makefile b/sys/modules/coredump/Makefile index c2deed72c0d7..b515b4cc0a72 100644 --- a/sys/modules/coredump/Makefile +++ b/sys/modules/coredump/Makefile @@ -1,26 +1,25 @@ -# $NetBSD: Makefile,v 1.6 2019/11/20 19:37:54 pgoyette Exp $ +# $NetBSD: Makefile,v 1.7 2020/10/19 19:33:02 christos Exp $ .include "../Makefile.inc" KMOD= coredump .PATH: ${S}/kern -SRCS= kern_core.c core_netbsd.c +SRCS= kern_core.c core_netbsd.c +SRCS+= ${OBJECT_FMTS:S/^/core_/:S/$/.c/} .PATH: ${S}/uvm SRCS+= uvm_coredump.c -.PATH: ${S}/arch/${MACHINE}/${MACHINE} -.PATH: ${S}/arch/${MACHINE_ARCH}/${MACHINE_ARCH} -.PATH: ${S}/arch/${MACHINE_CPU}/${MACHINE_CPU} -.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64" -.PATH: ${S}/arch/x86/x86 -.endif -.if ${MACHINE_ARCH} == "powerpc64" -.PATH: ${S}/arch/powerpc/powerpc -.endif +.include "../ptrace_common/machdep.mk" SRCS+= core_machdep.c +.include "${.CURDIR}/../../compat/netbsd32/netbsd32.mk" +.if ${COMPAT_USE_NETBSD32} != "no" +CPPFLAGS.core_elf32.c+= -DCOMPAT_NETBSD32 +CPPFLAGS.kern_core.c+= -DCOMPAT_NETBSD32 +.endif + WARNS= 3 COPTS.kern_core.c+= ${GCC_NO_CAST_FUNCTION_TYPE} diff --git a/sys/modules/exec_elf32/Makefile b/sys/modules/exec_elf32/Makefile index e8307249141a..222799b4bdd7 100644 --- a/sys/modules/exec_elf32/Makefile +++ b/sys/modules/exec_elf32/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.5 2019/11/20 19:37:54 pgoyette Exp $ +# $NetBSD: Makefile,v 1.6 2020/10/19 19:33:02 christos Exp $ .include "../Makefile.inc" @@ -19,7 +19,7 @@ CPPFLAGS+= -DPAX_ASLR .endif .PATH: ${S}/kern -SRCS= exec_elf32.c core_elf32.c +SRCS= exec_elf32.c WARNS= 3 diff --git a/sys/modules/exec_elf64/Makefile b/sys/modules/exec_elf64/Makefile index 50a6a90d13cf..5e7e121622a1 100644 --- a/sys/modules/exec_elf64/Makefile +++ b/sys/modules/exec_elf64/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.4 2019/11/20 19:37:54 pgoyette Exp $ +# $NetBSD: Makefile,v 1.5 2020/10/19 19:33:02 christos Exp $ .include "../Makefile.inc" @@ -11,7 +11,7 @@ CPPFLAGS+= -DPAX_ASLR .endif .PATH: ${S}/kern -SRCS= exec_elf64.c core_elf64.c +SRCS= exec_elf64.c WARNS= 3 diff --git a/sys/modules/ptrace_common/Makefile b/sys/modules/ptrace_common/Makefile index 611eeb1cfce9..72285c33dd04 100644 --- a/sys/modules/ptrace_common/Makefile +++ b/sys/modules/ptrace_common/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.3 2019/10/13 07:28:13 mrg Exp $ +# $NetBSD: Makefile,v 1.4 2020/10/19 19:33:02 christos Exp $ # .include "../Makefile.inc" @@ -6,8 +6,10 @@ CPPFLAGS+= -DPTRACE +.include "machdep.mk" + KMOD= ptrace_common -SRCS= sys_ptrace_common.c +SRCS= sys_ptrace_common.c process_machdep.c WARNS= 3 diff --git a/sys/modules/ptrace_common/machdep.mk b/sys/modules/ptrace_common/machdep.mk new file mode 100644 index 000000000000..54253d630ea5 --- /dev/null +++ b/sys/modules/ptrace_common/machdep.mk @@ -0,0 +1,13 @@ +# $NetBSD: machdep.mk,v 1.1 2020/10/19 19:33:02 christos Exp $ + +# Paths to find machine dependent sources + +.PATH: ${S}/arch/${MACHINE}/${MACHINE} +.PATH: ${S}/arch/${MACHINE_ARCH}/${MACHINE_ARCH} +.PATH: ${S}/arch/${MACHINE_CPU}/${MACHINE_CPU} +.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64" +.PATH: ${S}/arch/x86/x86 +.endif +.if ${MACHINE_ARCH} == "powerpc64" +.PATH: ${S}/arch/powerpc/powerpc +.endif diff --git a/sys/sys/compat_stub.h b/sys/sys/compat_stub.h index dd6926b9f489..f2274f8c6ad9 100644 --- a/sys/sys/compat_stub.h +++ b/sys/sys/compat_stub.h @@ -1,4 +1,4 @@ -/* $NetBSD: compat_stub.h,v 1.23 2020/03/08 00:53:13 pgoyette Exp $ */ +/* $NetBSD: compat_stub.h,v 1.24 2020/10/19 19:33:02 christos Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -377,6 +377,10 @@ MODULE_HOOK(coredump_write_hook, int, (struct coredump_iostate *, enum uio_seg, const void *, size_t)); MODULE_HOOK(coredump_netbsd_hook, int, (struct lwp *, struct coredump_iostate *)); +MODULE_HOOK(coredump_elf32_hook, int, + (struct lwp *, struct coredump_iostate *)); +MODULE_HOOK(coredump_elf64_hook, int, + (struct lwp *, struct coredump_iostate *)); MODULE_HOOK(uvm_coredump_walkmap_hook, int, (struct proc *, int (*)(struct uvm_coredump_state *), void *)); MODULE_HOOK(uvm_coredump_count_segs_hook, int, (struct proc *)); diff --git a/sys/sys/exec_elf.h b/sys/sys/exec_elf.h index d57f3ad02834..1b62ac97aedb 100644 --- a/sys/sys/exec_elf.h +++ b/sys/sys/exec_elf.h @@ -1,4 +1,4 @@ -/* $NetBSD: exec_elf.h,v 1.167 2020/10/10 21:25:51 thorpej Exp $ */ +/* $NetBSD: exec_elf.h,v 1.168 2020/10/19 19:33:02 christos Exp $ */ /*- * Copyright (c) 1994 The NetBSD Foundation, Inc. @@ -1439,12 +1439,14 @@ int elf32_populate_auxv(struct lwp *, struct exec_package *, char **); int elf32_copyargs(struct lwp *, struct exec_package *, struct ps_strings *, char **, void *); +int elf32_check_header(Elf32_Ehdr *); +#endif + +int real_coredump_elf32(struct lwp *, struct coredump_iostate *); int coredump_elf32(struct lwp *, struct coredump_iostate *); void coredump_savenote_elf32(struct note_state *, unsigned int, const char *, void *, size_t); -int elf32_check_header(Elf32_Ehdr *); -#endif #ifdef EXEC_ELF64 int exec_elf64_makecmds(struct lwp *, struct exec_package *); @@ -1452,12 +1454,14 @@ int elf64_populate_auxv(struct lwp *, struct exec_package *, char **); int elf64_copyargs(struct lwp *, struct exec_package *, struct ps_strings *, char **, void *); +int elf64_check_header(Elf64_Ehdr *); +#endif + +int real_coredump_elf64(struct lwp *, struct coredump_iostate *); int coredump_elf64(struct lwp *, struct coredump_iostate *); void coredump_savenote_elf64(struct note_state *, unsigned int, const char *, void *, size_t); -int elf64_check_header(Elf64_Ehdr *); -#endif #endif /* _KERNEL */