Commit Graph

14083 Commits

Author SHA1 Message Date
Jon Turney 4eb9397b6c
Cygwin: Avoid use-after-free warnings in __set_lc_time_from_win() etc.
Rewrite to avoid new use-after-free warnings about realloc(), seen with
gcc 12, e.g.:

> In function ‘void rebase_locale_buf(const void*, const void*, const char*, const char*, const char*)’,
>     inlined from ‘int __set_lc_time_from_win(const char*, const lc_time_T*, lc_time_T*, char**, wctomb_p, const char*)’ at ../../../../src/winsup/cygwin/nlsfuncs.cc:705:25:
> ../../../../src/winsup/cygwin/nlsfuncs.cc:338:24: error: pointer ‘new_lc_time_buf’ may be used after ‘void* realloc(void*, size_t)’ [-Werror=use-after-free]
>   338 |       *ptrs += newbase - oldbase;
>       |                ~~~~~~~~^~~~~~~~~
> ../../../../src/winsup/cygwin/nlsfuncs.cc: In function ‘int __set_lc_time_from_win(const char*, const lc_time_T*, lc_time_T*, char**, wctomb_p, const char*)’:
> ../../../../src/winsup/cygwin/nlsfuncs.cc:699:44: note: call to ‘void* realloc(void*, size_t)’ here
>   699 |               char *tmp = (char *) realloc (new_lc_time_buf, len);

Technically, it's UB to later refer to the realloced pointer (even just
for offset computations, without deferencing it), so switch to using
malloc() to create the resized copy.

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2024-08-13 19:44:00 +01:00
Jon Turney 80e7ed9383
Cygwin: Fix warnings about narrowing conversions of socket ioctls
Fix gcc 12 warnings about narrowing conversions of socket ioctl constants
when used as case labels, e.g:

> ../../../../src/winsup/cygwin/net.cc: In function ‘int get_ifconf(ifconf*, int)’:
> ../../../../src/winsup/cygwin/net.cc:1940:18: error: narrowing conversion of ‘2152756069’ from ‘long int’ to ‘int’ [-Wnarrowing]

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2024-08-13 19:35:49 +01:00
Corinna Vinschen 50cf10dfa4 Cygwin: asm/socket.h: drop outdated casts
The _IOR anbd _IOW macros cast the sizeof of their third arg
uselessly to long. The _IO definitions have been taken from BSD
in 1995 and never changed again.  The fact that the sizeof() gets
cast to long is probably a remnant from the past when the stuff
was supposed to be used on 16 bit machines, but the value was
supposed to be 32 bit.

Given that the values are not supposed to be ever bigger than 32 bit,
we drop the (long) cast.  Compare with current FreeBSD, which does
not cast at all.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-08-07 17:10:03 +02:00
Jon Turney f0c79f8ef7
Cygwin: Fix warning about narrowing conversions in tape options
Fix a gcc 12 warning about a narrowing conversion in case labels for
tape options.

> In file included from /wip/cygwin/src/winsup/cygwin/include/sys/mtio.h:14,
>                  from ../../../../src/winsup/cygwin/fhandler/tape.cc:13:
> ../../../../src/winsup/cygwin/fhandler/tape.cc: In member function ‘int mtinfo_drive::set_options(HANDLE, int32_t)’:
> ../../../../src/winsup/cygwin/fhandler/tape.cc:965:12: error: narrowing conversion of ‘4026531840’ from ‘unsigned int’ to ‘int’ [-Wnarrowing]

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2024-08-06 15:17:48 +01:00
Jon Turney 696cd4ee02
Cygwin: Fix warning about address known to be non-NULL in /proc/locales
Fix a gcc 12 warning about an address known to be non-NULL in
format_proc_locale_proc().

> ../../../../src/winsup/cygwin/fhandler/proc.cc: In function ‘BOOL format_proc_locale_proc(LPWSTR, DWORD, LPARAM)’:
> ../../../../src/winsup/cygwin/fhandler/proc.cc:2156:11: error: the address of ‘iso15924’ will never be NULL [-Werror=address]
>  2156 |       if (iso15924)
>       |           ^~~~~~~~
> ../../../../src/winsup/cygwin/fhandler/proc.cc:2133:11: note: ‘iso15924’ declared here
>  2133 |   wchar_t iso15924[ENCODING_LEN + 1] = { 0 };
>       |           ^~~~~~~~

Fixes: c42b98bdc6 ("Cygwin: introduce /proc/codesets and /proc/locales")
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2024-08-06 15:17:47 +01:00
Jon Turney 367b69a280
Cygwin: Fix warnings about narrowing conversions of NTSTATUS constants
Fix warnings with gcc 12 about narrowing conversions of NTSTATUS
constants when used as case labels, e.g:

> ../../../../src/winsup/cygwin/exceptions.cc: In static member function ‘static int exception::handle(EXCEPTION_RECORD*, void*, CONTEXT*, PDISPATCHER_CONTEXT)’:
> ../../../../src/winsup/cygwin/exceptions.cc:670:10: error: narrowing conversion of ‘-1073741682’ from ‘NTSTATUS’ {aka ‘int’} to ‘unsigned int’ [-Wnarrowing]

