Hi all,
This is the first of a series of patches, sent in separate emails as
requested.
The first patch allows a child which failed due to address space
clobbers to report cleanly back to the parent. As a result, DLL_LINK
which land wrong, DLL_LOAD whose space gets clobbered, and failure to
replicate the cygheap, generate retries and dispense with the terminal
spam. Handling of unexpected errors should not have changed. Further,
the patch fixes several sources of access violations and crashes,
including:
- accessing invalid state after failing to notice that a
statically-linked dll loaded at the wrong location
- accessing invalid state while running dtors on a failed forkee. I
follow cgf's approach of simply not running any dtors, based on the
observation that dlls in the parent (gcc_s!) can store state about other
dlls and crash trying to access that state in the child, even if they
appeared to map properly in both processes.
- attempting to generate a stack trace when somebody in the call chain
used alloca(). This one is only sidestepped here, because we eliminate
the access violations and api_fatal calls which would have triggered the
problematic stack traces. I have a separate patch which allows offending
functions to disable stack traces, if folks are interested, but it was
kind of noisy so I left it out for now (cygwin uses alloca pretty
liberally!).
Ryan
diff --git a/child_info.h b/child_info.h
--- a/child_info.h
+++ b/child_info.h
@@ -92,6 +92,18 @@ public:
void alloc_stack_hard_way (volatile char *);
};
+/* Several well-known problems can prevent us from patching up a
+ forkee; when such errors arise the child should exit cleanly (with
+ a failure code for the parent) rather than dumping stack. */
+#define fork_api_fatal(fmt, args...) \
+ do \
+ { \
+ sigproc_printf (fmt,## args); \
+ fork_info->handle_failure (-1); \
+ } \
+ while(0)
+
+
class fhandler_base;
class cygheap_exec_info
diff --git a/dll_init.cc b/dll_init.cc
--- a/dll_init.cc
+++ b/dll_init.cc
@@ -19,6 +19,7 @@ details. */
#include "dtable.h"
#include "cygheap.h"
#include "pinfo.h"
+#include "child_info.h"
#include "cygtls.h"
#include "exception.h"
#include<wchar.h>
@@ -131,10 +132,16 @@ dll_list::alloc (HINSTANCE h, per_proces
{
if (!in_forkee)
d->count++; /* Yes. Bump the usage count. */
+ else if (d->handle != h)
+ fork_api_fatal ("Location of %W changed from %p (parent) to %p (child)",
+ d->name, d->handle, h);