This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re; Initializing gnuwin DLLs


Hi,

I have had some success in initializing cygwin.dll from my own dll.
In my case 'own dll' is a Matlab mex-function.
I am not finished yet, but the results up till now are promising.

In a normal cygwin compiled main the runtime start-up (cygwin_crt0())
calls dll_crt0() which jumps into cygwin.dll by calling dll_crt0_1().
This one does all the initializing (heap, environment, file I/O,signals,
preparation for fork, and things like setting up _impure_ptr).
Finally it calls main() and then exit().

My idea is kind of a brute force approach:
 Just call cygwin_crt0() from my own dll. This one of course
 will call a main() provided by me. This main() should not
 finish, otherwise exit() will be called and the process with
 my own dll will be terminated.
 In the PROCESS_ATTACH entry of the dll entry function I create
 a new thread which contains the call to cygwin_crt0() and my main().
 This thread is given the highest priority and the dll entry function
 returns after creating the thread and setting its priority.
 The 'never ending main()' is realised by creating a non-signalled
 Windows32 event and then waiting for it to become signalled.

This approach seems to work, at least I can do file I/O (which involves
use of malloc()) and read environment variables (which are copied in the
cygwin.dll initialization).
Remaining problems to deal with: 
- Multiple dlls in the same process using cygwin.dll.
  We only want to initialize once, otherwise we end up
  with 3 extra threads for each initialization (1 doing
  the initialization and 2 from cygwin.dll (coolview nov 97 version).
  This can probably be solved by using a Mutex.
- Repeated loading/unloading of my own dll. (Matlab uses LoadLibrary
  to load the dll).

I hope this information is usefull also for people trying to combine
MSVC compiled programs with cygwin compiled dlls.

What we really need is a proper initialization function in cygwin.dll which
can be called by dll's in non-cygwin applications.
Alternatively the cygwin.dll dll entry function at PROCESS_ATTACH time
should somehow be able to check if it has to do some initialization itself or not.

Regards,
Ton van Overbeek, tvoverbe@wk.estec.esa.nl
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]