From cc1b0f7d9626bbd116429014444cbf61edf708a2 Mon Sep 17 00:00:00 2001 From: Dmitry Chagin Date: Thu, 2 Feb 2023 17:58:06 +0300 Subject: [PATCH] linux(4): Add coredump support to i386. MFC after: 1 week --- sys/i386/linux/linux.h | 28 ++++++++++++++++++++++++++++ sys/i386/linux/linux_machdep.c | 26 ++++++++++++++++++++++++++ sys/i386/linux/linux_sysvec.c | 9 ++++++--- sys/modules/linux/Makefile | 2 +- 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/sys/i386/linux/linux.h b/sys/i386/linux/linux.h index c651da6b5857..43bf3ca126b6 100644 --- a/sys/i386/linux/linux.h +++ b/sys/i386/linux/linux.h @@ -395,4 +395,32 @@ struct l_desc_struct { #define linux_copyout_rusage(r, u) copyout(r, u, sizeof(*r)) +/* This corresponds to 'struct user_regs_struct' in Linux. */ +struct linux_pt_regset { + l_uint ebx; + l_uint ecx; + l_uint edx; + l_uint esi; + l_uint edi; + l_uint ebp; + l_uint eax; + l_uint ds; + l_uint es; + l_uint fs; + l_uint gs; + l_uint orig_eax; + l_uint eip; + l_uint cs; + l_uint eflags; + l_uint esp; + l_uint ss; +}; + +#ifdef _KERNEL +struct reg; + +void bsd_to_linux_regset(const struct reg *b_reg, + struct linux_pt_regset *l_regset); +#endif /* _KERNEL */ + #endif /* !_I386_LINUX_H_ */ diff --git a/sys/i386/linux/linux_machdep.c b/sys/i386/linux/linux_machdep.c index dc156dbd673d..fb42c3e9df84 100644 --- a/sys/i386/linux/linux_machdep.c +++ b/sys/i386/linux/linux_machdep.c @@ -60,6 +60,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #include #include @@ -675,3 +677,27 @@ linux_mq_getsetattr(struct thread *td, struct linux_mq_getsetattr_args *args) return (ENOSYS); #endif } + +void +bsd_to_linux_regset(const struct reg *b_reg, + struct linux_pt_regset *l_regset) +{ + + l_regset->ebx = b_reg->r_ebx; + l_regset->ecx = b_reg->r_ecx; + l_regset->edx = b_reg->r_edx; + l_regset->esi = b_reg->r_esi; + l_regset->edi = b_reg->r_edi; + l_regset->ebp = b_reg->r_ebp; + l_regset->eax = b_reg->r_eax; + l_regset->ds = b_reg->r_ds; + l_regset->es = b_reg->r_es; + l_regset->fs = b_reg->r_fs; + l_regset->gs = b_reg->r_gs; + l_regset->orig_eax = b_reg->r_eax; + l_regset->eip = b_reg->r_eip; + l_regset->cs = b_reg->r_cs; + l_regset->eflags = b_reg->r_eflags; + l_regset->esp = b_reg->r_esp; + l_regset->ss = b_reg->r_ss; +} diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c index f67b19725cdf..f478255dff69 100644 --- a/sys/i386/linux/linux_sysvec.c +++ b/sys/i386/linux/linux_sysvec.c @@ -29,6 +29,8 @@ #include __FBSDID("$FreeBSD$"); +#define __ELF_WORD_SIZE 32 + #include #include #include @@ -65,6 +67,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -804,9 +807,9 @@ struct sysentvec elf_linux_sysvec = { .sv_szsigcode = &linux_szsigcode, .sv_name = "Linux ELF32", .sv_coredump = elf32_coredump, - .sv_elf_core_osabi = ELFOSABI_FREEBSD, - .sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR, - .sv_elf_core_prepare_notes = elf32_prepare_notes, + .sv_elf_core_osabi = ELFOSABI_NONE, + .sv_elf_core_abi_vendor = LINUX_ABI_VENDOR, + .sv_elf_core_prepare_notes = __linuxN(prepare_notes), .sv_imgact_try = linux_exec_imgact_try, .sv_minsigstksz = LINUX_MINSIGSTKSZ, .sv_minuser = VM_MIN_ADDRESS, diff --git a/sys/modules/linux/Makefile b/sys/modules/linux/Makefile index ac5b30b19265..db87f66474b5 100644 --- a/sys/modules/linux/Makefile +++ b/sys/modules/linux/Makefile @@ -12,6 +12,7 @@ CFLAGS+=-DCOMPAT_FREEBSD32 -DCOMPAT_LINUX32 KMOD= linux SRCS= linux${SFX}_dummy_machdep.c \ + linux_elf32.c \ linux_event.c \ linux_file.c \ linux_fork.c \ @@ -47,7 +48,6 @@ VDSODEPS=linux_vdso_gettc_x86.inc .endif .if ${MACHINE_CPUARCH} == "amd64" SRCS+= linux${SFX}_support.S -SRCS+= linux_elf32.c .else SRCS+= linux_copyout.c .endif