]> sourceware.org Git - newlib-cygwin.git/log
newlib-cygwin.git
11 months agoCygwin: Fix segfalt when too many command line args are specified.
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.

Reported-by: Ed Morton
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
11 months agoCygwin: termios: Refactor the function is_console_app().
Takashi Yano [Mon, 28 Aug 2023 08:38:52 +0000 (17:38 +0900)]
Cygwin: termios: Refactor the function is_console_app().

Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
11 months agoRevert "Cygwin: autoload: introduce LoadDLLfunc_pfx_only"
Corinna Vinschen [Sat, 26 Aug 2023 16:00:04 +0000 (18:00 +0200)]
Revert "Cygwin: autoload: introduce LoadDLLfunc_pfx_only"

This reverts commit 0e711d6cc9b5206335fe8562817b6d5e6cad876e.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
11 months agoRevert "Cygwin: select: workaround FD_WRITE network event handling"
Corinna Vinschen [Sat, 26 Aug 2023 15:59:58 +0000 (17:59 +0200)]
Revert "Cygwin: select: workaround FD_WRITE network event handling"

This reverts commit dedbbd74d0a8f3b7dfae6188321703a47bb8a2b3.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
11 months agoCygwin: document disabling mknod/mkfifo on NFS
Corinna Vinschen [Fri, 25 Aug 2023 12:50:48 +0000 (14:50 +0200)]
Cygwin: document disabling mknod/mkfifo on NFS

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
11 months agoCygwin: mknod: disable creating special files on NFS
Corinna Vinschen [Fri, 25 Aug 2023 12:39:04 +0000 (14:39 +0200)]
Cygwin: mknod: disable creating special files on NFS

This simply doesn't work (yet?) but leaves unusable files behind.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
11 months agoCygwin: doc: add new API calls in 3.5
Corinna Vinschen [Fri, 25 Aug 2023 09:11:32 +0000 (11:11 +0200)]
Cygwin: doc: add new API calls in 3.5

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
11 months agolibgloss: add Xtensa port
Alexey Lapshin [Tue, 8 Aug 2023 20:07:04 +0000 (00:07 +0400)]
libgloss: add Xtensa port

Supported esp32 and esp32s2 boards:
https://github.com/espressif/esp-toolchain-docs/blob/main/gcc/build-and-run-native-app.md

12 months agoCygwin: pty: Fix failure to clear switch_to_nat_pipe flag.
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>
12 months agonewlib: add Xtensa port
Alexey Lapshin [Wed, 16 Aug 2023 22:05:53 +0000 (02:05 +0400)]
newlib: add Xtensa port

12 months agoCygwin: shared: Fix access permissions setting in open_shared().
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.

Fixes: 93508e5bb841 ("Cygwin: open_shared: don't reuse shared_locations parameter as output")
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signedd-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
12 months agoCygwin: pty: Add missing pinfo check in transfer_input().
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>
12 months agoCygwin: cXXrtomb, mbrtcXX: use function-specific internal state
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.

Fixes: 4f258c55e87f ("Cygwin: Add ISO C11 functions c16rtomb, c32rtomb, mbrtoc16, mbrtoc32.")
Fixes: c49bc478b4a7 ("Cygwin: Add ISO C2X functions c8rtomb, mbrtoc8")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
12 months agostruct _reent: add state for unicode functions
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.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
12 months agoCygwin: testsuite: Tweak lseek03 after addition of SEEK_HOLE
Jon Turney [Thu, 10 Aug 2023 19:50:00 +0000 (20:50 +0100)]
Cygwin: testsuite: Tweak lseek03 after addition of SEEK_HOLE

After addition of SEEK_HOLE, the whence of *4* is not an invalid
argument, causing the test to FAIL.

See ltp commit  423e636a4c8f ("lseek03: change to fix with the lseek syscall")

12 months agoCygwin: testsuite: Add a small delay in kill01
Jon Turney [Tue, 8 Aug 2023 15:38:20 +0000 (16:38 +0100)]
Cygwin: testsuite: Add a small delay in kill01

Avoid transient failures by adding a small delay after fork()-ing to
allow the child to get into a state where it can recieve signals.

Also add same small delay to kill03 and kill04. kill02 has a more
elaborate setup where child processes write to a pipe to indicate they
have started.

12 months agoAdd wildcard support to recurse into sys include directories
Alexey Lapshin [Thu, 10 Aug 2023 18:13:11 +0000 (14:13 -0400)]
Add wildcard support to recurse into sys include directories

12 months agoCygwin: fhandler_base::lseek: fix formatting
Corinna Vinschen [Wed, 9 Aug 2023 16:08:16 +0000 (18:08 +0200)]
Cygwin: fhandler_base::lseek: fix formatting

Fixes: edfa581d3c5a ("Cygwin: lseek: implement SEEK_DATA and SEEK_HOLE for files")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
12 months agoCygwin: add SEEK_DATA/SEEK_HOLE addition to release message
Corinna Vinschen [Wed, 9 Aug 2023 15:21:54 +0000 (17:21 +0200)]
Cygwin: add SEEK_DATA/SEEK_HOLE addition to release message

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
12 months agoCygwin: lseek: implement SEEK_DATA and SEEK_HOLE for files
Corinna Vinschen [Wed, 9 Aug 2023 15:18:14 +0000 (17:18 +0200)]
Cygwin: lseek: implement SEEK_DATA and SEEK_HOLE for files

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
12 months agoCygwin: lseek: propagate new SEEK_DATA and SEEK_HOLE to fhandler
Corinna Vinschen [Wed, 9 Aug 2023 14:56:40 +0000 (16:56 +0200)]
Cygwin: lseek: propagate new SEEK_DATA and SEEK_HOLE to fhandler

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
12 months agoCygwin: clipboard: Only SEEK_SET and SEEK_CUR are supported
Corinna Vinschen [Wed, 9 Aug 2023 14:56:02 +0000 (16:56 +0200)]
Cygwin: clipboard: Only SEEK_SET and SEEK_CUR are supported

