Subject: Re: Using a Cygwin-built DLL outside of Cygwin
From: Christian Kreibich <[email-masked]>
To: [email-masked]
Cc: Thorsten Kampe <[email-masked]>
Date: Thu, 18 Oct 2007 16:26:53 -0700
List-Id: <cygwin.cygwin.com>

On Thu, 2007-10-18 at 09:42 -0700, Christian Kreibich wrote:
> I'll now try to get this snippet also mentioned in the FAQ to work:
> 
>   HMODULE h = LoadLibrary("cygwin1.dll");
>   void (*init)() = GetProcAddress(h, "cygwin_dll_init");
>   init();

Okay, I tweaked this slightly to get it to build:

  typedef int (__cdecl *MYPROC)();

  int _tmain(int argc, _TCHAR* argv[])
  {
	  HMODULE h = LoadLibrary(TEXT("cygwin1.dll"));
	  MYPROC init = (MYPROC) GetProcAddress(h, "cygwin_dll_init");
	  init();

This delays the problem -- I now see C0000005 exceptions triggered
inside my library when writing to stderr later, after it has worked for
a while. The only difference between the working and crashing fprintf()s
is that before the second call, a different function inside my library
has been entered and a few variables declared (I'm happy to provide
details on request). The tail part of the strace looks as follows:

  461   34209 [main] foo 2020 build_argv: argv[0] = 'foo.exe'
   89   34298 [main] foo 2020 build_argv: argc 1
  412   34710 [main] foo 2020 build_fh_pc: fh 0x61167878
  187   34897 [main] foo 2020 open_shared: name (null), n 0, shared 0x60020000 (wanted 0x60020000), h 0x7F4
  140   35037 [main] foo 2020 _pinfo::set_ctty: old no ctty
  103   35140 [main] foo 2020 _pinfo::set_ctty: attaching ctty /dev/console sid 2020, pid 2020, pgid 2020, tty->pgid 0, tty->sid 2020
 2487   37627 [main] foo 2020 fhandler_base::set_flags: flags 0x10002, supplied_bin 0x0
  135   37762 [main] foo 2020 fhandler_base::set_flags: O_TEXT/O_BINARY set in flags 0x10000
   91   37853 [main] foo 2020 fhandler_base::set_flags: filemode set to binary
  457   38310 [main] foo 2020 init_cygheap::manage_console_count: fhandler_console::open: console_count 1, amount 1, ctty /dev/console, avoid_freeing_console 0
  132   38442 [main] foo 2020 fhandler_console::open: opened conin$ 0xF, conout$ 0x13
  224   38666 [main] foo 2020 fhandler_console::output_tcsetattr: 0 = tcsetattr (,6002001C) (ENABLE FLAGS 3) (lflag 107 oflag 9)
  407   39073 [main] foo 2020 build_fh_pc: fh 0x61167A80
  125   39198 [main] foo 2020 fhandler_base::set_flags: flags 0x10002, supplied_bin 0x0
   91   39289 [main] foo 2020 fhandler_base::set_flags: O_TEXT/O_BINARY set in flags 0x10000
   90   39379 [main] foo 2020 fhandler_base::set_flags: filemode set to binary
  370   39749 [main] foo 2020 init_cygheap::manage_console_count: fhandler_console::open: console_count 2, amount 1, ctty /dev/console, avoid_freeing_console 0
  337   40086 [main] foo 2020 fhandler_console::open: opened conin$ 0x3, conout$ 0x17
  224   40310 [main] foo 2020 fhandler_console::output_tcsetattr: 0 = tcsetattr (,6002001C) (ENABLE FLAGS 3) (lflag 107 oflag 9)
  416   40726 [main] foo 2020 build_fh_pc: fh 0x61167C88
  126   40852 [main] foo 2020 fhandler_base::set_flags: flags 0x10002, supplied_bin 0x0
   92   40944 [main] foo 2020 fhandler_base::set_flags: O_TEXT/O_BINARY set in flags 0x10000
   88   41032 [main] foo 2020 fhandler_base::set_flags: filemode set to binary
  368   41400 [main] foo 2020 init_cygheap::manage_console_count: fhandler_console::open: console_count 3, amount 1, ctty /dev/console, avoid_freeing_console 0
  128   41528 [main] foo 2020 fhandler_console::open: opened conin$ 0x7, conout$ 0x1B
  205   41733 [main] foo 2020 fhandler_console::output_tcsetattr: 0 = tcsetattr (,6002001C) (ENABLE FLAGS 3) (lflag 107 oflag 9)
  355   42088 [main] foo 2020 fhandler_console::need_invisible: invisible_console 0
  168   42256 [main] foo 2020 dll_crt0_1: user_data->main 0x0
   92   42348 [main] foo 2020 __set_errno: void dll_crt0_1(void*):948 val 0
   89   42437 [main] foo 2020 _cygtls::remove: wait 0xFFFFFFFF
   85   42522 [main] foo 2020 _cygtls::remove: removed 0x12CE64 element 0
  569   43091 [main] foo 2020 sig_send: sendsig 0x704, pid 2020, signal -34, its_me 1
  109   43200 [main] foo 2020 sig_send: Not waiting for sigcomplete.  its_me 1 signal -34
   96   43296 [main] foo 2020 sig_send: returning 0x0 from sending signal -34
  192   43488 [main] foo 2020 fhandler_console::write: 12E2E0, 5
   90   43578 [main] foo 2020 fhandler_console::write: at 50(2) state is 0
  332   43910 [main] foo 2020 fhandler_console::write: 5 = write_console (,..5)
  580   44490 [main] foo 2020 sig_send: sendsig 0x704, pid 2020, signal -34, its_me 1
   99   44589 [main] foo 2020 sig_send: Not waiting for sigcomplete.  its_me 1 signal -34
   99   44688 [main] foo 2020 sig_send: returning 0x0 from sending signal -34
  168   44856 [main] foo 2020 fhandler_console::write: 61101197, 1
   83   44939 [main] foo 2020 fhandler_console::write: at 45(-) state is 0
  263   45202 [main] foo 2020 fhandler_console::write: 1 = write_console (,..1)
--- Process 2020, exception C0000005 at 610EEABC
--- Process 2020, exception C0000005 at 00010007
--- Process 2020, exception C0000005 at 00010007
--- Process 2020, exception C0000005 at 00010007
--- Process 2020, exception C0000005 at 00010007
--- Process 2020, exception C0000005 at 00010007
--- Process 2020, exception C0000005 at 00010007

Any ideas?

Cheers,
Christian
-- 
________________________________________________________________________
                                           http://www.icir.org/christian
                                                    http://www.whoop.org

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/