Sorry Andrew I put made a type in config_VC. A corrected patch is appended.
Regards Heinrich On 01/09/2017 10:46 PM, Heinrich Schuchardt wrote: > Hello Andrew, > > https://msdn.microsoft.com/en-us/library/6yh4a9k1.aspx > describes when the Windows specific restrictions for thread local > storage in DLLs apply: > "On Windows operating systems before Windows Vista" > > We should check the Windows version in DllMain and return false if the > Windows Version is below Vista and symbol TLS is defined. > > Please, apply the appended patch. > > Best regards > > Heinrich > > On 01/09/2017 08:32 PM, Heinrich Schuchardt wrote: >> Hello David, >> >> the thread local storage is not correctly implemented for usage with >> Windows in a DLL. See >> >> https://msdn.microsoft.com/en-us/library/windows/desktop/ms686997 >> >> I think we should do the following: >> >> Write a test case that demonstrates the usage of multithreading GLPK >> using the pthread library. >> >> Add a pthread emulation for Windows so we can use the same test code >> with Windows and with Posix. For a minimalistic implementation see >> http://sqlstat.sourceforge.net/doxygen/html/sqlthread_8h_source.html >> >> Rewrite the allocation and freeing of the env variable according to the >> Windows DLL requirements. >> >> Best regards >> >> Heinrich Schuchardt >> >> _______________________________________________ >> Help-glpk mailing list >> [email protected] >> https://lists.gnu.org/mailman/listinfo/help-glpk >> > > > > _______________________________________________ > Help-glpk mailing list > [email protected] > https://lists.gnu.org/mailman/listinfo/help-glpk >
From 22e6d2e327e8a4750f7f496ab4dc259e6ad87d15 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt <[email protected]> Date: Mon, 9 Jan 2017 21:23:23 +0100 Subject: [PATCH] Check Windows version when using TLS Signed-off-by: Heinrich Schuchardt <[email protected]> --- src/env/dll.c | 70 +++++++++++++++++++++++++++++++++++++++++++++ w32/Makefile_VC_DLL | 1 + w32/Makefile_VC_stdcall_DLL | 1 + w32/config_VC | 2 ++ w64/config_VC | 2 ++ w64/makefile_VC_DLL | 1 + 6 files changed, 77 insertions(+) create mode 100644 src/env/dll.c diff --git a/src/env/dll.c b/src/env/dll.c new file mode 100644 index 0000000..e84096a --- /dev/null +++ b/src/env/dll.c @@ -0,0 +1,70 @@ +/* dll.c (dll entry point) */ + +/*********************************************************************** +* This code is part of GLPK (GNU Linear Programming Kit). +* +* Author Heinrich Schuchardt <[email protected]> +* +* Copyright (C) 2017 Andrew Makhorin, Department for Applied +* Informatics, Moscow Aviation Institute, Moscow, Russia. All rights +* reserved. E-mail: <[email protected]>. +* +* GLPK is free software: you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GLPK is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +* License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GLPK. If not, see <http://www.gnu.org/licenses/>. +***********************************************************************/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef __WOE__ + +#pragma comment(lib, "user32.lib") +#include <windows.h> + +#define VISTA 0x06 + +/* + * This is the main entry point of the DLL. + */ +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ DWORD version; + DWORD major_version; + +#ifdef TLS + switch (fdwReason) { + case DLL_PROCESS_ATTACH: + /* + * @TODO: + * GetVersion is deprecated but the version help functions are not + * available in Visual Studio 2010. So lets use it until we remove + * the outdated Build files. + */ + version = GetVersion(); + major_version = version & 0xff; + + if (major_version < VISTA) { + MessageBoxA(NULL, "This GLPK library uses thread local storage.\n" + "You need at least Windows Vista to utilize it.\n", + "GLPK", MB_OK | MB_ICONERROR); + return FALSE; + } + break; + } +#endif /* TLS */ + + return TRUE; +} + +#endif /* WOE */ \ No newline at end of file diff --git a/w32/Makefile_VC_DLL b/w32/Makefile_VC_DLL index 1b5f025..cb90c8d 100644 --- a/w32/Makefile_VC_DLL +++ b/w32/Makefile_VC_DLL @@ -142,6 +142,7 @@ OBJSET = \ ..\src\cglib\mirgen.obj \ ..\src\colamd\colamd.obj \ ..\src\env\alloc.obj \ +..\src\env\dll.obj \ ..\src\env\dlsup.obj \ ..\src\env\env.obj \ ..\src\env\error.obj \ diff --git a/w32/Makefile_VC_stdcall_DLL b/w32/Makefile_VC_stdcall_DLL index 741dc8d..eb60f06 100644 --- a/w32/Makefile_VC_stdcall_DLL +++ b/w32/Makefile_VC_stdcall_DLL @@ -144,6 +144,7 @@ OBJSET = \ ..\src\colamd\colamd.obj \ ..\src\env\alloc.obj \ ..\src\env\dlsup.obj \ +..\src\env\dll.obj \ ..\src\env\env.obj \ ..\src\env\error.obj \ ..\src\env\stdout.obj \ diff --git a/w32/config_VC b/w32/config_VC index e831600..0e18c65 100644 --- a/w32/config_VC +++ b/w32/config_VC @@ -2,6 +2,8 @@ #define __WOE__ 1 +#define TLS __declspec( thread ) + #define ODBC_DLNAME "odbc32.dll" /* ODBC shared library name if this feature is enabled */ diff --git a/w64/config_VC b/w64/config_VC index e831600..0e18c65 100644 --- a/w64/config_VC +++ b/w64/config_VC @@ -2,6 +2,8 @@ #define __WOE__ 1 +#define TLS __declspec( thread ) + #define ODBC_DLNAME "odbc32.dll" /* ODBC shared library name if this feature is enabled */ diff --git a/w64/makefile_VC_DLL b/w64/makefile_VC_DLL index 1b5f025..cb90c8d 100644 --- a/w64/makefile_VC_DLL +++ b/w64/makefile_VC_DLL @@ -142,6 +142,7 @@ OBJSET = \ ..\src\cglib\mirgen.obj \ ..\src\colamd\colamd.obj \ ..\src\env\alloc.obj \ +..\src\env\dll.obj \ ..\src\env\dlsup.obj \ ..\src\env\env.obj \ ..\src\env\error.obj \ -- 2.11.0
_______________________________________________ Help-glpk mailing list [email protected] https://lists.gnu.org/mailman/listinfo/help-glpk
