Commit Graph

12281 Commits

Author SHA1 Message Date
Takashi Yano 33a21904a7 Cygwin: console: Add workaround for windows xterm compatible mode bug.
- The horizontal tab positions are broken after resizing console window.
  This seems to be a bug of xterm compatible mode of windows console.
  This workaround fixes this problem.
2019-08-12 17:08:48 +02:00
Takashi Yano 92e2c1ad9d Cygwin: console: Fix deadlock at calling fork().
- Calling fork() on console occasionally falls into deadlock. The reason
  is not clear, however, this patch fixes this problem anyway.
2019-08-12 17:08:48 +02:00
Joel Sherrill eae68bfc87 Add default implementation of fenv.h and all methods
The default implementation of the fenv.h methods return
	-EOPNOTSUP. Some of these have implementations appropriate
        for soft-float.

	The intention of the new fenv.h is that it be portable
	and that architectures provide their own implementation
	of sys/fenv.h.
2019-08-09 17:49:16 +02:00
Corinna Vinschen d59c2c9b82 Cygwin: drop preliminary 3.0.8 release file
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-08-09 17:49:16 +02:00
Corinna Vinschen 449e9a73d1 Cygwin: add missing bugfix release messages for 3.1.0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-08-09 17:47:55 +02:00
Corinna Vinschen 1f34405fea Cygwin: shmat: use mmap allocator strategy on 64 bit
This avoids collisions of shmat maps with Windows own datastructures
when allocating top-down.

This patch moves the mmap_allocator class definition into its
own files and just uses it from mmap and shmat.
2019-08-08 11:27:52 +02:00
Lavrentiev, Anton 5fa9a0e708 Cygwin: getpriority() and top display for priority is inconsistent
Fix this by aligning /proc/[PID]/stat to the values returned by getpriority().
2019-08-08 09:56:49 +02:00
Michael Haubenwallner 472fbb8b97 Cygwin: build_env: fix off-by-one bug when re-adding PATH
Adding default winvar 'PATH=C:\cygwin64\binZ' to an environment that is
already allocated for 'SYSTEMROOT=ZWINDIR=Z', we need to count that
trailing (Z)ero as well.  Otherwise we trigger this assertion failure:

$ /bin/env -i SYSTEMROOT= WINDIR= /bin/env
assertion "(s - envblock) <= tl" failed: file "/home/corinna/src/cygwin/cygwin-3.0.7/cygwin-3.0.7-1.x86_64/src/newlib-cygwin/winsup/cygwin/environ.cc", line 1302, function: char** build_env(const char* const*, WCHAR*&, int&, bool, HANDLE)
Aborted (core dumped)
2019-08-07 11:08:01 +02:00
Corinna Vinschen 98669a2476 Cygwin: exec: check execute bit prior to evaluating script
When the exec family of functions is called for a script-like
file, the av::setup function handles the exec[vl]p case as
well.  The execve case for files not starting with a she-bang
is handled first by returning ENOEXEC.  Only after that, the
file's executability is checked.

This leads to the problem that ENOEXEC is returned for non-executable
files as well.  A calling shell interprets this as a file it should try
to run as script.  This is not desired for non-executable files.

Fix this problem by checking the file for executability first.  Only
after that, follow the other potential code paths.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-08-06 10:50:42 +02:00
Mark Geisert 362b98b49a Cygwin: Implement CPU_SET(3) macros
This patch supplies an implementation of the CPU_SET(3) processor
affinity macros as documented on the relevant Linux man page.

There is a mostly superset implementation of cpusets under newlib's
libc/sys/RTEMS/include/sys that has Linux and FreeBSD compatibility
and is built on top of FreeBSD bitsets.  This Cygwin implementation
and the RTEMS one could be combined if desired at some future point.
2019-08-05 13:22:04 +02:00
Michael Haubenwallner 2986a524d8 Cygwin: fork: attach child not before success
Do not attach to the child before it was successfully initialized, or we
would need more sophisticated cleanup on child initialization failure,
like suppressing SIGCHILD delivery with multiple threads ("waitproc")
involved.

Improves "Cygwin: fork: Remember child not before success.",
commit f03ea8e1c5, which leads to fork
problems if cygserver is running:

https://cygwin.com/ml/cygwin-patches/2019-q2/msg00155.html
2019-07-31 13:27:51 +02:00
Michael Haubenwallner 23a779bf3d Cygwin: pinfo: stop remember doing reattach
During fork, the child process requires the process table to be
initialized for fixup_shms_after_fork, while still allowing subsequent
dlls.load_after_fork to fail silently (for when the "forkable" hardlinks
are not created yet).
pinfo::remember not performing reattach anymore requires explicit
pinfo::reattach now where appropriate.

