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.
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.
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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 #include <sys/modctl.h>
33 #include <kmdb/kmdb_module.h>
34 #include <mdb/mdb_debug.h>
35 #include <mdb/mdb_gelf.h>
36 #include <mdb/mdb_string.h>
40 * kmdb libdl-style interface for the manipulation of dmods.
43 static char *dl_errstr
;
45 static kmdb_modctl_t
*
46 dl_name2ctl(const char *pathname
)
50 if ((v
= mdb_nv_lookup(&mdb
.m_dmodctl
, strbasename(pathname
))) ==
54 return ((kmdb_modctl_t
*)MDB_NV_COOKIE(v
));
59 dlmopen(Lmid_t lmid
, const char *pathname
, int mode
)
63 if ((kmc
= dl_name2ctl(pathname
)) == NULL
) {
64 dl_errstr
= "unregistered module";
78 kmdb_modctl_t
*kmc
= dlp
;
82 ASSERT(kmc
->kmc_dlrefcnt
> 0);
83 if (--kmc
->kmc_dlrefcnt
> 0)
92 char *str
= dl_errstr
;
100 dl_findsym(kmdb_modctl_t
*kmc
, const char *name
)
105 if (mdb_gelf_symtab_lookup_by_name(kmc
->kmc_symtab
, name
, &sym
,
109 return ((void *)(uintptr_t)sym
.st_value
);
114 dlsym(void *dlp
, const char *name
)
116 kmdb_modctl_t
*kmc
= dlp
;
120 switch ((uintptr_t)dlp
) {
121 case (uintptr_t)RTLD_NEXT
:
122 mdb_nv_rewind(&mdb
.m_dmodctl
);
123 while ((v
= mdb_nv_advance(&mdb
.m_dmodctl
)) != NULL
) {
124 if ((addr
= dl_findsym(MDB_NV_COOKIE(v
), name
)) != NULL
)
129 case (uintptr_t)RTLD_DEFAULT
:
130 case (uintptr_t)RTLD_SELF
:
131 dl_errstr
= "invalid handle";
135 addr
= dl_findsym(kmc
, name
);
138 dl_errstr
= (addr
== NULL
) ? "symbol not found" : NULL
;
143 #pragma weak _dladdr1 = dladdr1
146 dladdr1(void *address
, Dl_info
*dlip
, void **info
, int flags
)
149 * umem uses this for debugging information. We'll pretend to fail.