Commit Graph

20121 Commits

Author SHA1 Message Date
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
Corinna Vinschen 9069cb9171 Cygwin: dup: fix handle inheritence for disk file pread/pwrite handle
The handle is created non-inheritable but gets inheritable when
dup'ing the file descriptor.  Fix that.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-08-30 21:56:33 +02:00
Joel Sherrill dcb515a953 libc/include/sys/signal.h: Change __STDINT_EXP() to __SIZEOF_INT__
__STDINT_EXP() is provided by newlib but not by stdint-gcc.h. stdint-gcc.h
is used when the GCC argument -ffreestanding is used and this results in this
file not compiling.
2021-08-27 11:41:56 -05:00
Corinna Vinschen 801120c1f4 Cygwin: loader script: add DWARF 5 sections
Modern gcc's generate additional DWARF 5 debug sections, which were
still missing in our Cygwin loader script.  With ld from binutils 2.37,
this results in diagnostic output when linking the Cygwin DLL...

  ld: cygwin0.dll:/4: section below image base
  ld: cygwin0.dll:/20: section below image base
  ld: cygwin0.dll:/36: section below image base

...and the section addresses given to these sections (.debug_loclists,
.debug_rnglists, debug_line_str) will be wrong.

Fix this by adding the missing DWARF 5 sections to our linker script
template cygwin.sc.in.  Add a comment in terms of the deprecated
DWARF 4 section .debug_types.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2021-08-27 14:27:41 +02:00
Corinna Vinschen 88c0276358 Cygwin: Allow using CFLAGS also for C++ files
This was used before switching to automake to allow easy tweaking
of optimization and debugging settings from the command line during
testing.  Reenable.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-08-26 22:21:53 +02:00
Corinna Vinschen bdb7991db3 Cygwin: workaround a g++ 11.2 initialization bug
trying to use aggregate initialization syntax on a member of a
nameless union member failes in g++ 11.2.

Workaround this by using explicit initialization.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-08-26 22:21:45 +02:00
Corinna Vinschen 3ca80b360c Cygwin: dumper: fix up GCC pragma for g++ 11.2
The GCC diagnostic ignored "-Wstringop-overflow" pragma doesn't work
as expected anymore.  Use the still working expression.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-08-26 22:15:49 +02:00
Corinna Vinschen 8169e39abf Cygwin: C++17: register keyword is deprecated
The register keyword was already deprecated with C++11, but
with C++17 it has been entirely removed.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-08-26 22:14:11 +02:00
Roger Sayle 6bb96d13a2 nvptx: Emulate clock and other machine stubs.
This patch to the libc/machine/nvptx port of newlib implements an
approximation of "clock" and provides some additional stub routines.
These changes not only reduce the number of (link) failures in the GCC
testsuite when targeting nvptx-none, but also allow the NIST scimark4
benchmark to compile and run without modification.

newlib already contains support for backends to provide their own
clock implementations via -DCLOCK_PROVIDED.  That functionality is
used here to return an approximate elapsed time based on the NVidia
GPU's clock64 cycle counter.  Although not great, this is better than
the current behaviour of link error from the unresolved symbol
_times_r.

The other part of the patch is to add a small number of stub functions
to nvptx's misc.c.  Adding isatty, for example, resolves linking
problems in libc from the dependency in __smakebuf_r, and the sync
stub, for example, fixes the failure with GCC's
testsuite/gfortran.dg/ISO_Fortran_binding_14.f90 [which simply tests
that gfortran can call a/any C function].

newlib/
        configure.host: Add -DCLOCK_PROVIDED to newlib_cflags on nvptx*.

newlib/libc/machine/nvptx
        Makefile.am: Add clock.c to lib_a_SOURCES.
        clock.c: New source file to implement/approximate clock().
        misc.c: Add stubs for fstat, isatty, open, sync and unlink.
2021-08-25 10:20:27 +02:00