From d66c5768caaee16a0c2c2c6411858d23fb9f21a9 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 17 Oct 2013 08:11:21 +0000 Subject: win32.c: check by module handles * win32/win32.c (console_emulator_p): check by comparison between module handle of WriteConsoleW and kernel32.dll. * configure.in, win32/Makefile.sub, win32/setup.mak: no longer need psapi.lib. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43331 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- win32/win32.c | 44 ++++++++++++-------------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) (limited to 'win32/win32.c') diff --git a/win32/win32.c b/win32/win32.c index 46bdbf99e4..e1ac4054fd 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -39,12 +39,6 @@ #include #include #include -#ifdef HAVE_PSAPI_H -#include -# define CHECK_CONSOLE_EMULATOR 1 -#else -# define CHECK_CONSOLE_EMULATOR 0 -#endif #include #if _MSC_VER >= 1400 #include @@ -611,11 +605,7 @@ static CRITICAL_SECTION select_mutex; static int NtSocketsInitialized = 0; static st_table *socklist = NULL; static st_table *conlist = NULL; -#if CHECK_CONSOLE_EMULATOR #define conlist_disabled ((st_table *)-1) -#else -#define conlist_disabled ((st_table *)NULL) -#endif static char *envarea; static char *uenvarea; @@ -5843,36 +5833,26 @@ rb_w32_pipe(int fds[2]) return 0; } -#if CHECK_CONSOLE_EMULATOR /* License: Ruby's */ static int console_emulator_p(void) { - HMODULE module_buf[10], *pmodule = module_buf; - DWORD nmodule = numberof(module_buf), needed = 0, i; - HANDLE proch = GetCurrentProcess(); +#ifdef _WIN32_WCE + return FALSE; +#else + const void *const func = WriteConsoleW; + HMODULE k; + MEMORY_BASIC_INFORMATION m; - if (!EnumProcessModules(proch, pmodule, nmodule * sizeof(HMODULE), &needed)) + memset(&m, 0, sizeof(m)); + if (!VirtualQuery(func, &m, sizeof(m))) { return FALSE; - if (needed / sizeof(HMODULE) > nmodule) { - nmodule = needed / sizeof(HMODULE); - pmodule = alloca(sizeof(HMODULE) * nmodule); - if (!EnumProcessModules(proch, pmodule, needed, &needed)) - return FALSE; - } - for (i = 0; i < nmodule; i++) { - WCHAR modname[MAX_PATH]; - - if (GetModuleBaseNameW(proch, pmodule[i], modname, numberof(modname))) { - if (PathMatchSpecW(modname, L"conemu*.dll")) return TRUE; - } } - - return 0; -} -#else -#define console_emulator_p() 0 + k = GetModuleHandle("kernel32.dll"); + if (!k) return FALSE; + return (HMODULE)m.AllocationBase != k; #endif +} /* License: Ruby's */ static struct constat * -- cgit v1.2.3