public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Takashi Yano <tyan0@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin/cygwin-3_3-branch] Cygwin: always add sigmask to child info
Date: Fri,  6 May 2022 18:47:19 +0000 (GMT)	[thread overview]
Message-ID: <20220506184719.3903D385840C@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=7da8066ae8f80da4859201674bc3bfff0e0fe9a2

commit 7da8066ae8f80da4859201674bc3bfff0e0fe9a2
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Tue May 3 15:16:18 2022 +0200

    Cygwin: always add sigmask to child info
    
    Even after fork, we might need the parent sigmask without having
    access to the real _main_tls. There's a short time at process startup,
    when _main_tls points to the system-allocated stack, but wait_sig is
    already running. If we can't lock _main_tls, because find_tls can't
    find it yet, we now access the parent's sigmask via child_info.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/child_info.h |  5 +++--
 winsup/cygwin/dcrt0.cc     |  2 +-
 winsup/cygwin/sigproc.cc   | 18 ++++++++++++++----
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/winsup/cygwin/child_info.h b/winsup/cygwin/child_info.h
index 505eaef23..d98308b60 100644
--- a/winsup/cygwin/child_info.h
+++ b/winsup/cygwin/child_info.h
@@ -37,7 +37,7 @@ enum child_status
 #define EXEC_MAGIC_SIZE sizeof(child_info)
 
 /* Change this value if you get a message indicating that it is out-of-sync. */
-#define CURR_CHILD_INFO_MAGIC 0xecc930b9U
+#define CURR_CHILD_INFO_MAGIC 0xacbf4682U
 
 #include "pinfo.h"
 struct cchildren
@@ -71,6 +71,8 @@ public:
   unsigned fhandler_union_cb;
   DWORD exit_code;	// process exit code
   static int retry_count;// retry count;
+  sigset_t sigmask;
+
   child_info (unsigned, child_info_types, bool);
   child_info (): subproc_ready (NULL), parent (NULL) {}
   ~child_info ();
@@ -130,7 +132,6 @@ public:
   int envc;
   char **envp;
   HANDLE myself_pinfo;
-  sigset_t sigmask;
   int nchildren;
   cchildren children[0];
   static cygheap_exec_info *alloc ();
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index 31dfd6f03..28b514618 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -849,7 +849,7 @@ dll_crt0_1 (void *)
   _my_tls.incyg++;
   /* Inherit "parent" exec'ed process sigmask */
   if (spawn_info && !in_forkee)
-    _my_tls.sigmask = spawn_info->moreinfo->sigmask;
+    _my_tls.sigmask = spawn_info->sigmask;
 
   if (dynamically_loaded)
     sigproc_init ();
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index e923f4ede..b5143e853 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -820,7 +820,7 @@ child_info::child_info (unsigned in_cb, child_info_types chtype,
   cb (in_cb), intro (PROC_MAGIC_GENERIC), magic (CHILD_INFO_MAGIC),
   type (chtype), cygheap (::cygheap), cygheap_max (::cygheap_max),
   flag (0), retry (child_info::retry_count), rd_proc_pipe (NULL),
-  wr_proc_pipe (NULL)
+  wr_proc_pipe (NULL), sigmask (_my_tls.sigmask)
 {
   /* It appears that when running under WOW64 on Vista 64, the first DWORD
      value in the datastructure lpReserved2 is pointing to (msv_count in
@@ -922,7 +922,6 @@ cygheap_exec_info::alloc ()
 					 sizeof (cygheap_exec_info)
 					 + (chld_procs.count ()
 					    * sizeof (children[0])));
-  res->sigmask = _my_tls.sigmask;
   return res;
 }
 
@@ -1373,9 +1372,20 @@ wait_sig (VOID *)
       threadlist_t *tl_entry;
       if (!pack.mask)
 	{
+	  /* There's a short time at process startup of a forked process,
+	     when _main_tls points to the system-allocated stack, not to
+	     the parent thread. In that case find_tls fails, and we fetch
+	     the sigmask from the child_info passed from the parent. */
 	  tl_entry = cygheap->find_tls (_main_tls);
-	  dummy_mask = _main_tls->sigmask;
-	  cygheap->unlock_tls (tl_entry);
+	  if (tl_entry)
+	    {
+	      dummy_mask = _main_tls->sigmask;
+	      cygheap->unlock_tls (tl_entry);
+	    }
+	  else if (child_proc_info)
+	    dummy_mask = child_proc_info->sigmask;
+	  else
+	    dummy_mask = 0;
 	  pack.mask = &dummy_mask;
 	}


                 reply	other threads:[~2022-05-06 18:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220506184719.3903D385840C@sourceware.org \
    --to=tyan0@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).