2 .\" Copyright (c) 2009, Sun Microsystems,
3 .\" Inc. All Rights Reserved.
4 .\" 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.
5 .\" 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.
6 .\" 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]
7 .TH DLINFO 3C "Feb 4, 2009"
9 dlinfo \- dynamic load information
18 \fBint\fR \fBdlinfo\fR(\fBvoid *\fR\fIhandle\fR, \fBint\fR \fIrequest\fR, \fBvoid *\fR\fIp\fR);
24 The \fBdlinfo()\fR function sets or extracts information from the runtime
25 linker \fBld.so.1\fR(1). This function is loosely modeled after the
26 \fBioctl\fR(2) function. The \fIrequest\fR argument and a third argument of
27 varying type are passed to \fBdlinfo()\fR. The action taken by \fBdlinfo()\fR
28 depends on the value of the \fIrequest\fR that is provided.
31 The \fIhandle\fR argument is either the value that is returned from a
32 \fBdlopen\fR(3C) or \fBdlmopen()\fR call, or the special handle
33 \fBRTLD_SELF\fR. A \fIhandle\fR argument is required for all requests except
34 \fBRTLD_DI_CONFIGADDR\fR, \fBRTLD_DI_GETSIGNAL\fR, and \fBRTLD_DI_SETSIGNAL\fR.
35 If \fIhandle\fR is the value that is returned from a \fBdlopen()\fR or
36 \fBdlmopen()\fR call, the information returned by the \fBdlinfo()\fR call
37 pertains to the specified object. If \fIhandle\fR is the special handle
38 \fBRTLD_SELF\fR, the information returned by the \fBdlinfo()\fR call pertains
42 The \fIrequest\fR argument can take the following values:
46 \fB\fBRTLD_DI_ARGSINFO\fR\fR
50 Obtain process argument information. The \fIp\fR argument is a pointer
51 (\fBDl_argsinfo_t *\fR\fIp\fR). The following elements from this structure are
59 The number of arguments passed to the process.
68 The argument array passed to the process.
77 The active environment variable array that is available to the process. This
78 element initially points to the environment variable array that is made
79 available to \fBexec\fR(2). This element can be updated should an alternative
80 environment be established by the process. See \fBputenv\fR(3C).
89 The auxiliary vector array passed to the process.
92 A process can be established from executing the runtime linker directly from
93 the command line. See \fBld.so.1\fR(1). The \fBDl_argsinfo_t\fR information
94 reflects the information that is made available to the application regardless
95 of how the runtime linker has been invoked.
101 \fB\fBRTLD_DI_CONFIGADDR\fR\fR
105 Obtain the configuration file information. The \fIp\fR argument is a
106 \fBDl_info_t\fR pointer (\fBDl_info_t *\fR\fIp\fR). The following elements from
107 this structure are initialized:
111 \fB\fBdli_fname\fR\fR
114 The full name of the configuration file.
120 \fB\fBdli_fbase\fR\fR
123 The base address of the configuration file loaded into memory.
131 \fB\fBRTLD_DI_LINKMAP\fR\fR
135 Obtain the \fBLink_map\fR for the \fIhandle\fR that is specified. The \fIp\fR
136 argument points to a \fBLink_map\fR pointer (\fBLink_map **\fR\fIp\fR). The
137 actual storage for the \fBLink_map\fR structure is maintained by \fBld.so.1\fR.
139 The \fBLink_map\fR structure includes the following members:
143 unsigned long l_addr; /* base address */
144 char *l_name; /* object name */
145 Elf32_Dyn *l_ld; /* .dynamic section */
146 Link_map *l_next; /* next link object */
147 Link_map *l_prev; /* previous link object */
148 char *l_refname; /* filter reference name */
158 The base address of the object loaded into memory.
167 The full name of the loaded object. This full name is the filename of the
168 object as referenced by \fBld.so.1\fR.
177 Points to the \fBSHT_DYNAMIC\fR structure.
186 The next \fBLink_map\fR on the link-map list. Other objects on the same
187 link-map list as the current object can be examined by following the
188 \fBl_next\fR and \fBl_prev\fR members.
197 The previous \fBLink_map\fR on the link-map list.
203 \fB\fBl_refname\fR\fR
206 If the object that is referenced is a \fIfilter\fR, this member points to the
207 name of the object being filtered. If the object is not a \fIfilter\fR, this
208 member is \fB0\fR. See the \fILinker and Libraries Guide\fR.
216 \fB\fBRTLD_DI_LMID\fR\fR
220 Obtain the \fBID\fR for the link-map list upon which the \fIhandle\fR is
221 loaded. The \fIp\fR argument is a \fBLmid_t\fR pointer (\fBLmid_t *\fR\fIp\fR).
227 \fB\fBRTLD_DI_MMAPCNT\fR\fR
231 Determine the number of segment mappings for the \fIhandle\fR that is
232 specified, for use in a \fBRTLD_DI_MMAPS\fR request. The \fIp\fR argument is a
233 \fBuint_t\fR pointer (\fBuint_t *\fR\fIp\fR). On return from a
234 \fBRTLD_DI_MMAPCNT\fR request, the \fBuint_t\fR value that is pointed to by
235 \fIp\fR contains the number of segment mappings that the associated object
238 To obtain the complete mapping information for an object, a
239 \fBmmapobj_result_t\fR array for \fBRTLD_DI_MMAPCNT\fR entries must be
240 provided. This array is assigned to the \fBdlm_maps\fR member, and the number
241 of entries available in the arry are assigned to the \fBdlm_acnt\fR member.
242 This initialized structure is then passed to a \fBRTLD_DI_MMAPS\fR request. See
249 \fB\fBRTLD_DI_MMAPS\fR\fR
253 Obtain segment mapping information for the \fIhandle\fR that is specified. The
254 \fIp\fR argument is a \fBDl_mapinfo_t\fR pointer (\fBDl_mapinfo_t *\fR\fIp\fR).
255 This structure can be initialized from the mapping count obtained from a
256 previous \fBRTLD_DI_MMAPCNT\fR request.
258 Segment mapping information is provided in an array of \fBmmapobj_result_t\fR
259 structures that originate from the \fBmmapobj\fR(2) of the associated object.
260 The \fBdlm_acnt\fR member, typically initialized from a previous
261 \fBRTLD_DI_MMAPCNT\fR request, indicates the number of enteries in a
262 \fBmmapobj_result_t\fR array. This array is assigned to the \fBdlm_maps\fR
263 member. This initialized structure is then passed to a \fBRTLD_DI_MMAPS\fR
264 request, where the segment mapping information is copied to the
265 \fBmmapobj_result_t\fR array. The \fBdlm_rcnt\fR member indicates the number of
266 \fBmmapobj_result_t\fR element entries that are returned. See \fBEXAMPLES\fR.
272 \fB\fBRTLD_DI_SERINFO\fR\fR
276 Obtain the library search paths for the \fIhandle\fR that is specified. The
277 \fIp\fR argument is a \fBDl_serinfo_t\fR pointer (\fBDl_serinfo_t *\fR\fIp\fR).
278 A user must first initialize the \fBDl_serinfo_t\fR structure with a
279 \fBRTLD_DI_SERINFOSIZE\fR request. See \fBEXAMPLES\fR.
281 The returned \fBDl_serinfo_t\fR structure contains \fBdls_cnt\fR
282 \fBDl_serpath_t\fR entries. Each entry's \fBdlp_name\fR member points to the
283 search path. The corresponding \fBdlp_info\fR member contains one of more flags
284 indicating the origin of the path. See the \fBLA_SER_*\fR flags that are
285 defined in <\fBlink.h\fR>.
291 \fB\fBRTLD_DI_SERINFOSIZE\fR\fR
295 Initialize a \fBDl_serinfo_t\fR structure for the \fIhandle\fR that is
296 specified, for use in a \fBRTLD_DI_SERINFO\fR request. Both the \fBdls_cnt\fR
297 and \fBdls_size\fR members are returned. The \fBdls_cnt\fR member indicates the
298 number of search paths that are applicable to the \fIhandle\fR. The
299 \fBdls_size\fR member indicates the total size of a \fBDl_serinfo_t\fR buffer
300 required to hold \fBdls_cnt\fR \fBDl_serpath_t\fR entries and the associated
301 search path strings. The \fIp\fR argument is a \fBDl_serinfo_t\fR pointer
302 (\fBDl_serinfo_t *\fR\fIp\fR).
304 To obtain the complete path information, a new \fBDl_serinfo_t\fR buffer of
305 size \fBdls_size\fR should be allocated. This new buffer should be initialized
306 with the \fBdls_cnt\fR and \fBdls_size\fR entries. The initialized buffer is
307 then passed to a \fBRTLD_DI_SERINFO\fR request. See \fBEXAMPLES\fR.
313 \fB\fBRTLD_DI_ORIGIN\fR\fR
317 Obtain the origin of the dynamic object that is associated with the
318 \fIhandle\fR. The \fIp\fR argument is a \fBchar\fR pointer (\fBchar
319 *\fR\fIp\fR). The \fBdirname\fR(3C) of the associated object's
320 \fBrealpath\fR(3C), which can be no larger than {\fBPATH_MAX\fR}, is copied to
327 \fB\fBRTLD_DI_GETSIGNAL\fR\fR
331 Obtain the numeric signal number used by the runtime linker to kill the process
332 in the event of a fatal runtime error. The \fIp\fR argument is an \fBint\fR
333 pointer (\fBint *\fR\fIp\fR). The signal number is copied to the pointer
336 By default, the signal used by the runtime linker to terminate a process is
337 \fBSIGKILL\fR. See \fBthr_kill\fR(3C). This default can be changed by calling
338 \fBdlinfo()\fR with \fBRTLD_DI_SETSIGNAL\fR or by setting the environment
339 variable \fBLD_SIGNAL\fR. See \fBld.so.1\fR(1).
345 \fB\fBRTLD_DI_SETSIGNAL\fR\fR
349 Provide a numeric signal number used by the runtime linker to kill the process
350 in the event of a fatal runtime error. The \fIp\fR argument is an \fBint\fR
351 pointer (\fBint *\fR\fIp\fR). The value pointed to by \fIp\fR is established as
352 the terminating signal value.
354 The current signal number used by the runtime linker to terminate a process can
355 be obtained from \fBdlinfo()\fR using \fBRTLD_DI_GETSIGNAL\fR. Use of the
356 \fBRTLD_DI_SETSIGNAL\fR option is equivalent to setting the environment
357 variable \fBLD_SIGNAL\fR. See \fBld.so.1\fR(1).
363 The \fBdlinfo()\fR function returns \(mi1 if the \fIrequest\fR is invalid, the
364 parameter \fIp\fR is \fINULL\fR, or the \fBDl_serinfo_t\fR structure is
365 uninitialized for a \fBRTLD_DI_SERINFO\fR request. \fBdlinfo()\fR also returns
366 \(mi1 if the \fIhandle\fR argument does not refer to a valid object opened by
367 \fBdlopen()\fR, or is not the special handle \fBRTLD_SELF\fR. Detailed
368 diagnostic information is available with \fBdlerror\fR(3C).
371 \fBExample 1 \fRUse \fBdlinfo()\fR to obtain library search paths.
374 The following example demonstrates how a dynamic object can inspect the library
375 search paths that would be used to locate a simple filename with
376 \fBdlopen()\fR. For simplicity, error checking has been omitted.
381 Dl_serinfo_t _info, *info = &_info;
385 /* determine search path count and required buffer size */
386 dlinfo(RTLD_SELF, RTLD_DI_SERINFOSIZE, info);
388 /* allocate new buffer and initialize */
389 info = malloc(_info.dls_size);
390 info->dls_size = _info.dls_size;
391 info->dls_cnt = _info.dls_cnt;
393 /* obtain sarch path information */
394 dlinfo(RTLD_SELF, RTLD_DI_SERINFO, info);
396 path = &info->dls_serpath[0];
398 for (cnt = 1; cnt <= info->dls_cnt; cnt++, path++) {
399 (void) printf("%2d: %s\en", cnt, path->dls_name);
405 \fBExample 2 \fRUse \fBdlinfo()\fR to obtain segment information.
408 The following example demonstrates how a dynamic object can inspect its segment
409 mapping information. For simplicity, error checking has been omitted
417 /* determine the number of segment mappings */
418 dlinfo(RTLD_SELF, RTLD_DI_MMAPCNT, &mi.dlm_acnt);
420 /* allocate the appropriate mapping array */
421 mi.dlm_maps = malloc(mi.dlm_acnt * sizeof (mmapobj_result_t));
423 /* obtain the mapping information */
424 dlinfo(RTLD_SELF, RTLD_DI_MMAPS, &mi);
426 for (cnt = 0; cnt < mi.dlm_rcnt; cnt++) {
427 (void) printf("addr=%x - memory size=%x\en",
428 mi.dlm_maps[cnt].mr_addr, mi.dlm_maps[cnt].mr_msize);
436 The \fBdlinfo()\fR function is one of a family of functions that give the user
437 direct access to the dynamic linking facilities. These facilities are available
438 to dynamically-linked processes only. See the \fILinker and Libraries Guide\fR.
442 See \fBattributes\fR(5) for descriptions of the following attributes:
450 ATTRIBUTE TYPE ATTRIBUTE VALUE
452 Interface Stability Stable
460 \fBld\fR(1), \fBld.so.1\fR(1), \fBexec\fR(2), \fBioctl\fR(2), \fBmmapobj\fR(2),
461 \fBdirname\fR(3C), \fBdlclose\fR(3C), \fBdldump\fR(3C), \fBdlerror\fR(3C),
462 \fBdlopen\fR(3C), \fBdlsym\fR(3C), \fBputenv\fR(3C), \fBrealpath\fR(3C),
463 \fBthr_kill\fR(3C), \fBattributes\fR(5)
466 \fILinker and Libraries Guide\fR