]> sourceware.org Git - newlib-cygwin.git/log
newlib-cygwin.git
2 years agolibgloss/newlib: update configure.ac in Makefile.in files
Mike Frysinger [Tue, 14 Sep 2021 02:53:54 +0000 (22:53 -0400)]
libgloss/newlib: update configure.ac in Makefile.in files

The maintainer rules refer to configure.in directly, so update that
after renaming all the configure.ac files.

2 years agoCygwin: fix permission problem when writing DAC info on Samba shares
Corinna Vinschen [Thu, 4 Nov 2021 20:48:45 +0000 (21:48 +0100)]
Cygwin: fix permission problem when writing DAC info on Samba shares

Cygwin always requests FILE_WRITE_ATTRIBUTES permissions when trying to
change DAC information.  This can lead to permission problems when
trying to chmod/chown files on Samba shares.  Drop requesting
FILE_WRITE_ATTRIBUTES on Samba shares and go with WRITE_DAC/WRITE_OWNER
only.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: Add a new 3.4.0 rel notes file
Corinna Vinschen [Thu, 4 Nov 2021 10:59:25 +0000 (11:59 +0100)]
Cygwin: Add a new 3.4.0 rel notes file

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: add release note for rounding issue
Corinna Vinschen [Thu, 4 Nov 2021 10:54:22 +0000 (11:54 +0100)]
Cygwin: add release note for rounding issue

Also rename release 3.4.0 to 3.3.2.  It doesn't make sense to
duplicate the issues fixed in 3.3.x into the 3.4.0 relnotes.
Only patches not backported into 3.3.x belong into 3.4.0.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoldtoa: fix dropping too many digits from output
Corinna Vinschen [Thu, 4 Nov 2021 10:30:44 +0000 (11:30 +0100)]
ldtoa: fix dropping too many digits from output

ldtoa cuts the number of digits it returns based on a computation of
number of supported bits (144) divide by log10(2).  Not only is the
integer approximation of log10(2) ~= 8/27 missing a digit here, it
also fails to take really small double and long double values into
account.

Allow for the full potential precision of long double values.  At the
same time, change the local string array allocation to request only as
much bytes as necessary to support the caller-requested number of
digits, to keep the stack size low on small targets.

In the long run a better fix would be to switch to gdtoa, as the BSD
variants, as well as Mingw64 do.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: console: Prevent the exec'ed bash from exiting by Ctrl-C.
Takashi Yano [Wed, 3 Nov 2021 06:14:42 +0000 (15:14 +0900)]
Cygwin: console: Prevent the exec'ed bash from exiting by Ctrl-C.

- Currently, bash occasionally exits by Ctrl-C with the following
  scenario.
    1) Start bash in the command prompt.
    2) Run 'exec bash'.
    3) Press Ctrl-C several times.
  This patch fixes the issue.

2 years agoCygwin: add release note
Corinna Vinschen [Tue, 2 Nov 2021 14:10:58 +0000 (15:10 +0100)]
Cygwin: add release note

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: console: Fix yet another bug on input when signalled.
Takashi Yano [Tue, 2 Nov 2021 08:09:40 +0000 (17:09 +0900)]
Cygwin: console: Fix yet another bug on input when signalled.

- Currently, read() returns EINTR due to a bug if signal handler
  is SIG_DFL and the process is suspended by Ctrl-Z and restarted.
  This patch fixes the issue.

2 years agoCygwin: console: Fix a bug on input when signalled.
Takashi Yano [Tue, 2 Nov 2021 03:40:10 +0000 (12:40 +0900)]
Cygwin: console: Fix a bug on input when signalled.

- This patch fixes the bug that Ctrl-C sometimes does not work as
  expected in Windows Terminal.

Addresses:
  https://cygwin.com/pipermail/cygwin/2021-November/249749.html

2 years agoCygwin: remove unused lsaauth authentication function
Corinna Vinschen [Fri, 29 Oct 2021 19:03:07 +0000 (21:03 +0200)]
Cygwin: remove unused lsaauth authentication function

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: remove support for Vista entirely
Corinna Vinschen [Fri, 29 Oct 2021 16:18:24 +0000 (18:18 +0200)]
Cygwin: remove support for Vista entirely

Fix up a few comments while at it

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: drop support for systems not supporting the CONSOLE LOGON SID
Corinna Vinschen [Fri, 29 Oct 2021 16:17:00 +0000 (18:17 +0200)]
Cygwin: drop support for systems not supporting the CONSOLE LOGON SID

i. e. Vista/2008.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: drop support for systems not supporting RFC 4646 locales
Corinna Vinschen [Fri, 29 Oct 2021 16:15:22 +0000 (18:15 +0200)]
Cygwin: drop support for systems not supporting RFC 4646 locales

i. e. Vista/2008.  This drops support for the sr_CS locale.

Regenerate LC_MESSAGES and LC_TIME ERA data from more recent Linux

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: drop support for systems not supporting processor groups
Corinna Vinschen [Fri, 29 Oct 2021 16:11:27 +0000 (18:11 +0200)]
Cygwin: drop support for systems not supporting processor groups

i. e., Vista/2008.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: drop support for simple invisible console code
Corinna Vinschen [Fri, 29 Oct 2021 16:08:32 +0000 (18:08 +0200)]
Cygwin: drop support for simple invisible console code

