* autoload.cc (std_dll_init): Add a retry loop.

This commit is contained in:
Christopher Faylor 2010-10-01 21:53:11 +00:00
parent dc9d9c731b
commit b66f254618
2 changed files with 21 additions and 8 deletions

View File

@ -1,3 +1,7 @@
2010-10-01 Christopher Faylor <me+cygwin@cgf.cx>
* autoload.cc (std_dll_init): Add a retry loop.
2010-09-30 Corinna Vinschen <corinna@vinschen.de> 2010-09-30 Corinna Vinschen <corinna@vinschen.de>
* fhandler.cc: Drop including nfs.h. * fhandler.cc: Drop including nfs.h.

View File

@ -208,7 +208,6 @@ union retchain
__attribute__ ((used, noinline)) static long long __attribute__ ((used, noinline)) static long long
std_dll_init () std_dll_init ()
{ {
HANDLE h;
struct func_info *func = (struct func_info *) __builtin_return_address (0); struct func_info *func = (struct func_info *) __builtin_return_address (0);
struct dll_info *dll = func->dll; struct dll_info *dll = func->dll;
retchain ret; retchain ret;
@ -222,21 +221,31 @@ std_dll_init ()
while (InterlockedIncrement (&dll->here)); while (InterlockedIncrement (&dll->here));
else if (!dll->handle) else if (!dll->handle)
{ {
HANDLE h;
fenv_t fpuenv; fenv_t fpuenv;
fegetenv (&fpuenv); fegetenv (&fpuenv);
WCHAR dll_path[MAX_PATH]; WCHAR dll_path[MAX_PATH];
/* http://www.microsoft.com/technet/security/advisory/2269637.mspx */ /* http://www.microsoft.com/technet/security/advisory/2269637.mspx */
wcpcpy (wcpcpy (dll_path, windows_system_directory), dll->name); wcpcpy (wcpcpy (dll_path, windows_system_directory), dll->name);
if ((h = LoadLibraryW (dll_path)) != NULL) dll->handle = NULL;
dll->handle = h; /* MSDN seems to imply that LoadLibrary can fail mysteriously, so,
else if (!(func->decoration & 1)) since there have been reports of this in the mailing list, retry
api_fatal ("could not load %W, %E", dll_path); several times before giving up. */
else for (int i = 1; !dll->handle && i <= 5; i++)
dll->handle = INVALID_HANDLE_VALUE; if ((h = LoadLibraryW (dll_path)) != NULL)
dll->handle = h;
/* FIXME: This isn't quite right. Probably should check for specific
error codes. */
else if ((func->decoration & 1))
dll->handle = INVALID_HANDLE_VALUE;
else if (i < 5)
yield ();
else
api_fatal ("could not load %W, %E", dll_path);
fesetenv (&fpuenv); fesetenv (&fpuenv);
} }
/* Set "arguments for dll_chain. */ /* Set "arguments" for dll_chain. */
ret.low = (long) dll->init; ret.low = (long) dll->init;
ret.high = (long) func; ret.high = (long) func;