summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/fork.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2015-12-03 12:38:19 +0100
committerCorinna Vinschen <corinna@vinschen.de>2015-12-03 12:38:19 +0100
commit89e86492b36cd15876ebb0ed725fbb4308828a9e (patch)
tree213e61fd097ef7204c642840dd71664bb4c3ba1f /winsup/cygwin/fork.cc
parent8974e06da3c0214613aa27dc08e1de2b02e27231 (diff)
downloadcygnal-89e86492b36cd15876ebb0ed725fbb4308828a9e.tar.gz
cygnal-89e86492b36cd15876ebb0ed725fbb4308828a9e.tar.bz2
cygnal-89e86492b36cd15876ebb0ed725fbb4308828a9e.zip
Safely recognize when fork is running from main thread or another pthread
* child_info.h (struct child_info): Add member from_main. * fork.cc (frok::child): Check from_main rather than stackaddr. (frok::parent): Set ch.from_main if running in the main thread. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup/cygwin/fork.cc')
-rw-r--r--winsup/cygwin/fork.cc3
1 files changed, 2 insertions, 1 deletions
diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
index d4a973eb2..158186781 100644
--- a/winsup/cygwin/fork.cc
+++ b/winsup/cygwin/fork.cc
@@ -149,7 +149,7 @@ frok::child (volatile char * volatile here)
/* If we've played with the stack, stacksize != 0. That means that
fork() was invoked from other than the main thread. Make sure that
the threadinfo information is properly set up. */
- if (fork_info->stackaddr)
+ if (!fork_info->from_main)
{
_main_tls = &_my_tls;
_main_tls->init_thread (NULL, NULL);
@@ -307,6 +307,7 @@ frok::parent (volatile char * volatile stack_here)
ch.forker_finished = forker_finished;
+ ch.from_main = &_my_tls == _main_tls;
ch.stackbase = NtCurrentTeb()->Tib.StackBase;
ch.stackaddr = NtCurrentTeb ()->DeallocationStack;
if (!ch.stackaddr)