From c6696a3426628761a201c12af68325b12ec6f0b8 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Thu, 23 May 2013 20:10:35 +0000 Subject: * 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. --- winsup/cygwin/dcrt0.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'winsup/cygwin/dcrt0.cc') diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 0208a9412..d435129d7 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -405,7 +405,7 @@ void child_info_fork::alloc_stack_hard_way (volatile char *b) { void *stack_ptr; - DWORD stacksize; + SIZE_T stacksize; /* 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 @@ -415,16 +415,19 @@ child_info_fork::alloc_stack_hard_way (volatile char *b) && stackbottom <= cygheap->user_heap.max) || is_mmapped_region ((caddr_t) stacktop, (caddr_t) stackbottom)) return; - /* 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)) - api_fatal ("fork: can't reserve memory for stack %p - %p, %E", - stackaddr, stackbottom); - stacksize = (char *) stackbottom - (char *) stacktop; + { + PTEB teb = NtCurrentTeb (); + 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); 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) { /* Allocate PAGE_GUARD page if it still fits. */ -- cgit v1.2.3