Commit Graph

13138 Commits

Author SHA1 Message Date
Ken Brown 8889d21010 Cygwin: fix fstatvfs on sockets that are not socket files
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()).
2021-02-25 17:23:33 -05:00
Ken Brown 2f24c0b993 Cygwin: fix fstat on sockets that are not socket files
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()).
2021-02-25 17:23:33 -05:00
Ken Brown 117ddd9dd0 Cygwin: facl: fail with EBADF on files opened with O_PATH
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.
2021-02-24 07:59:41 -05:00
Ken Brown 949fe7bec5 Cygwin: AF_UNIX: allow opening with the O_PATH flag
This was done for the fhandler_socket_local class in commits
3a2191653a, 141437d374, and 477121317d, but the fhandler_socket_unix
class was overlooked.
2021-02-24 07:59:40 -05:00
Takashi Yano via Cygwin-patches 6cde7279a0 Cygwin: console: Prevent NULL pointer access in close().
- There seems to be a case that shared_console_info is not set yet
  when close() is called. This patch adds guard for such case.
2021-02-22 14:57:57 +01:00
Takashi Yano via Cygwin-patches 18b91fbe58 Cygwin: pty: Fix segfault caused when tcflush() is called.
- After commit 253352e796, mc (midnight
  commander) crashes with segfault if the shell is bash. This is due
  to NULL pointer access in read(). This patch fixes the issue.
  Addresses::
    https://cygwin.com/pipermail/cygwin/2021-February/247870.html
2021-02-22 10:50:05 +01:00
Ken Brown 246121534a Cygwin: FIFO: temporarily keep a conv_handle in syscalls.cc:open
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.
2021-02-19 13:43:33 -05:00
Ken Brown 70f6360869 Cygwin: fstat_helper: always use handle in call to get_file_attribute
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.
2021-02-19 13:43:33 -05:00
Ken Brown e67679fcac Cygwin: define fhandler_fifo::fstat
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.
2021-02-19 13:43:33 -05:00
Corinna Vinschen 6d898f43fc Cygwin: realpath: fix cygwin installation dir being access via junction
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>
2021-02-19 18:15:58 +01:00
Corinna Vinschen 543e39bb12 Cygwin: default to O_BINARY in fhandler_base::reset_to_open_binmode()
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>
2021-02-19 18:12:41 +01:00
Takashi Yano via Cygwin-patches b56a371436 Cygwin: console: Add support for FLUSHO and Ctrl-O.
- With this patch, FLUSHO and Ctrl-O (VDISCARD) get working.
2021-02-19 18:07:57 +01:00
Takashi Yano via Cygwin-patches 9677efcf00 Cygwin: pty: Make FLUSHO and Ctrl-O work.
- Previously, FLUSHO feature was implemented incompletely. With
  this patch, FLUSHO and Ctrl-O (VDISCARD) get working.
2021-02-19 18:07:57 +01:00
Takashi Yano via Cygwin-patches 1c70319bda Cygwin: pty: Make tty setting NOFLSH work.
- With this patch, "stty noflsh" gets working in pty.
2021-02-19 18:05:22 +01:00
Takashi Yano via Cygwin-patches 9a7e6073d1 Cygwin: pty: Reflect tty settings to pseudo console mode.
- With this patch, tty setting such as echo, icanon, isig and onlcr
  are reflected to pseudo console mode.
2021-02-19 18:02:13 +01:00
Takashi Yano via Cygwin-patches b07b5829f2 Cygwin: Add console fix regarding Ctrl-Z etc. to release notes. 2021-02-19 17:58:15 +01:00
Takashi Yano via Cygwin-patches 48285aa36c Cygwin: console: Fix handling of Ctrl-S in Win7.
- 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.
2021-02-19 17:56:08 +01:00
Takashi Yano via Cygwin-patches 2b9219b4a5 Cygwin: console: Fix SIGWINCH handling in Win7.
- 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.
2021-02-19 17:56:08 +01:00
Brian Inglis 038d4a78f9 cpuinfo: add AVX features; move SME, SEV/_ES features
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)
2021-02-18 09:39:34 +01:00
Brian Inglis a8d99824ba cpuinfo: fix check for cpuid 0x80000007 support 2021-02-18 09:39:34 +01:00
Takashi Yano via Cygwin-patches ff4440fcf7 Cygwin: console: Introduce new thread which handles input signal.
- 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.html
    https://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.
2021-02-17 10:29:57 +01:00
Brian Inglis 2caca30309 winsup/doc/posix.xml: add note for getrlimit, setrlimit, xrefs to notes
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
2021-02-16 12:27:41 +01:00
Takashi Yano via Cygwin-patches ad28775055 Cygwin: console: Abort read() on signal if SA_RESTART is not set.
- 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.
2021-02-15 14:22:10 +01:00
Takashi Yano via Cygwin-patches 2b94fad48e Cygwin: pty: Fix a bug in input transfer for GDB.
- With this patch, not only NL but also CR is treated as a line end
  in the code checking if input transfer is necessary.
2021-02-15 13:05:56 +01:00
Takashi Yano via Cygwin-patches f206417894 Cygwin: pty: Reduce unecessary input transfer.
- 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.
2021-02-12 10:25:10 +01:00
Corinna Vinschen 67043f48dc Cygwin: only export tmpfile64 on 32 bit
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-02-12 10:24:54 +01:00
Mark Geisert 62ee6581a5 Cygwin: Have tmpfile(3) use O_TMPFILE
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.
2021-02-12 10:18:25 +01:00
Corinna Vinschen 5fea2f87dc Cygwin: fhandler: clean up 'copyto' logic
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>
2021-02-10 10:42:38 +01:00
Corinna Vinschen d0e0a59e78 Cygwin: check path_conv_handle for NULL before trying to dup it
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>
2021-02-10 10:42:38 +01:00
Corinna Vinschen 5f0913df13 Cygwin: drop path_conv::reset_conv_handle
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>
2021-02-10 10:42:38 +01:00
Corinna Vinschen c875ed3744 Cygwin: don't copy path_conv in fhandler_base::reset
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>
2021-02-10 10:42:38 +01:00
Ken Brown 89b3833211 Revert "Cygwin: fstat_helper: always use handle in call to get_file_attribute"
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.
2021-02-09 10:36:30 -05:00
Corinna Vinschen 3192da8f80 Cygwin: drop ftw.h in favor of new newlib ftw.h
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-02-09 11:31:56 +01:00
Marek Smetana d4a756f13a fhandler_serial.cc: MARK and SPACE parity for serial port 2021-02-02 10:41:01 +01:00
Ken Brown 05e2751665 Cygwin: recognize native Windows AF_UNIX sockets as reparse points
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.html
	   https://cygwin.com/pipermail/cygwin/2021-January/247666.html
2021-02-01 09:55:40 -05:00
Ken Brown c09320552b Cygwin: include/cygwin/limits.h: new header
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>.
2021-02-01 09:55:08 -05:00
Ken Brown 5b8358e6ed Cygwin: remove the OPEN_MAX_MAX macro
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.
2021-02-01 09:55:08 -05:00
Ken Brown b9cbc49b70 Cygwin: sysconf, getrlimit: don't call getdtablesize
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.
2021-02-01 09:55:07 -05:00
Ken Brown 3d256e22e2 Cygwin: getdtablesize: always return OPEN_MAX_MAX
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.
2021-02-01 09:55:07 -05:00
Takashi Yano via Cygwin-patches 6c1552b0da Cygwin: exceptions.cc: Suspend all threads in sig_handle_tty_stop().
- 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.
2021-02-01 10:54:04 +01:00
Takashi Yano via Cygwin-patches 6ab2d284e5 Cygwin: console: Align the behaviour against signal with pty.
- 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).
2021-02-01 10:54:04 +01:00
Takashi Yano via Cygwin-patches f186f61d60 Cygwin: pty: Make slave read() thread-safe.
- Currently slave read() is somehow not thread-safe. This patch
  fixes the issue.
2021-02-01 10:54:04 +01:00
Takashi Yano via Cygwin-patches 0b64cc6812 Cygwin: console: Make read() thread-safe.
- Currently read() is somehow not thread-safe. This patch fixes
  the issue.
2021-02-01 10:54:04 +01:00
Ken Brown 883abd9d7d Cygwin: fchmodat: add limited support for AT_SYMLINK_NOFOLLOW
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.
2021-01-29 11:50:53 -05:00
Takashi Yano via Cygwin-patches 253352e796 Cygwin: pty: Allow multiple apps to enable pseudo console simultaneously.
- 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.
2021-01-28 11:21:12 +01:00
Takashi Yano via Cygwin-patches 8aeb3f3e50 Cygwin: pty: Make apps using console APIs be able to debug with gdb.
- 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.
2021-01-28 11:21:12 +01:00
Takashi Yano via Cygwin-patches 442093214d Cygwin: pty: Keep code page between non-cygwin apps.
- 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.
2021-01-28 11:21:12 +01:00
Takashi Yano via Cygwin-patches 10d083c745 Cygwin: pty: Inherit typeahead data between two input pipes.
- 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.
2021-01-28 11:21:12 +01:00
Corinna Vinschen 5b941f21b5 Cygwin: Align *utime*() with POSIX/glibc
Followup to previous patch, this time matching definitions in Cygwin

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-01-26 17:27:35 +01:00
Ken Brown b32f6dd40a Cygwin: chown: make sure ctime gets updated when necessary
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.
2021-01-25 21:07:53 -05:00
Ben Wijen f4cac1217e syscalls.cc: Deduplicate remove
The remove code is already in the _remove_r function.
So, just call the _remove_r function.
2021-01-25 19:57:46 +01:00
Takashi Yano via Cygwin-patches 460eb128cb Cygwin: console: Add missing guard regarding attach_mutex.
- The commit a5333345 did not fix the problem enough. This patch
  provides additional guard for the issue.
2021-01-25 19:54:21 +01:00
Ben Wijen cb41c375a6 syscalls.cc: unlink_nt: Try FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE
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
2021-01-25 10:50:13 +01:00
Ken Brown a60a4501b7 Cygwin: ptsname_r: always return an error number on failure
Return EBADF on a bad file descriptor.  Previously 0 was returned, in
violation of the requirement in
https://man7.org/linux/man-pages/man3/ptsname_r.3.html that an error
number should be returned on failure.

