Module Name: src Committed By: maxv Date: Tue Jul 22 08:18:33 UTC 2014
Modified Files: src/sys/compat/linux32/common: linux32_mod.c src/sys/compat/netbsd32: netbsd32_mod.c src/sys/kern: exec_elf32.c exec_elf64.c Log Message: 1) On 64bit systems, don't add the 32bit execsw[] to the global exec array. exec_elf32 works on 32bit systems only, and will crash 32bit binaries on 64bit systems. 2) Now that exec_elf32 is dormant, we can give the native ELF loaders the highest priority. Binaries will load faster now (system boot, compilation, etc.). With the help of njloy@. Discussed a bit on tech-kern@, no disagreement. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/compat/linux32/common/linux32_mod.c cvs rdiff -u -r1.4 -r1.5 src/sys/compat/netbsd32/netbsd32_mod.c cvs rdiff -u -r1.140 -r1.141 src/sys/kern/exec_elf32.c cvs rdiff -u -r1.5 -r1.6 src/sys/kern/exec_elf64.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/compat/linux32/common/linux32_mod.c diff -u src/sys/compat/linux32/common/linux32_mod.c:1.5 src/sys/compat/linux32/common/linux32_mod.c:1.6 --- src/sys/compat/linux32/common/linux32_mod.c:1.5 Fri Mar 7 01:33:43 2014 +++ src/sys/compat/linux32/common/linux32_mod.c Tue Jul 22 08:18:33 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: linux32_mod.c,v 1.5 2014/03/07 01:33:43 christos Exp $ */ +/* $NetBSD: linux32_mod.c,v 1.6 2014/07/22 08:18:33 maxv Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux32_mod.c,v 1.5 2014/03/07 01:33:43 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux32_mod.c,v 1.6 2014/07/22 08:18:33 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_execfmt.h" @@ -67,7 +67,7 @@ static struct execsw linux32_execsw[] = .elf_probe_func = linux32_elf32_probe, }, .es_emul = &emul_linux32, - .es_prio = EXECSW_PRIO_FIRST, + .es_prio = EXECSW_PRIO_ANY, .es_arglen = LINUX32_ELF_AUX_ARGSIZ, .es_copyargs = linux32_elf32_copyargs, .es_setregs = NULL, Index: src/sys/compat/netbsd32/netbsd32_mod.c diff -u src/sys/compat/netbsd32/netbsd32_mod.c:1.4 src/sys/compat/netbsd32/netbsd32_mod.c:1.5 --- src/sys/compat/netbsd32/netbsd32_mod.c:1.4 Fri Jul 11 16:22:49 2014 +++ src/sys/compat/netbsd32/netbsd32_mod.c Tue Jul 22 08:18:33 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd32_mod.c,v 1.4 2014/07/11 16:22:49 maxv Exp $ */ +/* $NetBSD: netbsd32_mod.c,v 1.5 2014/07/22 08:18:33 maxv Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netbsd32_mod.c,v 1.4 2014/07/11 16:22:49 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netbsd32_mod.c,v 1.5 2014/07/22 08:18:33 maxv Exp $"); #ifdef _KERNEL_OPT #include "opt_execfmt.h" @@ -87,7 +87,7 @@ static struct execsw netbsd32_execsw[] = .elf_probe_func = netbsd32_elf32_probe, }, .es_emul = &emul_netbsd32, - .es_prio = EXECSW_PRIO_FIRST, + .es_prio = EXECSW_PRIO_ANY, .es_arglen = ELF32_AUXSIZE, .es_copyargs = netbsd32_elf32_copyargs, .es_setregs = NULL, Index: src/sys/kern/exec_elf32.c diff -u src/sys/kern/exec_elf32.c:1.140 src/sys/kern/exec_elf32.c:1.141 --- src/sys/kern/exec_elf32.c:1.140 Mon Apr 7 17:02:15 2014 +++ src/sys/kern/exec_elf32.c Tue Jul 22 08:18:33 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: exec_elf32.c,v 1.140 2014/04/07 17:02:15 rjs Exp $ */ +/* $NetBSD: exec_elf32.c,v 1.141 2014/07/22 08:18:33 maxv Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: exec_elf32.c,v 1.140 2014/04/07 17:02:15 rjs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: exec_elf32.c,v 1.141 2014/07/22 08:18:33 maxv Exp $"); #define ELFSIZE 32 @@ -59,7 +59,7 @@ static struct execsw exec_elf32_execsw[] .elf_probe_func = netbsd_elf32_probe, }, .es_emul = &emul_netbsd, - .es_prio = EXECSW_PRIO_ANY, + .es_prio = EXECSW_PRIO_FIRST, .es_arglen = ELF32_AUXSIZE, .es_copyargs = elf32_copyargs, .es_setregs = NULL, @@ -87,7 +87,28 @@ static struct execsw exec_elf32_execsw[] static int exec_elf32_modcmd(modcmd_t cmd, void *arg) { +#if ARCH_ELFSIZE == 64 + /* + * If we are on a 64bit system, we don't want the 32bit execsw[] to be + * added in the global array, because the exec_elf32 module only works + * on 32bit systems. + * + * However, we need the exec_elf32 module, because it will make the 32bit + * functions available for netbsd32 and linux32. + * + * Therefore, allow this module on 64bit systems, but make it dormant. + */ + (void)exec_elf32_execsw; /* unused */ + + switch (cmd) { + case MODULE_CMD_INIT: + case MODULE_CMD_FINI: + return 0; + default: + return ENOTTY; + } +#else /* ARCH_ELFSIZE == 64 */ switch (cmd) { case MODULE_CMD_INIT: return exec_add(exec_elf32_execsw, @@ -100,4 +121,5 @@ exec_elf32_modcmd(modcmd_t cmd, void *ar default: return ENOTTY; } +#endif /* ARCH_ELFSIZE == 64 */ } Index: src/sys/kern/exec_elf64.c diff -u src/sys/kern/exec_elf64.c:1.5 src/sys/kern/exec_elf64.c:1.6 --- src/sys/kern/exec_elf64.c:1.5 Fri Mar 7 01:34:29 2014 +++ src/sys/kern/exec_elf64.c Tue Jul 22 08:18:33 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: exec_elf64.c,v 1.5 2014/03/07 01:34:29 christos Exp $ */ +/* $NetBSD: exec_elf64.c,v 1.6 2014/07/22 08:18:33 maxv Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: exec_elf64.c,v 1.5 2014/03/07 01:34:29 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: exec_elf64.c,v 1.6 2014/07/22 08:18:33 maxv Exp $"); #define ELFSIZE 64 @@ -60,7 +60,7 @@ static struct execsw exec_elf64_execsw[] .elf_probe_func = netbsd_elf64_probe, }, .es_emul = &emul_netbsd, - .es_prio = EXECSW_PRIO_ANY, + .es_prio = EXECSW_PRIO_FIRST, .es_arglen = ELF64_AUXSIZE, .es_copyargs = elf64_copyargs, .es_setregs = NULL,