Prepares to improve "Cygwin: fork: Remember child not before success."
commit f03ea8e1c5, which leads to fork
problems if cygserver is running:

https://cygwin.com/ml/cygwin-patches/2019-q2/msg00155.html
2019-07-31 13:27:47 +02:00
Corinna Vinschen 3a72edc124 Cygwin: Fix the address of myself
Introducing an independent Cygwin PID introduced a regression:

The expectation is that the myself pinfo pointer always points to a
specific address right in front of the loaded Cygwin DLL.

However, the independent Cygwin PID changes broke this.  To create
myself at the right address requires to call init with h0 set to
INVALID_HANDLE_VALUE or an existing address:

void
pinfo::init (pid_t n, DWORD flag, HANDLE h0)
{
  [...]
  if (!h0 || myself.h)
    [...]
  else
    {
      shloc = SH_MYSELF;
      if (h0 == INVALID_HANDLE_VALUE)       <-- !!!
        h0 = NULL;
    }

The aforementioned commits changed that so h0 was always NULL, this way
creating myself at an arbitrary address.

This patch makes sure to set the handle to INVALID_HANDLE_VALUE again
when creating a new process, so init knows that myself has to be created
in the right spot.  While at it, fix a potential uninitialized handle
value in child_info_spawn::handle_spawn.

Fixes: b5e1003722 ("Cygwin: processes: use dedicated Cygwin PID rather than Windows PID")
Fixes: 88605243a1 ("Cygwin: fix child getting another pid after spawnve")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-07-25 10:45:52 +02:00
Corinna Vinschen 2232498c71 Cygwin: Don't change pgid to ctty pgid under debugger
_pinfo::set_ctty sets myself's pgid to the ctty pgid if the process has
been started from a non-Cygwin process.  This isn't the right thing to
do when started from GDB.  GDB starts the application via standard
Windows means, not via Cygwin fork/exec, so it's treated as being
a non-Cygwin parent.

But we want the app running in it's own process group.  So skip this
step when running under a debugger

Signed-off-by: Corinna Vinschen <corinna-cygwin@cygwin.com>
2019-07-25 10:45:52 +02:00
Corinna Vinschen a13145a30d Cygwin: Export newlib ndbm functions
Signed-off-by: Corinna Vinschen <corinna-cygwin@cygwin.com>
2019-07-24 22:32:48 +02:00
Ken Brown 6b843b82a8 Cygwin: document the last bug fix 2019-07-24 14:56:21 -04:00
Ken Brown 8a46b8ede2 Cygwin: fhandler_termios::tcsetpgrp: check that argument is non-negative
Return -1 with EINVAL if pgid < 0.

Previously tcsetpgrp() would blindly go ahead and set the pgid of the
controlling terminal to a negative value, causing later calls to
various functions to fail.

For example, gdb has code like the following:

  tcsetpgrp (0, getpgid (inf->pid));

If getpgid (inf->pid) fails (returns -1), then this code would set the
pgid of fd 0 to -1, so that some later calls to getpgid() would also
return -1.  This caused the problem reported here:

  https://cygwin.com/ml/cygwin/2019-07/msg00166.html.
2019-07-24 13:26:08 -04:00
Ken Brown ae59d09308 Cygwin: fix one more check for positive virtual_ftype_t values
Also drop more comments referring to numerical virtual_ftype_t values.
2019-07-22 14:06:35 -04:00
Corinna Vinschen dec444bee3 Cygwin: change virtual_ftype_t to not rely on negative values
So far negative values were denoting files, positive values
denoting directories.  We should prefer a less error prone
method.  Redefine virtual_ftype_t to contain only positive
values and replace checks for negativ or positive values with
inline functions virt_ftype_isfile() and virt_ftype_isdir().

Drop outdcated comments referring to numerical virtual_ftype_t
values.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-07-22 18:42:39 +02:00
Corinna Vinschen e118a605e2 Cygwin: fix /proc/PID/fd return value in error case
commit 2607639992 "Improve error handling in /proc/[pid]/
virtual files." changed the return value of the /proc/PID
formatting functions to return -1 instead of 0 in the error
case to allow a filesize of 0.

The patch neglected to change this behaviour for /proc/PID/fd
content.  This patch fixes that.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-07-22 18:42:38 +02:00
Ken Brown 86817773c5 Cygwin: add release notes for 3.0.8 2019-07-22 08:18:16 -04:00
Ken Brown 73f819534d Cygwin: socket files are not lnk special files
Change path_conv::is_lnk_special() so that it returns false on socket
files.

is_lnk_special() is called by rename2() in order to deal with special
files (FIFOs and symlinks, for example) whose Win32 names usually have
a ".lnk" suffix.  Socket files do not fall into this category, and
this change prevents ".lnk" from being appended erroneously when such
files are renamed.

Remove a now redundant !pc.issocket() from fhandler_disk_file::link().
2019-07-22 08:15:16 -04:00
Ken Brown af4d29e106 Cygwin: remove path_conv::is_fs_device()
It is used only once.
2019-07-22 08:15:16 -04:00
Ken Brown fb5ce26cfd Cygwin: remove path_conv::is_auto_device()
It is used only once, and the name is supposed to suggest "device that
is not based on the filesystem".  This intended meaning is clearer if
we just replace is_auto_device() by its definition at the place where
it's used.
2019-07-22 08:15:16 -04:00
Ken Brown 4beb9da118 Cygwin: fhandler_*: remove isdevice() and is_auto_device()
isdevice() is used only in the definition of is_auto_device().  And
the latter is used only once, in a context where isdevice() always
returns true.
2019-07-22 08:15:16 -04:00
Ken Brown 6b7723a830 Cygwin: unbreak the build with GCC 7
The recent port to GCC 8 used the 'nonstring' attribute, which is
unknown to GCC 7.  Define and use an 'ATTRIBUTE_NONSTRING' macro
instead.
2019-07-19 14:14:33 -04:00
Ken Brown 3a956a9bc3 Cygwin: fix GCC 8.3 'local external declaration' errors
Move external declarations out of function definition.
2019-07-17 11:08:20 -04:00
Ken Brown 81421eda7d Cygwin: fix GCC 8.3 'asm volatile' errors
Remove the volatile qualifier, which is no longer allowed outside of
the function body.  See
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89585 for discussion.
2019-07-17 10:39:27 -04:00
Ken Brown d730fa7b9c Cygwin: suppress GCC 8.3 errors with -Warray-bounds 2019-07-16 13:19:33 -04:00
Ken Brown b66dddb56d Cygwin: avoid GCC 8.3 errors with -Werror=stringop-truncation 2019-07-16 13:19:05 -04:00
Ken Brown f0cf44dc7d Cygwin: avoid GCC 8.3 errors with -Werror=class-memaccess 2019-07-16 13:17:43 -04:00
Corinna Vinschen bae987be12 Cygwin: sigpending: don't report pending signals for other threads
The sigpending mechanism failed to check if the pending signal was a
process-wide signal, or a signal for the curent thread.  Fix that by
adding a matching conditional to wait_sig's __SIGPENDING code.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-07-12 17:27:26 +02:00
Corinna Vinschen 948d40e482 Cygwin: return full sigset_t from sig_send
So far sig_send's return type is int.  The problem with this is
that sig_send returns a sigset_t on __SIGPENDING, and sigset_t
is defined as long type.  So the function only returns the lower
32 bit of sigset_t, which is fine on 32 bit, but casts away the
pending RT signals on 64 bit.

Fix this by changing the return type of sig_send to sigset_t, so
as not to narrow down the sigset when returning from handling
__SIGPENDING.  Make sure to cast correctly in all invocations
of sig_send.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-07-12 17:27:26 +02:00
Mark Geisert fff17ad73f Cygwin: Fix return value of sched_getaffinity
Have sched_getaffinity() interface like glibc's, and provide an
undocumented internal interface __sched_getaffinity_sys() like the Linux
kernel's sched_getaffinity() for benefit of taskset(1).
2019-06-28 17:10:39 +02:00
Corinna Vinschen 383e19ca55 sched: Move Cygwin cpuset definitions into Cygwin-specific header
This avoids build breakage on RTEMS.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-06-27 20:19:31 +02:00
Ken Brown aa55d22cb5 Cygwin: honor the O_PATH flag when opening a FIFO
Previously fhandler_fifo::open would treat the FIFO as a reader and
would block, waiting for a writer.
2019-06-27 07:46:14 -04:00
Mark Geisert f96f7bec6b Cygwin: Build cygwin-console-helper with correct compiler 2019-06-27 09:16:05 +02:00
Mark Geisert 40b947e7d5 Cygwin: Use correct string conversion
Correct the string conversion calls so both argv elements get converted
at full precision.
2019-06-27 09:13:47 +02:00
Ken Brown 09e2ec87ef Cygwin: FIFO: fix a thinko in raw_write
Remove a line that has no effect.
2019-06-25 18:45:34 -04:00
Ken Brown 3dcc10ec90 Tweak release message 2019-06-25 16:38:39 -04:00
Ken Brown 9604a251bd Cygwin: timerfd: avoid a deadlock
Add a function timerfd_tracker::enter_critical_section_cancelable,
which is like enter_critical_section but honors a cancel event.  Call
this when a timer expires while the timerfd thread is in its inner
loop.  This avoids a deadlock if timerfd_tracker::dtor has entered its
critical section and is trying to cancel the thread.  See
https://cygwin.com/ml/cygwin/2019-06/msg00096.html.
2019-06-25 15:44:43 -04:00
Mark Geisert 641ecb0753 Cygwin: Implement sched_[gs]etaffinity()
This patch set implements the Linux syscalls sched_getaffinity,
sched_setaffinity, pthread_getaffinity_np, and pthread_setaffinity_np.
Linux has a straightforward view of the cpu sets used in affinity masks.
They are simply long (1024-bit) bit masks.  This code emulates that view
while internally dealing with Windows' distribution of available CPUs among
processor groups.
2019-06-24 09:18:14 +02:00
Ken Brown d54edfdf81 Cygwin: FIFO: minor cleanup
Don't use a label with the same name as a variable.

Also fix indentation in fhandler.h.
2019-06-23 10:16:34 -04:00
Ken Brown 2357091617 Cygwin: FIFO: slightly change the use of write_ready
Make it a manual reset event.  It's only used once to allow a reader
to open, and there's no reason to ever reset it.  Defensively set it
when a client connection is recorded, even though it should be set by
the writer that connected.
2019-06-23 10:16:34 -04:00
Ken Brown 6e7e82fee7 Cygwin: FIFO: remove fifo_client_handler::connect_evt
It's not needed.  Instead just create and use an event in
fhandler_fifo::listen_client_thread.
2019-06-23 10:16:34 -04:00
Ken Brown 5b2696cb83 Cygwin: FIFO: simplify raw_read
Call NtReadFile directly instead of calling fhandler_base::raw_read.
In addition to being simpler, this gives us access to the return value
from NtReadFile.
2019-06-23 10:16:33 -04:00
Ken Brown 5bd5e3dc6c Cygwin: FIFO: improve termination of the listen_client thread
Add a method fifo_client_handler::pipe_state that queries Windows for
the state of a pipe instance.  Use this to help terminate the
listen_client thread cleanly.

If the last client handler is useless, delete it instead of declaring
it invalid.
2019-06-23 10:16:33 -04:00
Ken Brown d1b36ea949 Cygwin: FIFO: avoid deadlock when closing
fhandler_fifo::close could be called from a signal handler or another
thread at a time when another function is holding the fifo_client
lock.  This could prevent the listen_client thread from acting on the
thread termination event.  Avoid a deadlock by calling
fifo_client_unlock at the beginning of fhandler_fifo::close.
2019-06-23 10:16:33 -04:00
Ken Brown 281d3bf060 Cygwin: FIFO: clean up locks
Make sure to use the fifo_client lock when (and only when) it is
needed.
2019-06-23 10:16:33 -04:00
Ken Brown a9b6d32882 Cygwin: FIFO: add some error checking
Change the return type of fhandler_fifo::delete_client_handler from
void to int so that we can report errors.
2019-06-23 10:16:33 -04:00
Ken Brown 724c18ff7e Cygwin: FIFO: fix signal handling in raw_read and raw_write
cygwait wasn't being called correctly.

Also do some minor cleanup in raw_read and raw_write.
2019-06-23 10:16:33 -04:00
Corinna Vinschen ad101bcb0f Rename <xlocale.h> back to <sys/_locale.h>
libX11 provides <X11/Xlocale.h>.  The build of libX11 itself adds
include/X11 to the compiler's include path.  This results in a name
collision with /usr/include/xlocale.h on case-insensitive filesystems.

Commit 90e35b1eb3 renamed sys/_locale.h to xlocale.h in March 2017 under
the assumption that we should provide the locale_t type in the same file
as on Linux, FreeBSD, and Darwin.

A few weeks later (June 2017), glibc removed the xlocale.h file in favor
of bits/types/locale_t.h, which shouldn't be included directly anyway.

For reference and the reasoning, see
https://sourceware.org/git/?p=glibc.git;a=commit;h=f0be25b6336d

Given the above, revert 90e35b1eb3 and
fix additional usage of xlocale.h.
2019-06-14 10:02:08 +02:00
Ken Brown 000f2409b1 Revert "Cygwin: fork: Remember child not before success."
This reverts commit f03ea8e1c5.  That
commit leads to fork problems if cygserver is running:

https://cygwin.com/ml/cygwin-patches/2019-q2/msg00155.html
2019-06-11 08:50:41 -04:00
Corinna Vinschen 605bdcd410 Cygwin: map beyond EOF on 64 bit and WOW64 as well
32 bit Cygwin performs a POSIX-compatible mapping after EOF which
is not supported in this form on Windows.  The 64 bit Windows
kernel never supported the AT_ROUND_TO_PAGE mapping flag, so we
couldn't page-aligned map the space right after the file's EOF.
So mapping beyond EOF was disabled in 64 bit Windows and WOW64.

However,  if mmap works, a matching munmap should work as well,
*and* it should not accidentally unmap unrelated memory.

Therefore we enable mapping beyond EOF on 64 bit as well.  Since
that mapping is always 64K aligned, the are between the last file
page and the next 64K allocation boundary will be unallocated.
There's no way around that.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-06-05 20:08:34 +02:00
Ben Wijen b0c033bf3f mkdir: always check-for-existence
When using NtCreateFile when creating a directory that already exists,
it will correctly return 'STATUS_OBJECT_NAME_COLLISION'.

However using this function to create a directory (and all its parents)
a normal use would be to start with mkdir(‘/cygdrive/c’) which translates
to ‘C:\’ for which it'll instead return ‘STATUS_ACCESS_DENIED’.
2019-06-05 13:53:44 +02:00
Yaakov Selkowitz 5c2a3661c1 cygcheck: expand common_apps list
An increasing number of tools are being included in Windows which have the
same names as those included in Cygwin packages.  Indicating which one is
first in PATH can be helpful in diagnosing behavioural discrepencies
between them.

Also, fix the alphabetization of ssh.
2019-06-04 11:31:54 -04:00
Corinna Vinschen e1254add73 Cygwin: Allow accessing 48 bit address space in Windows 8.1 or later
64 bit Windows started out with a 44 bit address space due to a
restriction of the AMD64 CPUs at the time.  Starting with Windows
8.1, these CPUs are not supported anymore and Windows switched to
the full 48 bit address space supported by AMD64.

Cygwin didn't follow suit yet so mmaps are still restricted to
the lower 44 bit address space.  Fix that by using a system-specific
upper address for mmap allocations, 44 bit up to Windows 8, 48 bit
starting with Windows 8.1.

While at it, move the heap by another 8 Gigs to leave some space
for a potential extension of DLL address space, and restrict the
mmap lower address so the heap can grow to 32 Gigs before colliding
with mmaps.
2019-06-04 16:58:53 +02:00
Michael Haubenwallner f03ea8e1c5 Cygwin: fork: Remember child not before success.
Do not remember the child before it was successfully initialized, or we
would need more sophisticated cleanup on child initialization failure,
like cleaning up the process table and suppressing SIGCHILD delivery
with multiple threads ("waitproc") involved.  Compared to that, the
potential slowdown due to an extra yield () call should be negligible.
2019-06-03 18:43:45 +02:00
Michael Haubenwallner a8c23e4423 Cygwin: fork: Always pause child after fixups.
Pause the child process after performing fork fixups even if there were
no dynamically loaded dlls with extra data/bss transfers to wait for.
This allows the parent process to cancel the current fork call even if
the child process was successfully initialized already.

This is a preparation for when the parent does remember the child no
earlier than after successful child initialization.
2019-06-03 18:40:35 +02:00
Michael Haubenwallner a9c27900e3 Cygwin: dll_list: no recursive use of nt_max_path_buf
Querying the ntlength and existence of the /var/run/cygfork directory in
the very first Cygwin process should not use nt_max_path_buf, as that
one is used by dll_list::alloc already.
2019-06-03 18:38:16 +02:00
Michael Haubenwallner 6c9ad75a4b Cygwin: dll_list: stat_real_file_once with ntname
NtQueryVirtualMemory for MemorySectionName may return some old path even
if the process was just started, for when some directory in between was
renamed - maybe because the NT file cache is hot for the old path still.
This was seen during gcc bootstrap, returning a MemorySectionName of
".../gcc/xgcc.exe" even if started as ".../prev-gcc/xgcc.exe", where the
directory rename from "gcc" to "prev-gcc" was done the moment before.
As we stat the module's real file right after loading now, there is no
point in using NtQueryVirtualMemory with MemorySectionName any more, and
we can use what GetModuleFileName returned instead.
2019-06-03 18:37:52 +02:00
Jinke Fan ee7e49e193 Add support for Hygon Dhyana processor
-Add vendor identification
-Support in get_cpu_cache

Background:
    Chengdu Haiguang IC Design Co., Ltd (Hygon) is a Joint Venture
    between AMD and Haiguang Information Technology Co.,Ltd., aims at
    providing high performance x86 processor for China server market.
    Its first generation processor codename is Dhyana, which
    originates from AMD technology and shares most of the
    architecture with AMD's family 17h, but with different CPU Vendor
    ID("HygonGenuine")/Family series number(Family 18h).

Related Hygon kernel patch can be found on:
http://lkml.kernel.org/r/5ce86123a7b9dad925ac583d88d2f921040e859b.1538583282.git.puwen@hygon.cn

Signed-off-by: Jinke Fan <fanjinke@hygon.cn>
2019-06-03 10:32:58 +02:00
Ken Brown d79aa0f593 Cygwin: FIFO: respect the O_CLOEXEC flag
Set the inheritance of the Windows pipe handles according to the
O_CLOEXEC flag.  Previously the pipe was always created and opened
with OBJ_INHERIT.
2019-05-28 15:50:05 -04:00
Ken Brown 5bb8d445f4 Cygwin: FIFO: Open only one handle to NPFS
Make npfs_handle a static member function of fhandler_fifo, as in
fhandler_socket_unix.
2019-05-23 08:39:33 -04:00
Ken Brown e91bc190ff Cygwin: FIFO: code simplifications.
There's no longer a need to consider the connect_evt after fork/exec.
After stopping the listen_client thread, all client handlers should be
in the fc_connected or fc_invalid states, so their connect_evt members
won't be used again.

Also remove code in fhandler_fifo::dup that just repeats things
already done in stop_listen_client.
2019-05-09 14:41:29 -04:00
Ken Brown 0771fc7031 Cygwin: FIFO: make read_ready an auto-reset event
There's no point in allowing a writer to attempt to open until we've
created a pipe instance.
2019-05-09 14:41:29 -04:00
Ken Brown 102571f85d Cygwin: FIFO: improve the check for the listen_client thread
Add a method fhandler_fifo::check_listen_client_thread that checks
whether the thread is running.  Use it in raw_read instead of just
testing the handle listen_client_thr.
2019-05-09 14:41:29 -04:00
Ken Brown 7ad80b3c23 Cygwin: FIFO: set client handler flags more accurately
Reflect the fact that client handlers are only used for reading and
that, after connection, they are always nonblocking.
2019-05-09 14:41:29 -04:00
Ken Brown c12053a793 Cygwin: FIFO: don't leave a pending listen request
On exit from the listen_client thread, make sure there's no pending
FSCTL_PIPE_LISTEN request.  Otherwise we might get a client connection
after restarting the thread, and we won't have a handle for
communicating with that client.

Remove the retry loop in the case of STATUS_PIPE_LISTENING; that case
shouldn't occur.

Remove the now-unused fc_connecting value from
fifo_client_connect_state.
2019-05-09 14:41:29 -04:00
Ken Brown 816c6da53a Cygwin: FIFO: add a HANDLE parameter to open_pipe
It's now up to the caller to pass a handle to open_pipe and, if
desired, to call set_handle on return.

This will be useful for a future commit, in which we will open a
client connection without setting an io_handle.
2019-05-09 14:41:29 -04:00
Ken Brown 00b2e56d31 Cygwin: FIFO: re-implement duplexers
When opening a duplexer, open a client connection to the first client
handler.  Previously we gave the duplexer a bogus write handle, which
was just a duplicate of the first client handler's handle.  This meant
that we had a pipe server with no clients connected, and all I/O
attempts failed with STATUS_PIPE_LISTENING.

Extend the last fcntl change to duplexers.

Remove a now unused fifo_client_handler constructor, as well as the
long unusued method fifo_client_handler::connect.

Don't create the pipe in duplex mode; the server handle will only be
used for reading.
2019-05-09 14:41:29 -04:00
Ken Brown f3d1fe2ff8 Cygwin: FIFO: add 'record_connection' method
Future commits will have to re-use the code for recording a client
connection.  For convenience, factor out this code into a new method.
2019-05-09 14:41:29 -04:00
Ken Brown 1372021a2d Cygwin: FIFO: remove incorrect duplexer code
raw_read had some code that was based on an incorrect implementation
of duplexers.
2019-05-09 14:41:28 -04:00
Ken Brown 674b4fe995 Revert "Cygwin: check for STATUS_PENDING in fhandler_base::raw_read"
This reverts commit 10bf30bebf.  It was
made because an incorrect implementation of duplex FIFOs.
2019-05-09 14:41:28 -04:00
Michael Haubenwallner b6ebca61e3 Cygwin: dll_list: drop unused read_fbi method 2019-05-05 10:04:43 -04:00
Corinna Vinschen 4ac32559c0 Cygwin: Add release info for 3.0.7
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
(cherry picked from commit 01c253a4c58b6c1da01615431bdc4c88fcba48ea)
2019-04-30 18:49:23 +02:00
Michael Haubenwallner e33db96a14 Cygwin: dll_list: query dll file id at load time
NtQueryVirtualMemory for MemorySectionName does not reliable return the
changed dll file name when another process does move the file around,
and we may end up creating forkable hardlinks to wrong dll files.
So query the file id when loading the dll rather than before fork.
2019-04-30 18:10:08 +02:00
Michael Haubenwallner 0f5776c47c Cygwin: dll_list: stat_real_file_once as dll method
Make stat_real_file_once a method of struct dll, to be more flexible on
where to use.  Also, debug print memory section name queried for a dll.
This is a preparation to query the file id when loading the dll.
2019-04-30 18:10:08 +02:00
Michael Haubenwallner 4c79da8017 Cygwin: dll_list: drop FILE_BASIC_INFORMATION
Querying FILE_BASIC_INFORMATION is needless since using win pid+threadid
for forkables dirname rather than newest last write time.
2019-04-30 18:10:08 +02:00
Corinna Vinschen a4e62e3a4c Cygwin: update era and message locale data
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-04-30 11:55:04 +02:00
Ken Brown 440559c40a Cygwin: FIFO: synchronize the blocking mode of a writer's pipe
The blocking mode of the Windows pipe underlying a writer is set to
match that of the writer itself when the latter is opened.  Define
fhandler_fifo::fcntl to keep the pipe and the writer in sync if the
blocking mode is changed via fcntl.
2019-04-26 07:45:37 -04:00
Corinna Vinschen f527171a93 Cygwin: define MSG_EOR and refuse in send(2)
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-04-25 19:00:08 +02:00
Erik M. Bray 489e7e2048 Minor improvements to socket error handling:
* Change default fallback for failed winsock error -> POSIX error
  mappings to EACCES, which is a valid errno for more socket-related
  syscalls.

* Added a few previously missing entries to the wsock_errmap table
  that have obvious POSIX errno.h analogues.
2019-04-23 17:20:57 +02:00
Ken Brown 9957a7895b Cygwin: FIFO: restart listen_client thread after fork/exec
This allows writers to connect immediately.  Previously the lct wasn't
restarted until the reader attempted to read.
2019-04-22 07:55:58 -04:00
Ken Brown 4443100b53 Cygwin: FIFO: stop the listen_client thread before fork/exec
Add methods need_fixup_before, init_fixup_before, and
fixup_before_fork_exec to accomplish this.  Stopping the thread makes
sure that the client handler lists of the parent and child remain in
sync while the forking/execing is in progress.
2019-04-20 14:31:07 -04:00
Ken Brown 252cd0ce2b Cygwin: FIFO: close connect_evt handles as soon as possible
Keeping them open too long can cause an attempt to close them twice
after a fork or exec.
2019-04-20 14:31:07 -04:00
Ken Brown 24c56e5a2c Cygwin: FIFO: avoid WFMO error in listen_client_thread
Don't set lct_termination_evt to NULL too early in
fhandler_fifo::stop_listen_client.  Doing so leads to an "Invalid
Handle" error in WFMO.
2019-04-20 14:31:07 -04:00
Ken Brown ef269531a9 Cygwin: FIFO: duplicate the i/o handle when opening a duplexer
Don't use the same i/o handle for the first client handler as is used
for the fhandler itself; this can lead to a later attempt to close the
same handle twice.  Instead use a duplicate.
2019-04-20 14:31:07 -04:00
Ken Brown 4ecea14a58 Cygwin: FIFO: stop the listen_client thread on an opening error
Don't just close the thread handle.
2019-04-20 14:31:07 -04:00
Corinna Vinschen 28182bca18 Cygwin: drop unsupported Windows 10 versions
* Pre-release version still reporting kernel version 6.4.
* Windows 10 1511 is out of support since 2017-10-10.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-04-19 18:13:02 +02:00
Ken Brown 230c5df2df Cygwin: FIFO: avoid hang after exec
Define fhandler:fifo::fixup_after_exec, which sets listen_client_thr
and lct_termination_evt to NULL.  This forces the listen_client thread
to restart on the first attempt to read after an exec.  Previously the
exec'd process could hang in fhandler_fifo::raw_read.
2019-04-18 19:34:07 +02:00
Ken Brown 2b4cf7622e Cygwin: FIFO: fix and simplify listen_client_thread
Remove fifo_client_handler::connect and move its code into
listen_client_thread.  That way we can check the return status when a
client handler's connect_evt is signaled.  Previously we incorrectly
assumed there was a successful connection.

Also simplify listen_client_thread in the following ways:

- Replace fhandler_fifo::disconnect_and_reconnect by a new
  delete_client_handler method.  Now we just delete invalid client
  handlers rather than trying to re-use them.

- Try to maintain a client handler list that consists of connected
  client handlers and exactly one that is listening for a connection.
  This allows us to call WaitForMultipleObjects with only two wait
  objects.

- Remove 'dummy_evt' from the fifo_client_handler struct; it is no
  longer needed.

- On exit from listen_client_thread, delete the "extra" (listening)
  client handler.  Otherwise there could be a connection that doesn't
  get recorded in the client handler list.  This could happen when a
  file descriptor is being duplicated.
2019-04-16 12:54:43 +02:00
Ken Brown bb46627871 Cygwin: FIFO: improve raw_write
Don't set the write end of the pipe to non-blocking mode if the FIFO
is opened in blocking mode.

In fhandler_fifo::raw_write in blocking mode, wait for the write to
complete rather than returning -1 with EAGAIN.

If the amount to write is large, write in smaller chunks (of size
determined by a new data member max_atomic_write), as in
fhandler_base_overlapped.

For convenience, add two new NTSTATUS codes, STATUS_THREAD_SIGNALED
and STATUS_THREAD_CANCELED, to ntdll.h.
2019-04-16 12:54:43 +02:00
Ken Brown a7d08b3ecd Cygwin: FIFO: start the listen_client thread when duping a reader
Otherwise it doesn't get started until the dup'd fd tries to read,
which delays client connections.
2019-04-16 12:54:43 +02:00
Ken Brown 7b28776d3f Cygwin: FIFO: fix clone
After copyto is called, make the new fhandler's pipe_name point to the
new fhandler's pipe_name_buf, which is a *copy* of the old fhandler's
pipe_name_buf.  Previously, get_pipe_name would return the wrong
result after a clone/dup, causing create_pipe_instance and open_pipe
to fail.

Also, stop the listen_client thread when cloning.  Otherwise the
thread can keep accepting connections that the cloned fhandler won't
know about.

Do this via a new method fhandler_fifo::stop_listen_client, extracted
from fhandler_fifo::close.
2019-04-16 12:54:43 +02:00
Ken Brown c5bc7a8065 Cygwin: FIFO: use a retry loop when opening a writer
There may be short periods when there's no pipe instance available.
Keep trying.
2019-04-16 12:54:43 +02:00
Ken Brown 6b20be0944 Cygwin: FIFO: fix the use of the read_ready event
Make read_ready a manual reset event.  It should always be set shortly
after startup of the listen_client thread and remain set until the
thread terminates.  (We don't want writers to connect without being
recorded in the client handler list.)

Remove the unnecessary code that checks for read_ready when a reader
is opening.
2019-04-16 12:54:43 +02:00
Ken Brown 3ef03376c5 Cygwin: FIFO: fix fifo_client_handler::close
Make sure that fhandler_base::close rather than fhandler_fifo::close
is called on the fhandler.  Also, delete the fhandler, since we
allocated it.
2019-04-16 12:54:43 +02:00
Ken Brown d243b3c70e Cygwin: FIFO: code simplification: don't overload get_handle
Rename fhandler_fifo::get_handle(int) to get_fc_handle(int), and
remove fhandler_fifo::get_handle(void).
2019-04-16 12:54:43 +02:00
Ken Brown 10bf30bebf Cygwin: check for STATUS_PENDING in fhandler_base::raw_read
If NtReadFile returns STATUS_PENDING, wait for the read to complete.
This can happen, for instance, in the case of a FIFO opened with
O_RDRW.
2019-04-16 12:54:43 +02:00