We are intentionally deviating from Linux, on which ENOTTY is
returned.

Addresses: https://lists.gnu.org/archive/html/bug-gnulib/2021-01/msg00245.html
2021-01-22 10:36:43 -05:00
Ken Brown 4aefad2bb8 Cygwin: normalize_posix_path: fix error handling when .. is encountered
When .. is in the source path and the path prefix exists but is not a
directory, return ENOTDIR instead of ENOENT.  This fixes a POSIX
compliance issue for realpath(3):

  https://pubs.opengroup.org/onlinepubs/9699919799/functions/realpath.html

Addresses: https://lists.gnu.org/archive/html/bug-gnulib/2021-01/msg00214.html
2021-01-22 10:31:09 -05:00
Ben Wijen 0c0ff5dc21 Cygwin: Move post-dir unlink check
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.
2021-01-22 13:35:11 +01:00
Takashi Yano via Cygwin-patches a533334581 Cygwin: console: Fix "Bad file descriptor" error in script command.
- 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.
2021-01-20 10:19:39 +01:00
Takashi Yano via Cygwin-patches 5755870f7c Cygwin: pty: Reduce buffer size in get_console_process_id().
- 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.
2021-01-20 10:19:39 +01:00
Takashi Yano via Cygwin-patches 62e739b51b Cygwin: pty: Lessen the side effect of workaround for rlwarp.
- This patch lessens the side effect of the workaround for rlwrap
  introduced by commit 4e16b033.
2021-01-19 10:56:43 +01:00
Takashi Yano via Cygwin-patches 59ccb3a008 Cygwin: spawn.cc: Fix typo in comment by commit 974e6d76. 2021-01-19 10:56:18 +01:00
Corinna Vinschen 877f0d13f0 Cygwin: rmdir: handle /dev in fhandler_dev::rmdir
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>
2021-01-19 10:54:35 +01:00
Ken Brown 31ccf40583 Cygwin: document a recent bug fix
This documents commit aec64798, "Cygwin: add flag to indicate reparse
points unknown to WinAPI".
2021-01-18 11:11:45 -05:00
Takashi Yano via Cygwin-patches a776a0ce26 Cygwin: pty: Set input_available_event only for cygwin pipe.
- 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.
2021-01-18 16:26:28 +01:00
Takashi Yano via Cygwin-patches 25ce7a6245 Cygwin: pty: Make master thread functions be static.
- 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
2021-01-18 14:18:43 +01:00
Takashi Yano via Cygwin-patches 72770148ad Cygwin: pty: Prevent pty from changing code page of parent console.
- 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.
2021-01-18 14:18:43 +01:00
Ben Wijen 9e88e840c2 cxx.cc: Fix dynamic initialization for static local variables
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.)
2021-01-18 12:22:53 +01:00
Ben Wijen cbeb1009a9 syscalls.cc: Use EISDIR
This is the non-POSIX value returned by Linux since 2.1.132.
2021-01-18 12:04:42 +01:00
Ben Wijen 17ede0eae5 syscalls.cc: Fix num_links
NtQueryInformationFile on fh_ro needs FILE_READ_ATTRIBUTES
to succeed.
2021-01-18 12:01:19 +01:00
Corinna Vinschen 226ed24f2b Cygwin: Add Ben Wijen to list of contributors
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-01-18 12:01:19 +01:00
Takashi Yano via Cygwin-patches 85ea2614f5 Cygwin: pty: Make close_pseudoconsole() be a static member function.
- 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.
2021-01-18 11:02:46 +01:00
Takashi Yano via Cygwin-patches 974e6d76d8 Cygwin: console: Revise the code to switch xterm mode.
- 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.
2021-01-18 11:02:46 +01:00
Takashi Yano via Cygwin-patches fa22eea29d Cygwin: pty: Add workaround for rlwrap 0.40 or later.
- 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.
2021-01-18 11:02:46 +01:00
Ken Brown 9ad86f619c Cygwin: fstatat: call fstat64 instead of fstat
This fixes a bug on 32-bit Cygwin that was introduced in commit
84252946, "Cygwin: fstatat, fchownat: support the AT_EMPTY_PATH flag".

Add a comment explaining why fstat should not be called.

Addresses: https://cygwin.com/pipermail/cygwin/2021-January/247399.html
2021-01-12 14:41:53 -05:00
Brian Inglis 1dd3f69db5 fhandler_proc.cc(format_proc_cpuinfo): report Intel SGX bits
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.
2020-12-17 16:03:50 +01:00
Takashi Yano via Cygwin-patches 4e16b0330a Cygwin: pty: Revise the workaround for rlwrap.
- 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.
2020-12-16 10:31:09 +01:00
Takashi Yano via Cygwin-patches da8cebcded Cygwin: pty: Check response for CSI6n more strictly.
- 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.
2020-12-16 10:31:09 +01:00
Corinna Vinschen 532b91d24e Cygwin: Make sure newer apps get uname_x even when loading uname dynamically
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>
2020-12-15 13:05:13 +01:00
Takashi Yano via Cygwin-patches 8199b0cc38 Cygwin: pty: Add a workaround for rlwrap.
- If rlwrap is used with non-cygwin apps, it fails to setup pseudo
  console. This patch adds a workaround for this issue.
2020-12-14 11:02:23 +01:00
Takashi Yano via Cygwin-patches 55eff668b8 Cygwin: pty: Revise the code for timeout in term_has_pcon_cap().
- 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.
2020-12-14 11:02:23 +01:00
Takashi Yano via Cygwin-patches c2c33e4d67 Cygwin: pty: Skip term_has_pcon_cap() if pseudo console is disabled.
- This patch skips unnecessary term_has_pcon_cap() call if pseudo
  console is disabled.
2020-12-14 11:02:23 +01:00
Jeremy Drake via Cygwin-patches 21ec498d7f cygwin: use CREATE_DEFAULT_ERROR_MODE in spawn
This allows native processes to get Windows-default error handling
behavior (such as invoking the registered JIT debugger).
2020-12-10 10:57:40 +01:00
Ken Brown b6624e23e1 Cygwin: dtable::dup_worker: update comment and debug output
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=.
2020-12-07 16:19:57 -05:00
Mark Geisert 9e573ba50f Cygwin: Allow to set SO_PEERCRED zero (v2)
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.
2020-12-07 16:29:11 +01:00
Mark Geisert 58ac5f985c Cygwin: Launch cygmagic with bash, not sh
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.
2020-12-07 10:37:32 +01:00
Anton Lavrentiev via Cygwin-patches 6c9c37d0a9 Fix trace output for getdomainname() 2020-12-07 10:20:45 +01:00
Brian Inglis 31a69bf1d9 winsup/doc/Makefile.in: create man5 dir and install proc.5 2020-12-04 12:40:58 +01:00
Brian Inglis 4157cae5f8 specialnames.xml: add proc(5) Cygwin man page 2020-12-04 12:40:58 +01:00
Corinna Vinschen 604bb7126e
Cygwin: Fix remaining warnings building path testsuite 2020-12-02 15:31:58 +00:00
Jon Turney 0d0f06416a
Cygwin: Fix building of utils testsuite
Avoid referencing undefined max_mount_entry.
2020-12-02 15:31:57 +00:00
Corinna Vinschen aec6479820 Cygwin: add flag to indicate reparse points unknown to WinAPI
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>
2020-12-02 16:14:41 +01:00
Corinna Vinschen e9bc4cccef Cygwin: path.h: add comments to briefly explain path_types
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-12-02 16:14:41 +01:00
Corinna Vinschen 702bec7bc9 Cygwin: testsuite: libltp: fix warnings showing up with -Wall
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>
2020-12-02 14:12:56 +01:00
Corinna Vinschen 80e35a211f Cygwin: /proc/sys FS: don't export NFS and DFS as block devices
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>
2020-12-01 09:37:10 +01:00
Christian Franke 3434d35a64 Cygwin: Fix access to block devices below /proc/sys.
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>
2020-11-30 11:53:00 +01:00
Jon Turney 7fa8405d3f
Cygwin: Have cygmagic not create output if an error occurs
Improve the 'cygmagic' script, so it doesn't create the output file if
an error occurs, even in one of the backtick-enclosed pipelines it runs.
2020-11-25 13:34:18 +00:00
Jon Turney 47e698cc04
Cygwin: Use standard CXXFLAGS when compiling localtime_wrapper.c
This has an separate, explicit compilation rule which omits CXXFLAGS, so
expected flags like '-g -O2' aren't being used.
2020-11-25 13:34:07 +00:00
Jon Turney 6fbe3254a7
Cygwin: Drop libgmon.a build dependency on gcrt0.o
libgmon.a depends on gcrt0.o, but doesn't include it.
2020-11-25 13:34:00 +00:00
Takashi Yano via Cygwin-patches 796044ddcf Cygwin: pty: Fix minor style issue. 2020-11-23 16:23:27 +01:00
Takashi Yano via Cygwin-patches 2eee095928 Cygwin: pty: Discard "OSC Ps; ? BEL/ST" in pseudo console output.
- 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.
2020-11-23 16:23:27 +01:00
Takashi Yano via Cygwin-patches 65ee05d326 Cygwin: pty: Fix a bug in the code removing "CSI > Pm m".
- The code added by 8121b606e8 has a
  bug which fails to remove multiple "CSI > Pm m" sequences. This
  patch fixes the bug.
2020-11-23 16:23:27 +01:00
Jon Turney fccb9d7239
Cygwin: Remove surplus autoconf auxiliary files
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.)
2020-11-20 15:56:21 +00:00
Jon Turney dc93f7ef2d
Cygwin: Remove recursive configure
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.
2020-11-20 15:56:11 +00:00
Ken Brown 11c5fd6abd Cygwin: fhandler_fifo::cleanup_handlers: improve efficiency
Traverse the fifo_client_handler list from the top down to try to
avoid copying.
2020-11-19 15:22:56 -05:00
Jon Turney 9ea6f38dea
Cygwin: Testsuite Makefile cleanup
Drop unused variables CC_FOR_TARGET, GCC_INCLUDE, ALL_CFLAGS
Stop exporting CC, CFLAGS
Drop unused, empty targets force, dll_ofiles, all_target
2020-11-18 16:26:37 +00:00
Jon Turney cbf8fe6dca
Cygwin: Fix 'make check' in utils
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%)
2020-11-18 16:26:36 +00:00
Jon Turney 7d5efba796
Cygwin: Drop duplicate C++ flags used to build utils
'-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.
2020-11-18 16:26:35 +00:00
Jon Turney ff315bd18f
Cygwin: Use grep in text mode to look for version strings
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
2020-11-18 16:26:23 +00:00
Corinna Vinschen aa106b29a6 malloc/nano-malloc: correctly check for out-of-bounds allocation reqs
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>
2020-11-17 10:52:34 +01:00
Corinna Vinschen 3b80191f33 Cygwin: testsuite: fix insecure usage of printf in libltp
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-11-16 15:57:31 +01:00
Ken Brown 22d1ebacfc Cygwin: path_conv::eq_worker: add NULL pointer checks
Don't call cstrdup on NULL pointers.

