summaryrefslogtreecommitdiff
path: root/usr/src/cmd/mdb/common/kmdb/kctl/kctl_auxv.c
blob: 773a0887837a85ddf18ca3bd4bf11f3a84e660a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <kmdb/kctl/kctl.h>

#include <sys/modctl.h>
#include <sys/bootconf.h>
#include <sys/kobj.h>
#include <sys/kobj_impl.h>
#include <sys/kmdb.h>

static uintptr_t
kctl_lookup_by_name(char *modname, char *symname)
{
	struct modctl *mctl;
	Sym *ksym;
	uintptr_t addr;

	if ((mctl = mod_hold_by_name(modname)) == NULL)
		return (0);
	if ((ksym = kobj_lookup_all(mctl->mod_mp, symname, 1)) == NULL) {
		mod_release_mod(mctl);
		return (0);
	}

	addr = ksym->st_value;

	mod_release_mod(mctl);

	return (addr);
}

static uintptr_t
kctl_boot_lookup_by_name(char *modname, char *symname)
{
	struct modctl *mctl;
	Sym *ksym;

	if ((mctl = kobj_boot_mod_lookup(modname)) == NULL)
		return (0);

	if ((ksym = kobj_lookup_all(mctl->mod_mp, symname, 1)) == NULL)
		return (0);

	return (ksym->st_value);
}

void
kctl_auxv_init(kmdb_auxv_t *kav, const char *cfg, const char **argv, void *romp)
{
	bzero(kav, sizeof (kmdb_auxv_t));
	kav->kav_dseg = kctl.kctl_dseg;
	kav->kav_dseg_size = kctl.kctl_dseg_size;
	kav->kav_pagesize = PAGESIZE;
	kav->kav_ncpu = NCPU;
	kav->kav_kdi = &kobj_kdi;
	kav->kav_wrintr_fire = kctl_wrintr_fire;

	kav->kav_config = cfg;
	kav->kav_argv = argv;
	kav->kav_modpath = kobj_module_path;

	kctl_dprintf("kctl_auxv_init: modpath '%s'", kav->kav_modpath);

	if (kctl.kctl_boot_loaded) {
		kav->kav_lookup_by_name = kctl_boot_lookup_by_name;
		kav->kav_flags |= KMDB_AUXV_FL_NOUNLOAD;
	} else
		kav->kav_lookup_by_name = kctl_lookup_by_name;

	if (kctl.kctl_flags & KMDB_F_TRAP_NOSWITCH)
		kav->kav_flags |= KMDB_AUXV_FL_NOTRPSWTCH;

	kctl_auxv_init_isadep(kav, romp); /* can modify anything in kav */
}

void
kctl_auxv_fini(kmdb_auxv_t *kav)
{
	kctl_auxv_fini_isadep(kav);
}