From aaf219f01e5cd7fac54fafae24974e06a737b9ee Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Wed, 26 Dec 2001 21:35:16 +0000 Subject: [PATCH] * cygmagic: Add define name to warning. * dcrt0.cc (_dll_crt0): Check for changes in child_info size. (multiple_cygwin_problem): Avoid "proc" errors when testing. Just assume new cygwin proc. * shared_info.h (mount_info): Add 'cb' element for sanity checks. (shared_info): Ditto. * child_info.h (child_info): Add fhandler_union_size element for sanity checking. * shared.cc (open_shared): Detect shared region size mismatch between parent and child. (shared_info::initialize): Detect shared region size mismatch with expectation. (memory_Init): Ditto. * sigproc.cc (init_child_info): Correctly set cb in passed structure. * shared.cc (open_shared): --- winsup/cygwin/ChangeLog | 18 ++++++++++++++++++ winsup/cygwin/child_info.h | 3 ++- winsup/cygwin/cygmagic | 2 +- winsup/cygwin/dcrt0.cc | 26 ++++++++++++++++++++------ winsup/cygwin/shared.cc | 20 ++++++++++++++++---- winsup/cygwin/shared_info.h | 12 ++++++++---- winsup/cygwin/sigproc.cc | 3 ++- 7 files changed, 67 insertions(+), 17 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index bafc5c7d2..dad164f6d 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,21 @@ +2001-12-26 Christopher Faylor + + * cygmagic: Add define name to warning. + * dcrt0.cc (_dll_crt0): Check for changes in child_info size. + (multiple_cygwin_problem): Avoid "proc" errors when testing. Just + assume new cygwin proc. + * shared_info.h (mount_info): Add 'cb' element for sanity checks. + (shared_info): Ditto. + * child_info.h (child_info): Add fhandler_union_size element for sanity + checking. + * shared.cc (open_shared): Detect shared region size mismatch between + parent and child. + (shared_info::initialize): Detect shared region size mismatch with + expectation. + (memory_Init): Ditto. + * sigproc.cc (init_child_info): Correctly set cb in passed structure. + * shared.cc (open_shared): + 2001-12-26 Christopher Faylor * include/getopt.h: Protect a declaratin. diff --git a/winsup/cygwin/child_info.h b/winsup/cygwin/child_info.h index 36dcd95aa..4b249a808 100644 --- a/winsup/cygwin/child_info.h +++ b/winsup/cygwin/child_info.h @@ -28,7 +28,7 @@ enum #define EXEC_MAGIC_SIZE sizeof(child_info) -#define CURR_CHILD_INFO_MAGIC 0xba17 +#define CURR_CHILD_INFO_MAGIC 0x8b3c /* NOTE: Do not make gratuitous changes to the names or organization of the below class. The layout is checksummed to determine compatibility between @@ -49,6 +49,7 @@ public: init_cygheap *cygheap; void *cygheap_max; HANDLE cygheap_h; + unsigned fhandler_union_cb; }; class child_info_fork: public child_info diff --git a/winsup/cygwin/cygmagic b/winsup/cygwin/cygmagic index 17c74b496..f63531dee 100755 --- a/winsup/cygwin/cygmagic +++ b/winsup/cygwin/cygmagic @@ -14,7 +14,7 @@ while [ -n "$1" ]; do echo "#define $define $sum" curr=`sed -n "s/^#[ ]*define CURR_$define[ ][ ]*\([^ ][^ ]*\)/\1/p" $file` [ "$curr" == "$sum" ] || echo "*** WARNING WARNING WARNING WARNING WARNING *** -*** $file: magic number changed old $curr != new $sum +*** $file: magic number for $define changed old $curr != new $sum *** WARNING WARNING WARNING WARNING WARNING ***" 1>&2 done >> $file_magic exit 0 diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index a6a446f5e..c68a2bc12 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -831,20 +831,29 @@ _dll_crt0 () else if (fork_info->intro == PROC_MAGIC_GENERIC && fork_info->magic != CHILD_INFO_MAGIC) multiple_cygwin_problem ("proc", fork_info->magic, CHILD_INFO_MAGIC); + unsigned should_be_cb = 0; switch (fork_info->type) { case _PROC_FORK: user_data->forkee = fork_info->cygpid; + should_be_cb = sizeof (child_info_fork); case _PROC_SPAWN: if (fork_info->pppid_handle) CloseHandle (fork_info->pppid_handle); case _PROC_EXEC: - { - child_proc_info = fork_info; - cygwin_mount_h = child_proc_info->mount_h; - mypid = child_proc_info->cygpid; - break; - } + if (!should_be_cb) + should_be_cb = sizeof (child_info); + if (should_be_cb != fork_info->cb) + multiple_cygwin_problem ("proc size", fork_info->cb, should_be_cb); + else if (sizeof (fhandler_union) != fork_info->fhandler_union_cb) + multiple_cygwin_problem ("fhandler size", fork_info->fhandler_union_cb, sizeof (fhandler_union)); + else + { + child_proc_info = fork_info; + cygwin_mount_h = child_proc_info->mount_h; + mypid = child_proc_info->cygpid; + break; + } default: system_printf ("unknown exec type %d", fork_info->type); fork_info = NULL; @@ -1025,6 +1034,11 @@ __api_fatal (const char *fmt, ...) void multiple_cygwin_problem (const char *what, unsigned magic_version, unsigned version) { + if (_cygwin_testing && strstr (what, "proc")) + { + fork_info = NULL; + return; + } if (CYGWIN_VERSION_MAGIC_VERSION (magic_version) != version) api_fatal ("%s version mismatch detected - %p/%p.\n\ You have multiple copies of cygwin1.dll on your system.\n\ diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc index db99b0737..f10fd7f10 100644 --- a/winsup/cygwin/shared.cc +++ b/winsup/cygwin/shared.cc @@ -103,10 +103,12 @@ open_shared (const char *name, int n, HANDLE &shared_h, DWORD size, void *addr) void shared_info::initialize () { - if (inited) + if (version) { - if (inited != SHARED_VERSION_MAGIC) - multiple_cygwin_problem ("shared", inited, SHARED_VERSION); + if (version != SHARED_VERSION_MAGIC) + multiple_cygwin_problem ("shared", version, SHARED_VERSION); + else if (cb != SHARED_INFO_CB) + multiple_cygwin_problem ("shared size", cb, SHARED_INFO_CB); return; } @@ -115,7 +117,11 @@ shared_info::initialize () /* Initialize tty table. */ tty.init (); - inited = SHARED_VERSION_MAGIC; + version = SHARED_VERSION_MAGIC; + cb = sizeof (*this); + if (cb != SHARED_INFO_CB) + system_printf ("size of shared memory region changed from %u to %u", + SHARED_INFO_CB, cb); } void __stdcall @@ -162,10 +168,16 @@ memory_init () { mount_table->version = MOUNT_VERSION_MAGIC; debug_printf ("initializing mount table"); + mount_table->cb = sizeof (*mount_table); + if (mount_table->cb != MOUNT_INFO_CB) + system_printf ("size of mount table region changed from %u to %u", + MOUNT_INFO_CB, mount_table->cb); mount_table->init (); /* Initialize the mount table. */ } else if (mount_table->version != MOUNT_VERSION_MAGIC) multiple_cygwin_problem ("mount", mount_table->version, MOUNT_VERSION); + else if (mount_table->cb != MOUNT_INFO_CB) + multiple_cygwin_problem ("mount table size", mount_table->cb, MOUNT_INFO_CB); } diff --git a/winsup/cygwin/shared_info.h b/winsup/cygwin/shared_info.h index e8fa45cb1..16d71eef6 100644 --- a/winsup/cygwin/shared_info.h +++ b/winsup/cygwin/shared_info.h @@ -17,7 +17,6 @@ class mount_item public: /* FIXME: Nasty static allocation. Need to have a heap in the shared area [with the user being able to configure at runtime the max size]. */ - /* Win32-style mounted partition source ("C:\foo\bar"). native_path[0] == 0 for unused entries. */ char native_path[MAX_PATH]; @@ -42,7 +41,8 @@ class mount_item #define MOUNT_VERSION 27 // increment when mount table changes and #define MOUNT_VERSION_MAGIC CYGWIN_VERSION_MAGIC (MOUNT_MAGIC, MOUNT_VERSION) -#define CURR_MOUNT_MAGIC 0xfe35 +#define CURR_MOUNT_MAGIC 0x41e0 +#define MOUNT_INFO_CB 16488 class reg_key; @@ -53,6 +53,7 @@ class mount_info { public: DWORD version; + unsigned cb; DWORD sys_mount_table_counter; int nmounts; mount_item mount[MAX_MOUNTS]; @@ -138,14 +139,17 @@ public: cygwin_version.api_minor) #define SHARED_VERSION_MAGIC CYGWIN_VERSION_MAGIC (SHARED_MAGIC, SHARED_VERSION) -#define CURR_SHARED_MAGIC 0x6f6e +#define SHARED_INFO_CB 47112 + +#define CURR_SHARED_MAGIC 0x88e /* NOTE: Do not make gratuitous changes to the names or organization of the below class. The layout is checksummed to determine compatibility between different cygwin versions. */ class shared_info { - DWORD inited; + DWORD version; + DWORD cb; public: int heap_chunk_in_mb; DWORD sys_mount_table_counter; diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 6527313ec..2e409820a 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -857,13 +857,14 @@ void __stdcall init_child_info (DWORD chtype, child_info *ch, pid_t pid, HANDLE subproc_ready) { memset (ch, 0, sizeof *ch); - ch->cb = sizeof *ch; + ch->cb = chtype == PROC_FORK ? sizeof (child_info_fork) : sizeof (child_info); ch->intro = PROC_MAGIC_GENERIC; ch->magic = CHILD_INFO_MAGIC; ch->type = chtype; ch->cygpid = pid; ch->subproc_ready = subproc_ready; ch->pppid_handle = myself->ppid_handle; + ch->fhandler_union_cb = sizeof (fhandler_union); } /* Check the state of all of our children to see if any are stopped or