Subject: Re: Initialising gnuwin DLLs
From: [email-masked] (Fergus Henderson)

14 Feb 1998 21:24:50 -0800
Message-ID: <[email-masked]>
References: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
To: [email-masked]
Cc: [email-masked]

On 14-Feb-1998, Mikey <[email-masked]> wrote:
> >> (C) call into each user dll to initialize it's copy of
> >> struct _reent with the values of the exe's copy of
> >> struct _reent.
> >
> >Step (C) is not necessary if you initialize it in dll_entry().
> 
> I see what you mean, the comments in Makefile.DLLs 0.6
> about initializing the _impure_ptr's from the main program misled me
> I wondered why I was never able to get it to work :).
> Do you think those could be changed to reflect
> the current setup?

Done.

> If I understand correctly then the only changes to existing vc++ .dll code
> that would really need to be made, to link with libcygwin.a are to
> 
> ( 1 ) add a .c file to the dll with just 
> 
> #ifdef __CYGWIN32__
> void *_impure_ptr;
> #endif
> 
> in it
> 
> ( 2 ) in the file that contains DllMain make sure to #include <stdio.h>
> /* stdio.h already contains extern struct _reent *_impure_ptr; */
> 
> (3 ) change
> 
> BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
> {
> 
> to
> 
> #ifdef __CYGWIN32__
> extern struct _reent *__imp_reent_data;
> #endif
> BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
> {
> #ifdef __CYGWIN32__ 
> _impure_ptr=__imp_reent_data;
> #endif

I'd be inclined to simplify this procedure slightly by combining (1) - (3)
into a single step:

    change

	BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
	{

    to

	#ifdef __CYGWIN32__
	struct _reent *_impure_ptr;
	extern struct _reent *__imp_reent_data;
	#endif
	BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
	{
	#ifdef __CYGWIN32__ 
	_impure_ptr=__imp_reent_data;
	#endif

> if linking against the original B18 cygwin.dll/libcygwin.a you MUST
> give a --image-base other than 0x10000000 even to relocatable
> dll's, B18's cygwin.dll won't get relocated NO MATTER WHAT.
> 
> Is that about it?

That agrees with my understanding of things.
Of course no promises ;-)

-- 
Fergus Henderson <[email-masked]>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger [email-masked]         |     -- the last words of T. S. Garp.
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".