This fixes a crash that was observed when cloning an fhandler whose
path_conv member had freed its strings.
2020-11-16 08:15:31 -05:00
Jon Turney 140b0a6484
Cygwin: Fix testsuite tmpdir creation with non-default cygdrive prefix 2020-11-12 15:30:35 +00:00
Ken Brown f505e7a032 Cygwin: fhandler_fifo: reduce size
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.
2020-11-09 08:47:29 -05:00
Jon Turney f3ed5f2fe0
Cygwin: Ensure temporary directory used by tests exists
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.
2020-11-08 14:42:02 +00:00
Jon Turney 9cdb799806
Cygwin: Set PATH for tests to pick up cygwin0.dll
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.
2020-11-08 14:41:55 +00:00
Jon Turney 0c448d53e1
Cygwin: Check exit code of a test, rather than stdout
In winsup.exp, don't consider a command failed if it produced any output
(e.g. if the compiler produced warnings).  Instead check the exit code.
2020-11-08 14:41:46 +00:00
Jon Turney fb967562b0
Cygwin: Use absolute path to libltp includes
Use an absolute path to libltp includes, to allow for the fact that
we'll be compiling tests in a subdirectory.
2020-11-08 14:41:38 +00:00
Jon Turney e6248c2fd0
Cygiwn: Detect and use MinGW compilers for testsuite wrappers
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.
2020-11-08 14:41:28 +00:00
Jon Turney 20b5e6375c
Cygwin: Define target_builddir autoconf and Makefile variables
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)
2020-11-08 14:41:08 +00:00
Jon Turney 551df57fa0
Cygwin: Move adding libltp to VPATH after Makefile.common
Move adding libltp to the VPATH after Makefile.common, which sets VPATH.
2020-11-08 14:40:59 +00:00
Jon Turney 187281b711
Cygwin: Avoid 'Makefile.in seems to ignore the --datarootdir setting' warning
Avoid a 'Makefile.in seems to ignore the --datarootdir setting' warning
when configuring in testsuite directory.
2020-11-08 14:40:47 +00:00
Jon Turney 7b65f83c22
Cygwin: Add rule to testsuite Makefile to regenerate it when needed 2020-11-08 14:40:41 +00:00
Jon Turney a7cb126b14
Cygwin: Always configure in testsuite subdirectory
Doing this properly using AC_CONFIG_SUBDIRS is necessary to get the
correct paths in flags given to the compiler specified in CC/CXX.
2020-11-08 14:40:34 +00:00
Jon Turney 58ca21cf78
Cygwin: Add testsuite directory to autogen.sh
Also remove unneeded aclocal.m4 for an old aclocal version.
2020-11-08 14:40:26 +00:00
Ken Brown 26a5aff2a9 Cygwin: FIFO: update_my_handlers: fix handle leak 2020-11-06 08:16:45 -05:00
Jon Turney 5f3a301fd5
Cygwin: Drop passing '-c' compiler flag into gentls_offsets
That script appends a '-E', since we only use $(CC) to preprocess, and
thus adding '-c' is having no effect.
2020-11-02 16:49:03 +00:00
Jon Turney 22d79c79b5
Cygwin: Remove rules for building libcygwin_s.a
Untouched since added in 66a83f3e, and described as 'non-working'.
2020-11-02 16:49:02 +00:00
Jon Turney a5398eaecb
Cygwin: Remove Makefile contents conditional on PREPROCESS, which is never defined 2020-11-02 16:49:01 +00:00
Jon Turney f4bfaddb3c
Cygwin: Drop autoconf variable all_host
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.
2020-11-02 16:49:00 +00:00
Jon Turney 29817cc41e
Cygwin: Remove autoconf variable DLL_NAME
Remove autoconf variable DLL_NAME, which has a constant value which is
only used in one place.
2020-11-02 16:48:59 +00:00
Jon Turney d555072c94
Cygwin: Drop AC_SUBST(build_exeext)
The autoconf variable build_exeext isn't defined, and (since the doc
subdirectory doesn't build any executables) it's value isn't used.
2020-11-02 16:48:58 +00:00
Jon Turney 174268f4bb
Cygwin: Remove intro2man.stamp on clean 2020-11-02 16:48:57 +00:00
Jon Turney 9517e5f503
Revert "Cygwin: gendef generates sigfe.s and cygwin.def"
This reverts commit 74a164f1c1.

Shame we can't use '&:' for a grouped target here, since that requires
GNU make 4.3
2020-10-30 16:31:08 +00:00
Jon Turney 7fa743ca94
Cygwin: Restore setting CC and CXX Makefile variables
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.
2020-10-28 15:23:56 +00:00
Ken Brown 262de3ecf0 Cygwin: fix return value of sqrtl on negative infinity
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
2020-10-27 10:23:27 -04:00
Takashi Yano via Cygwin-patches 490d4862df Cygwin: pty: Disable ResizePseudoConsole() if stdout is redirected.
- 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.
2020-10-27 10:03:42 +01:00
Takashi Yano via Cygwin-patches 7b996f807e Cygwin: pty: Fix race condition in initialization of pseudo console.
- 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.
2020-10-26 10:04:12 +01:00
Ken Brown via Cygwin-patches 3752ab804b Cygwin: AF_INET and AF_LOCAL: recv_internal: fix MSG_WAITALL support
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.
2020-10-23 08:23:27 -04:00
Jon Turney 0c3c451ae3
Cygwin: Drop do-nothing install_target target 2020-10-21 17:11:15 +01:00
Jon Turney c50e0d8ba4
Cygwin: Drop do-nothing install_host target
Drop do-nothing install_host target, which is only used when not
cross-compiling.
2020-10-21 17:11:09 +01:00
Jon Turney 08f5cc2ef4
Cygwin: Remove nostdlib Makefile variable
It's used in one place, and it's value is unconditional.
2020-10-21 17:11:02 +01:00
Jon Turney 74a164f1c1
Cygwin: gendef generates sigfe.s and cygwin.def
Express that gendef generates sigfe.s and cygwin.def in a slightly less
nutty way.
2020-10-21 17:10:56 +01:00
Jon Turney b5bc608b32
Cygwin: Drop cygwin version.o from cygserver
The data it contains isn't referenced since 9e9bc3a4.
2020-10-21 17:10:50 +01:00
Jon Turney 161cd505e5
Cygwin: Remove lsaauth
Remove lsaauth, not built since 2741dd05.
2020-10-21 17:10:44 +01:00
Jon Turney 3662877f31
Cygwin: Use aclocal option --system-acdir rather than --acdir
In autogen.sh, use 'aclocal --system-acdir' rather than 'aclocal --acdir'.

'--acdir' was deprecated in automake 1.11 and removed in automake 1.13.
2020-10-18 14:55:15 +01:00
Jon Turney 78bfd7dbb9
Cygwin: Remove --with-windows-{libs,headers} 2020-10-18 14:55:14 +01:00
Jon Turney b55e3f1916
Cygwin: Remove ccwrap
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.
2020-10-18 14:55:13 +01:00
Jon Turney 5601d53640
Cygwin: Stop using c++wrap for MinGW-compiled utilities
Stop using c++wrap for MinGW-compiled utilities.

