24.05.2014 Views

AIX Version 4.3 Differences Guide

AIX Version 4.3 Differences Guide

AIX Version 4.3 Differences Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4.2.3.1 dlopen()<br />

The dlopen() function is used to dynamically load a module into a process’<br />

address space. The value returned by dlopen() is a handle that can be passed to<br />

dlsym() to look up symbols in the loaded module. The handle can also be passed<br />

to dlclose() to allow the module to be removed from the address space.<br />

Synopsis: #include void *dlopen(const char *pathname, int flags);<br />

If the is /unix, dlopen() returns a handle that can be used to look up<br />

symbols in the current kernel image, including all kernel extensions. If <br />

is NULL, a handle for the main executable is returned. Otherwise, <br />

names a module that will be loaded.<br />

If contains a slash character(/), the pathname is used directly, whether<br />

it is an absolute or a relative path. Otherwise, a search for the named module is<br />

made. Directories to be searched are listed in:<br />

1. Value of LIBPATH when the process was first loaded<br />

2. Current value of LIBPATH that can be modified during execution with the<br />

setenv command<br />

The new module and its dependents are actually loaded with the load() system<br />

call. If the main program was built with the -brtl option, the runtime linker<br />

processes the loaded modules. Next, initialization routines are called for modules<br />

loaded for the first time.<br />

If dlopen() succeeds, it returns a handle that can be used for calls to dlsym() and<br />

dlclose(). Otherwise, dlopen() returns NULL and sets errno. If errno is set to<br />

ENOEXEC, additional information can be obtained by calling dlerror().<br />

4.2.3.2 dlsym()<br />

This function returns the address of a symbol in a module opened by dlopen().<br />

Synopsis: #include void *dlsym(void *handle, const char *name);<br />

The argument must be a value returned by dlopen() that has not been<br />

passed to dlclose(). The argument is the name of a symbol or the special<br />

value RTLD_EP. For functions, the symbol name should not begin with a period.<br />

If the is RTLD_EP, the address of the entry point of the module is returned.<br />

If there is no entry point, the address of the data section of the module is<br />

returned. The returned value may be passed to loadbind().<br />

In general, the module denoted by and its original dependents are<br />

searched in breadth-first search order, based on the import file IDs listed in each<br />

module. If a module is linked with the -brtl option or the -G flag, the dependency<br />

list will contain all modules listed on the command line in the same order.<br />

Otherwise, all dependent modules will be listed in an unspecified order.<br />

If dlsym() succeeds, it returns the address of the desired symbol. Otherwise,<br />

NULL is returned.<br />

4.2.3.3 dlclose()<br />

This function is used to unload a module loaded by dlopen(). The function is<br />

implemented by calling unload(). If this is the last use of the module, it is removed<br />

Application Development and Pthreads 69

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!