summaryrefslogtreecommitdiffstats
path: root/usr.sbin/kvm_mkdb/nlist.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>1996-07-31 16:51:51 +0000
committerderaadt <deraadt@openbsd.org>1996-07-31 16:51:51 +0000
commit05940cd377466dbca934c1f6fa3bc54a9186922b (patch)
treec167798b6bdd48edd5b86e74ee0bf74221c4cecd /usr.sbin/kvm_mkdb/nlist.c
parentkernel is /bsd, and we are OpenBSD (diff)
downloadwireguard-openbsd-05940cd377466dbca934c1f6fa3bc54a9186922b.tar.xz
wireguard-openbsd-05940cd377466dbca934c1f6fa3bc54a9186922b.zip
zmagic/qmagic has kernel offset problem; netbsd pr#2665, leo@marco.de.
also rely on machine/exec.h DO_{AOUT,ELF,...} symbols, and declare a stub ecoff handler for niklas to finish writing (stealable from libc)
Diffstat (limited to 'usr.sbin/kvm_mkdb/nlist.c')
-rw-r--r--usr.sbin/kvm_mkdb/nlist.c98
1 files changed, 55 insertions, 43 deletions
diff --git a/usr.sbin/kvm_mkdb/nlist.c b/usr.sbin/kvm_mkdb/nlist.c
index dc3f29b9666..d9e27294b0a 100644
--- a/usr.sbin/kvm_mkdb/nlist.c
+++ b/usr.sbin/kvm_mkdb/nlist.c
@@ -33,12 +33,9 @@
#ifndef lint
/*static char sccsid[] = "from: @(#)nlist.c 8.1 (Berkeley) 6/6/93";*/
-static char *rcsid = "$Id: nlist.c,v 1.3 1996/05/24 09:22:59 deraadt Exp $";
+static char *rcsid = "$Id: nlist.c,v 1.4 1996/07/31 16:51:51 deraadt Exp $";
#endif /* not lint */
-#define DO_AOUT /* always do a.out */
-#define DO_ELF /* and elf too */
-
#include <sys/param.h>
#include <a.out.h>
@@ -68,14 +65,13 @@ typedef struct nlist NLIST;
#define _name n_un.n_name
#define badfmt(str) errx(1, "%s: %s: %s", kfile, str, strerror(EFTYPE))
-
-static void badread __P((int, char *));
-static u_long get_kerntext __P((char *kfn));
-
static char *kfile;
#if defined(DO_AOUT)
+static void badread __P((int, char *));
+static u_long get_kerntext __P((char *kfn, u_int magic));
+
int
__aout_knlist(name, db)
char *name;
@@ -131,7 +127,7 @@ __aout_knlist(name, db)
data.data = (u_char *)&nbuf;
data.size = sizeof(NLIST);
- kerntextoff = get_kerntext(name);
+ kerntextoff = get_kerntext(name, N_GETMAGIC(ebuf));
/* Read each symbol and enter it into the database. */
nsyms = ebuf.a_syms / sizeof(struct nlist);
@@ -192,6 +188,47 @@ __aout_knlist(name, db)
return(0);
}
+/*
+ * XXX: Using this value from machine/param.h introduces a
+ * XXX: machine dependency on this program, so /usr can not
+ * XXX: be shared between (i.e.) several m68k machines.
+ * Instead of compiling in KERNTEXTOFF or KERNBASE, try to
+ * determine the text start address from a standard symbol.
+ * For backward compatibility, use the old compiled-in way
+ * when the standard symbol name is not found.
+ */
+#ifndef KERNTEXTOFF
+#define KERNTEXTOFF KERNBASE
+#endif
+
+static u_long
+get_kerntext(name, magic)
+ char *name;
+ u_int magic;
+{
+ NLIST nl[2];
+
+ bzero((caddr_t)nl, sizeof(nl));
+ nl[0]._name = "_kernel_text";
+
+ if (nlist(name, nl) != 0)
+ return (KERNTEXTOFF);
+
+ if (magic == ZMAGIC || magic == QMAGIC)
+ return (nl[0].n_value - sizeof(struct exec));
+ return (nl[0].n_value);
+}
+
+static void
+badread(nr, p)
+ int nr;
+ char *p;
+{
+ if (nr < 0)
+ err(1, "%s", kfile);
+ badfmt(p);
+}
+
#endif
#ifdef DO_ELF
@@ -357,43 +394,15 @@ __elf_knlist(name, db)
}
#endif /* DO_ELF */
-static void
-badread(nr, p)
- int nr;
- char *p;
-{
- if (nr < 0)
- err(1, "%s", kfile);
- badfmt(p);
-}
-
-/*
- * XXX: Using this value from machine/param.h introduces a
- * XXX: machine dependency on this program, so /usr can not
- * XXX: be shared between (i.e.) several m68k machines.
- * Instead of compiling in KERNTEXTOFF or KERNBASE, try to
- * determine the text start address from a standard symbol.
- * For backward compatibility, use the old compiled-in way
- * when the standard symbol name is not found.
- */
-#ifndef KERNTEXTOFF
-#define KERNTEXTOFF KERNBASE
-#endif
-
-static u_long
-get_kerntext(name)
+#ifdef DO_ECOFF
+int
+__ecoff_knlist(name, db)
char *name;
+ DB *db;
{
- NLIST nl[2];
-
- bzero((caddr_t)nl, sizeof(nl));
- nl[0]._name = "_kernel_text";
-
- if (nlist(name, nl) != 0)
- return (KERNTEXTOFF);
-
- return (nl[0].n_value);
+ return (-1);
}
+#endif /* DO_ECOFF */
static struct knlist_handlers {
int (*fn) __P((char *name, DB *db));
@@ -404,6 +413,9 @@ static struct knlist_handlers {
#ifdef DO_ELF
{ __elf_knlist },
#endif
+#ifdef DO_ECOFF
+ { __ecoff_knlist },
+#endif
};
void