Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport console fixes #65

Merged
merged 5 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions include/ansidecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,49 @@ So instead we use the macro below and test it against specific values. */
# endif /* GNUC >= 4.9 */
#endif /* ATTRIBUTE_NO_SANITIZE_UNDEFINED */

/* Attribute 'nonstring' was valid as of gcc 8. */
#ifndef ATTRIBUTE_NONSTRING
# if GCC_VERSION >= 8000
# define ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
# else
# define ATTRIBUTE_NONSTRING
# endif
#endif

/* Attribute `alloc_size' was valid as of gcc 4.3. */
#ifndef ATTRIBUTE_RESULT_SIZE_1
# if (GCC_VERSION >= 4003)
# define ATTRIBUTE_RESULT_SIZE_1 __attribute__ ((alloc_size (1)))
# else
# define ATTRIBUTE_RESULT_SIZE_1
#endif
#endif

#ifndef ATTRIBUTE_RESULT_SIZE_2
# if (GCC_VERSION >= 4003)
# define ATTRIBUTE_RESULT_SIZE_2 __attribute__ ((alloc_size (2)))
# else
# define ATTRIBUTE_RESULT_SIZE_2
#endif
#endif

#ifndef ATTRIBUTE_RESULT_SIZE_1_2
# if (GCC_VERSION >= 4003)
# define ATTRIBUTE_RESULT_SIZE_1_2 __attribute__ ((alloc_size (1, 2)))
# else
# define ATTRIBUTE_RESULT_SIZE_1_2
#endif
#endif

/* Attribute `warn_unused_result' was valid as of gcc 3.3. */
#ifndef ATTRIBUTE_WARN_UNUSED_RESULT
# if GCC_VERSION >= 3003
# define ATTRIBUTE_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__))
# else
# define ATTRIBUTE_WARN_UNUSED_RESULT
# endif
#endif

/* We use __extension__ in some places to suppress -pedantic warnings
about GCC extensions. This feature didn't work properly before
gcc 2.8. */
Expand Down
32 changes: 24 additions & 8 deletions winsup/cygwin/fhandler/console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,12 @@ fhandler_console::cons_master_thread (handle_set_t *p, tty *ttyp)
}

WaitForSingleObject (p->input_mutex, mutex_timeout);
/* Ensure accessing input recored is not disabled. */
if (con.disable_master_thread)
{
ReleaseMutex (p->input_mutex);
continue;
}
total_read = 0;
switch (cygwait (p->input_handle, (DWORD) 0))
{
Expand Down Expand Up @@ -1005,10 +1011,14 @@ fhandler_console::read (void *pv, size_t& buflen)

push_process_state process_state (PID_TTYIN);

int copied_chars = 0;
size_t copied_chars = 0;

DWORD timeout = is_nonblocking () ? 0 : INFINITE;
DWORD timeout = is_nonblocking () ? 0 :
(get_ttyp ()->ti.c_lflag & ICANON ? INFINITE :
(get_ttyp ()->ti.c_cc[VMIN] == 0 ? 0 :
(get_ttyp ()->ti.c_cc[VTIME]*100 ? : INFINITE)));

read_more:
while (!input_ready && !get_cons_readahead_valid ())
{
int bgres;
Expand All @@ -1031,6 +1041,11 @@ fhandler_console::read (void *pv, size_t& buflen)
pthread::static_cancel_self ();
/*NOTREACHED*/
case WAIT_TIMEOUT:
if (copied_chars)
{
buflen = copied_chars;
return;
}
set_sig_errno (EAGAIN);
buflen = (size_t) -1;
return;
Expand Down Expand Up @@ -1076,19 +1091,20 @@ fhandler_console::read (void *pv, size_t& buflen)
}

/* Check console read-ahead buffer filled from terminal requests */
while (con.cons_rapoi && *con.cons_rapoi && buflen)
{
buf[copied_chars++] = *con.cons_rapoi++;
buflen --;
}
while (con.cons_rapoi && *con.cons_rapoi && buflen > copied_chars)
buf[copied_chars++] = *con.cons_rapoi++;

copied_chars +=
get_readahead_into_buffer (buf + copied_chars, buflen);
get_readahead_into_buffer (buf + copied_chars, buflen - copied_chars);

if (!con_ra.ralen)
input_ready = false;
release_input_mutex ();

if (buflen > copied_chars && !(get_ttyp ()->ti.c_lflag & ICANON)
&& copied_chars < get_ttyp ()->ti.c_cc[VMIN])
goto read_more;

#undef buf

buflen = copied_chars;
Expand Down
21 changes: 19 additions & 2 deletions winsup/cygwin/fhandler/pty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,8 @@ fhandler_pty_slave::open (int flags, mode_t)
errmsg = "can't call master, %E";
goto err;
}
CloseHandle (repl.to_slave_nat); /* not used. */
CloseHandle (repl.to_slave); /* not used. */
from_master_nat_local = repl.from_master_nat;
from_master_local = repl.from_master;
to_master_nat_local = repl.to_master_nat;
Expand Down Expand Up @@ -1218,6 +1220,10 @@ fhandler_pty_slave::reset_switch_to_nat_pipe (void)
if (!CallNamedPipe (pipe, &req, sizeof req,
&repl, sizeof repl, &len, 500))
return; /* What can we do? */
CloseHandle (repl.from_master); /* not used. */
CloseHandle (repl.to_master); /* not used. */
CloseHandle (repl.to_slave_nat); /* not used. */
CloseHandle (repl.to_slave); /* not used. */
CloseHandle (get_handle_nat ());
set_handle_nat (repl.from_master_nat);
CloseHandle (get_output_handle_nat ());
Expand Down Expand Up @@ -3932,10 +3938,20 @@ fhandler_pty_slave::transfer_input (tty::xfer_dir dir, HANDLE from, tty *ttyp,
if (!CallNamedPipe (pipe, &req, sizeof req,
&repl, sizeof repl, &len, 500))
return; /* What can we do? */
CloseHandle (repl.from_master_nat); /* not used. */
CloseHandle (repl.from_master); /* not used. */
CloseHandle (repl.to_master_nat); /* not used. */
CloseHandle (repl.to_master); /* not used. */
if (dir == tty::to_nat)
to = repl.to_slave_nat;
{
CloseHandle (repl.to_slave); /* not used. */
to = repl.to_slave_nat;
}
else
to = repl.to_slave;
{
CloseHandle (repl.to_slave_nat); /* not used. */
to = repl.to_slave;
}
}

UINT cp_from = 0, cp_to = 0;
Expand Down Expand Up @@ -4066,6 +4082,7 @@ fhandler_pty_slave::transfer_input (tty::xfer_dir dir, HANDLE from, tty *ttyp,
transfered = true;;
}
}
CloseHandle (to);

/* Fix input_available_event which indicates availability in cyg pipe. */
if (dir == tty::to_nat) /* all data is transfered to nat pipe,
Expand Down
Loading