Skip to content

Commit d937dbd

Browse files
authored
Merge pull request #73 from dscho/try-to-fix-hangs-on-arm64
Fix double-fork hang on Windows/ARM64
2 parents 6183b83 + 54a7252 commit d937dbd

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

winsup/cygwin/cygthread.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,20 @@ cygthread::terminate_thread ()
302302
if (!inuse)
303303
goto force_notterminated;
304304

305+
if (_my_tls._ctinfo != this)
306+
{
307+
CONTEXT context;
308+
context.ContextFlags = CONTEXT_CONTROL;
309+
/* SuspendThread makes sure a thread is "booted" from emulation before
310+
it is suspended. As such, the emulator hopefully won't be in a bad
311+
state (aka, holding any locks) when the thread is terminated. */
312+
SuspendThread (h);
313+
/* We need to call GetThreadContext, even though we don't care about the
314+
context, because SuspendThread is asynchronous and GetThreadContext
315+
will make sure the thread is *really* suspended before returning */
316+
GetThreadContext (h, &context);
317+
}
318+
305319
TerminateThread (h, 0);
306320
WaitForSingleObject (h, INFINITE);
307321
CloseHandle (h);

winsup/cygwin/pinfo.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,13 +1262,14 @@ proc_waiter (void *arg)
12621262

12631263
for (;;)
12641264
{
1265-
DWORD nb;
1265+
DWORD nb, err;
12661266
char buf = '\0';
12671267

12681268
if (!ReadFile (vchild.rd_proc_pipe, &buf, 1, &nb, NULL)
1269-
&& GetLastError () != ERROR_BROKEN_PIPE)
1269+
&& (err = GetLastError ()) != ERROR_BROKEN_PIPE)
12701270
{
1271-
system_printf ("error on read of child wait pipe %p, %E", vchild.rd_proc_pipe);
1271+
if (err != ERROR_OPERATION_ABORTED)
1272+
system_printf ("error on read of child wait pipe %p, %E", vchild.rd_proc_pipe);
12721273
break;
12731274
}
12741275

winsup/cygwin/sigproc.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ proc_terminate ()
410410
if (!have_execed || !have_execed_cygwin)
411411
chld_procs[i]->ppid = 1;
412412
if (chld_procs[i].wait_thread)
413-
chld_procs[i].wait_thread->terminate_thread ();
413+
if (!CancelSynchronousIo (chld_procs[i].wait_thread->thread_handle ()))
414+
chld_procs[i].wait_thread->terminate_thread ();
414415
/* Release memory associated with this process unless it is 'myself'.
415416
'myself' is only in the chld_procs table when we've execed. We
416417
reach here when the next process has finished initializing but we

0 commit comments

Comments
 (0)