Commit Graph

9978 Commits

Author SHA1 Message Date
Takashi Yano 322c7150b2 Cygwin: dsp: Avoid setting buffer that is too small.
The buffer size that is too small causes choppy sound. That is not
practical at all. With this patch, the minimum value of the buffer
size (i.e. fragstotal * fragsize) is restricted to 16384 bytes.

Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-09-17 21:54:11 +09:00
Takashi Yano 8484773f47 Cygwin: dsp: Fix a bug that app hangs if it killed during write().
If app is killed during blocking write(), it sometimes hangs. This
patch fixes the issue.

Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-09-17 21:53:44 +09:00
Christian Franke f5e37b93a0
Cygwin: Add initial support for SOURCE_DATE_EPOCH
If specified, set version timestamp to this value.
Enable deterministic archives for ar and ranlib.
Set cygwin1.dll PE and export table header timestamps to zero.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
2023-09-10 14:42:21 +01:00
Corinna Vinschen 5bbe0e56c6 Cygwin: NFS: remove recognizing native symlinks as FIFOs
Given the downsides of NFS symlinks as FIFOs, drop the code
added to recognize them as such.

Fixes: 622fb0776e ("Cygwin: enable usage of FIFOs on NFS")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-09-09 23:28:55 +02:00
Corinna Vinschen c0aa6ac30e Cygwin: NFS: create devices (especially FIFOs) as shortcut files
Creating real NFS symlinks for device files has a  major downside:
The way we store device info requires to change the symlink target
in case of calling chmod(2). This falls flat in two ways:

- It requires to remove and recreate the symlink, so it doesn't
  exist for a short period of time, and
- removing fails badly if there's another open handle to the symlink.

Therefore, change this to create FIFOs as shortcut files, just as on
most other filesystems.  Make sure to recognize these new shortcuts
on NFS (for devices only) in path handling and readdir.

Fixes: 622fb0776e ("Cygwin: enable usage of FIFOs on NFS")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-09-09 23:28:55 +02:00
Corinna Vinschen 8a953be5ef Cygwin: NFS: fetch actual DOS attributes
MSFT NFSv3 fakes DOS attributes based on file type and permissions.
Rather than just faking FILE_ATTRIBUTE_DIRECTORY for dirs, fetch the
"real" DOS attributes returned by NFS.

This allows to handle the "R/O" attribute on shortcut files and thus
reading and creating device shortcut files on NFS.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-09-09 23:28:55 +02:00
Corinna Vinschen 5302638f77 Cygwin: readdir: explain why we use FileNamesInformation on NFS
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-09-09 23:28:55 +02:00
Mark Geisert 27e8815535 Cygwin: Add relnote to 3.4.10 release file
Document the most recent update to include/sys/cpuset.h.
2023-09-09 23:28:55 +02:00
Mark Geisert 003fc33942 Cygwin: Fix __cpuset_zero_s prototype
Add a missing "void" to the prototype for __cpuset_zero_s().

Reported-by: Marco Mason <marco.mason@gmail.com>
Addresses: https://cygwin.com/pipermail/cygwin/2023-September/254423.html
Signed-off-by: Mark Geisert <mark@maxrnd.com>
Fixes: c6cfc99648d6 (Cygwin: sys/cpuset.h: add cpuset-specific external functions)
2023-09-09 23:28:55 +02:00
Corinna Vinschen c5913771a6 Cygwin: fix an ugly cast
fhandler_base::fchown casts any fhandler landing here to a
fhandler_disk_file.  That's ugly and dangerous.  Duplicate
the path_conv info into an explicitly create fhandler_disk_file
instead and call fchmod on that.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-09-08 22:41:21 +02:00
Corinna Vinschen bedefff9e2 Cygwin: fix chmod on native NFS FIFOs
By handling native NFS FIFOs as actual FIFOs, chmod on a FIFO
suddenly called fhandler_base::fchmod, which is insufficient
to handle FIFO files on any filesystem.

Note that this does not fix Cygwin FIFOs on NFS or AFS yet.

Fixes: 622fb0776e ("Cygwin: enable usage of FIFOs on NFS")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-09-08 22:38:53 +02:00
Corinna Vinschen 53472e1803 Cygwin: unlink_nt: declare in winsup.h
unlink_nt is used more than once so declare it in a header.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-09-08 22:34:52 +02:00
Takashi Yano 7ced682549 Cygwin: dsp: Improve response time of select()/poll().
With this patch, the response time of select()/poll() has been
improved by utilizing semaphore (select_sem) just like pipe and
fifo. In addition, notification of exceptional conditions has
been added.

