Joseph Faulls [Tue, 10 Oct 2023 19:12:00 +0000 (15:12 -0400)]
Delete check in catan, catanf, and catanl functions.
The check incorrectly results in catan returning nan + inf i when real part is +/- 1 and
imaginary part is 0. The same occurs for real 0.8 and imaginary 0.6.
Cygwin: dsp: Avoid setting buffer that is too small.
The buffer size that is too small causes choppy sound. That is not
practical at all. With this patch, the minimum value of the buffer
size (i.e. fragstotal * fragsize) is restricted to 16384 bytes.
Pekka Seppänen [Wed, 30 Aug 2023 09:16:36 +0000 (12:16 +0300)]
Reentrancy, attempt to always provide _Thread_local in <sys/reent.h>
Attempt to always provide _Thread_local in <sys/reent.h> by including
<sys/cdefs.h>. The C specific keyword _Thread_local is not available
unless targetting a suitable C version.
Pekka Seppänen [Wed, 30 Aug 2023 09:16:32 +0000 (12:16 +0300)]
Reentrancy, conditionally provide default __getreent() implementation
Conditionally provide default __getreent() implementation only if
_REENT_THREAD_LOCAL is not defined. If struct _reent is replaced by
dedicated thread-local objects neither the structure nor _impure_ptr is
available.
Pekka Seppänen [Wed, 30 Aug 2023 09:16:26 +0000 (12:16 +0300)]
Reentrancy, use _REENT_ERRNO()
Use _REENT_ERRNO() macro to access errno. This encapsulation is
required, as errno might be either _errno member of struct _reent,
_tls_errno or any such implementation detail.
If specified, set version timestamp to this value.
Enable deterministic archives for ar and ranlib.
Set cygwin1.dll PE and export table header timestamps to zero.
Signed-off-by: Christian Franke <christian.franke@t-online.de>
Cygwin: NFS: create devices (especially FIFOs) as shortcut files
Creating real NFS symlinks for device files has a major downside:
The way we store device info requires to change the symlink target
in case of calling chmod(2). This falls flat in two ways:
- It requires to remove and recreate the symlink, so it doesn't
exist for a short period of time, and
- removing fails badly if there's another open handle to the symlink.
Therefore, change this to create FIFOs as shortcut files, just as on
most other filesystems. Make sure to recognize these new shortcuts
on NFS (for devices only) in path handling and readdir.
Fixes: 622fb0776ea3 ("Cygwin: enable usage of FIFOs on NFS") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
MSFT NFSv3 fakes DOS attributes based on file type and permissions.
Rather than just faking FILE_ATTRIBUTE_DIRECTORY for dirs, fetch the
"real" DOS attributes returned by NFS.
This allows to handle the "R/O" attribute on shortcut files and thus
reading and creating device shortcut files on NFS.
fhandler_base::fchown casts any fhandler landing here to a
fhandler_disk_file. That's ugly and dangerous. Duplicate
the path_conv info into an explicitly create fhandler_disk_file
instead and call fchmod on that.
By handling native NFS FIFOs as actual FIFOs, chmod on a FIFO
suddenly called fhandler_base::fchmod, which is insufficient
to handle FIFO files on any filesystem.
Note that this does not fix Cygwin FIFOs on NFS or AFS yet.
Fixes: 622fb0776ea3 ("Cygwin: enable usage of FIFOs on NFS") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Cygwin: dsp: Improve response time of select()/poll().
With this patch, the response time of select()/poll() has been
improved by utilizing semaphore (select_sem) just like pipe and
fifo. In addition, notification of exceptional conditions has
been added.
Corinna Vinschen [Sat, 26 Aug 2023 13:41:18 +0000 (15:41 +0200)]
Cygwin: enable usage of FIFOs on NFS
FIFOs on NFS were never recogized as such in path handling.
stat(2) indicated native FIFOs as FIFOs but the path handling
code didn't set the matching values in the inner symlink checking
code, so the followup behaviour was wrong.
Basically for the same reason, Cygwin-created FIFOs were just treated
as symlinks with weird content by stat(2) as well as path handling.
Add code to enable both types of FIFOs on NFS as Cygwin FIFOs.
The latest incarnation of sys/cpuset.h broke building coreutils.
The reason is the inclusion of stdlib.h and string.h and hence
premature requests for datatypes not yet defined in the include
chain.
Avoid this by defining __cpuset_alloc and __cpuset_free as external
functions, now defined in sched.cc. Linux is doing this too, just
using different names for the functions. Redefine __cpuset_zero_s
to use __builtin_memset only on compilers supporting it, otherwise
using a simple loop. Drop the stdlib.h and string.h includes.
Fixes: 3f2790e04439 ("Cygwin: Make gcc-specific code in <sys/cpuset.h> compiler-agnostic") Reported-by: Denis Excoffier <cygwin@Denis-Excoffier.org> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Pekka Seppänen [Mon, 28 Aug 2023 11:02:20 +0000 (14:02 +0300)]
libc/stdlib/nano-mallocr.c, typo in variable name
Nano malloc uses `size' in assertation whereas the correct variable would be
`s'. Given this has existed ever since nano malloc support was added, based
on the context ("returned payload area of desired size does not exceed the
actual allocated chunk") I presume that indeed `s' (user input) and not
`r->size' (computed) shall be used.
Corinna Vinschen [Tue, 29 Aug 2023 09:55:10 +0000 (11:55 +0200)]
Cygwin: execve: drop argument size limit
Before commit 44f73c5a6206 ("Cygwin: Fix segfalt when too many command
line args are specified.") we had no actual argument size limit, except
for the fact that the child process created another copy of the argv
array on the stack, which could result in a stack overflow and a
subsequent SEGV. Commit 44f73c5a6206 changed that by allocating the
additional argv array via malloc, and it introduced a new SC_ARG_MAX
limit along the lines of the typical Linux limit.
However, this new limit is artificial. Cygwin allocates all argument
and environment data on the cygheap. We only run out of ARG_MAX space
if we're out of memory resources.
Change argument size handling accordingly:
- Drop the args size check from child_info_spawn::worker.
- Return -1 from sysconf (SC_ARG_MAX), i. e., the argument size limit
is undefined.
- Change argv handling in class av, so that a failing cmalloc is not
fatal. This allows the parent process to return E2BIG if it's out
of cygheap resources.
- In the child, add a check around the new malloc call, so that it
doesn't result in a SEGV if the child process gets unexpectedly into
an ENOMEM situation at this point. In this (unlikely) case, proceed
with the original __argv array instead. Add comment to explain why.
Fixes: 44f73c5a6206 ("Cygwin: Fix segfalt when too many command line args are specified.") Tested-by: Takashi Yano <takashi.yano@nifty.ne.jp> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Takashi Yano [Mon, 28 Aug 2023 13:14:41 +0000 (22:14 +0900)]
Cygwin: Fix segfalt when too many command line args are specified.
Previously, the number of command line args was not checked for
cygwin process. Due to this, segmentation fault was caused if too
many command line args are specified.
https://cygwin.com/pipermail/cygwin/2023-August/254333.html
Since char *argv[argc + 1] is placed on the stack in dll_crt0_1(),
STATUS_STACK_OVERFLOW occurs if the stack does not have enough
space.
With this patch, char *argv[] is placed in heap instead of stack
and ARG_MAX is increased from 32000 to 2097152 which is default
value of Linux. The argument length is also compared with ARG_MAX
and spawnve() returns E2BIG if it is too long.
Takashi Yano [Sat, 19 Aug 2023 05:10:16 +0000 (14:10 +0900)]
Cygwin: pty: Fix failure to clear switch_to_nat_pipe flag.
After the commit fbfea31dd9b9, switch_to_nat_pipe is not cleared
properly when non-cygwin app is terminated in the case where the
pseudo console is disabled. This is because get_winpid_to_hand_over()
sometimes returns PID of cygwin process even though it should return
only PID of non-cygwin process. This patch fixes the issue by adding
a new argument which requests only PID of non-cygwin process to
get_console_process_id().
Fixes: fbfea31dd9b9 ("Cygwin: pty: Avoid cutting the branch the pty master is sitting on.") Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Takashi Yano [Tue, 15 Aug 2023 23:00:27 +0000 (08:00 +0900)]
Cygwin: shared: Fix access permissions setting in open_shared().
After the commit 93508e5bb841, the access permissions argument passed
to open_shared() is ignored and always replaced with (FILE_MAP_READ |
FILE_MAP_WRITE). This causes the weird behaviour that sshd service
process loses its cygwin PID. This triggers the failure in pty that
transfer_input() does not work properly.
This patch resumes the access permission settings to fix that.
Takashi Yano [Mon, 14 Aug 2023 10:48:12 +0000 (19:48 +0900)]
Cygwin: pty: Add missing pinfo check in transfer_input().
The commit 10d083c745dd has a bug that lacks a check for pinfo pointer
value for master_pid. This causes segmentation fault if the process
whose pid is master_pid no longer exists. This patch fixes the issue.
Fixes: 10d083c745dd ("Cygwin: pty: Inherit typeahead data between two input pipes.") Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Corinna Vinschen [Tue, 15 Aug 2023 20:34:29 +0000 (22:34 +0200)]
Cygwin: cXXrtomb, mbrtcXX: use function-specific internal state
As described in the previous commit b5111e46424b
("struct _reent: add state for unicode functions") every unicode
conversion function has to use their own state object, if the
state parameter is NULL.
Corinna Vinschen [Tue, 15 Aug 2023 20:30:59 +0000 (22:30 +0200)]
struct _reent: add state for unicode functions
C23 requires that the unicode functions c16rtomb, c8rtomb, mbrtoc16,
mbrtoc32 and mbrtoc8 use their own internal state object. c32rtomb
only needs an internal state if the lib supports encoding with
shift states, but that's the case for newlib and Cygwin.
Only Cygwin implements these functions so add the states
objects only for Cygwin for now.
sys/unistd.h: define GNU extensions SEEK_DATA and SEEK_HOLE
SEEK_DATA and SEEK_HOLE are GNU nonstandard extensions also present
in Solaris, FreeBSD, and DragonFly BSD; they are proposed for inclusion
in the next POSIX revision (Issue 8).
Cygwin: fix build failure due to redefinition of __restrict in sys/cdefs.h
Commit 3c75fac130b5 fixed the __restrict definition in sys/cdefs.h,
but uncovered a problem in the definition of lio_listio in Cygwin's
aio.h. It uses the C99 extension of using the restrict keyword
to define non-overlapping arrays. However, this is not allowed in
C++.
Use the newly defined __restrict_arr from commit e66c63be6b80
("sys/cdefs.h: introduce __restrict_arr, as in glibc")
Fixes: 3c75fac130b5 ("sys/cdefs.h: fix for use __restrict in C++" Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
As an extension, GCC and clang offer C99-style restricted pointers in
C++ mode:
https://gcc.gnu.org/onlinedocs/gcc/Restricted-Pointers.html
We notice that this extension is broken when including newlib headers:
restricted pointers are treated as ordinary pointers.
We traced this to the following section of
newlib/libc/include/sys/cdefs.h:
/*
* GCC 2.95 provides `__restrict' as an extension to C90 to support the
* C99-specific `restrict' type qualifier. We happen to use `__restrict' as
* a way to define the `restrict' type qualifier without disturbing older
* software that is unaware of C99 keywords.
*/
#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95)
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901
#define __restrict
#else
#define __restrict restrict
#endif
#endif
While the GCC __restrict extension was indeed introduced in GCC 2.95, it
is not limited to this version; the extension is also not limited to
C90:
https://gcc.gnu.org/gcc-2.95/c++features.html
Rewrite the logic in the header so that __restrict is kept alone when
available.
Takashi Yano [Fri, 4 Aug 2023 08:45:34 +0000 (17:45 +0900)]
Cygwin: pty: Fix thread safety of readahead buffer handling in pty master.
Previously, though readahead buffer handling in pty master was not
fully thread-safe, accept_input() was called from peek_pipe() thread
in select.cc. This caused the problem reported in:
https://cygwin.com/pipermail/cygwin/2023-July/253984.html
The mechanism of the problem is:
1) accept_input() which is called from peek_pipe() thread calls
eat_readahead(-1) before reading readahead buffer. This allows
writing to the readahead buffer from another (main) thread.
2) The main thread calls fhandler_pty_master::write() just after
eat_readahead(-1) was called and before reading the readahead
buffer by accept_input() called from peek_pipe() thread. This
overwrites the readahead buffer.
3) The read result from readahead buffer which was overwritten is
sent to the slave.
This patch makes readahead buffer handling fully thread-safe using
input_mutex to resolve this issue.
Fixes: 7b03b0d8cee0 ("select.cc (peek_pipe): Call flush_to_slave whenever we're checking for a pty master.") Reported-by: Thomas Wolff <towo@towo.net> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Cygwin: uchar.h: fix definition of uchar16_t and uchar32_t
Per C++11, uchar16_t and uchar32_t are defined the same as
uint_least16_t and uint_least32_t. Also, check for the C++
version to make sure that the types are not colliding with
predefined c++ types.
After the commit a4705d387f78, printf() for floating-point values
causes a memory leak. The legacy _ldtoa_r() assumed the char pointer
returned will be free'ed by Bfree(). However, gdtoa-based _ldtoa_r()
returns the pointer returned by gdtoa() which should be free'ed by
freedtoa(). Due to this issue, the caller of _ldtoa_r() fails to free
the allocated char buffer. This is the cause of the said memory leak.
https://cygwin.com/pipermail/cygwin/2023-July/254054.html
This patch makes rv_alloc()/freedtoa() allocate/free the buffer in
a compatible way with legacy _ldtoa_r().
The FD_WRITE event is a false friend. It indicates ready to write
even if the next send fails with WSAEWOULDBLOCK. *After* the fact,
FD_WRITE will be cleared until sending is again possible, but that
is too late for a select/write loop.
Workaround that by using the WinSock select function when peeking
at a socket and FD_WRITE gets indicated. WinSock select fortunately
indicates writability correctly.
Fixes: 70e476d27be8 ("(peek_socket): Use event handling for peeking socket.") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This macro loads and defines a function just as usual, except
that the Windows function is exposed only with the prefix
_win32_. So Windows select (the immediate victim) is only
exposed as _win32_select. That allows to autoload the windows
function without collision with a Cygwin function of the same
name.
For a start, only define the most simple macro, setting all
extensions to 0.
Cygwin: Add ISO C11 functions c16rtomb, c32rtomb, mbrtoc16, mbrtoc32.
Add uchar.h accordingly.
For the c32 functions, use the internal functions wirtomb and mbrtowi
as base, and convert wirtomb and mbrtowi to inline functions calling
the c32 functions.
The changes to support GB18030 were insufficient and the underlying
Windows conversion functions just failed. Fix how the Windows functions
are called for GB18030.
Fixes: 5da71b605995 ("Cygwin: add support for GB18030 codeset") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
For some reason lost in time, commit 2b77087a48ea5 introduced
Cygwin-specific code treating single byte characters outside the
portable character set as illegal chars. However, Cygwin was
always alone with this over-correct behaviour and it leads to
stuff like gnulib replacing functions defined in Cygwin with
their own implementation just due to that.
Revert this change, sans the changes to ChangeLog.
Cygwin: belatedly bump CYGWIN_VERSION_API_MINOR for new posix_spawn funcs
Commit c743751aafa84 ("Cygwin: Export
posix_spawn_file_actions_add{f}chdir_np")
added two new functions but we forgot to bump the API version.
Catch up.
Commit c36064bbd0c5 introduced operating on character pointers
instead of operating on characters, to allow collating symbols.
This patch neglected to change the expression for range
comparison in case we're in the C locale. Thus it suddenly
compared pointers instead of characters. Fix that.
Fixes: c36064bbd0c5 ("Cygwin: fnmatch: support collating symbols in [. .] brackets") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Fix rounding results in lrint() & llrint() when close to 0
soft-fp should round floating pointer numbers according to the current
rounding mode. However, in the current code of lrint() and llrint(),
there are if statements before the actual rounding computation
if(j0 < -1)
return 0;
Where j0 is the exponent of the floating point number.
It means any number having a exponent less than -1
(i.e. interval (-0.5, 0.5)) will be rounded to 0 regardeless of the
rounding mode.
The bug already fixed in glibc in 2006 by moving the check afterwards
the rounding computation, but still persists in newlib.
Rename _NL_CTYPE_OUTDIGITSx_MB/WC to _NL_CTYPE_OUTDIGITx_MB/WC
The extended _NL_foo names were originally designed after their GLibc
counterparts. However, the OUTDIGIT macros were accidentally defined as
OUTDIGITS, plural. Fix them.
Fixes: d47d5b850bed ("Extend locale support to maintain wide char values of native strings") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Zfinx/Zdinx are new extensions ratified in 2022, it similar to F/D extensions,
support hard float operation for single/double precision, but the difference
between Zfinx/Zdinx and F/D is Zfinx/Zdinx is operating under general purpose
registers rather than dedicated floating-point registers.
This patch improve the hard float support detection for RISC-V port, so
that Zfinx/Zdinx can have better/right performance.
The GLIBC extension AT_EMPTY_PATH allows the functions fchownat
and fstatat to operate on dirfd alone, if the given pathname is an
empty string. This also allows to operate on any file type, not
only directories.
Commit fa84aa4dd2fb4 broke this. It only allows dirfd to be a
directory in calls to these two functions.
Fix that by handling AT_EMPTY_PATH right in gen_full_path_at.
A valid dirfd and an empty pathname is now a valid combination
and, noticably, this returns a valid path in path_ret. That
in turn allows to remove the additional path generation code
from the callers.
Fixes: fa84aa4dd2fb ("Cygwin: fix errno values set by readlinkat") Reported-by: Johannes Schindelin <johannes.schindelin@gmx.de> Tested-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Convert gen_full_path_at to take flag values from the caller, rather
than just a bool indicating that empty paths are allowed. This is in
preparation of a better AT_EMPTY_PATH handling in a followup patch.
Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Cygwin needs an internal flag to allow specifying an empty pathname
in utimesat (GLIBC extension). We define it in _default_fcntl.h to
make sure we never introduce a value collision accidentally.
While at it, define the values as 16 bit hex values.
Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The check if the local variable p is NULL is useless. The preceeding
code always sets p to a valid pointer, or it crashes if path_ret is
invalid (which would be a bug in Cygwin).
Jon Turney [Sat, 22 Jul 2023 12:23:15 +0000 (13:23 +0100)]
Cygwin: CI: Upgrade checkout actions to avoid deprecation warning
Also: workaround a problem with actions/checkout's post-run step using
Cygwin git but being incompatible with it. (This would be better solved
by cygwin-install-action having a post-run step to unwind it's PATH
changes, but that's not currently possible)
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
Jon Turney [Wed, 24 Aug 2022 17:21:18 +0000 (18:21 +0100)]
Cygwin: testsuite: Drop using DejaGnu to run tests
A more sophisticated (and modern) test harness would probably be useful,
but switching to Automake's built-in test harness gets us parallel test
execution, colourization of failures, simplifies matters, seems adequate
for the current testuite, and means we don't need to write any icky Tcl.
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>