Commit 4448d4d5 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

win32: use thread-safe error mode (only)

parent d1f94520
......@@ -29,9 +29,6 @@
#ifdef HAVE_GETOPT_H
# include <getopt.h>
#endif
#ifdef _WIN32
# include <windows.h>
#endif
static void version (void)
{
......@@ -48,9 +45,6 @@ static void usage (const char *path)
int main (int argc, char *argv[])
{
#if defined(_WIN32) && (_WIN32_WINNT < _WIN32_WINNT_WIN7)
SetErrorMode(SEM_FAILCRITICALERRORS);
#endif
#ifdef HAVE_GETOPT_H
static const struct option opts[] =
{
......
......@@ -135,9 +135,6 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
setvbuf (stderr, NULL, _IONBF, BUFSIZ);
#endif
#if (_WIN32_WINNT < _WIN32_WINNT_WIN7)
SetErrorMode(SEM_FAILCRITICALERRORS);
#endif
HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
/* SetProcessDEPPolicy, SetDllDirectory, & Co. */
......
......@@ -152,14 +152,9 @@ LIBVLC_API const char *libvlc_printerr (const char *fmt, ...);
pthread_sigmask(SIG_BLOCK, &set, NULL);
* @endcode
*
* On Microsoft Windows Vista/2008, the process error mode
* SEM_FAILCRITICALERRORS flag <b>must</b> be set before using LibVLC.
* On later versions, that is optional and unnecessary.
* Also on Microsoft Windows (Vista and any later version), setting the default
* DLL directories to SYSTEM32 exclusively is strongly recommended for
* security reasons:
* On Microsoft Windows, setting the default DLL directories to SYSTEM32
* exclusively is strongly recommended for security reasons:
* @code
SetErrorMode(SEM_FAILCRITICALERRORS);
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32);
* @endcode
*
......
......@@ -35,45 +35,6 @@
extern DWORD LoadLibraryFlags;
#if (_WIN32_WINNT < _WIN32_WINNT_WIN7)
static BOOL WINAPI SetThreadErrorModeFallback(DWORD mode, DWORD *oldmode)
{
/* TODO: cache the pointer */
HANDLE h = GetModuleHandle(_T("kernel32.dll"));
if (unlikely(h == NULL))
return FALSE;
BOOL (WINAPI *SetThreadErrorModeReal)(DWORD, DWORD *);
SetThreadErrorModeReal = GetProcAddress(h, "SetThreadErrorMode");
if (SetThreadErrorModeReal != NULL)
return SetThreadErrorModeReal(mode, oldmode);
# if (_WIN32_WINNT < _WIN32_WINNT_VISTA)
/* As per libvlc_new() documentation, the calling process is responsible
* for setting a proper error mode on Windows 2008 and earlier versions.
* This is only a sanity check. */
UINT (WINAPI *GetErrorModeReal)(void);
DWORD curmode = 0;
GetErrorModeReal = (void *)GetProcAddress(h, "GetErrorMode");
if (GetErrorModeReal != NULL)
curmode = GetErrorModeReal();
else
curmode = SEM_FAILCRITICALERRORS;
# else
DWORD curmode = GetErrorMode();
# endif
/* Extra flags should be OK. Missing flags are NOT OK. */
if ((mode & curmode) != mode)
return FALSE;
if (oldmode != NULL)
*oldmode = curmode;
return TRUE;
}
# define SetThreadErrorMode SetThreadErrorModeFallback
#endif
static char *GetWindowsError( void )
{
wchar_t wmsg[256];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment