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>
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>
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>
Nano malloc uses `size' in assertation whereas the correct variable would be
`s'. Given this has existed ever since nano malloc support was added, based
on the context ("returned payload area of desired size does not exceed the
actual allocated chunk") I presume that indeed `s' (user input) and not
`r->size' (computed) shall be used.
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>
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>
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>
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>
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>
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>
C23 requires that the unicode functions c16rtomb, c8rtomb, mbrtoc16,
mbrtoc32 and mbrtoc8 use their own internal state object. c32rtomb
only needs an internal state if the lib supports encoding with
shift states, but that's the case for newlib and Cygwin.
Only Cygwin implements these functions so add the states
objects only for Cygwin for now.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
After addition of SEEK_HOLE, the whence of *4* is not an invalid
argument, causing the test to FAIL.
See ltp commit 423e636a4c8f ("lseek03: change to fix with the lseek syscall")
Avoid transient failures by adding a small delay after fork()-ing to
allow the child to get into a state where it can recieve signals.
Also add same small delay to kill03 and kill04. kill02 has a more
elaborate setup where child processes write to a pipe to indicate they
have started.
SEEK_DATA and SEEK_HOLE are GNU nonstandard extensions also present
in Solaris, FreeBSD, and DragonFly BSD; they are proposed for inclusion
in the next POSIX revision (Issue 8).
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Example test case that fails with undefined reference to getentropy:
Testing g++.robertl/eb77.C, -std=c++20
doing compile
Executing on host: /build/gcc-13-2709-g9ac9fde961f/bin/arm-none-eabi-g++ /build/src/gcc/gcc/testsuite/g++.old-deja/g++.robertl/eb77.C -mthumb -march=armv6s-m -mcpu=cortex-m0 -mfloat-abi=soft -fdiagnostics-plain-output -fmessage-length=0 -std=c++20 -pedantic-errors -Wno-long-long -Wl,--start-group -lc -lm -Wl,--end-group --specs=nosys.specs -Wl,--allow-multiple-definition -Wl,-u,_isatty,-u,_fstat -Wl,-wrap,exit -Wl,-wrap,_exit -Wl,-wrap,main -Wl,-wrap,abort -Wl,g++_tg.o -lm -o ./eb77.exe (timeout = 800)
spawn -ignore SIGHUP /build/gcc-13-2709-g9ac9fde961f/bin/arm-none-eabi-g++ /build/src/gcc/gcc/testsuite/g++.old-deja/g++.robertl/eb77.C -mthumb -march=armv6s-m -mcpu=cortex-m0 -mfloat-abi=soft -fdiagnostics-plain-output -fmessage-length=0 -std=c++20 -pedantic-errors -Wno-long-long -Wl,--start-group -lc -lm -Wl,--end-group --specs=nosys.specs -Wl,--allow-multiple-definition -Wl,-u,_isatty,-u,_fstat -Wl,-wrap,exit -Wl,-wrap,_exit -Wl,-wrap,main -Wl,-wrap,abort -Wl,g++_tg.o -lm -o ./eb77.exe
pid is 28414 -28414
/build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/bin/ld: /build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libstdc++.a(random.o): in function `std::(anonymous namespace)::__libc_getentropy(void*)':
(.text._ZNSt12_GLOBAL__N_117__libc_getentropyEPv+0x8): undefined reference to `getentropy'
/build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/bin/ld: /build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libstdc++.a(random.o): in function `std::random_device::_M_init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
(.text._ZNSt13random_device7_M_initERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x58): undefined reference to `getentropy'
/build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/bin/ld: /build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libc.a(libc_a-arc4random.o): in function `_rs_stir':
(.text._rs_stir+0x8): undefined reference to `getentropy'
collect2: error: ld returned 1 exit status
pid is -1
close result is 28414 exp6 0 1
output is /build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/bin/ld: /build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libstdc++.a(random.o): in function `std::(anonymous namespace)::__libc_getentropy(void*)':
(.text._ZNSt12_GLOBAL__N_117__libc_getentropyEPv+0x8): undefined reference to `getentropy'
/build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/bin/ld: /build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libstdc++.a(random.o): in function `std::random_device::_M_init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
(.text._ZNSt13random_device7_M_initERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x58): undefined reference to `getentropy'
/build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/bin/ld: /build/gcc-13-2709-g9ac9fde961f/bin/../lib/gcc/arm-none-eabi/13.0.0/../../../../arm-none-eabi/lib/thumb/v6-m/nofp/libc.a(libc_a-arc4random.o): in function `_rs_stir':
(.text._rs_stir+0x8): undefined reference to `getentropy'
collect2: error: ld returned 1 exit status
status 1
compiler exited with status 1
FAIL: g++.old-deja/g++.robertl/eb77.C -std=c++20 (test for excess errors)
Excess errors:
(.text._ZNSt12_GLOBAL__N_117__libc_getentropyEPv+0x8): undefined reference to `getentropy'
(.text._ZNSt13random_device7_M_initERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x58): undefined reference to `getentropy'
(.text._rs_stir+0x8): undefined reference to `getentropy'
UNRESOLVED: g++.old-deja/g++.robertl/eb77.C -std=c++20 compilation failed to produce executable
Contributed by STMicroelectronics
Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
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>
C99 allows to define arrays as non-overlappiung using the restrict
keyword. This is supported by GCC 3.1 and later, but it's not
allowed in C++.
This is in preparation of fixing a Cygwin build problem introduce by
commit 3c75fac130.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Newlib shares large parts of <sys/cdefs.h> with FreeBSD and received
this bug report:
https://sourceware.org/pipermail/newlib/2023/020400.html
As an extension, GCC and clang offer C99-style restricted pointers in
C++ mode:
https://gcc.gnu.org/onlinedocs/gcc/Restricted-Pointers.html
We notice that this extension is broken when including newlib headers:
restricted pointers are treated as ordinary pointers.
We traced this to the following section of
newlib/libc/include/sys/cdefs.h:
/*
* GCC 2.95 provides `__restrict' as an extension to C90 to support the
* C99-specific `restrict' type qualifier. We happen to use `__restrict' as
* a way to define the `restrict' type qualifier without disturbing older
* software that is unaware of C99 keywords.
*/
#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95)
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901
#define __restrict
#else
#define __restrict restrict
#endif
#endif
While the GCC __restrict extension was indeed introduced in GCC 2.95, it
is not limited to this version; the extension is also not limited to
C90:
https://gcc.gnu.org/gcc-2.95/c++features.html
Rewrite the logic in the header so that __restrict is kept alone when
available.
PR: 272723
MFC after: 1 week
version of __generic()
This ensures that __generic() more closely matches _Generic() when
using the fallback version when _Generic() is not available (such as
GCC).
Co-authored by: jrtc27
Reviewed by: jrtc27
Differential Revision: https://reviews.freebsd.org/D38215
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>
Add feature test for C2X code. Add matching definitions
_ISOC2X_SOURCE for requesting sources and __ISO_C_VISIBLE
to be used in headers.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
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>
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>
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>