* dcrt0.cc: Semi-revert commit 12743c2d5d.
(dll_crt0_0): Drop setting wow64_needs_stack_adjustment on 64 bit.
(_dll_crt0): Split out 64 bit code again and always create new main
thread stack, unless forked off from the non main thread in the parent.
Call create_new_main_thread_stack with parent stack commitsize if
started from the parent's main thread.
Only call child_info_fork::alloc_stack for the latter case on 64 bit.
Slightly rearrange moving rsp and rbp to new stack and document how.
Revert 32 bit wow64 handling to its former self.
* miscfunc.cc (create_new_main_thread_stack): Take a commitsize
parameter and use it if it's not 0. Don't set _main_tls here, it's
done in the caller _dll_crt0 anyway. Return stackbase - 16 bytes,
rather than stacklimit (which was very wrong anyway).
* miscfuncs.h (create_new_main_thread_stack): Accommodate declaration
to aforementioned change.
* wincap.h (wincaps::has_3264_stack_broken): Remove element.
* wincap.cc: Ditto, throughout.
* wow64.cc: Semi-revert to pre-12743c2d5d2721f3a80b4d7671a349be03c1f520
but keep architecture-agnostic type changes intact. Fix formatting.
* wow64.h: Revert to pre-12743c2d5d2721f3a80b4d7671a349be03c1f520.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* dcrt0.cc (dll_crt0_0): On 64 bit, set wow64_needs_stack_adjustment
if not started from a 64 bit process.
(_dll_crt0): Enable wow64_needs_stack_adjustment branch on 64 bit
as well. Remove 64 bit only code. Introduce CREATE_STACK and
FIX_STACK macros to conditionalize the code. Rearrange and
partially rewrite comments.
* wincap.h (wincaps::has_3264_stack_broken): New element.
* wincap.cc: Implement above element throughout.
(wincapc::init): Set has_3264_stack_broken to false on 32 bit.
* wow64.cc: Enable functionality on 64 bit architecture, except for
wow64_revert_to_original_stack. Enhance comments to explain.
(wow64_eval_expected_main_stack): Make 64 bit clean.
(wow64_test_for_64bit_parent): Ditto.
* wow64.h: Export wow64_revert_to_original_stack on 32 bit only,
everything else on all architectures.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* cygtls.h (_tlsbase): Remove. Replace throughout with
NtCurrentTeb()->Tib.StackBase.
(_tlstop): Remove. Replace throughout with
NtCurrentTeb()->Tib.StackLimit.
* dcrt0.cc (child_info_fork::alloc_stack): Move definition of local
teb variable up to be used throughout.
* include/cygwin/config.h (__getreent): Use inline function on both
architectures.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* dcrt0.cc (initial_env): Reduce size of local path buffers to
PATH_MAX. Allocate debugger_command from process heap.
(init_windows_system_directory): Very early initialize new global
variable global_progname.
* dll_init.cc (dll_list::alloc): Make path buffer static. Explain why.
(dll_list::populate_deps): Use tmp_pathbuf for local path buffer.
* exceptions.cc (debugger_command): Convert to PWCHAR.
(error_start_init): Allocate debugger_command and fill with wide char
strings. Only allocate if NULL.
(try_to_debug): Just check if debugger_command is a NULL pointer to
return. Drop conversion from char to WCHAR and drop local variable
dbg_cmd.
* globals.cc (global_progname): New global variable to store Windows
application path.
* pinfo.cc (pinfo_basic::pinfo_basic): Just copy progname over from
global_progname.
(pinfo::status_exit): Let path_conv create the POSIX path to
avoid local buffer.
* pseudo_reloc.cc (__report_error): Utilize global_progname, drop local
buffer.
* smallprint.cc (__small_vsprintf): Just utilize global_progname for
%P format specifier.
(__small_vswprintf): Ditto.
* strace.cc (PROTECT): Change to reflect x being a pointer. Reformat.
(CHECK): Ditto. Reformat.
(strace::activate): Utilize global_progname, drop local buffer.
Fix formatting.
(strace::vsprntf): Reduce size of local progname buffer to NAME_MAX.
Copy and, if necessary, convert only the last path component to
progname.
(strace_buf_guard): New muto.
(buf): New static pointer.
(strace::vprntf): Use buf under strace_buf_guard lock only. Allocate
buffer space for buf on Windows heap.
* wow64.cc (wow64_respawn_process): Utilize global_progname, drop
local path buffer.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
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.
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.
parent stack fits into the child stack. Align comment.
* wow64.cc (wow64_eval_expected_main_stack): New function to fetch
expected addresses of main thread stack from PE/COFF image header
values.
(wow64_test_for_64bit_parent): Fix comment. Check current stack
against real expected main thread stack addresses.
(wow64_revert_to_original_stack): Fix and add comments. Check memory
against real expected main thread stack addresses. Use orignal stack
if reserved area is >= 256K.
* dcrt0.cc (CYGWIN_GUARD): Drop execute permission for stack, it's
not used for stacks by the OS either.
(child_info_fork::alloc_stack_hard_way): Ditto.
(child_info_fork::alloc_stack): Don't alloc_stack_hard_way under WOW64
if forked from a 64 bit parent. Set child's StackBase to parent's
StackBase. Add comments to explain why.
(wow64_respawn): Move to wow64.cc.
(wow64_started_from_native64): Move to wow64.cc.
(respawn_wow64_process): Move to wow64.cc.
(dll_crt0_0): Drop wow64_test_stack_marker and move stack test into
wow64_test_for_64bit_parent function. Don't return early if WOW64
process has been started from native 64 bit process.
(_dll_crt0): Implement moving stack for WOW64 processes started from
native 64 bit process.
* wow64.cc: New file.
(wow64_has_64bit_parent): Rename from wow64_respawn.
(wow64_test_for_64bit_parent): Rename from wow64_started_from_native64.
Change comment.
(wow64_revert_to_original_stack): New function.
(wow64_respawn_process): Rename from respawn_wow64_process for symmetry.
* wow64.h: New file.