Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Remove dead code. The kernel already checks for PT_INTER...



details:   https://anonhg.NetBSD.org/src/rev/f5375fbed6e5
branches:  trunk
changeset: 796900:f5375fbed6e5
user:      maxv <maxv%NetBSD.org@localhost>
date:      Tue Jun 24 11:59:10 2014 +0000

description:
Remove dead code. The kernel already checks for PT_INTERP sections, and puts
their content into "itp". There's no need for re-reading the whole binary and
trying to find this section again. Just use "itp".

DEBUG_FREEBSD_ELF is now unused, so remove its references in amd64/conf/ALL
and i386/conf/ALL.

diffstat:

 sys/arch/amd64/conf/ALL                 |   5 +-
 sys/arch/i386/conf/ALL                  |   5 +-
 sys/compat/freebsd/freebsd_exec_elf32.c |  75 +++++---------------------------
 3 files changed, 17 insertions(+), 68 deletions(-)

diffs (164 lines):

diff -r 342d3e8bb88e -r f5375fbed6e5 sys/arch/amd64/conf/ALL
--- a/sys/arch/amd64/conf/ALL   Tue Jun 24 11:32:36 2014 +0000
+++ b/sys/arch/amd64/conf/ALL   Tue Jun 24 11:59:10 2014 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.9 2014/06/10 01:42:39 hikaru Exp $
+# $NetBSD: ALL,v 1.10 2014/06/24 11:59:10 maxv Exp $
 # From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
 #
 # ALL machine description file
@@ -17,7 +17,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident                 "ALL-$Revision: 1.9 $"
+#ident                 "ALL-$Revision: 1.10 $"
 
 maxusers       64              # estimated number of users
 
@@ -1829,7 +1829,6 @@
 options DEBUG_FIND_PCIC
 options DEBUG_FIND_PCIC_I82365SL_ONLY
 options DEBUG_FPE
-options DEBUG_FREEBSD_ELF
 options DEBUG_GPIO
 options DEBUG_GPIO2
 options DEBUG_HPUX
diff -r 342d3e8bb88e -r f5375fbed6e5 sys/arch/i386/conf/ALL
--- a/sys/arch/i386/conf/ALL    Tue Jun 24 11:32:36 2014 +0000
+++ b/sys/arch/i386/conf/ALL    Tue Jun 24 11:59:10 2014 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.376 2014/06/10 01:42:39 hikaru Exp $
+# $NetBSD: ALL,v 1.377 2014/06/24 11:59:10 maxv Exp $
 # From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
 #
 # ALL machine description file
@@ -17,7 +17,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident                 "ALL-$Revision: 1.376 $"
+#ident                 "ALL-$Revision: 1.377 $"
 
 maxusers       64              # estimated number of users
 
@@ -2030,7 +2030,6 @@
 options DEBUG_FIND_PCIC
 options DEBUG_FIND_PCIC_I82365SL_ONLY
 options DEBUG_FPE
-options DEBUG_FREEBSD_ELF
 options DEBUG_GPIO
 options DEBUG_GPIO2
 options DEBUG_HPUX
diff -r 342d3e8bb88e -r f5375fbed6e5 sys/compat/freebsd/freebsd_exec_elf32.c
--- a/sys/compat/freebsd/freebsd_exec_elf32.c   Tue Jun 24 11:32:36 2014 +0000
+++ b/sys/compat/freebsd/freebsd_exec_elf32.c   Tue Jun 24 11:59:10 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: freebsd_exec_elf32.c,v 1.17 2007/04/22 08:29:56 dsl Exp $      */
+/*     $NetBSD: freebsd_exec_elf32.c,v 1.18 2014/06/24 11:59:10 maxv Exp $     */
 
 /*
  * Copyright (c) 1993, 1994 Christopher G. Demetriou
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: freebsd_exec_elf32.c,v 1.17 2007/04/22 08:29:56 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: freebsd_exec_elf32.c,v 1.18 2014/06/24 11:59:10 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -54,25 +54,15 @@
 
 
 int
-ELFNAME2(freebsd,probe)(
-       struct lwp *l,
-       struct exec_package *epp,
-       void *veh,
-       char *itp,
-       vaddr_t *pos)
+ELFNAME2(freebsd,probe)(struct lwp *l, struct exec_package *epp, void *veh,
+    char *itp, vaddr_t *pos)
 {
        int error;
-       size_t i;
-       size_t phsize;
        Elf_Ehdr *eh = (Elf_Ehdr *) veh;
-       Elf_Phdr *ph;
-       Elf_Phdr *ephp;
-       Elf_Nhdr *np;
+       static const char wantBrand[] = FREEBSD_ELF_BRAND_STRING;
+       static const char wantInterp[] = FREEBSD_ELF_INTERP_PREFIX_STRING;
 
-        static const char wantBrand[] = FREEBSD_ELF_BRAND_STRING;
-        static const char wantInterp[] = FREEBSD_ELF_INTERP_PREFIX_STRING;
-
-        /*
+       /*
         * Insist that the executable have a brand, and that it be "FreeBSD".
         * Newer FreeBSD binaries have OSABI set to ELFOSABI_FREEBSD. This
         * is arguably broken, but they seem to think they need it, for
@@ -81,56 +71,17 @@
 #ifndef EI_BRAND
 #define EI_BRAND 8
 #endif
-        if ((eh->e_ident[EI_BRAND] == '\0'
-               || strcmp(&eh->e_ident[EI_BRAND], wantBrand) != 0)
-           && eh->e_ident[EI_OSABI] != ELFOSABI_FREEBSD)
+       if ((eh->e_ident[EI_BRAND] == '\0' ||
+            strcmp(&eh->e_ident[EI_BRAND], wantBrand) != 0) &&
+               eh->e_ident[EI_OSABI] != ELFOSABI_FREEBSD)
                return ENOEXEC;
 
-       i = eh->e_phnum;
-       if (i != 0) {
-               phsize = i * sizeof(Elf_Phdr);
-               ph = (Elf_Phdr *) malloc(phsize, M_TEMP, M_WAITOK);
-               if ((error = exec_read_from(l, epp->ep_vp, eh->e_phoff, ph,
-                   phsize)) != 0)
-                       goto bad1;
-
-               for (ephp = ph; i--; ephp++) {
-                       if (ephp->p_type != PT_INTERP)
-                               continue;
-
-                       /* Check for "legal" intepreter name. */
-                       if (ephp->p_filesz < sizeof wantInterp)
-                               goto bad1;
-
-                       np = (Elf_Nhdr *) malloc(ephp->p_filesz+1,
-                           M_TEMP, M_WAITOK);
-
-                       if (((error = exec_read_from(l, epp->ep_vp,
-                           ephp->p_offset, np, ephp->p_filesz)) != 0))
-                               goto bad2;
-
-                       if (strncmp((char *)np, wantInterp,
-                           sizeof wantInterp - 1))
-                               goto bad2;
-
-                       free(np, M_TEMP);
-                       break;
-               }
-               free(ph, M_TEMP);
-       }
-
        if (itp) {
+               if (strncmp(itp, wantInterp, sizeof(wantInterp) - 1))
+                       return ENOEXEC;
                if ((error = emul_find_interp(l, epp, itp)))
                        return error;
        }
-#ifdef DEBUG_FREEBSD_ELF
-       printf("freebsd_elf32_probe: returning 0\n");
-#endif
+
        return 0;
-
-bad2:
-       free(np, M_TEMP);
-bad1:
-       free(ph, M_TEMP);
-       return ENOEXEC;
 }



Home | Main Index | Thread Index | Old Index