Commit Graph

20179 Commits

Author SHA1 Message Date
Takashi Yano 0063ffeb73 Cygwin: pipe: Fix deadlock if pipe is created by non-cygwin app. 2021-09-13 17:45:55 +02:00
Takashi Yano 0b538118b2 Cygwin: fifo: Utilize select_sem for fifo as well as pipe. 2021-09-13 17:45:55 +02:00
Corinna Vinschen ba4c58299f 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>
2021-09-13 17:45:55 +02:00
Takashi Yano 08b8534d0a Cygwin: pipe: Fix notification timing of select_sem.
- Make select_sem notify even when read/write partially.
2021-09-13 17:45:54 +02:00
Takashi Yano 597f87294d Cygwin: select: Introduce select_sem semaphore for pipe.
- This patch introduces select_sem semaphore which notifies pipe status
  change.
2021-09-13 17:45:54 +02:00
Takashi Yano b07660ac19 Revert "Cygwin: select: Improve select/poll response."
... because this commit (23bb19ef) causes high CPU load.
2021-09-13 17:45:54 +02:00
Ken Brown 99be238347 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.
2021-09-13 17:45:54 +02:00
Corinna Vinschen 27b24069d1 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>
2021-09-13 17:45:54 +02:00
Corinna Vinschen 9d7fd8d416 Cygwin: pipes: handle signals and thread cancellation in blocking mode only
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:54 +02:00
Corinna Vinschen 4003e3dfa1 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>
2021-09-13 17:45:54 +02:00
Corinna Vinschen 477a593693 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>
2021-09-13 17:45:54 +02:00
Takashi Yano fadbedd9ca 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.
2021-09-13 17:45:54 +02:00
Ken Brown 085fc12948 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().
2021-09-13 17:45:54 +02:00
Ken Brown eb50f82677 Cygwin: FIFO: open pipes with FILE_READ_ATTRIBUTES access
This is needed by NtQueryInformationFile, which is used by select.
2021-09-13 17:45:54 +02:00
Ken Brown 44693e80b1 Cygwin: pipes: minor code cleanup
Clarify a comment in raw_read, and remove a useless line from
raw_write.
2021-09-13 17:45:54 +02:00
Corinna Vinschen 82643bd18e 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>
2021-09-13 17:45:54 +02:00
Corinna Vinschen ea9c0bbedc Cygwin: pipes: call nt_create with handle references
...to avoid potential pointer mishandling.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:54 +02:00
Corinna Vinschen 8653eb1df3 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>
2021-09-13 17:45:54 +02:00
Corinna Vinschen a5b2c735e6 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>
2021-09-13 17:45:54 +02:00
Corinna Vinschen fcccc4b743 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>
2021-09-13 17:45:54 +02:00
Corinna Vinschen 8efcee2500 Cygwin: pipes: use NtClose when file has been opened with an NtXxx function
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:54 +02:00
Corinna Vinschen b12cf6b3cf Cygwin: pipes: always close read side pipe handle in error case
Add missing CloseHandle.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:54 +02:00
Corinna Vinschen 464f7145f6 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>
2021-09-13 17:45:54 +02:00
Corinna Vinschen e9d4cb765f 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>
2021-09-13 17:45:54 +02:00
Corinna Vinschen 9cfbb5aa82 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>
2021-09-13 17:45:53 +02:00
Corinna Vinschen 28eac9272f Revert "Cygwin: fhandler_pipe.cc:nt_select: fix flags"
This reverts commit a62f4d128505481c4c683e813a3b16da641af6ff.
2021-09-13 17:45:53 +02:00
Corinna Vinschen 71f02bcc3f Revert "Cygwin: fhandler_pipe.cc:nt_select: fix flags again"
This reverts commit c35db324efb5cdc6605eac947e0d4fdeb45e8b43.
2021-09-13 17:45:53 +02:00
Ken Brown 6b52d97900 Cygwin: fhandler_pipe.cc:nt_select: fix flags again 2021-09-13 17:45:53 +02:00
Ken Brown 9d4e58be76 Cygwin: fhandler_pipe.cc:nt_select: fix flags 2021-09-13 17:45:53 +02:00
Ken Brown 24b7a74b94 Revert "Cygwin: pipe: Revert to create() rather than nt_create()."
This reverts commit 5a7a0d34c74a55aa1e76644e61bf4889051cb640.
2021-09-13 17:45:53 +02:00
Takashi Yano cf3a7a9132 Cygwin: pipe: Revert to create() rather than nt_create(). 2021-09-13 17:45:53 +02:00
Takashi Yano b75d855fb0 Cygwin: select: Improve select/poll response. 2021-09-13 17:45:53 +02:00
Ken Brown 8a10f6302c 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.
2021-09-13 17:45:53 +02:00
Ken Brown f002d02b17 Cygwin: remove the fhandler_base_overlapped class
Also remove the 'was_nonblocking' flag, which was needed only for
fhandler_base_overlapped.
2021-09-13 17:45:53 +02:00
Ken Brown f56206cd86 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.
2021-09-13 17:45:53 +02:00
Ken Brown d0ad52aa6e 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.
2021-09-13 17:45:53 +02:00
Ken Brown 4b25687ea3 Cygwin: fhandler_pipe: add raw_read and raw_write 2021-09-13 17:45:53 +02:00
Ken Brown 72e083c4a0 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.
2021-09-13 17:45:53 +02:00
Corinna Vinschen 8c8d3b7a94 Regenerate Makefile.in after configure.in -> configure.ac change
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:25:46 +02:00
Mike Frysinger e8e0eb7398 Add myself to sim & general write-after-approval maintainers
There are a few files that are tied to the GNU simulator, so add myself
to match the general sim project.

