git: 2434137f690d - main - linux(4): Deduplicate translate_traps()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 23 May 2022 10:20:12 UTC
The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=2434137f690dabc35586ab45fc4c4ecc5b71184f commit 2434137f690dabc35586ab45fc4c4ecc5b71184f Author: Dmitry Chagin <dchagin@FreeBSD.org> AuthorDate: 2022-05-23 10:16:26 +0000 Commit: Dmitry Chagin <dchagin@FreeBSD.org> CommitDate: 2022-05-23 10:16:26 +0000 linux(4): Deduplicate translate_traps() As translate_traps() is common for x86 Linuxulators, move it under x86/linux. MFC after: 2 weeks --- sys/amd64/linux/linux_sysvec.c | 23 ---------------- sys/amd64/linux32/linux32_sysvec.c | 22 --------------- sys/i386/linux/linux_sysvec.c | 22 --------------- sys/modules/linux/Makefile | 3 +- sys/modules/linux_common/Makefile | 6 +++- sys/x86/linux/linux_x86.c | 56 ++++++++++++++++++++++++++++++++++++++ sys/x86/linux/linux_x86.h | 2 ++ 7 files changed, 65 insertions(+), 69 deletions(-) diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c index fbdd40433198..4592c2c26e12 100644 --- a/sys/amd64/linux/linux_sysvec.c +++ b/sys/amd64/linux/linux_sysvec.c @@ -176,29 +176,6 @@ LINUX_VDSO_SYM_INTPTR(kern_timekeep_base); LINUX_VDSO_SYM_INTPTR(kern_tsc_selector); LINUX_VDSO_SYM_INTPTR(kern_cpu_selector); -/* - * If FreeBSD & Linux have a difference of opinion about what a trap - * means, deal with it here. - * - * MPSAFE - */ -static int -linux_translate_traps(int signal, int trap_code) -{ - - if (signal != SIGBUS) - return (signal); - switch (trap_code) { - case T_PROTFLT: - case T_TSSFLT: - case T_DOUBLEFLT: - case T_PAGEFLT: - return (SIGSEGV); - default: - return (signal); - } -} - static int linux_fetch_syscall_args(struct thread *td) { diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c index 991047571e7d..ff6b1f882bc9 100644 --- a/sys/amd64/linux32/linux32_sysvec.c +++ b/sys/amd64/linux32/linux32_sysvec.c @@ -190,28 +190,6 @@ LINUX_VDSO_SYM_INTPTR(kern_tsc_selector); LINUX_VDSO_SYM_INTPTR(kern_cpu_selector); LINUX_VDSO_SYM_CHAR(linux_platform); -/* - * If FreeBSD & Linux have a difference of opinion about what a trap - * means, deal with it here. - * - * MPSAFE - */ -static int -linux_translate_traps(int signal, int trap_code) -{ - if (signal != SIGBUS) - return (signal); - switch (trap_code) { - case T_PROTFLT: - case T_TSSFLT: - case T_DOUBLEFLT: - case T_PAGEFLT: - return (SIGSEGV); - default: - return (signal); - } -} - static int linux_copyout_auxargs(struct image_params *imgp, uintptr_t base) { diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c index 2fd259aca1e5..f4c14abe6996 100644 --- a/sys/i386/linux/linux_sysvec.c +++ b/sys/i386/linux/linux_sysvec.c @@ -164,28 +164,6 @@ LINUX_VDSO_SYM_INTPTR(kern_timekeep_base); LINUX_VDSO_SYM_INTPTR(kern_tsc_selector); LINUX_VDSO_SYM_INTPTR(kern_cpu_selector); -/* - * If FreeBSD & Linux have a difference of opinion about what a trap - * means, deal with it here. - * - * MPSAFE - */ -static int -linux_translate_traps(int signal, int trap_code) -{ - if (signal != SIGBUS) - return (signal); - switch (trap_code) { - case T_PROTFLT: - case T_TSSFLT: - case T_DOUBLEFLT: - case T_PAGEFLT: - return (SIGSEGV); - default: - return (signal); - } -} - static int linux_fixup(uintptr_t *stack_base, struct image_params *imgp) { diff --git a/sys/modules/linux/Makefile b/sys/modules/linux/Makefile index b94605853743..be6231f767f1 100644 --- a/sys/modules/linux/Makefile +++ b/sys/modules/linux/Makefile @@ -41,7 +41,8 @@ OBJS= linux${SFX}_vdso.so .if ${MACHINE_CPUARCH} == "i386" SRCS+= linux_ptrace_machdep.c imgact_linux.c linux_util.c linux_mib.c \ - linux_mmap.c linux_dummy.c linux_emul.c linux_errno.c opt_cpu.h linux.c + linux_mmap.c linux_dummy.c linux_emul.c linux_errno.c opt_cpu.h linux.c \ + linux_x86.c .endif .if ${MACHINE_CPUARCH} == "i386" diff --git a/sys/modules/linux_common/Makefile b/sys/modules/linux_common/Makefile index 1815714e9202..033fabe27188 100644 --- a/sys/modules/linux_common/Makefile +++ b/sys/modules/linux_common/Makefile @@ -1,12 +1,16 @@ # $FreeBSD$ -.PATH: ${SRCTOP}/sys/compat/linux +.PATH: ${SRCTOP}/sys/compat/linux ${SRCTOP}/sys/x86/linux KMOD= linux_common SRCS= linux_common.c linux_mib.c linux_mmap.c linux_util.c linux_emul.c \ linux_dummy.c linux_errno.c \ linux.c device_if.h vnode_if.h bus_if.h opt_inet6.h +.if ${MACHINE_CPUARCH} == "amd64" +SRCS+= linux_x86.c +.endif + EXPORT_SYMS= EXPORT_SYMS+= linux_emul_path EXPORT_SYMS+= linux_get_osname diff --git a/sys/x86/linux/linux_x86.c b/sys/x86/linux/linux_x86.c new file mode 100644 index 000000000000..160a721b1418 --- /dev/null +++ b/sys/x86/linux/linux_x86.c @@ -0,0 +1,56 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 1994-1996 Søren Schmidt + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/signal.h> +#include <x86/trap.h> + +#include <x86/linux/linux_x86.h> + +/* + * If FreeBSD & Linux have a difference of opinion about what a trap + * means, deal with it here. + */ +int +linux_translate_traps(int signal, int trap_code) +{ + if (signal != SIGBUS) + return (signal); + switch (trap_code) { + case T_PROTFLT: + case T_TSSFLT: + case T_DOUBLEFLT: + case T_PAGEFLT: + return (SIGSEGV); + default: + return (signal); + } +} diff --git a/sys/x86/linux/linux_x86.h b/sys/x86/linux/linux_x86.h index 79e6e7fbfeec..a7eb871113ee 100644 --- a/sys/x86/linux/linux_x86.h +++ b/sys/x86/linux/linux_x86.h @@ -35,4 +35,6 @@ int linux_vdso_tsc_selector_idx(void); int linux_vdso_cpu_selector_idx(void); +int linux_translate_traps(int, int); + #endif /* _X86_INCLUDE_LINUX_LINUX_X86_H_ */