i. e., Vista/2008.

AllocConsole appears to allow creating a console only on the currently
visible desktop since Windows 7, which broke the simple code opening
the console on an invisible desktop in an invisible window station.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: drop support for systems not supporting QueryUnbiasedInterruptTime
Corinna Vinschen [Fri, 29 Oct 2021 16:01:33 +0000 (18:01 +0200)]
Cygwin: drop support for systems not supporting QueryUnbiasedInterruptTime

i. e., Vista/2008

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: drop Vista WOW64 specific child process handle bug
Corinna Vinschen [Fri, 29 Oct 2021 12:52:58 +0000 (14:52 +0200)]
Cygwin: drop Vista WOW64 specific child process handle bug

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: bump DLL major version cygwin-3.4.0-dev
Corinna Vinschen [Thu, 28 Oct 2021 20:29:42 +0000 (22:29 +0200)]
Cygwin: bump DLL major version

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: bump DLL minor version
Corinna Vinschen [Thu, 28 Oct 2021 11:41:19 +0000 (13:41 +0200)]
Cygwin: bump DLL minor version

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoUnconditionally declare strsignal cygwin-3_3_0-release
Christian Biesinger via Newlib [Wed, 27 Oct 2021 16:41:22 +0000 (12:41 -0400)]
Unconditionally declare strsignal

Currently, newlib does not declare strsignal if DEFS_H is defined,
ostensibly to work around a gdb bug. However, gdb itself compiles
even with this ifndef removed, and this makes sim (another part of
gdb) fail to compile.

Since it is not clear exactly what issue this was working around,
this patch just replaces that ifdef with the correct check,
i.e. __POSIX_VISIBLE >= 200809.

2 years agolibgloss/riscv: Fix hard coded reference to configure.in after rename
Lewis Revill [Wed, 27 Oct 2021 13:24:06 +0000 (14:24 +0100)]
libgloss/riscv: Fix hard coded reference to configure.in after rename

The file configure.in was renamed to configure.ac in libgloss/riscv but
the hard coded name in the Makefile for that directory was not updated.
This patch simply renamed this to configure.ac.

2 years agoCygwin: convert malloc lock to SRWLOCK
Corinna Vinschen [Tue, 26 Oct 2021 15:53:08 +0000 (17:53 +0200)]
Cygwin: convert malloc lock to SRWLOCK

Per https://cygwin.com/pipermail/cygwin-developers/2021-October/012429.html,
we may encounter a crash when starting multiple threads during process
startup (here: fhandler_fifo::fixup_after_{fork,exec}) which in turn
allocate memory via malloc.

The problem is concurrent usage of malloc before the malloc muto has
been initialized.

To fix this issue, convert the muto to a SRWLOCK and make sure it is
statically initalized.  Thus, malloc can be called as early as necessary
and malloc_init is only required to check for user space provided malloc.

Note that this requires to implement a __malloc_trylock macro to be
called from fork.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: Make native clipboard layout same for 32- and 64-bit
Mark Geisert [Mon, 25 Oct 2021 09:25:40 +0000 (02:25 -0700)]
Cygwin: Make native clipboard layout same for 32- and 64-bit

This patch unifies the layout of the clipboard descriptor cygcb_t for
32- and 64-bit Cygwin.  It allows correct copy/paste between the two
environments without corruption of user's copied data and without access
violations due to interpreting that data as a size field.

The definitions of CYGWIN_NATIVE and cygcb_t are moved to a new include
file, sys/clipboard.h.  The include file is used by fhandler_clipboard.cc
as well as getclip.c and putclip.c in the Cygwin cygutils package.

When copy/pasting between 32- and 64-bit Cygwin environments, both must
be running version 3.3.0 or later for successful operation.

2 years agoCygwin: document sig2str and str2sig in version.h
Ken Brown [Fri, 22 Oct 2021 17:56:05 +0000 (13:56 -0400)]
Cygwin: document sig2str and str2sig in version.h

2 years agoCygwin: drop outdated -O3 optimization for malloc and sync
Corinna Vinschen [Fri, 22 Oct 2021 10:47:09 +0000 (12:47 +0200)]
Cygwin: drop outdated -O3 optimization for malloc and sync

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: update cygcheck OS information
Corinna Vinschen [Thu, 21 Oct 2021 16:33:35 +0000 (18:33 +0200)]
Cygwin: update cygcheck OS information

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipe: Use NtQuerySystemInformation() instead of EnumProcesses().
Takashi Yano [Tue, 19 Oct 2021 08:40:19 +0000 (17:40 +0900)]
Cygwin: pipe: Use NtQuerySystemInformation() instead of EnumProcesses().

- Using EnumProcess() breaks Windows Vista compatibility. This patch
  replaces EnumProcesses() with NtQuerySystemInformation().

Addresses:
https://cygwin.com/pipermail/cygwin-developers/2021-October/012422.html

