summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authoretheisen <etheisen@cvs.openbsd.org>1996-05-28 14:11:22 +0000
committeretheisen <etheisen@cvs.openbsd.org>1996-05-28 14:11:22 +0000
commit31beaec168439f823a5cc938dd3131863b291ecd (patch)
treecfa97fdeaf2ca839860b16e9d78a662053936041 /lib/libc
parent7c0d720f533eb03027edc2fbf7b19ca0852eec95 (diff)
All platforms get elf_nlist(). Hidden __elf_is_okay__() function is
now present for ELF platforms. This function is not ABI compliant and it's use should be restricted. exec_sup.h now determines the target OMF for various platforms.
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/gen/Makefile.inc29
-rw-r--r--lib/libc/gen/elf_hash.c49
-rw-r--r--lib/libc/gen/elf_sup.c45
-rw-r--r--lib/libc/gen/exec_sup.h68
-rw-r--r--lib/libc/gen/nlist.c19
5 files changed, 164 insertions, 46 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index 2da0e6ec6fd..fa527cc1402 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.3 1996/04/29 04:53:27 etheisen Exp $
+# $OpenBSD: Makefile.inc,v 1.4 1996/05/28 14:11:20 etheisen Exp $
# $NetBSD: Makefile.inc,v 1.71 1996/04/15 23:44:53 jtc Exp $
# @(#)Makefile.inc 8.3 (Berkeley) 4/16/94
@@ -6,19 +6,20 @@
.PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/gen ${.CURDIR}/gen
SRCS+= alarm.c assert.c clock.c closedir.c confstr.c ctermid.c \
- ctype_.c daemon.c devname.c disklabel.c err.c errx.c errlist.c \
- errno.c exec.c fnmatch.c fstab.c ftok.c fts.c getbsize.c getcap.c \
- getcwd.c getdomainname.c getgrent.c getgrouplist.c gethostname.c \
- getloadavg.c getlogin.c getmntinfo.c getnetgrent.c getpagesize.c \
- getpass.c getpwent.c getsubopt.c getttyent.c getusershell.c glob.c \
- initgroups.c isatty.c isctype.c nice.c nlist.c opendir.c pause.c \
- popen.c psignal.c pwcache.c raise.c readdir.c rewinddir.c scandir.c \
- seekdir.c setdomainname.c sethostname.c setjmperr.c setmode.c \
- setproctitle.c siginterrupt.c siglist.c signal.c signame.c \
- sigsetops.c sleep.c sysconf.c sysctl.c syslog.c telldir.c \
- time.c times.c timezone.c tolower_.c ttyname.c ttyslot.c toupper_.c \
- ualarm.c uname.c unvis.c usleep.c utime.c valloc.c vis.c wait.c \
- wait3.c waitpid.c warn.c warnx.c vwarn.c vwarnx.c verr.c verrx.c
+ ctype_.c daemon.c devname.c disklabel.c elf_hash.c err.c \
+ errx.c errlist.c errno.c exec.c fnmatch.c fstab.c ftok.c fts.c \
+ getbsize.c getcap.c getcwd.c getdomainname.c getgrent.c \
+ getgrouplist.c gethostname.c getloadavg.c getlogin.c getmntinfo.c \
+ getnetgrent.c getpagesize.c getpass.c getpwent.c getsubopt.c \
+ getttyent.c getusershell.c glob.c initgroups.c isatty.c isctype.c \
+ nice.c nlist.c opendir.c pause.c popen.c psignal.c pwcache.c raise.c \
+ readdir.c rewinddir.c scandir.c seekdir.c setdomainname.c \
+ sethostname.c setjmperr.c setmode.c setproctitle.c siginterrupt.c \
+ siglist.c signal.c signame.c sigsetops.c sleep.c sysconf.c sysctl.c \
+ syslog.c telldir.c time.c times.c timezone.c tolower_.c ttyname.c \
+ ttyslot.c toupper_.c ualarm.c uname.c unvis.c usleep.c utime.c \
+ valloc.c vis.c wait.c wait3.c waitpid.c warn.c warnx.c vwarn.c \
+ vwarnx.c verr.c verrx.c
# indirect reference stubs, to be removed soon.
SRCS+= _err.c _errx.c _sys_errlist.c _sys_nerr.c _sys_siglist.c \
diff --git a/lib/libc/gen/elf_hash.c b/lib/libc/gen/elf_hash.c
new file mode 100644
index 00000000000..3ed039f5d00
--- /dev/null
+++ b/lib/libc/gen/elf_hash.c
@@ -0,0 +1,49 @@
+/* $OpenBSD: elf_hash.c,v 1.1 1996/05/28 14:11:20 etheisen Exp $ */
+/*
+ * Copyright (c) 1995, 1996 Erik Theisen
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 <elf_abi.h>
+
+/*
+ * Standard ELF ABI hash function.
+ * DO NOT MODIFY THIS FUNCTION -- INVALID
+ * HASH TABLES WILL BE GENERATED!
+ */
+unsigned long
+elf_hash(name)
+ const unsigned char *name;
+{
+ register unsigned long h = 0, g;
+
+ while(*name)
+ {
+ h = (h << 4) + *name++;
+ if (g = h & 0xf0000000)
+ h ^= g >> 24;
+ h &= ~g;
+ }
+ return h;
+} /* end elf_hash() */
diff --git a/lib/libc/gen/elf_sup.c b/lib/libc/gen/elf_sup.c
index 597352b0b0f..38bdce85ba5 100644
--- a/lib/libc/gen/elf_sup.c
+++ b/lib/libc/gen/elf_sup.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: elf_sup.c,v 1.1 1996/04/29 04:53:28 etheisen Exp $ */
+/* $OpenBSD: elf_sup.c,v 1.2 1996/05/28 14:11:21 etheisen Exp $ */
/*
* Copyright (c) 1995, 1996 Erik Theisen
* All rights reserved.
@@ -25,25 +25,36 @@
* (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 <elf_abi.h>
+#include "exec_sup.h"
/*
- * Standard ELF ABI hash function.
- * DO NOT MODIFY THIS FUNCTION -- INVALID
- * HASH TABLES WILL BE GENERATED!
+ * __elf_is_okay__ - Determine if ehdr really
+ * is ELF and valid for the target platform.
+ *
+ * WARNING: This is NOT a ELF ABI function and
+ * as such it's use should be restricted.
*/
-unsigned long
-elf_hash(name)
- const unsigned char *name;
+int
+__elf_is_okay__(ehdr)
+ register Elf32_Ehdr *ehdr;
{
- register unsigned long h = 0, g;
+ register int retval = 0;
+
+ /*
+ * We need to check magic, class size, endianess,
+ * and version before we look at the rest of the
+ * Elf32_Ehdr structure. These few elements are
+ * represented in a machine independant fashion.
+ */
+ if(IS_ELF(*ehdr) &&
+ ehdr->e_ident[EI_CLASS] == ELF_TARG_CLASS &&
+ ehdr->e_ident[EI_DATA] == ELF_TARG_DATA &&
+ ehdr->e_ident[EI_VERSION] == ELF_TARG_VER) {
- while(*name)
- {
- h = (h << 4) + *name++;
- if (g = h & 0xf0000000)
- h ^= g >> 24;
- h &= ~g;
+ /* Now check the machine dependant header */
+ if(ehdr->e_machine == ELF_TARG_MACH &&
+ ehdr->e_version == ELF_TARG_VER)
+ retval = 1;
}
- return h;
-} /* end elf_hash() */
+ return retval;
+} /* end __elf_is_okay__() */
diff --git a/lib/libc/gen/exec_sup.h b/lib/libc/gen/exec_sup.h
new file mode 100644
index 00000000000..f46ca9e0b11
--- /dev/null
+++ b/lib/libc/gen/exec_sup.h
@@ -0,0 +1,68 @@
+/* $OpenBSD: exec_sup.h,v 1.1 1996/05/28 14:11:21 etheisen Exp $ */
+/*
+ * Copyright (c) 1995, 1996 Erik Theisen
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
+ */
+
+#ifndef _EXEC_SUP_H_
+#define _EXEC_SUP_H_
+
+#define DO_AOUT /* Always do a.out */
+
+#if defined (__i386__) || defined (__mips__)
+#define DO_ELF
+#define ELF_TARG_VER 1 /* The ver for which this code is intended */
+#include <elf_abi.h>
+int __elf_is_okay__ (Elf32_Ehdr *ehdr); /* XXX - should this be hidden??? */
+#endif /* ELF machines */
+
+#if defined (__i386__)
+ #define ELF_TARG_CLASS ELFCLASS32
+ #define ELF_TARG_DATA ELFDATA2LSB
+ #define ELF_TARG_MACH EM_386
+
+#elif defined (__mips__)
+ #define ELF_TARG_CLASS ELFCLASS32
+ #define ELF_TARG_DATA ELFDATA2LSB
+ #define ELF_TARG_MACH EM_MIPS
+
+#elif defined (__alpha__)
+ #define DO_ECOFF
+
+#elif defined (pica)
+ #define DO_ECOFF
+
+#endif /* Machines */
+
+#ifdef DO_AOUT
+#include <sys/types.h>
+#include <a.out.h>
+#endif
+
+#ifdef DO_ECOFF
+#include <sys/exec_ecoff.h>
+#endif
+
+#endif /* _EXEC_SUP_H_ */
diff --git a/lib/libc/gen/nlist.c b/lib/libc/gen/nlist.c
index 826500414a6..1f5458189a0 100644
--- a/lib/libc/gen/nlist.c
+++ b/lib/libc/gen/nlist.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nlist.c,v 1.7 1996/05/24 10:59:00 deraadt Exp $ */
+/* $OpenBSD: nlist.c,v 1.8 1996/05/28 14:11:21 etheisen Exp $ */
/* $NetBSD: nlist.c,v 1.7 1996/05/16 20:49:20 cgd Exp $ */
/*
@@ -35,14 +35,10 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: nlist.c,v 1.7 1996/05/24 10:59:00 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: nlist.c,v 1.8 1996/05/28 14:11:21 etheisen Exp $";
#endif /* LIBC_SCCS and not lint */
-#define DO_AOUT /* always do a.out */
-#if defined(__alpha__) || defined(pica)
-#define DO_ECOFF
-#endif
-#define DO_ELF
+#include "exec_sup.h" /* determine targ OMFs for a given machine */
#include <sys/param.h>
#include <sys/mman.h>
@@ -50,13 +46,6 @@ static char rcsid[] = "$OpenBSD: nlist.c,v 1.7 1996/05/24 10:59:00 deraadt Exp $
#include <sys/file.h>
#include <errno.h>
-#include <a.out.h>
-#ifdef DO_ECOFF
-#include <sys/exec_ecoff.h>
-#endif
-#ifdef DO_ELF
-#include <elf_abi.h>
-#endif
#include <stdio.h>
#include <string.h>
#include <unistd.h>
@@ -274,7 +263,7 @@ __elf_fdnlist(fd, list)
if (lseek(fd, (off_t)0, SEEK_SET) == -1 ||
read(fd, &eh, sizeof(eh)) != sizeof(eh) ||
- !IS_ELF(eh) ||
+ !__elf_is_okay__(&eh) ||
fstat(fd, &st) < 0)
return (-1);