* dcrt0.cc (dll_crt0_0): Check for wincap.wow64_has_secondary_stack

rather than for wincap.is_wow64.  Accommodate name change from
	wow64_has_64bit_parent to wow64_needs_stack_adjustment.  Align comment.
	(_dll_crt0): Ditto.
	* wincap.h (wincaps::wow64_has_secondary_stack): New element.
	* wincap.cc: Implement above element throughout.
	(wincapc::init): Set wow64_has_secondary_stack to false on non-64 bit
	systems.
	* wow64.cc (wow64_needs_stack_adjustment): Rename (hopefully the last
	time) from wow64_has_64bit_parent.
	(wow64_eval_expected_main_stack): Fix comment to reflect real life.
	(wow64_test_for_64bit_parent): Fix comment.
	* wow64.h (wow64_needs_stack_adjustment): Accommodate new name.
This commit is contained in:
Corinna Vinschen 2011-12-19 12:50:35 +00:00
parent 93a61a6fe3
commit f08bc85858
6 changed files with 53 additions and 17 deletions

View File

@ -1,3 +1,19 @@
2011-12-19 Corinna Vinschen <vinschen@redhat.com>
* dcrt0.cc (dll_crt0_0): Check for wincap.wow64_has_secondary_stack
rather than for wincap.is_wow64. Accommodate name change from
wow64_has_64bit_parent to wow64_needs_stack_adjustment. Align comment.
(_dll_crt0): Ditto.
* wincap.h (wincaps::wow64_has_secondary_stack): New element.
* wincap.cc: Implement above element throughout.
(wincapc::init): Set wow64_has_secondary_stack to false on non-64 bit
systems.
* wow64.cc (wow64_needs_stack_adjustment): Rename (hopefully the last
time) from wow64_has_64bit_parent.
(wow64_eval_expected_main_stack): Fix comment to reflect real life.
(wow64_test_for_64bit_parent): Fix comment.
* wow64.h (wow64_needs_stack_adjustment): Accommodate new name.
2011-12-17 Christopher Faylor <me.cygwin2011@cgf.cx>
* fhandler.cc (fhandler_base::close): Move setting isclosed() from here

View File

