diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2015-07-07 17:05:20 +0200 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2015-07-07 17:05:20 +0200 |
commit | 606013bcf108716f6a84b574864c26cff74f8a37 (patch) | |
tree | ae2128b965ef702c51df85441b2093449434118b /winsup/cygwin/fork.cc | |
parent | c9b37162799ebbfadd5d4ffba11aa9a44c4d9853 (diff) | |
download | cygnal-606013bcf108716f6a84b574864c26cff74f8a37.tar.gz cygnal-606013bcf108716f6a84b574864c26cff74f8a37.tar.bz2 cygnal-606013bcf108716f6a84b574864c26cff74f8a37.zip |
Simplify fork code setting up child stack info
* fork.cc (frok::parent): Simplify code propagating stack setup to
child process. Tweak comments.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup/cygwin/fork.cc')
-rw-r--r-- | winsup/cygwin/fork.cc | 49 |
1 files changed, 20 insertions, 29 deletions
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; + { + /* 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 - 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; + /* 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); |