pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Christian Ullrich <chris@chrullrich.net>
Subject: [PATCH] Pin any DLL as soon as seen when looking for _putenv()
Date: Tue, 6 Sep 2016 10:02:06 +0200
---
src/port/win32env.c | 54 ++++++++++++++++++++++++++++++++++-------------------
1 file changed, 35 insertions(+), 19 deletions(-)
inline patch 1: src/port/win32env.c (+35/-19 lines) download inline-1.patch diff --git a/src/port/win32env.c b/src/port/win32env.c
index 3f56ba8..7417b60 100644
--- a/src/port/win32env.c
+++ b/src/port/win32env.c
@@ -43,36 +43,37 @@ pgwin32_putenv(const char *envval)
char *modulename;
HMODULE hmodule;
PUTENVPROC putenvFunc;
+ BOOL pinned;
} rtmodules[] =
{
/* Visual Studio 6.0 / mingw */
- {"msvcrt", NULL, NULL},
- {"msvcrtd", NULL, NULL},
+ {"msvcrt", NULL, NULL, FALSE},
+ {"msvcrtd", NULL, NULL, FALSE},
/* Visual Studio 2002 */
- {"msvcr70", NULL, NULL},
- {"msvcr70d", NULL, NULL},
+ {"msvcr70", NULL, NULL, FALSE},
+ {"msvcr70d", NULL, NULL, FALSE},
/* Visual Studio 2003 */
- {"msvcr71", NULL, NULL},
- {"msvcr71d", NULL, NULL},
+ {"msvcr71", NULL, NULL, FALSE},
+ {"msvcr71d", NULL, NULL, FALSE},
/* Visual Studio 2005 */
- {"msvcr80", NULL, NULL},
- {"msvcr80d", NULL, NULL},
+ {"msvcr80", NULL, NULL, FALSE},
+ {"msvcr80d", NULL, NULL, FALSE},
/* Visual Studio 2008 */
- {"msvcr90", NULL, NULL},
- {"msvcr90d", NULL, NULL},
+ {"msvcr90", NULL, NULL, FALSE},
+ {"msvcr90d", NULL, NULL, FALSE},
/* Visual Studio 2010 */
- {"msvcr100", NULL, NULL},
- {"msvcr100d", NULL, NULL},
+ {"msvcr100", NULL, NULL, FALSE},
+ {"msvcr100d", NULL, NULL, FALSE},
/* Visual Studio 2012 */
- {"msvcr110", NULL, NULL},
- {"msvcr110d", NULL, NULL},
+ {"msvcr110", NULL, NULL, FALSE},
+ {"msvcr110d", NULL, NULL, FALSE},
/* Visual Studio 2013 */
- {"msvcr120", NULL, NULL},
- {"msvcr120d", NULL, NULL},
+ {"msvcr120", NULL, NULL, FALSE},
+ {"msvcr120d", NULL, NULL, FALSE},
/* Visual Studio 2015 and later */
- {"ucrtbase", NULL, NULL},
- {"ucrtbased", NULL, NULL},
- {NULL, NULL, NULL}
+ {"ucrtbase", NULL, NULL, FALSE},
+ {"ucrtbased", NULL, NULL, FALSE},
+ {NULL, NULL, NULL, FALSE}
};
int i;
@@ -90,6 +91,21 @@ pgwin32_putenv(const char *envval)
}
else
{
+ /*
+ * Pin this DLL handle as soon as possible to avoid it
+ * to be unloaded until the process terminates.
+ */
+ if (!rtmodules[i].pinned)
+ {
+ HMODULE tmp;
+ BOOL res = GetModuleHandleEx(
+ GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
+ | GET_MODULE_HANDLE_EX_FLAG_PIN,
+ (LPCTSTR)rtmodules[i].hmodule,
+ &tmp);
+ rtmodules[i].pinned = res;
+ }
+
rtmodules[i].putenvFunc = (PUTENVPROC) GetProcAddress(rtmodules[i].hmodule, "_putenv");
if (rtmodules[i].putenvFunc == NULL)
{
--
2.10.0.windows.1
--------------63886F5E27B20EF033573BDA
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
--------------63886F5E27B20EF033573BDA--
Message-ID: <no-message-id-6712@localhost>
Permalink: ../no-message-id-6712@localhost/
Also on: postgresql.org/message-id/no-message-id-6712@localhost
copy link · copy postgr.es · copy git am
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: chris@chrullrich.net
Subject: Re: [PATCH] Pin any DLL as soon as seen when looking for _putenv()
In-Reply-To: <no-message-id-6712@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox