4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-24 01:29:34 +08:00

21886 Commits

Author SHA1 Message Date
Jeremy Drake via Cygwin-patches
dcb963b672 Cygwin: store list of mounts for volumes in dos_drive_mappings.
The existing code only stored the first mount for each volume, but now
we store the complete list, and split it into a linked list.  This will
be used in a subsequent commit to populate cygdrive mount entries.

Signed-off-by: Jeremy Drake <cygwin@jdrake.com>
2025-02-13 15:12:09 +01:00
Alexey Lapshin
59891375d7 Protect strcat from accessing an unaligend long pointer
- related to Bug libc/32679
2025-02-12 10:25:24 +01:00
Jeff Johnston
a473f960e5 Protect strncat from accessing an unaligend long pointer
- fixes Bug libc/32679
2025-02-11 14:28:33 -05:00
Corinna Vinschen
68c13dc92f newlib: Regenerate autotools files
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-10 15:40:12 +01:00
Alexey Lapshin
dcf5d237fd newlib: introduce --enable-newlib-hw-misaligned-access option
Some hardware may perform better when copying unaligned
word-sized memory compared to byte-by-byte copying.

In case not defined explicitly by --enable-newlib-hw-misaligned-access
config option or variable $default_newlib_hw_misaligned_access in
configure.host file the compiler check will be performed to detect if
__riscv_misaligned_fast or __riscv_misaligned_slow is defined.

This commit introduces autodetection for RISC-V. Additionally, checking
for __ARM_FEATURE_UNALIGNED could be checked for ARM architecture.
However, this was not implemented in the commit, as changes in
newlib/libc/machine/[arm|aarch64] need to be performed.
2025-02-10 15:35:20 +01:00
Alexey Lapshin
9a706d0479 newlib: str[n]cat: optimize skipping of the destination string
Prepare pointer to be aligned and than use word-size iterator on aligned
memory.
2025-02-10 15:33:35 +01:00
Alexey Lapshin
2a79b76c07 newlib: memmove: improve performance for overlapping buffers
This change provides word-sized copy for overlapping buffers, that could
increase performance significantly. Performance measurement for RISCV:

    uint8_t buf[1024];
    memmove (buf + 4, buf, sizeof(buf) - 4);

CPU cycles: 12255 -> 2076
2025-02-10 15:31:10 +01:00
Alexey Lapshin
ab827c1a6c newlib: mem[p]cpy/memmove improve performance for optimized versions
This change improves performance on memory blocks with sizes in range
[4..15]. Performance measurements made for RISCV machine (memset):

size  4, CPU cycles change: 50 -> 37
size  5, CPU cycles change: 57 -> 40
size  6, CPU cycles change: 64 -> 47
size  7, CPU cycles change: 71 -> 54
size  8, CPU cycles change: 78 -> 44
size  9, CPU cycles change: 85 -> 47
size 10, CPU cycles change: 92 -> 54
size 11, CPU cycles change: 99 -> 61
size 12, CPU cycles change: 106 -> 51
size 13, CPU cycles change: 113 -> 54
size 14, CPU cycles change: 120 -> 61
size 15, CPU cycles change: 127 -> 68
2025-02-10 15:30:46 +01:00
Alexey Lapshin
bc2723e989 newlib: memccpy: unify mask filling with other memory functions
This change made just to have memccpy like others mem-functions
2025-02-10 15:26:51 +01:00
Alexey Lapshin
c9b74e3289 newlib: string: refactor str/mem-family functions
Move common macros to local.h header
2025-02-10 15:20:47 +01:00
Jeremy Drake via Cygwin-patches
0d113da235 Cygwin: /proc/<PID>/mount*: escape strings.
In order for these formats to be machine-parseable, characters used as
delimiters must be escaped.  Linux escapes space, tab, newline,
backslash, and hash (because code that parses mounts/mtab and fstab
would handle comments) using octal escapes.  Replicate that behavior
here.

Addresses: https://cygwin.com/pipermail/cygwin/2024-June/256082.html
Signed-off-by: Jeremy Drake <cygwin@jdrake.com>
2025-02-05 11:09:08 +01:00
Jeremy Drake via Cygwin-patches
5a706ff0fc Cygwin: factor out code to resolve a symlink target.
This code was duplicated between the lnk symlink type and the native
symlink type.

