]> sourceware.org Git - newlib-cygwin.git/commitdiff
* cygheap.cc (init_cygheap::init_installation_root): Convert function
authorCorinna Vinschen <corinna@vinschen.de>
Tue, 14 Feb 2012 11:27:43 +0000 (11:27 +0000)
committerCorinna Vinschen <corinna@vinschen.de>
Tue, 14 Feb 2012 11:27:43 +0000 (11:27 +0000)
init_installation_root into a cygheap method.
* cygheap.h (struct init_cygheap): Move installation_root,
installation_key, and installation_key_buf from shared
.cygwin_dll_common DLL section to cygheap.  Declare new method
init_installation_root.
* dtable.cc (handle_to_fn): Accommodate the move of installation strings
to the cygheap.
* external.cc (cygwin_internal): Ditto.
* fhandler_console.cc (fhandler_console::open_shared_console): Ditto.
* fhandler_mailslot.cc (fhandler_mailslot::get_object_attr): Ditto.
* fhandler_tty.cc: Ditto, throughout.
* mount.cc (mount_info::init): Ditto.
* pipe.cc (fhandler_pipe::create): Ditto.
* shared.cc: Ditto, throughout.
(installation_root): Remove.
(installation_key): Move to cygheap.
(installation_key_buf): Ditto.
(installation_root_inited): Remove.
(SPIN_WAIT): Remove.
(init_installation_root): Move to cygheap.
(memory_init): Call cygheap->init_installation_root right after
cygheap->user.init.  Drop call of init_installation_root function.
* shared_info.h (init_installation_root): Drop declaration.
(installation_root): Ditto.
(installation_key): Ditto.
* uinfo.cc (pwdgrp::load): Accommodate the move of installation strings
to the cygheap.

13 files changed:
winsup/cygwin/ChangeLog
winsup/cygwin/cygheap.cc
winsup/cygwin/cygheap.h
winsup/cygwin/dtable.cc
winsup/cygwin/external.cc
winsup/cygwin/fhandler_console.cc
winsup/cygwin/fhandler_mailslot.cc
winsup/cygwin/fhandler_tty.cc
winsup/cygwin/mount.cc
winsup/cygwin/pipe.cc
winsup/cygwin/shared.cc
winsup/cygwin/shared_info.h
winsup/cygwin/uinfo.cc

index b271707e52883ef5bae7691906838fb9d780acfd..834fe7ac087afcd6fc0cc628f4f67eca45fae495 100644 (file)
@@ -1,3 +1,34 @@
+2012-02-14  Corinna Vinschen  <corinna@vinschen.de>
+
+       * cygheap.cc (init_cygheap::init_installation_root): Convert function
+       init_installation_root into a cygheap method.
+       * cygheap.h (struct init_cygheap): Move installation_root,
+       installation_key, and installation_key_buf from shared
+       .cygwin_dll_common DLL section to cygheap.  Declare new method
+       init_installation_root.
+       * dtable.cc (handle_to_fn): Accommodate the move of installation strings
+       to the cygheap.
+       * external.cc (cygwin_internal): Ditto.
+       * fhandler_console.cc (fhandler_console::open_shared_console): Ditto.
+       * fhandler_mailslot.cc (fhandler_mailslot::get_object_attr): Ditto.
+       * fhandler_tty.cc: Ditto, throughout.
+       * mount.cc (mount_info::init): Ditto.
+       * pipe.cc (fhandler_pipe::create): Ditto.
+       * shared.cc: Ditto, throughout.
+       (installation_root): Remove.
+       (installation_key): Move to cygheap.
+       (installation_key_buf): Ditto.
+       (installation_root_inited): Remove.
+       (SPIN_WAIT): Remove.
+       (init_installation_root): Move to cygheap.
+       (memory_init): Call cygheap->init_installation_root right after
+       cygheap->user.init.  Drop call of init_installation_root function.
+       * shared_info.h (init_installation_root): Drop declaration.
+       (installation_root): Ditto.
+       (installation_key): Ditto.
+       * uinfo.cc (pwdgrp::load): Accommodate the move of installation strings
+       to the cygheap.
+
 2012-02-14  Corinna Vinschen  <corinna@vinschen.de>
 
        * thread.cc: Drop including unused headers.