(Partially reverts 96079146)
2020-10-18 14:55:11 +01:00
Torbjörn SVENSSON via Newlib 7ed952000c libc/time: Move internal newlib tz-structs into own header
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>
2020-10-15 16:59:51 +02:00
Jon Turney 93216e2791
Cygwin: Remove unused doc/ug-info.xml
Remove doc/ug-info.xml, not used in any document.
2020-10-14 15:04:24 +01:00
Jon Turney e78a7f8f6e
Cygwin: Remove empty MT_SAFE and MT_SAFE_OBJECTS 2020-10-14 15:04:23 +01:00
Jon Turney 1996cb7e84
Cygwin: Remove autoconf variable INSTALL_LICENSE
Remove autoconf variable INSTALL_LICENSE, which has a constant value
which is only used once.
2020-10-14 15:04:22 +01:00
Jon Turney 66c76e8aff
Cygwin: Drop AC_SUBST(LIBSERVER)
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).
2020-10-14 15:04:21 +01:00
Jon Turney 177d15686d
Cygwin: Remove AC_ARG_PROGRAM/program_transform_name
Not done consistently, and probably never used.
2020-10-14 15:04:20 +01:00
Jon Turney b21158bc4e
Cygwin: Remove AC_PROG_MAKE_SET
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.
2020-10-14 15:04:19 +01:00
Jon Turney ad0f139c74
Cygwin: Drop STDINCFLAGS overrides
This used to turn off -nostdinc on a per-file basis, but has no effect
since 4c36016b57.
2020-10-14 15:04:18 +01:00
Jon Turney 08e7ee1912
Cygwin: Drop looking for w32api in winsup/w32api
Stop looking for w32api headers in the (no longer existent)
winsup/w32api directory (removed in commit 61746d6ae8).
2020-10-14 15:04:17 +01:00
Brian Inglis 3fd14da2c3 format_proc_cpuinfo: add enqcmd cpuinfo flag
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.
2020-10-13 18:14:02 +02:00
Ken Brown 2031b48c93 Cygwin: AF_UNIX: open_pipe: call recv_peer_info
If open_pipe is called with xchg_sock_info true, call recv_peer_info
in addition to send_sock_info.
2020-10-04 12:53:05 -04:00
Ken Brown 6748c6ecf8 Cygwin: AF_UNIX: listen_pipe: check for STATUS_SUCCESS
A successful connection can be indicated by STATUS_SUCCESS or
STATUS_PIPE_CONNECTED.  Previously we were checking only for the
latter.
2020-10-04 12:53:05 -04:00
Ken Brown 5930dca459 Cygwin: AF_UNIX: socket: set the O_RDWR flag 2020-10-04 12:53:05 -04:00
Ken Brown 0e29048956 Cygwin: always recognize AF_UNIX sockets as reparse points
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.
2020-10-04 12:53:05 -04:00
Ken Brown 0b4beaf46f Cygwin: fix handling of known reparse points that are not symlinks
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.
2020-10-04 12:53:05 -04:00
Ken Brown 4b4fffe0f2 Cygwin: AF_UNIX: use FILE_OPEN_REPARSE_POINT when needed
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.
2020-10-04 12:53:04 -04:00
Jon Turney c5bdf60ac4
Cygwin: avoid GCC 10 error with -Werror=narrowing
../../../../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.
2020-09-28 14:11:27 +01:00
Jon Turney 129c9844a6
Cygwin: avoid GCC 10 error with -Werror=narrowing
../../../../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.
2020-09-28 14:11:26 +01:00
Jon Turney 3bb579a43c
Cygwin: avoid GCC 10 error with -Werror=parentheses
../../../../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]
2020-09-28 14:11:25 +01:00
Ken Brown 6b6dd5fede Cygwin: check_reparse_point_target: update comment
Commit aa467e6e, "Cygwin: add AF_UNIX reparse points to path
handling", changed the return values of check_reparse_point_target.
Update the comment accordingly.
2020-09-26 16:44:44 -04:00
Ken Brown c1f7c4d1b6 Cygwin: winlean.h: remove most of the extended memory API
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.
2020-09-24 12:28:03 -04:00
Brian Inglis 749cbccc55 winsup/doc/faq-what.xml: FAQ 1.2 Windows versions supported
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
2020-09-18 07:52:24 -04:00
Brian Inglis 1732249529 fhandler_proc.cc(format_proc_cpuinfo): add tsxldtrk, sev_es flags
Add linux-next cpuinfo flags for Intel TSX suspend load address tracking
instructions and AMD Secure Encrypted Virtualization with Encrypted State.
2020-09-17 18:31:50 -04:00
Takashi Yano 2ed80d04f4 Cygwin: pty: Drop handling for UTF-7 in convert_mb_str().
- 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.
2020-09-11 20:14:33 +02:00
Jon Turney f4a1b6ae18
Cygwin: ldd: Also look for not found DLLs when exit status is non-zero
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.
2020-09-11 13:27:03 +01:00
Takashi Yano via Cygwin-patches 232fde0e76 Cygwin: pty: Prevent garbled output for existing non-cygwin apps.
- 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.
2020-09-11 14:09:10 +02:00
Corinna Vinschen 09738c3062 Cygwin: pty: setup new pty on opening the master, not in constructor
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>
2020-09-09 22:57:09 +02:00
Takashi Yano via Cygwin-patches fd3ad92f9e Cygwin: pty: Fix input charset for non-cygwin apps with disable_pcon.
- If the non-cygwin apps is executed under pseudo console disabled,
  multibyte input for the apps are garbled. This patch fixes the
  issue.
2020-09-09 21:35:46 +02:00
Takashi Yano via Cygwin-patches 91908fe000 Cygwin: pty: Revise convert_mb_str() function.
- 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.
2020-09-09 21:35:46 +02:00
Ken Brown 7de33047ec Cygwin: document last bug fix 2020-09-08 15:01:07 -04:00
Ken Brown 6775ac8cb5 Cygwin: path_conv::check: handle error from fhandler_process::exists
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.
2020-09-08 15:00:55 -04:00
Ken Brown 58cc67d653 Cygwin: format_process_fd: add directory check
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.
2020-09-08 14:58:18 -04:00
Corinna Vinschen eaed594d73 Cygwin: pty: move codepage evaluation to nlsfuncs.cc
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>
2020-09-08 10:36:04 +02:00
Corinna Vinschen 8d0ff0768f Cygwin: drop internal O_NOSYMLINK and O_DIROPEN flags
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>
2020-09-07 22:45:56 +02:00
David McFarland via Cygwin-patches 5d962bc718 Cygwin: create install dir for libs
This fixes a race in parallel installs.
2020-09-04 14:53:47 +02:00
Corinna Vinschen 7c4719f548 Cygwin: libpthread: Export C11 thread symbols from libpthread.a as well
...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>
2020-09-01 12:52:08 +02:00
Corinna Vinschen fc352c07ad Cygwin: mtx_init: drop glibc workaround
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>
2020-09-01 12:46:15 +02:00
Takashi Yano via Cygwin-patches 6871c8418d Cygwin: pty: Fix a bug in the code removing set window title sequence.
- Commit 4e08fe42c9 has a bug which
  may cause infinite loop in pty_master_fwd_thread(). This patch
  fixes the issue.
2020-08-31 16:25:11 +02:00
Takashi Yano via Cygwin-patches 4e08fe42c9 Cygwin: pty: Disable pseudo console if TERM does not have CSI6n.
- 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.
2020-08-31 12:07:09 +02:00
Jon Turney a30cd7a5b9
Cygwin: Remove waitloop argument from try_to_debug()
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.
2020-08-30 16:24:47 +01:00
Ken Brown 0416f68de1 Cygwin: sigproc.cc: add comment 2020-08-30 09:33:30 -04:00
Corinna Vinschen 6af1524aaa Cygwin: Add modfl fix to release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-08-30 14:27:43 +02:00
Martin Storsjö 023ddc4128 Cygwin: crt: Add "volatile" to all inline assembly snippets under math
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>
2020-08-30 14:27:43 +02:00
Liu Hao 0e6690a92c Cygwin: math/modfl.c: Fix segment faults in modfl().
Reference: https://sourceforge.net/p/mingw-w64/bugs/478/
Signed-off-by: Liu Hao <lh_mouse@126.com>
2020-08-30 14:27:43 +02:00
Corinna Vinschen ec9734dbb5 Cygwin: Add Cygwin 3.2 release info
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-08-30 14:27:43 +02:00
Corinna Vinschen 75a669790e Cygwin: Add C11 threads API
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>
2020-08-30 14:27:43 +02:00
Corinna Vinschen 5999c433bb Cygwin: make pthread_yield available for internal usage
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>
2020-08-30 14:27:43 +02:00
Corinna Vinschen 8b85b3c3ad Cygwin: pthread_yield: Add BSD visibility
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>
2020-08-30 14:27:43 +02:00
Corinna Vinschen b9ad0fbf28 Cygwin: pthreads: iterate over key destructors per POSIX
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>
2020-08-30 14:27:43 +02:00
Corinna Vinschen bf251d5a0b Cygwin: sigproc: Fix a thinko in array size
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>
2020-08-28 19:38:05 +02:00
Corinna Vinschen b05b0b78fa Cygwin: sigproc: Eliminate redundant copying of chld_procs
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>
2020-08-28 19:37:42 +02:00
Corinna Vinschen c6b45af544 Cygwin: sigproc: fix minor formatting issue
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-08-28 15:40:16 +02:00
Takashi Yano via Cygwin-patches c8b076a233 Cygwin: select: Fix a bug on closing pi->bye event.
- Close event handle pi->bye only if it was created.
  Addresses:
  https://cygwin.com/pipermail/cygwin-developers/2020-August/011948.html
2020-08-28 15:24:22 +02:00
Corinna Vinschen 7c963c7ba0 Cygwin: sigproc: Allow more child processes per process
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>
2020-08-28 15:22:58 +02:00
Corinna Vinschen 163daed37c Cygwin: drop PROC_DETACHED_CHILD flag
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>
2020-08-28 11:10:48 +02:00
Corinna Vinschen 558fa888e5 Cygwin: sigproc: drop __stdcall
Nothing to gain here

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-08-28 09:44:18 +02:00
Corinna Vinschen eb3e3e4738 Cygwin: sigproc: return int from remove_proc
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>
2020-08-28 09:44:18 +02:00
Corinna Vinschen 0a31ad6f4c Cygwin: fix up proc_subproc flags and matching pinfo methods
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>
2020-08-28 09:44:18 +02:00
Ken Brown 49a9ffdf4b Cygwin: fhandler_fifo::delete_client_handler: improve efficiency
Delete a client handler by swapping it with the last one in the list
instead of calling memmove.
2020-08-27 07:14:19 -04:00
Brian Inglis 573dda0cf2 winsup/doc/faq-api.xml(faq.api.timezone): explain time zone updates
based on material from tz@IANA.org mailing list sources
2020-08-27 10:53:58 +02:00
Takashi Yano via Cygwin-patches 69a2a8db58 Cygwin: console: Replace WriteConsoleA() with WriteConsoleW().
- To allow sending non-ASCII chars to console, all WriteConsoleA()
  are replaced by WriteConsoleW().
  Addresses:
  https://cygwin.com/pipermail/cygwin-patches/2020q3/010476.html
2020-08-27 10:51:31 +02:00
Brian Inglis ed97836149 winsup/doc/faq-api.xml, -programming.xml: change Win32 to Windows/API 2020-08-26 10:08:13 +02:00
Brian Inglis 6329d546dd winsup/doc/faq-setup.xml, faq-using.xml: update setup FAQ
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
2020-08-26 10:08:13 +02:00
Ken Brown c1f177d6a9 Cygwin: cwdstuff::get: clean up debug_printf output
Set errno = 0 at the beginning so that the debug_printf call at the
end doesn't report a nonzero errno left over from some other function
call.
2020-08-23 18:50:00 -04:00
Takashi Yano bb42852062 Cygwin: pty: Implement new pseudo console support.
- 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.html
      https://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.html
      https://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.
2020-08-22 13:43:49 +02:00
Corinna Vinschen b9261fa1d9 Cygwin: bump version to 3.2.0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-08-22 13:43:46 +02:00
Ken Brown a93a85a1ff Cygwin: strace: ignore GCC exceptions
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.
2020-08-20 10:48:48 -04:00
Ken Brown 14c0a4c67d Cygwin: add header defining GCC exception codes
Include it in exceptions.cc instead of defining the exception codes
there.
2020-08-20 10:46:23 -04:00
Ken Brown 74cf7dabcb Cygwin: main exception handler (64-bit): continue 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.html
  https://sourceware.org/pipermail/cygwin/2020-August/245897.html
