Commit Graph

19438 Commits

Author SHA1 Message Date
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
Corinna Vinschen 453b6d17bf localtime define _DIAGASSERT 2020-04-29 09:51:52 +02:00
Corinna Vinschen 489a47d603 localtime 1.82 2020-04-28 21:35:41 +02:00
Corinna Vinschen 3003c3dacd localtime 1.81 2020-04-28 21:26:45 +02:00
Corinna Vinschen 9e29639ca0 localtime 1.80 2020-04-28 21:21:14 +02:00
Corinna Vinschen a40701c7dc localtime 1.79 2020-04-28 21:20:18 +02:00
Corinna Vinschen 0a41de2725 localtime 1.78 2020-04-28 21:14:01 +02:00
Corinna Vinschen b8aa5f7a0f localtime 1.77 2020-04-28 20:58:29 +02:00
Corinna Vinschen 0f4bda8792 localtime 1.76 2020-04-28 20:57:34 +02:00
Corinna Vinschen 65bf580752 localtime 1.75 2020-04-28 20:56:16 +02:00
Corinna Vinschen 3f0c2ac96e localtime 1.74 2020-04-28 20:50:57 +02:00
Corinna Vinschen 76d4d40b8b localtime 1.73 2020-04-27 11:22:57 +02:00
Corinna Vinschen f2e06d8af5 Cygwin: localtime.cc: reformat for easier patching
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-27 11:22:51 +02:00
Corinna Vinschen d94763fc2e Cygwin: add release message for fixed floppy bugs
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-24 16:40:25 +02:00
Corinna Vinschen 39a1c3c96f Cygwin: raw disk I/O: lock floppys as well
The workaround to access the full disk required since Vista
and described in http://support.microsoft.com/kb/942448
(NOT ACCESSIBLE at the time of writing this commit message)
is required on floppy drives as well.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-24 16:22:26 +02:00
Corinna Vinschen b834921895 Cygwin: raw disk I/O: Fix return value in error case
The cast to generate the return value uses a DWORD variable
as test and set value.  The error case is the constant -1.
Given the type of the other half of the conditioal expression,
-1 is cast to DWORD as well.

On 64 bit, this results in the error case returning a 32 bit
-1 value which is equivalent to (ssize_t) 4294967295 rather
than (ssize_t) -1.

Add a fixing cast.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-24 16:19:09 +02:00
Corinna Vinschen 5a7e130c31 Cygwin: file I/O: make sure to treat write return value as ssize_t
The return type of fhandler write methods is ssize_t.  Don't
use an int to store the return value, use ssize_t.  Use ptrdiff_t
for the buffer size.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-24 16:14:43 +02:00
David Macek via Cygwin-patches 8a0bdd84b8 Cygwin: accounts: Report unrecognized db_* nsswitch.conf keywords
Signed-off-by: David Macek <david.macek.0@gmail.com>
2020-04-22 09:32:33 +02:00
David Macek via Cygwin-patches 969c8392fe Cygwin: accounts: Don't keep old schemes when parsing nsswitch.conf
The implicit assumption seemed to be that any subsequent occurence of
the same setting in nsswitch.conf is supposed to rewrite the previous
ones completely.  This was not the case if the third or any further
schema was previously defined and the last line defined less than that
(but at least 2), for example:

```
db_home: windows cygwin /myhome/%U
db_home: cygwin desc
```

Let's document this behavior as well.

Signed-off-by: David Macek <david.macek.0@gmail.com>
2020-04-22 09:32:33 +02:00
David Macek via Cygwin-patches d5add9ee5e Cygwin: accounts: Unify nsswitch.conf db_* defaults
Signed-off-by: David Macek <david.macek.0@gmail.com>
2020-04-22 09:32:33 +02:00
Corinna Vinschen f47347716c Cygwin: Add David Macek to CONTRIBUTORS
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-21 10:39:36 +02:00
Corinna Vinschen 6b97962073 Cygwin: symlinks: fix WSL symlink creation if cygdrive prefix is /
If the cygdrive prefix is /, then the following happens right now:

  $ ln -s /tmp/foo .
  $ ls -l foo
  lrwxrwxrwx 1 user group 12 Apr 15 23:44 foo -> /mnt/tmp/foo

Fix this by skipping cygdrive prefix conversion to WSL drive
prefix "/mnt", if the cygdrive prefix is just "/".  There's no
satisfying way to do the right thing all the time in this case
anyway.  For a description and the alternatives, see
https://cygwin.com/pipermail/cygwin-developers/2020-April/011859.html