index 31212666d04be79eabd555e6d1e6da817394b895..bc96a55330c1ea2f70a30ab7f9d62144ac01d6f5 100644 (file)
@@ -23,6 +23,8 @@
 #include "heap.h"
 #include "sigproc.h"
 #include "pinfo.h"
+#include "registry.h"
+#include "ntdll.h"
 #include <unistd.h>
 #include <wchar.h>
 
@@ -138,6 +140,84 @@ _csbrk (int sbs)
   return prebrk;
 }
 
+/* Use absolute path of cygwin1.dll to derive the Win32 dir which
+   is our installation_root.  Note that we can't handle Cygwin installation
+   root dirs of more than 4K path length.  I assume that's ok...
+
+   This function also generates the installation_key value.  It's a 64 bit
+   hash value based on the path of the Cygwin DLL itself.  It's subsequently
+   used when generating shared object names.  Thus, different Cygwin
+   installations generate different object names and so are isolated from
+   each other.
+
+   Having this information, the installation key together with the
+   installation root path is written to the registry.  The idea is that
+   cygcheck can print the paths into which the Cygwin DLL has been
+   installed for debugging purposes.
+
+   Last but not least, the new cygwin properties datastrcuture is checked
+   for the "disabled_key" value, which is used to determine whether the
+   installation key is actually added to all object names or not.  This is
+   used as a last resort for debugging purposes, usually.  However, there
+   could be another good reason to re-enable object name collisions between
+   multiple Cygwin DLLs, which we're just not aware of right now.  Cygcheck
+   can be used to change the value in an existing Cygwin DLL binary. */
+void
+init_cygheap::init_installation_root ()
+{
+  if (!GetModuleFileNameW (cygwin_hmodule, installation_root, PATH_MAX))
+    api_fatal ("Can't initialize Cygwin installation root dir.\n"
+              "GetModuleFileNameW(%p, %p, %u), %E",
+              cygwin_hmodule, installation_root, PATH_MAX);
+  PWCHAR p = installation_root;
+  if (wcsncmp (p, L"\\\\?\\", 4))      /* No long path prefix. */
+    {
+      if (!wcsncasecmp (p, L"\\\\", 2))        /* UNC */
+       {
+         p = wcpcpy (p, L"\\??\\UN");
+         GetModuleFileNameW (cygwin_hmodule, p, PATH_MAX - 6);
+         *p = L'C';
+       }
+      else
+       {
+         p = wcpcpy (p, L"\\??\\");
+         GetModuleFileNameW (cygwin_hmodule, p, PATH_MAX - 4);
+       }
+    }
+  installation_root[1] = L'?';
+
+  RtlInitEmptyUnicodeString (&installation_key, installation_key_buf,
+                            sizeof installation_key_buf);
+  RtlInt64ToHexUnicodeString (hash_path_name (0, installation_root),
+                             &installation_key, FALSE);
+
+  PWCHAR w = wcsrchr (installation_root, L'\\');
+  if (w)
+    {
+      *w = L'\0';
+      w = wcsrchr (installation_root, L'\\');
+    }
+  if (!w)
+    api_fatal ("Can't initialize Cygwin installation root dir.\n"
+              "Invalid DLL path");
+  *w = L'\0';
+
+  for (int i = 1; i >= 0; --i)
+    {
+      reg_key r (i, KEY_WRITE, _WIDE (CYGWIN_INFO_INSTALLATIONS_NAME),
+                NULL);
+      if (NT_SUCCESS (r.set_string (installation_key_buf,
+                                   installation_root)))
+       break;
+    }
+
+  if (cygwin_props.disable_key)
+    {
+      installation_key.Length = 0;
+      installation_key.Buffer[0] = L'\0';
+    }
+}
+
 void __stdcall
 cygheap_init ()
 {
index 7c2380e4dd27b43b73689b9c283c00cb08cc49ca..054297bd72793bf169ca9271bca530cd5dc1b412 100644 (file)
@@ -280,6 +280,9 @@ struct init_cygheap: public mini_cygheap
 {
   _cmalloc_entry *chain;
   char *buckets[32];
+  WCHAR installation_root[PATH_MAX];
+  UNICODE_STRING installation_key;
+  WCHAR installation_key_buf[18];
   cygheap_root root;
   cygheap_user user;
   user_heap_info user_heap;
@@ -303,6 +306,7 @@ struct init_cygheap: public mini_cygheap
   } inode_list;                        /* Global inode pointer for adv. locking. */
   hook_chain hooks;
   void close_ctty ();
+  void init_installation_root ();
 };
 
 