Make sure of that, especially given the addition of
SEEK_DATA and SEEK_HOLE.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
12 months agosys/unistd.h: define GNU extensions SEEK_DATA and SEEK_HOLE
Corinna Vinschen [Wed, 9 Aug 2023 14:51:57 +0000 (16:51 +0200)]
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).

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
12 months agoAdd stub for getentropy
Torbjörn SVENSSON [Tue, 8 Aug 2023 16:09:50 +0000 (18:09 +0200)]
Add stub for getentropy

Example test case that fails with undefined reference to getentropy:

Testing g++.robertl/eb77.C,  -std=c++20
doing compile
Executing on host: /build/gcc-13-2709-g9ac9fde961f/bin/arm-none-eabi-g++  /build/src/gcc/gcc/testsuite/g++.old-deja/g++.robertl/eb77.C  -mthumb -march=armv6s-m -mcpu=cortex-m0 -mfloat-abi=soft -fdiagnostics-plain-output   -fmessage-length=0  -std=c++20 -pedantic-errors -Wno-long-long        -Wl,--start-group -lc -lm -Wl,--end-group --specs=nosys.specs -Wl,--allow-multiple-definition -Wl,-u,_isatty,-u,_fstat   -Wl,-wrap,exit -Wl,-wrap,_exit -Wl,-wrap,main -Wl,-wrap,abort -Wl,g++_tg.o -lm -o ./eb77.exe    (timeout = 800)
spawn -ignore SIGHUP /build/gcc-13-2709-g9ac9fde961f/bin/arm-none-eabi-g++ /build/src/gcc/gcc/testsuite/g++.old-deja/g++.robertl/eb77.C -mthumb -march=armv6s-m -mcpu=cortex-m0 -mfloat-abi=soft -fdiagnostics-plain-output -fmessage-length=0 -std=c++20 -pedantic-errors -Wno-long-long -Wl,--start-group -lc -lm -Wl,--end-group --specs=nosys.specs -Wl,--allow-multiple-definition -Wl,-u,_isatty,-u,_fstat -Wl,-wrap,exit -Wl,-wrap,_exit -Wl,-wrap,main -Wl,-wrap,abort -Wl,g++_tg.o -lm -o ./eb77.exe
pid is 28414 -28414
/build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/bin/ld: /build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libstdc++.a(random.o): in function `std::(anonymous namespace)::__libc_getentropy(void*)':
(.text._ZNSt12_GLOBAL__N_117__libc_getentropyEPv+0x8): undefined reference to `getentropy'
/build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/bin/ld: /build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libstdc++.a(random.o): in function `std::random_device::_M_init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
(.text._ZNSt13random_device7_M_initERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x58): undefined reference to `getentropy'
/build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/bin/ld: /build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libc.a(libc_a-arc4random.o): in function `_rs_stir':
(.text._rs_stir+0x8): undefined reference to `getentropy'
collect2: error: ld returned 1 exit status
pid is -1
close result is 28414 exp6 0 1
output is /build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/bin/ld: /build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libstdc++.a(random.o): in function `std::(anonymous namespace)::__libc_getentropy(void*)':
(.text._ZNSt12_GLOBAL__N_117__libc_getentropyEPv+0x8): undefined reference to `getentropy'
/build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/bin/ld: /build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libstdc++.a(random.o): in function `std::random_device::_M_init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
(.text._ZNSt13random_device7_M_initERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x58): undefined reference to `getentropy'
/build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/bin/ld: /build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libc.a(libc_a-arc4random.o): in function `_rs_stir':
(.text._rs_stir+0x8): undefined reference to `getentropy'
collect2: error: ld returned 1 exit status
 status 1
