Initialising gnuwin DLLs

Ton van Overbeek
Fri Jan 30 03:21:00 GMT 1998

Patrick Fay wrote: 
> I'm just guessing but it sounds like you are running into things that
> are not thread-safe.
>  .....
> My guess is that, say, thread 1's printf calls malloc while
> another thread is in malloc. What happens? who knows.

Your thread-safeness argument is certainly valid, but before that
there are a lot of other things which need to be done.

The scenario we are talking about is for writing a dll (say sample.dll)
to be used with a non cygwin compiled application (e.g with a MS Visual C++,
or as extension of an existing application (Matlab for example)).
The sample.dll will also pull in cygwin.dll when it is compiled with
the cygnus gnu-win32 compiler. When you do thing like disk file I/O,
malloc() or getenv() in sample.dll it crashes.

The reason for this is that cygwin.dll is not initialised. In a cygnus
gnu-win32 compiled application this is done by the C runtime startup code.
I started looking at the dll_crt0_1 routine in the
winsup source of the latest Coolview.
dll_crt0_1 is the part of the runtime startup done in cygwin.dll.
A lot of things are done there: initialisation of heap
(needed by malloc() and friends), initialisation of file I/O (connecting
to Win32 filemap), etc. All these inits are not done in our scenario.
It is a pity that all these init routines are not in the exported
interface of cygwin.dll, so I do not know (yet) how to do them from
our sample.dll.

Any pointers (which inits are really necessary ?) from people in the know (Sergey ?)

Ton van Overbeek.
For help on using this list (especially unsubscribing), send a message to
"" with one line of text: "help".

More information about the Cygwin mailing list