xref: /titanic_50/usr/src/uts/common/krtld/kobj_lm.c (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * krtld link maps
31  */
32 
33 #include <sys/kobj.h>
34 #include <sys/kobj_impl.h>
35 #include <sys/modctl.h>
36 #include <sys/types.h>
37 
38 #pragma weak primaries = kobj_linkmaps	/* backwards compatibility */
39 struct modctl_list *kobj_linkmaps[] = {
40 	NULL,
41 	NULL,
42 	NULL
43 };
44 
45 #define	KOBJ_LM_NENT	(sizeof (kobj_linkmaps) / sizeof (struct modctl *) - 1)
46 
47 struct modctl_list *
48 kobj_lm_lookup(int lmid)
49 {
50 	if (lmid < 0 || lmid >= KOBJ_LM_NENT)
51 		return (NULL);
52 
53 	return (kobj_linkmaps[lmid]);
54 }
55 
56 void
57 kobj_lm_append(int lmid, struct modctl *modp)
58 {
59 	struct modctl_list **lpp, *lp;
60 
61 	if (lmid < 0 || lmid >= KOBJ_LM_NENT)
62 		return;
63 
64 	lpp = &kobj_linkmaps[lmid];
65 
66 	lp = kobj_zalloc(sizeof (struct modctl_list), KM_WAIT);
67 	lp->modl_modp = modp;
68 
69 	if (*lpp == NULL) {
70 		*lpp = lp;
71 	} else {
72 		struct modctl_list *last;
73 
74 		for (last = *lpp; last->modl_next != NULL;
75 		    last = last->modl_next)
76 			/* */;
77 
78 		last->modl_next = lp;
79 	}
80 }
81 
82 void
83 kobj_lm_dump(int lmid)
84 {
85 	struct modctl_list *lp;
86 
87 	for (lp = kobj_lm_lookup(lmid); lp; lp = lp->modl_next) {
88 		struct module *mp = lp->modl_modp->mod_mp;
89 
90 		_kobj_printf(ops, "module %s: ", mp->filename);
91 		_kobj_printf(ops, "text at [0x%p, ", mp->text);
92 		_kobj_printf(ops, "0x%lx] ", (uintptr_t)mp->text +
93 		    mp->text_size - 1);
94 		_kobj_printf(ops, "data at 0x%p\n", mp->data);
95 	}
96 }
97