handle

The shared library's handle (type shl_t).

filename A character array containing the library's path name as specified at link time or at explicit load time.

initializer A pointer to the shared library's initializer routine (see Initializers for Shared Libraries. It is NULL if there is no initializer. This field is useful for calling the initializer if it was disabled by the BIND_NOSTART flag to shl_load.

If the shared library has multiple initializers, this field is also set to NULL. Multiple initializers can be found with shl_getsymbols, described later in this chapter.

This buffer is statically allocated. Therefore, if a program intends to use any of the members of the structure, the program must make a copy of the structure before the next call to shl_get. Otherwise, shl_get overwrites the static buffer when called again.

Return Value

If successful, shl_get returns an integer value 0. If the index value exceeds the number of currently loaded libraries, shl_get returns -1 and sets errno to EINVAL.

Description

To obtain information on currently loaded libraries, use the shl_get function. If you are programming in a threaded environment, use the thread-safe version shl_get_r which is the same as shl_get in all other respects. (See Programming with Threads on HP-UXfor more information about threads.)

Other than obtaining interesting information, this routine is of little use to most programmers. A typical use may be to display the names and starting/ending address of all shared libraries in a process's virtual memory address space.

Example

The function show_loaded_libs shown below displays the name and start and end address of the text and data/bss segments the library occupies in a process's virtual address space.

show_loaded_libs - Display Library Information

#include

<stdio.h>

/* contains standard I/O defs

*/

 

#include

<dl.h>

/* contains shared library type defs

*/

void

show_loaded_libs(void)

 

 

{

 

 

 

 

int

idx;

 

 

 

struct

shl_descriptor

*desc;

 

 

printf("SUMMARY of currently loaded libraries:\n"); printf("%-25s %10s %10s %10s %10s\n",

"___library___", "_tstart_", "__tend__", "_dstart_", "__dend__");

idx = 0;

for (idx = 0; shl_get(idx, &desc) != -1; idx++) printf("%-25s %#10lx %#10lx %#10lx %#10lx\n",

desc->filename, desc->tstart, desc->tend, desc->dstart, desc->dend);

}

Calling this function from a C program compiled with shared libc and libdld produced the following output:

SUMMARY of currently loaded libraries:

 

 

 

___library___

_tstart_

__tend__

_dstart_

__dend__

./a.out

0x1000

0x1918

0x40000000

0x40000200

/usr/lib/libdld.so

0x800ac800

0x800ad000

0x6df62800

0x6df63000

/usr/lib/libc.so

0x80003800

0x80091000

0x6df63000

0x6df85000

176 Shared Library Management Routines