diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 13d6fe734..141307e4f 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2015-07-07 Corinna Vinschen + + * fork.cc (frok::parent): Simplify code propagating stack setup to + child process. Tweak comments. + 2015-07-06 Yaakov Selkowitz * path.cc: Rework basename redefinition handling. Explain why. diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc index 951c7fd58..317aec7e3 100644 --- a/winsup/cygwin/fork.cc +++ b/winsup/cygwin/fork.cc @@ -307,39 +307,30 @@ frok::parent (volatile char * volatile stack_here) ch.forker_finished = forker_finished; - PTEB teb = NtCurrentTeb (); - ch.stackaddr = teb->DeallocationStack; ch.stackbottom = _tlsbase; - /* If DeallocationStack is NULL, we're running on an application-provided - stack. If so, the entire stack is committed anyway and StackLimit points - to the allocation address of the stack. Otherwise we're running on a - system-allocated stack and using StackLimit is dangerous, in case the - application encountered a stack overflow and recovered from it via - a signal handler running on an alternate 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 - child will not need the rest of the stack anyway. */ + ch.stackaddr = NtCurrentTeb ()->DeallocationStack; if (!ch.stackaddr) - ch.stacktop = _tlstop; - else - ch.stacktop = (void *) ((uintptr_t) stack_here & ~wincap.page_size ()); - ch.guardsize = 0; - if (&_my_tls != _main_tls) { - /* We have not been started from the main thread. Fetch the - information required to set up the thread stack identically - in the child. */ - if (!ch.stackaddr) - { - /* Pthread with application-provided stack. Don't set up a - PAGE_GUARD page. guardsize == -1 is used in alloc_stack_hard_way - to recognize this type of stack. */ - ch.stackaddr = _my_tls.tid->attr.stackaddr; - ch.guardsize = (size_t) -1; - } - else if (_my_tls.tid) - /* If it's a pthread, fetch guardsize from thread attributes. */ - ch.guardsize = _my_tls.tid->attr.guardsize; + /* If DeallocationStack is NULL, we're running on an application-provided + 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 = _tlstop; + 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 + 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.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);