From 22e6d2e327e8a4750f7f496ab4dc259e6ad87d15 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 9 Jan 2017 21:23:23 +0100 Subject: [PATCH] Check Windows version when using TLS Signed-off-by: Heinrich Schuchardt --- 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 +* +* Copyright (C) 2017 Andrew Makhorin, Department for Applied +* Informatics, Moscow Aviation Institute, Moscow, Russia. All rights +* reserved. E-mail: . +* +* 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 . +***********************************************************************/ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef __WOE__ + +#pragma comment(lib, "user32.lib") +#include + +#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