SCCS-vsn: usr.sbin/kvm_mkdb/kvm_mkdb.c 5.15
SCCS-vsn: usr.sbin/kvm_mkdb/nlist.c 5.6
#endif /* not lint */
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)kvm_mkdb.c 5.14 (Berkeley) %G%";
+static char sccsid[] = "@(#)kvm_mkdb.c 5.15 (Berkeley) %G%";
#endif /* not lint */
#include <sys/param.h>
#endif /* not lint */
#include <sys/param.h>
#include <db.h>
#include <errno.h>
#include <stdio.h>
#include <db.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <paths.h>
#include <string.h>
#include <paths.h>
-char *tmp;
-#define basename(cp) ((tmp=rindex((cp), '/')) ? tmp+1 : (cp))
+static void usage __P(());
+
+int
main(argc, argv)
int argc;
char **argv;
{
main(argc, argv)
int argc;
char **argv;
{
- char *nlistpath, *nlistname, dbtemp[MAXPATHLEN], dbname[MAXPATHLEN];
+ char *p, *nlistpath, *nlistname, dbtemp[MAXPATHLEN], dbname[MAXPATHLEN];
while ((ch = getopt(argc, argv, "")) != EOF)
switch((char)ch) {
while ((ch = getopt(argc, argv, "")) != EOF)
switch((char)ch) {
+ /* If the existing db file matches the currently running kernel, exit */
+ if (testdb())
+ exit(0);
+
+#define basename(cp) ((p = rindex((cp), '/')) != NULL ? p + 1 : (cp))
nlistpath = argc > 1 ? argv[0] : _PATH_UNIX;
nlistname = basename(nlistpath);
nlistpath = argc > 1 ? argv[0] : _PATH_UNIX;
nlistname = basename(nlistpath);
- (void)sprintf(dbtemp, "%skvm_%s.tmp", _PATH_VARRUN, nlistname);
- (void)sprintf(dbname, "%skvm_%s.db", _PATH_VARRUN, nlistname);
+ (void)snprintf(dbtemp, sizeof(dbtemp), "%skvm_%s.tmp",
+ _PATH_VARDB, nlistname);
+ (void)snprintf(dbname, sizeof(dbname), "%skvm_%s.db",
+ _PATH_VARDB, nlistname);
- db = dbopen(dbtemp, O_CREAT|O_WRONLY|O_EXCL,
+ db = dbopen(dbtemp, O_CREAT|O_EXLOCK|O_TRUNC|O_WRONLY,
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, DB_HASH, NULL);
if (!db) {
(void)fprintf(stderr,
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, DB_HASH, NULL);
if (!db) {
(void)fprintf(stderr,
usage()
{
(void)fprintf(stderr, "usage: kvm_mkdb [file]\n");
usage()
{
(void)fprintf(stderr, "usage: kvm_mkdb [file]\n");
-static char sccsid[] = "@(#)nlist.c 5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)nlist.c 5.6 (Berkeley) %G%";
#endif /* not lint */
#include <sys/param.h>
#endif /* not lint */
#include <sys/param.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
typedef struct nlist NLIST;
#define _strx n_un.n_strx
#define _name n_un.n_name
typedef struct nlist NLIST;
#define _strx n_un.n_strx
#define _name n_un.n_name
+static void badread __P((int, char *));
+static void badfmt __P((char *));
+
create_knlist(name, db)
char *name;
DB *db;
create_knlist(name, db)
char *name;
DB *db;
/* Read in exec structure. */
nr = read(fd, (char *)&ebuf, sizeof(struct exec));
if (nr != sizeof(struct exec))
/* Read in exec structure. */
nr = read(fd, (char *)&ebuf, sizeof(struct exec));
if (nr != sizeof(struct exec))
- badfmt(nr, "no exec header");
+ badfmt("no exec header");
/* Check magic number and symbol count. */
if (N_BADMAG(ebuf))
/* Check magic number and symbol count. */
if (N_BADMAG(ebuf))
if ((db->put)(db, &key, &data, 0))
error("put");
if ((db->put)(db, &key, &data, 0))
error("put");
- if (!strncmp((char *)key.data, VRS_SYM, sizeof(VRS_SYM) - 1)) {
- off_t cur_off, rel_off, vers_off;
-
- /* Offset relative to start of text image in VM. */
- rel_off = nbuf.n_value & ~KERNBASE;
-#ifdef tahoe
- /*
- * On tahoe, first 0x800 is reserved for communication
- * with the console processor.
- */
- rel_off -= 0x800;
+ if (strcmp((char *)key.data, VRS_SYM) == 0) {
+ off_t cur_off, voff;
+#ifndef KERNTEXTOFF
+#define KERNTEXTOFF KERNBASE
- * When loaded, data is rounded to next page cluster
- * after text, but not in file.
+ * 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.
- rel_off -= CLBYTES - (ebuf.a_text % CLBYTES);
- vers_off = N_TXTOFF(ebuf) + rel_off;
-
+ voff = nbuf.n_value - KERNTEXTOFF + N_TXTADDR(ebuf);
+ if ((nbuf.n_type & N_TYPE) == N_TEXT)
+ voff += N_TXTOFF(ebuf) - N_TXTADDR(ebuf);
+ else
+ voff += N_DATOFF(ebuf) - N_DATADDR(ebuf);
- if (fseek(fp, vers_off, SEEK_SET) == -1)
+ if (fseek(fp, voff, SEEK_SET) == -1)
badfmt("corrupted string table");
/*
badfmt("corrupted string table");
/*
badread(nr, p)
int nr;
char *p;
badread(nr, p)
int nr;
char *p;