-
Notifications
You must be signed in to change notification settings - Fork 491
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
msys2-runtime: integrate suspendthread fixup
This corresponds to msys2/msys2-runtime#239 and integrates one minor change of behavior where `remove_proc()` now _also_ tries `CancelSynchronousIo()` before using the big `terminate_thread()` hammer. Probably not a very noticeable change of behavior. But still. Better stay aligned with Cygwin! Signed-off-by: Johannes Schindelin <[email protected]>
- Loading branch information
Showing
2 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
msys2-runtime/0044-fixup-cygthread-suspend-thread-before-terminating.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
From 7829673c0c6aad989084a9b72287988efe00a317 Mon Sep 17 00:00:00 2001 | ||
From: Jeremy Drake <[email protected]> | ||
Date: Tue, 19 Nov 2024 10:57:05 -0800 | ||
Subject: [PATCH 44/N] fixup! cygthread: suspend thread before terminating. | ||
|
||
Address review comments: | ||
* add comments | ||
* change nested ifs to && conditions | ||
|
||
Added CancelSynchronousIo before another terminate_thread call, which | ||
was not the one that was causing issues, but still makes sense to avoid | ||
termination if possible. | ||
--- | ||
winsup/cygwin/pinfo.cc | 3 +++ | ||
winsup/cygwin/sigproc.cc | 15 +++++++++++---- | ||
2 files changed, 14 insertions(+), 4 deletions(-) | ||
|
||
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc | ||
index 43e0034..4bb1946 100644 | ||
--- a/winsup/cygwin/pinfo.cc | ||
+++ b/winsup/cygwin/pinfo.cc | ||
@@ -1268,6 +1268,9 @@ proc_waiter (void *arg) | ||
if (!ReadFile (vchild.rd_proc_pipe, &buf, 1, &nb, NULL) | ||
&& (err = GetLastError ()) != ERROR_BROKEN_PIPE) | ||
{ | ||
+ /* ERROR_OPERATION_ABORTED is expected due to the possibility that | ||
+ CancelSynchronousIo interruped the ReadFile call, so don't output | ||
+ that error */ | ||
if (err != ERROR_OPERATION_ABORTED) | ||
system_printf ("error on read of child wait pipe %p, %E", vchild.rd_proc_pipe); | ||
break; | ||
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc | ||
index 0089626..19a2aec 100644 | ||
--- a/winsup/cygwin/sigproc.cc | ||
+++ b/winsup/cygwin/sigproc.cc | ||
@@ -409,9 +409,12 @@ proc_terminate () | ||
to 1 iff it is a Cygwin process. */ | ||
if (!have_execed || !have_execed_cygwin) | ||
chld_procs[i]->ppid = 1; | ||
- if (chld_procs[i].wait_thread) | ||
- if (!CancelSynchronousIo (chld_procs[i].wait_thread->thread_handle ())) | ||
- chld_procs[i].wait_thread->terminate_thread (); | ||
+ /* Attempt to exit the wait_thread cleanly via CancelSynchronousIo | ||
+ before falling back to the (explicitly dangerous) cross-thread | ||
+ termination */ | ||
+ if (chld_procs[i].wait_thread | ||
+ && !CancelSynchronousIo (chld_procs[i].wait_thread->thread_handle ())) | ||
+ chld_procs[i].wait_thread->terminate_thread (); | ||
/* Release memory associated with this process unless it is 'myself'. | ||
'myself' is only in the chld_procs table when we've execed. We | ||
reach here when the next process has finished initializing but we | ||
@@ -1175,7 +1178,11 @@ remove_proc (int ci) | ||
{ | ||
if (have_execed) | ||
{ | ||
- if (_my_tls._ctinfo != chld_procs[ci].wait_thread) | ||
+ /* Attempt to exit the wait_thread cleanly via CancelSynchronousIo | ||
+ before falling back to the (explicitly dangerous) cross-thread | ||
+ termination */ | ||
+ if (_my_tls._ctinfo != chld_procs[ci].wait_thread | ||
+ && !CancelSynchronousIo (chld_procs[ci].wait_thread->thread_handle ())) | ||
chld_procs[ci].wait_thread->terminate_thread (); | ||
} | ||
else if (chld_procs[ci] && chld_procs[ci]->exists ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters