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>
|
2015-12-02 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* cygtls.h (_tlsbase): Remove. Replace throughout with
|
* cygtls.h (_tlsbase): Remove. Replace throughout with
|
||||||
|
@ -39,7 +39,7 @@ enum child_status
|
|||||||
#define EXEC_MAGIC_SIZE sizeof(child_info)
|
#define EXEC_MAGIC_SIZE sizeof(child_info)
|
||||||
|
|
||||||
/* Change this value if you get a message indicating that it is out-of-sync. */
|
/* 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
|
#define NPROCS 256
|
||||||
|
|
||||||
@ -103,9 +103,10 @@ class child_info_fork: public child_info
|
|||||||
public:
|
public:
|
||||||
HANDLE forker_finished;// for synchronization with child
|
HANDLE forker_finished;// for synchronization with child
|
||||||
jmp_buf jmp; // where child will jump to
|
jmp_buf jmp; // where child will jump to
|
||||||
void *stackaddr; // address of parent stack
|
void *stackaddr; // DeallocationStack or user-provided allocation address
|
||||||
void *stacktop; // location of top of parent stack
|
// of parent thread
|
||||||
void *stackbottom; // location of bottom of parent stack
|
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
|
size_t guardsize; // size of POSIX guard region or (size_t) -1 if
|
||||||
// user stack
|
// user stack
|
||||||
char filler[4];
|
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
|
/* 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
|
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
|
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
|
stack of the parent has been slightly rearranged. See comment in
|
||||||
wow64_revert_to_original_stack for details. We check here if the
|
wow64_revert_to_original_stack for details. We check here if the
|
||||||
parent stack fits into the child stack. */
|
parent stack fits into the child stack. */
|
||||||
PTEB teb = NtCurrentTeb ();
|
PTEB teb = NtCurrentTeb ();
|
||||||
if (teb->Tib.StackBase != stackbottom
|
if (teb->Tib.StackBase != stackbase
|
||||||
&& (!wincap.is_wow64 ()
|
&& (!wincap.is_wow64 ()
|
||||||
|| stacktop < teb->DeallocationStack
|
|| stacklimit < teb->DeallocationStack
|
||||||
|| stackbottom > teb->Tib.StackBase))
|
|| stackbase > teb->Tib.StackBase))
|
||||||
{
|
{
|
||||||
void *stack_ptr;
|
void *stack_ptr;
|
||||||
size_t stacksize;
|
size_t stacksize;
|
||||||
@ -430,21 +430,21 @@ child_info_fork::alloc_stack ()
|
|||||||
if (guardsize == (size_t) -1)
|
if (guardsize == (size_t) -1)
|
||||||
return;
|
return;
|
||||||
/* Reserve entire stack. */
|
/* Reserve entire stack. */
|
||||||
stacksize = (PBYTE) stackbottom - (PBYTE) stackaddr;
|
stacksize = (PBYTE) stackbase - (PBYTE) stackaddr;
|
||||||
if (!VirtualAlloc (stackaddr, stacksize, MEM_RESERVE, PAGE_NOACCESS))
|
if (!VirtualAlloc (stackaddr, stacksize, MEM_RESERVE, PAGE_NOACCESS))
|
||||||
{
|
{
|
||||||
api_fatal ("fork: can't reserve memory for parent stack "
|
api_fatal ("fork: can't reserve memory for parent stack "
|
||||||
"%p - %p, (child has %p - %p), %E",
|
"%p - %p, (child has %p - %p), %E",
|
||||||
stackaddr, stackbottom, teb->DeallocationStack,
|
stackaddr, stackbase, teb->DeallocationStack,
|
||||||
teb->Tib.StackBase);
|
teb->Tib.StackBase);
|
||||||
}
|
}
|
||||||
/* Commit the area commited in parent. */
|
/* Commit the area commited in parent. */
|
||||||
stacksize = (PBYTE) stackbottom - (PBYTE) stacktop;
|
stacksize = (PBYTE) stackbase - (PBYTE) stacklimit;
|
||||||
stack_ptr = VirtualAlloc (stacktop, stacksize, MEM_COMMIT,
|
stack_ptr = VirtualAlloc (stacklimit, stacksize, MEM_COMMIT,
|
||||||
PAGE_READWRITE);
|
PAGE_READWRITE);
|
||||||
if (!stack_ptr)
|
if (!stack_ptr)
|
||||||
api_fatal ("can't commit memory for stack %p(%ly), %E",
|
api_fatal ("can't commit memory for stack %p(%ly), %E",
|
||||||
stacktop, stacksize);
|
stacklimit, stacksize);
|
||||||
/* Set up guardpages. */
|
/* Set up guardpages. */
|
||||||
ULONG real_guardsize = guardsize
|
ULONG real_guardsize = guardsize
|
||||||
? roundup2 (guardsize, wincap.page_size ())
|
? 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
|
/* Fork has been called from main thread. Simply commit the region
|
||||||
of the stack commited in the parent but not yet commited in the
|
of the stack commited in the parent but not yet commited in the
|
||||||
child and create new guardpages. */
|
child and create new guardpages. */
|
||||||
if (NtCurrentTeb()->Tib.StackLimit > stacktop)
|
if (NtCurrentTeb()->Tib.StackLimit > stacklimit)
|
||||||
{
|
{
|
||||||
SIZE_T commitsize = (PBYTE) NtCurrentTeb()->Tib.StackLimit
|
SIZE_T commitsize = (PBYTE) NtCurrentTeb()->Tib.StackLimit
|
||||||
- (PBYTE) stacktop;
|
- (PBYTE) stacklimit;
|
||||||
if (!VirtualAlloc (stacktop, commitsize, MEM_COMMIT, PAGE_READWRITE))
|
if (!VirtualAlloc (stacklimit, commitsize, MEM_COMMIT, PAGE_READWRITE))
|
||||||
api_fatal ("can't commit child memory for stack %p(%ly), %E",
|
api_fatal ("can't commit child memory for stack %p(%ly), %E",
|
||||||
stacktop, commitsize);
|
stacklimit, commitsize);
|
||||||
PVOID guardpage = (PBYTE) stacktop - wincap.def_guard_page_size ();
|
PVOID guardpage = (PBYTE) stacklimit - wincap.def_guard_page_size ();
|
||||||
if (!VirtualAlloc (guardpage, wincap.def_guard_page_size (),
|
if (!VirtualAlloc (guardpage, wincap.def_guard_page_size (),
|
||||||
MEM_COMMIT, PAGE_READWRITE | PAGE_GUARD))
|
MEM_COMMIT, PAGE_READWRITE | PAGE_GUARD))
|
||||||
api_fatal ("fork: couldn't allocate new stack guard page %p, %E",
|
api_fatal ("fork: couldn't allocate new stack guard page %p, %E",
|
||||||
guardpage);
|
guardpage);
|
||||||
NtCurrentTeb()->Tib.StackLimit = stacktop;
|
NtCurrentTeb()->Tib.StackLimit = stacklimit;
|
||||||
}
|
}
|
||||||
stackaddr = 0;
|
stackaddr = 0;
|
||||||
/* This only affects forked children of a process started from a native
|
/* 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
|
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
|
StackBase in the child to be the same as in the parent, so that the
|
||||||
computation of _my_tls is correct. */
|
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. */
|
this step. */
|
||||||
if (fork_info->stackaddr)
|
if (fork_info->stackaddr)
|
||||||
{
|
{
|
||||||
NtCurrentTeb()->Tib.StackBase = (PVOID) fork_info->stackbottom;
|
NtCurrentTeb()->Tib.StackBase = (PVOID) fork_info->stackbase;
|
||||||
NtCurrentTeb()->Tib.StackLimit = (PVOID) fork_info->stacktop;
|
NtCurrentTeb()->Tib.StackLimit = (PVOID) fork_info->stacklimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Not resetting _my_tls.incyg here because presumably fork will overwrite
|
/* 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.forker_finished = forker_finished;
|
||||||
|
|
||||||
ch.stackbottom = NtCurrentTeb()->Tib.StackBase;
|
ch.stackbase = NtCurrentTeb()->Tib.StackBase;
|
||||||
ch.stackaddr = NtCurrentTeb ()->DeallocationStack;
|
ch.stackaddr = NtCurrentTeb ()->DeallocationStack;
|
||||||
if (!ch.stackaddr)
|
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
|
stack. If so, the entire stack is committed anyway and StackLimit
|
||||||
points to the allocation address of the stack. Mark in guardsize that
|
points to the allocation address of the stack. Mark in guardsize that
|
||||||
we must not set up guard pages. */
|
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;
|
ch.guardsize = (size_t) -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Otherwise we're running on a system-allocated stack. Since stack_here
|
/* 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
|
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
|
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
|
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
|
the guardpage size from the pthread attribs, otherwise we use the
|
||||||
system default. */
|
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)
|
ch.guardsize = (&_my_tls != _main_tls && _my_tls.tid)
|
||||||
? _my_tls.tid->attr.guardsize
|
? _my_tls.tid->attr.guardsize
|
||||||
: wincap.def_guard_page_size ();
|
: wincap.def_guard_page_size ();
|
||||||
}
|
}
|
||||||
debug_printf ("stack - bottom %p, top %p, addr %p, guardsize %ly",
|
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;
|
PROCESS_INFORMATION pi;
|
||||||
STARTUPINFOW si;
|
STARTUPINFOW si;
|
||||||
@ -475,7 +475,7 @@ frok::parent (volatile char * volatile stack_here)
|
|||||||
impure_end = _impure_ptr + 1;
|
impure_end = _impure_ptr + 1;
|
||||||
}
|
}
|
||||||
rc = child_copy (hchild, true,
|
rc = child_copy (hchild, true,
|
||||||
"stack", stack_here, ch.stackbottom,
|
"stack", stack_here, ch.stackbase,
|
||||||
impure, impure_beg, impure_end,
|
impure, impure_beg, impure_end,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user