This is the mail archive of the
cygwin-cvs@cygwin.com
mailing list for the Cygwin project.
[newlib-cygwin] Always restore full TEB stack info in forkee
- From: Corinna Vinschen <corinna at sourceware dot org>
- To: cygwin-cvs at sourceware dot org
- Date: 3 Dec 2015 12:29:01 -0000
- Subject: [newlib-cygwin] Always restore full TEB stack info in forkee
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=111f32f4ba709be038234fbc7f0254b8f6506564
commit 111f32f4ba709be038234fbc7f0254b8f6506564
Author: Corinna Vinschen <corinna@vinschen.de>
Date: Thu Dec 3 12:58:37 2015 +0100
Always restore full TEB stack info in forkee
* dcrt0.cc (dll_crt0_1): Always restore the TEB stack info. Especially
restore DeallocationStack. Fix comment.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diff:
---
winsup/cygwin/ChangeLog | 5 +++++
winsup/cygwin/dcrt0.cc | 18 +++++++++---------
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index e539b89..03cc4e2 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,10 @@
2015-12-03 Corinna Vinschen <corinna@vinschen.de>
+ * crt0.cc (dll_crt0_1): Always restore the TEB stack info. Especially
+ restore DeallocationStack. Fix comment.
+
+2015-12-03 Corinna Vinschen <corinna@vinschen.de>
+
* dcrt0.cc (child_info_fork::alloc_stack): Don't set stackaddr to 0.
2015-12-03 Corinna Vinschen <corinna@vinschen.de>
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index ac3360c..9140fa0 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -910,18 +910,18 @@ dll_crt0_1 (void *)
cygbench ("pre-forkee");
if (in_forkee)
{
- /* If we've played with the stack, stacksize != 0. That means that
- fork() was invoked from other than the main thread. Make sure that
- frame pointer is referencing the new stack so that the OS knows what
- to do when it needs to increase the size of the stack.
+ /* Make sure to restore the TEB's stack info. If guardsize is -1 the
+ stack has been provided by the application and must not be deallocated
+ automagically when the thread exits.
NOTE: Don't do anything that involves the stack until you've completed
this step. */
- if (fork_info->stackaddr)
- {
- NtCurrentTeb()->Tib.StackBase = (PVOID) fork_info->stackbase;
- NtCurrentTeb()->Tib.StackLimit = (PVOID) fork_info->stacklimit;
- }
+ PTEB teb = NtCurrentTeb ();
+ teb->Tib.StackBase = (PVOID) fork_info->stackbase;
+ teb->Tib.StackLimit = (PVOID) fork_info->stacklimit;
+ teb->DeallocationStack = (fork_info->guardsize == (size_t) -1)
+ ? NULL
+ : (PVOID) fork_info->stackaddr;
/* Not resetting _my_tls.incyg here because presumably fork will overwrite
it with the value of the forker and all will be good. */