2 years agostring: Fix buffer overrun in picolibc/newlib/libc/string/strrchr.c (#184)
Keith Packard [Mon, 11 Oct 2021 16:24:54 +0000 (09:24 -0700)]
string: Fix buffer overrun in picolibc/newlib/libc/string/strrchr.c (#184)

Reported by prodisDown:

In picolibc/newlib/libc/string/strrchr.c

if (i) { while ((s=strchr(s, i))) { last = s; s++; } } else { last = strchr(s, i); }

Value (for example 0xFFFFFF00) in if (i) can pass test and
then be typecasted to char inside strchr(). Then s++ and then
buffer overrun.

It can be fixed by preventive typecast i = (int) (char) i; or
typecasting inside expression if ((char) i).

Fixed by casting to char.

Signed-off-by: Keith Packard <keithp@keithp.com>
2 years agoCygwin: pty: Fix handle leak regarding attach_mutex.
Takashi Yano [Sun, 10 Oct 2021 00:49:53 +0000 (09:49 +0900)]
Cygwin: pty: Fix handle leak regarding attach_mutex.

- If the process having master pty opened is forked, attach_mutex
  fails to be closed when master is closed. This patch fixes the
  issue.

2 years agoCygwin: pty: Fix master closing error regarding attach_mutex.
Takashi Yano [Fri, 8 Oct 2021 16:28:54 +0000 (01:28 +0900)]
Cygwin: pty: Fix master closing error regarding attach_mutex.

- If two or more pty masters are opened in a process, closing master
  causes error when closing attach_mutex. This patch fixes the issue.

Addresses:
https://cygwin.com/pipermail/cygwin-developers/2021-October/012418.html

2 years agosys/tree.h: Red child with black sibling rotations
Sebastian Huber [Tue, 5 Oct 2021 13:53:47 +0000 (15:53 +0200)]
sys/tree.h: Red child with black sibling rotations

Add specialized rotations RB_RED_ROTATE_LEFT() and RB_RED_ROTATE_RIGHT() which
may be used if we rotate a red child which has a black sibling.  Such a red
node must have at least two child nodes so that the following red-black tree
invariant is fulfilled:

  Every path from a given node to any of its descendant NULL nodes goes through
  the same number of black nodes.

      PARENT
     /      \
  BLACK     RED
           /   \
        BLACK BLACK

2 years agosys/tree.h: Add parent rotations
Sebastian Huber [Tue, 5 Oct 2021 13:43:34 +0000 (15:43 +0200)]
sys/tree.h: Add parent rotations

Add specialized rotations RB_PARENT_ROTATE_LEFT() and RB_PARENT_ROTATE_RIGHT()
which may be used if the parent node exists and the direction of the child is
known.  The specialized rotations are derived from RB_ROTATE_LEFT() and
RB_ROTATE_RIGHT() where the RB_SWAP_CHILD() was replaced by a simple
assignment.

2 years agosys/tree.h: Simplify chain of conditions
Sebastian Huber [Tue, 5 Oct 2021 13:39:10 +0000 (15:39 +0200)]
sys/tree.h: Simplify chain of conditions

In RB_GENERATE_REMOVE_COLOR() simplify a chain of conditions of the following
pattern

if (x) {
  ...
} else if (!x) {
  ...
}

to

if (x) {
  ...
} else {
  ...
}

2 years agosys/tree.h: Simplify loop condition
Sebastian Huber [Tue, 5 Oct 2021 13:31:22 +0000 (15:31 +0200)]
sys/tree.h: Simplify loop condition

We have

  #define RB_ISRED(elm, field) \
    ((elm) != NULL && RB_COLOR(elm, field) == RB_RED)

So, the RB_ISRED() contains an implicit check for NULL.  In
RB_GENERATE_REMOVE_COLOR() the "elm" pointer cannot be NULL in the while
condition.  Use RB_COLOR(elm) == RB_BLACK instead.

2 years agoCygwin: pipe: Use ProcessHandleInformation if available.
Takashi Yano [Thu, 23 Sep 2021 14:33:55 +0000 (23:33 +0900)]
Cygwin: pipe: Use ProcessHandleInformation if available.

- The commit b531d6b0 introduced temporary_query_hdl() which uses
  SystemHandleInformation. With this patch, ProcessHandleInformation
  rather than SystemHandleInformation is used if it is available.
  This request is faster, however, is only available since Windows 8,
  therefore, SystemHandleInformation is used for Windows Vista and 7
  as before.

2 years agoCygwin: pipe: Introduce temporary query_hdl.
Takashi Yano [Mon, 20 Sep 2021 23:02:43 +0000 (08:02 +0900)]
Cygwin: pipe: Introduce temporary query_hdl.

- The commit f79a4611 introduced query_hdl, which is the read pipe
  handle kept in the write pipe instance in order to determine if
  the pipe is ready to write in select().  This implementation has
  a potential risk that the write side fails to detect the closure
  of the read side if more than one writer exists and one of them
  is a non-cygwin process.

  With this patch, the strategy of commit f79a4611 is used only if
  the process is running as a service.  For a normal process,
  instead of keeping query_hdl in the write pipe instance, it is
  retrieved temporarily when select() is called.  Actually, we
  want to use tenporary query_hdl for all processes, however, it
  does not work for service processes due to OpenProcess()
  failure.

2 years agoCygwin: pipes: remove unnecessary NULL checks for hdl_cnt_mtx
Ken Brown [Sat, 18 Sep 2021 13:25:20 +0000 (09:25 -0400)]
Cygwin: pipes: remove unnecessary NULL checks for hdl_cnt_mtx

In view of the previous changes to open_setup, we can always assume
that hdl_cnt_mtx is non-NULL.

2 years agoCygwin: make callers of open_setup check for failure
Ken Brown [Sat, 18 Sep 2021 13:10:23 +0000 (09:10 -0400)]
Cygwin: make callers of open_setup check for failure

open_setup is called by dtable::init_std_file_from_handle and
fhandler_base::open_with_arch.  In both cases, failure of open_setup
is now a fatal error.

Currently this can only happen in the following situation: A Cygwin
process is started by a non-Cygwin process, one of the standard IO
handles is a pipe handle, and Cygwin is unable to create a required
mutex (read_mtx or hdl_cnt_mtx).

2 years agoCygwin: fhandler_pipe::open_setup: fail on error creating mutexes
Ken Brown [Sat, 18 Sep 2021 12:34:04 +0000 (08:34 -0400)]
Cygwin: fhandler_pipe::open_setup: fail on error creating mutexes

2 years agoCygwin: allow open_setup to fail
Ken Brown [Sat, 18 Sep 2021 12:13:55 +0000 (08:13 -0400)]
Cygwin: allow open_setup to fail

Convert fhandler_base::open_setup to a (virtual) method that returns a
bool result.  For the moment, it and its overrides always return true.

2 years agoCygwin: statically link the tools in winsup/utils/mingw
Ken Brown [Sat, 18 Sep 2021 01:38:07 +0000 (21:38 -0400)]
Cygwin: statically link the tools in winsup/utils/mingw

This fixes the problem reported here:

  https://cygwin.com/pipermail/cygwin-developers/2021-September/012375.html

2 years agoCygwin: fix typos in release notes
Ken Brown [Fri, 17 Sep 2021 20:16:14 +0000 (16:16 -0400)]
Cygwin: fix typos in release notes

2 years agoCygwin: pipe, fifo: Move query_hdl and hdl_cnt_mtx to fhandler_pipe.
Takashi Yano [Thu, 16 Sep 2021 19:23:12 +0000 (04:23 +0900)]
Cygwin: pipe, fifo: Move query_hdl and hdl_cnt_mtx to fhandler_pipe.

- query_hdl and hdl_cnt_mtx are moved from fhandler_pipe_fifo to
  fhandler_pipe. Then reader_closed() is changed to virtual and
  overridden in fhandler_pipe.

2 years agoCygwin: pipe: Fix race issue regarding handle count.
Takashi Yano [Thu, 16 Sep 2021 14:21:57 +0000 (23:21 +0900)]
Cygwin: pipe: Fix race issue regarding handle count.

- This patch fixes the race issue in the handle counting to detect
  closure of read pipe, which is introduced by commit f79a4611.
  A mutex hdl_cnt_mtx is introduced for this issue.

2 years agoCygwin: pipe: Fix error handling in fhandler_pip::create().
Takashi Yano [Thu, 16 Sep 2021 14:15:17 +0000 (23:15 +0900)]
Cygwin: pipe: Fix error handling in fhandler_pip::create().

- Currently, error handling in fhandler_pipe::create() is broken.
  This patch fixes that.

2 years agoCygwin: close_all_files: Do not duplicate stderr for write pipe.
Takashi Yano [Thu, 16 Sep 2021 11:50:54 +0000 (20:50 +0900)]
Cygwin: close_all_files: Do not duplicate stderr for write pipe.

- Currently, the stderr handle is duplicated in close_all_files().
  This interferes the handle counting for detecting closure of read
  pipe, which is introduced by commit f79a4611. This patch stops
  duplicating stderr handle if it is write pipe.

2 years agoCygwin: select: check for negative return from pipe_data_available
Ken Brown [Wed, 15 Sep 2021 16:56:34 +0000 (12:56 -0400)]
Cygwin: select: check for negative return from pipe_data_available

Make sure except_ready is set (if except_selected) on a negative
return from pipe_data_available.

2 years agonewlib: sig2str: use __restrict
Mike Frysinger [Wed, 15 Sep 2021 05:04:14 +0000 (01:04 -0400)]
newlib: sig2str: use __restrict

This matches the header prototype style and most of newlib, and fixes
building with older versions of gcc which only accept the __ form.

2 years agolibgloss: add missing aclocal.m4 files
Mike Frysinger [Wed, 15 Sep 2021 04:27:13 +0000 (00:27 -0400)]
libgloss: add missing aclocal.m4 files

These subdirs were missing aclocal.m4 files pulling in macros from
../acinclude.m4 which caused some macros to not be expanded.  For
example, autoconf complains:

configure.ac:25: error: possibly undefined macro: LIB_AC_PROG_CC
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.

These were generated with aclocal-1.9 as that seems to be what was
used in these dirs previously, and with whatever version of autoconf
the specific subdir was using.  This should minimize diffs.

2 years agolibgloss: epiphany: rename symbol prefix cache var
Mike Frysinger [Wed, 15 Sep 2021 04:20:58 +0000 (00:20 -0400)]
libgloss: epiphany: rename symbol prefix cache var

Autoconf emits a warning for this:
configure.ac:75: warning: AC_CACHE_VAL(libc_symbol_prefix, ...): suspicious cache-id, must contain _cv_ to be cached

Rename the variable to match the naming in libnosys/ subdir.

2 years agolibgloss: fix AC_LANG_SOURCE warnings w/newer autoconf
Mike Frysinger [Wed, 15 Sep 2021 04:18:55 +0000 (00:18 -0400)]
libgloss: fix AC_LANG_SOURCE warnings w/newer autoconf

When running autoconf-2.69 in here, we get:
configure.ac:57: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body
../../lib/autoconf/lang.m4:193: AC_LANG_CONFTEST is expanded from...
../../lib/autoconf/general.m4:2503: _AC_PREPROC_IFELSE is expanded from...
../../lib/autoconf/general.m4:2518: AC_PREPROC_IFELSE is expanded from...
configure.ac:57: the top level
configure.ac:61: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body
../../lib/autoconf/lang.m4:193: AC_LANG_CONFTEST is expanded from...
../../lib/autoconf/general.m4:2503: _AC_PREPROC_IFELSE is expanded from...
../../lib/autoconf/general.m4:2518: AC_PREPROC_IFELSE is expanded from...
configure.ac:61: the top level

Add AC_LANG_PROGRAM wrappings to fix these.

2 years agoCygwin: pipes: don't call NtQueryInformationFile on read side of pipes
Corinna Vinschen [Wed, 15 Sep 2021 12:17:59 +0000 (14:17 +0200)]
Cygwin: pipes: don't call NtQueryInformationFile on read side of pipes

NtQueryInformationFile hangs if it's called on the read side handle of
a pipe while another thread or process is performing a blocking read.

Avoid select potentially hanging by calling NtQueryInformationFile
only on the write side of the pipe and using PeekNamedPipe otherwise.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: drop useless method fhandler_base::has_ongoing_io
Corinna Vinschen [Wed, 15 Sep 2021 11:58:36 +0000 (13:58 +0200)]
Cygwin: drop useless method fhandler_base::has_ongoing_io

This was a remnant of the fhandler_base_overlapped class.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipe: Do not call PeekNamedPipe() if it is not necessary.
Takashi Yano [Wed, 15 Sep 2021 00:55:57 +0000 (09:55 +0900)]
Cygwin: pipe: Do not call PeekNamedPipe() if it is not necessary.

- In pipe_data_available() in select.cc, PeekNamedPipe() call is
  not needed if WriteQuotaAvailable is non-zero because we already
  know the write pipe has a space. Therefore, with this patch,
  PeekNamedPipe() is called only when WriteQuotaAvailable is zero.
  This makes select() on pipe faster a bit.

2 years agoCygwin: document the recent pipe changes
Ken Brown [Tue, 14 Sep 2021 18:59:28 +0000 (14:59 -0400)]
Cygwin: document the recent pipe changes

2 years agoCygwin: pipe: Fix handling of EPIPE and SIGPIPE in raw_write().
Takashi Yano [Tue, 14 Sep 2021 11:59:08 +0000 (20:59 +0900)]
Cygwin: pipe: Fix handling of EPIPE and SIGPIPE in raw_write().

2 years agoCygwin: pipe, fifo: Release select_sem semaphore as much as needed.
Takashi Yano [Tue, 14 Sep 2021 09:50:49 +0000 (18:50 +0900)]
Cygwin: pipe, fifo: Release select_sem semaphore as much as needed.

- Currently, raw_read(), raw_write() and close() release select_sem
  unconditionally even if no waiter for select_sem exists. With this
  patch, only the minimum number of semaphores required is released.

2 years agoCygwin: pipe: Use read pipe handle for select() on write pipe.
Takashi Yano [Tue, 14 Sep 2021 10:10:48 +0000 (19:10 +0900)]
Cygwin: pipe: Use read pipe handle for select() on write pipe.

- Usually WriteQuotaAvailable retrieved by NtQueryInformationFile()
  on the write side reflects the space available in the inbound buffer
  on the read side. However, if a pipe read is currently pending,
  WriteQuotaAvailable on the write side is decremented by the number
  of bytes the read side is requesting. So it's possible (even likely)
  that WriteQuotaAvailable is 0, even if the inbound buffer on the
  read side is not full. This can lead to a deadlock situation:
  The reader is waiting for data, but select on the writer side
  assumes that no space is available in the read side inbound buffer.

  Currently, to avoid this stuation, read() does not request larger
  block than pipe size - 1. However, this mechanism does not take
  effect if the reader side is non-cygwin app.

  The only reliable information is available on the read side, so
  fetch info from the read side via the pipe-specific query handle
  (query_hdl) introduced.

  If the query_hdl (read handle) is kept in write side, writer can
  not detect closure of read pipe. Therefore, raw_write() counts
  write handle and query_hdl. If they are equal, only the pairs of
  write handle and query_hdl are alive. In this case, raw_write()
  returns EPIPE and raises SIGPIPE.

- Nonblocking pipes (PIPE_NOWAIT) are not well handled by non-Cygwin
  tools, so convert pipe handles to PIPE_WAIT handles when spawning
  a non-Cygwin process.

2 years agoCygwin: pipe, fifo: Call set_no_inheritance() for adjunct handles.
Takashi Yano [Tue, 14 Sep 2021 03:49:35 +0000 (12:49 +0900)]
Cygwin: pipe, fifo: Call set_no_inheritance() for adjunct handles.

- Currntly, set_no_inheritance() is not called for the adjunct handles
  such as select_sem. This patch fixes the issue.

2 years agoCygwin: fhandler_base::dup Reflect O_CLOEXEC to inheritance flag.
Takashi Yano [Tue, 14 Sep 2021 03:48:03 +0000 (12:48 +0900)]
Cygwin: fhandler_base::dup Reflect O_CLOEXEC to inheritance flag.

- Currently fhandler_base::dup duplicates handles with bInheritHandle
  TRUE unconditionally. This patch reflects O_CLOEXEC flag to that
  parameter.

2 years agoCygwin: pipes: do not duplicate sec_none{_nih} locally when creating objects
Corinna Vinschen [Mon, 13 Sep 2021 20:02:51 +0000 (22:02 +0200)]
Cygwin: pipes: do not duplicate sec_none{_nih} locally when creating objects

We already fetched the correct SECURITY_ATTRIBUTES at the start of
fhandler_pipe::create, so using another SECURITY_ATTRIBUTES object for
the mutex and semaphore objects doesn't make much sense.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: fix inheritence of select_sem on write side of pipe
Corinna Vinschen [Mon, 13 Sep 2021 17:33:56 +0000 (19:33 +0200)]
Cygwin: fix inheritence of select_sem on write side of pipe

select_sem gets created on the read side with inheritence settings
depending on the O_CLOEXEC flag.  Then it gets duplicated to the write
side with unconditional inheritence.  Fix that.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipe: Fix deadlock if pipe is created by non-cygwin app.
Takashi Yano [Sun, 12 Sep 2021 06:06:05 +0000 (15:06 +0900)]
Cygwin: pipe: Fix deadlock if pipe is created by non-cygwin app.

2 years agoCygwin: fifo: Utilize select_sem for fifo as well as pipe.
Takashi Yano [Thu, 9 Sep 2021 23:43:59 +0000 (08:43 +0900)]
Cygwin: fifo: Utilize select_sem for fifo as well as pipe.

2 years agoCygwin: pipes: always signal select_sem if any bytes are read or written
Corinna Vinschen [Thu, 9 Sep 2021 09:35:54 +0000 (11:35 +0200)]
Cygwin: pipes: always signal select_sem if any bytes are read or written

Fold all code branches potentially having read or written data into
a single if branch, so signalling select_sem catches all cases.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipe: Fix notification timing of select_sem.
Takashi Yano [Thu, 9 Sep 2021 03:08:39 +0000 (12:08 +0900)]
Cygwin: pipe: Fix notification timing of select_sem.

- Make select_sem notify even when read/write partially.

2 years agoCygwin: select: Introduce select_sem semaphore for pipe.
Takashi Yano [Wed, 8 Sep 2021 08:18:35 +0000 (17:18 +0900)]
Cygwin: select: Introduce select_sem semaphore for pipe.

- This patch introduces select_sem semaphore which notifies pipe status
  change.

2 years agoRevert "Cygwin: select: Improve select/poll response."
Takashi Yano [Wed, 8 Sep 2021 10:22:40 +0000 (19:22 +0900)]
Revert "Cygwin: select: Improve select/poll response."

... because this commit (23bb19ef) causes high CPU load.

2 years agoCygwin: set buffer size for pipes created by non-Cygwin processes
Ken Brown [Tue, 7 Sep 2021 21:40:21 +0000 (17:40 -0400)]
Cygwin: set buffer size for pipes created by non-Cygwin processes

Rename fhandler_pipe_and_fifo::max_atomic_write to pipe_buf_size.
This reflect its actual meaning better.  The fhandler_pipe_and_fifo
constructor initializes it to DEFAULT_PIPEBUFSIZE (== 64K), which is
the buffer size for the windows pipes created by fhandler_pipe and
fhandler_fifo.  But if we inherit a stdio pipe handle from a
non-Cygwin process, the buffer size could be different.

To remedy this, add a method fhandler_pipe::set_pipe_buf_size that
queries the OS for the pipe buffer size, and use it in
dtable::init_std_file_from_handle.

2 years agoCygwin: pipes: drop "tiny pipe" handling
Corinna Vinschen [Tue, 7 Sep 2021 10:56:48 +0000 (12:56 +0200)]
Cygwin: pipes: drop "tiny pipe" handling

Given we return 1 already if WriteQuotaAvailable is > 0, the condition
for tiny pipes is never true.  Fix the comments.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: handle signals and thread cancellation in blocking mode only
Corinna Vinschen [Tue, 7 Sep 2021 09:14:09 +0000 (11:14 +0200)]
Cygwin: pipes: handle signals and thread cancellation in blocking mode only

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: always terminate async IO in blocking mode
Corinna Vinschen [Tue, 7 Sep 2021 08:50:47 +0000 (10:50 +0200)]
Cygwin: pipes: always terminate async IO in blocking mode

In blocking mode, the underlying IO must always be terminated,
one way or the other, to make sure the application knows the exact
state after returning from the IO function.  Therefore, always call
CancelIo in blocking mode.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: cancel async IO if thread cancellation is in progress
Corinna Vinschen [Mon, 6 Sep 2021 12:35:05 +0000 (14:35 +0200)]
Cygwin: pipes: cancel async IO if thread cancellation is in progress

Just cancelling a thread doesn't cancel async IO started by this thread.
Fix this by returning from cygwait and calling CancelIo before canceling
self.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipe: Stop counting reader and read all available data.
Takashi Yano [Mon, 6 Sep 2021 11:12:16 +0000 (20:12 +0900)]
Cygwin: pipe: Stop counting reader and read all available data.

- By guarding read with read_mtx, no more than one ReadFile can
  be called simultaneously. So couting read handles is no longer
  necessary.
- Make raw_read code as similar as possible to raw_write code.

2 years agoCygwin: new class fhandler_pipe_fifo
Ken Brown [Fri, 3 Sep 2021 23:41:52 +0000 (19:41 -0400)]
Cygwin: new class fhandler_pipe_fifo

This is a parent of fhandler_pipe and fhandler_fifo for code that is
common between the two classes.  Currently it just contains
max_atomic_write and raw_write().  The latter is identical to what
used to be fhandler_pipe::raw_write().

2 years agoCygwin: FIFO: open pipes with FILE_READ_ATTRIBUTES access
Ken Brown [Fri, 3 Sep 2021 18:23:47 +0000 (14:23 -0400)]
Cygwin: FIFO: open pipes with FILE_READ_ATTRIBUTES access

This is needed by NtQueryInformationFile, which is used by select.

2 years agoCygwin: pipes: minor code cleanup
Ken Brown [Fri, 3 Sep 2021 13:42:00 +0000 (09:42 -0400)]
Cygwin: pipes: minor code cleanup

Clarify a comment in raw_read, and remove a useless line from
raw_write.

2 years agoCygwin: pipes: nt_create: set read handle to NULL in error case
Corinna Vinschen [Fri, 3 Sep 2021 08:59:02 +0000 (10:59 +0200)]
Cygwin: pipes: nt_create: set read handle to NULL in error case

Fix accidentally setting read handle to INVALID_HANDLE_VALUE in a
single error case.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: call nt_create with handle references
Corinna Vinschen [Fri, 3 Sep 2021 08:57:21 +0000 (10:57 +0200)]
Cygwin: pipes: call nt_create with handle references

...to avoid potential pointer mishandling.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: workaround unrelibale system info
Corinna Vinschen [Fri, 3 Sep 2021 08:48:40 +0000 (10:48 +0200)]
Cygwin: pipes: workaround unrelibale system info

FILE_PIPE_LOCAL_INFORMATION::WriteQuotaAvailable is unreliable.

Usually WriteQuotaAvailable on the write side reflects the space
available in the inbound buffer on the read side.  However, if a
pipe read is currently pending, WriteQuotaAvailable on the write side
is decremented by the number of bytes the read side is requesting.
So it's possible (even likely) that WriteQuotaAvailable is 0, even
if the inbound buffer on the read side is not full.  This can lead to
a deadlock situation: The reader is waiting for data, but select
on the writer side assumes that no space is available in the read
side inbound buffer.

This patch implements a workaround by never trying to read more than
half the buffer size blocking if the read buffer is empty.  This first
cut tries to take the number of open readers into account by reducing
the amount of requested bytes accordingly.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: fix POSIX requirement for non-blocking pipe writes
Corinna Vinschen [Fri, 3 Sep 2021 08:45:49 +0000 (10:45 +0200)]
Cygwin: pipes: fix POSIX requirement for non-blocking pipe writes

POSIX requires atomicity for non-blocking writes <= PIPE_BUF bytes
and writing of at least 1 byte if any buffer space is left.
Windows NtWriteFile returns STATUS_SUCCESS and "0 bytes written"
if the write doesn't match buffer space.  Fix this discrepancy.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: create pipes with synchronization enabled
Corinna Vinschen [Fri, 3 Sep 2021 08:32:30 +0000 (10:32 +0200)]
Cygwin: pipes: create pipes with synchronization enabled

This isn't used by Cygwin, but it might be used by Win32 processes
inheriting the handle.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: use NtClose when file has been opened with an NtXxx function
Corinna Vinschen [Fri, 3 Sep 2021 08:31:27 +0000 (10:31 +0200)]
Cygwin: pipes: use NtClose when file has been opened with an NtXxx function

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: always close read side pipe handle in error case
Corinna Vinschen [Fri, 3 Sep 2021 08:25:29 +0000 (10:25 +0200)]
Cygwin: pipes: always close read side pipe handle in error case

Add missing CloseHandle.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: pipes: fix a bug in raw_write
Corinna Vinschen [Fri, 3 Sep 2021 08:24:15 +0000 (10:24 +0200)]
Cygwin: pipes: fix a bug in raw_write

The buffer pointer is incremented by "chunk", which is what we
typically try to write, but this isn't what actually got written.
Increment the buffer pointer by what we actually wrote, as returned
by NtWriteFile.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: move get_obj_handle_count() to miscfuncs.cc
Corinna Vinschen [Fri, 3 Sep 2021 08:15:57 +0000 (10:15 +0200)]
Cygwin: move get_obj_handle_count() to miscfuncs.cc

get_obj_handle_count() is used in flock only so far, but pipe
handling might have a usage, too, soon.  Given that this function
might be generally useful and isn't restricted to flock usage,
move it to miscfuncs.cc and make it non-static.  Add a prototype
in miscfuncs.h.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoCygwin: _pipe: add a comment
Corinna Vinschen [Tue, 31 Aug 2021 08:50:23 +0000 (10:50 +0200)]
Cygwin: _pipe: add a comment

I wasted valuable minutes of my life just to find out why we export
this weird version of pipe.  In the pre-2000 era the idea was Cygwin
could be used as drop-in replacement for msvcrt.dll, apparently.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2 years agoRevert "Cygwin: fhandler_pipe.cc:nt_select: fix flags"
Corinna Vinschen [Tue, 31 Aug 2021 09:39:52 +0000 (11:39 +0200)]
Revert "Cygwin: fhandler_pipe.cc:nt_select: fix flags"

This reverts commit a62f4d128505481c4c683e813a3b16da641af6ff.

2 years agoRevert "Cygwin: fhandler_pipe.cc:nt_select: fix flags again"
Corinna Vinschen [Tue, 31 Aug 2021 09:39:49 +0000 (11:39 +0200)]
Revert "Cygwin: fhandler_pipe.cc:nt_select: fix flags again"

This reverts commit c35db324efb5cdc6605eac947e0d4fdeb45e8b43.

2 years agoCygwin: fhandler_pipe.cc:nt_select: fix flags again
Ken Brown [Mon, 30 Aug 2021 15:54:04 +0000 (11:54 -0400)]
Cygwin: fhandler_pipe.cc:nt_select: fix flags again

2 years agoCygwin: fhandler_pipe.cc:nt_select: fix flags
Ken Brown [Mon, 30 Aug 2021 15:11:49 +0000 (11:11 -0400)]
Cygwin: fhandler_pipe.cc:nt_select: fix flags

2 years agoRevert "Cygwin: pipe: Revert to create() rather than nt_create()."
Ken Brown [Mon, 30 Aug 2021 13:53:06 +0000 (09:53 -0400)]
Revert "Cygwin: pipe: Revert to create() rather than nt_create()."

This reverts commit 5a7a0d34c74a55aa1e76644e61bf4889051cb640.

2 years agoCygwin: pipe: Revert to create() rather than nt_create().
Takashi Yano [Sun, 29 Aug 2021 08:23:57 +0000 (17:23 +0900)]
Cygwin: pipe: Revert to create() rather than nt_create().

2 years agoCygwin: select: Improve select/poll response.
Takashi Yano [Fri, 27 Aug 2021 10:54:41 +0000 (19:54 +0900)]
Cygwin: select: Improve select/poll response.

2 years agoCygwin: add fhandler_base::npfs_handle
Ken Brown [Thu, 26 Aug 2021 22:05:53 +0000 (18:05 -0400)]
Cygwin: add fhandler_base::npfs_handle

It replaces the three identical functions of the same name in the
classes fhandler_pipe, fhandler_fifo, and fhandler_socket_unix.

2 years agoCygwin: remove the fhandler_base_overlapped class
Ken Brown [Thu, 26 Aug 2021 22:00:27 +0000 (18:00 -0400)]
Cygwin: remove the fhandler_base_overlapped class

Also remove the 'was_nonblocking' flag, which was needed only for
fhandler_base_overlapped.

2 years agoCygwin: fhandler_pipe: fix permission problem
Ken Brown [Sat, 25 May 2019 14:27:38 +0000 (10:27 -0400)]
Cygwin: fhandler_pipe: fix permission problem

The read handles of pipes created by CreateNamedPipe don't have
FILE_WRITE_ATTRIBUTES access unless the pipe is created with
PIPE_ACCESS_DUPLEX.  This causes set_pipe_non_blocking to fail on such
handles.  To fix this, add a helper function nt_create, which uses
NtCreateNamedPipeFile instead of CreateNamedPipe and gives us more
flexibility in setting access rights.

Use this helper function in fhandler_pipe::create (fhandler_pipe *[2],
unsigned, int), which is the version of fhandler_pipe::create used by
the pipe and pipe2 system calls.

For convenience, also add a static member function
fhandler_pipe::npfs_handle similar to those used by fhandler_fifo and
fhandler_socket_unix.

2 years agoCygwin: fhandler_pipe: control blocking mode of the Windows pipe
Ken Brown [Sat, 25 May 2019 17:05:49 +0000 (13:05 -0400)]
Cygwin: fhandler_pipe: control blocking mode of the Windows pipe

Add methods 'set_pipe_non_blocking' and 'fcntl' to keep the blocking
mode of the Windows pipe in sync with that of the fhandler_pipe
object.  This applies to pipes created with the 'pipe' and 'pipe2'
system calls.

2 years agoCygwin: fhandler_pipe: add raw_read and raw_write
Ken Brown [Sat, 25 May 2019 17:03:08 +0000 (13:03 -0400)]
Cygwin: fhandler_pipe: add raw_read and raw_write

2 years agoCygwin: fhandler_pipe: derive from fhandler_base
Ken Brown [Thu, 26 Aug 2021 20:57:21 +0000 (16:57 -0400)]
Cygwin: fhandler_pipe: derive from fhandler_base

Previously fhandler_pipe was derived from fhandler_base_overlapped,
which we are going to remove in a future commit.  Make minimal changes
so that the build still succeeds.

This page took 0.064664 seconds and 5 git commands to generate.