valid shared library, dlgetfileinfo returns information about the library through the info parameter.

The info_size is the size in bytes of the info buffer.

The info is a pointer to a buffer allocated by the user program. The dynamic loader fills this buffer with file information.

A dlfileinfo structure has the following members:

struct dlfileinfo {

size_t text_size; size_t data_size; char *filename;

}

The text_size is the size in bytes of a shared library's text segment.

The data_size is the size in bytes of a shared library's data segment.

The filename is the path to the shared library. This path may be passed to a subsequent dlopen or dlopene call to avoid searching for the library a second time. The caller of dlgetfileinfo must copy the value of filename to insure that it is not corrupted. Examples The following example illustrates the use of dlgetfileinfo to allocate memory for mapping a shared library's data segment. For simplicity, error checking has been omitted.

#include <dlfcn.h> #include <string.h>

/* allocate_data is a user-supplied routine that allocates a

*memory buffer of at least "data_size" bytes and returns

*a pointer to the buffer.

*/

extern char *allocate_data(size_t data_size);

int main()

{

 

void

*handle;

 

int

status;

 

char

*pathname;

 

struct

dlfileinfo

info;

struct

dlopen_opts opts;

/* Locate library

and get file information */

status

= dlgetfileinfo("mylib.so", sizeof(info), &info);

if (status == 0) {

/* Make a copy of the library pathname returned by

*dlgetfileinfo().

*/

pathname = strdup(info.filename); /* Allocate data segment */

opts.data_addr = allocate_data(info.data_size); /* Not preallocating text segment */ opts.text_addr = 0;

/* Set dlopen() flags to indicate the data segment

*has been preallocated.

*/

opts.flags = RTLD_EXT_DATA_ADDR:

/* Call dlopene() to load the library using the path

*where dlgetfileinfo found the library and the

*preallocated memory buffer for mapping the library

*data segment.

*/

handle = dlopene(pathname, RTLD_LAZY, &opts); /* Remove copy of library pathname */ free(pathname);

/* Insert code here to use library */ /* Close library */

status = dlclose(handle);

/* Insert code here to free storage allocated by

156 Shared Library Management Routines