+2010-01-02 Peter Rosin <peda@lysator.liu.se>
+
+ Use GetErrorMode if it is available.
+ * libltdl/loaders/loadlibrary.c (wrap_geterrormode): New
+ function that checks if GetErrorMode is supported by the
+ system and makes use of it if it is.
+ (fallback_geterrormode): New function that is used otherwise
+ that implements the old workaround.
+ (geterrormode): New function pointer that points at either
+ of the above or directly at GetErrorMode.
+ (vm_open): Make use of the above.
+
2010-01-11 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
Ensure functions from resident modules work in atexit handlers.
/* loader-loadlibrary.c -- dynamic linking for Win32
Copyright (C) 1998, 1999, 2000, 2004, 2005, 2006,
- 2007, 2008 Free Software Foundation, Inc.
+ 2007, 2008, 2010 Free Software Foundation, Inc.
Written by Thomas Tanner, 1998
NOTE: The canonical source of this file is maintained with the
#include <windows.h>
+static UINT WINAPI wrap_geterrormode (void);
+static UINT WINAPI fallback_geterrormode (void);
+
+typedef UINT (WINAPI geterrormode_type) (void);
+
+static geterrormode_type *geterrormode = wrap_geterrormode;
+
+
/* A function called through the vtable when this loader is no
longer needed by the application. */
static int
}
{
- /* Silence dialog from LoadLibrary on some failures.
- No way to get the error mode, but to set it,
- so set it twice to preserve any previous flags. */
- UINT errormode = SetErrorMode(SEM_FAILCRITICALERRORS);
- SetErrorMode(errormode | SEM_FAILCRITICALERRORS);
+ /* Silence dialog from LoadLibrary on some failures. */
+ UINT errormode = geterrormode ();
+ SetErrorMode (errormode | SEM_FAILCRITICALERRORS);
module = LoadLibrary (wpath);
/* Restore the error mode. */
- SetErrorMode(errormode);
+ SetErrorMode (errormode);
}
/* libltdl expects this function to fail if it is unable
return address;
}
+
+
+
+/* --- HELPER FUNCTIONS --- */
+
+
+/* A function called through the geterrormode variable which checks
+ if the system supports GetErrorMode and arranges for it or a
+ fallback implementation to be called directly in the future. The
+ selected version is then called. */
+static UINT WINAPI
+wrap_geterrormode (void)
+{
+ HMODULE kernel32 = GetModuleHandleA ("kernel32.dll");
+ geterrormode = (geterrormode_type *) GetProcAddress (kernel32,
+ "GetErrorMode");
+ if (!geterrormode)
+ geterrormode = fallback_geterrormode;
+ return geterrormode ();
+}
+
+/* A function called through the geterrormode variable for cases
+ where the system does not support GetErrorMode */
+static UINT WINAPI
+fallback_geterrormode (void)
+{
+ /* Prior to Windows Vista, the only way to get the current error
+ mode was to set a new one. In our case, we are setting a new
+ error mode right after "getting" it, so that's fairly ok. */
+ return SetErrorMode (SEM_FAILCRITICALERRORS);
+}