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
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.
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]
23 * Copyright 2000-2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <mdb/mdb_modapi.h>
30 #include <sys/machelf.h>
35 #include "proc_kludges.h"
37 typedef struct prockuldge_mappings
{
38 struct ps_prochandle
*pkm_Pr
;
45 prmap_t
*pkm_mappings
;
48 prmap_t
*pkm_old_mappings
;
49 } prockludge_mappings_t
;
53 prockludge_mappings_iter(prockludge_mappings_t
*pkm
, const prmap_t
*pmp
,
54 const char *object_name
)
56 if (pkm
->pkm_count
>= pkm
->pkm_max
) {
57 int s
= pkm
->pkm_max
? pkm
->pkm_max
* 2 : 16;
59 pkm
->pkm_old_max
= pkm
->pkm_max
;
60 pkm
->pkm_old_mappings
= pkm
->pkm_mappings
;
62 pkm
->pkm_mappings
= mdb_alloc(sizeof (prmap_t
) * s
, UM_SLEEP
);
64 bcopy(pkm
->pkm_old_mappings
, pkm
->pkm_mappings
,
65 sizeof (prmap_t
) * pkm
->pkm_old_max
);
67 mdb_free(pkm
->pkm_old_mappings
,
68 sizeof (prmap_t
) * pkm
->pkm_old_max
);
70 pkm
->pkm_old_mappings
= NULL
;
73 bcopy(pmp
, &pkm
->pkm_mappings
[pkm
->pkm_count
++], sizeof (prmap_t
));
79 prockludge_mappings_walk_init(mdb_walk_state_t
*mws
)
81 struct ps_prochandle
*Pr
;
84 prockludge_mappings_t
*pkm
;
86 if (mdb_get_xdata("pshandle", &Pr
, sizeof (Pr
)) == -1) {
87 mdb_warn("couldn't read pshandle xdata");
91 pkm
= mdb_zalloc(sizeof (prockludge_mappings_t
), UM_SLEEP
);
95 rc
= Pmapping_iter(Pr
, (proc_map_f
*)prockludge_mappings_iter
, pkm
);
97 mdb_warn("Pmapping_iter failed");
99 prockludge_mappings_walk_fini(mws
);
106 prockludge_mappings_walk_step(mdb_walk_state_t
*wsp
)
108 prockludge_mappings_t
*pkm
= wsp
->walk_data
;
111 if (pkm
->pkm_idx
>= pkm
->pkm_count
)
114 status
= wsp
->walk_callback(0, &pkm
->pkm_mappings
[pkm
->pkm_idx
++],
121 prockludge_mappings_walk_fini(mdb_walk_state_t
*wsp
)
123 prockludge_mappings_t
*pkm
= wsp
->walk_data
;
125 if (pkm
->pkm_old_mappings
!= NULL
) {
126 mdb_free(pkm
->pkm_old_mappings
,
127 sizeof (prmap_t
) * pkm
->pkm_old_max
);
129 if (pkm
->pkm_mappings
&&
130 pkm
->pkm_mappings
!= pkm
->pkm_old_mappings
) {
131 mdb_free(pkm
->pkm_mappings
,
132 sizeof (prmap_t
) * pkm
->pkm_max
);
134 mdb_free(pkm
, sizeof (prockludge_mappings_t
));
138 static int add_count
= 0;
141 prockludge_add_walkers(void)
145 if (add_count
++ == 0) {
146 w
.walk_name
= KLUDGE_MAPWALK_NAME
;
147 w
.walk_descr
= "kludge: walk the process' prmap_ts";
148 w
.walk_init
= prockludge_mappings_walk_init
;
149 w
.walk_step
= prockludge_mappings_walk_step
;
150 w
.walk_fini
= prockludge_mappings_walk_fini
;
151 w
.walk_init_arg
= NULL
;
153 if (mdb_add_walker(&w
) == -1) {
154 mdb_warn("unable to add walker "KLUDGE_MAPWALK_NAME
);
160 prockludge_remove_walkers(void)
162 if (--add_count
== 0) {
163 mdb_remove_walker(KLUDGE_MAPWALK_NAME
);