OSDN Git Service

* autoload.cc (GetSystemDEPPolicy): Define.
authorcorinna <corinna>
Wed, 12 Nov 2008 11:04:26 +0000 (11:04 +0000)
committercorinna <corinna>
Wed, 12 Nov 2008 11:04:26 +0000 (11:04 +0000)
(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
winsup/cygwin/autoload.cc
winsup/cygwin/dcrt0.cc
winsup/cygwin/wincap.cc
winsup/cygwin/wincap.h
winsup/cygwin/winsup.h

index 1a21594..c808785 100644 (file)
@@ -1,5 +1,19 @@
 2008-11-11  Corinna Vinschen  <corinna@vinschen.de>
 
+       * 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  <corinna@vinschen.de>
+
        * mount.cc (mount_info::cygdrive_win32_path): Always upper case
        DOS drive letter to accommodate case sensitivity.
        (cygdrive_getmntent): Ditto.
index c86deb9..e69a332 100644 (file)
@@ -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)
 
index cd9863e..ccdedc6 100644 (file)
@@ -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");
 }
 
index 4d20ecc..646e3dc 100644 (file)
@@ -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))
index 7028402..038bf0b 100644 (file)
@@ -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
 };
index 79ae39a..f4e4179 100644 (file)
@@ -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 <sys/types.h>