4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-28 20:15:24 +08:00

14203 Commits

Author SHA1 Message Date
Corinna Vinschen
230f4802ed Cygwin: pipes: fix error handling when creating a pipe
The nt_create() function returns a Windows error code, but
it only calls NT functions.  In one case, it returns the
Windows error code without converting the NT status code
to a Windows error code first.

To fix this mess, change nt_create() to a function returning
the NT status code directly. Let the (only) caller handle
the conversion from NT status code to errno value.

Reported-by: "knut st. osmundsen" <bird-cygwin@anduin.net>
Fixes: f56206cd86b9 ("Cygwin: fhandler_pipe: fix permission problem")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-26 09:45:04 +01:00
Corinna Vinschen
2164981d26 Cygwin: document posix_close
Reported-by: Christian Franke <Christian.Franke@t-online.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-26 09:45:04 +01:00
Corinna Vinschen
4bcc6adec7 Cygwin: pipe_data_available: drop special casing select
After 11a84cc757ef ("Cygwin: fix SSH hangs"), select returns
writability if any number of bytes are left in the buffer.
Thus, the reason for pipe_data_available() to return PIPE_BUF
when called from select() is gone, and we can drop special casing
select().

So together with 11a84cc757ef ("Cygwin: fix SSH hangs"), this
patch essentially reverts 555afcb2f3a6 ("Cygwin: select: set pipe
writable only if PIPE_BUF bytes left")

Rather than reverting the flag parameter to a bool, keep a mode
argument set to PDA_READ or PDA_WRITE.  If we can't evaluate
the number of bytes left, just return 1 to select(), as for any
other caller.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-25 10:29:29 +01:00
Johannes Schindelin
11a84cc757 Cygwin: fix SSH hangs
It was reported in https://github.com/git-for-windows/git/issues/5199
that as of v3.5.4, cloning or fetching via SSH is hanging indefinitely.

Bisecting the problem points to 555afcb2f3 (Cygwin: select: set pipe
writable only if PIPE_BUF bytes left, 2024-08-18). That commit's
intention seems to look at the write buffer, and only report the pipe as
writable if there are more than one page (4kB) available.

However, the number that is looked up is the number of bytes that are
already in the buffer, ready to be read, and further analysis
shows that in the scenario described in the report, the number of
available bytes is substantially below `PIPE_BUF`, but as long as they
are not handled, there is apparently a dead-lock.

Since the old logic worked, and the new logic causes a dead-lock, let's
essentially revert 555afcb2f3a6 ("Cygwin: select: set pipe writable only if
PIPE_BUF bytes left").

Note: This is not a straight revert, as the code in question has been
modified subsequently, and trying to revert the original commit would
cause merge conflicts. Therefore, the diff looks very different from the
reverse diff of the commit whose logic is reverted.

Fixes: 555afcb2f3a6 ("Cygwin: select: set pipe writable only if PIPE_BUF bytes left")
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2025-02-24 22:33:44 +01:00
Christian Franke
78ff40d78e Cygwin: FAQ: Add section about sparse files
Signed-off-by: Christian Franke <christian.franke@t-online.de>
2025-02-24 18:12:00 +01:00
Corinna Vinschen
7aae9f323a Cygwin: fhandler_netdrive: use correct thread names
Fix the cygthread names used for debugging when calling the
thread_netdrive_wnet thread, so they actually show the provider
getting enumerated.

Fixes: 7db1c6fc4e2a ("Cygwin: //server: revert to using WNet and support NFS shares")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-24 16:52:27 +01:00
Corinna Vinschen
01bcd7d29e Cygwin: fhandler_netdrive: skip enumerating WebDAV shares
So far there's no known way to enumerate connected WebDAV resources.
WNetGetResourceInformationW/WNetOpenEnumW both return ERROR_BAD_NET_NAME.

Windows Explorer also shows an error dialog when trying to open a
Nextcloud instance to see the shares.

However, `net use' enumerates the connected cloud shares, so
there must be a way to do this.

For the time being, we just don't even try to enumerate WebDAV
shares and return an empty list.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-24 16:42:01 +01:00
Corinna Vinschen
7124d1c23d Cygwin: fhandler_netdrive: don't enumerate NFS shares on WebDAV server
WebDAV resources trigger the code trying to enumerate NFS shares
on the server.  Disable this by checking for an at-sign as well.

Fixes: 8cebbb2b42bf ("Cygwin: fhandler_netdrive::exists: handle WebDAV URLs")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-24 16:35:46 +01:00
Corinna Vinschen
5f9cc2a6ab Cygwin: winsup/doc/posix.xml: add posix_close doc
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-24 12:27:55 +01:00
Corinna Vinschen
004e95cf35 Cygwin: winsup/doc/posix.xml: add missing POSIX.1e functions to docs
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-24 11:49:00 +01:00
Brian Inglis
117feceea9 Cygwin: winsup/doc/posix.xml: SUS V5 POSIX 2024 combine multiple notes
Combine multiple notes after an entry separated by hyphen ") (" -> " - "

Signed-off-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
2025-02-24 11:42:11 +01:00
Brian Inglis
8fd4966195 Cygwin: winsup/doc/posix.xml: move wrongly sorted entries
Fix some entries not in sorting order.

Signed-off-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
2025-02-24 11:41:17 +01:00
Brian Inglis
32b39f2b02 Cygwin: winsup/doc/posix.xml: SUS V5 POSIX 2024 move or remove dropped entries
Move entries no longer in POSIX from the SUS/POSIX section to
Deprecated Interfaces section and mark with (SUSv4).
Remove entries no longer in POSIX from the NOT Implemented section.

Signed-off-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
2025-02-24 11:39:40 +01:00
Brian Inglis
1e58e7d5d5 Cygwin: winsup/doc/posix.xml: SUS V5 POSIX 2024 not implemented new additions
Add unavailable POSIX additions to Not Implemented section.

Signed-off-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
2025-02-24 11:34:37 +01:00
Brian Inglis
3dc2707bf9 Cygwin: winsup/doc/posix.xml: SUS V5 POSIX 2024 new additions available
Add POSIX new additions available as header macros and inline functions,
or exported by Cygwin distro DLL or library packages

Signed-off-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
2025-02-24 11:28:49 +01:00
Brian Inglis
b1eb09167a Cygwin: winsup/doc/posix.xml: SUS V5 POSIX 2024 TOG Issue 8 ISO 9945 move new POSIX
Update anchor id and description to current version, year, issue, etc.
Move new POSIX entries in other sections to the SUS/POSIX section.

Signed-off-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
2025-02-24 10:12:08 +01:00
Corinna Vinschen
8cebbb2b42 Cygwin: fhandler_netdrive::exists: handle WebDAV URLs
WebDAV URLs may contain an at-sign followed by a port number or SSL.
This will throw GetAddrInfoW, so remove the at-sign prior to calling
GetAddrInfoW.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-21 21:56:03 +01:00
Christian Franke
5e16fd9887 Cygwin: sched_setscheduler: Fix crash if pid of other process is used
Add missing PID_MAP_RW to allow changes of _pinfo::sched_policy.

Fixes: 48b189245a13 ("Cygwin: sched_setscheduler: accept SCHED_OTHER, SCHED_FIFO and SCHED_RR")
Signed-off-by: Christian Franke <christian.franke@t-online.de>
2025-02-21 21:25:17 +01:00
Corinna Vinschen
8cc55d819b Cygwin: fhandler_netdrive::exists: fix new debug statement
The debug statement was wrong twice: Not only was it in the wrong
spot, it was also supposed to print the share name and missed to
add said argument.

Fixes: df307349a09e ("Cygwin: fhandler_netdrive::exists: add debug statement")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-21 10:51:51 +01:00
Corinna Vinschen
df307349a0 Cygwin: fhandler_netdrive::exists: add debug statement
Add a debug_printf printing the return code from GetAddrInfoW.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-20 20:28:01 +01:00
Jeremy Drake via Cygwin-patches
78fb13d21f Cygwin: skip floppy drives in cygdrive_getmntent.
This was previously done, but was lost when the function was updated to
list all Windows mount points, not just drive letters.

Fixes: 04a5b072940cc ("Cygwin: expose all windows volume mount points.")
Signed-off-by: Jeremy Drake <cygwin@jdrake.com>
2025-02-19 20:11:40 +01:00
Jeremy Drake via Cygwin-patches
e49de2adea Cygwin: include network mounts in cygdrive_getmntent.
After migrating from GetLogicalDrives to Find(First|Next)VolumeW, mapped
network drives no longer showed up in getmntent output.  To fix that,
also iterate GetLogicalDriveStringsW when builing dos_drive_mappings,
and merge with volume mounts (skipping any volume mounts that are just
mounted on the root of a drive, and replacing the dos mounts in the
mapping for a volume which is mounted on both a drive root and a
directory).

Fixes: 04a5b072940cc ("Cygwin: expose all windows volume mount points.")
Addresses: https://cygwin.com/pipermail/cygwin/2025-February/257384.html
Signed-off-by: Jeremy Drake <cygwin@jdrake.com>
2025-02-19 09:53:14 +01:00
Corinna Vinschen
5790c180d1 Cygwin: pathnames.xml: sparse mount option is always set on SSDs
Reported by: Christian Franke <Christian.Franke@t-online.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-17 11:16:42 +01:00
Corinna Vinschen
fac7441835 Cygwin: lseek: fix an off-by-one condition in SEEK_DATA/SEEK_HOLE
The conditional checking if lseek should return ENXIO checks the
offset being bigger than the current filesize, but accidentally not
for being equal to the current filesize.

This can lead to an endless loop in newer versions of cp(1).

Fixes: edfa581d3c5a7 ("Cygwin: lseek: implement SEEK_DATA and SEEK_HOLE for files")
Reported-by: Christian Franke <Christian.Franke@t-online.de>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-14 15:10:01 +01:00
Corinna Vinschen
6363caef2d Cygwin: pathnames.xml: explain dir mounts since 3.6.0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-14 12:24:03 +01:00
Corinna Vinschen
701cec0aa1 Cygwin: pathnames.xml: improve chapters mount-table and cygdrive
Fix case in example output of mount and a bunch of clumsy expressions
and descriptions in the cygdrive section.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-14 12:23:16 +01:00
Corinna Vinschen
9bcb273f41 Cygwin: new-features.xml: transfer 3.6.0 release message to docs
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-14 11:57:52 +01:00
Corinna Vinschen
b50c195218 Cygwin: new-features.xml: drop two dashes remaining from copy/paste
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-02-14 11:57:52 +01:00
Jeremy Drake via Cygwin-patches
93f390c798 Cygwin: 3.6.0: add release entries for my patches.
These are:
  04a5b07294 Cygwin: expose all windows volume mount points.
  0d113da235 Cygwin: /proc/<PID>/mount*: escape strings.
  7923059bff Cygwin: uname: add host machine tag to sysname.
  b091b47b9e cygthread: suspend thread before terminating.

Signed-off-by: Jeremy Drake <cygwin@jdrake.com>
2025-02-14 10:54:30 +01:00
Jeremy Drake via Cygwin-patches
d4497366b4 Cygwin: always output cygdrive mntents.
Previously, if there was an explicit mount entry for a drive letter
(say, C:), the output of the corresponding cygdrive mntent (like
/cygdrive/c) would be suppressed.  Once Windows directory mounts were
added to cygdrive mounts, the de-duplication code got more complicated.
Instead, always output the cygdrive mounts, under the cygdrive prefix.

Addresses: https://cygwin.com/pipermail/cygwin-patches/2025q1/013367.html
Signed-off-by: Jeremy Drake <cygwin@jdrake.com>
2025-02-13 15:12:09 +01:00
Jeremy Drake via Cygwin-patches
04a5b07294 Cygwin: expose all windows volume mount points.
They are exposed via the getmntent API and proc filesystem entries
dealing with mounts.  This allows things like `df` to show volumes
that are only mounted on directories, not on drive letters.

Addresses: https://cygwin.com/pipermail/cygwin/2025-February/257251.html
Signed-off-by: Jeremy Drake <cygwin@jdrake.com>
2025-02-13 15:12:09 +01:00
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
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
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
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
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