From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 936843858D39; Wed, 2 Mar 2022 19:54:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 936843858D39 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_3-branch] Cygwin: pty: Add still missing acquire/release_attach_mutex. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/cygwin-3_3-branch X-Git-Oldrev: d2f690ac8f2bdc7277d8ae617d1517957b1f58e4 X-Git-Newrev: 7a9321ceef27e80ca1e3bd94c3c2cf55f9f60160 Message-Id: <20220302195407.936843858D39@sourceware.org> Date: Wed, 2 Mar 2022 19:54:07 +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: Wed, 02 Mar 2022 19:54:07 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D7a9321ceef2= 7e80ca1e3bd94c3c2cf55f9f60160 commit 7a9321ceef27e80ca1e3bd94c3c2cf55f9f60160 Author: Takashi Yano Date: Thu Mar 3 04:18:31 2022 +0900 Cygwin: pty: Add still missing acquire/release_attach_mutex. =20 - transfer_input() function uses console api, so it should be guarded by attach_mutex. However, in most cases, it is missing. This patch fixes the issue. Diff: --- winsup/cygwin/fhandler_tty.cc | 46 +++++++++++++++++++++++++++++++++++----= ---- winsup/cygwin/tty.cc | 4 ++++ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 76b5cba18..1fd8a6094 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -241,8 +241,10 @@ atexit_func (void) && ttyp->pcon_input_state_eq (tty::to_nat) && !force_switch_to) { WaitForSingleObject (ptys->input_mutex, mutex_timeout); + acquire_attach_mutex (mutex_timeout); fhandler_pty_slave::transfer_input (tty::to_cyg, from, ttyp, input_available_event); + release_attach_mutex (); ReleaseMutex (ptys->input_mutex); } WaitForSingleObject (ptys->pcon_mutex, INFINITE); @@ -1102,8 +1104,10 @@ fhandler_pty_slave::set_switch_to_pcon (void) && get_ttyp ()->pcon_input_state_eq (tty::to_cyg)) { WaitForSingleObject (input_mutex, mutex_timeout); + acquire_attach_mutex (mutex_timeout); transfer_input (tty::to_nat, get_handle (), get_ttyp (), input_available_event); + release_attach_mutex (); ReleaseMutex (input_mutex); } } @@ -1153,8 +1157,10 @@ fhandler_pty_slave::reset_switch_to_pcon (void) && get_ttyp ()->pcon_input_state_eq (tty::to_nat)) { WaitForSingleObject (input_mutex, mutex_timeout); + acquire_attach_mutex (mutex_timeout); transfer_input (tty::to_cyg, get_handle_nat (), get_ttyp (), input_available_event); + release_attach_mutex (); ReleaseMutex (input_mutex); } if (get_ttyp ()->master_is_running_as_service @@ -1267,8 +1273,10 @@ fhandler_pty_slave::reset_switch_to_pcon (void) && get_ttyp ()->switch_to_pcon_in) { WaitForSingleObject (input_mutex, mutex_timeout); + acquire_attach_mutex (mutex_timeout); transfer_input (tty::to_cyg, get_handle_nat (), get_ttyp (), input_available_event); + release_attach_mutex (); ReleaseMutex (input_mutex); } } @@ -1280,8 +1288,12 @@ fhandler_pty_slave::reset_switch_to_pcon (void) WaitForSingleObject (input_mutex, mutex_timeout); if (get_ttyp ()->switch_to_pcon_in && !get_ttyp ()->pcon_activated && get_ttyp ()->pcon_input_state_eq (tty::to_nat)) - transfer_input (tty::to_cyg, get_handle_nat (), get_ttyp (), - input_available_event); + { + acquire_attach_mutex (mutex_timeout); + transfer_input (tty::to_cyg, get_handle_nat (), get_ttyp (), + input_available_event); + release_attach_mutex (); + } ReleaseMutex (input_mutex); get_ttyp ()->pcon_input_state =3D tty::to_cyg; get_ttyp ()->pcon_pid =3D 0; @@ -1356,11 +1368,19 @@ fhandler_pty_slave::mask_switch_to_pcon_in (bool ma= sk, bool xfer) if (!!masked !=3D mask && xfer && (need_gdb_xfer || need_xfer)) { if (mask && get_ttyp ()->pcon_input_state_eq (tty::to_nat)) - transfer_input (tty::to_cyg, get_handle_nat (), get_ttyp (), - input_available_event); + { + acquire_attach_mutex (mutex_timeout); + transfer_input (tty::to_cyg, get_handle_nat (), get_ttyp (), + input_available_event); + release_attach_mutex (); + } else if (!mask && get_ttyp ()->pcon_input_state_eq (tty::to_cyg)) - transfer_input (tty::to_nat, get_handle (), get_ttyp (), - input_available_event); + { + acquire_attach_mutex (mutex_timeout); + transfer_input (tty::to_nat, get_handle (), get_ttyp (), + input_available_event); + release_attach_mutex (); + } } ReleaseMutex (input_mutex); } @@ -2283,9 +2303,11 @@ fhandler_pty_master::write (const void *ptr, size_t = len) if (get_readahead_valid ()) accept_input (); WaitForSingleObject (input_mutex, mutex_timeout); + acquire_attach_mutex (mutex_timeout); fhandler_pty_slave::transfer_input (tty::to_nat, from_master, get_ttyp (), input_available_event); + release_attach_mutex (); ReleaseMutex (input_mutex); } get_ttyp ()->pcon_start_pid =3D 0; @@ -2337,8 +2359,12 @@ fhandler_pty_master::write (const void *ptr, size_t = len) non-cygwin app is terminated if pseudo console is disabled. */ if (to_be_read_from_pcon () && !get_ttyp ()->pcon_activated && get_ttyp ()->pcon_input_state =3D=3D tty::to_cyg) - fhandler_pty_slave::transfer_input (tty::to_nat, from_master, - get_ttyp (), input_available_event); + { + acquire_attach_mutex (mutex_timeout); + fhandler_pty_slave::transfer_input (tty::to_nat, from_master, + get_ttyp (), input_available_event); + release_attach_mutex (); + } ReleaseMutex (input_mutex); =20 line_edit_status status =3D line_edit (p, len, ti, &ret); @@ -4055,8 +4081,10 @@ fhandler_pty_slave::setup_for_non_cygwin_app (bool n= opcon, PWCHAR envblock, && stdin_is_ptys && get_ttyp ()->pcon_input_state_eq (tty::to_cyg)) { WaitForSingleObject (input_mutex, mutex_timeout); + acquire_attach_mutex (mutex_timeout); transfer_input (tty::to_nat, get_handle (), get_ttyp (), input_available_event); + release_attach_mutex (); ReleaseMutex (input_mutex); } } @@ -4070,8 +4098,10 @@ fhandler_pty_slave::cleanup_for_non_cygwin_app (hand= le_set_t *p, tty *ttyp, && ttyp->pcon_input_state_eq (tty::to_nat)) { WaitForSingleObject (p->input_mutex, mutex_timeout); + acquire_attach_mutex (mutex_timeout); transfer_input (tty::to_cyg, p->from_master_nat, ttyp, p->input_available_event); + release_attach_mutex (); ReleaseMutex (p->input_mutex); } WaitForSingleObject (p->pcon_mutex, INFINITE); diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc index 1782be6c5..44be3c8b4 100644 --- a/winsup/cygwin/tty.cc +++ b/winsup/cygwin/tty.cc @@ -323,9 +323,11 @@ tty_min::setpgid (int pid) && ttyp->pcon_input_state_eq (tty::to_cyg)) { WaitForSingleObject (ptys->input_mutex, mutex_timeout); + acquire_attach_mutex (mutex_timeout); fhandler_pty_slave::transfer_input (tty::to_nat, ptys->get_handle (), ttyp, ptys->get_input_available_event ()); + release_attach_mutex (); ReleaseMutex (ptys->input_mutex); } else if (was_pcon_fg && !pcon_fg && ttyp->switch_to_pcon_in @@ -333,6 +335,7 @@ tty_min::setpgid (int pid) { bool attach_restore =3D false; HANDLE from =3D ptys->get_handle_nat (); + acquire_attach_mutex (mutex_timeout); if (ttyp->pcon_activated && ttyp->pcon_pid && !ptys->get_console_process_id (ttyp->pcon_pid, true)) { @@ -359,6 +362,7 @@ tty_min::setpgid (int pid) AttachConsole (ATTACH_PARENT_PROCESS); init_console_handler (false); } + release_attach_mutex (); } ReleaseMutex (ptys->pcon_mutex); }