2020-08-18 07:04:25 -04:00
Takashi Yano via Cygwin-patches 70d02aaca6 Cygwin: pty: Change the timing of set_locale() call again.
- 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.
2020-08-17 11:12:59 +02:00
Takashi Yano via Cygwin-patches 095972ce5b Cygwin: pty: Change the timing of setup_locale() call.
- 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.
2020-08-13 10:20:53 +02:00
Takashi Yano f14d123ac6 Cygwin: pty: Add a workaround for issue of starting a lot of mintty.
- 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.
2020-08-11 12:19:33 +02:00
Ken Brown 225d376b70 Cygwin: cygserver: build with -Wimplicit-fallthrough=5
Define the pseudo keyword 'fallthrough' in woutsup.h to support this.
2020-08-07 13:40:13 -04:00
Jon Turney 1be41b802a
Cygwin: Use documented QueryWorkingSetEx() in dumper
In dumper, use the documented QueryWorkingSetEx(), rather than the
undocumented NtQueryVirtualMemory() with MemoryWorkingSetExInformation.
2020-08-07 15:08:30 +01:00
Corinna Vinschen c8dc3fa0ba Cygwin: cygserver: build with -Wimplicit-fallthrough=4 -Werror
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-08-07 15:09:56 +02:00
Corinna Vinschen acfed1364a Cygwin: utils: build with -Wimplicit-fallthrough=4 -Werror
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-08-07 15:09:56 +02:00
Corinna Vinschen e7fca6f867 Cygwin: utils: convert usage() to proper noreturn function throughout
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-08-07 15:09:56 +02:00
Corinna Vinschen 9beb7b9771 Cygwin: utils: cygcheck: avoid GCC warning concatenating strings
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-08-07 15:09:48 +02:00
Corinna Vinschen 238c2b14ca Cygwin: utils: refresh tzmap
- update path to Unicode windowsZones.xml file
- drop Windows XP considerations
- regenerate tzmap.h

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-08-07 15:09:39 +02:00
Corinna Vinschen 50ad198085 Cygwin: Add 'fallthrough' pseudo keyword for switch/case use
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.
2020-08-05 21:58:22 +02:00
Corinna Vinschen 5898a044c3 Cygwin: Fix missing breaks in switch statement
Two switch statements in sysconf() and
fhandler_fifo::take_ownership were missing breaks.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-08-05 21:46:53 +02:00
Ken Brown 4f5b52ffe7 Cygwin: FIFO: add a third pass to raw_read
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.
2020-08-04 08:15:19 -04:00
Ken Brown 55b93b27d6 Cygwin: FIFO: fix indentation 2020-08-04 08:15:19 -04:00
Ken Brown 0fda55133a Cygwin: FIFO: synchronize the fifo_reader and fifosel threads
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.
2020-08-04 08:15:19 -04:00
Ken Brown 251624a352 Cygwin: FIFO: don't read from pipes that are closing
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.
2020-08-04 08:15:19 -04:00
Ken Brown 289af73a89 Cygwin: FIFO: reorganize some fifo_client_handler methods
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().
2020-08-04 08:15:19 -04:00
Ken Brown 6ed067a0ae Cygwin: FIFO: add a timeout to take_ownership
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.
2020-08-04 08:15:19 -04:00
Ken Brown 6acce025d0 Cygwin: FIFO: fix timing issue with owner change
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.
2020-08-04 08:02:07 -04:00
Ken Brown e319fd0e62 Cygwin: FIFO: lock fixes
Add some missing locks and remove one extra unlock.  Clarify for some
functions whether caller or callee acquires lock, and add appropriate
comments.
2020-08-04 07:57:45 -04:00
Brian Inglis cb7fba2f3e fhandler_proc.cc(format_proc_cpuinfo): use _small_sprintf %X for microcode
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
2020-08-04 10:10:40 +02:00
Brian Inglis 4ecc804d54 fhandler_proc.cc(format_proc_cpuinfo): add SERIALIZE instruction flag
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
2020-08-04 10:10:40 +02:00
Corinna Vinschen 3fbfcd11fb Cygwin: posix_spawn: add Cygwin-specific code fixing process synchronisation
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>
2020-08-03 12:41:44 +02:00
Jon Turney c222c1b294
Cygwin: Speed up dumper
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).
2020-07-31 14:01:02 +01:00
Jon Turney 0d4d2d38fb
Cygwin: Remove synchronization event from dumper
The use of the 'cygwin_error_start_event' for synchronization with
dumper was removed from the DLL in commit 8abeff1e (April 2001).
2020-07-31 14:01:01 +01:00
Jon Turney a5218ff772
Cygwin: Add --nokill dumper option
Add --nokill option to dumper, for compatibility with minidumper, and to
assist with testing.
2020-07-31 14:01:00 +01:00
Jon Turney 7b1416c3ab
Cygwin: Decorate NtQueryVirtualMemory() to fix 32-bit build
Decorate NtQueryVirtualMemory() with NTAPI (for stdcall) to fix 32-bit
build.

Reported-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2020-07-28 13:27:31 +01:00
Brian Inglis 0947efb859 fhandler_proc.cc(format_proc_cpuinfo): add flags and TLB size
update to Linux-next 5.8 order fields and flags:
add amd_dcm, arch_lbr, arch_perfmon, art, cpuid, extd_apicid, ibpb,
ibrs, ibrs_enhanced, nonstop_tsc_s3, nopl, rep_good, ring3mwait, ssbd,
stibp, tsc_known_freq, tsc_reliable, xtopology flags;
add TLB size line;
add ftuprint macro for feature test unconditional flag print;
add commented out flags requiring CR or MSR access in print order with
comment explaining issue;
make cpuid leaf numbers consistent 8 hex digits for searching
2020-07-24 10:10:47 +02:00
Corinna Vinschen 1c803a6d88 Cygwin: mmap: Remove AT_ROUND_TO_PAGE workaround
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>
2020-07-22 10:51:27 +02:00
Ken Brown eeb2dc1537 Cygwin: mmap: document recent bugfix 2020-07-21 17:57:37 -04:00
Jon Turney b245014abd
Cygwin: Use MEMORY_WORKING_SET_EX_INFORMATION in dumper
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)
2020-07-21 15:19:43 +01:00
Jon Turney 35227fec97
Cygwin: Don't dump non-writable image regions
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)
2020-07-21 15:19:42 +01:00
Jon Turney 44103c0621
Cygwin: Drop excluded regions list from dumper
Drop excluded regions, now it's always empty
2020-07-21 15:19:42 +01:00
Jon Turney 0302c69164
Cygwin: Remove reading of PE for section flags from dumper 2020-07-21 15:19:40 +01:00
Jon Turney b40983eda1
Cygwin: Show details of all memory regions in dumper debug output 2020-07-21 15:19:39 +01:00
Corinna Vinschen 119e8d5c11 Cygwin: mmap: constify pagesize throughout
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-07-20 18:08:33 +02:00
Ken Brown d8a8d2ce59 Cygwin: mmap: fix mapping beyond EOF on 64 bit
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.
2020-07-20 11:56:29 -04:00
Takashi Yano via Cygwin-patches e0a53d6625 Cygwin: pty: Fix a bug on redirecting something to /dev/pty*.
- 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.
2020-07-20 10:06:37 +02:00
Corinna Vinschen 2aa3eb7503 Cygwin: sockets: Rearrange check for connect failure
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-07-20 09:49:34 +02:00
Ken Brown 53b7116705 Cygwin: FIFO: document recent fixes 2020-07-16 16:21:03 -04:00
Ken Brown ac371ee1ba Cygwin: FIFO: update commentary 2020-07-16 15:59:53 -04:00
Ken Brown f56dc33579 Cygwin: FIFO: clean up
Remove the fhandler_fifo::get_me method, which is no longer used.
Make the methods get_owner, set_owner, owner_lock, and owner_unlock
private.
2020-07-16 15:59:53 -04:00
Ken Brown 4eaa55463d Cygwin: FIFO: allow take_ownership to be interrupted
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.
2020-07-16 15:59:53 -04:00
Ken Brown a4dc0eb15c Cygwin: fhandler_fifo::take_ownership: don't set event unnecessarily
Don't set update_needed_evt if there's currently no owner.  This will
cause unnecessary churn once I'm the owner and am listening for
connections.
2020-07-16 15:59:53 -04:00
Ken Brown 4f25d82cb1 Cygwin: FIFO: add missing lock 2020-07-16 15:59:53 -04:00
Ken Brown d3a01b7ec2 Cygwin: FIFO: make certain errors non-fatal
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.
2020-07-16 15:59:53 -04:00
Ken Brown b0418138fe Cygwin: FIFO: fix indentation 2020-07-16 15:59:53 -04:00
Ken Brown 6b8a829496 Cygwin: FIFO: improve taking ownership in fifo_reader_thread
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.
2020-07-16 15:59:53 -04:00
Ken Brown 1c0cf5f4f9 Cygwin: FIFO: reduce I/O interleaving
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.
2020-07-16 15:59:53 -04:00
Ken Brown e10425e1e3 Cygwin: fhandler_fifo::hit_eof: improve reliability
Use the writer count introduced in the previous commit to help detect
EOF.  Drop the maybe_eof method, which is no longer needed.
2020-07-16 15:59:53 -04:00
Ken Brown 8ca713d70a Cygwin: FIFO: keep a writer count in shared memory
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.
2020-07-16 15:59:53 -04:00
Ken Brown da9fea0759 Cygwin: FIFO: fix problems finding new owner
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.
2020-07-16 15:59:53 -04:00
Corinna Vinschen 52ad92e1b6 Cygwin: document previous poll/select patch
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-07-16 10:58:40 +02:00
Marc Hoersken aa86784937 Cygwin: make sure failed sockets always signal writability
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
2020-07-16 10:50:51 +02:00
Brian Inglis b1237e64fd Cygwin: FAQ 1.6: Update "Who's behind the project?"
winsup/doc/faq-what.xml: remove Red Hat, Net, Win32 references and clean up
2020-07-13 17:19:50 +02:00
Brian Inglis 906ce51747 Cygwin: FAQ 1.5: Clarify "What version is this"
Patch to:
https://sourceware.org/git/?p=newlib-cygwin.git;f=winsup/doc/faq-what.xml;a=blob
as a result of thread:
	https://cygwin.com/pipermail/cygwin/2020-July/245442.html