index fa442f77108fdec4461634ab600d7f8b743a24d8..f152b82a3071044a8e5fe4d294be9bf5092c5c5c 100644 (file)
@@ -931,8 +931,9 @@ handle_to_fn (HANDLE h, char *posix_fn)
            return false;
          w32 += WCLEN (L"cygwin-");
          /* Check for installation key and trailing dash. */
-         w32len = installation_key.Length / sizeof (WCHAR);
-         if (w32len && wcsncmp (w32, installation_key.Buffer, w32len) != 0)
+         w32len = cygheap->installation_key.Length / sizeof (WCHAR);
+         if (w32len
+             && wcsncmp (w32, cygheap->installation_key.Buffer, w32len) != 0)
            return false;
          w32 += w32len;
          if (*w32 != L'-')
index e6e3493950ec2998133155a85bf2d26c8c779759..146dda9532f738aae14c6f9a2db5961551b25ca1 100644 (file)
@@ -1,7 +1,7 @@
 /* external.cc: Interface to Cygwin internals from external programs.
 
    Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-   2006, 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
+   2006, 2007, 2008, 2009, 2010, 2011, 2012 Red Hat, Inc.
 
    Written by Christopher Faylor <cgf@cygnus.com>
 
@@ -468,9 +468,8 @@ cygwin_internal (cygwin_getinfo_types t, ...)
        break;
       case CW_GET_INSTKEY:
        {
-         extern WCHAR installation_key_buf[18];
          PWCHAR dest = va_arg (arg, PWCHAR);
-         wcscpy (dest, installation_key_buf);
+         wcscpy (dest, cygheap->installation_key_buf);
          res = 0;
        }
        break;
index 134b2614132d7b96ffe2edbc4acdfbca1decc5c1..01892f69edda2ce0907f5f4ef3122145b050c9f3 100644 (file)
@@ -82,7 +82,7 @@ fhandler_console::console_state *
 fhandler_console::open_shared_console (HWND hw, HANDLE& h, bool& create)
 {
   wchar_t namebuf[(sizeof "XXXXXXXXXXXXXXXXXX-consNNNNNNNNNN")];
-  __small_swprintf (namebuf, L"%S-cons%p", &installation_key, hw);
+  __small_swprintf (namebuf, L"%S-cons%p", &cygheap->installation_key, hw);
 
   shared_locations m = create ? SH_SHARED_CONSOLE : SH_JUSTOPEN;
   console_state *res = (console_state *)
index 7e4052137e9110bd0d38742306d709c13775e1c0..52526356a5a4af7f77d25ff8b42f3188bd8aa8de 100644 (file)
@@ -1,6 +1,6 @@
 /* fhandler_mailslot.cc.  See fhandler.h for a description of the fhandler classes.
 
-   Copyright 2005, 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
+   Copyright 2005, 2007, 2008, 2009, 2010, 2011, 2012 Red Hat, Inc.
 
    This file is part of Cygwin.
 
 #include "winsup.h"
 
 #include "cygerrno.h"
+#include "security.h"
 #include "path.h"
 #include "fhandler.h"
+#include "dtable.h"
+#include "cygheap.h"
 #include "ntdll.h"
 #include "shared_info.h"
 #include "tls_pbuf.h"
@@ -51,7 +54,7 @@ fhandler_mailslot::get_object_attr (OBJECT_ATTRIBUTES &attr,
 {
 
   RtlCopyUnicodeString (path, pc.get_nt_native_path ());
-  RtlAppendUnicodeStringToString (path, &installation_key);
+  RtlAppendUnicodeStringToString (path, &cygheap->installation_key);
   InitializeObjectAttributes (&attr, path,
                              OBJ_CASE_INSENSITIVE
                              | (flags & O_CLOEXEC ? 0 : OBJ_INHERIT),
index 064dc41dc359f562fdae7f4dd45edcbde95db145..b316a0aaf922e6b75fd116243851179482847d9f 100644 (file)
@@ -488,7 +488,7 @@ fhandler_pty_slave::open (int flags, mode_t)
       DWORD len;
 
       __small_sprintf (buf, "\\\\.\\pipe\\cygwin-%S-pty%d-master-ctl",
-                      &installation_key, get_unit ());
+                      &cygheap->installation_key, get_unit ());
       termios_printf ("dup handles via master control pipe %s", buf);
       if (!CallNamedPipe (buf, &req, sizeof req, &repl, sizeof repl,
                          &len, 500))
@@ -1272,7 +1272,7 @@ fhandler_pty_master::close ()
          DWORD len;
 
          __small_sprintf (buf, "\\\\.\\pipe\\cygwin-%S-pty%d-master-ctl",
-                          &installation_key, get_unit ());
+                          &cygheap->installation_key, get_unit ());
          CallNamedPipe (buf, &req, sizeof req, &repl, sizeof repl, &len, 500);
          CloseHandle (master_ctl);
          master_thread->detach ();
@@ -1675,7 +1675,7 @@ fhandler_pty_master::setup ()
   /* Create master control pipe which allows the master to duplicate
      the pty pipe handles to processes which deserve it. */
   __small_sprintf (buf, "\\\\.\\pipe\\cygwin-%S-pty%d-master-ctl",
-                  &installation_key, unit);
+                  &cygheap->installation_key, unit);
   master_ctl = CreateNamedPipe (buf, PIPE_ACCESS_DUPLEX,
                                PIPE_WAIT | PIPE_TYPE_MESSAGE
                                | PIPE_READMODE_MESSAGE, 1, 4096, 4096,
index 5724298b35bb3860b248bfbfd94ff3001eb36a1a..ef7d746df63b4382125c811f40e1e29c07326a9e 100644 (file)
@@ -467,7 +467,7 @@ mount_info::init ()
   PWCHAR pathend;
   WCHAR path[PATH_MAX];
 
-  pathend = wcpcpy (path, installation_root);
+  pathend = wcpcpy (path, cygheap->installation_root);
   create_root_entry (path);
   pathend = wcpcpy (pathend, L"\\etc\\fstab");
 
index 6befd22221ba289ff3f759da7b4e537fedd26e35..52f2ba0580a5d952737bf79d19415e199d764865 100644 (file)
@@ -1,7 +1,7 @@
 /* pipe.cc: pipe for Cygwin.
 
    Copyright 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-   2008, 2009, 2010, 2011, 2011 Hat, Inc.
+   2008, 2009, 2010, 2011, 2012 Hat, Inc.
 
 This file is part of Cygwin.
 
@@ -212,7 +212,7 @@ fhandler_pipe::create (LPSECURITY_ATTRIBUTES sa_ptr, PHANDLE r, PHANDLE w,
 
   char pipename[MAX_PATH];
   const size_t len = __small_sprintf (pipename, PIPE_INTRO "%S-",
-                                     &installation_key);
+                                     &cygheap->installation_key);
   if (name)
     strcpy (pipename + len, name);
 
index e9f46133812973ecfaa66e0ea6ff910ed6ff9275..86f93c269e058d754066938af4d9434944004c1b 100644 (file)
@@ -1,7 +1,7 @@
 /* shared.cc: shared data area support.
 
    Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-   2006, 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
+   2006, 2007, 2008, 2009, 2010, 2011, 2012 Red Hat, Inc.
 
 This file is part of Cygwin.
 
@@ -34,96 +34,6 @@ user_info NO_COPY *user_shared;
 HANDLE NO_COPY cygwin_shared_h;
 HANDLE NO_COPY cygwin_user_h;
 
-WCHAR installation_root[PATH_MAX] __attribute__((section (".cygwin_dll_common"), shared));
-UNICODE_STRING installation_key __attribute__((section (".cygwin_dll_common"), shared));
-WCHAR installation_key_buf[18] __attribute__((section (".cygwin_dll_common"), shared));
-static LONG installation_root_inited __attribute__((section (".cygwin_dll_common"), shared));
-
-#define SPIN_WAIT 10000
-
-/* Use absolute path of cygwin1.dll to derive the Win32 dir which
-   is our installation_root.  Note that we can't handle Cygwin installation
-   root dirs of more than 4K path length.  I assume that's ok...
-
-   This function also generates the installation_key value.  It's a 64 bit
-   hash value based on the path of the Cygwin DLL itself.  It's subsequently
-   used when generating shared object names.  Thus, different Cygwin
-   installations generate different object names and so are isolated from
-   each other.
-
-   Having this information, the installation key together with the
-   installation root path is written to the registry.  The idea is that
-   cygcheck can print the paths into which the Cygwin DLL has been
-   installed for debugging purposes.
-
-   Last but not least, the new cygwin properties datastrcuture is checked
-   for the "disabled_key" value, which is used to determine whether the
-   installation key is actually added to all object names or not.  This is
-   used as a last resort for debugging purposes, usually.  However, there
-   could be another good reason to re-enable object name collisions between
-   multiple Cygwin DLLs, which we're just not aware of right now.  Cygcheck
-   can be used to change the value in an existing Cygwin DLL binary. */
-
-void inline
-init_installation_root ()
-{
-  spinlock iri (installation_root_inited);
-  if (!iri)
-    {
-      if (!GetModuleFileNameW (cygwin_hmodule, installation_root, PATH_MAX))
-       api_fatal ("Can't initialize Cygwin installation root dir.\n"
-                  "GetModuleFileNameW(%p, %p, %u), %E",
-                  cygwin_hmodule, installation_root, PATH_MAX);
-      PWCHAR p = installation_root;
-      if (wcsncmp (p, L"\\\\?\\", 4))  /* No long path prefix. */
-       {
-         if (!wcsncasecmp (p, L"\\\\", 2))     /* UNC */
-           {
-             p = wcpcpy (p, L"\\??\\UN");
-             GetModuleFileNameW (cygwin_hmodule, p, PATH_MAX - 6);
-             *p = L'C';
-           }
-         else
-           {
-             p = wcpcpy (p, L"\\??\\");
-             GetModuleFileNameW (cygwin_hmodule, p, PATH_MAX - 4);
-           }
-       }
-      installation_root[1] = L'?';
-
-      RtlInitEmptyUnicodeString (&installation_key, installation_key_buf,
-                                sizeof installation_key_buf);
-      RtlInt64ToHexUnicodeString (hash_path_name (0, installation_root),
-                                 &installation_key, FALSE);
-
-      PWCHAR w = wcsrchr (installation_root, L'\\');
-      if (w)
-       {
-         *w = L'\0';
-         w = wcsrchr (installation_root, L'\\');
-       }
-      if (!w)
-       api_fatal ("Can't initialize Cygwin installation root dir.\n"
-                  "Invalid DLL path");
-      *w = L'\0';
-
-      for (int i = 1; i >= 0; --i)
-       {
-         reg_key r (i, KEY_WRITE, _WIDE (CYGWIN_INFO_INSTALLATIONS_NAME),
-                    NULL);
-         if (NT_SUCCESS (r.set_string (installation_key_buf,
-                                       installation_root)))
-           break;
-       }
-
-      if (cygwin_props.disable_key)
-       {
-         installation_key.Length = 0;
-         installation_key.Buffer[0] = L'\0';
-       }
-    }
-}
-
 /* This function returns a handle to the top-level directory in the global
    NT namespace used to implement global objects including shared memory. */
 
@@ -142,7 +52,7 @@ get_shared_parent_dir ()
       __small_swprintf (bnoname, L"\\BaseNamedObjects\\%s%s-%S",
                        cygwin_version.shared_id,
                        _cygwin_testing ? cygwin_version.dll_build_date : "",
-                       &installation_key);
+                       &cygheap->installation_key);
       RtlInitUnicodeString (&uname, bnoname);
       InitializeObjectAttributes (&attr, &uname, OBJ_OPENIF, NULL,
                                  everyone_sd (CYG_SHARED_DIR_ACCESS));
