Rather than having testsuite.h do various things, depending on defines,
just have it do one thing, and then explicitly redirect to test stubs in
path.cc when building test.
Rather than fetching the system Windows directory at dll init time
only on 32 bit, fetch it on all platforms. Store as WCHAR and
UNICODE_STRING. Use where appropriate to simplify code.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
commit 456c3a4638 was only going half-way. It handled symlinks and
junction points as inner path components and made realpath return the
correct path, but it ignored drive letter substitution, i. e., virtual
drives created with, e. g.
subst X: C:\foo\bar
It was also too simple. Just returning an error code from
symlink_info::check puts an unnecessary onus on the symlink evaluation
loop in path_conv::check.
Rework the code to use GetFinalPathNameByHandle, and only do this after
checking the current file for being a symlink failed.
If the final path returned by GetFinalPathNameByHandle is not the same
as the incoming path, replace the incoming path with the POSIXified
final path. This also short-circuits path evaluation, because
path_conv::check doesn't have to recurse over the inner path components
multiple times if all symlinks are of a native type, while still getting
the final path as end result.
Virtual drives are now handled like symlinks. This is a necessary change
from before to make sure virtual drives are handled identically across
different access methods. An example is realpath(1) from coreutils. It
doesn't call readlink(2), but iterates over all path components using
lstat/readlink calls. Both methods should result in the same real path.
Fixes: 456c3a4638 ("path_conv: Try to handle native symlinks more sanely")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Converting to automake dropped the former, handwritten tags/ctags
target. This leads to a couple of problems:
- For no good reason the tags file gets written to the builddir
instead of to the srcdir where it's needed.
- `make tags' requires etags to exist, rather than checking if it
exists and skipping it.
- Adding the extra ctags arguments to AM_CTAGSFLAGS still results
in a shortened tags file.
(Temporary?) solution: Revert the old tags/ctags rules and silence
the automake warnings.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
autogen.sh expects to run from within the winsup dir, so
set CWD accordingly before running autotools.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
page/swap space name >= 40 or size/used >= 8 leaves no space between fields;
ensure a space after name and add extra tabs after size and used fields;
output appears like Linux 5.8 after changes to mm/swapfile(swap_show);
proc-swaps-space-before.log:
==> /proc/swaps <==
Filename Type Size Used Priority
/mnt/c/pagefile.sys file 11567748292920 0
/mnt/d/pagefile.sys file 12582912205960 0
proc-swaps-space-after.log:
==> /proc/swaps <==
Filename Type Size Used Priority
/mnt/c/pagefile.sys file 11567748 241024 0
/mnt/d/pagefile.sys file 12582912 182928 0
Install autoconf and automake, and run winsup/autogen.sh, and don't have
it silently ignore failures.
On AppVeyor:
- use latest VM image, to reduce time spent installing updates.
- run the testsuite, but ignore the result, as some tests don't work
correctly.
- hardcode the python-lxml and python-ply packages to install, so we get
ones for the right python.
- install texlive collections now needed to build documentation.
On github:
- Use a copr for cocom, since RPMSphere's package updates don't track
fedora:latest very efficently.
_mq_send as well as _mq_receive call ipc_mutex_unlock twice in case
of success, after having introduced __try/__except blocks.
Fixes: 3f3bd10104 ("* Throughout, use __try/__except/__endtry blocks, rather than myfault handler.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
POSIX requires that message priorities range from 0 (low) to
sysconf(_SC_MQ_PRIO_MAX) - 1 (high). Cygwin's mq_send erroneously
allowed a message priority of sysconf(_SC_MQ_PRIO_MAX). Fix it.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
We are building a ps executable, but the rule to build the target
collides with an auto-generated, documentation-related `ps' rule.
Work around that by naming the executable "cygps" at build time
and use a transform rule to rename it at installation time.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Specify toollibdir and toolincludedir in terms of tooldir, so the
install location is correct if tooldir is the default
($(exec_prefix)/$(target_alias)), or explicitly specified on the 'make'
command line.
Linux 5.12 Frozen Wasteland added features and changes:
add AMD 0x8000000a EDX:20 v_spec_ctrl virtual speculation control support
add Intel 0x00000007 ECX:24 bus_lock_detect bus lock detect debug exception
v2:
* Include tzmap.h in BUILT_SOURCES
* Make per-file flags appear after user-supplied CXXFLAGS, so they can
override optimization level.
* Correct .o files used to define symbols exported by libm.a
* Drop gcrt0.o mistakenly included in libgmon.a
* Add missing line continuations in GMON_FILES value
v3:
* use per-file flags for .c compilation
* override C{XX,}FLAGS, as they are set on the command line by top-level make
v4:
* Drop -Wno-error=write-strings from path_testsuite CXXFLAGS
v5:
* Update for changes in master
- Add -fno-threadsafe-statics to CXX flags
- Add hypotl.cc
- Remove fenv.cc (in favour of newlib), add fenv.c stub
- Add proc.5 manpage rules
Following POSIX and Linux, allow a connected DGRAM socket's connection
to be reset (so that the socket becomes unconnected). This is done by
calling connect and specifing an address whose family is AF_UNSPEC.
When connect is called on a DGRAM socket, the call to Winsock's
connect can immediately return successfully rather than failing with
WSAEWOULDBLOCK. Set the connect state to "connected" in this case.
Previously the connect state remained "connect_pending" after the
successful connection.
- In commit bb93c6d7, the race issue was not completely fixed. In
the pseudo console inheritance, if the destination process to
which the ownership of pseudo console switches, is found but exits
before switching, the inheritance fails. Currently, this extremely
rarely happens. This patch fixes the issue.
Commit 456c3a4638 added a workaround when handling paths with native
symlinks as inner path components. This patch introduced a problem for
paths handled by the WOW64 File System Redirector (FSR).
Fix this problem by not performing the new code from commit 456c3a4638
for paths under the Windows directory. Only do this in WOW64.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
For local paths, add a check if the inner path components contain native
symlinks or junctions. Compare the incoming path with the path returned
by NtQueryInformationFile(FileNameInformation). If they differ, there
must be at least one native symlink or junction in the path. If so,
treat the currently evaluated file as non-existant. This forces
path_conv::check to backtrack inner path components until we eliminated
all native symlinks or junctions and have a normalized path.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The simple newlib hypotl for real long double architectures is too
simple at this point. It's implemented as a real call to sqrtl(x^2+y^2).
This has a fatal tendency to overflow for big input numbers. Hypotl
isn't supposed to do that if the result would still be valid in range of
long double.
Given the complexity of implementing hypotl for various architectures,
we just take the hypotl function from Mingw-w64, which is in the public
domain.
Even though this hypotl is an architecture-independent implementation,
we can't use it for newlib yet, unfortunately, because it requires logbl
under the hood. Logbl is yet another function missing in newlib for
real long double architectures.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Use the more official fesetenv(FE_DFL_ENV) from _dll_crt0, thus
allowing to drop the _feinitialise declaration from fenv.h.
Provide a no-op _feinitialise in Cygwin as exportable symbol for really
old applications when _feinitialise was called from mainCRTStartup in
crt0.o.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Drop the Cygwin-specific fenv.cc and fenv.h file and use the equivalent
newlib functionality now, so we have at least one example of a user for
this new mechanism.
fenv.c: allow _feinitialise to be called from Cygwin startup code
fenv.h: add declarations for fegetprec and fesetprec for Cygwin only.
Fix a comment.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
An FD_CLOSE event sets a socket descriptor ready for writing.
This is incorrect if the FD_CLOSE is a result of shutdown(SHUT_RD).
Only set the socket descriptor ready for writing if the FD_CLOSE
is indicating an connection abort or reset error condition.
This requires to tweak fhandler_socket_wsock::evaluate_events.
FD_CLOSE in conjunction with FD_ACCEPT/FD_CONNECT special cases
a shutdown condition by setting an error code. This is correct
for accept/connect, but not for select. In this case, make sure
to return with an error code only if FD_CLOSE indicates a
connection error.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
So far select wrongly sets the descriptor as ready for exception
when a shutdown occurs. This is entirely non-standard. Only set
this bit on an out-of-band event.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
- Currently, functions/variables regarding the handles for cygwin
apps are with "_cyg", and those of handles for non-cygwin apps
are without "_cyg", such as get_handle_cyg() and get_handle().
This patch renames these to the names without "_nat" and with
"_nat" respectively, such as get_handle() and get_handle_nat().
When the Windows Store version of Python is installed, so-called "app
execution aliases" are put into the `PATH`. These are reparse points
under the hood, with an undocumented format.
We do know a bit about this format, though, as per the excellent analysis:
https://www.tiraniddo.dev/2019/09/overview-of-windows-execution-aliases.html
The first 4 bytes is the reparse tag, in this case it's
0x8000001B which is documented in the Windows SDK as
IO_REPARSE_TAG_APPEXECLINK. Unfortunately there doesn't seem to
be a corresponding structure, but with a bit of reverse
engineering we can work out the format is as follows:
Version: <4 byte integer>
Package ID: <NUL Terminated Unicode String>
Entry Point: <NUL Terminated Unicode String>
Executable: <NUL Terminated Unicode String>
Application Type: <NUL Terminated Unicode String>
Let's treat them as symbolic links. For example, in this developer's
setup, this will result in the following nice output:
$ cd $LOCALAPPDATA/Microsoft/WindowsApps/
$ ls -l python3.exe
lrwxrwxrwx 1 me 4096 105 Aug 23 2020 python3.exe -> '/c/Program Files/WindowsApps/PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0/python.exe'
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
The Windows Store version of Python (and apparently other Windows Store
applications) install a special reparse point called "app execution
alias" into the user's `PATH`.
These applications can be executed without any problem, but they cannot
be read as if they were files. This trips up Cygwin's beautiful logic that
tries to determine whether we're about to execute a Cygwin executable or
not: instead of executing the application, it will fail, saying
"Permission denied".
Let's detect this situation (`NtOpenFile()` helpfully says that this
operation is not supported on this reparse point type), and simply skip
the logic: Windows Store apps are not Cygwin executables (and even if
they were, it is unlikely that they would come with a compatible
`cygwin1.dll` or `msys-2.0.dll`).
This fixes https://github.com/msys2/MSYS2-packages/issues/1943
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
- Currently, names of output pipes are "pty%d-to-master" and "pty%d-
to-master-cyg" and names of input pipes are "pty%d-to-slave" and
"pty%d-from-master". With this patch, these pipes are renamed to
"pty%d-to-master-nat", "pty%d-to-master", "pty%d-from-master-nat"
and "pty%d-from-master" respectively.
- Currently, transfer input is triggered even if the stdin of native
app is not a pseudo console. With this patch it is triggered only
if the stdin is a pseudo console.
- If two non-cygwin apps are started simultaneously, attaching to
pseudo console sometimes fails. This is because the second app
trys to attach to the process not started yet. This patch avoids
the issue by attaching to the stub process rather than the other
non-cygwin app.
- Perhaps current code misunderstand meaning of the IGNBRK. As far
as I investigated, IGNBRK is concerned with break signal in serial
port but there is no evidence that it has effect to ignore Ctrl-C.
This patch stops ignoring Ctrl-C by IGNBRK for non-cygwin apps.
This reverts commit 532b91d24e.
It turned out that this patch has undesired side effects. To wit, if a
newer, post-uname_x executable was linked against or loading an older,
pre-uname_x DLL, and this DLL called uname. This call would jump into
the old uname with the old struct utsname as parameter, but given the
newer executable it would get redirected to uname_x. uname_x in turn
would overwrite stack memory it should leave well alone, given it
expects the newer, larger struct utsname.
For the entire discussion see the thread starting at
https://cygwin.com/pipermail/cygwin/2021-February/247870.html
and continuing in March at
https://cygwin.com/pipermail/cygwin/2021-March/247930.html
For a description where we're coming from, see
https://cygwin.com/pipermail/cygwin/2021-March/247959.html
While we *could* make the scenario in question work by patching dlsym,
the problem would actually be the same, just for dynamic loading. In
the end, we're missing the information, which Cygwin version has been
used when building DLLs.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
- If two non-cygwin apps are started simultaneously and this is the
first execution of non-cygwin apps in the pty, these occasionally
hang up. The cause is the race issue between term_has_pcon_cap(),
reset_switch_to_pcon() and setup_pseudoconsole(). This patch fixes
the issue.
linkat(olddirfd, oldpath, oldname, newdirfd, newname, AT_EMPTY_PATH)
is supposed to create a link to the file referenced by olddirfd if
oldname is the empty string. Currently this is done via the /proc
filesystem by converting the call to
linkat(AT_FDCWD, "/proc/self/fd/<olddirfd>", newdirfd, newname,
AT_SYMLINK_FOLLOW),
which ultimately leads to a call to the appropriate fhandler's link
method. Simplify this by using cygheap_fdget to obtain the fhandler
directly.
If linkat(2) is called with AT_EMPTY_PATH on an AF_LOCAL or
AF_UNIX socket that is not a socket file, the current code calls
fhandler_disk_file::link in most cases. The latter expects to be
operating on a disk file and uses the socket's io_handle, which
is not a file handle.
Fix this by calling fhandler_disk_file::link only if the
fhandler_socket object is a file (determined by testing
dev().isfs()).
Also fix the case of a socket file opened with O_PATH by setting
the fhandler_disk_file's io_handle.
If facl(2) is called on an AF_LOCAL or AF_UNIX socket that is not a
socket file, the current code calls fhandler_disk_file::facl in most
cases. The latter expects to be operating on a disk file and uses the
socket's io_handle, which is not a file handle.
Fix this by calling fhandler_disk_file::facl only if the
fhandler_socket object is a file (determined by testing dev().isfs()).
If fchown(2) is called on an AF_LOCAL or AF_UNIX socket that is not a
socket file, the current code calls fhandler_disk_file::fchown in most
cases. The latter expects to be operating on a disk file and uses the
socket's io_handle, which is not a file handle.
Fix this by calling fhandler_disk_file::fchown only if the
fhandler_socket object is a file (determined by testing dev().isfs()).
If fchmod(2) is called on an AF_LOCAL or AF_UNIX socket that is not a
socket file, the current code calls fhandler_disk_file::fchmod in most
cases. The latter expects to be operating on a disk file and uses the
socket's io_handle, which is not a file handle.
Fix this by calling fhandler_disk_file::fchmod only if the
fhandler_socket object is a file (determined by testing dev().isfs()).
If fstatvfs(2) is called on an AF_LOCAL or AF_UNIX socket that is not
a socket file, the current code calls fhandler_disk_file::fstatvfs in
most cases. The latter expects to be operating on a disk file and
uses the socket's io_handle, which is not a file handle.
Fix this by calling fhandler_disk_file::fstatvfs only if the
fhandler_socket object is a socket file (determined by testing
dev().isfs()).
If fstat(2) is called on an AF_LOCAL or AF_UNIX socket that is not a
socket file, the current code calls fstat_fs. The latter expects to
be operating on a disk file and uses the socket's io_handle, which is
not a file handle.
Fix this by calling fstat_fs only if the fhandler_socket object is a
file (determined by testing dev().isfs()).
This is in the spirit of the Linux requirement that file operations
like fchmod(2), fchown(2), and fgetxattr(2) fail with EBADF on files
opened with O_PATH.
This was done for the fhandler_socket_local class in commits
3a2191653a, 141437d374, and 477121317d, but the fhandler_socket_unix
class was overlooked.
When a FIFO is opened, syscalls.cc:open always calls fstat on the
newly-created fhandler_fifo. This results from a call to
device_access_denied.
To speed-up this fstat call, and therefore the open(2) call, use
PC_KEEP_HANDLE when the fhandler is created. The resulting
conv_handle is retained until after the fstat call if the fhandler is
a FIFO; otherwise, it is closed immediately.
Previously, the call to get_file_attribute for FIFOs set the first
argument to NULL instead of the handle h returned by get_stat_handle,
thereby forcing the file to be opened for fetching the security
descriptor in get_file_sd(). This was done because h might have been
a pipe handle rather than a file handle, and its permissions would not
necessarily reflect those of the file.
That situation can no longer occur with the new fhandler_fifo::fstat
introduced in the previous commit.
Previously fstat on a FIFO would call fhandler_base::fstat.
The latter is not appropriate if fhandler_fifo::open has already been
called (and O_PATH is not set), for the following reason. If a FIFO
has been opened as a writer or duplexer, then it has an io_handle that
is a pipe handle rather than a file handle. fhandler_base::fstat will
use this handle and potentially return incorrect results. If the FIFO
has been opened as a reader, then it has no io_handle, and a call to
fhandler_base::fstat will lead to a call to fhandler_base::open.
Opening the fhandler a second time can change it in undesired ways;
for example, it can modify the flags and status_flags.
The new fhandler_fifo::fstat avoids these problems by creating an
fhandler_disk_file and calling its fstat method in case
fhandler_fifo::open has already been called and O_PATH is not set.
Consider this case:
- Cygwin installed in C:\cygwin64
- mklink /j D:\cygwin64 C:\cygwin64
- create testcase calling
realpath("/", result);
printf ("%s\n", result);
- start cmd
>C:\cygwin64\bin\bash -lc <path-to-testcase>
/
>D\cygwin64\bin\bash -lc <path-to-testcase>
/cygdrive/c/cygwin64
This scenario circumventing the mount point handling which is automated
in terms of /, depending on the path returned from GetModuleFileNameW
for the Cygwin DLL. When calling D:\cygwin64\bin\bash the dir returned
from GetModuleFileNameW is D:\cygwin64\bin, thus root is D:\cygwin64.
However, junctions are treated as symlinks in Cygwin which explains why
the path gets converted to a cygdrive path.
Fix this by calling GetFinalPathNameByHandleW on the result from
GetModuleFileNameW to get the correct root path, even if accessed via
a junction point.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This only affects the very seldom bordercase of apps calling setmode(fd,
0) on fhandlers not calling fhandler_base::set_open_status(). All
fhandlers not calling set_open_status() are binary mode only, but the
way reset_to_open_binmode worked, calling setmode(fd, 0) would have
"reset" their open flags to O_TEXT accidentally.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
- If ENABLE_LINE_INPUT is set, Ctrl-S is handled by Windows if the
OS is Windows 7. This conflicts with Ctrl-S handling in cygwin
console code. This patch unsets ENABLE_LINE_INPUT flag in cygwin
and set it when native app is executed.
- If ENABLE_VIRTUAL_TERMINAL_INPUT is not set, changing window height
does not generate WINDOW_BUFFER_SIZE_EVENT. This happens if console
is in the legacy mode. Therefore, with this patch, the windows size
is checked every time in cons_master_thread() if the cosole is in
the legacy mode.
Linux 5.11 💕 Valentine's Day Edition 💕 added features and changes:
add Intel 0x00000007 EDX:23 avx512_fp16 and 0x00000007:1 EAX:4 avx_vnni;
group scattered AMD 0x8000001f EAX Secure Mem/Encrypted Virt features at end:
0 sme, 1 sev, 3 sev_es (more to come not yet displayed)
- Currently, Ctrl-Z, Ctrl-\ and SIGWINCH does not work in console
if the process does not call read() or select(). This is because
these are processed in process_input_message() which is called
from read() or select(). This is a long standing issue of console.
Addresses:
https://cygwin.com/pipermail/cygwin/2020-May/244898.htmlhttps://cygwin.com/pipermail/cygwin/2021-February/247779.html
With this patch, new thread which handles only input signals is
introduced so that Crtl-Z, etc. work without calling read() or
select(). Ctrl-S and Ctrl-Q are also handled in this thread.
change notes to see "Implementation Notes" to xref to std-notes;
add xref to std-notes to getrlimit, setrlimit;
add note to document limitations of getrlimit, setrlimit resources support
- Currently, console read() keeps reading after SIGWINCH is sent
even if SA_RESTART flag is not set. With this patch, read()
returns EINTR on SIGWINCH if SA_RESTART flag is not set.
The same problem for SIGQUIT and SIGTSTP has also been fixed.
- Currently, input transfer is performed every time one line is read(),
if the non-cygwin app is running in the background. With this patch,
transfer is triggered by setpgid() rather than read() so that the
unnecessary input transfer can be reduced much in that situation.
Per discussion on cygwin-developers, a Cygwin tmpfile(3) implementation
has been added to syscalls.cc. This overrides the one supplied by
newlib. Then the open(2) flag O_TMPFILE was added to the open call that
tmpfile internally makes.
This v2 patch removes O_CREAT from open() call as O_TMPFILE obviates it.
Note that open() takes a directory's path but returns an fd to a file.
Analyzing the fhandler::copyto logic shows that the fhandler_base::reset
method was only called from copyto anyway.
Trying to convert reset to a protected method uncovered that the copyto
method is actually thought upside down from an object oriented POV.
Rather than calling copyto, manipulating the object given as parameter,
rename the method to copy_from, which manipulates the calling object
itself with data from the object given as parameter.
Eventually make reset a protected method and rename it to
_copy_from_reset_helper to clarify it's only called from copy_from.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
path_conv_handle::dup calls DuplicateHandle unconditionally,
but we only have a handle in some cases. Check handle for being
non-NULL before calling DuplicateHandle.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
path_conv::reset_conv_handle is only called after fhandler::copyto
has been called. This duplicated the path_conv_handle if there was
one, so just setting the conv handle to NULL potentially produces a
handle leak. Replace reset_conv_handle calls with calls to
close_conv_handle and drop the reset_conv_handle method.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
There's a slim chance that duplicating fhandlers may end up duplicating
path_conv_handle handles twice ending up with a handle leak, due to
fhandler_base::reset calling path_conv::operator<< after the only
caller, fhandler::copyto, already called path_conv::operator=.
Just drop the call which basically duplicates what path_conv::operator=
already did.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This reverts commit 76dca77f04. That
commit was based on the incorrect assumption that get_stat_handle,
when called on a FIFO in fstat_helper, would always return a handle
that is safe to use for getting the file information.
That assumption is true in many cases but not all. For example, if
the call to fstat_helper arises from a call to fstat(2) on a FIFO that
has been opened for writing, then get_stat_handle will return a pipe
handle instead of a file handle.
Allow check_reparse_point_target to recognize reparse points with
reparse tag IO_REPARSE_TAG_AF_UNIX. These are used in recent versions
of Windows 10 to represent AF_UNIX sockets.
check_reparse_point_target now returns PATH_REP on files of this type,
so that they are treated as known reparse points (but not as sockets).
This allows tools like 'rm', 'ls', etc. to operate on these files.
Addresses: https://cygwin.com/pipermail/cygwin/2020-September/246362.htmlhttps://cygwin.com/pipermail/cygwin/2021-January/247666.html
The new header defines some Cygwin-specific limits, using private
names. It is included by include/limits.h.
For example, we now have
#define __OPEN_MAX 3200
in include/cygwin/limits.h and
#define OPEN_MAX __OPEN_MAX
in include/limits.h. The purpose is to hide implementation details
from users who view <limits.h>.
Replace all occurrences of OPEN_MAX_MAX by OPEN_MAX, and define the
latter to be 3200, which was the value of the former. In view of the
recent change to getdtablesize, there is no longer a need to
distinguish between these two macros.
Now that getdtablesize always returns OPEN_MAX_MAX, we can simplify
sysconf(_SC_OPEN_MAX) and getrlimit(RLIMIT_NOFILE) to just use that
same constant instead of calling getdtablesize.
According to the Linux man page for getdtablesize(3), the latter is
supposed to return "the maximum number of files a process can have
open, one more than the largest possible value for a file descriptor."
The constant OPEN_MAX_MAX is the only limit enforced by Cygwin, so we
now return that.
Previously getdtablesize returned the current size of cygheap->fdtab,
Cygwin's internal file descriptor table. But this is a dynamically
growing table, and its current size does not reflect an actual limit
on the number of open files.
With this change, gnulib now reports that getdtablesize and
fcntl(F_DUPFD) work on Cygwin. Packages like GNU tar that use the
corresponding gnulib modules will no longer use gnulib replacements on
Cygwin.
- Currently, thread created by pthread_create() is not suspended by
the signal SIGTSTP. For example, even if a process with a thread
is suspended by Ctrl-Z, the thread continues running. This patch
fixes the issue.
- Currently, read() returns -1 with EINTR if the process is suspended
by Ctrl-Z and resumed by fg command, while pty continues to read.
For example, xxd command stops with error "Interrupted system call"
after Ctrl-Z and fg. This patch aligns the behaviour with pty (and
Linux).
Allow fchmodat with the AT_SYMLINK_NOFOLLOW flag to succeed on
non-symlinks. Previously it always failed, as it does on Linux. But
POSIX permits it to succeed on non-symlinks even if it fails on
symlinks.
The reason for following POSIX rather than Linux is to make gnulib
report that fchmodat works on Cygwin. This improves the efficiency of
packages like GNU tar that use gnulib's fchmodat module. Previously
such packages would use a gnulib replacement for fchmodat on Cygwin.
- After commit bb428520, there has been the disadvantage:
7) Pseudo console cannot be activated if it is already activated for
another process on same pty.
This patch clears this disadvantage.
- After commit bb428520, there has been the disadvantage:
2) The apps which use console API cannot be debugged with gdb. This
is because pseudo console is not activated since gdb uses
CreateProcess() rather than exec(). Even with this limitation,
attaching gdb to native app, in which pseudo console is already
activated, works.
This patch clears this disadvantage.
- After commit bb428520, there has been the disadvantage:
4) Code page cannot be changed by chcp.com. Acctually, chcp works
itself and changes code page of its own pseudo console. However,
since pseudo console is recreated for another process, it cannot
inherit the code page.
This patch clears this disadvantage.
- PTY has a problem that the key input, which is typed during windows
native app is running, disappears when it returns to shell. This is
beacuse pty has two input pipes, one is for cygwin apps and the other
one is for native windows apps. The key input during windows native
program is running is sent to the second input pipe while cygwin
shell reads input from the first input pipe. This issue had been
fixed once by commit 29431fcb, however, the new implementation of
pseudo console support by commit bb428520 could not inherit this
feature. This patch realize transfering input data between these
two pipes bidirectionally by utilizing cygwin-console-helper process.
The helper process is launched prior to starting the non-cygwin app,
however, exits immediately unlike previous implementation.
Following POSIX, ensure that ctime is updated if chown succeeds,
unless the new owner is specified as (uid_t)-1 and the new group is
specified as (gid_t)-1. Previously, ctime was unchanged whenever the
owner and group were both unchanged.
Aside from POSIX compliance, this fix makes gnulib report that chown
works on Cygwin. This improves the efficiency of packages like GNU
tar that use gnulib's chown module. Previously such packages would
use a gnulib replacement for chown on Cygwin.
I think we don't need an extra flag as we can utilize: access & FILE_WRITE_ATTRIBUTES
What do you think?
Ben Wijen (1):
syscalls.cc: unlink_nt: Try FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE
winsup/cygwin/ntdll.h | 3 ++-
winsup/cygwin/syscalls.cc | 22 +++++++--------
winsup/cygwin/wincap.cc | 11 ++++++++
winsup/cygwin/wincap.h | 56 ++++++++++++++++++++-------------------
4 files changed, 53 insertions(+), 39 deletions(-)
--
2.30.0
>From 2d0ff6fec10d03c24d11c747852018b7bc1136ac Mon Sep 17 00:00:00 2001
In-Reply-To: <20210122105201.GD810271@calimero.vinschen.de>
References: <20210122105201.GD810271@calimero.vinschen.de>
From: Ben Wijen <ben@wijen.net>
Date: Tue, 17 Dec 2019 15:15:25 +0100
Subject: [PATCH v3 1/8] syscalls.cc: unlink_nt: Try
FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE
Implement wincap.has_posix_unlink_semantics_with_ignore_readonly and when set
skip setting/clearing of READONLY attribute and instead use
FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE
Move post-dir unlink check from fhandler_disk_file::rmdir to
_unlink_nt_post_dir_check
If a directory is not removed through fhandler_disk_file::rmdir
we can now make sure the post dir check is performed.
- After the commit 72770148, script command exits occasionally with
the error "Bad file descriptor" if it is started in console on Win7
and non-cygwin process is executed. This patch fixes the issue.
- The buffer used in get_console_process_id(), introduced by commit
72770148, is too large and ERROR_NOT_ENOUGH_MEMORY occurs in Win7.
Therefore, the buffer size has been reduced.
The isdev_dev check in rmdir is unclean. Create a virtual method
fhandler_dev::rmdir to handle this transparently.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
- cat exits immediately in the following senario.
1) Execute env CYGWIN=disable_pcon script
2) Execute cmd.exe
3) Execute cat in cmd.exe.
This is caused by setting input_available_event for the pipe for
non-cygwin app. This patch fixes the issue.
- The functions pty_master_thread() and pty_master_fwd_thread()
should be static (i.e. should not access class member) because
the instance is deleted if the master is dup()'ed and the first
master is closed. In this case, because the dup()'ed instance
still exists, these master threads are also still alive even
though the instance has been deleted. As a result, accesing
class members in these functions causes accessi violation.
Addresses:
https://cygwin.com/pipermail/cygwin-developers/2021-January/012030.html
- After commit 232fde0e, pty changes console code page when the first
non-cygwin app is executed. If pty is started in real console device,
pty changes the code page of root console. This causes very annoying
result because changing code page changes the font of command prompt
if console is in legacy mode. This patch avoids this by creating a
new invisible console for the first pty started in console device.
The old implementation for __cxa_guard_acquire did not return 1,
therefore dynamic initialization was never performed.
If concurrent-safe dynamic initialisation is ever needed, CXX ABI
must be followed when re-implementing __cxa_guard_acquire (et al.)
- The function close_pseudoconsole() should be static so that it
can be safely called in spawn.cc even after the fhandler_pty_slave
instance has been deleted. That is, there is a problem with the
current code. This patch fixes the issue.
- If application changes the console mode, mode management introduced
by commit 10d8c278 will be corrupted. For example, stdout of jansi
v2.0.1 or later is piped to less, jansi resets the xterm mode flag
ENABLE_VIRTUAL_TERMINA_PROCESSING when jansi is terminated. This
causes garbled output in less because less needs this flag enabled.
This patch fixes the issue.
- The workaround for rlwrap introduced by commit 8199b0cc does not
take effect for rlwrap 0.40 or later. This patch add a workaround
for rlwrap 0.40 or later as well.
Update to Linux next 5.10 cpuinfo flags for Intel SDM 36.7.1 Software
Guard Extensions, and 38.1.4 SGX Launch Control Configuration.
Launch control restricts what software can run with enclave protections,
which helps protect the system from bad enclaves.
- Previous workaround has a problem that screen is distorted if up
arrow key is pressed at the first line after running "rlwrap cmd".
This patch fixes the issue.
- Previous code to read response for CSI6n allows invalid response
such as "CSI Pl; Pc H" other than correct response "CSI Pl; Pc R".
With this patch, the response is checked more strictly.
if an application built after API version 334 loads uname dynamically,
it actually gets the old uname, rather than the new uname_x. Fix this by
checking the apps API version in uname and call uname_x instead, if it's
a newer app.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
- Sometimes timeout period in term_has_pcon_cap() may not be enough
when the machine slows down for some reason. This patch eases the
issue. In the new code, effective timeout period is expected to be
extended as a result due to slowing-down the wait loop as well when
the machine gets into busy.
The comment and debug output became obsolete in commit 23771fa1f7 when
dup_worker started calling fhandler_base::clone instead of build_fh_pc
and fhandler_base::operator=.
The existing code errors as EINVAL any attempt to set a value for
SO_PEERCRED via setsockopt() on an AF_UNIX/AF_LOCAL socket. But to
enable the workaround set_no_getpeereid behavior for Python one has
to be able to set SO_PEERCRED to zero. Ergo, this patch. Python has
no way to specify a NULL pointer for 'optval'.
This v2 of patch allows the original working (i.e., allow NULL,0 for
optval,optlen to mean turn off SO_PEERCRED) in addition to the new
working described above. The sense of the 'if' stmt is reversed for
readability.
On some systems /bin/sh is not /bin/bash and cygmagic has bash-isms in
it. So even though cygmagic has a /bin/bash shebang, it also needs to be
launched with bash from within Makefile.in.
https://cygwin.com/pipermail/cygwin/2020-December/246938.html
reports a problem where, when adding a Cygwin default symlink
to $PATH since Cygwin 3.1.5, $PATH handling appears to be broken.
3.1.5 switched to WSL symlinks as Cygwin default symlinks.
A piece of code in path handling skips resolving reparse points
if they are the last component in the path. Thus a reparse point
in $PATH is not resolved but converted to Windows path syntax
verbatim.
If you do this with a WSL symlink, certain WinAPI functions fail.
The underlying $PATH handling fails to recognize the reparse
point in $PATH and returns with STATUS_IO_REPARSE_TAG_NOT_HANDLED.
As a result, the calling WinAPI function fails, most prominently
so CreateProcess.
Fix this problem by adding a PATH_REP_NOAPI bit to path_types
and a matching method path_conv::is_winapi_reparse_point().
Right now this flag is set for WSL symlinks and Cygwin AF_UNIX
sockets (new type implemented as reparse points).
The aforementioned code skipping repare point path resolution calls
is_winapi_reparse_point() rather than is_known_reparse_point(),
so now path resolution is only skipped for reparse points known
to WinAPI.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This libltp is old as old dirt and still using K&R style.
If it's really to be used again at all, it needs a serious
refresh.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Network filesystems are not block devices. Apparently this code
hasn't been executed anyway, given how network filesystems are
hidden behind \Device\Mup.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Use fhandler_dev_floppy instead of fhandler_procsys for such devices.
The read()/write() functions from fhandler_procsys do not ensure
sector aligned transfers and lseek() fails always.
Signed-off-by: Christian Franke <franke@computer.org>
- If vim is executed in WSL in mintty, some garbage string caused
by "OSC Ps;? BEL/ST" will be shown in some situations. This patch
fixes the issue by removing "OSC Ps;? BEL/ST" from pseudo console
output.
Since we are now only configuring once, in winsup, with
AC_CONFIG_AUX_DIR(..), the auxiliary files are taken from the top-level.
(Previously we had a random assorment of AC_CONFIG_AUX_DIR(..) and
AC_CONFIG_AUX_DIR(../..) in winsup subdirectories, so auxiliary files
would be taken from winsup or the top-level.)
There's doesn't seem to be much use in independently distributing these
subdirectories, so allowing them to be independently configured seems
pointless and overcomplicated.
The order in which the subdirectories are built is still a little odd,
as cygwin is linked with libcygserver, and cygserver is then linked with
cygwin. So, we build the cygwin directory first, which invokes a build
of libcygserver in the cygserver directory, and then build in the
cygserver directory to build the cygserver executable.
Drop AC_CONFIGURE_ARGS, since we don't need to recursively call
configure with the same arguments anymore.
Slightly refine when we build utils: Previously we didn't build any
utils if MinGW compiler use was avoided, now we just avoid building
those utils which require that compiler.
Greatly simplify how winsup_srcdir and target_builddir are set, since
we're only configuring from one directory. (These are still kept
absolute, since we don't adjust them where used for being used in a
subdirectory).
Remove configure.cygwin and put it's (greatly reduced) contents inline
in the one place it's used now.
Remove generated configure and aclocal.m4 in subdirectories.
This has a test of the path translation code used in various utilities
(mount, cygpath, strace).
MOUNT_BINARY is replaced with the absence of MOUNT_TEXT since 26e0b37e.
The issys member of mnt_t struct was removed in b677a99b.
> $ make check
[...]
> total tests: 63
> pass : 63 (100.0%)
> fail : 0 (0.0%)
'-fno-exceptions -fno-rtti' are already present in the compile command
COMPILE.cc set by Makefile.common, so we don't need to add them to
CXXFLAGS as well.
Invoke grep in text mode when looking for version strings inside the
cygwin DLL, so it outputs something more informative than:
Binary file ../cygwin/cygwin0.dll matches
The overflow check in mEMALIGn erroneously checks for INT_MAX,
albeit the input parameter is size_t. Fix this to check for
__SIZE_MAX__ instead. Also, it misses to check the req against
adding the alignment before calling mALLOc.
While at it, add out-of-bounds checks to pvALLOc, nano_memalign,
nano_valloc, and Cygwin's (unused) dlpvalloc.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Replace the 'WCHAR pipe_name_buf[48]' class member by 'PWCHAR
pipe_name_buf', and allocate space for the latter as needed.
Change the default constructor to accommodate this change, and add a
destructor that frees the allocated space.
Also change get_pipe_name and clone to accommodate this change.
By default, libltp tests will create temporary files in a subdirectory
of /tmp, which will (nowadays) be located relative to the test DLL (by
assuming that it is in /bin). This will evaluate to the directory
$target_builddir/winsup/tmp, which doesn't exist.
The location used for these temporary files can be explicitly controlled
by setting the TDIRECTORY env var. Arrange to set that env var to the
/cygdrive path of a tmp subdirectory of the build directory.
Unfortunately, libltp doesn't clean the temporary directory if
TDIRECTORY is set, and some tests assume they are started in a clean
directory, so we need to do that in tcl.
Set the PATH so that tests can pick up cygwin0.dll. Looks like this was
dropped by accident in 2e488e95 ("Don't rely on in-build tools"), so
restore it as it was prior to 9d89f634.
Drop MINGW_FE, which I can't find any trace of, and instead detect and
use MinGW compilers.
This requires adding AC_CANONICAL_TARGET, to set $target_cpu.
This is now required as cygwin_build is defined in terms of
target_builddir.
(Note that in other subdirectories, the autoconf variable
target_builddir is AC_SUBST-ed as a side-effect of using a macro from
winsup/acinclude.m4, which is perhaps less than ideal)
The autoconf variable all_host is used to make building of the stub
library used by the testsuite conditional on not cross-compiling.
Make it unconditional, so we will notice if it's broken when
cross-compiling.
b55e3f19 was a bit too aggressive in dropping, rather than just
un-exporting these Makefile variables. We need to set these to the
configured host compiler if we are cross-compiling, otherwise they
default to the build compiler.
Also export CC to the mkvers.sh script (which requires it since
4eca5e6a). It's unclear why we can't just cause windres to use the
build 'cpp' as the pre-processor there.
The return value is now -NaN.
This fixes a bug in the mingw-w64 code that was imported into Cygwin.
The fix is consistent with Posix and Linux. It is also consistent
with the current mingw-w64 code, with one exception: The mingw-w64
code sets errno to EDOM if the input is -NaN, but this appears to
differ from Posix and Linux.
Addresses: https://cygwin.com/pipermail/cygwin/2020-October/246606.html
- Calling ResizePseudoConsole() generates some escape sequences.
Due to this behaviour, if the output of non-cygwin app is piped
to less, screen is sometimes distorted when the screen is resized.
With this patch, ResizePseudoConsole() is not called if stdout is
redirected.
- If output of non-cygwin process is piped to cygwin process, such
as less, the non-cygwin process sometimes fails to start and hangs.
This patch fixes the issue.
If MSG_WAITALL is set, recv_internal calls WSARecv or WSARecvFrom in a
loop, in an effort to fill all the scatter-gather buffers. The test
for whether all the buffers are full was previously incorrect.
ccwrap massages the compiler's standard include directories to remove
'/usr/include/w32api', with the intent of allowing it to be overriden by
'--with-windows-headers' (See 4c36016b).
I'm not 100% convinced that this is always working as desired, since in
some places w32api includes are done using <w32api/something.h>, which
will find them via the path /usr/include.
If this does turn out to be needed, this could also be implemented by
constructing the appropriate compiler flags once, rather than on every
compiler invocation.
As discussed in GCC bug 97088
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97088), parameters in
prototypes of library functions should use reserved names, or no name
at all.
This patch moves the internal struct __tzrule_struct to its own
internal header sys/_tz_structs.h. This is included from newlib's
time code as well as from Cygwin's localtime wrapper.
Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The autoconf variable LIBSERVER isn't defined, and it's value isn't
used. (The Makefile.in contains a literal value for the name of this
library instead).
This is only needed if we are using an ancient make which doesn't set
${MAKE}, but we say "This makefile requires GNU make." everywhere.
It only has an effect if @SET_MAKE@ is used, which we aren't doing
consistently.
Add linux-next 5.9 cpuinfo flag for Intel enqcmd/s instructions:
x86/cpufeatures: Enumerate ENQCMD and ENQCMDS instructions:
Work submission instruction comes in two flavors. ENQCMD can be called
both in ring 3 and ring 0 and always uses the contents of a PASID MSR
when shipping the command to the device. ENQCMDS allows a kernel driver
to submit commands on behalf of a user process. The driver supplies the
PASID value in ENQCMDS. There isn't any usage of ENQCMD in the kernel as
of now.
The CPU feature flag is shown as "enqcmd" in /proc/cpuinfo.
If __WITH_AF_UNIX is defined when Cygwin is built, then a named
AF_UNIX socket is represented by a reparse point with a
Cygwin-specific tag and GUID. Make such files recognizable as reparse
points (but not as sockets) even if __WITH_AF_UNIX is not defined.
That way utilities such as 'ls' and 'rm' still behave reasonably.
This requires two changes:
- Define the GUID __cygwin_socket_guid unconditionally.
- Make check_reparse_point_target return PATH_REP on a reparse point
of this type if __WITH_AF_UNIX is not defined.
Commit aa467e6e, "Cygwin: add AF_UNIX reparse points to path
handling", changed check_reparse_point_target so that it could return
a positive value on a known reparse point that is not a symlink. But
some of the code in check_reparse_point that handles this positive
return value was executed unconditionally, when it should have been
executed only for symlinks.
As a result, posixify could be called on a buffer containing garbage,
and check_reparse_point could erroneously return a positive value on a
non-symlink. This is now fixed so that posixify is only called if the
reparse point is a symlink, and check_reparse_point returns 0 if the
reparse point is not a symlink.
Also fix symlink_info::check to handle this last case, in which
check_reparse_point returns 0 on a known reparse point.
The following Windows system calls currently fail with
STATUS_IO_REPARSE_TAG_NOT_HANDLED when called on an AF_UNIX socket:
- NtOpenFile in get_file_sd
- NtOpenFile in set_file_sd
- NtCreateFile in fhandler_base::open
Fix this by adding the FILE_OPEN_REPARSE_POINT flag to those calls
when the file is a known reparse point.
../../../../src/winsup/cygwin/pinfo.cc: In member function 'DWORD pinfo::status_exit(DWORD)':
../../../../src/winsup/cygwin/ntdll.h:21:68: error: narrowing conversion of '-536870295' from 'NTSTATUS' {aka 'int'} to 'unsigned int' [-Wnarrowing]
../../../../src/winsup/cygwin/pinfo.cc:136:10: note: in expansion of macro 'STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION'
../../../../src/winsup/cygwin/sigproc.cc: In member function 'DWORD child_info::proc_retry(HANDLE)':
../../../../src/winsup/cygwin/ntdll.h:21:68: error: narrowing conversion of '-536870295' from 'NTSTATUS' {aka 'int'} to 'unsigned int' [-Wnarrowing]
../../../../src/winsup/cygwin/sigproc.cc:1120:10: note: in expansion of macro 'STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION'
NT error statuses seem to be variously DWORD (unsigned) or NTSTATUS
(signed)? So use the one which doesn't cause problems here.
../../../../src/winsup/cygwin/fhandler_console.cc: In member function 'const unsigned char* fhandler_console::write_normal(const unsigned char*, const unsigned char*)':
../../../../src/winsup/cygwin/fhandler_console.cc:2782:8: error: narrowing conversion of '-2' from 'int' to 'long unsigned int' [-Wnarrowing]
../../../../src/winsup/cygwin/fhandler_console.cc:2786:8: error: narrowing conversion of '-1' from 'int' to 'long unsigned int' [-Wnarrowing]
../../../../src/winsup/cygwin/fhandler_console.cc:2836:8: error: narrowing conversion of '-2' from 'int' to 'long unsigned int' [-Wnarrowing]
../../../../src/winsup/cygwin/fhandler_console.cc:2840:8: error: narrowing conversion of '-1' from 'int' to 'long unsigned int' [-Wnarrowing]
A mbtowc_p function returns an int, so that seems the correct type to use here.
../../../../src/winsup/cygwin/fhandler_socket_inet.cc: In member function 'ssize_t fhandler_socket_wsock::send_internal(_WSAMSG*, int)':
../../../../src/winsup/cygwin/fhandler_socket_inet.cc:1381:69: error: suggest parentheses around assignment used as truth value [-Werror=parentheses]
Commit aa467e6e, "Cygwin: add AF_UNIX reparse points to path
handling", changed the return values of check_reparse_point_target.
Update the comment accordingly.
This was added as a temporary measure in commit e18f7f99 because it
wasn't yet in the mingw-w64 headers. With one exception, it is now in
the current release of the headers (version 8.0.0), so we don't need
it in winlean.h.
The exception is that VirtualAlloc2 is declared conditionally in
<w32api/memoryapi.h>, but the compilation of Cygwin requires it to
always be declared, even though it will only be executed on systems
that support it. So retain the declaration in winlean.h. And add
"WINAPI" to the declaration, as in memoryapi.h.
Add a check that version >= 8 of the mingw-w64 headers is intalled.
Also revert commit 3d136011, which was a related temporary workaround.
enumerate Vista, 7, 8, 10 progression to be clear, and earliest server 2008;
add 8.1, exclude S mode, add Cygwin32 on ARM, specify 64 bit only AMD/Intel
- Charset conversion for UTF-7, ISO-2022 and ISCII, which are not
supported in cygwin, does not work properly as a result. At the
expense of the above, the code has been simplified a bit.
If the process exited with e.g. STATUS_DLL_NOT_FOUND, also process the
file to look for not found DLLs.
(We currently only do this when a STATUS_DLL_NOT_FOUND exception occurs,
which I haven't managed to observe)
This still isn't 100% correct, as it only examines the specified file
for missing DLLs, not recursively on the DLLs it depends upon.
- If pseudo console is disabled, non-cygwin apps do not detect
console device. In this case, some apps output UTF-8 regardless
of the locale setting. At least git-for-windows, rust-based apps
and node.js do that. This patch provides backward compatibility
as default behaviour by setting console codepage to the charset of
the locale. Even in the cases above, garbled output is prevented
with this patch in most cases because mintty uses UTF-8 by default.
I beleave this is not really a problem in cygwin side but that in
app side, however, some users complain about garbled output with
existing apps in MSYS2 (which is based on cygwin) in which pseudo
console is disabled by default.
Setting up the pty in the master constructor ends up creating a new pty
on every stat(2) call on /dev/ptmx. Only do this when actually opening
the device, not when using the device class in another, non-opening
context.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
- Use tmp_pathbuf instead of HeapAlloc()/HeapFree().
- Remove mb_str_free() function.
- Consider the case where the multibyte string stops in the middle
of a multibyte char.
fhandler_process::exists is called when we are checking a path
starting with "/proc/<pid>/fd". If it returns virt_none and sets an
errno, there is no need for further checking. Just set 'error' and
return.
The incoming path is allowed to have the form "$PID/fd/[0-9]*/.*"
provided the descriptor symlink points to a directory. Check that
this is indeed the case.
The new function __eval_codepage_from_internal_charset
is a simplified version of the former code in
fhandler_tty.cc. It probably needs some extension,
but the gist is to use knowledge of internals to
be as quick as possible.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Both flags are outdated and collide with official flags in
sys/_default_fcntl.h, which may result in weird misbehaviour
of file functions.
O_NOSYMLINK is not used anyway.
O_DIROPEN is used in fhandler_virtual and derived classes.
The collision with O_NOFOLLOW results in spurious EISDIR
errors when, e. g., reading files in the registry.
fhandler_base::open_fs uses O_DIROPEN in the call to
fhandler_base::open, but it's not used in this context
further down the road.
Drop both flags and create an alternative "diropen" bool
flag in fhandler_virtual.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
...as on glibc right now. This is supposed to support autoconf scripts
checking for existence of these symbols in libpthread.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
GLibc will change this code in the forseeable future to align more
with FreeBSD, so this hack is not actually desired.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
- Pseudo console internally sends escape sequence CSI6n (query cursor
position) on startup of non-cygwin apps. If the terminal does not
support CSI6n, CreateProcess() hangs waiting for response. To prevent
hang, this patch disables pseudo console if the terminal does not
have CSI6n. This is checked on the first execution of non-cygwin
app using the following steps.
1) Check if the terminal support ANSI escape sequences by looking
into terminfo database. If terminfo has cursor_home (ESC [H),
the terminal is supposed to support ANSI escape sequences.
2) If the terminal supports ANSI escape sequneces, send CSI6n for
a test and wait for a responce for 40ms.
3) If there is a responce within 40ms, CSI6n is supposed to be
supported.
Also set-title capability is checked, and removes escape sequence
for setting window title if the terminal does not have the set-
title capability.
Currently, when using CYGWIN's error_start facility, the faulting
process isn't stopped while the error_start process is started when the
fault is caused by an exception. (it even seems possible in theory that
the faulting process could have exited before the error_start process
attaches).
This leads to e.g. the core dump written by CYGWIN='error_start=dumper'
in response to an exception being non-deterministic.
Remove the waitloop argument from try_to_debug(), only used in the
exception case, so the faulting process busy-waits until the error_start
process attaches.
Code archaeology to determine why the code is this way didn't really
turn up any answers, but this seems a low-risk change, as this only
changes the behaviour when:
- a debugger isn't already attached
- an error_start is specified in CYGWIN env var
- an exception has occurred which will be translated to a signal
If error_start invokes something which doesn't attach using
DebugActiveProcess(), we will spin indefinitely, but that will also
currently occur for any of the existing other uses of try_to_debug(),
which default to waitloop=TRUE.
On 32 bit x86, clang seems to miss loading input parameters based
on asm constraints for inline assembly that uses the x87 floating
registers, unless the snippet has got the volatile keyword.
Signed-off-by: Martin Storsjö <martin@martin.st>
Code taken from FreeBSD, which implements C11 threads as
wrapper around pthreads. Fix up machine/_threads.h which
is called from newlib's machine-independent threads.h to
match Cygwin's pthreads types.
Add the FreeBSD source files to libc subdir and take
opportunity to define LIBC_OFILES var in Makefile.
Add new symbols to common.din and sort symbols.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
In preparation of importing FreeBSDs stdthreads functions,
change the way pthread_yield is exported, so that the symbol
can be used internally as well.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
pthread_yield was only declared under GNU visibility,
but the function should be available under BSD visibility
as well.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
POSIX requires that key destructors are called in a loop
for each key with a non-NULL value until all values are
NULL, or until all destructors for non-NULL values
have been called at least PTHREAD_DESTRUCTOR_ITERATIONS
(per POSIX: 4) times.
Cygwinonly called all destructors with non-NULL values
exactly once. This patch fixes Cygwin to follow POSIX.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
We need one more entry than max children in the arrays.
There's no reason to do this for the static array, though.
One more entry in the overflow array is sufficient.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
On PROC_EXEC_CLEANUP, the pinfo's in chld_procs are removed.
This is done in a loop always removing the child with index 0.
This, however, results in copying the last child's pinfo in
chld_procs to position 0. Do this for 100 children and you
get 99 entirely useless copy operations.
Fix this by calling remove_proc in reverse order.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
256 children per process is a bit tight in some scenarios.
Fix this by revamping the `procs' array. Convert it to an
extensible class child_procs and rename procs to chld_procs.
Fix code throughout to use matching class methods rather than
direct access.
To allow a lot more child processes while trying to avoid
allocations at DLL startup, maintain two arrays within class
child_procs, one using a default size for 255 (i686) or 1023
(x86_64) children, the other, dynamically allocated on overflowing
the first array, giving room for another 1023 (i686) or 4095
(x86_64) processes.
On testing with a simple reproducer on a x86_64 machine with
4 Gigs RAM, a system memory overflow occured after forking
about 1450 child processes, so this simple dynamic should
suffice for a while.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
pinfo::remember with the detach parameter set to true is
the only way to call proc_subproc with PROC_DETACHED_CHILD.
This call is exclusively used in spawn to set up a pinfo for
a detached child, and that pinfo goes out of scope right
afterwards without any further action.
Drop the flag and drop the detach parameter from pinfo::remember.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The return value is used in a numerical context and remove_proc
already returned inconsistently "true" vs. 0.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
After patch 23a779bf3d
"Cygwin: pinfo: stop remember doing reattach",
PROC_ADDCHILD actually just sets up a new child, mirroring
PROC_DETACHED_CHILD. The actual attaching of the child is
performed by action PROC_REATTACH_CHILD or pinfo::reattach
respectively.
To better reflect what's going on, rename PROC_REATTACH_CHILD
to PROC_ATTACH_CHILD and rename pinfo::reattach to pinfo::attach.
For better readability change PROC_ADDCHILD to PROC_ADD_CHILD.
Fix comments accordingly.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
change all kinds of setup references to "the Cygwin Setup program";
emphasize 64 bit and deemphasize 32 bit;
update options list;
explain why installing everything is now extremely inadvisable, with stats
- In this implementation, pseudo console is created for each native
console app. Advantages and disadvantages of this implementation
over the previous implementation are as follows.
Advantages:
1) No performance degradation in pty output for cygwin process.
https://cygwin.com/pipermail/cygwin/2020-February/243858.html
2) Free from the problem caused by difference of behaviour of control
sequences between real terminal and pseudo console.
https://cygwin.com/pipermail/cygwin/2019-December/243281.htmlhttps://cygwin.com/pipermail/cygwin/2020-February/243855.html
3) Free from the problem in cgdb and emacs gud.
https://cygwin.com/pipermail/cygwin/2020-January/243601.htmlhttps://cygwin.com/pipermail/cygwin/2020-March/244146.html
4) Redrawing screen on executing native console apps is not necessary.
5) cygwin-console-helper is not necessary for the pseudo console
support.
6) The codes for pseudo console support are much simpler than that
of the previous one.
Disadvantages:
1) The cygwin program which calls console API directly does not work.
2) The apps which use console API cannot be debugged with gdb. This
is because pseudo console is not activated since gdb uses
CreateProcess() rather than exec(). Even with this limitation,
attaching gdb to native apps, in which pseudo console is already
activated, works.
3) Typeahead key inputs are discarded while native console app is
executed. Simirally, typeahead key inputs while cygwin app is
executed are not inherited to native console app.
4) Code page cannot be changed by chcp.com. Acctually, chcp works
itself and changes code page of its own pseudo console. However,
since pseudo console is recreated for another process, it cannot
inherit the code page.
5) system_printf() does not work after stderr is closed. (Same with
cygwin 3.0.7)
6) Startup time of native console apps is about 3 times slower than
previous implemenation.
7) Pseudo console cannot be activated if it is already activated for
another process on same pty.
Any C++ app that calls 'throw' on 64-bit Cygwin results in an
exception of type STATUS_GCC_THROW (0x20474343) generated by the C++
runtime. Don't pollute the strace output by printing information
about this and other GCC exceptions.
This is necessary in order to be consistent with the following comment
in the definition of _Unwind_RaiseException() in the GCC source file
libgcc/unwind-seh.c:
The exception handler installed in crt0 will continue any GCC
exception that reaches there (and isn't marked non-continuable).
Previously we failed to do this and, as a consequence, the C++ runtime
didn't call std::terminate after an unhandled exception.
This fixes the problem reported here:
https://cygwin.com/pipermail/cygwin/2019-October/242795.htmlhttps://sourceware.org/pipermail/cygwin/2020-August/245897.html
- After commit 095972ce5b, charset
conversion in mintty is broken if charset is set to other than
UTF-8. This seems to be caused because mintty does not set locale
yet at fork() call. This patch changes the timing of set_locale()
call again to avoid this issue.
- If native app is exec()'ed in a new pty, setup_locale() loses the
chance to be called. For example, with "mintty -e cmd", charset
conversion does not work as expected. This patch fixes the issue.
- If a lot of mintty are started in a short time from a mintty, some
of them hang with empty screen, crash immediately or hang on exiting
mintty. The following report seems to be related to this issue.
https://cygwin.com/pipermail/cygwin/2020-August/245751.html
The cause is not clear at all, but this patch seems to solve the
issue.
- update path to Unicode windowsZones.xml file
- drop Windows XP considerations
- regenerate tzmap.h
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This patch has been inspired by the Linux kernel patch
294f69e662d1 compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use
written by Joe Perches <joe AT perches DOT com> based on an idea from
Dan Carpenter <dan DOT carpenter AT oracle DOT com>. The following text
is from the original log message:
Reserve the pseudo keyword 'fallthrough' for the ability to convert the
various case block /* fallthrough */ style comments to appear to be an
actual reserved word with the same gcc case block missing fallthrough
warning capability.
All switch/case blocks now should end in one of:
break;
fallthrough;
goto <label>;
return [expression];
continue;
In C mode, GCC supports the __fallthrough__ attribute since 7.1,
the same time the warning and the comment parsing were introduced.
Cygwin-only: add an explicit -Wimplicit-fallthrough=5 to the build
flags.
Currently raw_read makes two passes through the list of clients. On
the first pass it tries to read from the client from which it last
read successfully. On the second pass it tries to read from all
connected clients.
Add a new pass in between these two, in which raw_read tries to read
from all clients that are in the fc_input_avail case. This should be
more efficient in case select was previously called and detected input
available.
Slightly tweak the first pass. If a client is marked as having the
last successful read but reading from it now finds no input, don't
unmark it unless we successfully read from a different client on one
of the later passes.
The fifo_reader thread function and the function select.cc:peek_fifo()
can both change the state of a fifo_client_handler. These changes are
made under fifo_client_lock, so there is no race, but the changes can
still be incompatible.
Add code to make sure that only one of these functions can change the
state from its initial fc_listening state. Whichever function does
this calls the fhandler_fifo::record_connection method, which is now
public so that peek_fifo can call it.
Slightly modify that method to make it suitable for being called by
peek_fifo.
Make a few other small changes to the fifo_reader thread function to
change how it deals with the STATUS_PIPE_CLOSING value that can
(rarely) be returned by NtFsControlFile.
Add commentary to fhandler_fifo.cc to explain fifo_client connect
states and where they can be changed.
Don't try to read from fifo_client_handlers that are in the fc_closing
state. Experiments have shown that this always yields
STATUS_PIPE_BROKEN, so it just wastes a Windows system call.
Re-order the values in enum fifo_client_connect_state to reflect the
new status of fc_closing.
Rename the existing set_state() to query_and_set_state() to reflect
what it really does. (It queries the O/S for the pipe state.) Add a
new set_state() method, which is a standard setter, and a
corresponding getter get_state().
fhandler_fifo::take_ownership() is called from select.cc::peek_fifo
and fhandler_fifo::raw_read and could potentially block indefinitely
if something goes wrong. This is always undesirable in peek_fifo, and
it is undesirable in a nonblocking read. Fix this by adding a timeout
parameter to take_ownership.
Arbitrarily use a 1 ms timeout in peek_fifo and a 10 ms timeout in
raw_read. These numbers may have to be tweaked based on experience.
Replace the call to cygwait in take_ownership by a call to WFSO.
There's no need to allow interruption now that we have a timeout.
fhandler_fifo::take_ownership() tacitly assumes that the current
owner's fifo_reader_thread will be woken up from WFMO when
update_needed_evt is signaled. But it's possible that the the current
owner's fifo_reader_thread is at the beginning of its main loop rather
than in its WFMO call when that event is signaled.
In this case the owner will never see that the event has been
signaled, and it will never update the shared fifo_client_handlers.
The reader that wants to take ownership will then spin its wheels
forever.
Fix this by having the current owner call update_shared_handlers at
the beginning of its loop, if necessary.
microcode is unsigned long long, printed by _small_sprintf using %x;
Cygwin32 used last 4 bytes of microcode for next field MHz, printing 0;
use correct _small_sprintf format %X to print microcode, producing
correct MHz value under Cygwin32
CPUID 7:0 EDX[14] serialize added in linux-next 5.8 by Ricardo Neri-Calderon:
The Intel architecture defines a set of Serializing Instructions (a
detailed definition can be found in Vol.3 Section 8.3 of the Intel "main"
manual, SDM). However, these instructions do more than what is required,
have side effects and/or may be rather invasive. Furthermore, some of
these instructions are only available in kernel mode or may cause VMExits.
Thus, software using these instructions only to serialize execution (as
defined in the manual) must handle the undesired side effects.
As indicated in the name, SERIALIZE is a new Intel architecture
Serializing Instruction. Crucially, it does not have any of the mentioned
side effects. Also, it does not cause VMExit and can be used in user mode.
This new instruction is currently documented in the latest "extensions"
manual (ISE). It will appear in the "main" manual in the future.
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/arch/x86/include/asm/cpufeatures.h?id=85b23fbc7d88f8c6e3951721802d7845bc39663d
Newlib's posix_spawn has been taken from FreeBSD. The code relies on
BSD-specific behaviour of vfork, namely the fact that vfork blocks
the parent until the child exits or calls execve as well as the fact
that the child shares parent memory in non-COW mode.
This behaviour can't be emulated by Cygwin. Cygwin's vfork is
equivalent to fork. This is POSIX-compliant, but it's lacking BSD's
vfork ingrained synchronization of the parent to wait for the child
calling execve, or the chance to just write a variable and the parent
will see the result.
So this requires a Cygwin-specific solution. The core function of
posix_spawn, called do_posix_spawn is now implemented twice, once using
the BSD method, and once for Cygwin using Windows synchronization under
the hood waiting for the child to call execve and signalling errors
upstream. The Windows specifics are hidden inside Cygwin, so newlib
only calls internal Cygwin functions.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Stop after we've written the dump in response to the initial breakpoint
EXCEPTION_DEBUG_EVENT we recieve for attaching to the process.
(rather than bogusly sitting there for 20 seconds waiting for more debug
events from a stopped process after we've already written the dump).
It's working on 32 bit OSes only anyway. It even fails on WOW64.
Drop unsupported NtMapViewOfSection flags.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Use the (undocumented) MEMORY_WORKING_SET_EX_INFORMATION in dumper to
determine if a MEM_IMAGE region is unsharable, and hence has been
modified.
After this, we will end up dumping memory regions where:
- state is MEM_COMMIT (i.e. is not MEM_RESERVE or MEM_FREE), and
-- type is MEM_PRIVATE and protection allows reads (i.e. not a guardpage), or
-- type is MEM_IMAGE and attribute is non-sharable (i.e. it was WC, got
written to, and is now a RW copy)
After this, we will end up dumping memory regions where:
- state is MEM_COMMIT (i.e. is not MEM_RESERVE or MEM_FREE), and
-- type is MEM_PRIVATE and protection allows reads (i.e. not a guardpage), or
-- type is MEM_IMAGE and protection allows writes
Making this decision based on the current protection isn't 100% correct,
because it may have been changed using VirtualProtect(). But we don't
know how to determine if a region is shareable.
(As a practical matter, anything which gets us the stack (MEM_PRIVATE)
and .data/.bss (RW MEM_IMAGE) is going to be enough for 99% of cases)
Commit 605bdcd410 enabled mapping beyond
EOF in 64 bit environments. But the variable 'orig_len' did not get
rounded up to a multiple of 64K. This rounding was done on 32 bit
only. Fix this by rounding up orig_len on 64 bit, in the same place
where 'len' is rounded up.
Rounding up is needed to make sigbus_page_len a multiple of the
allocation granularity.
In addition, failing to round up could cause orig_len to be smaller
than len. Since these are both unsigned values, the statement
'orig_len -= len' could then cause orig_len to be huge, and mmap would
fail with errno EFBIG.
I observed this failure while debugging the problem reported in
https://sourceware.org/pipermail/cygwin/2020-July/245557.html.
The failure can be seen by running the test case in that report under
gdb or strace.
- After commit 0365031ce1, key input
becomes not working by following steps.
1) Start cmd.exe in mintty.
2) Open another mintty.
3) Execute "echo AAA > /dev/pty*" (pty* is the pty opened in 1.)
This patch fixes the issue.
Use cygwait in take_ownership to allow interruption while waiting to
become owner. Return the cygwait return value or a suitable value to
indicate an error.
raw_read now checks the return value and acts accordingly.
If update_my_handlers fails to duplicate one or more handles, just
mark the corresponding handlers as being in an error state.
But if update_my_handlers is unable to open the process of the
previous owner, it's likely that something serious has gone wrong, so
we continue to make that a fatal error.
When a reader takes ownership in fifo_reader_thread, it now goes
directly to the part of the main loop that listens for a connection.
Previously it went back to the beginning of the loop.
Also, if the reader has to delay taking ownership because the previous
owner has not finished updating the shared fifo_client handlers, it
now checks to see if cancel_evt has been set. Previously it might
have had to spin its wheels unnecessarily only to eventually find that
its thread had been canceled.
Add a bool member 'last_read' to the fifo_client_handler structure,
which is set to true on a successful read. This is used by raw_read
as follows.
When raw_read is called, it first locates the writer (if any) for
which last_read is true. raw_read tries to read from that writer and
returns if there is input available. Otherwise, it proceeds to poll
all the writers, as before.
The effect of this is that if a writer writes some data that is only
partially read, the next attempt to read will continue to read from
the same writer. This should reduce the interleaving of output from
different writers.
When a reader opens, it needs to block if there are no writers open
(unless is is opened with O_NONBLOCK). This is easy for the first
reader to test, since it can just wait for a writer to signal that it
is open (via the write_ready event). But when a second reader wants
to open, all writers might have closed.
To check this, use a new '_nwriters' member of struct fifo_shmem_t,
which keeps track of the number of open writers. This should be more
reliable than the previous method.
Add nwriters_lock to control access to shmem->_nwriters, and remove
reader_opening_lock, which is no longer needed.
Previously only readers had access to the shared memory, but now
writers access it too so that they can increment _nwriters during
open/dup/fork/exec and decrement it during close.
Add an optional 'only_open' argument to create_shmem for use by
writers, which only open the shared memory rather than first trying to
create it. Since writers don't need to access the shared memory until
they have successfully connected to a pipe instance, they can safely
assume that a reader has already created the shared memory.
For debugging purposes, change create_shmem to return 1 instead of 0
when a reader successfully opens the shared memory after finding that
it had already been created.
Remove check_write_ready_evt, write_ready_ok_evt, and
check_write_ready(), which are no longer needed.
When opening a writer and looping to try to get a connection, recheck
read_ready at the top of the loop since the number of readers might
have changed.
To slightly speed up the process of opening the first reader, take
ownership immediately rather than waiting for the fifo_reader_thread
to handle it.
When the owning reader closes and there are still readers open, the
owner needs to wait for a new owner to be found before closing its
fifo_client handlers. This involves a loop in which dec_nreaders is
called at the beginning and inc_nreaders is called at the end. Any
other reader that tries to access shmem->_nreaders during this loop
will therefore get an inaccurate answer.
Fix this by adding an nreaders method and using it instead of
dec_nreaders and inc_nreaders. Also add nreaders_lock to control
access to the shmem->_nreaders.
Make various other changes to improve the reliability of finding a new
owner.
Since FD_CONNECT is only given once, we manually need to set
FD_WRITE for connection failed sockets to have consistent
behaviour in programs calling poll/select multiple times.
Example test to non-listening port: curl -v 127.0.0.1:47
If the acl_t struct was at or above 0x80000000 then the pointer was
sign-extended to 0xffff_ffff_8000_0000 and so the index was lost.
Signed-off-by: David Allsopp <david.allsopp@metastack.com>
This should slightly speed up especially path conversions,
given there's one less function call rearranging all function
arguments in registers/stack (and less stack pressure).
For clarity, rename overloaded sys_wcstombs to _sys_wcstombs
and sys_cp_mbstowcs to _sys_mbstowcs.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Re: CPU microcode reported wrong in /proc/cpuinfo
https://sourceware.org/pipermail/cygwin/2020-May/245063.html
earlier Windows releases used different registry values to store microcode
revisions depending on the MSR name being used to get microcode revisions:
add these alternative registry values to the cpuinfo registry value lookup;
iterate thru the registry data until a valid microcode revision is found;
some revision values are in the high bits, so if the low bits are all clear,
shift the revision value down into the low bits
sys_mbstowcs is called with the destination buffer length
set to MaximumLength from the receiving UNICODE_STRING buffer.
This is twice as much as the actual size of the buffer in
wchar_t units, which is the unit expected by sys_mbstowcs.
sys_mbstowcs always attaches a NUL, within the destination
buffersize given. But if the string is exactly one wchar_t
less than the actual buffer, and the buffersize is given too
large, sys_mbstowcs writes a NUL one wchar_t beyond the buffer.
This has only been exposed with Cygwin 3.1.5 because alloca
on newer gcc 9 apparently allocates more tightly. The alloca
buffer here is requested with 16 bytes, which is exactly the
number of bytes required for the string L"cmd.exe". Older gcc
apparently allocated a few more bytes on the stack, while gcc 9
allocates in 16 byte granularity...
Fix this by giving the correct destination buffer size to
sys_mbstowcs.
Fixes: https://cygwin.com/pipermail/cygwin/2020-June/245226.html
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>