From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id AA1DE38346AE; Tue, 3 May 2022 13:16:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AA1DE38346AE Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: always add sigmask to child info X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 28970dae34522059e094eb7db466404facb09460 X-Git-Newrev: 5a6de512ab5d46f7a0f019e7345e800a0a274a62 Message-Id: <20220503131656.AA1DE38346AE@sourceware.org> Date: Tue, 3 May 2022 13:16:56 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 May 2022 13:16:56 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D5a6de512ab5= d46f7a0f019e7345e800a0a274a62 commit 5a6de512ab5d46f7a0f019e7345e800a0a274a62 Author: Corinna Vinschen Date: Tue May 3 15:16:18 2022 +0200 Cygwin: always add sigmask to child info =20 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. =20 Signed-off-by: Corinna Vinschen 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 7a67a1b51..181db8fa2 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) =20 /* Change this value if you get a message indicating that it is out-of-syn= c. */ -#define CURR_CHILD_INFO_MAGIC 0xecc930b9U +#define CURR_CHILD_INFO_MAGIC 0xacbf4682U =20 #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 dee8482c2..8869cbd75 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -845,7 +845,7 @@ dll_crt0_1 (void *) _my_tls.incyg++; /* Inherit "parent" exec'ed process sigmask */ if (spawn_info && !in_forkee) - _my_tls.sigmask =3D spawn_info->moreinfo->sigmask; + _my_tls.sigmask =3D spawn_info->sigmask; =20 if (dynamically_loaded) sigproc_init (); diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 62df96652..987dfea37 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -820,7 +820,7 @@ child_info::child_info (unsigned in_cb, child_info_type= s chtype, msv_count (0), 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) + rd_proc_pipe (NULL), wr_proc_pipe (NULL), sigmask (_my_tls.sigmask) { fhandler_union_cb =3D sizeof (fhandler_union); user_h =3D cygwin_user_h; @@ -902,7 +902,6 @@ cygheap_exec_info::alloc () sizeof (cygheap_exec_info) + (chld_procs.count () * sizeof (children[0]))); - res->sigmask =3D _my_tls.sigmask; return res; } =20 @@ -1353,9 +1352,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 =3D cygheap->find_tls (_main_tls); - dummy_mask =3D _main_tls->sigmask; - cygheap->unlock_tls (tl_entry); + if (tl_entry) + { + dummy_mask =3D _main_tls->sigmask; + cygheap->unlock_tls (tl_entry); + } + else if (child_proc_info) + dummy_mask =3D child_proc_info->sigmask; + else + dummy_mask =3D 0; pack.mask =3D &dummy_mask; }