Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Jun 2022 19:40:57 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: 06f6414a648a - stable/13 - linux(4): Deduplicate bsd_to_linux_trapcode()
Message-ID:  <202206171940.25HJevVd028927@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=06f6414a648add4a0fbd90f3001be193d80fe4f5

commit 06f6414a648add4a0fbd90f3001be193d80fe4f5
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2022-05-23 10:16:58 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2022-06-17 19:35:28 +0000

    linux(4): Deduplicate bsd_to_linux_trapcode()
    
    As bsd_to_linux_trapcode() is common for x86 Linuxulators,
    move it under x86/linux.
    
    MFC after:              2 weeks
    
    (cherry picked from commit 9016ec056ae3896522798ead39bb2f3ff4f68809)
---
 sys/amd64/linux/linux_sysvec.c     | 39 ----------------------------------
 sys/amd64/linux32/linux32_sysvec.c | 39 ----------------------------------
 sys/i386/linux/linux_sysvec.c      | 39 ----------------------------------
 sys/x86/linux/linux_x86.c          | 43 ++++++++++++++++++++++++++++++++++++++
 sys/x86/linux/linux_x86.h          |  1 +
 5 files changed, 44 insertions(+), 117 deletions(-)

diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c
index 96df6b25cf12..329a0a2567c0 100644
--- a/sys/amd64/linux/linux_sysvec.c
+++ b/sys/amd64/linux/linux_sysvec.c
@@ -131,45 +131,6 @@ static int	linux_on_exec_vmspace(struct proc *p,
 static void	linux_set_fork_retval(struct thread *td);
 static int	linux_vsyscall(struct thread *td);
 
-#define LINUX_T_UNKNOWN  255
-static int _bsd_to_linux_trapcode[] = {
-	LINUX_T_UNKNOWN,	/* 0 */
-	6,			/* 1  T_PRIVINFLT */
-	LINUX_T_UNKNOWN,	/* 2 */
-	3,			/* 3  T_BPTFLT */
-	LINUX_T_UNKNOWN,	/* 4 */
-	LINUX_T_UNKNOWN,	/* 5 */
-	16,			/* 6  T_ARITHTRAP */
-	254,			/* 7  T_ASTFLT */
-	LINUX_T_UNKNOWN,	/* 8 */
-	13,			/* 9  T_PROTFLT */
-	1,			/* 10 T_TRCTRAP */
-	LINUX_T_UNKNOWN,	/* 11 */
-	14,			/* 12 T_PAGEFLT */
-	LINUX_T_UNKNOWN,	/* 13 */
-	17,			/* 14 T_ALIGNFLT */
-	LINUX_T_UNKNOWN,	/* 15 */
-	LINUX_T_UNKNOWN,	/* 16 */
-	LINUX_T_UNKNOWN,	/* 17 */
-	0,			/* 18 T_DIVIDE */
-	2,			/* 19 T_NMI */
-	4,			/* 20 T_OFLOW */
-	5,			/* 21 T_BOUND */
-	7,			/* 22 T_DNA */
-	8,			/* 23 T_DOUBLEFLT */
-	9,			/* 24 T_FPOPFLT */
-	10,			/* 25 T_TSSFLT */
-	11,			/* 26 T_SEGNPFLT */
-	12,			/* 27 T_STKFLT */
-	18,			/* 28 T_MCHK */
-	19,			/* 29 T_XMMFLT */
-	15			/* 30 T_RESERVED */
-};
-#define bsd_to_linux_trapcode(code) \
-    ((code)<nitems(_bsd_to_linux_trapcode)? \
-     _bsd_to_linux_trapcode[(code)]: \
-     LINUX_T_UNKNOWN)
-
 LINUX_VDSO_SYM_INTPTR(linux_rt_sigcode);
 LINUX_VDSO_SYM_CHAR(linux_platform);
 LINUX_VDSO_SYM_INTPTR(kern_timekeep_base);
diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c
index a01c7271c122..2b0d2d267fbe 100644
--- a/sys/amd64/linux32/linux32_sysvec.c
+++ b/sys/amd64/linux32/linux32_sysvec.c
@@ -134,45 +134,6 @@ static void	linux_vdso_reloc(char *mapping, Elf_Addr offset);
 static void	linux32_set_fork_retval(struct thread *td);
 static void	linux32_set_syscall_retval(struct thread *td, int error);
 
-#define LINUX_T_UNKNOWN  255
-static int _bsd_to_linux_trapcode[] = {
-	LINUX_T_UNKNOWN,	/* 0 */
-	6,			/* 1  T_PRIVINFLT */
-	LINUX_T_UNKNOWN,	/* 2 */
-	3,			/* 3  T_BPTFLT */
-	LINUX_T_UNKNOWN,	/* 4 */
-	LINUX_T_UNKNOWN,	/* 5 */
-	16,			/* 6  T_ARITHTRAP */
-	254,			/* 7  T_ASTFLT */
-	LINUX_T_UNKNOWN,	/* 8 */
-	13,			/* 9  T_PROTFLT */
-	1,			/* 10 T_TRCTRAP */
-	LINUX_T_UNKNOWN,	/* 11 */
-	14,			/* 12 T_PAGEFLT */
-	LINUX_T_UNKNOWN,	/* 13 */
-	17,			/* 14 T_ALIGNFLT */
-	LINUX_T_UNKNOWN,	/* 15 */
-	LINUX_T_UNKNOWN,	/* 16 */
-	LINUX_T_UNKNOWN,	/* 17 */
-	0,			/* 18 T_DIVIDE */
-	2,			/* 19 T_NMI */
-	4,			/* 20 T_OFLOW */
-	5,			/* 21 T_BOUND */
-	7,			/* 22 T_DNA */
-	8,			/* 23 T_DOUBLEFLT */
-	9,			/* 24 T_FPOPFLT */
-	10,			/* 25 T_TSSFLT */
-	11,			/* 26 T_SEGNPFLT */
-	12,			/* 27 T_STKFLT */
-	18,			/* 28 T_MCHK */
-	19,			/* 29 T_XMMFLT */
-	15			/* 30 T_RESERVED */
-};
-#define bsd_to_linux_trapcode(code) \
-    ((code)<nitems(_bsd_to_linux_trapcode)? \
-     _bsd_to_linux_trapcode[(code)]: \
-     LINUX_T_UNKNOWN)
-
 struct linux32_ps_strings {
 	u_int32_t ps_argvstr;	/* first of 0 or more argument strings */
 	u_int ps_nargvstr;	/* the number of argument strings */
diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c
index 9b99a5dfbed0..b11a3ae136bf 100644
--- a/sys/i386/linux/linux_sysvec.c
+++ b/sys/i386/linux/linux_sysvec.c
@@ -117,45 +117,6 @@ static void	linux_vdso_install(const void *param);
 static void	linux_vdso_deinstall(const void *param);
 static void	linux_vdso_reloc(char *mapping, Elf_Addr offset);
 
-#define LINUX_T_UNKNOWN  255
-static int _bsd_to_linux_trapcode[] = {
-	LINUX_T_UNKNOWN,	/* 0 */
-	6,			/* 1  T_PRIVINFLT */
-	LINUX_T_UNKNOWN,	/* 2 */
-	3,			/* 3  T_BPTFLT */
-	LINUX_T_UNKNOWN,	/* 4 */
-	LINUX_T_UNKNOWN,	/* 5 */
-	16,			/* 6  T_ARITHTRAP */
-	254,			/* 7  T_ASTFLT */
-	LINUX_T_UNKNOWN,	/* 8 */
-	13,			/* 9  T_PROTFLT */
-	1,			/* 10 T_TRCTRAP */
-	LINUX_T_UNKNOWN,	/* 11 */
-	14,			/* 12 T_PAGEFLT */
-	LINUX_T_UNKNOWN,	/* 13 */
-	17,			/* 14 T_ALIGNFLT */
-	LINUX_T_UNKNOWN,	/* 15 */
-	LINUX_T_UNKNOWN,	/* 16 */
-	LINUX_T_UNKNOWN,	/* 17 */
-	0,			/* 18 T_DIVIDE */
-	2,			/* 19 T_NMI */
-	4,			/* 20 T_OFLOW */
-	5,			/* 21 T_BOUND */
-	7,			/* 22 T_DNA */
-	8,			/* 23 T_DOUBLEFLT */
-	9,			/* 24 T_FPOPFLT */
-	10,			/* 25 T_TSSFLT */
-	11,			/* 26 T_SEGNPFLT */
-	12,			/* 27 T_STKFLT */
-	18,			/* 28 T_MCHK */
-	19,			/* 29 T_XMMFLT */
-	15			/* 30 T_RESERVED */
-};
-#define bsd_to_linux_trapcode(code) \
-    ((code)<nitems(_bsd_to_linux_trapcode)? \
-     _bsd_to_linux_trapcode[(code)]: \
-     LINUX_T_UNKNOWN)
-
 LINUX_VDSO_SYM_CHAR(linux_platform);
 LINUX_VDSO_SYM_INTPTR(__kernel_vsyscall);
 LINUX_VDSO_SYM_INTPTR(linux_vdso_sigcode);
diff --git a/sys/x86/linux/linux_x86.c b/sys/x86/linux/linux_x86.c
index 160a721b1418..2f4658106621 100644
--- a/sys/x86/linux/linux_x86.c
+++ b/sys/x86/linux/linux_x86.c
@@ -35,6 +35,41 @@ __FBSDID("$FreeBSD$");
 
 #include <x86/linux/linux_x86.h>
 
+#define LINUX_T_UNKNOWN  255
+static int _bsd_to_linux_trapcode[] = {
+	LINUX_T_UNKNOWN,	/* 0 */
+	6,			/* 1  T_PRIVINFLT */
+	LINUX_T_UNKNOWN,	/* 2 */
+	3,			/* 3  T_BPTFLT */
+	LINUX_T_UNKNOWN,	/* 4 */
+	LINUX_T_UNKNOWN,	/* 5 */
+	16,			/* 6  T_ARITHTRAP */
+	254,			/* 7  T_ASTFLT */
+	LINUX_T_UNKNOWN,	/* 8 */
+	13,			/* 9  T_PROTFLT */
+	1,			/* 10 T_TRCTRAP */
+	LINUX_T_UNKNOWN,	/* 11 */
+	14,			/* 12 T_PAGEFLT */
+	LINUX_T_UNKNOWN,	/* 13 */
+	17,			/* 14 T_ALIGNFLT */
+	LINUX_T_UNKNOWN,	/* 15 */
+	LINUX_T_UNKNOWN,	/* 16 */
+	LINUX_T_UNKNOWN,	/* 17 */
+	0,			/* 18 T_DIVIDE */
+	2,			/* 19 T_NMI */
+	4,			/* 20 T_OFLOW */
+	5,			/* 21 T_BOUND */
+	7,			/* 22 T_DNA */
+	8,			/* 23 T_DOUBLEFLT */
+	9,			/* 24 T_FPOPFLT */
+	10,			/* 25 T_TSSFLT */
+	11,			/* 26 T_SEGNPFLT */
+	12,			/* 27 T_STKFLT */
+	18,			/* 28 T_MCHK */
+	19,			/* 29 T_XMMFLT */
+	15			/* 30 T_RESERVED */
+};
+
 /*
  * If FreeBSD & Linux have a difference of opinion about what a trap
  * means, deal with it here.
@@ -54,3 +89,11 @@ linux_translate_traps(int signal, int trap_code)
 		return (signal);
 	}
 }
+
+int
+bsd_to_linux_trapcode(int code)
+{
+
+	return (code < nitems(_bsd_to_linux_trapcode) ?
+	    _bsd_to_linux_trapcode[code] : LINUX_T_UNKNOWN);
+}
\ No newline at end of file
diff --git a/sys/x86/linux/linux_x86.h b/sys/x86/linux/linux_x86.h
index a7eb871113ee..ce083bb1c3f5 100644
--- a/sys/x86/linux/linux_x86.h
+++ b/sys/x86/linux/linux_x86.h
@@ -36,5 +36,6 @@ int	linux_vdso_tsc_selector_idx(void);
 int	linux_vdso_cpu_selector_idx(void);
 
 int	linux_translate_traps(int, int);
+int	bsd_to_linux_trapcode(int);
 
 #endif /* _X86_INCLUDE_LINUX_LINUX_X86_H_ */



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