compiler exited with status 1
FAIL: g++.old-deja/g++.robertl/eb77.C  -std=c++20 (test for excess errors)
Excess errors:
(.text._ZNSt12_GLOBAL__N_117__libc_getentropyEPv+0x8): undefined reference to `getentropy'
(.text._ZNSt13random_device7_M_initERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x58): undefined reference to `getentropy'
(.text._rs_stir+0x8): undefined reference to `getentropy'
UNRESOLVED: g++.old-deja/g++.robertl/eb77.C  -std=c++20 compilation failed to produce executable

Contributed by STMicroelectronics

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
12 months agoCygwin: CI: XFAIL umask03
Jon Turney [Tue, 1 Aug 2023 14:34:28 +0000 (15:34 +0100)]
Cygwin: CI: XFAIL umask03

umask03 fails in CI due to some not understood weirdness.

12 months agoCygwin: testsuite: Fix cygload test
Jon Turney [Sat, 22 Jul 2023 19:54:49 +0000 (20:54 +0100)]
Cygwin: testsuite: Fix cygload test

Use cygrun to isolate the cygload test from the current DLL, which
allows it to pass.

12 months agoCygwin: testsuite: Update README
Jon Turney [Mon, 10 Jul 2023 15:37:41 +0000 (16:37 +0100)]
Cygwin: testsuite: Update README

v2:
Polish instructions on adding a test

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
12 months agoCygwin: testsuite: Add '-notimeout' option to cygrun
Jon Turney [Thu, 20 Jul 2023 12:54:09 +0000 (13:54 +0100)]
Cygwin: testsuite: Add '-notimeout' option to cygrun

Add '-notimeout' option for cygrun.  This is very useful when using it
to run a test standalone and under a debugger.

Also: warn about excess arguments

12 months agoCygwin: fix build failure due to redefinition of __restrict in sys/cdefs.h
Corinna Vinschen [Mon, 7 Aug 2023 14:04:32 +0000 (16:04 +0200)]
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>
12 months agosys/cdefs.h: introduce __restrict_arr, as in glibc
Corinna Vinschen [Mon, 7 Aug 2023 13:59:42 +0000 (15:59 +0200)]
sys/cdefs.h: introduce __restrict_arr, as in glibc

C99 allows to define arrays as non-overlappiung using the restrict
keyword.  This is supported by GCC 3.1 and later, but it's not
allowed in C++.

This is in preparation of fixing a Cygwin build problem introduce by
commit 3c75fac130b5.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
12 months agosys/cdefs.h: fix for use __restrict in C++
Sebastian Huber [Sun, 6 Aug 2023 13:27:27 +0000 (16:27 +0300)]
sys/cdefs.h: fix for use __restrict in C++

Newlib shares large parts of <sys/cdefs.h> with FreeBSD and received
this bug report:

https://sourceware.org/pipermail/newlib/2023/020400.html

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.

PR: 272723
MFC after: 1 week

12 months ago<sys/cdefs.h>: Decay expression passed to fallback
John Baldwin [Fri, 27 Jan 2023 00:28:22 +0000 (16:28 -0800)]
<sys/cdefs.h>: Decay expression passed to fallback

version of __generic()

This ensures that __generic() more closely matches _Generic() when
using the fallback version when _Generic() is not available (such as
GCC).

Co-authored by: jrtc27
Reviewed by: jrtc27
Differential Revision: https://reviews.freebsd.org/D38215

12 months agoCygwin: pty: Fix thread safety of readahead buffer handling in pty master.
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>
12 months agonewlib: gdtoa: Suppress compiler warning.
Takashi Yano [Fri, 4 Aug 2023 08:42:18 +0000 (17:42 +0900)]
newlib: gdtoa: Suppress compiler warning.

Fixes: 5ac83ea47a7a ("newlib: Fix memory leak regarding gdtoa-based _ldtoa_r().")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
12 months agoCygwin: CI: don't run on both main and master refs
Jon Turney [Sat, 22 Jul 2023 16:47:02 +0000 (17:47 +0100)]
Cygwin: CI: don't run on both main and master refs

12 months agoCygwin: Add ISO C2X functions c8rtomb, mbrtoc8
Corinna Vinschen [Wed, 2 Aug 2023 14:55:52 +0000 (16:55 +0200)]
Cygwin: Add ISO C2X functions c8rtomb, mbrtoc8

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
12 months agosys/features.h: Define _ISOC2X_SOURCE and __ISO_C_VISIBLE
Corinna Vinschen [Wed, 2 Aug 2023 14:52:27 +0000 (16:52 +0200)]
sys/features.h: Define _ISOC2X_SOURCE and __ISO_C_VISIBLE

Add feature test for C2X code. Add matching definitions
_ISOC2X_SOURCE for requesting sources and __ISO_C_VISIBLE
to be used in headers.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
12 months agoCygwin: uchar.h: fix definition of uchar16_t and uchar32_t
Corinna Vinschen [Wed, 2 Aug 2023 14:50:23 +0000 (16:50 +0200)]
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.

Fixes: 4f258c55e87f ("Cygwin: Add ISO C11 functions c16rtomb, c32rtomb, mbrtoc16, mbrtoc32.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
12 months agonewlib: Fix memory leak regarding gdtoa-based _ldtoa_r().
Takashi Yano [Wed, 2 Aug 2023 05:31:53 +0000 (14:31 +0900)]
newlib: Fix memory leak regarding gdtoa-based _ldtoa_r().

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().

Fixes: a4705d387f78 ("ldtoa: Import gdtoa from OpenBSD.")
Reported-by: natan_b <natan_b@libero.it>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
12 months agoCygwin: select: workaround FD_WRITE network event handling
Corinna Vinschen [Tue, 1 Aug 2023 12:22:55 +0000 (14:22 +0200)]
Cygwin: select: workaround FD_WRITE network event handling

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>
12 months agoCygwin: autoload: introduce LoadDLLfunc_pfx_only
Corinna Vinschen [Tue, 1 Aug 2023 12:16:40 +0000 (14:16 +0200)]
Cygwin: autoload: introduce LoadDLLfunc_pfx_only

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.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
12 months agoCygwin: Add ISO C11 functions c16rtomb, c32rtomb, mbrtoc16, mbrtoc32.
Corinna Vinschen [Mon, 31 Jul 2023 20:38:28 +0000 (22:38 +0200)]
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.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
12 months agoCygwin: fix GB18030 support
Corinna Vinschen [Fri, 28 Jul 2023 21:33:52 +0000 (23:33 +0200)]
Cygwin: fix GB18030 support

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>
12 months agoRevert "* libc/stdlib/mbtowc_r.c (__ascii_mbtowc): Disallow conversion of"
Corinna Vinschen [Mon, 31 Jul 2023 10:44:16 +0000 (12:44 +0200)]
Revert "* libc/stdlib/mbtowc_r.c (__ascii_mbtowc): Disallow conversion of"

This reverts commit 2b77087a48ea56e77fca5aeab478c922f6473d7c.

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.

Fixes: 2b77087a48ea ("* libc/stdlib/mbtowc_r.c (__ascii_mbtowc): Disallow conversion of")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
12 months agoCygwin: belatedly bump CYGWIN_VERSION_API_MINOR for new posix_spawn funcs
Corinna Vinschen [Mon, 31 Jul 2023 20:23:45 +0000 (22:23 +0200)]
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.

Fixes: c743751aafa84 ("Cygwin: Export posix_spawn_file_actions_add{f}chdir_np")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
12 months agoCygwin: fnmatch: fix range comparison in C locale
Corinna Vinschen [Thu, 27 Jul 2023 19:57:49 +0000 (21:57 +0200)]
Cygwin: fnmatch: fix range comparison in C locale

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>
12 months agoFix rounding results in lrint() & llrint() when close to 0
Jesse Huang via Newlib [Thu, 27 Jul 2023 08:49:41 +0000 (01:49 -0700)]
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.

This patch fixed it in a similar way to glibc
Ref Commit in glibc: 6624dbc07b5a9fb316ed188ef01f65b8eea8b47c

12 months agoRename _NL_CTYPE_OUTDIGITSx_MB/WC to _NL_CTYPE_OUTDIGITx_MB/WC
Corinna Vinschen [Wed, 26 Jul 2023 17:48:34 +0000 (19:48 +0200)]
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>
12 months agoRISC-V: Support Zfinx/Zdinx extension.
Kito Cheng via Newlib [Wed, 26 Jul 2023 10:03:19 +0000 (18:03 +0800)]
RISC-V: Support Zfinx/Zdinx extension.

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.

Co-authored-by: Jesse Huang <jesse.huang@sifive.com>
12 months agoCygwin: add AT_EMPTY_PATH fix to release message
Corinna Vinschen [Wed, 12 Jul 2023 11:55:23 +0000 (13:55 +0200)]
Cygwin: add AT_EMPTY_PATH fix to release message

Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
12 months agoCygwin: Fix and streamline AT_EMPTY_PATH handling
Corinna Vinschen [Wed, 12 Jul 2023 11:47:49 +0000 (13:47 +0200)]
Cygwin: Fix and streamline AT_EMPTY_PATH handling

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>
12 months agoCygwin: use new _AT_NULL_PATHNAME_ALLOWED flag
Corinna Vinschen [Wed, 12 Jul 2023 11:45:24 +0000 (13:45 +0200)]
Cygwin: use new _AT_NULL_PATHNAME_ALLOWED flag

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>
12 months agoDefine _AT_NULL_PATHNAME_ALLOWED
Corinna Vinschen [Wed, 12 Jul 2023 11:27:04 +0000 (13:27 +0200)]
Define _AT_NULL_PATHNAME_ALLOWED

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>
12 months agoCygwin: gen_full_path_at: drop never reached code
Corinna Vinschen [Wed, 12 Jul 2023 11:31:31 +0000 (13:31 +0200)]
Cygwin: gen_full_path_at: drop never reached code

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).

Fixes: c57b57e5c43a ("* cygwin.din: Sort.")
Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
13 months agoCygwin: CI: Upgrade checkout actions to avoid deprecation warning
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>
13 months agoCygwin: CI: Retain test logs as a build artifact
Jon Turney [Sat, 8 Jul 2023 19:53:54 +0000 (20:53 +0100)]
Cygwin: CI: Retain test logs as a build artifact

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agoCygwin: testsuite: Drop using DejaGnu to run tests
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>
13 months agoCygwin: get_posix_access: do not merge permissions for just created files
Corinna Vinschen [Fri, 21 Jul 2023 19:49:54 +0000 (21:49 +0200)]
Cygwin: get_posix_access: do not merge permissions for just created files

When creating the POSIX ACL rewrite, the code merging permissions from
everyone/group to group/user ACEs was accidentally called for newly
generated files as well.

This could result in broken permissions, if umask used unusual values
like "0100", granted permissions to everyone/group not granted to
group/user.

Make sure to skip permission merging if the file got just created and
we only want to set correct permissions for the first time.

Fixes: bc444e5aa4ca ("Reapply POSIX ACL changes.")
Reported-by: Jon Turney <jon.turney@dronecode.org.uk>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
13 months agoCygwin: Fix uninitialized use of fh in strace output in stat_worker()
Jon Turney [Fri, 21 Jul 2023 13:22:27 +0000 (14:22 +0100)]
Cygwin: Fix uninitialized use of fh in strace output in stat_worker()

Move strace output to fix uninitalized use of fh introduced in previous commit.

../../../../src/winsup/cygwin/syscalls.cc: In function ‘int stat_worker(path_conv&, stat*)’:
../../../../src/winsup/cygwin/syscalls.cc:1971:69: error: ‘fh’ may be used uninitialized [-Werror=maybe-uninitialized]

Fixes: 42b44044b34d ("Cygwin: Fix Windows file handle leak in stat("file", -1)")
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agoCygwin: Fix Windows file handle leak in stat("file", -1)
Jon Turney [Mon, 17 Jul 2023 15:05:01 +0000 (16:05 +0100)]
Cygwin: Fix Windows file handle leak in stat("file", -1)

Don't leak a Windows file handle if stat() is called with a valid
filename, but invalid stat buffer pointer.

We do not destroy fh (which closes a Windows handle it has opened) if an
exception happens in the __try block.

Avoid this by re-ordering things so that we don't construct the fhandler
object until after we've attempted to use the struct stat buffer.

Fixes: 73151c54d581 ("syscalls.cc (stat_worker): Don't call build_fh_pc with invalid pc.")
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agoCygwin: testsuite: Drop setting TDIRECTORY
Jon Turney [Thu, 6 Jul 2023 10:54:04 +0000 (11:54 +0100)]
Cygwin: testsuite: Drop setting TDIRECTORY

Drop setting TDIRECTORY, just use /tmp in the 'test installation' now
that we have it.

This effectively reverts f3ed5f2fe029d74372aca68b18936e164ff47cf7

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agoCygwin: don't wait infinitely on a pthread cancel event
Corinna Vinschen [Mon, 17 Jul 2023 16:02:04 +0000 (18:02 +0200)]
Cygwin: don't wait infinitely on a pthread cancel event

Starting with commit 42faed412857 ("* thread.h (class pthread): Add bool
member canceled."), pthread::testcancel waits infinitely on cancel_event
after it checked if the canceled variable is set.  However, this might
introduce a deadlock, if the thread calling pthread_cancel is terminated
after setting canceled to true, but before calling SetEvent on cancel_event.

In fact, it's not at all necessary to wait infinitely.  By definition,
the thread is only canceled if cancel_event is set.  The canceled
variable is just a helper to speed up code.  We can safely assume that
the thread hasn't been canceled yet, if canceled is set, but cancel_event
isn't.

Fixes: 42faed412857 ("* thread.h (class pthread): Add bool member canceled.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
13 months agoFix typo.
Jeff Johnston [Tue, 18 Jul 2023 17:43:03 +0000 (13:43 -0400)]
Fix typo.

13 months agoCygwin: testsuite: Make cancel3 and cancel5 more robust
Jon Turney [Sat, 15 Jul 2023 16:57:43 +0000 (17:57 +0100)]
Cygwin: testsuite: Make cancel3 and cancel5 more robust

Despite our efforts, sometimes the async cancellation gets deferred.

Notice this by calling pthread_testcancel(), and then try to work out if
async cancellation was ever successful by checking if all threads ran
for the full expected time, or if some were stopped early.

Also, increase the time we allow for the async cancellation to get
delivered to 30 seconds.

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agoCygwin: Restore signal handlers on thread cancellation during system()
Jon Turney [Sun, 16 Jul 2023 13:46:00 +0000 (14:46 +0100)]
Cygwin: Restore signal handlers on thread cancellation during system()

Add back the restoration of signal handlers modified during system() on
thread cancellation.

Removed in 3cb9da14 which describes it as 'ill-conceived' (additional
context doesn't appear to be available).

We use the internal implementation helpers for the pthread cleanup
chain, so we can neatly tuck it inside the object, and keep the point
when we restore the signal handlers the same. (The
pthread_cleanup_push/pop() functions are implemented as macros which
must appear in the same lexical scope.)

Fixes: 3cb9da14617c ("Put signals on hold and use system_call_cleanup
class to set and restore signals rather than doing it prior to to
running the program.  Remove the ill-conceived pthread_cleanup stuff.")
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agoCygwin: pthread: Take note of schedparam in pthread_create
Jon Turney [Thu, 6 Jul 2023 15:39:13 +0000 (16:39 +0100)]
Cygwin: pthread: Take note of schedparam in pthread_create

Take note of schedparam in any pthread_attr_t passed to pthread_create.

postcreate() (racily, after the thread is actually created), sets the
scheduling priority if it's inherited, but precreate() doesn't store any
scheduling priority explicitly set via a non-default attr to
pthread_create, so schedparam.sched_priority has the default value of 0.

(I think this is another long-standing bug exposed by 4b51e4c1.  Now we
don't lie about the actual thread priority, it's apparent it's not
really being set in this case.)

Fixes testcase priority2.

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agoChange getlogin() to only check stdin being null
Jordi Sanfeliu [Mon, 17 Jul 2023 18:58:04 +0000 (14:58 -0400)]
Change getlogin() to only check stdin being null

13 months agoCygwin: testsuite: Drop Adminstrator privileges while running tests
Jon Turney [Tue, 11 Jul 2023 14:40:09 +0000 (15:40 +0100)]
Cygwin: testsuite: Drop Adminstrator privileges while running tests

Test access05 and symlink03 expect operations to fail which succeed when
we have Adminstrator privileges.

There's perhaps a bit of incoherency here: some XFAILed tests expect to
run as root (so maybe we need the ability to selectively cygdrop?).

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agoCygwin: testsuite: Minor fixes to umask03
Jon Turney [Tue, 11 Jul 2023 14:27:47 +0000 (15:27 +0100)]
Cygwin: testsuite: Minor fixes to umask03

Change TCIDs to they match the filename
Fix use of "%0" rather than "%o"
Record failure on mismatched permissions, rather than immediately breaking

See ltp commits fa31d55d923b23ff and b846e7bb

https://github.com/linux-test-project/ltp/commit/fa31d55d3486830313bd044f7333697ce6124d22
https://github.com/linux-test-project/ltp/commit/923b23ff1fd1b77bd895949f9a6b4508c6485f33
https://github.com/linux-test-project/ltp/commit/b846e7bb9c1e6b00af25fdd28d88a5847fb0b052

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agoCygwin: testsuite: Fix a buffer overflow in symlink01
Jon Turney [Tue, 11 Jul 2023 14:08:14 +0000 (15:08 +0100)]
Cygwin: testsuite: Fix a buffer overflow in symlink01

full_path needs to hold a overlong pathname of length PATH_MAX+1, plus a
terminating null.

See ltp commit 44d51c3f

https://github.com/linux-test-project/ltp/commit/44d51c3f0670961149ba486a678cfc13b37cce2c

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agoCygwin: testsuite: Busy-wait in cancel3 and cancel5
Jon Turney [Mon, 10 Jul 2023 18:04:58 +0000 (19:04 +0100)]
Cygwin: testsuite: Busy-wait in cancel3 and cancel5

These tests async thread cancellation of a thread that doesn't have any
cancellation points.

Unfortunately, since 2b165a45 the async cancellation silently fails when
the thread is inside the kernel function Sleep(), so it just exits
normally after 10 seconds. (See the commentary in pthread::cancel() in
thread.cc, where it checks if the target thread is inside the kernel,
and silently converts the cancellation into a deferred one)

Work around this by busy-waiting rather than Sleep()ing for 10 seconds.

This is still somewhat fragile: the async cancel could still fail, if it
happens to occur while we're inside the kernel function that time()
calls.

v2:
Do nothing more efficiently

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agoCygwin: testsuite: Fix for limited thread priority values
Jon Turney [Thu, 1 Sep 2022 11:13:50 +0000 (12:13 +0100)]
Cygwin: testsuite: Fix for limited thread priority values

Since commit 4b51e4c1, we return the actual thread priority, not what we
originally stored in the thread attributes.

Windows only supports 7 thread priority levels, which we map onto the 32
required by POSIX.  So, only a subset of values will be returned exactly
by by pthread_getschedparam() after pthread_setschedparam().

Adjust tests priority1, priority2 and inherit1 so they only check for
round-tripping priority values which can be exactly represented.

For CI, this needs to handle process priority class "below normal
priority" as well.

Also check that the range of priority values is at least 32, as required
by POSIX.

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agoCygwin: testsuite: Also check direct call in systemcall
Jon Turney [Sun, 9 Jul 2023 11:12:23 +0000 (12:12 +0100)]
Cygwin: testsuite: Also check direct call in systemcall

Check direct call to system(), as well as one in a subprocess.

(This is a lot easier to debug when it's completely broken by the
environment the test is running in)

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agoCygwin: testsuite: Just log result of second open of /dev/dsp
Jon Turney [Fri, 7 Jul 2023 12:36:29 +0000 (13:36 +0100)]
Cygwin: testsuite: Just log result of second open of /dev/dsp

Do not rate successful second open of /dev/dsp as an error, just log the
result.

Based on this patch by Gerd Spalink:

https://cygwin.com/pipermail/cygwin-patches/2004q3/004848.html
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agoCygwin: testsuite: Skip devdsp test when no audio devices present
Jon Turney [Sat, 8 Jul 2023 11:50:58 +0000 (12:50 +0100)]
Cygwin: testsuite: Skip devdsp test when no audio devices present

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agoCygwin: testsuite: Remove const from writable string in fcntl07b
Jon Turney [Sat, 8 Jul 2023 14:28:47 +0000 (15:28 +0100)]
Cygwin: testsuite: Remove const from writable string in fcntl07b

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agoCygwin: testsuite: Add a simple timeout mechanism
Jon Turney [Tue, 11 Jul 2023 10:17:56 +0000 (11:17 +0100)]
Cygwin: testsuite: Add a simple timeout mechanism

Astonishingly, we don't have this already, so tests which hang just stop
the testsuite dead in it's tracks...

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agoCygwin: testsuite: Setup test prereqs in 'installation' the tests run in
Jon Turney [Tue, 4 Jul 2023 12:59:14 +0000 (13:59 +0100)]
Cygwin: testsuite: Setup test prereqs in 'installation' the tests run in

Do some setup in the Cygwin 'installation' at testsuite/testinst/:

* Ensure /tmp exists

* Use BusyBox to provide executables needed by tests which use system()
(sh, sleep, ls)

This enables tests which use system(), or require /tmp to exist to pass.

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
13 months agonewlib: posix: add HAVE_OPENDIR build condition for [n]ftw.c
Alexey Lapshin [Thu, 13 Jul 2023 09:52:26 +0000 (09:52 +0000)]
newlib: posix: add HAVE_OPENDIR build condition for [n]ftw.c

13 months agoCygwin: Update release/3.4.8 for latest <sys/cpuset.h> commit
Mark Geisert [Thu, 13 Jul 2023 05:36:59 +0000 (22:36 -0700)]
Cygwin: Update release/3.4.8 for latest <sys/cpuset.h> commit

13 months agoCygwin: Make gcc-specific code in <sys/cpuset.h> compiler-agnostic
Mark Geisert [Sun, 9 Jul 2023 07:59:22 +0000 (00:59 -0700)]
Cygwin: Make gcc-specific code in <sys/cpuset.h> compiler-agnostic

The current version of <sys/cpuset.h> cannot be compiled by Clang due to
the use of builtin versions of malloc, free, and memset.  Their presence
here was a dubious optimization anyway, so their usage has been
converted to standard library functions.

The use of __builtin_popcountl remains because Clang implements it just
like gcc does.  If/when some other compiler (Rust? Go?) runs into this
issue we can deal with specialized handling then.

The "#include <sys/cdefs>" here to define __inline can be removed since
both of the new includes sub-include it.

Addresses: https://cygwin.com/pipermail/cygwin/2023-July/253927.html
Fixes: 9cc910dd33a5 (Cygwin: Make <sys/cpuset.h> safe for c89 compilations)
Signed-off-by: Mark Geisert <mark@maxrnd.com>
13 months agoCygwin: fstat(): Fix st_rdev returned by fstat() for /dev/tty.
Takashi Yano [Thu, 6 Jul 2023 21:39:13 +0000 (06:39 +0900)]
Cygwin: fstat(): Fix st_rdev returned by fstat() for /dev/tty.

While st_rdev returned by fstat() for /dev/tty should be FH_TTY,
the current cygwin1.dll returns FH_PTYS+minor or FH_CONS+minor.
Similarly, fstat() does not return correct value for /dev/console,
/dev/conout, /dev/conin or /dev/ptmx.

This patch fixes the issue by:
1) Introduce dev_referred_via in fhandler_termios.
2) Add new argument, which has dev_t value referred by open(),
  for constructors of fhandler_pty_slave and fhandler_pty_master to
  set the value of dev_referred_via.
3) Set st_rdev using dev_referred_via in fhandler_termios::fstat()
  if it is available.

Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
13 months agoCygwin: stat(): Fix "Bad address" error on stat() for /dev/tty.
Takashi Yano [Thu, 6 Jul 2023 21:11:52 +0000 (06:11 +0900)]
Cygwin: stat(): Fix "Bad address" error on stat() for /dev/tty.

As reported in
https://cygwin.com/pipermail/cygwin/2023-June/253888.html,
"Bad address" error occurs when stat() is called after the commit
3721a756b0d8 ("Cygwin: console: Make the console accessible from
other terminals.").

There are two problems in the current code. One is fhandler_console::
fstat() calls get_ttyp()->getsid(). However, fh_alloc() in dtable.cc
omits to initialize the fhandler_console instance when stat() is
called. Due to this, get_ttyp() returns NULL and access violation
occurs. The other problem is fh_alloc() assigns fhandler_console
even if the CTTY is not a console. So the first problem above occurs
even if the CTTY is a pty.

This patch fixes the issue by:
1) Call set_unit() to initialize _tc if the get_ttyp() returns NULL.
2) Assign fhandler_pty_slave for /dev/tty if CTTY is a pty in fh_alloc().

Fixes: 3721a756b0d8 ("Cygwin: console: Make the console accessible
  from other terminals.").
Fixes: 23771fa1f7028 ("dtable.cc (fh_alloc): Make different decisions
  when generating fhandler for not-opened devices. Add kludge to deal
  with opening /dev/tty.")
Reported-by: Bruce Jerrick <bmj001@gmail.com>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
13 months agoCygwin: Fix latest release message being in the wrong release file.
Corinna Vinschen [Tue, 4 Jul 2023 14:50:00 +0000 (16:50 +0200)]
Cygwin: Fix latest release message being in the wrong release file.

Fixes: 6422e76637d3 ("Cygwin: Make <sys/cpuset.h> safe for c89 compilations")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
13 months agoCygwin: Make <sys/cpuset.h> safe for c89 compilations
Mark Geisert [Tue, 4 Jul 2023 00:51:41 +0000 (17:51 -0700)]
Cygwin: Make <sys/cpuset.h> safe for c89 compilations

Four modifications to include/sys/cpuset.h:
* Change C++-style comments to C-style also supported by C++
* Change "inline" to "__inline" on code lines
* Add "#include <sys/cdefs.h>" to make sure __inline is defined
* Don't declare loop variables on for-loop init clauses

Tested by first reproducing the reported issue with home-grown test
programs by compiling with gcc option "-std=c89", then compiling again
using the modified <sys/cpuset.h>. Other "-std=" options tested too.

Addresses: https://cygwin.com/pipermail/cygwin-patches/2023q3/012308.html
Fixes: 315e5fbd99ec ("Cygwin: Fix type mismatch on sys/cpuset.h")
Signed-off-by: Mark Geisert <mark@maxrnd.com>
13 months agoCygwin: thread: Reset _my_tls.tid if it's pthread_null in init_mainthread().
Takashi Yano [Thu, 22 Jun 2023 15:07:26 +0000 (00:07 +0900)]
Cygwin: thread: Reset _my_tls.tid if it's pthread_null in init_mainthread().

Currently, _my_tls.tid is set to pthread_null if pthread::self()
is called before pthread::init_mainthread(). As a result, pthread::
init_mainthread() does not set _my_tls.tid appropriately. Due to
this, pthread_join() fails in LDAP environment if the program is
the first program which loads cygwin1.dll.

https://cygwin.com/pipermail/cygwin/2023-June/253792.html

With this patch, _my_tls.tid is re-initialized in pthread::
init_mainthread() if it is pthread_null.

Reported-by: Mümin A. <muminaydin06@gmail.com>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
14 months agoFor GCC, newlib combined tree, newlib build-tree testing, use standard search paths
Thomas Schwinge [Fri, 14 Apr 2023 19:26:32 +0000 (21:26 +0200)]
For GCC, newlib combined tree, newlib build-tree testing, use standard search paths

For example, for GCC/GCN target (AMD GPUs), target libraries are built
individually per supported hardware ISA ('-march=[...]').  Testing such a
toolchain via, for example:

    $ make RUNTESTFLAGS='--target_board=[...]/-march=gfx90a' check[...]

... does work fine for all 'check-gcc-[...]' as well as GCC-provided target
libraries, 'check-target-[...]'.  Just for 'check-target-newlib', for the
example above, not the '-march=gfx90a' newlib libraries are linked in, but
instead always the default ones, which results in link FAILure.  This is cured
simply by skipping use of 'newlib/testsuite/lib/flags.exp', so that the
standard search paths as determined by GCC, DejaGnu are used for newlib, too.

14 months agoMake SIG2STR_MAX usable in #if
Mingye Wang [Wed, 21 Jun 2023 12:11:57 +0000 (20:11 +0800)]
Make SIG2STR_MAX usable in #if

The text accepted for POSIX issue 8 requires that SIG2STR_MAX be usable
in #if, which we currently break with sizeof. Use static values instead.

14 months agofhandler/proc.cc: use wincap.has_user_shstk
Brian Inglis [Mon, 19 Jun 2023 18:15:19 +0000 (12:15 -0600)]
fhandler/proc.cc: use wincap.has_user_shstk

In test for AMD/Intel Control flow Enforcement Technology user mode
shadow stack support replace Windows version tests with test of wincap
member addition has_user_shstk with Windows version dependent value

Fixes: 41fdb869f998 ("fhandler/proc.cc(format_proc_cpuinfo): Add Linux 6.3 cpuinfo")
Signed-off-by: Brian Inglis <Brian.Inglis@Shaw.ca>
14 months agowincap.cc: set wincap member has_user_shstk true for 2004+
Brian Inglis [Mon, 19 Jun 2023 18:15:18 +0000 (12:15 -0600)]
wincap.cc: set wincap member has_user_shstk true for 2004+

Signed-off-by: Brian Inglis <Brian.Inglis@Shaw.ca>
14 months agowincap.h: add wincap member has_user_shstk
Brian Inglis [Mon, 19 Jun 2023 18:15:17 +0000 (12:15 -0600)]
wincap.h: add wincap member has_user_shstk

Indicate support of user mode hardware-enforced shadow stack

Signed-off-by: Brian Inglis <Brian.Inglis@Shaw.ca>
14 months agoCygwin: use new XATTR_{NAME,SIZE}_MAX instead of MAX_EA_{NAME,VALUE}_LEN
Philippe Cerfon [Tue, 6 Jun 2023 00:52:49 +0000 (02:52 +0200)]
Cygwin: use new XATTR_{NAME,SIZE}_MAX instead of MAX_EA_{NAME,VALUE}_LEN

Signed-off-by: Philippe Cerfon <philcerf@gmail.com>
14 months agoCygwin: export XATTR_{NAME,SIZE,LIST}_MAX
Philippe Cerfon [Tue, 30 May 2023 11:16:18 +0000 (13:16 +0200)]
Cygwin: export XATTR_{NAME,SIZE,LIST}_MAX

These are used for example by CPython.

Signed-off-by: Philippe Cerfon <philcerf@gmail.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
14 months agoDo not rely on `getenv ("HOME")`'s path conversion
Johannes Schindelin [Mon, 22 May 2023 11:13:02 +0000 (13:13 +0200)]
Do not rely on `getenv ("HOME")`'s path conversion

In the very early code path where `dll_crt0_1 ()` calls
`user_shared->initialize ()`, the Cygwin runtime calls `internal_pwsid ()`
to initialize the user name in preparation for reading the `fstab` file.

In case `db_home: env` is defined in `/etc/nsswitch.conf`, we need to
look at the environment variable `HOME` and use it, if set.

When all of this happens, though, the `pinfo_init ()` function has had no
chance to run yet (and therefore, `environ_init ()`). At this stage,
therefore, `getenv ()`'s `findenv_func ()` call still finds `getearly ()`
and we get the _verbatim_ value of `HOME`. That is, the Windows form.
But we need the "POSIX" form.

To add insult to injury, later calls to `getpwuid (getuid ())` will
receive a cached version of the home directory via
`cygheap->pg.pwd_cache.win.find_user ()` thanks to the first
`internal_pwsid ()` call caching the result via
`add_user_from_cygserver ()`, read: we will never receive the converted
`HOME` but always the Windows variant.

So, contrary to the assumptions made in 27376c60a9 (Allow deriving the
current user's home directory via the HOME variable, 2023-03-28), we
cannot assume that `getenv ("HOME")` returned a "POSIX" path.

This is a real problem. Even setting aside that common callers of
`getpwuid ()` (such as OpenSSH) are unable to handle Windows paths in the
`pw_dir` attribute, the Windows path never makes it back to the caller
unscathed. The value returned from `fetch_home_env ()` is not actually
used as-is. Instead, the `fetch_account_from_windows ()` method uses it
to write a pseudo `/etc/passwd`-formatted line that is _then_ parsed via
the `pwdgrp::parse_passwd ()` method which sees no problem with
misinterpreting the colon after the drive letter as a field separator of
that `/etc/passwd`-formatted line, and instead of a Windows path, we now
have a mere drive letter.

Let's detect when the `HOME` value is still in Windows format in
`fetch_home_env ()`, and convert it in that case.

For good measure, interpret this "Windows format" not only to include
absolute paths with drive prefixes, but also UNC paths.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
14 months agouinfo: special-case IIS APPPOOL accounts
Johannes Schindelin [Mon, 22 May 2023 11:12:56 +0000 (13:12 +0200)]
uinfo: special-case IIS APPPOOL accounts

The account under which Azure Web Apps run is an IIS APPOOL account that
is generated on the fly.

These are special because the virtual machines on which thes Apps run
are not domain-joined, yet the accounts are domain accounts.

To support the use case where such a Web App needs to call `ssh` (e.g.
to deploy from a Git repository that is accessible only via SSH), we do
need OpenSSH's `getpwuid (getuid ())` invocation to work.

But currently it does not. Concretely, `getuid ()` returns -1 for these
accounts, and OpenSSH fails to find the correct home directory
(_especially_ when that home directory was overridden via a `db_home:
env` line in `/etc/nsswitch.conf`).

This can be verified e.g. in a Kudu console (for details about Kudu
consoles, see https://github.com/projectkudu/kudu/wiki/Kudu-console):
the domain is `IIS APPPOOL`, the account name is the name of the Azure
Web App, the SID starts with 'S-1-5-82-`, and
`pwdgrp::fetch_account_from_windows()` runs into the code path where
"[...] the domain returned by LookupAccountSid is not our machine name,
and if our machine is no domain member, we lose.  We have nobody to ask
for the POSIX offset."

