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 (c) 1994, by Sun Microsytems, Inc.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * Interfaces that deal with loadobjects (shared objects) in target
38 #include <sys/procfs.h>
41 #include "prb_proc_int.h"
45 * iterate over all loadobjects calling the callback function "obj_func"
46 * for every loadobject with information about the loadobject.
49 prb_loadobj_iter(prb_proc_ctl_t
*proc_p
, prb_loadobj_f
*obj_func
, void *cd
)
56 prb_loadobj_t loadobj
;
59 DBG_TNF_PROBE_0(prb_loadobj_iter_start
, "libtnfctl",
60 "start prb_loadobj_iter; sunw%verbosity 1");
62 if (proc_p
->dbgaddr
== 0) {
63 DBG((void) fprintf(stderr
,
64 "prb_loadobj_iter: dbgaddr not set\n"));
65 return (PRB_STATUS_BADARG
);
68 prbstat
= prb_proc_read(proc_p
, proc_p
->dbgaddr
, &dentry
,
70 if (prbstat
|| !dentry
.d_un
.d_ptr
) {
71 DBG((void) fprintf(stderr
,
72 "prb_lmap_update: error in d_un.d_ptr\n"));
75 /* read in the debug struct that it points to */
76 prbstat
= prb_proc_read(proc_p
, dentry
.d_un
.d_ptr
,
77 &r_dbg
, sizeof (r_dbg
));
81 DBG_TNF_PROBE_1(prb_loadobj_iter_1
, "libtnfctl", "sunw%verbosity 1",
82 tnf_string
, link_map_state
,
83 (r_dbg
.r_state
== RT_CONSISTENT
) ? "RT_CONSISTENT" :
84 (r_dbg
.r_state
== RT_ADD
) ? "RT_ADD" : "RT_DELETE");
86 /* if the link map is not consistent, bail now */
87 if (r_dbg
.r_state
!= RT_CONSISTENT
)
88 return (PRB_STATUS_BADLMAPSTATE
);
90 lmap
.l_next
= NULL
; /* makes lint happy */
92 for (lmapaddr
= (uintptr_t) r_dbg
.r_map
; lmapaddr
;
93 lmapaddr
= (uintptr_t) lmap
.l_next
) {
95 prbstat
= prb_proc_read(proc_p
, lmapaddr
, &lmap
, sizeof (lmap
));
99 loadobj
.text_base
= lmap
.l_addr
;
100 loadobj
.data_base
= lmap
.l_addr
;
101 loadobj
.objname
= NULL
;
103 * client of this interface should deal with -1 for objfd,
104 * so no error checking is needed on this ioctl
106 loadobj
.objfd
= ioctl(proc_p
->procfd
, PIOCOPENM
, &lmap
.l_addr
);
108 (void) prb_proc_readstr(proc_p
, (uintptr_t) lmap
.l_name
,
110 retval
= obj_func(proc_p
, &loadobj
, cd
);
112 free((char *)loadobj
.objname
);
113 if (loadobj
.objfd
!= -1)
114 close(loadobj
.objfd
);
115 /* check for error */
117 return (PRB_STATUS_BADARG
);
120 DBG_TNF_PROBE_0(prb_loadobj_iter_end
, "libtnfctl",
121 "end prb_loadobj_iter; sunw%verbosity 1");
122 return (PRB_STATUS_OK
);
126 * Return a fd for the main executable and also the address of where
130 prb_mainobj_get(prb_proc_ctl_t
*proc_p
, int *objfd
, uintptr_t *baseaddr
)
136 procfd
= proc_p
->procfd
;
138 retfd
= ioctl(procfd
, PIOCOPENM
, 0);
142 DBG((void) fprintf(stderr
,
143 "prb_mainobj_get: PIOCOPENM failed: %s\n",
145 return (prb_status_map(errno
));
150 return (PRB_STATUS_OK
);