See also: c5bdf60ac4

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2024-08-06 15:17:45 +01:00
Jon Turney a0482c612c
Cygwin: Suppress array-bounds warning from NtCurrentTeb()
This disables a warning seen with gcc 12 caused by intrinsics used by
the inline implementation of NtCurrentTeb() inside w32api headers.

> In function ‘long long unsigned int __readgsqword(unsigned int)’,
>     inlined from ‘_TEB* NtCurrentTeb()’ at /usr/include/w32api/winnt.h:10020:86,
> [...]
> /usr/include/w32api/psdk_inc/intrin-impl.h:838:1: error: array subscript 0 is outside array bounds of ‘long long unsigned int [0]’ [-Werror=array-bounds]

See also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523#c6

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2024-08-06 15:17:44 +01:00
Brian Inglis ec54f5f43d Cygwin: fhandler/proc.cc(format_proc_cpuinfo): Linux 6.10 flags resync
Linux 6.10 changed the content of cpufeatures.h to require explicit
quoted flag names for output in comments, instead of requiring a null
quoted string "" at the start of comments to suppress flag name output.
As a result, some flags (not all for output) were renamed and others moved:

- change dts to ds; move intel_ppin down; swap ibpd and ibrs;
- change some flag names and descriptions that are not output.

Signed-off-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
2024-07-19 11:52:10 +02:00
Brian Inglis a430ffd165 Cygwin: fhandler/proc.cc(format_proc_cpuinfo): add newlines
Linux cpuinfo follows output for each processor with a blank line,
so we output newlines to get a blank line:
- newline after power management feature flags if printed;
- newline to give blank line after each processor output.

Reported-by: Achim Gratz https://cygwin.com/pipermail/cygwin/2024-July/256223.html
Signed-off-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
2024-07-19 11:52:09 +02:00
Brian Inglis 003d85107b Cygwin: fhandler/proc.cc(format_proc_cpuinfo): Linux 6.10 flags added
0x8000000a EDX 18 x2avic	     virtual x2apic
0x80000022 EAX  2 amd_lbr_pmc_freeze AMD last br rec and perf mon ctrs freeze

Signed-off-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
2024-07-19 11:52:09 +02:00
Takashi Yano 1fb17a4b2d Cygwin: console: Fix for GNU screen/tmux in ConEmu
If the master process of GNU screen or tmux is started in ConEmu
and ConEmu is closed, reattaching to the GNU screen/tmux in another
console will not work correctly. This is because the ConEmu master
process was already closed even though some console APIs are hooked
by ConEmuHk64.dll to communicate with ConEmu master process. With
this patch, to make them unhooked, DllMain() of ConEmuHk64.dll is
called with DLL_PROCESS_DETACH.

Fixes: 3721a756b0 ("Cygwin: console: Make the console accessible from other terminals.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-07-09 00:05:43 +09:00
Takashi Yano 10477d95ec Cygwin: console: Fix race issue on allocating console simultaneously.
Previously, if two or more processes request to allocate a console at
the same time, the same device number could be accidentally allocated.
This patch fixes the issue by creating a named mutex (input_mutex) and
checking if GetLastError() is ERROR_ALREADY_EXIST or not to ensure
the unit number will be allocated in an atomic way. Thanks to this,
EnumWindow() is not necessary anymore to scan console units.

This also makes minor device numbers unique and console devices visible
across sessions. This disallows duplicated device number for different
sessions, so the MAX_CONS_DEV has been increased from 64 to 128.

Additionally, the console allocation and scanning will be faster as
a side effect of eliminating EnumWindows().

Fixes: 3721a756b0 ("Cygwin: console: Make the console accessible from other terminals.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-07-09 00:01:22 +09:00
Takashi Yano 462059da26 Cygwin: console: Bug fix for the last console code change
The commit baf2764dca has a serious bug that shared_info_state is
common for all console devices despite it should be individual for
each console device. This patch fixes that.

Fixes: baf2764dca ("Cygwin: console: Fixes an issue that tmux can not run on the console.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-07-07 00:16:29 +09:00
Takashi Yano baf2764dca Cygwin: console: Fixes an issue that tmux can not run on the console.
After the commit c77a5689f7, tmux can not run on the console.
This patch replaces the countermeasure for the race issue between
console setup and close with another mechanism using a mutex.

Fixes: c77a5689f7 ("Cygwin: console: Do not unmap shared console memory belonging to ctty.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-07-06 14:02:26 +09:00
Takashi Yano f7a77d0146 Cygwin: console: Fix conflict on shared names between sessions.
Previously, shared names in the console were created using get_minor().
However, get_minor() was not unique to the console across sessions.
This is because EnumWindows(), which is used to look for console windows,
cannot enumerate windows across sessions. This causes conflict on the
shared names between sessions (e.g. sessions of different users,
different services, a service and a user session, etc.).

With this patch, GetConsoleWindow() is used instead of get_minor().
GetConsoleWindow() has been used for the name of shared memory, which
should be unique to each console.

Addresses: https://cygwin.com/pipermail/cygwin/2024-April/255893.html
Fixes: ff4440fcf7 ("Cygwin: console: Introduce new thread which handles input signal.");
Reported-by: Johannes Khoshnazar-Thoma <johannes@johannesthoma.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-07-03 23:17:33 +09:00
Takashi Yano c4fb5da278 Cygwin: pty: Avoid client deadlock when pty master stops to read.
Previsouly, the following commands hangs:
  mintty -e timeout 1 dash -c 'yes aaaaaaaaaaaaaaaaaaaaaaaaa | cat'

The mechanism is as follows.

When the child process (timeout) is terminated, mintty seems to stop
reading pty master even if yes or cat still alive.

If the the pipe used to transfer output from pty slave to pty master
is full due to lack of master reader, WriteFile() to the pipe is
blocked. WriteFile() cannot be canceled by cygwin signal, therefore,
pty slave hangs.

This patch avoids hanging by checking pipe space before calling
WriteFile() and prevents writing data more than space.

Addresses: https://cygwin.com/pipermail/cygwin/2024-June/256178.html
Reported-by: jojelino <jojelino@gmail.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-07-01 17:45:00 +09:00
Takashi Yano 8d8f11b2b7 Cygwin: console: Add debug print on thread_sync_event creation error
Fixes: 55baaac2ef ("Cygwin: console: Add error handling for thread_sync_event")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-06-30 08:38:11 +09:00
Takashi Yano 55baaac2ef Cygwin: console: Add error handling for thread_sync_event
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-06-29 19:03:20 +09:00
Takashi Yano eaa606c0b7 Cygwin: dsp: Fix incorrect openflags when opening multiple /dev/dsp
Previously, the following steps failed with error:
  1) Open /dev/dsp with O_RDONLY
  2) Open /dev/dsp with O_WRONLY
  3) Issue SNDCTL_DSP_GETOSPACE ioctl() for 2)