@ -705,11 +705,12 @@ dll_crt0_0 ()
if (!child_proc_info)
{
memory_init (true);
/* WOW64 process? Check if we have been started from 64 bit process
and if our stack is at an unusual address. Set wow64_has_64bit_parent
if so. Problem description in wow64_test_for_64bit_parent. */
if (wincap.is_wow64 ())
wow64_has_64bit_parent = wow64_test_for_64bit_parent ();
/* WOW64 process on XP/64 or Server 2003/64? Check if we have been
started from 64 bit process and if our stack is at an unusual
address. Set wow64_needs_stack_adjustment if so. Problem
description in wow64_test_for_64bit_parent. */
if (wincap.wow64_has_secondary_stack ())
wow64_needs_stack_adjustment = wow64_test_for_64bit_parent ();
}
else
{
@ -945,9 +946,10 @@ __cygwin_exit_return: \n\
extern "C" void __stdcall
_dll_crt0 ()
{
/* Handle WOW64 process started from native 64 bit process. See comment
in wow64_test_for_64bit_parent for a full problem description. */
if (wow64_has_64bit_parent && !dynamically_loaded)
/* Handle WOW64 process on XP/2K3 which has been started from native 64 bit
process. See comment in wow64_test_for_64bit_parent for a full problem
description. */
if (wow64_needs_stack_adjustment && !dynamically_loaded)
{
/* Must be static since it's referenced after the stack pointers have
been moved. */

View File

@ -52,6 +52,7 @@ wincaps wincap_2000 __attribute__((section (".cygwin_dll_common"), shared)) = {
use_dont_resolve_hack:false,
has_stack_size_param_is_a_reservation:false,
has_console_logon_sid:false,
wow64_has_secondary_stack:false,
};
wincaps wincap_2000sp4 __attribute__((section (".cygwin_dll_common"), shared)) = {
@ -83,6 +84,7 @@ wincaps wincap_2000sp4 __attribute__((section (".cygwin_dll_common"), shared)) =
use_dont_resolve_hack:false,
has_stack_size_param_is_a_reservation:false,
has_console_logon_sid:false,
wow64_has_secondary_stack:false,
};
wincaps wincap_xp __attribute__((section (".cygwin_dll_common"), shared)) = {
@ -114,6 +116,7 @@ wincaps wincap_xp __attribute__((section (".cygwin_dll_common"), shared)) = {
use_dont_resolve_hack:true,
has_stack_size_param_is_a_reservation:true,
has_console_logon_sid:false,
wow64_has_secondary_stack:false,
};
wincaps wincap_xpsp1 __attribute__((section (".cygwin_dll_common"), shared)) = {
@ -145,6 +148,7 @@ wincaps wincap_xpsp1 __attribute__((section (".cygwin_dll_common"), shared)) = {
use_dont_resolve_hack:true,
has_stack_size_param_is_a_reservation:true,
has_console_logon_sid:false,
wow64_has_secondary_stack:false,
};
wincaps wincap_xpsp2 __attribute__((section (".cygwin_dll_common"), shared)) = {
@ -176,6 +180,7 @@ wincaps wincap_xpsp2 __attribute__((section (".cygwin_dll_common"), shared)) = {
use_dont_resolve_hack:true,
has_stack_size_param_is_a_reservation:true,
has_console_logon_sid:false,
wow64_has_secondary_stack:false,
};
wincaps wincap_2003 __attribute__((section (".cygwin_dll_common"), shared)) = {
@ -207,6 +212,7 @@ wincaps wincap_2003 __attribute__((section (".cygwin_dll_common"), shared)) = {
use_dont_resolve_hack:true,
has_stack_size_param_is_a_reservation:true,
has_console_logon_sid:false,
wow64_has_secondary_stack:true,
};
wincaps wincap_vista __attribute__((section (".cygwin_dll_common"), shared)) = {
@ -238,6 +244,7 @@ wincaps wincap_vista __attribute__((section (".cygwin_dll_common"), shared)) = {
use_dont_resolve_hack:false,
has_stack_size_param_is_a_reservation:true,
has_console_logon_sid:false,
wow64_has_secondary_stack:false,
};
wincaps wincap_7 __attribute__((section (".cygwin_dll_common"), shared)) = {
@ -269,6 +276,7 @@ wincaps wincap_7 __attribute__((section (".cygwin_dll_common"), shared)) = {
use_dont_resolve_hack:false,
has_stack_size_param_is_a_reservation:true,
has_console_logon_sid:true,
wow64_has_secondary_stack:false,
};
wincapc wincap __attribute__((section (".cygwin_dll_common"), shared));
@ -356,6 +364,7 @@ wincapc::init ()
{
((wincaps *)caps)->needs_count_in_si_lpres2 = false;
((wincaps *)caps)->has_restricted_stack_args = false;
((wincaps *)caps)->wow64_has_secondary_stack = false;
}
__small_sprintf (osnam, "NT-%d.%d", version.dwMajorVersion,

View File

@ -42,6 +42,7 @@ struct wincaps
unsigned use_dont_resolve_hack : 1;
unsigned has_stack_size_param_is_a_reservation : 1;
unsigned has_console_logon_sid : 1;
unsigned wow64_has_secondary_stack : 1;
};
class wincapc
@ -92,6 +93,7 @@ public:
bool IMPLEMENT (use_dont_resolve_hack)
bool IMPLEMENT (has_stack_size_param_is_a_reservation)
bool IMPLEMENT (has_console_logon_sid)
bool IMPLEMENT (wow64_has_secondary_stack)
#undef IMPLEMENT
};

View File

@ -15,7 +15,7 @@ details. */
#define PTR_ADD(p,o) ((PVOID)((PBYTE)(p)+(o)))
bool NO_COPY wow64_has_64bit_parent = false;
bool NO_COPY wow64_needs_stack_adjustment = false;
static void
wow64_eval_expected_main_stack (PVOID &allocbase, PVOID &stackbase)
@ -27,10 +27,17 @@ wow64_eval_expected_main_stack (PVOID &allocbase, PVOID &stackbase)
dosheader = (PIMAGE_DOS_HEADER) GetModuleHandle (NULL);
ntheader = (PIMAGE_NT_HEADERS32) ((PBYTE) dosheader + dosheader->e_lfanew);
/* The main thread stack is expected to be located at 0x30000, which is the
case for all observed NT systems to date, unless the stacksize requested
by the StackReserve field in the PE/COFF header is so big that the stack
doesn't fit in the area between 0x30000 and the start of the image. In
case of a conflict, the OS allocates the stack right after the image. */
case for all observed NT systems up to Server 2003 R2, unless the
stacksize requested by the StackReserve field in the PE/COFF header is
so big that the stack doesn't fit in the area between 0x30000 and the
start of the image. In case of a conflict, the OS allocates the stack
right after the image.
Sidenote: While post-2K3 32 bit systems continue to have the default
main thread stack address located at 0x30000, the default main thread
stack address on Vista/2008 64 bit is 0x80000 and on W7/2K8R2 64 bit
it is 0x90000. However, this is no problem because the system sticks
to that address for all WOW64 processes, not only for the first one
started from a 64 bit parent. */
allocbase = (PVOID) 0x30000;
/* Stack size. The OS always rounds the size up to allocation granularity
and it never allocates less than 256K. */
@ -62,9 +69,9 @@ wow64_test_for_64bit_parent ()
else in the child process.
What we do here is to check if the current stack is the excpected main
thread stack and if not, if we really have been started from a 64 bit
process here. If so, we note this fact in wow64_has_64bit_parent so we
can workaround the stack problem in _dll_crt0. See there for how we go
along. */
process here. If so, we note this fact in wow64_needs_stack_adjustment
so we can workaround the stack problem in _dll_crt0. See there for how
we go along. */
NTSTATUS ret;
PROCESS_BASIC_INFORMATION pbi;
HANDLE parent;

View File

@ -8,7 +8,7 @@ This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
extern bool NO_COPY wow64_has_64bit_parent;
extern bool NO_COPY wow64_needs_stack_adjustment;
extern bool wow64_test_for_64bit_parent ();
extern PVOID wow64_revert_to_original_stack (PVOID &allocationbase);