and comments:
	https://cygwin.com/pipermail/cygwin-patches/2020q3/010331.html
Relate Cygwin DLL to Unix kernel,
add required options to command examples,
differentiate Unix and Cygwin commands;
mention that the cygwin package contains the DLL,
replace setup.exe reference by Cygwin Setup program wording.
2020-07-13 17:19:01 +02:00
Jon Turney 2a0e84c8db
Cygwin: Make dumper scan more than first 4GB of VM on x86_64
It's unclear that we need an end address here at all, or can just rely
on VirtualQueryEx() failing when we reach the end of memory regions.
2020-07-12 15:09:41 +01:00
Jon Turney 7dd1b08836
Cygwin: Add a new win32_pstatus data type for modules on x86_64
Also take a bit more care with sizes in other data types to ensure they
are the same on x86 and x86_64.

Add some explanatory comments.
2020-07-12 15:09:40 +01:00
Jon Turney 38f8860146
Cygwin: Update ELF target used by dumper on x86_64
Like [1], but actually making the effort to be 'usable' and 'tested'.

[1] https://cygwin.com/pipermail/cygwin/2019-October/242815.html
2020-07-12 15:09:39 +01:00
Jon Turney f2a285bd4f
Cygwin: Slightly improve error_start documentation 2020-07-12 15:09:38 +01:00
David Allsopp acfc63b0cf Fix invalid acl_entry_t on 32-bit Cygwin
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>
2020-07-10 10:29:47 +02:00
Corinna Vinschen 462fcdb67f Cygwin: convert sys_wcstombs/sys_mbstowcs wrapper to inline functions
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>
2020-07-10 10:29:33 +02:00
Corinna Vinschen b3af1d5aa3 Cygwin: Bump DLL version to 3.1.7
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-07-09 10:14:23 +02:00
Corinna Vinschen 4b94604c79 Cygwin: add microcode patch to release messages
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-07-09 09:55:34 +02:00
Brian Inglis 7b2c7fca04 format_proc_cpuinfo: fix microcode revision shift direction 2020-07-09 09:49:54 +02:00
Brian Inglis 54bb6589c3 fhandler_proc.cc(format_proc_cpuinfo): add microcode registry lookup values
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
2020-07-09 09:49:54 +02:00
Corinna Vinschen bb96bd03b0 Cygwin: fix buffer overrun in cygwin_strcasecmp
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>
2020-07-06 13:17:53 +02:00
Corinna Vinschen 5266248285 Cygwin: add new IPPROTO_TCP options to release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-07-01 21:33:15 +02:00
Corinna Vinschen ee22924137 Cygwin: tcp: Support TCP_QUICKACK
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-07-01 21:26:59 +02:00
Corinna Vinschen ffb07b41bc Cygwin: tcp: Support TCP_USER_TIMEOUT
Use TCP_MAXRTMS on newer systems, TCP_MAXRT on older systems.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-07-01 20:30:52 +02:00
Corinna Vinschen 8ccffddc91 Cygwin: tcp: Support TCP_KEEPIDLE, TCP_KEEPCNT, TCP_KEEPINTVL
Use WSAIoctl(SIO_KEEPALIVE_VALS) on older systems.

Make sure that keep-alive timeout is equivalent to
TCP_KEEPIDLE + TCP_KEEPCNT * TCP_KEEPINTVL on older systems,
even with TCP_KEEPCNT being a fixed value on those systems.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-07-01 20:30:52 +02:00
Corinna Vinschen 0feb77c260 Cygwin: tcp: Support TCP_FASTOPEN
TCP_FASTOPEN is supported since W10 1607.  Fake otherwise.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-07-01 20:30:40 +02:00
Corinna Vinschen e037192b50 Cygwin: tcp: fix IPPROTO_TCP option handling
- Drop definitions from <cygwin/sockets.h>
- Drop options only available on BSD
- Fix value of TCP_MAXSEG.  It was still defined as the BSD value
  while WinSock uses another value
- Handle the fact that TCP_MAXSEG is a R/O value in WinSock

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-07-01 09:25:54 +02:00
Takashi Yano via Cygwin-patches c11b0343c0 Cygwin: pty, termios: Unify thoughts of read ahead beffer handling.
- Return value of eat_readahead() is redefined. The return values
  of fhandler_termios::eat_readahead() and fhandler_pty_slave::
  eat_readahead() were little bit different. This patch unifies
  them to number of bytes eaten by eat_readahead().
- Considerration for raixget() is added to fhandler_pty_master::
  accept_input() code.
- Transfering contents of read ahead buffer in
  fhandler_pty_master::transfer_input_to_pcon() is removed since
  it is not necessary.
- fhandler_pty_slave::eat_readahead() ckecks EOL only when ICANON
  is set.
- Guard for _POSIX_VDISABLE is added in checking EOL.
2020-07-01 09:25:54 +02:00
Takashi Yano via Cygwin-patches 8121b606e8 Cygwin: pty: Discard CSI > Pm m sequence from native windows apps.
- If vim is started from WSL (Ubuntu) which is executed in pseudo
  console in mintty, shift key and ctrl key do not work. Though
  this issue is similar to the issue resolved by commit
  4527541ec6, that commit is not
  effective for this issue. This patch fixes the issue by discarding
  "CSI > Pm m" in fhandler_pty_master::pty_master_fwd_thread().
2020-07-01 09:25:54 +02:00
Takashi Yano via Cygwin-patches 8014dc7099 Cygwin: pty: Fix screen distortion after less for native apps again.
- Commit c4b060e3fe seems to be not
  enough. Moreover, it does not work as expected at all in Win10
  1809. This patch essentially reverts that commit and add another
  fix. After all, the cause of the problem was a race issue in
  switch_to_pcon_out flag. That is, this flag is set when native
  app starts, however, it is delayed by wait_pcon_fwd(). Since the
  flag is not set yet when less starts, the data which should go
  into the output_handle accidentally goes into output_handle_cyg.
  This patch fixes the problem more essentially for the cause of
  the problem than previous one.
2020-06-05 21:34:52 -04:00
Corinna Vinschen 8873f073c8 Bump version to 3.1.6
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-06-01 10:48:11 +02:00
Takashi Yano via Cygwin-patches c4b060e3fe Cygwin: pty: Fix screen distortion after using less for native apps.
- If the output of non-cygwin apps is browsed using less, screen is
  ocasionally distorted after less exits. This frequently happens
  if cmd.exe is executed after less. This patch fixes the issue.
2020-06-01 10:13:57 +02:00
Takashi Yano via Cygwin-patches d212bdc400 Cygwin: pty: Revise the code which prevents undesired window title.
- In current pty, the window title can not be set from non-cygwin
  program due to the code which prevents overwriting the window
  title to "cygwin-console-helper.exe" in fhandler_pty_master::pty_
  master_fwd_thread(). This patch fixes the issue.
2020-05-31 10:33:55 +02:00
Takashi Yano via Cygwin-patches ac1f63ef28 Cygwin: pty: Clean up fhandler_pty_master::pty_master_fwd_thread().
- Remove the code which is not necessary anymore.
2020-05-31 10:33:55 +02:00
Takashi Yano via Cygwin-patches 4527541ec6 Cygwin: console: Discard some unsupported escape sequences.
- If the cygwin vim is started from a non-cygwin process which is
  executed in pseudo console, shift key and ctrl key do not work.
  In this case, vim is executed under /dev/cons*. If vim outputs
  escape sequence which is not supported by pseudo console, the
  escape sequence is leaked into the parent pty. This causes
  unexpected results. This patch fixes the issue by discarding
  "CSI > Pm m". "OSC 10;? BEL/ST" and "OSC 11;? BEL/ST" are
  discarded as well.
2020-05-31 10:33:55 +02:00
Takashi Yano via Cygwin-patches 0f7193f4fb Cygwin: pty: Prevent garbage remained in read ahead buffer.
- After commit 29431fcb5b, the issue
  reported in https://cygwin.com/pipermail/cygwin/2020-May/245057.html
  occurs. This is caused by the following mechanism. Cygwin less
  called from non-cygwin git is executed under /dev/cons* rather
  than /dev/pty* because parent git process only inherits pseudo
  console handle. Therefore, less sets ICANON flag for /dev/cons*
  rather than original /dev/pty*. When pty is switched to non-cygwin
  git process, line_edit() is used in fhandler_pty_master::write()
  only to set input_available_event and read ahead buffer is supposed
  to be flushed in accept_input(). However, ICANON flag is not set
  for /dev/pty*, so accept_input() is not called unless newline
  is entered. As a result, the input data remains in the read ahead
  buffer. This patch fixes the issue.
2020-05-31 10:33:55 +02:00
Corinna Vinschen d6242d8733 Cygwin: update C++ dialect to gnu++14
Disable -std option since gnu++14 is default anyway, but keep
it available as comment.

Update dynamic exception specifications deprecated with
C++11 to C++11-introduced noexcept expression.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-05-30 19:41:18 +02:00
Takashi Yano via Cygwin-patches 0c5aab9c99 Cygwin: console: Make cursor keys work in vim under ConEmu.
- After commit 774b8996d1, cursor
  keys do not work in vim under ConEmu without cygwin-connector.
  This patch fixes the issue.
2020-05-30 17:05:17 +02:00
Ken Brown 41ae84e6dc Cygwin: stat: fix st_mode of fifos again
This partially reverts commit
f36262d56a.  That commit incorrectly
made the st_mode of a fifo reflect the Windows permissions of the disk
file underlying the fifo.
2020-05-28 13:34:19 -04:00
Takashi Yano via Cygwin-patches b5089f339a Cygwin: pty: Prevent meaningless ResizePseudoConsole() calls.
- This patch prevents to call ResizePseudoConsole() unless the pty
  is resized.
2020-05-28 16:44:36 +02:00
Takashi Yano via Cygwin-patches 25987b2c2a Cygwin: pty: Fix a bug in free_attached_console().
- After commit 7659ff0f5a, nohup does
  not work as expected. This patch fixes the issue.

  Addresses:
  https://cygwin.com/pipermail/cygwin-developers/2020-May/011885.html
