nlist.c revision 1.13 1 /*-
2 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
3 * Copyright (c) 1990, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 #ifndef lint
36 /*static char sccsid[] = "from: @(#)nlist.c 8.1 (Berkeley) 6/6/93";*/
37 static char *rcsid = "$Id: nlist.c,v 1.13 1996/09/29 02:19:57 cgd Exp $";
38 #endif /* not lint */
39
40 #include <sys/param.h>
41
42 #include <a.out.h>
43 #include <db.h>
44 #include <err.h>
45 #include <errno.h>
46 #include <fcntl.h>
47 #include <kvm.h>
48 #include <limits.h>
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <string.h>
52 #include <unistd.h>
53
54 #include "extern.h"
55
56 static struct {
57 int (*knlist) __P((const char *, DB *));
58 } knlist_fmts[] = {
59 #ifdef NLIST_AOUT
60 { create_knlist_aout },
61 #endif
62 #ifdef NLIST_ECOFF
63 { create_knlist_ecoff },
64 #endif
65 #ifdef NLIST_ELF32
66 { create_knlist_elf32 },
67 #endif
68 #ifdef NLIST_ELF64
69 { create_knlist_elf64 },
70 #endif
71 };
72
73 void
74 create_knlist(name, db)
75 const char *name;
76 DB *db;
77 {
78 int i;
79
80 for (i = 0; i < sizeof(knlist_fmts) / sizeof(knlist_fmts[0]); i++)
81 if ((*knlist_fmts[i].knlist)(name, db) != -1)
82 return;
83 warnx("%s: file format not recognized", name);
84 punt();
85 }
86
87 /*
88 * XXX: Using this value from machine/param.h introduces a
89 * XXX: machine dependency on this program, so /usr can not
90 * XXX: be shared between (i.e.) several m68k machines.
91 * Instead of compiling in KERNTEXTOFF or KERNBASE, try to
92 * determine the text start address from a standard symbol.
93 * For backward compatibility, use the old compiled-in way
94 * when the standard symbol name is not found.
95 */
96 #ifndef KERNTEXTOFF
97 #define KERNTEXTOFF KERNBASE
98 #endif
99
100 u_long
101 get_kerntext(name)
102 const char *name;
103 {
104 struct nlist nl[2];
105
106 bzero((caddr_t)nl, sizeof(nl));
107 nl[0].n_un.n_name = "_kernel_text";
108
109 if (nlist(name, nl) != 0)
110 return (KERNTEXTOFF);
111
112 return (nl[0].n_value);
113 }
114