@@ -178,7 +88,7 @@ get_session_parent_dir ()
                            L"\\Sessions\\BNOLINKS\\%d\\%s%s-%S",
                            psi.SessionId, cygwin_version.shared_id,
                            _cygwin_testing ? cygwin_version.dll_build_date : "",
-                           &installation_key);
+                           &cygheap->installation_key);
          RtlInitUnicodeString (&uname, bnoname);
          InitializeObjectAttributes (&attr, &uname, OBJ_OPENIF, NULL,
                                      everyone_sd(CYG_SHARED_DIR_ACCESS));
@@ -422,7 +332,7 @@ shared_info::initialize ()
         up to this point.  Debug output except for system_printf requires
         the global shared memory to exist. */
       debug_printf ("Installation root: <%W> key: <%S>",
-                   installation_root, &installation_key);
+                   cygheap->installation_root, &cygheap->installation_key);
     }
   else if (sversion != (LONG) CURR_SHARED_MAGIC)
     sversion.multiple_cygwin_problem ("system shared memory version",
@@ -441,9 +351,9 @@ memory_init (bool init_cygheap)
     {
       cygheap_init ();
       cygheap->user.init ();
+      cygheap->init_installation_root (); /* Requires user.init! */
     }
 
-  init_installation_root ();   /* Initialize installation root dir */
   shared_info::create ();      /* Initialize global shared memory */
   user_info::create (false);   /* Initialize per-user shared memory */
 }
