if (shl_findsym(&lib_handle, DRAW2D, TYPE_PROCEDURE, (void *) &draw2d)) perror("shl_findsym: error finding function draw2d"), exit(1);
if (shl_findsym(&lib_handle, MAXX, TYPE_DATA, (void *) &maxX)) perror("shl_findsym: error finding data maxX"), exit(1);
if (shl_findsym(&lib_handle, MAXY, TYPE_DATA, (void *) &maxY)) perror("shl_findsym: error finding data maxY"), exit(1);
/*
*Using the routines, draw a line from (0,0) to (maxX,maxY):
*/
(*gopen)(); | /* open the graphics device | */ |
(*move2d)(0,0); | /* move to pixel 0,0 | */ |
(*draw2d)(*maxX,*maxY); | /* draw line to maxX,maxY pixel | */ |
(*gclose)(); | /* close the graphics device | */ |
}
Shown below is the compile line for this program, along with the commands to set SHLPATH appropriately before running the program. SHLPATH is declared and used by load_lib(), defined in “The shl_load Routine” (page 168) and cxxshl_load Routines example. Notice that load_lib() is compiled here along with this program. Finally, this example assumes you have created a graphics library, libgrphdd.so:
$ cc
$ export SHLPATH $ drawline
The shl_get and shl_get_r Routines
The shl_get and shl_get_r routines obtain information on the currently loaded libraries.
Syntax
int shl_get( int index,
struct shl_descriptor **desc )
Parameters
index | Specifies an ordinal number of the shared library in the process. For libraries loaded implicitly |
| ||
| (at startup time), index is the ordinal number of the library as it appeared on the command line. |
| ||
| For example, if | libc was the first library specified on the ld command line, then libc has an |
| |
| index of 1. For explicitly loaded libraries, index corresponds to the order in which the libraries |
| ||
| were loaded, starting after the ordinal number of the last implicitly loaded library. Two index |
| ||
| values have special meaning: |
| ||
|
|
|
|
|
|
| Refers to the dynamic loader (dld.so) |
| |
|
|
|
|
|
|
| Refers to the main program itself. |
| |
|
|
|
| |
| A shared library's index can be modified during program execution by either of the following |
| ||
| events: |
|
|
|
|
|
|
| |
| • The program loads a shared library with the BIND_FIRST modifier to shl_load. This |
| ||
| increments all the shared library indexes by one. |
| ||
| • The program unloads a shared library with shl_unload. Any libraries following the unloaded |
| ||
| library have their index decremented by one. |
| ||
|
|
|
| |
desc | Returns a pointer to a statically allocated buffer (struct shl_descriptor **) containing a |
| ||
| shared library descriptor. The structure contains these important fields: |
| ||
|
|
|
|
|
| tstart |
| The start address (unsigned long) of the shared library text segment. |
|
|
|
|
|
|
| tend |
| The end address (unsigned long) of the shared library text segment. |
|
|
|
|
|
|
| dstart |
| The start address (unsigned long) of the shared library data segment. |
|
|
|
|
|
|
| dend |
| The end address (unsigned long) of the shared library bss segment. The data |
|
|
|
| and bss segments together form a contiguous memory block starting at dstart |
|
|
|
| and ending at dend. |
|
|
|
|
|
|
The shl_load Shared Library Management Routines 175