Fixes: 2c06014f12 ("Cygwin: dsp: Implement select()/poll().")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-09-07 17:36:04 +09:00
Takashi Yano 2c06014f12 Cygwin: dsp: Implement select()/poll().
Previously, sound device /dev/dsp did not support select()/poll().
These have been implemented with this patch.

Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-09-06 22:06:57 +09:00
Takashi Yano 7a43763d24 Cygwin: dsp: Fix trivial editorial issue. 2023-09-05 18:28:01 +09:00
Takashi Yano 8b2b54b41d Cygwin: dsp: Reduce wait time for blocking read().
Previous wait time of 100msec is too long if application specifies
smaller buffer. With this patch, the wait time is reduced to 1msec.
2023-09-05 18:28:01 +09:00
Takashi Yano 2654a5ba76 Cygwin: dps: Fix a bug that read() could not return -1 on error. 2023-09-05 18:28:01 +09:00
Corinna Vinschen 2ab2e73c2c Cygwin: document FIFO over NFS change
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-09-04 10:41:06 +02:00
Corinna Vinschen 46e986f0e4 Revert "Cygwin: mknod: disable creating special files on NFS"
This reverts commit d085592daa.

This reenables creating Cygwin FIFOs on NFS.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-09-04 10:41:06 +02:00
Corinna Vinschen 622fb0776e Cygwin: enable usage of FIFOs on NFS
FIFOs on NFS were never recogized as such in path handling.

stat(2) indicated native FIFOs as FIFOs but the path handling
code didn't set the matching values in the inner symlink checking
code, so the followup behaviour was wrong.

Basically for the same reason, Cygwin-created FIFOs were just treated
as symlinks with weird content by stat(2) as well as path handling.

Add code to enable both types of FIFOs on NFS as Cygwin FIFOs.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-09-04 10:41:02 +02:00
Brian Inglis c4aa56bbf2 Cygwin: cpuinfo: Linux 6.5 additions
add AMD 0x8000001f EAX 14 debug_swap SEV-ES full debug state swap

Signed-off-by: Brian Inglis <Brian.Inglis@Shaw.ca>
2023-09-01 20:40:54 +02:00
Takashi Yano 2a4af36614 Cygwin: Implement sound mixer device.
This patch adds implementation of OSS-based sound mixer device. This
allows applications to change the sound playing volume.

NOTE: Currently, the recording volume cannot be changed.

Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-09-01 21:33:38 +09:00
Corinna Vinschen 3daedf267d Cygwin: document latest sys/cpuset.h fix
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-09-01 12:42:10 +02:00
Corinna Vinschen ac4699fdf3 Cygwin: sys/cpuset.h: use internal base types
Use __size_t and __pid_t instead of size_t and pid_t to avoid
further dependencies to external headers.

Reported-by: Brian Inglis <Brian.Inglis@Shaw.ca>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-09-01 12:38:52 +02:00
Corinna Vinschen d27e9fb29a Cygwin: sys/cpuset.h: add cpuset-specific external functions
The latest incarnation of sys/cpuset.h broke building coreutils.
The reason is the inclusion of stdlib.h and string.h and hence
premature requests for datatypes not yet defined in the include
chain.

Avoid this by defining __cpuset_alloc and __cpuset_free as external
functions, now defined in sched.cc.  Linux is doing this too, just
using different names for the functions. Redefine  __cpuset_zero_s
to use __builtin_memset only on compilers supporting it, otherwise
using a simple loop. Drop the stdlib.h and string.h includes.