Also add myself to the general write-after-approval since I've been doing
that for a long time now anyways :).
2021-09-13 10:14:37 -04:00
Mike Frysinger 920617998e libgloss/newlib: rename configure.in to configure.ac
The .in name has been deprecated for a long time in favor of .ac.
2021-09-13 10:14:37 -04:00
Corinna Vinschen 8fba45f0cc Cygwin: fix initializing MEM_EXTENDED_PARAMETER, take 2
In https://cygwin.com/pipermail/cygwin/2021-September/249361.html
Brian pointed out that initializing the structure would be more
future proof, should the developers at Microsoft ever decide to
split the Reserved field and use some bits of the struct for
other purposes.

Fixes: 3d322ac930 ("Cygwin: fix initializing MEM_EXTENDED_PARAMETER")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-08 10:07:46 +02:00
Takashi Yano b52f10c4ca Cygwin: pty: Fix error handling of master write().
- Currently, error handling of write() in pty master side is broken.
  This patch fixes that.
2021-09-07 20:21:18 +02:00
Torbjorn SVENSSON via Newlib 522cdab541 nano-malloc: Fix redefined compilation warning
When newlib is configured with --enable-newlib-reent-check-verify,
the assert macro is already defined in the nano-mallocr.c compile unit.

Contributed by STMicroelectronics

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>
2021-09-06 20:29:39 +02:00
Corinna Vinschen 3d322ac930 Cygwin: fix initializing MEM_EXTENDED_PARAMETER
MEM_EXTENDED_PARAMETER consists of a 64 bit bitfield which contains
the Type and the Reserved members.  The former usage of designated
initializer lists initialized Type, but not Reserved.  Since that's
not possible anymore due to a g++ 11.2 bug, Cygwin initializes the
MEM_EXTENDED_PARAMETER structs explicitely.  This results in a
random value in Reserved, which at least VirtualAlloc2 chokes on
(ERROR_INVALID_PARAMETER).

Set Reserved explicitely to 0 for a fix.

Fixes: bdb7991db3 ("Cygwin: workaround a g++ 11.2 initialization bug")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-06 20:28:34 +02:00
Corinna Vinschen eeeb5650cf Cygwin: fix declaration of RtlInitEmptyUnicodeString
This avoids "-Werror=maybe-uninitialized" errors due to
using WCSTR accidentally.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-03 13:16:48 +02:00
Corinna Vinschen 76c2c7a891 ldexp/ldexpf: avoid assembler warning
libm/machine/i386/f_ldexp.S:30: Warning: no instruction mnemonic suffix given and no register operands; using default for `fild'
libm/machine/i386/f_ldexpf.S:30: Warning: no instruction mnemonic suffix given and no register operands; using default for `fild'

fix this by adding the l mnemonic suffix

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-03 12:52:47 +02:00
Corinna Vinschen c2fe205b50 strstr: avoid warnings
unused function warning for two_way_short_needle,
different char type warnings for standard string functions

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-03 12:51:30 +02:00
Corinna Vinschen 6a35ae33f5 nftw: fix thread cancellation support
_STDIO_WITH_THREAD_CANCELLATION_SUPPORT was never defined.
Include ../stdio/local.h to get the right definition per target.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-03 12:26:17 +02:00
Corinna Vinschen d5cc66426b Cygwin: testsuite: avoid "conflicting types" gcc warning
With gcc 11.2:

test.h:50:5: warning: conflicting types for built-in function ‘execve’; expected ‘int(const char *, char * const*)’ [-Wbuiltin-declaration-mismatch]
test.h:51:5: warning: conflicting types for built-in function ‘execv’; expected ‘int(const char *, char * const*)’ [-Wbuiltin-declaration-mismatch]
test.h:52:5: warning: conflicting types for built-in function ‘execvp’; expected ‘int(const char *, char * const*)’ [-Wbuiltin-declaration-mismatch]

Fix prototypes accordingly.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-03 12:15:53 +02:00