Signed-off-by: Jeremy Drake <cygwin@jdrake.com>
2025-02-03 23:02:21 +01:00
Yuriy Kolerov
0387c7e1cc libgloss: arc: Add clock() system call to libnsim
clock() system call is used in some GDB tests thus it is
necessary to implement it for testing purposes. A value
for clock() is taken from a default timer (timer 0). If it is
not presented than the error value (-1) is returned.

Signed-off-by: Yuriy Kolerov <ykolerov@synopsys.com>
2025-02-03 15:11:40 +01:00
Yuriy Kolerov
6d7ace3681 libgloss: arc: Add _getentropy stub
Stub function for _getentropy is presented in libnosys and it is
not presented in libgloss libraries for ARC. When libstdc++ is
built it detects that _getentropy is presented in the default
libgloss library (libnosys). However, then GCC fails to link
applications with another libgloss libraries like nSIM, HostLink,
boards, etc. because of missing _getentropy stub in corresponding
libraries.

Here is an example:

    $ cat getentropy.cpp
    #include <unistd.h>

    int main () {
        unsigned i;
        ::getentropy(&i, sizeof(i));
        return 0;
    }

    $ arc64-elf-g++ -mcpu=hs6x -specs=nsim.specs getentropy.cpp
    ...
    ... undefined reference to `_getentropy'
    collect2: error: ld returned 1 exit status

Thus, it is necessary to add _getentropy stub to all ARC
libgloss libraries to prevent errors while building even
simple C++ programs.

Signed-off-by: Yuriy Kolerov <ykolerov@synopsys.com>
2025-02-03 15:11:40 +01:00
Terraneo Federico
987d040394 Lift 256 arg limit in execl, execle and execlp
add --enable-newlib-use-malloc-in-execl option

The previous version of these functions allocated a 256 entry array and
copied arguments in that array with no bound checking. That
implementation always occupied 1024 bytes of stack for the array even in
the common case in which the number of passed arguments is far less than
256, risking stack overflows in environments with small stacks, and
caused a stack buffer overflow if called with more than 256 arguments.

The improved implementation counts the actual number of passed arguments
and allocates a suitable buffer. The default implementation uses alloca
to allocate the buffer to satisfy the POSIX.1-2008 requirement that
execl and execle should be callable from signal handlers, but it is
possible to override this behavior and use malloc for targets where the
risk of stack overflow due to unbounded stack allocations is a more
pressing requirement than the corner case of allowing execl calls from
signal handlers.
2025-02-03 12:43:51 +01:00
Terraneo Federico
1efcb2a300 newlib: update Makefile.in
The libc/sys/xtensa directory was removed in commit 48f1655c955c154b3165692e02aa66699212453c, but the change to Makefile.in wasn't committed.
2025-02-03 11:37:07 +01:00
Corinna Vinschen
d52d983e5b Cygwin: implement posix_close
per
https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_close.html

Add a flag value to fhandler_*::close() and close_with_arch() methods,
taking -1 as default argument, used to indicate default close(2)
behaviour.

The only fhandlers capable of returning EINTR are the INET based
socket fhandlers.  Handle -1 and POSIX_CLOSE_RESTART equivalent,
making close() and posix_close(POSIX_CLOSE_RESTART) behaving
identically.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-28 16:50:12 +01:00
Corinna Vinschen
c7eb1a1f52 Cygwin: fhandler: move "isclosed" status flag into fhandler_pipe_fifo
The isclosed flag is only used in pipe and FIFO code, so move the
flag down into the fhandler_pipe_fifo class.

Note that such a flag is not sufficient to avoid evil, like closing
an already closing fhandler from another thread.  If we ever need this,
it has to be implemented threadsafe.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-28 16:11:03 +01:00
Corinna Vinschen
6baa8484db unistd.h: declare posix_close
Declare posix_close, a new function defined by POSIX-1.2024, per
https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_close.html

Define POSIX_CLOSE_RESTART.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-28 12:43:03 +01:00
Corinna Vinschen
fe6ddc15a3 Cygwin: message queues: avoid deadlocks in multi-threaded processes
Deadlocks have been observed if the message queue functions are called
from different threads in the same process.

Remove incorrectly locking the descriptor table while accessing the
message queue fhandler, potentially calling blocking functions.

Fixes: 46f3b0ce85a9 ("Cygwin: POSIX msg queues: move all mq_* functionality into fhandler_mqueue")
Reported-by: Christian Franke <Christian.Franke@t-online.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-27 22:01:46 +01:00
Corinna Vinschen
b940faa144 Cygwin: message queues are not devices
Message queues are basically just files and in most cases can be handled
like normal files.  So it was a mistake to set the "on-disk-device" flag
for them to fix the mq_unlink() problem reported in
https://cygwin.com/pipermail/cygwin/2025-January/257119.html

Rather, given that unlink() just checks if the object to be deleted
has an on-disk representation, make sure message queues are added to
the path_conv::isondisk() predicate.

This also reverts commit d870655f570f25393dcefbaf0b1dc807f277749c.

Fixes: d870655f570f ("Cygwin: path_conv: set on-disk-device flag for message queue files")
Reported-by: Christian Franke <Christian.Franke@t-online.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-27 11:17:27 +01:00
Corinna Vinschen
df63cbfedd Cygwin: add release msg for mq_unlink changes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-25 12:54:40 +01:00
Corinna Vinschen
bf94b87f54 Cygwin: unlink_nt: clean up debug output and comment
The debug statement supposed to be printed when deleting with POSIX
semantics failed with STATUS_CANNOT_DELETE or STATUS_INVALID_PARAMETER
is in the wrong spot.  While at it, simplify the related comment.

Fixes: 9fa22dba558f ("Cygwin: unlink: allow fallback from POSIX to default method")
Fixes: 527dd1b407e7 ("Cygwin: fix unlink in container")
Fixes: 87ab6c7b26bf ("Cygwin: log disabling posix semantics")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-23 23:40:53 +01:00
Takashi Yano
5182a92a72 Cygwin: Drop const qualifier from 2nd argument of tcgetwinsize()
Fixes: 0eef1b6c9684 ("Cygwin: Add new APIs tc[gs]etwinsize()")
Reported-by: Alexander Kleinsorge <aleks@physik.tu-berlin.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2025-01-24 04:27:23 +09:00
Takashi Yano
0eef1b6c96 Cygwin: Add new APIs tc[gs]etwinsize()
New APIs tcgetwinsize/tcsetwinsize are added, which is added in
POSIX.1-2024.

Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2025-01-24 03:22:44 +09:00
Corinna Vinschen
41baac804d devctl.h: update for POSIX-1.2024
posix_devctl is now part of POSIX-1.2024, thus the requirement to
define _POSIX_26_C_SOURCE has been dropped.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-23 17:02:02 +01:00
Mark Geisert
0135b94949
Cygwin: Minor updates to load average calculations
Commentary wording now refers to tasks (i.e., threads) rather than
processes.  This makes it somewhat easier to justify adding two kinds of
counters together.  After researching what "load average" has meant over
time, we have what seems like a reasonable implementation, modulo
Windows differences to Linux.  The best resource I found is:
https://www.brendangregg.com/blog/2017-08-08/linux-load-averages.html

At end of load_init(), obtain and discard the first measure of the
counters to deal with the first call always returning error, no data.
Follow this with a specific short delay so the next measure actually has
data to report.

At least one older version of Windows, i.e. Win10 Pro 21H1, has a different
name/location for the '% Processor Time' counter and is missing the
'Processor Queue Length' counter entirely.  Code is changed to support
both possible locations of the former and treat the missing latter as always
reporting 0.0.

A release note is added for 3.5.6.

Reported-by: Mark Liam Brown <brownmarkliam@gmail.com>
Addresses: https://cygwin.com/pipermail/cygwin/2024-August/256361.html
Signed-off-by: Mark Geisert <mark@maxrnd.com>
Fixes: 4dc982ddf60b (Cygwin: loadavg: improve debugging of load_init)
2025-01-23 12:51:20 +00:00
Ken Brown
e0bc817271 Cygwin: mmap: use 64K pages for bookkeeping, second attempt
This reinstates with one change commit 74017d229d5e ("Cygwin: mmap:
use 64K pages for bookkeeping"), which was reverted in commit
fd57eea5617a.  The change is that in mmap_record::match, we now align
the record length to the 4K Windows page boundary rather than the 64K
Windows allocation granularity.  The reason for this is explained in
an extensive comment in the code.

Addresses: https://cygwin.com/pipermail/cygwin-patches/2025q1/013240.html
Fixes: 74017d229d5e ("Cygwin: mmap: use 64K pages for bookkeeping")
Signed-off-by: Ken Brown <kbrown@cornell.edu>
2025-01-22 11:36:59 -05:00
Takashi Yano
a880e0dffb Cygwin: signal: Avoid frequent TLS lock/unlock for SIGCONT processing
It seems that current _cygtls::handle_SIGCONT() code sometimes falls
into a deadlock due to frequent TLS lock/unlock operation in the
yield() loop. With this patch, the yield() in the wait loop is placed
outside the TLS lock to avoid frequent TLS lock/unlock.

Fixes: 9ae51bcc51a7 ("Cygwin: signal: Fix another deadlock between main and sig thread")
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2025-01-22 19:16:29 +09:00
Takashi Yano
2cc4d14f2a Cygwin: Document hang fixs introduced in 3.5.5
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2025-01-22 08:03:46 +09:00
Corinna Vinschen
b879cd1661 Cygwin: unlink: fix error checking order
Checking EPERM only makes sense if the file exists, so
let the EEXIST check change places with the EPERM check.

Add a debug statement to the EPERM condition.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-21 17:31:21 +01:00
Corinna Vinschen
890086ad37 Cygwin: path_conv: simplify, rearrange, rename combined device checks
Some checks in path_conv are checking for various properties
to generate a boolean value, mostly to indicate different
combinations of on-disk files and devices.

Simplify these checks and, especially, document them inline.

Drop the isdevice() check in favor of a new isondisk() check.

Fixes: 4fc922b2c8a5 ("Cygwin: POSIX msg queues: Convert mqd_t to a descriptor")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-21 17:31:13 +01:00
Corinna Vinschen
d870655f57 Cygwin: path_conv: set on-disk-device flag for message queue files
This simplifies further checks for on-disk-devices in places with
special handling for such files.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-21 17:22:29 +01:00
Mark Geisert
9a4a44523b Cygwin: Add fd validation where needed in mq_* functions
Validate the fd returned by cygheap_getfd operating on given mqd.
A release note is provided for 3.5.6.

Reported-by: Christian Franke <Christian.Franke@t-online.de>
Addresses: https://cygwin.com/pipermail/cygwin/2025-January/257090.html
Signed-off-by: Mark Geisert <mark@maxrnd.com>
Fixes: 46f3b0ce85a9 (Cygwin: POSIX msg queues: move all mq_* functionality into fhandler_mqueue)
2025-01-21 17:22:24 +01:00
Takashi Yano
83afe3e238 Cygwin: signal: Do not handle signal when __SIGFLUSHFAST is sent
The commit a22a0ad7c4f0 was not entirely correct. Even with the patch,
some hangs still occur. This patch overrides the previous commit along
with the patch that makes cygwait() reentrant, to fix these hangs.

Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256954.html
Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256987.html
Fixes: d243e51ef1d3 ("Cygwin: signal: Fix deadlock between main thread and sig thread")
Fixes: a22a0ad7c4f0 ("Cygwin: signal: Do not handle signal when __SIGFLUSHFAST is sent")
Reported-by: Daisuke Fujimura <booleanlabel@gmail.com>
Reported-by: Jeremy Drake <cygwin@jdrake.com>
Reviewed-by: Corinna Vinschen <corinna@vinshcen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2025-01-21 23:26:50 +09:00
Takashi Yano
ea1914000a Cygwin: cygwait: Make cygwait() reentrant
To allow cygwait() to be called in the signal handler, a locally
created timer is used instead of _cygtls::locals.cw_timer if it is
in use.

Co-Authored-By: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2025-01-21 23:15:28 +09:00
Takashi Yano
6172e5283b Revert "Cygwin: signal: Do not handle signal when __SIGFLUSHFAST is sent"
This reverts commit a22a0ad7c4f0 to apply a new patch for the same
purpose.

Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2025-01-21 23:15:28 +09:00
Corinna Vinschen
dbd662300b Cygwin: seteuid: set errno if TranslateNameW fails
The call to TranslateNameW in s4uauth can fail and the code
leaves the function indicating an error, if so.  It just
misses to set errno in this case, so add that.

Fixes: 0fb497165f85 ("Cygwin: seteuid: use Kerberos/MsV1_0 S4U authentication by default")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-20 13:27:57 +01:00
Jon Turney
ca22984cc4
Cygwin: CI: update deprecated artifacts action 2025-01-19 15:28:31 +00:00
Markus Eisenmann
5ee0e96939 Fixes compile failure if REENTRANT_SYSCALLS_PROVIDED and MISSING_SYSCALL_NAMES defined
If the macros REENTRANT_SYSCALLS_PROVIDED and MISSING_SYSCALL_NAMES are defined some
_reent_*-functions are replaced by the system-call and this leads to compile-warning
or a runtime-failure.

 * newlib/libc/stdio/fopen.c _open_r is replaces by open(), declared in <fcntl.h>
 * newlib/libc/stdio64/fopen64.c ditto
 * newlib/libc/stdio/rename.c _rename_r is rename() itself; i.e, fix recursion
2025-01-17 14:07:23 +01:00
Corinna Vinschen
0813644661 Cygwin: doc: the library is called libcrypt, not crypt
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-17 13:19:32 +01:00
Corinna Vinschen
4adb6c3806 Cygwin: doc: Remove executable name setup.exe from user guide
Use "Cygwin Setup program" and add a link to the homepage in some
cases.

Reported-by: David Dyck <david.dyck@gmail.com>
Reviewed-by: Jon Turney <jon.turney@dronecode.org.uk>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-17 12:20:08 +01:00
Corinna Vinschen
d21eb90bbc Cygwin: doc: clarify usage of sshd vs. cygsshd
When Microsoft started to claim the "sshd" service name, we had
to rename our service to "cygsshd" but we never updated the docs.

Make sure the docs reflect the changed service name and fix a
few bumpy expression.

Reported-by: Mario Emmenlauer <mario@emmenlauer.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-17 11:44:03 +01:00
Corinna Vinschen
37ed066c5f Cygwin: doc: remove "faq.using.sshd-in-domain"
This FAQ entry has been commented out for quite some time.
Drop it.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-17 11:44:03 +01:00
Corinna Vinschen
23f4aac7e7 Add posix_spawn_file_actions_add{f}chdir
POSIX®.1-2024 now defines posix_spawn_file_actions_addchdir and
posix_spawn_file_actions_addfchdir.  Add these interfaces to spawn.h,
guarded as POSIX 202405 symbols.

Cygwin-only: Export them as aliases of the *_np counterparts. Bump
API minor.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-16 18:38:52 +01:00
Corinna Vinschen
1e6a3b39f1 Cygwin: cygwin/fs.h: rename FS_COMPRESSED_FL to FS_COMPR_FL
FS_COMPR_FL is the Linux-compatible macro name.  Redefine
FS_COMPRESSED_FL as an alias of FS_COMPR_FL for backward
compatibility.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 18:33:31 +01:00
Ken Brown
fd57eea561 Revert "Cygwin: mmap: use 64K pages for bookkeeping"
This reverts commit 74017d229d5e46867c8a3ec01bf653e4392bf14c.

After this commit, gdb exits with a fatal error on startup.

Addresses: https://cygwin.com/pipermail/cygwin-patches/2025q1/013240.html
Fixes: 74017d229d5e ("Cygwin: mmap: use 64K pages for bookkeeping")
Signed-off-by: Ken Brown <kbrown@cornell.edu>
2025-01-15 11:22:15 -05:00
Corinna Vinschen
25e5824fb1 Cygwin: get_posix_access: make sure pos is correctly set when used
The code merging permissions relies on `pos' being set to the number
of current entries in the local aclent_t buffer.  Commit 0e6d36766c83
("Cygwin: get_posix_access: move umask masking to the end") moved that
code to run earlier, but neglected to move setting `pos' correctly
as well.

Make sure to set `pos' inside the code block, as well as in the
final array size check, so `pos' is set correctly where it belongs.

Fixes: 0e6d36766c83 ("Cygwin: get_posix_access: move umask masking to the end")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 15:57:56 +01:00
Corinna Vinschen
a6bc726adf Cygwin: get_posix_access: initalize obj_idx
This fixes a false positive gcc warning.

Fixes: 01c9386fd805 ("Cygwin: get_posix_access: improve merging permissions")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 15:50:29 +01:00
Corinna Vinschen
0e6d36766c Cygwin: get_posix_access: move umask masking to the end
umask handling for new file gets overriden by subsequent merging of
permissions in Windows-generated ACLs.  Fix this by performing
umask masking after all other ACL manipulations.

Fixes: a8716448cecc ("Simplify "Windows-standard-like" permissions")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 12:27:03 +01:00