Since these IIS APPPOOL accounts are relatively similar to AzureAD
accounts in this scenario, let's imitate the latter to support also the
former.

Reported-by: David Ebbo <david.ebbo@gmail.com>
Helped-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
14 months agoCygwin: pty: Additional fix for transferring input at exit.
Takashi Yano [Fri, 2 Jun 2023 01:19:18 +0000 (10:19 +0900)]
Cygwin: pty: Additional fix for transferring input at exit.

The commit 9fc746d17dc3 does not fix transferring input at exit
appropriately. If the more than one non-cygwin apps are executed
simultaneously and one of them is terminated, the pty master failed
to send input to the other non-cygwin apps. This patch fixes that.

Fixes: 9fc746d17dc3 ("Cygwin: pty: Fix transferring type-ahead input between input pipes.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
14 months agoCygwin: pty: Fix transferring type-ahead input between input pipes.
Takashi Yano [Thu, 1 Jun 2023 10:44:41 +0000 (19:44 +0900)]
Cygwin: pty: Fix transferring type-ahead input between input pipes.

After the commit e5fcc5837c95, transferring type-ahead input between
the pipe for cygwin app and the pipe for non-cygwin app will not be
done appropriately when the stdin of the non-cygwin app is not pty.
Due to this issue, sometimes the keyboard input might be lost which
should be sent to cygwin app. This patch fixes the issue.

Fixes: e5fcc5837c95 ("Cygwin: pty: Fix reading CONIN$ when stdin is not a pty.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
14 months agoconfig/mt-d30v: Append flags
Chris Packham [Sun, 28 May 2023 03:05:45 +0000 (15:05 +1200)]
config/mt-d30v: Append flags

Append to CFLAGS_FOR_TARGET/CXXFLAGS_FOR_TARGET rather than replacing
them.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
14 months agom68k: disallow unaligned access for m68010 and m68020
Remy Bohmer [Sun, 28 May 2023 03:05:44 +0000 (15:05 +1200)]
m68k: disallow unaligned access for m68010 and m68020

Disable at least  m68010 and m68020. These processors certainly do not
like unaligned accesses.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Signed-off-by: Austin Morton <austinpmorton@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
15 months agoCygwin: Adjust CWD magic to accommodate for the latest Windows previews
Johannes Schindelin [Mon, 22 May 2023 11:36:27 +0000 (13:36 +0200)]
Cygwin: Adjust CWD magic to accommodate for the latest Windows previews

Reportedly Windows 11 build 25*** from Insider changed the current
working directory logic a bit, and Cygwin's "magic" (or:
"technologically sufficiently advanced") code needs to be adjusted
accordingly.

This fixes https://github.com/git-for-windows/git/issues/4429

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This page took 0.083305 seconds and 5 git commands to generate.