From babd4a9c621c872cc366c679e507f5a968ad1ea3 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 12 Nov 2008 11:04:27 +0000 Subject: [PATCH] * autoload.cc (GetSystemDEPPolicy): Define. (GetProcessDEPPolicy): Ditto. (SetProcessDEPPolicy): Ditto. * dcrt0.cc (disable_dep): New static function. (dll_crt0_0): Call disable_dep on platforms requiring it. Add longish comment to explain the circumstances. * wincap.h (wincaps::ts_has_dep_problem): New element. * wincap.cc: Implement above element throughout. (wincapc::init): Set ts_has_dep_problem to true on 2008 Terminal Servers. * winsup.h (WINVER): Set to 0x0601. --- winsup/cygwin/ChangeLog | 14 ++++++++++++ winsup/cygwin/autoload.cc | 3 +++ winsup/cygwin/dcrt0.cc | 46 +++++++++++++++++++++++++++++++++++++++ winsup/cygwin/wincap.cc | 20 +++++++++++++++-- winsup/cygwin/wincap.h | 2 ++ winsup/cygwin/winsup.h | 2 +- 6 files changed, 84 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 1a2159441..c8087856f 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,17 @@ +2008-11-11 Corinna Vinschen + + * autoload.cc (GetSystemDEPPolicy): Define. + (GetProcessDEPPolicy): Ditto. + (SetProcessDEPPolicy): Ditto. + * dcrt0.cc (disable_dep): New static function. + (dll_crt0_0): Call disable_dep on platforms requiring it. Add longish + comment to explain the circumstances. + * wincap.h (wincaps::ts_has_dep_problem): New element. + * wincap.cc: Implement above element throughout. + (wincapc::init): Set ts_has_dep_problem to true on 2008 Terminal + Servers. + * winsup.h (WINVER): Set to 0x0601. + 2008-11-11 Corinna Vinschen * mount.cc (mount_info::cygdrive_win32_path): Always upper case diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc index c86deb991..e69a33222 100644 --- a/winsup/cygwin/autoload.cc +++ b/winsup/cygwin/autoload.cc @@ -413,6 +413,9 @@ LoadDLLfuncEx (FindVolumeClose, 4, kernel32, 1) LoadDLLfuncEx (GetConsoleWindow, 0, kernel32, 1) LoadDLLfuncEx (GetSystemWindowsDirectoryW, 8, kernel32, 1) LoadDLLfuncEx (GetVolumeNameForVolumeMountPointA, 12, kernel32, 1) +LoadDLLfuncEx (GetSystemDEPPolicy, 0, kernel32, 1) +LoadDLLfuncEx (GetProcessDEPPolicy, 12, kernel32, 1) +LoadDLLfuncEx (SetProcessDEPPolicy, 4, kernel32, 1) LoadDLLfunc (SHGetDesktopFolder, 4, shell32) diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index cd9863ecb..ccdedc6c0 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -686,6 +686,31 @@ child_info_spawn::handle_spawn () fixup_lockf_after_exec (); } +static DEP_SYSTEM_POLICY_TYPE dep_system_policy = (DEP_SYSTEM_POLICY_TYPE) -1; + +static void +disable_dep () +{ + DWORD ppolicy; + BOOL perm; + + if (dep_system_policy < 0) + { + dep_system_policy = GetSystemDEPPolicy (); + debug_printf ("DEP System Policy: %d", (int) dep_system_policy); + } + if (dep_system_policy < OptIn) + return; + if (!GetProcessDEPPolicy (hMainProc, &ppolicy, &perm)) + { + debug_printf ("GetProcessDEPPolicy: %E"); + return; + } + debug_printf ("DEP Process Policy: %d (permanent = %d)", ppolicy, perm); + if (ppolicy > 0 && !perm && !SetProcessDEPPolicy (0)) + debug_printf ("SetProcessDEPPolicy: %E"); +} + void __stdcall dll_crt0_0 () { @@ -750,6 +775,27 @@ dll_crt0_0 () events_init (); tty_list::init_session (); + /* FIXME: This is hopefully a temporary hack, at least until the support + case at Microsoft has been closed one way or the other. + + The disable_dep function disables DEP for all Cygwin processes if + the process runs on a Windows Server 2008 with Terminal Services + installed. This combination (TS+DEP) breaks *some* Cygwin + applications. The Terminal Service specific DLL tsappcmp.dll + changes the page protection of some pages in the application's text + segment from PAGE_EXECUTE_WRITECOPY to PAGE_WRITECOPY for no + apparent reason. This occurs before any Cygwin or applicaton code + had a chance to run. MS has no explanation for this so far, but is + rather busy trying to avoid giving support for this problem (as of + 2008-11-11). + + Unfortunately disabling DEP seems to have a not negligible + performance hit. In the long run, either MS has to fix their + problem, or we have to find a better workaround, if any exists. + Idle idea: Adding EXECUTE protection to all text segment pages? */ + if (wincap.ts_has_dep_problem ()) + disable_dep (); + debug_printf ("finished dll_crt0_0 initialization"); } diff --git a/winsup/cygwin/wincap.cc b/winsup/cygwin/wincap.cc index 4d20ecce3..646e3dc80 100644 --- a/winsup/cygwin/wincap.cc +++ b/winsup/cygwin/wincap.cc @@ -50,6 +50,7 @@ wincaps wincap_unknown __attribute__((section (".cygwin_dll_common"), shared)) = supports_all_posix_ai_flags:false, has_restricted_stack_args:false, has_transactions:false, + ts_has_dep_problem:false, }; wincaps wincap_nt4 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -82,6 +83,7 @@ wincaps wincap_nt4 __attribute__((section (".cygwin_dll_common"), shared)) = { supports_all_posix_ai_flags:false, has_restricted_stack_args:false, has_transactions:false, + ts_has_dep_problem:false, }; wincaps wincap_nt4sp4 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -114,6 +116,7 @@ wincaps wincap_nt4sp4 __attribute__((section (".cygwin_dll_common"), shared)) = supports_all_posix_ai_flags:false, has_restricted_stack_args:false, has_transactions:false, + ts_has_dep_problem:false, }; wincaps wincap_2000 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -146,6 +149,7 @@ wincaps wincap_2000 __attribute__((section (".cygwin_dll_common"), shared)) = { supports_all_posix_ai_flags:false, has_restricted_stack_args:false, has_transactions:false, + ts_has_dep_problem:false, }; wincaps wincap_2000sp4 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -178,6 +182,7 @@ wincaps wincap_2000sp4 __attribute__((section (".cygwin_dll_common"), shared)) = supports_all_posix_ai_flags:false, has_restricted_stack_args:false, has_transactions:false, + ts_has_dep_problem:false, }; wincaps wincap_xp __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -210,6 +215,7 @@ wincaps wincap_xp __attribute__((section (".cygwin_dll_common"), shared)) = { supports_all_posix_ai_flags:false, has_restricted_stack_args:false, has_transactions:false, + ts_has_dep_problem:false, }; wincaps wincap_xpsp1 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -242,6 +248,7 @@ wincaps wincap_xpsp1 __attribute__((section (".cygwin_dll_common"), shared)) = { supports_all_posix_ai_flags:false, has_restricted_stack_args:false, has_transactions:false, + ts_has_dep_problem:false, }; wincaps wincap_xpsp2 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -274,6 +281,7 @@ wincaps wincap_xpsp2 __attribute__((section (".cygwin_dll_common"), shared)) = { supports_all_posix_ai_flags:false, has_restricted_stack_args:false, has_transactions:false, + ts_has_dep_problem:false, }; wincaps wincap_2003 __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -306,6 +314,7 @@ wincaps wincap_2003 __attribute__((section (".cygwin_dll_common"), shared)) = { supports_all_posix_ai_flags:false, has_restricted_stack_args:true, has_transactions:false, + ts_has_dep_problem:false, }; wincaps wincap_vista __attribute__((section (".cygwin_dll_common"), shared)) = { @@ -338,6 +347,7 @@ wincaps wincap_vista __attribute__((section (".cygwin_dll_common"), shared)) = { supports_all_posix_ai_flags:true, has_restricted_stack_args:false, has_transactions:true, + ts_has_dep_problem:false, }; wincapc wincap __attribute__((section (".cygwin_dll_common"), shared)); @@ -419,8 +429,14 @@ wincapc::init () } if (has_osversioninfoex && version.wProductType != VER_NT_WORKSTATION) - ((wincaps *)caps)->is_server = true; - + { + ((wincaps *)caps)->is_server = true; + if (version.dwMajorVersion >= 6 + && (version.wSuiteMask + & (VER_SUITE_TERMINAL | VER_SUITE_SINGLEUSERTS)) + == VER_SUITE_TERMINAL) + ((wincaps *)caps)->ts_has_dep_problem = true; + } if (NT_SUCCESS (NtQueryInformationProcess (GetCurrentProcess (), ProcessWow64Information, &wow64, sizeof wow64, NULL)) diff --git a/winsup/cygwin/wincap.h b/winsup/cygwin/wincap.h index 7028402c1..038bf0b59 100644 --- a/winsup/cygwin/wincap.h +++ b/winsup/cygwin/wincap.h @@ -42,6 +42,7 @@ struct wincaps unsigned supports_all_posix_ai_flags : 1; unsigned has_restricted_stack_args : 1; unsigned has_transactions : 1; + unsigned ts_has_dep_problem : 1; }; class wincapc @@ -90,6 +91,7 @@ public: bool IMPLEMENT (supports_all_posix_ai_flags) bool IMPLEMENT (has_restricted_stack_args) bool IMPLEMENT (has_transactions) + bool IMPLEMENT (ts_has_dep_problem) #undef IMPLEMENT }; diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h index 79ae39aec..f4e41796a 100644 --- a/winsup/cygwin/winsup.h +++ b/winsup/cygwin/winsup.h @@ -26,7 +26,7 @@ details. */ #define EXPORT_ALIAS(sym,symalias) extern "C" __typeof (sym) symalias __attribute__ ((alias(#sym))); -#define WINVER 0x0600 +#define WINVER 0x0601 #define _NO_W32_PSEUDO_MODIFIERS #include