xref: /illumos-gate/usr/src/cmd/mdb/common/kmdb/kctl/kctl_auxv.c (revision 8aafd47d0dbabbca4365c9565fbe0e051e7346dd)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <kmdb/kctl/kctl.h>
27 
28 #include <sys/modctl.h>
29 #include <sys/bootconf.h>
30 #include <sys/kobj.h>
31 #include <sys/kobj_impl.h>
32 #include <sys/kmdb.h>
33 
34 static uintptr_t
35 kctl_lookup_by_name(char *modname, char *symname)
36 {
37 	struct modctl *mctl;
38 	Sym *ksym;
39 	uintptr_t addr;
40 
41 	if ((mctl = mod_hold_by_name(modname)) == NULL)
42 		return (0);
43 	if ((ksym = kobj_lookup_all(mctl->mod_mp, symname, 1)) == NULL) {
44 		mod_release_mod(mctl);
45 		return (0);
46 	}
47 
48 	addr = ksym->st_value;
49 
50 	mod_release_mod(mctl);
51 
52 	return (addr);
53 }
54 
55 static uintptr_t
56 kctl_boot_lookup_by_name(char *modname, char *symname)
57 {
58 	struct modctl *mctl;
59 	Sym *ksym;
60 
61 	if ((mctl = kobj_boot_mod_lookup(modname)) == NULL)
62 		return (0);
63 
64 	if ((ksym = kobj_lookup_all(mctl->mod_mp, symname, 1)) == NULL)
65 		return (0);
66 
67 	return (ksym->st_value);
68 }
69 
70 void
71 kctl_auxv_init(kmdb_auxv_t *kav, const char *cfg, const char **argv, void *romp)
72 {
73 	bzero(kav, sizeof (kmdb_auxv_t));
74 	kav->kav_dseg = kctl.kctl_dseg;
75 	kav->kav_dseg_size = kctl.kctl_dseg_size;
76 	kav->kav_pagesize = PAGESIZE;
77 	kav->kav_ncpu = NCPU;
78 	kav->kav_kdi = &kobj_kdi;
79 	kav->kav_wrintr_fire = kctl_wrintr_fire;
80 
81 	kav->kav_config = cfg;
82 	kav->kav_argv = argv;
83 	kav->kav_modpath = kobj_module_path;
84 
85 	kctl_dprintf("kctl_auxv_init: modpath '%s'", kav->kav_modpath);
86 
87 	if (kctl.kctl_boot_loaded) {
88 		kav->kav_lookup_by_name = kctl_boot_lookup_by_name;
89 		kav->kav_flags |= KMDB_AUXV_FL_NOUNLOAD;
90 	} else
91 		kav->kav_lookup_by_name = kctl_lookup_by_name;
92 
93 	if (kctl.kctl_flags & KMDB_F_TRAP_NOSWITCH)
94 		kav->kav_flags |= KMDB_AUXV_FL_NOTRPSWTCH;
95 
96 	kctl_auxv_init_isadep(kav, romp); /* can modify anything in kav */
97 }
98 
99 void
100 kctl_auxv_fini(kmdb_auxv_t *kav)
101 {
102 	kctl_auxv_fini_isadep(kav);
103 }
104