2020-05-28 09:25:49 +02:00
Corinna Vinschen 50d7dcaa0b Cygwin: FAQ: fix Cygwin build requirements
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-05-26 19:15:37 +02:00
Corinna Vinschen 4914c426c7 Cygwin: drop useless comment
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-05-26 10:22:41 +02:00
Corinna Vinschen 36b8811c3e Cygwin: add missing files to 'clean' build rule
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-05-26 10:19:35 +02:00
Corinna Vinschen 4d5efe1e1d Cygwin: revamp localtime.o build rule
Rename localtime.c.patched to localtime.patched.c to keep the correct
language suffix.

Create localtime.patched.c in the build dir rather than in the source
dir.  Decouple the build rule for creating localtime.patched.c from
the rule to build localtime.o, so we don't have to rebuild the patched
source file all the time.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-05-26 10:06:49 +02:00
Corinna Vinschen 49a843b407 Cygwin: convert localtime_wrapper.c to plain C source
That also requires a small tweak to localtime.c.patch, otherwise
GCC complains about the position of the 'trydefrules' label.
Also, simplify includes.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-05-26 09:56:57 +02:00
Corinna Vinschen 57625ac256 Cygwin: rename localtime.cc to localtime_wrapper.c
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-05-25 13:46:24 +02:00
Corinna Vinschen 2ce569ec92 Cygwin: move localtime.o build rule to end of file
otherwise a simple `make' in the cygwin dir won't build
the DLL anymore.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-05-25 13:45:17 +02:00
Mark Geisert 63ff2b84ff Cygwin: tzcode resync: details
Add tz_posixrules.h with data generated from most recent Cygwin tzdata
package.  Establish localtime.cc as primarily a wrapper around a patched
copy of localtime.c.  See README for more information.
2020-05-25 13:32:49 +02:00
Mark Geisert 2452e0b806 Cygwin: tzcode resync: imports
Import most recent NetBSD localtime.c, private.h, and tzfile.h.  An
empty namespace.h suffices for Cygwin.
2020-05-25 13:32:49 +02:00
Mark Geisert c66f16b2ff Cygwin: tzcode resync: basics
Modifies winsup/cygwin/Makefile.in to build localtime.o from items in
new winsup/cygwin/tzcode subdirectory.  Compiler option "-fpermissive"
is used to accept warnings about missing casts on the return values of
malloc() calls.  This patch also removes existing localtime.cc and
tz_posixrules.h from winsup/cygwin as they are superseded by the
subsequent patches in this set.
2020-05-25 13:32:49 +02:00
Corinna Vinschen 5489240c1b Cygwin: fix declaration of __small_{v}sprintf
Both functions are declared as extern "C" functions in
sys/smallprint.h, but as C++ funcs in winsup.h and in the
source itself.

Add extern "C to definitions, remove declarations in winsup.h
and include sys/smallprint.h instead.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-05-25 13:32:49 +02:00
Takashi Yano via Cygwin-patches 8d7a5b39d2 Cygwin: pty: Stop counting number of slaves attached to pseudo console.
- The number of slaves attached to pseudo console is used only for
  triggering redraw screen. Counting was not only needless, but also
  did not work as expected. This patch removes the code for counting.
2020-05-25 11:01:28 +02:00
Takashi Yano via Cygwin-patches c26e08095d Cygwin: pty: Revise code to make system_printf() work after close.
- After commit 0365031ce1, the issue
  https://cygwin.com/pipermail/cygwin-patches/2020q2/010259.html
  occurs. This patch fixes the issue.
2020-05-25 10:51:54 +02:00
Ken Brown bf07202e16 Cygwin: FIFO: add missing unlock
There was a missing call to reader_opening_unlock on one of the error
exits in fhandler_fifo::open.
2020-05-22 10:30:54 -04:00
Ken Brown fe937e21ad Cygwin: FIFO: Revert "take ownership on exec"
This reverts commit 39a9cd9465.

There is no need to explicitly take ownership in fixup_after_exec; if
ownership transfer is needed, it will be taken care of by
fhandler_fifo::close when the parent closes.  Moreover, closing the
parent's fifo_reader_thread can cause problems, such as the one
reported here:

  https://cygwin.com/pipermail/cygwin-patches/2020q2/010235.html
2020-05-22 10:30:54 -04:00
Takashi Yano via Cygwin-patches 0365031ce1 Cygwin: pty: Make system_printf() work after closing pty slave.
- Current pty cannot show system_printf() output after closing pty
  slave. This patch fixes the issue.
2020-05-19 15:28:21 +02:00
Takashi Yano via Cygwin-patches 7659ff0f5a Cygwin: pty: Call FreeConsole() only if attached to current pty.
- After commit 071b8e0cbd, the problem
  reported in https://cygwin.com/pipermail/cygwin/2020-May/244873.html
  occurs. This is due to freeing console device accidentally rather
  than pseudo console. This patch makes sure to call FreeConsole()
  only if the process is attached to the pseudo console of the current
  pty.
2020-05-19 15:27:31 +02:00
Takashi Yano via Cygwin-patches 5f5810e01c Cygwin: termios: Set ECHOE, ECHOK, ECHOCTL and ECHOKE by default.
- Backspace key does not work correctly in linux session opend by
  ssh from cygwin console if the shell is bash. This is due to lack
  of these flags.

  Addresses: https://cygwin.com/pipermail/cygwin/2020-May/244837.html.
2020-05-19 12:05:02 +02:00
David Macek via Cygwin-patches 6867660301 cygwin: doc: Add keywords for ACE order issues
Windows Explorer shows a warning with Cygwin-created DACLs, but putting
the text of the warning into Google doesn't lead to the relevant Cygwin
docs.  Let's copy the warning text into the docs in the hopes of helping
confused users.  Most of the credit for the wording belongs to Yaakov
Selkowitz.

Latest inquiry: <https://cygwin.com/pipermail/cygwin/2020-May/244814.html>

Signed-off-by: David Macek <david.macek.0@gmail.com>
2020-05-19 11:42:02 +02:00
Ken Brown e637d53617 Cygwin: FIFO: improve the interruptibility of raw_read
During a blocking read, we sleep for 1 ms after each iteration through
the connected writers.  Currently we do this by calling Sleep (1).
Remove this call to Sleep and instead change the timeout in the
cygwait call from 0 to 1, so that raw_read can be interrupted while
sleeping.
2020-05-11 09:52:23 -04:00
Ken Brown 1f27345947 Cygwin: FIFO: code simplification
There are currently three functions that call NtQueryInformationFile
to determine the state of a pipe instance.  Do this only once, in a
new fifo_client_handler::set_state () function, and call that when
state information is needed.

Remove the fifo_client_handler methods pipe_state and get_state, which
are no longer needed.

Make fhandler_fifo::get_fc_handler return a reference, for use in
select.cc:peek_fifo.

Make other small changes to ensure that this commit doesn't change any
decisions based on the state of a fifo_client_handler.

The tricky part is interpreting FILE_PIPE_CLOSING_STATE, which we
translate to fc_closing.  Our current interpretation, which is not
changing as a result of this commit, is that the writer at the other
end of the pipe instance is viewed as still connected from the point
of view of raw_read and determining EOF.

But it is not viewed as still connected if we are deciding whether to
unblock a new reader that is trying to open.
2020-05-11 09:52:16 -04:00
Corinna Vinschen 2125ca8a69 Cygwin: fifo: fix type of fifo_reader_id_t operators
fifo_reader_id_t::operator == and != have been defined without type
accidentally.  For some weird reason, only x86 gcc complains about
this problem, not x86_64 gcc.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-05-08 20:00:24 +02:00
Corinna Vinschen e6ddeca1d3 Cygwin: add pseudo console patch to release text
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-05-08 19:42:12 +02:00
Ken Brown 84d446734f Document recent FIFO changes 2020-05-08 07:42:14 -04:00
Ken Brown 98dfadec3a Cygwin: FIFO: update commentary
The beginning of fhandler_fifo.cc contains a long comment giving an
overview of the FIFO implementation.  This is now updated to describe
the support for multiple readers.
2020-05-08 06:45:24 -04:00
Ken Brown 4811889e0c Cygwin: FIFO: support opening multiple readers
Although we can have multiple readers open because of dup/fork/exec,
the current code does not support multiple readers opening a FIFO by
explicitly calling 'open'.

The main complication in supporting this is that when a blocking
reader tries to open and there's already one open, it has to check
whether there any writers open.  It can't rely on the write_ready
event, whose state hasn't changed since the first writer opened.

To fix this, add two new named events, check_write_ready_evt and
write_ready_ok_evt, and a new method, check_write_ready().

The first event signals the owner's reader thread to call
check_write_ready(), which polls the fc_handler list to check for
connected writers.  If it finds none, it checks to see if there's a
writer in the process and then sets/resets write_ready appropriately.

When check_write_ready() finishes it sets write_ready_ok_evt to signal
the reader that write_ready has been updated.

The polling is done via fifo_client_handler::pipe_state().  As long as
it's calling that function anyway, check_write_ready() updates the
state of each handler.

Also add a new lock to prevent a race if two readers are trying to
open simultaneously.
2020-05-08 06:45:24 -04:00
Ken Brown bf66a56cca Cygwin: FIFO: allow any reader to take ownership
Add a take_ownership method, used by raw_read and select.cc:peek_fifo.
It wakes up all fifo_reader_threads and allows the caller to become
owner.  The work is done by the fifo_reader_threads.

For synchronization we introduce several new fhandler_fifo data
members and methods:

- update_needed_evt signals the current owner to stop listening for
  writer connections and update its fc_handler list.

- shared_fc_handler() gets and sets the status of the fc_handler
  update process.

- get_pending_owner() and set_pending_owner() get and set the reader
  that is requesting ownership.

Finally, a new 'reading_lock' prevents two readers from trying to take
ownership simultaneously.
2020-05-08 06:45:24 -04:00
Ken Brown f35dfff3de Cygwin: FIFO: find a new owner when closing
If the owning reader is closing, wait for another reader (if there is
one) to take ownership before closing the owner's pipe handles.

To synchronize the ownership transfer, add events owner_needed_evt and
owner_found_evt, and add methods owner_needed and owner_found to
set/reset them.

Modify the fifo_reader_thread function to wake up all non-owners when
a new owner is needed.

Make a cosmetic change in close so that fhandler_base::close is called
only if we have a write handle.  This prevents strace output from
being littered with statements that the null handle is being closed.
2020-05-08 06:45:24 -04:00
Ken Brown 39a9cd9465 Cygwin: FIFO: take ownership on exec
If fixup_after_exec is called on a non-close-on-exec reader whose
parent is the owner, transfer ownership to the child.  Otherwise the
parent's pipe handles will be closed before any other reader can
duplicate them.

To help with this, make the cancel_evt and thr_sync_evt handles
inheritable, so that the child can terminate the parent's
fifo_reader_thread (and the parent will update the shared fc_handler
list).

Add an optional argument 'from_exec' to update_my_handlers to simplify
its use in this case; no handle duplication is required.
2020-05-08 06:45:20 -04:00
Ken Brown d9918451e2 Cygwin: FIFO: add a shared fifo_client_handler list
This is in a new shared memory section.  We will use it for temporary
storage of the owner's fc_handler list when we need to change owner.
The new owner can then duplicate the pipe handles from that list
before taking ownership.

Add several shared data members and methods that are needed for the
duplication process

Add methods update_my_handlers and update_shared_handlers that carry
out the duplication.

Allow the shared list to grow dynamically, up to a point.  Do this by
initially reserving a block of memory (currently 100 pages) and only
committing pages as needed.

Add methods create_shared_fc_handler, reopen_shared_fc_handler, and
remap_shared_fc_handler to create the new shared memory section,
reopen it, and commit new pages.  The first is called in open, the
second is called in dup/fork/exec, and the third is called in
update_shared_handlers if more shared memory is needed.

Modify the fifo_reader_thread function to call update_my_handlers when
it finds that there is no owner.  Also make it call
update_shared_handlers when the owner's thread terminates, so that the
new owner will have an accurate shared fc_handler list from which to
duplicate.

For convenience, add new methods cleanup_handlers and
close_all_handlers.  And add an optional arg to add_client_handler
that allows it to create a new fifo_client_handler without creating a
new pipe instance.
2020-05-08 06:36:31 -04:00
Ken Brown c76ded2ca0 Cygwin: FIFO: allow fc_handler list to grow dynamically
Make fc_handler a pointer to malloc'd memory instead of a fixed-size
array.  The size is now a new data member 'shandlers'.  Call realloc
in add_client_handler if we need to grow the array.

free fc_handler in close.  As long as we're touching that code, also
remove an unneeded lock.
2020-05-08 06:32:00 -04:00
Ken Brown 606baf5566 Cygwin: FIFO: designate one reader as owner
Among all the open readers of a FIFO, one is declared to be the owner.
This is the only reader that listens for client connections, and it is
the only one that has an accurate fc_handler list.

Add shared data and methods for getting and setting the owner, as well
as a lock to prevent more than one reader from accessing these data
simultaneously.

Modify the fifo_reader_thread so that it checks the owner at the
beginning of its loop.  If there is no owner, it takes ownership.  If
there is an owner but it is a different reader, the thread just waits
to be canceled.  Otherwise, it listens for client connections as
before.

Remove the 'first' argument from create_pipe_instance.  It is not
needed, and it may be confusing in the future since only the owner
knows whether a pipe instance is the first.

When opening a reader, don't return until the fifo_reader_thread has
time to set an owner.

If the owner closes, indicate that there is no longer an owner.

Clear the child's fc_handler list in dup, and don't bother duplicating
the handles.  The child never starts out as owner, so it can't use
those handles.

Do the same thing in fixup_after_fork in the close-on-exec case.  In
the non-close-on-exec case, the child inherits an fc_handler list that
it can't use, but we can just leave it alone; the handles will be
closed when the child is closed.
2020-05-08 06:32:00 -04:00
Ken Brown 16e7c10578 Cygwin: FIFO: introduce a new type, fifo_reader_id_t
This uniquely identifies an fhandler_fifo open for reading in any
process.

Add a new data member 'me' of this type, which is set in open, dup,
fork, and exec.
2020-05-08 06:32:00 -04:00
Ken Brown 365818a4a5 Cygwin: FIFO: keep track of the number of readers
Add data and methods to the shared memory that keep track of the
number of open readers.

Increment this number in open, dup, fork, and exec.  Decrement it in
close.  Reset read_ready if there are no readers left.
2020-05-08 06:32:00 -04:00
Ken Brown 878eb22462 Cygwin: FIFO: add shared memory
Even though we currently allow a FIFO to be opened for reading only
once, we can still have more than one reader open because of dup and
fork.  Add a named shared memory section accessible to all readers of
a given FIFO.  In future commits we will add information needed by all
readers to this section

Add a class fifo_shmem_t that lets us access this information.

Add a method create_shmem that is called when a reader opens, and add
a method reopen_shmem that is called by dup, fork, and exec.  (Each
new reader needs its own view of the shared memory.)
2020-05-08 06:32:00 -04:00
Ken Brown 71726ba70b Cygwin: FIFO: use a cygthread instead of a homemade thread
This will simplify future work.

Rename the thread from "listen_client_thread" to "fifo_reader_thread"
because it will be used for more than just listening.

Remove the fixup_before stuff, which won't be needed after future
changes to fixup_after_fork and fixup_after_exec.
2020-05-08 06:32:00 -04:00
Ken Brown 9ee8fdf2b3 Cygwin: FIFO: make opening a writer more robust
- Make read_ready a manual-reset event.

- Signal read_ready in open instead of in the listen_client_thread.

- Don't reset read_ready when the listen_client thread terminates;
  instead do it in close().

- Rearrange open and change its error handling.

- Add a wait_open_pipe method that waits for a pipe instance to be
  available and then calls open_pipe.  Use it when opening a writer if
  we can't connect immediately.  This can happen if the system is
  heavily loaded and/or if many writers are trying to open
  simultaneously.
2020-05-08 06:32:00 -04:00
Ken Brown 301454f132 Cygwin: FIFO: fix hit_eof
According to Posix, a FIFO open for reading is at EOF if it is empty
and there are no writers open.

The only way to test this is to poll the fifo_client_handlers as in
raw_read and select.cc:peek_fifo.  The current hit_eof instead relies
on the value of nconnected, which can be out of date.  On the one
hand, it doesn't take into account writers that were connected but
have since closed.  On the other hand, it doesn't take into account
writers that are in the process of opening but haven't yet connected.

Fix this by introducing a maybe_eof method that tentatively assumes
EOF if there are no connected writers after polling.  Then check for
writers currently opening (via a new 'writer_opening' event), and wait
for the fifo_reader_thread to record any new connection that was made
while we were polling.

To handle the needs of peek_fifo, replace the get_fc_handle method
by a get_fc_handler method, and add a fifo_client_handler::get_state
method.

Remove the is_connected method, which was used only in peek_fifo and
is no longer needed.

Remove the nconnected data member, which was used only for the flawed
hit_eof.

Add some comments about events to fhandler.h.
2020-05-08 06:32:00 -04:00
Ken Brown 13c65c43c2 Cygwin: FIFO: dup/fork/exec: make sure child starts unlocked
There can be deadlocks if the child starts with its fifo_client_lock
in the locked state.
2020-05-08 06:32:00 -04:00
Ken Brown 624fda1e96 Cygwin: FIFO: honor the flags argument in dup
Also improve the error handling.
2020-05-08 06:32:00 -04:00
Ken Brown 25e8727368 Cygwin: FIFO: remove the arm method
There's no reason to check for errors when we set read_ready or
write_ready.  We don't do that for other events.
2020-05-08 06:32:00 -04:00
Ken Brown 9b2afd78ce Cygwin: FIFO: simplify the listen_client_thread code
Always return 0; no one is doing anything with the return value
anyway.

Remove the return value from stop_listen_client.

Make the connection event auto-reset, so that we don't have to reset
it later.

Simplify the process of connecting a bogus client when thread
termination is signaled.

Make some failures fatal.

Remove the unnecessary extra check for thread termination near the end
of listen_client_thread.
2020-05-08 06:32:00 -04:00
Ken Brown 32dbc3d215 Cygwin: FIFO: change the fifo_client_connect_state enum
Make the values correspond to the possible return values of
fifo_client_handler::pipe_state().

When cleaning up the fc_handler list in listen_client_thread(), don't
delete handlers in the fc_closing state.  I think the pipe might still
have input to be read in that case.

Set the state to fc_closing later in the same function if a connection
is made and the status returned by NtFsControlFile is
STATUS_PIPE_CLOSING.

In raw_read, don't error out if NtReadFile returns an unexpected
status; just set the state of that handler to fc_error.  One writer in
a bad state doesn't justify giving up on reading.
2020-05-08 06:32:00 -04:00
Ken Brown ce23e97640 Cygwin: FIFO: simplify the fifo_client_handler structure
Replace the 'fhandler_base *' member by a HANDLE to the server side of
the Windows named pipe instance.  Make the corresponding
simplifications throughout.
2020-05-08 06:32:00 -04:00
Ken Brown d05124dc6b Cygwin: FIFO: minor change - use NtClose
Replace CloseHandle by NtClose since all handles are created by NT
functions.
2020-05-08 06:32:00 -04:00
Corinna Vinschen 72865dc2a3 Revert "localtime define _DIAGASSERT" and followups affecting localtime.cc
This reverts commits 453b6d17bf,
                     489a47d603,
                     3003c3dacd,
                     9e29639ca0,
                     a40701c7dc,
                     0a41de2725,
                     b8aa5f7a0f,
                     0f4bda8792,
                     65bf580752,
                     3f0c2ac96e,
                     76d4d40b8b,
                     f2e06d8af5.
2020-05-04 11:25:30 +02:00
Johannes Schindelin 717db9fd1c setup_pseudoconsole(): handle missing/incorrect helper gracefully
When `cygwin-console-helper.exe` is either missing, or corresponds to a
different Cygwin runtime, we currently wait forever while setting up
access to the pseudo console, even long after the process is gone that
was supposed to signal that it set up access to the pseudo console.

Let's handle that more gracefully: if the process exited without
signaling, we cannot use the pseudo console. In that case, let's just
fall back to not using it.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2020-05-04 11:19:19 +02:00