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: pty: Add still missing acquire/release_attach_mutex. Date: Wed, 2 Mar 2022 19:54:07 +0000 (GMT) [thread overview] Message-ID: <20220302195407.936843858D39@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=7a9321ceef27e80ca1e3bd94c3c2cf55f9f60160 commit 7a9321ceef27e80ca1e3bd94c3c2cf55f9f60160 Author: Takashi Yano <takashi.yano@nifty.ne.jp> Date: Thu Mar 3 04:18:31 2022 +0900 Cygwin: pty: Add still missing acquire/release_attach_mutex. - 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 = tty::to_cyg; get_ttyp ()->pcon_pid = 0; @@ -1356,11 +1368,19 @@ fhandler_pty_slave::mask_switch_to_pcon_in (bool mask, bool xfer) if (!!masked != 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 = 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 == 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); line_edit_status status = line_edit (p, len, ti, &ret); @@ -4055,8 +4081,10 @@ fhandler_pty_slave::setup_for_non_cygwin_app (bool nopcon, 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 (handle_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 = false; HANDLE from = 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); }
reply other threads:[~2022-03-02 19:54 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=20220302195407.936843858D39@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: linkBe 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).