Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Feb 2023 07:56:43 GMT
From:      Dmitry Chagin <dchagin@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: b8c62b5a07e3 - stable/13 - linux(4): Add coredump support to i386.
Message-ID:  <202302090756.3197uh6M092895@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by dchagin:

URL: https://cgit.FreeBSD.org/src/commit/?id=b8c62b5a07e333dd08b78361ba763994ec47a5fc

commit b8c62b5a07e333dd08b78361ba763994ec47a5fc
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2023-02-02 14:58:06 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2023-02-09 07:55:18 +0000

    linux(4): Add coredump support to i386.
    
    MFC after:              1 week
    
    (cherry picked from commit cc1b0f7d9626bbd116429014444cbf61edf708a2)
---
 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 <vm/vm.h>
 #include <vm/vm_map.h>
 
+#include <x86/reg.h>
+
 #include <i386/linux/linux.h>
 #include <i386/linux/linux_proto.h>
 #include <compat/linux/linux_emul.h>
@@ -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 6726dc2cf0fd..cff9b1c780d5 100644
--- a/sys/i386/linux/linux_sysvec.c
+++ b/sys/i386/linux/linux_sysvec.c
@@ -29,6 +29,8 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#define __ELF_WORD_SIZE	32
+
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/exec.h>
@@ -65,6 +67,7 @@ __FBSDID("$FreeBSD$");
 #include <x86/linux/linux_x86.h>
 #include <i386/linux/linux.h>
 #include <i386/linux/linux_proto.h>
+#include <compat/linux/linux_elf.h>
 #include <compat/linux/linux_emul.h>
 #include <compat/linux/linux_fork.h>
 #include <compat/linux/linux_ioctl.h>
@@ -803,9 +806,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 2cd7c54cd216..4e41f8e9403c 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 \
@@ -46,7 +47,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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202302090756.3197uh6M092895>