Fixes: 3f2790e044 ("Cygwin: Make gcc-specific code in <sys/cpuset.h> compiler-agnostic")
Reported-by: Denis Excoffier <cygwin@Denis-Excoffier.org>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-09-01 12:38:52 +02:00
Takashi Yano cc4ff714ff Cygwin: dsp: Fix a few trivial bugs.
Signed-off-by: Takashi Yano <takashi.yanao@nifty.ne.jp>
2023-09-01 11:32:51 +09:00
Corinna Vinschen ca2a4ec243 Cygwin: execve: drop argument size limit
Before commit 44f73c5a62 ("Cygwin: Fix segfalt when too many command
line args are specified.") we had no actual argument size limit, except
for the fact that the child process created another copy of the argv
array on the stack, which could result in a stack overflow and a
subsequent SEGV.  Commit 44f73c5a62 changed that by allocating the
additional argv array via malloc, and it introduced a new SC_ARG_MAX
limit along the lines of the typical Linux limit.

However, this new limit is artificial. Cygwin allocates all argument
and environment data on the cygheap.  We only run out of ARG_MAX space
if we're out of memory resources.

Change argument size handling accordingly:
- Drop the args size check from  child_info_spawn::worker.
- Return -1 from sysconf (SC_ARG_MAX), i. e., the argument size limit
  is undefined.
- Change argv handling in class av, so that a failing cmalloc is not
  fatal.  This allows the parent process to return E2BIG if it's out
  of cygheap resources.
- In the child, add a check around the new malloc call, so that it
  doesn't result in a SEGV if the child process gets unexpectedly into
  an ENOMEM situation at this point. In this (unlikely) case, proceed
  with the original __argv array instead.  Add comment to explain why.

Fixes: 44f73c5a62 ("Cygwin: Fix segfalt when too many command line args are specified.")
Tested-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-08-29 14:17:04 +02:00
Takashi Yano 44f73c5a62 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>
2023-08-29 00:17:30 +09:00
Takashi Yano 50ff7901a5 Cygwin: termios: Refactor the function is_console_app().
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-08-28 18:20:57 +09:00
Corinna Vinschen eb1584b491 Revert "Cygwin: autoload: introduce LoadDLLfunc_pfx_only"
This reverts commit 0e711d6cc9.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-08-27 14:40:22 +02:00
Corinna Vinschen a841911ea4 Revert "Cygwin: select: workaround FD_WRITE network event handling"
This reverts commit dedbbd74d0.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-08-27 14:40:22 +02:00
Corinna Vinschen 384e572f41 Cygwin: document disabling mknod/mkfifo on NFS
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-08-25 14:50:48 +02:00
Corinna Vinschen d085592daa 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>
2023-08-25 14:39:04 +02:00
Takashi Yano 90d3b16d2b Cygwin: pty: Fix failure to clear switch_to_nat_pipe flag.
After the commit fbfea31dd9, 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: fbfea31dd9 ("Cygwin: pty: Avoid cutting the branch the pty master is sitting on.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-08-19 14:53:10 +09:00
Takashi Yano 65d34484e9 Cygwin: shared: Fix access permissions setting in open_shared().
After the commit 93508e5bb8, 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: 93508e5bb8 ("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>
2023-08-16 22:11:17 +09:00
Takashi Yano 2ee8de782b Cygwin: pty: Add missing pinfo check in transfer_input().
The commit 10d083c745 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: 10d083c745 ("Cygwin: pty: Inherit typeahead data between two input pipes.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2023-08-16 08:33:47 +09:00
Corinna Vinschen 46c4a90724 Cygwin: cXXrtomb, mbrtcXX: use function-specific internal state
As described in the previous commit b5111e4642
("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: 4f258c55e8 ("Cygwin: Add ISO C11 functions c16rtomb, c32rtomb, mbrtoc16, mbrtoc32.")
Fixes: c49bc478b4 ("Cygwin: Add ISO C2X functions c8rtomb, mbrtoc8")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-08-15 22:34:29 +02:00
Corinna Vinschen adc7eafa76 Cygwin: fhandler_base::lseek: fix formatting
Fixes: edfa581d3c ("Cygwin: lseek: implement SEEK_DATA and SEEK_HOLE for files")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-08-09 18:08:45 +02:00
Corinna Vinschen 9939aa7d09 Cygwin: add SEEK_DATA/SEEK_HOLE addition to release message
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-08-09 17:21:54 +02:00
Corinna Vinschen edfa581d3c Cygwin: lseek: implement SEEK_DATA and SEEK_HOLE for files
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-08-09 17:18:14 +02:00
Corinna Vinschen b6fbe0fc2e Cygwin: lseek: propagate new SEEK_DATA and SEEK_HOLE to fhandler
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-08-09 16:56:40 +02:00
Corinna Vinschen 5b53633b5d 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>
2023-08-09 16:56:02 +02:00
Corinna Vinschen 2e7332d6bd Cygwin: fix build failure due to redefinition of __restrict in sys/cdefs.h
Commit 3c75fac130 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 e66c63be6b
("sys/cdefs.h: introduce __restrict_arr, as in glibc")

Fixes: 3c75fac130 ("sys/cdefs.h: fix for use __restrict in C++"
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-08-07 16:04:32 +02:00
Takashi Yano 3b4f6217c3 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: 7b03b0d8ce ("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>
2023-08-04 17:49:29 +09:00
Corinna Vinschen c49bc478b4 Cygwin: Add ISO C2X functions c8rtomb, mbrtoc8
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-08-02 16:56:24 +02:00
Corinna Vinschen 8fbbc668a0 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: 4f258c55e8 ("Cygwin: Add ISO C11 functions c16rtomb, c32rtomb, mbrtoc16, mbrtoc32.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-08-02 16:56:24 +02:00
Takashi Yano 5ac83ea47a newlib: Fix memory leak regarding gdtoa-based _ldtoa_r().
After the commit a4705d387f, 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: a4705d387f ("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>
2023-08-02 15:00:56 +09:00
Corinna Vinschen dedbbd74d0 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: 70e476d27b ("(peek_socket): Use event handling for peeking socket.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-08-01 14:22:55 +02:00
Corinna Vinschen 0e711d6cc9 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>
2023-08-01 14:16:40 +02:00
Corinna Vinschen 4f258c55e8 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>
2023-07-31 22:39:09 +02:00