Use the symbol "_kernel_text" if it exists, instead of KERNTEXTOFF.

This allows /usr/sbin/kvm_mkdb to be shared among m68k machines.
This commit is contained in:
gwr 1996-05-16 21:17:21 +00:00
parent a964fa9b57
commit 36c3560196

View File

@ -33,7 +33,7 @@
#ifndef lint
/*static char sccsid[] = "from: @(#)nlist.c 8.1 (Berkeley) 6/6/93";*/
static char *rcsid = "$Id: nlist.c,v 1.10 1994/06/11 07:57:41 mycroft Exp $";
static char *rcsid = "$Id: nlist.c,v 1.11 1996/05/16 21:17:21 gwr Exp $";
#endif /* not lint */
#include <sys/param.h>
@ -59,6 +59,7 @@ typedef struct nlist NLIST;
#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;
@ -73,6 +74,7 @@ create_knlist(name, db)
NLIST nbuf;
DBT data, key;
int fd, nr, strsize;
u_long kerntextoff;
char *strtab, buf[1024];
kfile = name;
@ -115,6 +117,8 @@ create_knlist(name, db)
data.data = (u_char *)&nbuf;
data.size = sizeof(NLIST);
kerntextoff = get_kerntext(name);
/* Read each symbol and enter it into the database. */
nsyms = ebuf.a_syms / sizeof(struct nlist);
while (nsyms--) {
@ -133,16 +137,13 @@ create_knlist(name, db)
if (strcmp((char *)key.data, VRS_SYM) == 0) {
long cur_off, voff;
#ifndef KERNTEXTOFF
#define KERNTEXTOFF KERNBASE
#endif
/*
* Calculate offset relative to a normal (non-kernel)
* a.out. KERNTEXTOFF is where the kernel is really
* loaded; N_TXTADDR is where a normal file is loaded.
* From there, locate file offset in text or data.
*/
voff = nbuf.n_value - KERNTEXTOFF + N_TXTADDR(ebuf);
voff = nbuf.n_value - kerntextoff + N_TXTADDR(ebuf);
if ((nbuf.n_type & N_TYPE) == N_TEXT)
voff += N_TXTOFF(ebuf) - N_TXTADDR(ebuf);
else
@ -185,3 +186,31 @@ badread(nr, p)
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)
char *name;
{
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);
}