OSDN Git Service

* shared.cc (offsets): Reorder so that console_state is lowest in
authorcorinna <corinna>
Fri, 27 May 2011 06:11:04 +0000 (06:11 +0000)
committercorinna <corinna>
Fri, 27 May 2011 06:11:04 +0000 (06:11 +0000)
memory.  Explain why.
(open_shared): Accommodate reordering of offsets array.
* shared_info.h (shared_locations): Reorder SH_SHARED_CONSOLE after
SH_MYSELF.

winsup/cygwin/ChangeLog
winsup/cygwin/shared.cc
winsup/cygwin/shared_info.h

index dec2d50..ba73a26 100644 (file)
@@ -1,3 +1,11 @@
+2011-05-27  Corinna Vinschen  <corinna@vinschen.de>
+
+       * shared.cc (offsets): Reorder so that console_state is lowest in
+       memory.  Explain why.
+       (open_shared): Accommodate reordering of offsets array.
+       * shared_info.h (shared_locations): Reorder SH_SHARED_CONSOLE after
+       SH_MYSELF.
+
 2011-05-26  Corinna Vinschen  <corinna@vinschen.de>
 
        * mount.h (MAX_MOUNTS): Raise to 64.
index 0bfd4be..b505cc9 100644 (file)
@@ -204,18 +204,24 @@ shared_name (WCHAR *ret_buf, const WCHAR *str, int num)
 #define page_const (65535)
 #define pround(n) (((size_t) (n) + page_const) & ~page_const)
 
+/* The order in offsets is so that the constant blocks shared_info
+   and user_info are right below the cygwin DLL, then the pinfo block
+   which changes with each process.  Below that is the console_state,
+   an optional block which only exists when running in a Windows console
+   window.  Therefore, if we are not running in a console, we have 64K
+   more of contiguous memory below the Cygwin DLL. */
 static ptrdiff_t offsets[] =
 {
+  - pround (sizeof (shared_info)),
+  - pround (sizeof (shared_info))
+  - pround (sizeof (user_info)),
   - pround (sizeof (shared_info))
   - pround (sizeof (user_info))
-  - pround (sizeof (console_state))
   - pround (sizeof (_pinfo)),
+  - pround (sizeof (shared_info))
   - pround (sizeof (user_info))
-  - pround (sizeof (console_state))
-  - pround (sizeof (_pinfo)),
-  - pround (sizeof (console_state))
-  - pround (sizeof (_pinfo)),
-  - pround (sizeof (_pinfo)),
+  - pround (sizeof (_pinfo))
+  - pround (sizeof (console_state)),
   0
 };
 
@@ -269,8 +275,7 @@ open_shared (const WCHAR *name, int n, HANDLE& shared_h, DWORD size,
        return NULL;
     }
 
-  shared = (shared_info *)
-    MapViewOfFileEx (shared_h, access, 0, 0, 0, addr);
+  shared = (shared_info *) MapViewOfFileEx (shared_h, access, 0, 0, 0, addr);
 
   if (!shared && addr)
     {
@@ -292,7 +297,7 @@ open_shared (const WCHAR *name, int n, HANDLE& shared_h, DWORD size,
       offsets[0] = (caddr_t) shared - (caddr_t) cygwin_hmodule;
       for (int i = SH_USER_SHARED + 1; i < SH_TOTAL_SIZE; i++)
        {
-         unsigned size = offsets[i + 1] - offsets[i];
+         unsigned size = offsets[i] - offsets[i + 1];
          offsets[i] += delta;
          if (!VirtualAlloc (off_addr (i), size, MEM_RESERVE, PAGE_NOACCESS))
            continue;  /* oh well */
index 8a6a3f8..408a65e 100644 (file)
@@ -64,8 +64,8 @@ enum shared_locations
 {
   SH_CYGWIN_SHARED,
   SH_USER_SHARED,
-  SH_SHARED_CONSOLE,
   SH_MYSELF,
+  SH_SHARED_CONSOLE,
   SH_TOTAL_SIZE,
   SH_JUSTCREATE,
   SH_JUSTOPEN