Documentation on the dl family of calls
Introduction
The implementation of dlopen, dlclose, dlsym, and dlerror allow '.dll's
to have almost the same behavior as '.so' on UNIX:
- link dll = dll automatically loaded (i.e. exe has linked with import lib)
- open dll = dll opened with dlopen
Description:
- Implementation of dlopen, dlcose, dlsym, dlerror
- When loaded link and open dlls are correctly initialized,
global constructors are called.
- When dll is detached (exit for link dll or dlclose for open dll),
the global destructors are called.
- When process is forked:
- Data of link dlls are correctly copied in child process and
the global destructors are called when child is terminated.
- Two cases for open dlls:
- Reload is allowed (dlfork (FORK_RELOAD): see below).
In this case, loaded dlls are reloaded in child process,
data are correctly copied from parent to the child,
and handles opened in the
parent process are accessible in the child.
(WARNING: to have this functionality the dlls MUST be
loaded with dlopen and not with LoadLibrary).
- Reload is disallowed (default). In this case child can't access
open dlls of parent.
This functionality depends on the hypothesis that in a forked process
the dlls will be mapped at the same addresses as in the parent if they are
loaded in same order.
How to use it:
In your dll code you must
1) #include <cygwin/cygwin_dll.h>
then use the declaration macro:
DECLARE_CYGWIN_DLL(<your entry point>);
Note that the fixup to terminate import section is included in macro.
2) In the link phase use "__cygwin_dll_entry@12" as entry point.
Note that you may have to perform 3 link passes.
3) dlfork is a new Cygwin-specific function. Its prototype is in
dlfcn.h. dlfork takes an int as an argument which can have the
following values:
- FORK_NO_RELOAD: this is the default behavior, the child
process won't reload open libraries of parent, and so can't
access to parent's handles.
- FORK_RELOAD: the child process will reload all
open dlls and can access parent's handles (lib or functions).
This should be used only if necessary, because it may be
slower.
The dlfork flag is a global variable which is not inherited by child
process. (I.e. a forked process begins always with
FORK_NO_RELOAD).