Subject: RE: Another problem with DLL's
From: [email-masked] (Sergey Okhapkin)

22 Mar 1997 07:04:40 -0800
Sender: [email-masked]
Approved: [email-masked]
Distribution: cygnus
Message-ID: <01BC36B5.D95F4050.cygnus.gnu-win32@sos>
Original-To: Valery Fine <[email-masked]>, "'John Cerney'" <[email-masked]>
Original-Cc: "[email-masked]" <[email-masked]>,
        "'Geoffrey Noer'"
	 <[email-masked]>,
        "'Jeremy Allison'" <[email-masked]>
Encoding: 51 TEXT, 52 UUENCODE
X-MS-Attachment: dll.diff 0 00-00-1980 00:00
Original-Sender: [email-masked]

John Cerney wrote:
>
> When running, the thing crashes when the DLL function is called. An 
access
> violation occurs in cygwin.dll. The foo.dll that is built uses cygwin.dll 
for
> its printf function. If I take the printf out of the foo.dll code the 
VC++
> main2.exe will run just fine.
>

This problem is due to struct reent_data in a dll and pointer to it 
(_impure_ptr) remains uninitialized after dll loading. The patch below 
solves this problem. This patch moves reent_data from application's private 
address space to cygwin.dll and adds pointer to this structure to 
cygwin.dll export table. Auto-initialisation code of your dll now can 
initialize _impure_ptr properly. Also, this patch modifies fork() code to 
copy contents of parent's reent_data to the child. Allpy this patch (it 
modifies files dcrt0.cc, fork.cc and winsup.h), add "reent_data" to export 
list in cygwin.din, and rebuild cygwin.dll. Add the following file to your 
dll:

#include <windows.h>
#include <stdio.h>
extern struct _reent *_impure_ptr, 
*__imp_reent_data;
int WINAPI dll_main(HANDLE a, DWORD reason, void *q)
{ 
switch (reason){
   case DLL_PROCESS_ATTACH: break;
   case 
DLL_PROCESS_DETACH: break;
   case DLL_THREAD_ATTACH:  break;
   case 
DLL_THREAD_DETACH:  break;
  };
  _impure_ptr=__imp_reent_data;
  return 
1;
}
main(){}

and build your dll (I've used three-pass method as for cygwin.dll). Ld's 
command line should contain "-e _dll_main@12".

--
Sergey Okhapkin
Moscow, Russia
Looking for a job

-
For help on using this list, send a message to
"[email-masked]" with one line of text: "help".