From bfce73c261fd9da02ce1d25a4a466ece1b3a55ea Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 27 May 2011 06:11:05 +0000 Subject: [PATCH] * 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. --- winsup/cygwin/ChangeLog | 8 ++++++++ winsup/cygwin/shared.cc | 23 ++++++++++++++--------- winsup/cygwin/shared_info.h | 2 +- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index dec2d507d..ba73a2682 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,11 @@ +2011-05-27 Corinna Vinschen + + * 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 * mount.h (MAX_MOUNTS): Raise to 64. diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc index 0bfd4be8d..b505cc947 100644 --- a/winsup/cygwin/shared.cc +++ b/winsup/cygwin/shared.cc @@ -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 */ diff --git a/winsup/cygwin/shared_info.h b/winsup/cygwin/shared_info.h index 8a6a3f8fc..408a65eae 100644 --- a/winsup/cygwin/shared_info.h +++ b/winsup/cygwin/shared_info.h @@ -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 -- 2.43.5