This is because IS_WRITE() returns false for 2) due to incorrect
openflags handling in archetype instance. This patch fixes the
issue by adding open_setup() to fhandler_dev_dsp to set openflags
correctly for each instance.

Fixes: 92ddb74290 ("* fhandler_dsp.cc (fhandler_dev_dsp::open): Remove archetype handling.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-06-28 19:54:19 +09:00
Jon Turney 7e3c833592
Cygwin: suppress a warning generated with w32api >= 12.0.0
w32api 12.0.0 adds the returns_twice attribute to RtlCaptureContext().
There's some data-flow interaction with using it inside a while loop
which causes a maybe-uninitialized warning.

../../../../winsup/cygwin/exceptions.cc: In member function 'int _cygtls::call_signal_handler()':
../../../../winsup/cygwin/exceptions.cc:1720:33: error: '<anonymous>' may be used uninitialized in this function [-Werror=maybe-uninitialized]
2024-06-16 15:30:34 +01:00
Jeremy Drake via Cygwin-patches 10b9216811 Cygwin: disable high-entropy VA for ldh
If ldd is run against a DLL which links to the Cygwin DLL, ldh will end
up loading the Cygwin DLL dynamically, much like cygcheck or strace.

Addresses: https://cygwin.com/pipermail/cygwin/2024-May/255991.html
Fixes: 60675f1a7e ("Cygwin: decouple shared mem regions from Cygwin DLL")
Reviewed-by: Ken Brown <kbrown@cornell.edu>, Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Jeremy Drake <cygwin@jdrake.com>
2024-06-03 05:31:18 +09:00
Takashi Yano 5a859642f0 Cygwin: pthread: Fix a race issue introduced by the commit 2c5433e5da
To avoid race issues, pthread::once() uses pthread_mutex. This caused
the handle leak which was fixed by the commit 2c5433e5da. However,
this fix introduced another race issue, i.e., the mutex may be used
after it is destroyed. This patch fixes the issue. Special thanks to
Bruno Haible for discussing how to fix this.

Addresses: https://cygwin.com/pipermail/cygwin/2024-May/255987.html
Reported-by: Bruno Haible <bruno@clisp.org>
Fixes: 2c5433e5da ("Cygwin: pthread: Fix handle leak in pthread_once.")
Reviewed-by: Ken Brown <kbrown@cornell.edu>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-06-02 23:18:29 +09:00
Takashi Yano abfa508e72 Cygwin: mixer: Fix volume control for no WAVECAPS_LRVOLUME device
Currently, if the device does not have capability WAVECAPS_LRVOLUME,
the volume control does not work properly. This patch fixes that.

Fixes: 2a4af36614 ("Cygwin: Implement sound mixer device.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-06-01 15:23:37 +09:00
Corinna Vinschen 579064bf4d Cygwin: globify: read full 32 bit character
While commit 0321fb5736 ("Cygwin: glob: convert wchar_t to wint_t")
switched the entire glob mechanism from wchar_t to wint_t, the globify
function calling glob on a DOS command line did not catch up and only
checked for the next character constituting a 16 bit wchar_t. This
broke reading surrogate pairs from incoming DOS command lines if the
string had to go through glob(3).

Check for an entire 32 bit unicode char instead.

Fixes: 0321fb5736 ("Cygwin: glob: convert wchar_t to wint_t")
Reported-by: David Allsopp <david@tarides.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-04-09 22:30:03 +02:00
Corinna Vinschen 2855c35c41 Cygwin: fhandler_virtual::exists: always set fileid
Commit a0a25849f9 ("Cygwin: fhandler_virtual: move fileid to path_conv
member") broke `ls -l /proc/<PID>'.  Turns out, the commit forgot to set
the fileid in case of a virtual root dir (i. e., returning virt_rootdir)
in fhandlers utilizing fileid.  This crashed opendir() due to a random
fileid.

Make sure to set fileid in any case.

Fixes: a0a25849f9 ("Cygwin: fhandler_virtual: move fileid to path_conv member")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-04-09 17:02:35 +02:00
Corinna Vinschen 38b5139835 Cygwin: fhandler_base::fstat_by_name: improve debug output.
Since we're opening the parent dir, it doesn't make sense
to print the name of the file in debug output.  Print parent
dirname instead.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-04-04 18:21:13 +02:00
Corinna Vinschen 56e7563b9a Cygwin: FILE_OPEN_NO_RECALL is incompatible with FILE_DIRECTORY_FILE
If FILE_DIRECTORY_FILE is given, FILE_OPEN_NO_RECALL is not allowed,
otherwise NtCreateFile returns STATUS_INVALID_PARAMETER.

Drop FILE_OPEN_NO_RECALL where FILE_DIRECTORY_FILE is specified.

Fixes: f6b56abec1 ("Cygwin: try to avoid recalling offline files")
Reported-by: Bruce Jerrick <bmj001@gmail.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-04-04 18:21:13 +02:00
Corinna Vinschen db454e9868 Cygwin: add a fake 3.5.3 release file
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-04-03 19:47:58 +02:00
Corinna Vinschen a0a25849f9 Cygwin: fhandler_virtual: move fileid to path_conv member
Commit 80f722e97c ("Cygwin: opendir(3): move ENOTDIR check into main
function") introduced a bug in fhandler_virtual handling.  While the
assertion that path_conv::check() already calls exists() and sets
FILE_ATTRIBUTE_DIRECTORY accordingly, the exists() function is called
on a fhandler_virtual object created for just this code snippet.  The
side effect of this is that the fileid member in the calling
fhandler_virtual object is not set after path_conv::check().

Move the fhandler_virtual::fileid member to path_conv::_virt_fileid
and create matching path_conv::virt_fileid() and fhandler_virtual::fileid()
methods.

Let path_conv::check() propagate the fileid set in the local
fhandler_virtual::exists() call to its own  _virt_fileid.

Use new fhandler_virtual::fileid() method throughout.

Fixes: 80f722e97c ("Cygwin: opendir(3): move ENOTDIR check into main function")
Reported-by: Bruce Jerrick <bmj001@gmail.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-04-02 14:43:27 +02:00
Corinna Vinschen b7f5a33200 Cygwin: //: fetch only one item per loop
Simplify code in that it only fetches a single entry per
IEnumShellItems::Next call.  For some reason this appears to
be quicker most of the time.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-27 21:57:32 +01:00
Corinna Vinschen 9761c6cca1 Cygwin: add //tsclient and //wsl$ support to relnotes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-24 20:06:13 +01:00
Corinna Vinschen 178a8fca15 Cygwin: // and //server: add support for WSL
Root dirs of WSL installations are exposed via \\wsl$.
Add support to expose \\wsl$.

While at it, check if TERMSRV and P9 provider exist before
exposing them.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-24 20:02:15 +01:00
Corinna Vinschen 18b8a104ac Cygwin: dir_cache::add: constify input string
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-24 19:40:36 +01:00
Corinna Vinschen b95ab5982e Cygwin: fhandler_netdrive: use WNNC_NET_SMB instead of WNNC_NET_LANMAN
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-24 19:39:49 +01:00
Corinna Vinschen cc74a38d4a Cygwin: //tsclient: allow to enumerate shares
The //tsclient provider is WNNC_NET_TERMSRV.

Fixes: 7db1c6fc4e ("Cygwin: //server: revert to using WNet and support NFS shares")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-23 23:54:26 +01:00
Corinna Vinschen 7db1c6fc4e Cygwin: //server: revert to using WNet and support NFS shares
Continue using WSD for enumerating //, but switch back to
WNet for enumerating shares.

Add trying to enumerate NFS shares for machine names given as FQDN.

Only downcase server names, keep case of shares intact.
Move downcasing into dir_cache class.

Add a comment to explain an extrem weirdness in Windows.

Fixes: 205190a80b ("Cygwin: // and //server: switch to Network Discovery")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-23 22:32:42 +01:00
Corinna Vinschen 8d2c1b4ce6 Cygwin: //server: check existence of server with getaddrinfo
Checking server existence by trying to enumerate its shares
may result in 2 minutes delay until some internal timeout is hit.

In the light that every network is an IP network anyway these
days, let's try with a simple getaddrinfo() call.  This is usually
back in 3 secs even if the server doesn't exist, and it's usually
back in 8 secs if the DNS server can't be connected.  This is the
fastest method I found to check server existence yet.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-22 15:34:29 +01:00
Corinna Vinschen 290843bbda Cygwin: utils: refresh tzmap.h
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-21 21:45:26 +01:00
Corinna Vinschen 2c67eeb233 Cygwin: tzmap-from-unicode.org: drop "E. Europe Standard Time" default
E. Europe Standard Time is available in the unicode.org windowsZones.xml
file, so we can drop the default handling.

Fix a few comments.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-21 21:45:26 +01:00
Corinna Vinschen ace936b707 Cygwin: tzset(1): use GetDynamicTimeZoneInformation
Use official GetDynamicTimeZoneInformation() function instead of
scanning the registry for the timezone keyname.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-21 21:44:57 +01:00
Corinna Vinschen 4c4e6d67d4 Cygwin: fix tzmap-from-unicode.org
The previous change introduced a missing end of comment

Fixes: 60ea9c1c4b ("Cygwin: tzmap-from-unicode.org: drop support for Vista/2008")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-21 21:22:49 +01:00
Corinna Vinschen 8e12860944 Cygwin: utils: refresh tzmap.h
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-20 23:00:02 +01:00
Corinna Vinschen 60ea9c1c4b Cygwin: tzmap-from-unicode.org: drop support for Vista/2008
Commit b794f2c603 ("Cygwin: drop support for systems not supporting
RFC 4646 locales") erroneously changed tzmap.h manually.  Change
the script accordingly.

Fixes: b794f2c603 ("Cygwin: drop support for systems not supporting RFC 4646 locales")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-20 22:59:37 +01:00
Corinna Vinschen b9ed33dec0 Cygwin: readdir: drop support for NT4/Win2K shares and Samba < 3.0.22
These systems are at least 18 years old and so buggy that they are
hopefully not used anymore.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-20 17:45:41 +01:00
Corinna Vinschen 8bd6ba8f16 Cygwin: /proc: fix mem leak in opendir in error case
Fixes: 1f08558f14 ("* fhandler.h (fhandler_proc::opendir): Declare.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-20 14:48:55 +01:00
Corinna Vinschen 205190a80b Cygwin: // and //server: switch to Network Discovery
SMBv1 is ultimately deprecated since Novemer 2023.  It's also
not installed by default on latest Windows versions.

Drop using the WNet (SMBv1) API in favor of using Network Discovery.
Given there's no documented Win32 API for that, the code now uses
the Shell API.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-20 14:46:49 +01:00
Corinna Vinschen 80f722e97c Cygwin: opendir(3): move ENOTDIR check into main function
So far the check for a directory is in the fhandler::opendir
methods. Given that path_conv::check sets FILE_ATTRIBUTE_DIRECTORY
on virtual files either, we can move the check up into the
opendir(3) function. This avoids calling exists() twice when
calling opendir(3).

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-20 12:34:51 +01:00
Corinna Vinschen 1719169604 Cygwin: (mostly) drop NT4 and Samba < 3.0 support
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-20 12:31:50 +01:00
Corinna Vinschen 14970f2645 Cygwin: dirent.h: fix a comment
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-19 23:21:35 +01:00
Corinna Vinschen d06113bf8b Cygwin: readdir(3): stop support for pre-Cygwin 1.5.0 apps
We're filling dirent::__d_internal1 with the inode number to
support apps built under Cygwin 1.3 and earlier.  This doesn't
make sense anymore.  Drop this to free up __d_internal1 for
other TBD use.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-19 16:22:40 +01:00
Brian Inglis bfe2790e7b winsup/cygwin/fhandler/proc.cc: format_proc_cpuinfo() Linux 6.8 cpuinfo flags
add Linux 6.8 cpuinfo flags:
Intel 0x00000007:1 eax:17 fred		Flexible Return and Event Delivery;
AMD   0x8000001f   eax:4  sev_snp	SEV secure nested paging;
document unused and some unprinted bits that could look like omissions;
fix typos and misalignments;

Signed-off-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
2024-03-18 16:33:56 +01:00
Corinna Vinschen 89afbb8d8a Revert "Cygwin: glob: perform ignore_case_with_glob on input"
This reverts commit a51147467e.

Dumb thinko on my part.  What was supposed to be an optimization
actually broke caseinsensitive globbing in that the entire input
of globbed expressions were downcased.

Drop the unused CCHAR() macro nevertheless.

Fixes: a51147467e ("Cygwin: glob: perform ignore_case_with_glob on input")
Reported-by: Michael Goldshteyn <mgold10000@gmail.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-18 11:10:13 +01:00
Takashi Yano fc691d0246 Cygwin: pipe: Make sure to set read pipe non-blocking for cygwin apps.
If pipe reader is a non-cygwin app first, and cygwin process reads
the same pipe after that, the pipe has been set to bclocking mode
for the cygwin app. However, the commit 9e4d308cd5 assumes the
pipe for cygwin process always is non-blocking mode. With this patch,
the pipe mode is reset to non-blocking when cygwin app is started.

Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255644.html
Fixes: 9e4d308cd5 ("Cygwin: pipe: Adopt FILE_SYNCHRONOUS_IO_NONALERT flag for read pipe.")
Reported-by: wh <wh9692@protonmail.com>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-03-12 10:17:40 +09:00
Corinna Vinschen 3af5d2bbdd Cygwin: 3.6.0: add release entries for pinned/unpinned flag handling
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-11 12:53:50 +01:00
Corinna Vinschen 775069553b Cygwin: add 3.5.2 release entries for latest commits
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-11 12:53:24 +01:00
Corinna Vinschen 5f586adc63 Cygwin: getgrent: don't skip SAM-only builtin-accounts
Since commit 15e82eef3a ("Cygwin: getgrent: fix local SAM enumeration
on domain member machines") we skip enumerating local BUILTIN accounts
if we also enumerate AD.  However, there are two local accounts which
are only available in local SAM, not in AD.  Don't skip enumerating
those.

Fixes: 15e82eef3a ("Cygwin: getgrent: fix local SAM enumeration on domain member machines")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-11 12:46:50 +01:00
Corinna Vinschen 06aa5a7516 Cygwin: FS_IOC_[GS]ETFLAGS: handle pinned and unpinned attributes
Add FS_PINNED_FL and FS_UNPINNED_FL flags and handle them with
mode bits 'p' and 'u' in chattr(1) and lsattr(1).

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-08 21:54:58 +01:00
Corinna Vinschen 2100c6ef0d Cygwin: get/set security descriptors using FILE_OPEN_NO_RECALL
Add FILE_OPEN_NO_RECALL to NtOpenFile calls trying to fetch
or write file security descriptors so as not to recall them
from offline storage inadvertently.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-08 21:30:57 +01:00
Corinna Vinschen f6b56abec1 Cygwin: try to avoid recalling offline files
Chances are high that Cygwin recalls offline files from remote
storage, even if the file is only accessed during stat(2) or
readdir(3).

To avoid this
- make sure Cygwin is placeholder-aware,
- open files in path_conv handling, as well as in stat(2)/readdir(3)
  scenarios with FILE_OPEN_NO_RECALL, and
- during symlink checking or testing for executablility, don't even
  try to open the file if one of the OFFLINE attributes is set.

Reported-by: Marcin Wisnicki <mwisnicki@gmail.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-08 20:57:06 +01:00
Corinna Vinschen f2010ed784 Cygwin: move EXPORT_ALIAS expressions to end of source
This isn't strictly required, but it avoids confusion in ctags.
Ctags fails to record the next function or method following the
EXPORT_ALIAS expression.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-07 21:50:07 +01:00
Takashi Yano c2310061c6 Cygwin: pipe: Simplify chhecking procedure of query_hdl.
This patch eliminates verbose NtQueryObject() calls in the procedure
to get query_hdl by storing pipe name into fhandler_base::pc when
the pipe is created.  fhandler_pipe::temporary_query_hdl() uses the
storedpipe name rather than the name retrieved by NtQueryObject().

Suggested-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-03-06 03:44:37 +09:00
Takashi Yano 46bb999a89 Cygwin: pipe: Give up to use query_hdl for non-cygwin apps.
Non-cygwin app may call ReadFile() for empty pipe, which makes
NtQueryObject() for ObjectNameInformation block in fhandler_pipe::
get_query_hdl_per_process. Therefore, do not to try to get query_hdl
for non-cygwin apps.

Addresses: https://github.com/msys2/msys2-runtime/issues/202

Fixes: b531d6b06e ("Cygwin: pipe: Introduce temporary query_hdl.")
Reported-by: Alisa Sireneva, Johannes Schindelin <Johannes.Schindelin@gmx.de>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-03-05 22:03:01 +09:00
Takashi Yano b160b690b6 Cygwin: console: Fix a race issue between close() and open().
The open() call for console sometimes fails if the console owner
process is closing the console by close() at the same time. This
is due to mismatch state of con.owner variable and attaching state
to the console. With this patch, checking con.owner and attaching
to con.owner sequence in open(), and resetting con.owner and freeing
console sequence in close() are guarded by output_mutex to avoid
such a race issue.
Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255575.html

Fixes: 3721a756b0 ("Cygwin: console: Make the console accessible from other terminals.")
Reported-by: Kate Deplaix <kit-ty-kate@outlook.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-03-04 11:58:09 +09:00
Corinna Vinschen abb532a87f Cygwin: cygheap: compute bucket instead of looping over it
Start at index 0 and use 32 bytes as minimal allocation size.
Reduce NBUCKETS, we don't have such big objects on the
cygheap anyway.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-01 22:35:22 +01:00
Corinna Vinschen 5d3e79ec6b Cygwin: cygheap: use SRWLOCK for cygheap locking
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-01 22:31:33 +01:00
Corinna Vinschen e2ea60728c Cygwin: posix_getdents: do not clear attached DIR structure at fork(2)
The upcoming POSIX issue 8 will require that posix_getdents after
fork() will pick up at the right spot, independently of being
called in the parent or in the child process.  Remove the expression
clearing out the attached DIR after fork.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-01 15:32:39 +01:00
Corinna Vinschen 6d93691547 Cygwin: lseek: improve seeking posix_getdents descriptors
Transfer code lseeking on posix_getdents() directory descriptor
into its own static function and rework it so SEEK_END, SEEK_DATA
and SEEK_HOLE work here as expected, too.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-01 15:32:39 +01:00
Takashi Yano c77a5689f7 Cygwin: console: Do not unmap shared console memory belonging to ctty.
In the condition that console setup for CTTY and close run at the
sametime, accessing shared console memory which is already unmapped
may occur. With this patch, to avoid this race issue, shared console
memory which belongs to contorolling terminal (CTTY) is kept mapped
as before.
Addresses: https://cygwin.com/pipermail/cygwin/2024-February/255561.html

Fixes: 3721a756b0 ("Cygwin: console: Make the console accessible from other terminals.")
Reported-by: Kate Deplaix <kit-ty-kate@outlook.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-03-01 20:00:11 +09:00
Christian Franke ee97ae1d5f Cygwin: set ENOSHARE and ECASECLASH _sys_errlist[] entries to empty
These errno values are no longer used by Cygwin.  Change the entries
to empty strings instead of NULL to avoid crashes in existing
binaries directly accessing the table.  Enhance strerror_worker()
such that empty strings also result in "Unknown error ..." messages.
Also add a static_assert check for the _sys_errlist[] size.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-02-28 09:59:07 +01:00
Corinna Vinschen 7a89f7261d Cygwin: add release text for getgrent local SAM enumeration patch
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-26 15:56:10 +01:00
Christian Franke c2f6c04155 Cygwin: errmap[]: update comments using current winerror.h
Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-02-26 15:56:10 +01:00
Christian Franke 2b7cc8972f Cygwin: errmap[]: add error numbers to /* ERROR_... */ comments
Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-02-26 15:56:10 +01:00
Christian Franke 4f843719d3 Cygwin: errmap[]: reduce value size from 32 to 8 bits
Overflow would be detected at compile time.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-02-26 15:56:10 +01:00
Christian Franke b55eed943b Cygwin: introduce constexpr errmap_size and errmap[] consistency checks
Use constexpr instead of const for errmap[] to allow static_assert
checks on its values.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-02-26 15:56:10 +01:00
Christian Franke 4af5f9d51e Cygwin: Map ERROR_NO_SUCH_DEVICE and ERROR_MEDIA_CHANGED to ENODEV
If a removable (USB) device is disconnected after opening its raw
device, R/W attempts fail with ERROR_NO_SUCH_DEVICE(433).  If the
raw device of a partition is used, ERROR_MEDIA_CHANGED(1110) is
returned instead.  Both are mapped to ENODEV(19) because <errno.h>
does not offer a value which better matches ERROR_MEDIA_CHANGED.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-02-24 13:12:14 +01:00
Corinna Vinschen 388da83dce Cygwin: add newgrp release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-24 13:12:14 +01:00
Corinna Vinschen 0e3bb302de Cygwin: newgrp: only allow group from supplementary group list
Windows only allows to set the primary group to a group already
present in the TOKEN_GROUP list.  Cygwin OTOH fakes success at
setgid() time, to allow a subsequent call to setuid() to do
the actual account switching.  To have a sane behaviour in the
command line tool, check group membership and disallow to switch
to groups other than those already present in the user token.

Fixes: 8bd56ec873 ("Cygwin: newgrp: first full version")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-24 13:08:34 +01:00
Corinna Vinschen 808a95d24d Cygwin: newgrp: fix invalid usage of argv
Fix an error message accessing argv[1] even after it has been
potentially moved.  Print group name from group DB instead.

Fixes: 8bd56ec873 ("Cygwin: newgrp: first full version")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-24 13:08:33 +01:00
Corinna Vinschen a0d7758359 Cygwin: strptime: add release note
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-21 20:00:29 +01:00
Corinna Vinschen 585855eef8 Cygwin: strptime: fix am/pm handling
The %p format specifier is handled immediately.  It requires
that tm_hour is already set.  This falls flat in case the am/pm
marker preceeds the time specification.  Locales with am/pm
marker preceeding time spec by default exist (e. g. ko_KR).

Also, the code expects that tm_hour might be set to an invalid
value because the %p specifier is used in conjunction with %H.
But this usage is invalid in itself and now catched as error
condition after commit 343a2a5581 ("Cygwin: strptime: make
sure to fail on invalid input digits").

Change the %H/%I/%p handling according to GLibC, i. e.

- fix tm_hour for pm only if the time value has been specified
  as 12 hour time %I, and

- perform the fixup only after the entire input has been scanned.
  This decouples the fixup from the %p position relativ to %I.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-21 19:54:20 +01:00
Corinna Vinschen 343a2a5581 Cygwin: strptime: make sure to fail on invalid input digits
conv_num returns NULL if the input is invalid, e. g., the
numbers are out of range.  However, the code fails to test
this in a lot of places.

Rather than adding checks all over the place, rename conv_num
to __conv_num and create a wrapper macro conv_num to perform
the task of error checking.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-21 19:39:37 +01:00
Corinna Vinschen c90b20192d Cygwin: getgrent/getpwent: avoid local enumeration on DCs
...if we're supposed to enumerate the AD accounts anyway.  This
avoids some useless duplication.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-20 23:55:51 +01:00
Corinna Vinschen 15e82eef3a Cygwin: getgrent: fix local SAM enumeration on domain member machines
Don't skip output of local SAM groups on domain member machines.
They can have valid, user-defined groups in their SAM.  Just
skip builtin groups if we're enumerating AD as well.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-20 23:51:33 +01:00
Corinna Vinschen 5cc6996987 Cygwin: passwd/group: drop Capability SIDs
Capability SIDs (S-1-15-3-...) have been introduced with
Windows 10 1909.  They don't resolve with LookupAccountSid.
We don't need them and they don't map gracefully into out
POSIX account namespace.  Also, add code to make sure to
filter them out *iff* they become resolvable at one point.

While at it, slightly reorder code for non-resolving SIDs
by authority values.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-20 17:25:23 +01:00
Corinna Vinschen 70653fd8f1 Cygwin: gettimeofday: allow tv NULL pointer
Add a missing check for the struct timeval pointer being NULL.

Reported-by: 109224573 <109224573@qq.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-20 12:30:34 +01:00
Corinna Vinschen a7bf7c7dd5 Cygwin: timespec_get: implement C11 function
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-16 20:44:31 +01:00
Takashi Yano f9542a2e8e Cygwin: pty: Re-fix the last bug regarding nat-pipe.
Fixes: f907b5f405 ("Cygwin: pty: Fix failure to revert from nat-pipe in disable_pcon.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-16 18:18:26 +09:00
Takashi Yano f907b5f405 Cygwin: pty: Fix failure to revert from nat-pipe in disable_pcon.
Fixes: a903878948 ("Cygwin: pty: Additional fix for transferring input at exit.");
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-16 17:15:29 +09:00
Takashi Yano f3ba4db2e2 Cygwin: console: Fix a bug that 64th console cannot be handled.
Fixes: 930e553da8 ("Cygwin: console: Unify EnumWindows() callback functions.");
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-16 04:06:01 +09:00
Takashi Yano 4dd3dc876c Cygwin: console: Fix a bug that cannot handle consoles more than 32.
Fixes: 3721a756b0 ("Cygwin: console: Make the console accessible from other terminals.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-16 02:37:46 +09:00
Takashi Yano 930e553da8 Cygwin: console: Unify EnumWindows() callback functions.
Previously, three similar callback fuctions were used in console
code. This patch unifies these functions to ease maintenance cost.

Fixes: 8aad3a7ede ("Cygwin: console: Fix a problem that minor ID is incorrect in ConEmu.")
Suggested-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-14 23:18:23 +09:00
Takashi Yano 054f4801e6 Cygwin: pty: Make GNU screen and tmux work in ConEmu cygwin-connector.
Fixes: 3721a756b0 ("Cygwin: console: Make the console accessible from other terminals.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-14 23:18:04 +09:00
Corinna Vinschen 2a2a6486a0 Cygwin: accommodate gcc -Og option
All three warnings produced with -Og are false positives.
But given we're using -Werror unconditionally it's better
to be safe than sorry.

Reported-by: Kevin Ushey <kevinushey@gmail.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-14 14:00:34 +01:00
Corinna Vinschen 4e77fa9b8b Cygwin: find_fast_cwd: don't run assembler checking code on ARM64
https://cygwin.com/pipermail/cygwin/2024-February/255397.html
reports a crash on ARM64 probably related to checking x86_64
code on the x86_64 emulator on AArch64.

At least for testing, pull the code checking the host HW
up to be called before trying to evaluate assembler code.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-13 16:48:15 +01:00
Takashi Yano 8aad3a7ede Cygwin: console: Fix a problem that minor ID is incorrect in ConEmu.
Previously, minor device number of console was not assigned correctly
in ConEmu environment. This is because console window of ConEmu is
not enumerated by EnumWindows(). This patch fixes the issue.

Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-13 23:27:44 +09:00
Takashi Yano ac92c4c9f5 Cygwin: console: Make VMIN and VTIME work.
Previously, VMIN and VTIME did not work at all. This patch fixes that.

Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-13 23:26:50 +09:00
Takashi Yano 8e24d162f4 Cygwin: pty: Fix potential handle leak regarding CallNamedPipe().
In pty master_thread, 6 handles are duplicated when CallNamedPipe()
requests that. Though some of them are not used so should be closed,
they were not. This causes handle leak potentially.

Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-13 23:24:45 +09:00
Takashi Yano 06992ed6b4 Cygwin: pty: Fix handle leak in master process.
If non-cygwin process is started in pty, closing from_master_nat
pipe handle was missing in fhandler_pty_slave::input_transfer().
This occured because the handle was duplicated but not closed.

https://github.com/msys2/msys2-runtime/issues/198

Fixes: 29431fcb5b ("Cygwin: pty: Inherit typeahead data between two input pipes.")
Reported-by: Hakkin Lain
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-02-13 23:23:52 +09:00
Corinna Vinschen dace0bfa6c Cygwin: dumper: use void* in place of PTR
The definition of PTR has been dropped from newer versions
of ansidecl.h.

Convert definition of print_section_name to use void * instead,
as required by bfd_map_over_sections.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-12 13:43:03 +01:00
Corinna Vinschen 35b10bb8c6 Cygwin: fix typo in winjitdebug description
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-02-03 20:28:46 +01:00