* dcrt0.cc (child_info_fork::alloc_stack_hard_way): Fix datatype of

stacksize to SIZE_T.  Cast to SIZE_T in pointer arithmetic.  Slightly
	enhance output in case of a fatal error.
	* fork.cc (frok::parent): Always set ch.stackaddr to DeallocationStack
	value of current thread to help stack reservation in
	child_info_fork::alloc_stack_hard_way along.  Simplify subsequent code
	storing stack values in ch.  Print guardsize in hex, too.
This commit is contained in:
Corinna Vinschen 2013-05-23 20:10:35 +00:00
parent df7a7e2e82
commit c6696a3426
3 changed files with 27 additions and 18 deletions

View File

@ -1,3 +1,13 @@
2013-05-23 Corinna Vinschen <corinna@vinschen.de>
* dcrt0.cc (child_info_fork::alloc_stack_hard_way): Fix datatype of
stacksize to SIZE_T. Cast to SIZE_T in pointer arithmetic. Slightly
enhance output in case of a fatal error.
* fork.cc (frok::parent): Always set ch.stackaddr to DeallocationStack
value of current thread to help stack reservation in
child_info_fork::alloc_stack_hard_way along. Simplify subsequent code
storing stack values in ch. Print guardsize in hex, too.
2013-05-23 Corinna Vinschen <corinna@vinschen.de> 2013-05-23 Corinna Vinschen <corinna@vinschen.de>
* environ.cc (set_winsymlinks): Handle "winsymlinks:nativestrict" * environ.cc (set_winsymlinks): Handle "winsymlinks:nativestrict"

View File

@ -405,7 +405,7 @@ void
child_info_fork::alloc_stack_hard_way (volatile char *b) child_info_fork::alloc_stack_hard_way (volatile char *b)
{ {
void *stack_ptr; void *stack_ptr;
DWORD stacksize; SIZE_T stacksize;
/* First check if the requested stack area is part of the user heap /* First check if the requested stack area is part of the user heap
or part of a mmapped region. If so, we have been started from a or part of a mmapped region. If so, we have been started from a
@ -415,16 +415,19 @@ child_info_fork::alloc_stack_hard_way (volatile char *b)
&& stackbottom <= cygheap->user_heap.max) && stackbottom <= cygheap->user_heap.max)
|| is_mmapped_region ((caddr_t) stacktop, (caddr_t) stackbottom)) || is_mmapped_region ((caddr_t) stacktop, (caddr_t) stackbottom))
return; return;
/* First, try to reserve the entire stack. */ /* First, try to reserve the entire stack. */
stacksize = (char *) stackbottom - (char *) stackaddr; stacksize = (SIZE_T) stackbottom - (SIZE_T) 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 stack %p - %p, %E", {
stackaddr, stackbottom); PTEB teb = NtCurrentTeb ();
stacksize = (char *) stackbottom - (char *) stacktop; api_fatal ("fork: can't reserve memory for parent stack "
"%p - %p, (child has %p - %p), %E",
stackaddr, stackbottom, teb->DeallocationStack, _tlsbase);
}
stacksize = (SIZE_T) stackbottom - (SIZE_T) stacktop;
stack_ptr = VirtualAlloc (stacktop, stacksize, MEM_COMMIT, PAGE_READWRITE); stack_ptr = VirtualAlloc (stacktop, stacksize, MEM_COMMIT, PAGE_READWRITE);
if (!stack_ptr) if (!stack_ptr)
abort ("can't commit memory for stack %p(%d), %E", stacktop, stacksize); abort ("can't commit memory for stack %p(%ly), %E", stacktop, stacksize);
if (guardsize != (size_t) -1) if (guardsize != (size_t) -1)
{ {
/* Allocate PAGE_GUARD page if it still fits. */ /* Allocate PAGE_GUARD page if it still fits. */

View File

@ -302,17 +302,17 @@ frok::parent (volatile char * volatile stack_here)
ch.forker_finished = forker_finished; ch.forker_finished = forker_finished;
PTEB teb = NtCurrentTeb ();
ch.stackbottom = _tlsbase; ch.stackbottom = _tlsbase;
ch.stacktop = (void *) _tlstop; ch.stacktop = (void *) _tlstop;
ch.stackaddr = 0; ch.stackaddr = teb->DeallocationStack;
ch.guardsize = 0; ch.guardsize = 0;
if (&_my_tls != _main_tls) if (&_my_tls != _main_tls)
{ {
/* We have not been started from the main thread. Fetch the /* We have not been started from the main thread. Fetch the
information required to set up the thread stack identically information required to set up the thread stack identically
in the child. */ in the child. */
PTEB teb = NtCurrentTeb (); if (!ch.stackaddr)
if (!teb->DeallocationStack)
{ {
/* Pthread with application-provided stack. Don't set up a /* Pthread with application-provided stack. Don't set up a
PAGE_GUARD page. guardsize == -1 is used in alloc_stack_hard_way PAGE_GUARD page. guardsize == -1 is used in alloc_stack_hard_way
@ -320,15 +320,11 @@ frok::parent (volatile char * volatile stack_here)
ch.stackaddr = _my_tls.tid->attr.stackaddr; ch.stackaddr = _my_tls.tid->attr.stackaddr;
ch.guardsize = (size_t) -1; ch.guardsize = (size_t) -1;
} }
else else if (_my_tls.tid)
{
ch.stackaddr = teb->DeallocationStack;
/* If it's a pthread, fetch guardsize from thread attributes. */ /* If it's a pthread, fetch guardsize from thread attributes. */
if (_my_tls.tid)
ch.guardsize = _my_tls.tid->attr.guardsize; ch.guardsize = _my_tls.tid->attr.guardsize;
} }
} debug_printf ("stack - bottom %p, top %p, addr %p, guardsize %ly",
debug_printf ("stack - bottom %p, top %p, addr %p, guardsize %lu",
ch.stackbottom, ch.stacktop, ch.stackaddr, ch.guardsize); ch.stackbottom, ch.stacktop, ch.stackaddr, ch.guardsize);
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;