]> sourceware.org Git - newlib-cygwin.git/commit
Cygwin: dlfcn: Fix reference counting
authorCorinna Vinschen <corinna@vinschen.de>
Tue, 21 Mar 2017 13:30:24 +0000 (14:30 +0100)
committerCorinna Vinschen <corinna@vinschen.de>
Tue, 21 Mar 2017 13:31:03 +0000 (14:31 +0100)
commit33297d810d9033ffca661b8f9158116602615dd7
tree94a85b260190f4badca35cd5f899d0a3e402bb3d
parent33c7b2b544a96ee443728f9558ce07a13e05f1e8
Cygwin: dlfcn: Fix reference counting

The original dll_init code was living under the wrong assumption that
dll_dllcrt0_1 and in turn dll_list::alloc will be called for each
LoadLibrary call.  The same wrong assumption was made for
cygwin_detach_dll/dll_list::detach called via FreeLibrary.

In reality, dll_dllcrt0_1 gets only called once at first LoadLibrary
and cygwin_detach_dll once at last FreeLibrary.

In effect, reference counting for DLLs was completely broken after fork:

  parent:
    l1 = dlopen ("lib1");  // LoadLibrary, LoadCount = 1
    l2 = dlopen ("lib1");  // LoadLibrary, LoadCount = 2

    fork ();               // LoadLibrary in the child, LoadCount = 1!
      child:
        dlclose (l1);      // FreeLibrary actually frees the lib
        x = dlsym (l2);    // SEGV

* Move reference counting to dlopen/dlclose since only those functions
  have to keep track of loading/unloading DLLs in the application context.

* Remove broken accounting code from dll_list::alloc and dll_list::detach.

* Fix error handling in dlclose.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
winsup/cygwin/dlfcn.cc
winsup/cygwin/dll_init.cc
winsup/cygwin/release/2.8.0
This page took 0.030788 seconds and 5 git commands to generate.