index e6f9c832e30755401dd7e3e0e4635fa3c3b1baa1..a569ea5ba1c1263cfe9efcbaca4bdac179b3e855 100644 (file)
@@ -1,7 +1,7 @@
 /* shared_info.h: shared info for cygwin
 
    Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009,
-   2010, 2011 Red Hat, Inc.
+   2010, 2011, 2012 Red Hat, Inc.
 
 This file is part of Cygwin.
 
@@ -93,6 +93,3 @@ void *__stdcall open_shared (const WCHAR *, int, HANDLE&, DWORD,
                             shared_locations *, PSECURITY_ATTRIBUTES = &sec_all,
                             DWORD = FILE_MAP_READ | FILE_MAP_WRITE);
 extern void user_shared_create (bool reinit);
-extern void init_installation_root ();
-extern WCHAR installation_root[PATH_MAX];
-extern UNICODE_STRING installation_key;
index e0f6e910d7b59660f10b91332d8332b098de69bb..a26ccb88e84274ed6fffc305471f2f0aefaac789 100644 (file)
@@ -549,13 +549,13 @@ pwdgrp::load (const wchar_t *rel_path)
   curr_lines = 0;
 
   if (!path &&
-      !(path = (PWCHAR) malloc ((wcslen (installation_root)
+      !(path = (PWCHAR) malloc ((wcslen (cygheap->installation_root)
                                 + wcslen (rel_path) + 1) * sizeof (WCHAR))))
     {
       paranoid_printf ("malloc (%W) failed", rel_path);
       goto out;
     }
-  wcpcpy (wcpcpy (path, installation_root), rel_path);
+  wcpcpy (wcpcpy (path, cygheap->installation_root), rel_path);
   RtlInitUnicodeString (&upath, path);
 
   InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE, NULL, NULL);
This page took 0.076009 seconds and 5 git commands to generate.