Also, fix a typo in a comment.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-21 10:39:36 +02:00
David Macek via Cygwin-patches 5951b3e600 cygheap_pwdgrp: Handle invalid db_* entries correctly
If the first scheme in db_* was invalid, the code would think there
were no schemes specified and replace the second scheme with
NSS_SCHEME_DESC.

Signed-off-by: David Macek <david.macek.0@gmail.com>
2020-04-17 09:54:40 +02:00
Corinna Vinschen 1fac24078a Cygwin: faq: disable outdated "sshd in domain" faq
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-14 13:26:37 +02:00
Brian Inglis 073edd5329 proc_cpuinfo: Add PPIN support for AMD
Newer AMD CPUs support a feature called protected processor
identification number (PPIN). This feature can be detected via
CPUID_Fn80000008_EBX[23].
2020-04-14 12:35:51 +02:00
Corinna Vinschen 3d1360113d Cygwin: utils: override definition of PMEM_EXTENDED_PARAMETER
PMEM_EXTENDED_PARAMETER is defined in the local winlean.h as long
as mingw-w64 doesn't define it (in winnt.h).  ntdll.h needs the
definition for declaring NtMapViewOfSectionEx.  cygpath.cc and ps.cc
both include ntdll.h but not winlean.h, so they complain about the
missing definition.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-07 19:04:41 +02:00
Corinna Vinschen 3fe9b02ccd Cygwin: mmap_alloc: fix comment to document using the extended memory API
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-07 18:23:11 +02:00
Corinna Vinschen b8ecbaaac0 Cygwin: threads: use extended memory API if available
So far Cygwin was jumping through hoops to restrict memory
allocation to specific regions.  With the advent of VirtualAlloc2
and MapViewOfFile3 (and it's NT counterpart NtMapViewOfSectionEx),
we can skip searching for free space in the specific regions
and just call these functions and let the OS do the job more
efficiently and less racy.

Use VirtualAlloc2 on W10 1803 and later in thread stack allocation.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-07 18:23:11 +02:00
Corinna Vinschen 8d0a7701aa Cygwin: mmap: use extended memory API if available
So far Cygwin was jumping through hoops to restrict memory
allocation to specific regions.  With the advent of VirtualAlloc2
and MapViewOfFile3 (and it's NT counterpart NtMapViewOfSectionEx),
we can skip searching for free space in the specific regions
and just call these functions and let the OS do the job more
efficiently and less racy.

Use the new functions on W10 1803 and later in mmap.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-07 17:42:02 +02:00
Corinna Vinschen e18f7f99cc Cygwin: memory: declare extended memory API
Windows 10 1803 introduced an extended memory API allowing
to specify memory regions allocations are to be taken off.

In preparation of using this API, define the struct
MEM_EXTENDED_PARAMETER and friends.  Declare and allow to
autoload the functions VirtualAlloc2 and NtMapViewOfSectionEx.

Introduce a wincap flag has_extended_mem_api.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-07 17:42:02 +02:00
Corinna Vinschen ccb3a40dad Cygwin: threads: add missing include of mmap_alloc.h
This is needed for using mmap_alloc.alloc()

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-07 17:42:02 +02:00
Corinna Vinschen e8ae404440 Cygwin: threads: lower thread size from pool to 256 Megs
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-07 14:18:08 +02:00
Corinna Vinschen aa4d960306 Cygwin: threads: use mmap area to fulfill requests for big stacks
Otherwise big stacks have a higher probability to collide with
randomized PEBs and TEBs after fork.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-07 14:18:08 +02:00
Corinna Vinschen ece49e4090 Cygwin: symlinks: Allow traversing WSL symlinks
Unfortunately Windows doesn't understand WSL symlinks,
despite being a really easy job.  NT functions trying
to access paths traversing WSL symlinks return the status
code STATUS_IO_REPARSE_TAG_NOT_HANDLED.  Handle this
status code same as STATUS_OBJECT_PATH_NOT_FOUND in
symlink_info::check to align behaviour to traversing
paths with other non-NTFS type symlinks.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-05 16:18:05 +02:00
Corinna Vinschen 44fe41a766 Cygwin: docs: revamp docs explaining symlinks
The descriptions of symlink handling are a bit dated, so
revamp them and add the new WSL symlink type.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-03 21:44:00 +02:00
Corinna Vinschen 44da5e4b8c Cygwin: symlinks: create WSL symlinks on supporting filesystems
WSL symlinks are reparse points containing a POSIX path in UTF-8.
On filesystems supporting reparse points, use this symlink type.
On other filesystems, or in case of error, fall back to the good
old plain SYSTEM file.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-04-03 21:40:01 +02:00