* cxx.cc (default_cygwin_cxx_malloc): Enhance commenting.
* dll_init.cc (dll_dllcrt0_1): Likewise. * dlfcn.cc (dlopen): Prevent dlopen()'d DLL from installing any cxx malloc overrides. * include/cygwin/cygwin_dll.h (__dynamically_loaded): New variable. * lib/_cygwin_crt0_common.cc (_cygwin_crt0_common): Check it and only install cxx malloc overrides when statically loaded. Extend comments.
This commit is contained in:
@@ -93,7 +93,28 @@ dlopen (const char *name, int)
|
||||
wchar_t *path = tp.w_get ();
|
||||
|
||||
pc.get_wide_win32_path (path);
|
||||
|
||||
/* Workaround for broken DLLs built against Cygwin versions 1.7.0-49
|
||||
up to 1.7.0-57. They override the cxx_malloc pointer in their
|
||||
DLL initialization code even if loaded dynamically. This is a
|
||||
no-no since a later dlclose lets cxx_malloc point into nirvana.
|
||||
The below kludge "fixes" that by reverting the original cxx_malloc
|
||||
pointer after LoadLibrary. This implies that their overrides
|
||||
won't be applied; that's OK. All overrides should be present at
|
||||
final link time, as Windows doesn't allow undefined references;
|
||||
it would actually be wrong for a dlopen'd DLL to opportunistically
|
||||
override functions in a way that wasn't known then. We're not
|
||||
going to try and reproduce the full ELF dynamic loader here! */
|
||||
|
||||
/* Store original cxx_malloc pointer. */
|
||||
struct per_process_cxx_malloc *tmp_malloc;
|
||||
tmp_malloc = __cygwin_user_data.cxx_malloc;
|
||||
|
||||
ret = (void *) LoadLibraryW (path);
|
||||
|
||||
/* Restore original cxx_malloc pointer. */
|
||||
__cygwin_user_data.cxx_malloc = tmp_malloc;
|
||||
|
||||
if (ret == NULL)
|
||||
__seterrno ();
|
||||
}
|
||||
|
Reference in New Issue
Block a user