Rename parent stack members in child_info struct to align with OS names
* child_info.h (CURR_CHILD_INFO_MAGIC): Align to below change. (class child_info_fork): Rename stacktop to stacklimit. Rename stackbottom to stackbase. Accommodate name change throughout Cygwin. Rephrase comments to be clearer. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
7b0c063f12
commit
8974e06da3
@ -1,3 +1,10 @@
|
||||
2015-12-02 Corinna Vinschen <corinna@vinschen.de>
|
||||
|
||||
* child_info.h (CURR_CHILD_INFO_MAGIC): Align to below change.
|
||||
(class child_info_fork): Rename stacktop to stacklimit. Rename
|
||||
stackbottom to stackbase. Accommodate name change throughout Cygwin.
|
||||
Rephrase comments to be clearer.
|
||||
|
||||
2015-12-02 Corinna Vinschen <corinna@vinschen.de>
|
||||
|
||||
* cygtls.h (_tlsbase): Remove. Replace throughout with
|
||||
|
@ -39,7 +39,7 @@ enum child_status
|
||||
#define EXEC_MAGIC_SIZE sizeof(child_info)
|
||||
|
||||
/* Change this value if you get a message indicating that it is out-of-sync. */
|
||||
#define CURR_CHILD_INFO_MAGIC 0x4a91a908U
|
||||
#define CURR_CHILD_INFO_MAGIC 0xc96f5e9U
|
||||
|
||||
#define NPROCS 256
|
||||
|
||||
@ -103,9 +103,10 @@ class child_info_fork: public child_info
|
||||
public:
|
||||
HANDLE forker_finished;// for synchronization with child
|
||||
jmp_buf jmp; // where child will jump to
|
||||
void *stackaddr; // address of parent stack
|
||||
void *stacktop; // location of top of parent stack
|
||||
void *stackbottom; // location of bottom of parent stack
|
||||
void *stackaddr; // DeallocationStack or user-provided allocation address
|
||||
// of parent thread
|
||||
void *stacklimit; // StackLimit of parent thread
|
||||
void *stackbase; // StackBase of parent thread
|
||||
size_t guardsize; // size of POSIX guard region or (size_t) -1 if
|
||||
// user stack
|
||||
char filler[4];
|
||||
|
@ -412,15 +412,15 @@ child_info_fork::alloc_stack ()
|
||||
/* Make sure not to try a hard allocation if we have been forked off from
|
||||
the main thread of a Cygwin process which has been started from a 64 bit
|
||||
parent. In that case the StackBase of the forked child is not the same
|
||||
as the StackBase of the parent (== stackbottom), but only because the
|
||||
as the StackBase of the parent (== this.stackbase), but only because the
|
||||
stack of the parent has been slightly rearranged. See comment in
|
||||
wow64_revert_to_original_stack for details. We check here if the
|
||||
parent stack fits into the child stack. */
|
||||
PTEB teb = NtCurrentTeb ();
|
||||
if (teb->Tib.StackBase != stackbottom
|
||||
if (teb->Tib.StackBase != stackbase
|
||||
&& (!wincap.is_wow64 ()
|
||||
|| stacktop < teb->DeallocationStack
|
||||
|| stackbottom > teb->Tib.StackBase))
|
||||
|| stacklimit < teb->DeallocationStack
|
||||
|| stackbase > teb->Tib.StackBase))
|
||||
{
|
||||
void *stack_ptr;
|
||||
size_t stacksize;
|
||||
@ -430,21 +430,21 @@ child_info_fork::alloc_stack ()
|
||||
if (guardsize == (size_t) -1)
|
||||
return;
|
||||
/* Reserve entire stack. */
|
||||
stacksize = (PBYTE) stackbottom - (PBYTE) stackaddr;
|
||||
stacksize = (PBYTE) stackbase - (PBYTE) stackaddr;
|
||||
if (!VirtualAlloc (stackaddr, stacksize, MEM_RESERVE, PAGE_NOACCESS))
|
||||
{
|
||||
api_fatal ("fork: can't reserve memory for parent stack "
|
||||
"%p - %p, (child has %p - %p), %E",
|
||||
stackaddr, stackbottom, teb->DeallocationStack,
|
||||
stackaddr, stackbase, teb->DeallocationStack,
|
||||
teb->Tib.StackBase);
|
||||
}
|
||||
/* Commit the area commited in parent. */
|
||||
stacksize = (PBYTE) stackbottom - (PBYTE) stacktop;
|
||||
stack_ptr = VirtualAlloc (stacktop, stacksize, MEM_COMMIT,
|
||||
stacksize = (PBYTE) stackbase - (PBYTE) stacklimit;
|
||||
stack_ptr = VirtualAlloc (stacklimit, stacksize, MEM_COMMIT,
|
||||
PAGE_READWRITE);
|
||||
if (!stack_ptr)
|
||||
api_fatal ("can't commit memory for stack %p(%ly), %E",
|
||||
stacktop, stacksize);
|
||||
stacklimit, stacksize);
|
||||
/* Set up guardpages. */
|
||||
ULONG real_guardsize = guardsize
|
||||
? roundup2 (guardsize, wincap.page_size ())
|
||||
@ -472,26 +472,26 @@ child_info_fork::alloc_stack ()
|
||||
/* Fork has been called from main thread. Simply commit the region
|
||||
of the stack commited in the parent but not yet commited in the
|
||||
child and create new guardpages. */
|
||||
if (NtCurrentTeb()->Tib.StackLimit > stacktop)
|
||||
if (NtCurrentTeb()->Tib.StackLimit > stacklimit)
|
||||
{
|
||||
SIZE_T commitsize = (PBYTE) NtCurrentTeb()->Tib.StackLimit
|
||||
- (PBYTE) stacktop;
|
||||
if (!VirtualAlloc (stacktop, commitsize, MEM_COMMIT, PAGE_READWRITE))
|
||||
- (PBYTE) stacklimit;
|
||||
if (!VirtualAlloc (stacklimit, commitsize, MEM_COMMIT, PAGE_READWRITE))
|
||||
api_fatal ("can't commit child memory for stack %p(%ly), %E",
|
||||
stacktop, commitsize);
|
||||
PVOID guardpage = (PBYTE) stacktop - wincap.def_guard_page_size ();
|
||||
stacklimit, commitsize);
|
||||
PVOID guardpage = (PBYTE) stacklimit - wincap.def_guard_page_size ();
|
||||
if (!VirtualAlloc (guardpage, wincap.def_guard_page_size (),
|
||||
MEM_COMMIT, PAGE_READWRITE | PAGE_GUARD))
|
||||
api_fatal ("fork: couldn't allocate new stack guard page %p, %E",
|
||||
guardpage);
|
||||
NtCurrentTeb()->Tib.StackLimit = stacktop;
|
||||
NtCurrentTeb()->Tib.StackLimit = stacklimit;
|
||||
}
|
||||
stackaddr = 0;
|
||||
/* This only affects forked children of a process started from a native
|
||||
64 bit process, but it doesn't hurt to do it unconditionally. Fix
|
||||
StackBase in the child to be the same as in the parent, so that the
|
||||
computation of _my_tls is correct. */
|
||||
teb->Tib.StackBase = (PVOID) stackbottom;
|
||||
teb->Tib.StackBase = (PVOID) stackbase;
|
||||
}
|
||||
}
|
||||
|
||||
@ -920,8 +920,8 @@ dll_crt0_1 (void *)
|
||||
this step. */
|
||||
if (fork_info->stackaddr)
|
||||
{
|
||||
NtCurrentTeb()->Tib.StackBase = (PVOID) fork_info->stackbottom;
|
||||
NtCurrentTeb()->Tib.StackLimit = (PVOID) fork_info->stacktop;
|
||||
NtCurrentTeb()->Tib.StackBase = (PVOID) fork_info->stackbase;
|
||||
NtCurrentTeb()->Tib.StackLimit = (PVOID) fork_info->stacklimit;
|
||||
}
|
||||
|
||||
/* Not resetting _my_tls.incyg here because presumably fork will overwrite
|
||||
|
@ -307,7 +307,7 @@ frok::parent (volatile char * volatile stack_here)
|
||||
|
||||
ch.forker_finished = forker_finished;
|
||||
|
||||
ch.stackbottom = NtCurrentTeb()->Tib.StackBase;
|
||||
ch.stackbase = NtCurrentTeb()->Tib.StackBase;
|
||||
ch.stackaddr = NtCurrentTeb ()->DeallocationStack;
|
||||
if (!ch.stackaddr)
|
||||
{
|
||||
@ -315,25 +315,25 @@ frok::parent (volatile char * volatile stack_here)
|
||||
stack. If so, the entire stack is committed anyway and StackLimit
|
||||
points to the allocation address of the stack. Mark in guardsize that
|
||||
we must not set up guard pages. */
|
||||
ch.stackaddr = ch.stacktop = NtCurrentTeb()->Tib.StackLimit;
|
||||
ch.stackaddr = ch.stacklimit = NtCurrentTeb()->Tib.StackLimit;
|
||||
ch.guardsize = (size_t) -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Otherwise we're running on a system-allocated stack. Since stack_here
|
||||
is the address of the stack pointer we start the child with anyway, we
|
||||
can set ch.stacktop to this value rounded down to page size. The
|
||||
can set ch.stacklimit to this value rounded down to page size. The
|
||||
child will not need the rest of the stack anyway. Guardsize depends
|
||||
on whether we're running on a pthread or not. If pthread, we fetch
|
||||
the guardpage size from the pthread attribs, otherwise we use the
|
||||
system default. */
|
||||
ch.stacktop = (void *) ((uintptr_t) stack_here & ~wincap.page_size ());
|
||||
ch.stacklimit = (void *) ((uintptr_t) stack_here & ~wincap.page_size ());
|
||||
ch.guardsize = (&_my_tls != _main_tls && _my_tls.tid)
|
||||
? _my_tls.tid->attr.guardsize
|
||||
: wincap.def_guard_page_size ();
|
||||
}
|
||||
debug_printf ("stack - bottom %p, top %p, addr %p, guardsize %ly",
|
||||
ch.stackbottom, ch.stacktop, ch.stackaddr, ch.guardsize);
|
||||
ch.stackbase, ch.stacklimit, ch.stackaddr, ch.guardsize);
|
||||
|
||||
PROCESS_INFORMATION pi;
|
||||
STARTUPINFOW si;
|
||||
@ -475,7 +475,7 @@ frok::parent (volatile char * volatile stack_here)
|
||||
impure_end = _impure_ptr + 1;
|
||||
}
|
||||
rc = child_copy (hchild, true,
|
||||
"stack", stack_here, ch.stackbottom,
|
||||
"stack", stack_here, ch.stackbase,
|
||||
impure, impure_beg, impure_end,
|
||||
NULL);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user