From f500a700b15d6a55202cfac4cc05039ba23e9361 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 21 Dec 2011 17:19:48 +0000 Subject: [PATCH] * dcrt0.cc (_dll_crt0): Rephrase comments. Set $ebp to NULL, as in the pthread stack setup. * wow64.cc (wow64_revert_to_original_stack): Rephrase some comments. Return _tlsbase-16 rather than _main_tls-4 so as not to waste stack. --- winsup/cygwin/ChangeLog | 7 +++++++ winsup/cygwin/dcrt0.cc | 12 +++++++----- winsup/cygwin/wow64.cc | 10 ++++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 507593289..039affeba 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +2011-12-11 Corinna Vinschen + + * dcrt0.cc (_dll_crt0): Rephrase comments. Set $ebp to NULL, as in + the pthread stack setup. + * wow64.cc (wow64_revert_to_original_stack): Rephrase some comments. + Return _tlsbase-16 rather than _main_tls-4 so as not to waste stack. + 2011-12-19 Corinna Vinschen * syscalls.cc (rename): Fix typo in comment. Fix condition to handle diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 8d5017715..827ab143d 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -951,19 +951,21 @@ _dll_crt0 () description. */ if (wow64_needs_stack_adjustment && !dynamically_loaded) { - /* Must be static since it's referenced after the stack pointers have - been moved. */ + /* Must be static since it's referenced after the stack and frame + pointer registers have been changed. */ static PVOID allocationbase = 0; - /* Check if we just move the stack. See comment in + /* Check if we just move the stack. If so, wow64_revert_to_original_stack + returns a non-NULL, 16 byte aligned address. See comments in wow64_revert_to_original_stack for the gory details. */ PVOID stackaddr = wow64_revert_to_original_stack (allocationbase); if (stackaddr) { - /* 2nd half of the stack move. Set stack pointers to new address. */ + /* 2nd half of the stack move. Set stack pointer to new address. + Set frame pointer to 0. */ __asm__ ("\n\ movl %[ADDR], %%esp \n\ - movl %%esp, %%ebp \n" + xorl %%ebp, %%ebp \n" : : [ADDR] "r" (stackaddr)); /* Now we're back on the original stack. Free up space taken by the former main thread stack and set DeallocationStack correctly. */ diff --git a/winsup/cygwin/wow64.cc b/winsup/cygwin/wow64.cc index 342b7edbf..35dd5cda9 100644 --- a/winsup/cygwin/wow64.cc +++ b/winsup/cygwin/wow64.cc @@ -128,7 +128,8 @@ wow64_revert_to_original_stack (PVOID &allocationbase) /* Next we expect a guard page. We fetch the size of the guard area to see how big it is. Apparently the guard area on 64 bit systems spans - 2 pages. */ + 2 pages, only for the main thread for some reason. We better keep it + that way. */ PVOID addr = PTR_ADD (mbi.BaseAddress, mbi.RegionSize); VirtualQuery (addr, &mbi, sizeof mbi); if (mbi.AllocationBase != allocationbase @@ -163,12 +164,13 @@ wow64_revert_to_original_stack (PVOID &allocationbase) /* We're going to reuse the original stack. Yay, no more respawn! Set the StackBase and StackLimit values in the TEB, set _main_tls - accordingly, and return the new address for the stack pointer. - The second half of the stack move is done by the caller _dll_crt0. */ + accordingly, and return the new, 16 byte aligned address for the + stack pointer. The second half of the stack move is done by the + caller _dll_crt0. */ _tlsbase = (char *) newbase; _tlstop = (char *) newtop; _main_tls = &_my_tls; - return PTR_ADD (_main_tls, -4); + return PTR_ADD (_tlsbase, -16); } /* Respawn WOW64 process. This is only called if we can't reuse the original