DLL Programmer's Guide for TNS/E Systems

Dynamic Use of DLLs
DLL Programmer’s Guide for TNS/E Systems527252-006
3-8
Error Encoding: dlresultcode
There has never been a call to dlopen, dlclose, or dlsym in this process.
Otherwise, dlerror returns a pointer to a buffer that contains a null-terminated character
string containing only displayable characters and no trailing newline character. The
string is a read-only value that is overwritten by the occurrence of any subsequent
error in a dynamic library call, or by any call to dlopen, dlsym, or dlclose, so to preserve
or modify the string, a process should make its own copy of it.
The loader cannot recognize threads that may be used in a multi-threaded application.
Therefore, if you create such an application, you must ensure that no thread switch
occurs between a dynamic library call and the invocation of dlerror that retrieves
information about that call. Since the NonStop operating system supports only user-
level threads, this means that during this interval, you must avoid invoking functions
that can cause explicit thread switching.
Error Encoding: dlresultcode
To obtain information in encoded form about any error that occurred in a dynamic
library call (dlopen, dlsym, or dlclose), a process can invoke the following function:
char dlresultcode(void)
dlresultcode has no parameters.
If the previous call of dlopen, dlsym, or dlclose encountered no error, or if none of
those functions has been called in this process, dlresultcode returns 0. Otherwise, it
returns a nonzero value encoding the information about the previous error. The 32-bit
result is subdivided: the upper 16 bits are an error code; the lower 16 bits are an error-
detail code.
Most of the errors encountered by dlopen() are similar to those encountered when
loading a program and its requisite libraries, so they are encoded the same way, as
process creation errors. These error and error-detail codes are described in the
Guardian Procedure Errors and Messages Manual and in the PROCESS_LAUNCH_
description in the Guardian Procedure Calls Reference Manual.
Certain errors are unique to the dynamic loading functions. These are reported with
error code 100; the error-detail is one of the following:
1 - An invalid handle argument was passed to dlsym() or dlclose().
2 - The symbol sought by dlsym() was not found.
3 - An unrecognized option was passed to dlopen().
4 - A bounds error occurred on the pathname parameter to dlopen().
5 - 7 An inconsistent state was detected in dlopen() or dlclose() processing.
Perhaps a process flag at the high-address end of the stack is corrupted.
8 - RTLD_NOLOAD was specified as an option to dlopen(), but the specified library
was not already loaded.