From: sos AT prospect DOT com DOT ru (Sergey Okhapkin) Subject: RE: Another problem with DLL's 22 Mar 1997 07:04:40 -0800 Sender: daemon AT cygnus DOT com Approved: cygnus DOT gnu-win32 AT cygnus DOT com Distribution: cygnus Message-ID: <01BC36B5.D95F4050.cygnus.gnu-win32@sos> Original-To: Valery Fine , "'John Cerney'" Original-Cc: "gnu-win32 AT cygnus DOT com" , "'Geoffrey Noer'" , "'Jeremy Allison'" Encoding: 51 TEXT, 52 UUENCODE X-MS-Attachment: dll.diff 0 00-00-1980 00:00 Original-Sender: owner-gnu-win32 AT cygnus DOT com 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 #include 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 AT 12". -- Sergey Okhapkin Moscow, Russia Looking for a job begin 600 dll.diff M*BHJ(&1C2!F;W)K960 AT 8VAI;&1R96X AT 9V5T('1H96ER(&5X M8V5P=&EO;B!H86YD;&5R('-E="!U<"!O:RX@("HO"BTM+2 R-C4L,C"P@=2T^71H:6YG('1O(&EG;F]R92X@*B\* ` end - For help on using this list, send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".