Commit Graph

13241 Commits

Author SHA1 Message Date
Corinna Vinschen 282f40e469 Cygwin: set the FILE_ATTRIBUTE_ARCHIVE DOS attribute on file creation
Do this for normal files and symlinks, not for temporary files,
device files or unix sockets.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-11-15 20:57:41 +01:00
Corinna Vinschen 3c19e1e0d9 Cygwin: dllfixdbg: create .gnu_debuglink section in the right spot
A recent change in binutils marks the .gnu_debuglink_overlay section
as debug section.  When dllfixdbg calls objcopy -g, the section
is removed and the --add-gnu-debuglink option on the same command line
appends the section consequentially at the end of the sections.
This in turn breaks Windows Version info and, potentially, raising
the cygheap size at runtime.

Fix this by adding an explicit --keep-section=.gnu_debuglink_overlay
to the objcopy command line.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-11-15 13:45:26 +01:00
Corinna Vinschen bd3996f218 Cygwin: add 3.3.3 release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-11-11 11:02:08 +01:00
Corinna Vinschen e1f02dca90 Cygwin: introduce isabspath_strict macro
isabspath handles a path "X:", without trailing slash or backslash,
as absolute path.  This breaks some scenarios with relative paths
starting with "X:".  For instance, fstatat will mishandle a call
with valid dirfd and "c:" as path.

The reason is that gen_full_path_at() will check for isabspath("C:")
which returns true.  So the path will be used verbatim in fstatat,
rather than being converted to a path "<dirfd-path>/c:".

So, introduce isabspath_strict, which returns true for paths starting
with "X:" only if the next char is actually a slash or backslash.
Use it from gen_full_path_at().

This still fixes only half the problem.  The right thing would have been
to disallow using DOS paths in the first place.  Unfortunately it's much
too late for that.

Addresses: https://cygwin.com/pipermail/cygwin/2021-November/249837.html
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-11-11 11:02:08 +01:00
Corinna Vinschen 8539c39172 Cygwin: drop unused isabspath_u and iswabspath macros
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-11-11 11:02:08 +01:00
Takashi Yano 7c902b3c90 Cygwin: pipe: Fix raw_write() for non-cygwin pipe with size zero.
- Currently, raw_write() fails to handle size zero pipe which may
  be created by non-cygwin apps (e.g. Windows native ninja). This
  patch fixes the issue.

Addresses:
  https://cygwin.com/pipermail/cygwin/2021-November/249844.html
2021-11-11 14:31:27 +09:00
Takashi Yano 08253fae73 Cygwin: pipe: Handle WAIT_CANCELED when waiting read_mtx.
- Add missing handling for WAIT_CANCELED in cygwait() for read_mtx
  in raw_read().
2021-11-10 21:11:27 +09:00
Corinna Vinschen 975a808a56 Cygwin: bump DLL minor version
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-11-08 16:58:50 +01:00
Takashi Yano 1f7aa67b1c Cygwin: pipe: Avoid false EOF while reading output of C# programs.
- If output of C# program is redirected to pipe, pipe reader falsely
  detects EOF. This happens after overhaul of pipe implementation.
  This patch fixes the issue.

Addresses:
  https://cygwin.com/pipermail/cygwin/2021-November/249777.html
2021-11-08 10:48:23 +01:00
Corinna Vinschen 0390cc8572 Cygwin: fix permission problem when writing DAC info on Samba shares
Cygwin always requests FILE_WRITE_ATTRIBUTES permissions when trying to
change DAC information.  This can lead to permission problems when
trying to chmod/chown files on Samba shares.  Drop requesting
FILE_WRITE_ATTRIBUTES on Samba shares and go with WRITE_DAC/WRITE_OWNER
only.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-11-04 21:54:06 +01:00
Corinna Vinschen bd4eaebb6f Cygwin: add release note for rounding issue
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-11-04 13:15:39 +01:00
Takashi Yano b3d2f35cb1 Cygwin: console: Prevent the exec'ed bash from exiting by Ctrl-C.
- Currently, bash occasionally exits by Ctrl-C with the following
  scenario.
    1) Start bash in the command prompt.
    2) Run 'exec bash'.
    3) Press Ctrl-C several times.
  This patch fixes the issue.
2021-11-03 15:09:55 +01:00
Corinna Vinschen b01b5e45e9 Cygwin: add release note
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-11-02 15:10:40 +01:00
Takashi Yano ea64a781c7 Cygwin: console: Fix yet another bug on input when signalled.
- Currently, read() returns EINTR due to a bug if signal handler
  is SIG_DFL and the process is suspended by Ctrl-Z and restarted.
  This patch fixes the issue.
2021-11-02 15:07:25 +01:00
Takashi Yano a4bda4f626 Cygwin: console: Fix a bug on input when signalled.
- This patch fixes the bug that Ctrl-C sometimes does not work as
  expected in Windows Terminal.

Addresses:
  https://cygwin.com/pipermail/cygwin/2021-November/249749.html
2021-11-02 15:07:25 +01:00
Corinna Vinschen 8cdb4afbf1 Cygwin: bump DLL minor version
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-11-02 15:05:26 +01:00
Corinna Vinschen e528cfe919 Cygwin: split malloc_init
Cygwin 3.3 only: Replace SRWLOCK usage for malloc synchronization with
the first incarnation of the patch splitting malloc_init into two parts.
The SRWLOCK usage requires TryAcquireSRWLockExclusive, which isn't
available on Vista / Server 2008, unfortunately.

Per https://cygwin.com/pipermail/cygwin-developers/2021-October/012429.html,
we may encounter a crash when starting multiple threads during process
startup (here: fhandler_fifo::fixup_after_{fork,exec}) which in turn
allocate memory via malloc.

The problem is concurrent usage of malloc before the malloc muto has
been initialized.

To fix this issue, split malloc_init into malloc_init_0, called from
dll_crt0_0, and malloc_init_1, called from dll_crt_0_1.  malloc_init_0
just initializes the muto, malloc_init_1 checks for user space provided
malloc.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-10-28 22:35:17 +02:00
Corinna Vinschen 462ca33745 Revert "Cygwin: convert malloc lock to SRWLOCK"
This reverts commit 44a79a6eca.
2021-10-28 20:44:27 +02:00
Corinna Vinschen 3860338968 Cygwin: bump DLL minor version
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-10-28 13:41:19 +02:00
Corinna Vinschen 44a79a6eca Cygwin: convert malloc lock to SRWLOCK
Per https://cygwin.com/pipermail/cygwin-developers/2021-October/012429.html,
we may encounter a crash when starting multiple threads during process
startup (here: fhandler_fifo::fixup_after_{fork,exec}) which in turn
allocate memory via malloc.

The problem is concurrent usage of malloc before the malloc muto has
been initialized.

To fix this issue, convert the muto to a SRWLOCK and make sure it is
statically initalized.  Thus, malloc can be called as early as necessary
and malloc_init is only required to check for user space provided malloc.

Note that this requires to implement a __malloc_trylock macro to be
called from fork.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-10-26 18:47:22 +02:00
Mark Geisert 23b1400f83 Cygwin: Make native clipboard layout same for 32- and 64-bit
This patch unifies the layout of the clipboard descriptor cygcb_t for
32- and 64-bit Cygwin.  It allows correct copy/paste between the two
environments without corruption of user's copied data and without access
violations due to interpreting that data as a size field.

The definitions of CYGWIN_NATIVE and cygcb_t are moved to a new include
file, sys/clipboard.h.  The include file is used by fhandler_clipboard.cc
as well as getclip.c and putclip.c in the Cygwin cygutils package.

When copy/pasting between 32- and 64-bit Cygwin environments, both must
be running version 3.3.0 or later for successful operation.
2021-10-26 12:42:21 +02:00
Ken Brown 65d6818661 Cygwin: document sig2str and str2sig in version.h 2021-10-22 13:56:05 -04:00
Corinna Vinschen cb21b9cc57 Cygwin: drop outdated -O3 optimization for malloc and sync
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-10-22 12:47:09 +02:00
Corinna Vinschen 548f124698 Cygwin: update cygcheck OS information
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-10-21 18:33:35 +02:00
Takashi Yano 745b547ebd Cygwin: pipe: Use NtQuerySystemInformation() instead of EnumProcesses().
- Using EnumProcess() breaks Windows Vista compatibility. This patch
  replaces EnumProcesses() with NtQuerySystemInformation().

Addresses:
https://cygwin.com/pipermail/cygwin-developers/2021-October/012422.html
2021-10-19 11:09:47 +02:00
Takashi Yano dcd564f65c Cygwin: pty: Fix handle leak regarding attach_mutex.
- If the process having master pty opened is forked, attach_mutex
  fails to be closed when master is closed. This patch fixes the
  issue.
2021-10-10 08:57:51 -04:00
Takashi Yano 8a09deb1b7 Cygwin: pty: Fix master closing error regarding attach_mutex.
- If two or more pty masters are opened in a process, closing master
  causes error when closing attach_mutex. This patch fixes the issue.

Addresses:
https://cygwin.com/pipermail/cygwin-developers/2021-October/012418.html
2021-10-08 13:27:50 -04:00
Takashi Yano 6c1f49f83f Cygwin: pipe: Use ProcessHandleInformation if available.
- The commit b531d6b0 introduced temporary_query_hdl() which uses
  SystemHandleInformation. With this patch, ProcessHandleInformation
  rather than SystemHandleInformation is used if it is available.
  This request is faster, however, is only available since Windows 8,
  therefore, SystemHandleInformation is used for Windows Vista and 7
  as before.
2021-09-23 12:24:19 -04:00
Takashi Yano b531d6b06e Cygwin: pipe: Introduce temporary query_hdl.
- The commit f79a4611 introduced query_hdl, which is the read pipe
  handle kept in the write pipe instance in order to determine if
  the pipe is ready to write in select().  This implementation has
  a potential risk that the write side fails to detect the closure
  of the read side if more than one writer exists and one of them
  is a non-cygwin process.

  With this patch, the strategy of commit f79a4611 is used only if
  the process is running as a service.  For a normal process,
  instead of keeping query_hdl in the write pipe instance, it is
  retrieved temporarily when select() is called.  Actually, we
  want to use tenporary query_hdl for all processes, however, it
  does not work for service processes due to OpenProcess()
  failure.
2021-09-21 14:47:33 -04:00
Ken Brown 643db9ec9e Cygwin: pipes: remove unnecessary NULL checks for hdl_cnt_mtx
In view of the previous changes to open_setup, we can always assume
that hdl_cnt_mtx is non-NULL.
2021-09-18 09:25:20 -04:00
Ken Brown be08c5c40b Cygwin: make callers of open_setup check for failure
open_setup is called by dtable::init_std_file_from_handle and
fhandler_base::open_with_arch.  In both cases, failure of open_setup
is now a fatal error.

Currently this can only happen in the following situation: A Cygwin
process is started by a non-Cygwin process, one of the standard IO
handles is a pipe handle, and Cygwin is unable to create a required
mutex (read_mtx or hdl_cnt_mtx).
2021-09-18 09:10:23 -04:00
Ken Brown 6fc0aa8e5d Cygwin: fhandler_pipe::open_setup: fail on error creating mutexes 2021-09-18 08:49:06 -04:00
Ken Brown e5fcb021cc Cygwin: allow open_setup to fail
Convert fhandler_base::open_setup to a (virtual) method that returns a
bool result.  For the moment, it and its overrides always return true.
2021-09-18 08:40:11 -04:00
Ken Brown 9b0841aa78 Cygwin: statically link the tools in winsup/utils/mingw
This fixes the problem reported here:

  https://cygwin.com/pipermail/cygwin-developers/2021-September/012375.html
2021-09-17 21:38:07 -04:00
Ken Brown 98859e00d0 Cygwin: fix typos in release notes 2021-09-17 16:16:14 -04:00
Takashi Yano 9814cfd8f6 Cygwin: pipe, fifo: Move query_hdl and hdl_cnt_mtx to fhandler_pipe.
- query_hdl and hdl_cnt_mtx are moved from fhandler_pipe_fifo to
  fhandler_pipe. Then reader_closed() is changed to virtual and
  overridden in fhandler_pipe.
2021-09-16 15:53:57 -04:00
Takashi Yano 199482654b Cygwin: pipe: Fix race issue regarding handle count.
- This patch fixes the race issue in the handle counting to detect
  closure of read pipe, which is introduced by commit f79a4611.
  A mutex hdl_cnt_mtx is introduced for this issue.
2021-09-16 10:57:36 -04:00
Takashi Yano d8614e355d Cygwin: pipe: Fix error handling in fhandler_pip::create().
- Currently, error handling in fhandler_pipe::create() is broken.
  This patch fixes that.
2021-09-16 10:57:24 -04:00
Takashi Yano 350806f882 Cygwin: close_all_files: Do not duplicate stderr for write pipe.
- Currently, the stderr handle is duplicated in close_all_files().
  This interferes the handle counting for detecting closure of read
  pipe, which is introduced by commit f79a4611. This patch stops
  duplicating stderr handle if it is write pipe.
2021-09-16 10:57:14 -04:00
Ken Brown 18fab2f834 Cygwin: select: check for negative return from pipe_data_available
Make sure except_ready is set (if except_selected) on a negative
return from pipe_data_available.
2021-09-16 08:53:40 -04:00
Corinna Vinschen 34b1447040 Cygwin: pipes: don't call NtQueryInformationFile on read side of pipes
NtQueryInformationFile hangs if it's called on the read side handle of
a pipe while another thread or process is performing a blocking read.

Avoid select potentially hanging by calling NtQueryInformationFile
only on the write side of the pipe and using PeekNamedPipe otherwise.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-15 14:20:03 +02:00
Corinna Vinschen f961a63ed6 Cygwin: drop useless method fhandler_base::has_ongoing_io
This was a remnant of the fhandler_base_overlapped class.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-15 13:58:36 +02:00
Takashi Yano 00cbbaa33e Cygwin: pipe: Do not call PeekNamedPipe() if it is not necessary.
- In pipe_data_available() in select.cc, PeekNamedPipe() call is
  not needed if WriteQuotaAvailable is non-zero because we already
  know the write pipe has a space. Therefore, with this patch,
  PeekNamedPipe() is called only when WriteQuotaAvailable is zero.
  This makes select() on pipe faster a bit.
2021-09-15 11:29:27 +02:00
Ken Brown 593a86f9b0 Cygwin: document the recent pipe changes 2021-09-14 14:59:28 -04:00
Takashi Yano a217fa98fd Cygwin: pipe: Fix handling of EPIPE and SIGPIPE in raw_write(). 2021-09-14 16:16:15 +02:00
Takashi Yano e4e4537979 Cygwin: pipe, fifo: Release select_sem semaphore as much as needed.
- Currently, raw_read(), raw_write() and close() release select_sem
  unconditionally even if no waiter for select_sem exists. With this
  patch, only the minimum number of semaphores required is released.
2021-09-14 13:02:51 +02:00
Takashi Yano f79a46112e Cygwin: pipe: Use read pipe handle for select() on write pipe.
- Usually WriteQuotaAvailable retrieved by NtQueryInformationFile()
  on the write side reflects the space available in the inbound buffer
  on the read side. However, if a pipe read is currently pending,
  WriteQuotaAvailable on the write side is decremented by the number
  of bytes the read side is requesting. So it's possible (even likely)
  that WriteQuotaAvailable is 0, even if the inbound buffer on the
  read side is not full. This can lead to a deadlock situation:
  The reader is waiting for data, but select on the writer side
  assumes that no space is available in the read side inbound buffer.

  Currently, to avoid this stuation, read() does not request larger
  block than pipe size - 1. However, this mechanism does not take
  effect if the reader side is non-cygwin app.

  The only reliable information is available on the read side, so
  fetch info from the read side via the pipe-specific query handle
  (query_hdl) introduced.

  If the query_hdl (read handle) is kept in write side, writer can
  not detect closure of read pipe. Therefore, raw_write() counts
  write handle and query_hdl. If they are equal, only the pairs of
  write handle and query_hdl are alive. In this case, raw_write()
  returns EPIPE and raises SIGPIPE.

- Nonblocking pipes (PIPE_NOWAIT) are not well handled by non-Cygwin
  tools, so convert pipe handles to PIPE_WAIT handles when spawning
  a non-Cygwin process.
2021-09-14 13:01:40 +02:00
Takashi Yano 0d12015670 Cygwin: pipe, fifo: Call set_no_inheritance() for adjunct handles.
- Currntly, set_no_inheritance() is not called for the adjunct handles
  such as select_sem. This patch fixes the issue.
2021-09-14 10:22:15 +02:00
Takashi Yano 3e80b12fde Cygwin: fhandler_base::dup Reflect O_CLOEXEC to inheritance flag.
- Currently fhandler_base::dup duplicates handles with bInheritHandle
  TRUE unconditionally. This patch reflects O_CLOEXEC flag to that
  parameter.
2021-09-14 10:22:15 +02:00
Corinna Vinschen 8985f1c7c4 Cygwin: pipes: do not duplicate sec_none{_nih} locally when creating objects
We already fetched the correct SECURITY_ATTRIBUTES at the start of
fhandler_pipe::create, so using another SECURITY_ATTRIBUTES object for
the mutex and semaphore objects doesn't make much sense.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 22:04:04 +02:00
Corinna Vinschen c48361ad9e Cygwin: fix inheritence of select_sem on write side of pipe
select_sem gets created on the read side with inheritence settings
depending on the O_CLOEXEC flag.  Then it gets duplicated to the write
side with unconditional inheritence.  Fix that.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 19:34:07 +02:00
Takashi Yano 0063ffeb73 Cygwin: pipe: Fix deadlock if pipe is created by non-cygwin app. 2021-09-13 17:45:55 +02:00
Takashi Yano 0b538118b2 Cygwin: fifo: Utilize select_sem for fifo as well as pipe. 2021-09-13 17:45:55 +02:00
Corinna Vinschen ba4c58299f Cygwin: pipes: always signal select_sem if any bytes are read or written
Fold all code branches potentially having read or written data into
a single if branch, so signalling select_sem catches all cases.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:55 +02:00
Takashi Yano 08b8534d0a Cygwin: pipe: Fix notification timing of select_sem.
- Make select_sem notify even when read/write partially.
2021-09-13 17:45:54 +02:00
Takashi Yano 597f87294d Cygwin: select: Introduce select_sem semaphore for pipe.
- This patch introduces select_sem semaphore which notifies pipe status
  change.
2021-09-13 17:45:54 +02:00
Takashi Yano b07660ac19 Revert "Cygwin: select: Improve select/poll response."
... because this commit (23bb19ef) causes high CPU load.
2021-09-13 17:45:54 +02:00
Ken Brown 99be238347 Cygwin: set buffer size for pipes created by non-Cygwin processes
Rename fhandler_pipe_and_fifo::max_atomic_write to pipe_buf_size.
This reflect its actual meaning better.  The fhandler_pipe_and_fifo
constructor initializes it to DEFAULT_PIPEBUFSIZE (== 64K), which is
the buffer size for the windows pipes created by fhandler_pipe and
fhandler_fifo.  But if we inherit a stdio pipe handle from a
non-Cygwin process, the buffer size could be different.

To remedy this, add a method fhandler_pipe::set_pipe_buf_size that
queries the OS for the pipe buffer size, and use it in
dtable::init_std_file_from_handle.
2021-09-13 17:45:54 +02:00
Corinna Vinschen 27b24069d1 Cygwin: pipes: drop "tiny pipe" handling
Given we return 1 already if WriteQuotaAvailable is > 0, the condition
for tiny pipes is never true.  Fix the comments.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:54 +02:00
Corinna Vinschen 9d7fd8d416 Cygwin: pipes: handle signals and thread cancellation in blocking mode only
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:54 +02:00
Corinna Vinschen 4003e3dfa1 Cygwin: pipes: always terminate async IO in blocking mode
In blocking mode, the underlying IO must always be terminated,
one way or the other, to make sure the application knows the exact
state after returning from the IO function.  Therefore, always call
CancelIo in blocking mode.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:54 +02:00
Corinna Vinschen 477a593693 Cygwin: pipes: cancel async IO if thread cancellation is in progress
Just cancelling a thread doesn't cancel async IO started by this thread.
Fix this by returning from cygwait and calling CancelIo before canceling
self.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:54 +02:00
Takashi Yano fadbedd9ca Cygwin: pipe: Stop counting reader and read all available data.
- By guarding read with read_mtx, no more than one ReadFile can
  be called simultaneously. So couting read handles is no longer
  necessary.
- Make raw_read code as similar as possible to raw_write code.
2021-09-13 17:45:54 +02:00
Ken Brown 085fc12948 Cygwin: new class fhandler_pipe_fifo
This is a parent of fhandler_pipe and fhandler_fifo for code that is
common between the two classes.  Currently it just contains
max_atomic_write and raw_write().  The latter is identical to what
used to be fhandler_pipe::raw_write().
2021-09-13 17:45:54 +02:00
Ken Brown eb50f82677 Cygwin: FIFO: open pipes with FILE_READ_ATTRIBUTES access
This is needed by NtQueryInformationFile, which is used by select.
2021-09-13 17:45:54 +02:00
Ken Brown 44693e80b1 Cygwin: pipes: minor code cleanup
Clarify a comment in raw_read, and remove a useless line from
raw_write.
2021-09-13 17:45:54 +02:00
Corinna Vinschen 82643bd18e Cygwin: pipes: nt_create: set read handle to NULL in error case
Fix accidentally setting read handle to INVALID_HANDLE_VALUE in a
single error case.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:54 +02:00
Corinna Vinschen ea9c0bbedc Cygwin: pipes: call nt_create with handle references
...to avoid potential pointer mishandling.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:54 +02:00
Corinna Vinschen 8653eb1df3 Cygwin: pipes: workaround unrelibale system info
FILE_PIPE_LOCAL_INFORMATION::WriteQuotaAvailable is unreliable.

Usually WriteQuotaAvailable on the write side reflects the space
available in the inbound buffer on the read side.  However, if a
pipe read is currently pending, WriteQuotaAvailable on the write side
is decremented by the number of bytes the read side is requesting.
So it's possible (even likely) that WriteQuotaAvailable is 0, even
if the inbound buffer on the read side is not full.  This can lead to
a deadlock situation: The reader is waiting for data, but select
on the writer side assumes that no space is available in the read
side inbound buffer.

This patch implements a workaround by never trying to read more than
half the buffer size blocking if the read buffer is empty.  This first
cut tries to take the number of open readers into account by reducing
the amount of requested bytes accordingly.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:54 +02:00
Corinna Vinschen a5b2c735e6 Cygwin: pipes: fix POSIX requirement for non-blocking pipe writes
POSIX requires atomicity for non-blocking writes <= PIPE_BUF bytes
and writing of at least 1 byte if any buffer space is left.
Windows NtWriteFile returns STATUS_SUCCESS and "0 bytes written"
if the write doesn't match buffer space.  Fix this discrepancy.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:54 +02:00
Corinna Vinschen fcccc4b743 Cygwin: pipes: create pipes with synchronization enabled
This isn't used by Cygwin, but it might be used by Win32 processes
inheriting the handle.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:54 +02:00
Corinna Vinschen 8efcee2500 Cygwin: pipes: use NtClose when file has been opened with an NtXxx function
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:54 +02:00
Corinna Vinschen b12cf6b3cf Cygwin: pipes: always close read side pipe handle in error case
Add missing CloseHandle.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:54 +02:00
Corinna Vinschen 464f7145f6 Cygwin: pipes: fix a bug in raw_write
The buffer pointer is incremented by "chunk", which is what we
typically try to write, but this isn't what actually got written.
Increment the buffer pointer by what we actually wrote, as returned
by NtWriteFile.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:54 +02:00
Corinna Vinschen e9d4cb765f Cygwin: move get_obj_handle_count() to miscfuncs.cc
get_obj_handle_count() is used in flock only so far, but pipe
handling might have a usage, too, soon.  Given that this function
might be generally useful and isn't restricted to flock usage,
move it to miscfuncs.cc and make it non-static.  Add a prototype
in miscfuncs.h.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:54 +02:00
Corinna Vinschen 9cfbb5aa82 Cygwin: _pipe: add a comment
I wasted valuable minutes of my life just to find out why we export
this weird version of pipe.  In the pre-2000 era the idea was Cygwin
could be used as drop-in replacement for msvcrt.dll, apparently.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-13 17:45:53 +02:00
Corinna Vinschen 28eac9272f Revert "Cygwin: fhandler_pipe.cc:nt_select: fix flags"
This reverts commit a62f4d128505481c4c683e813a3b16da641af6ff.
2021-09-13 17:45:53 +02:00
Corinna Vinschen 71f02bcc3f Revert "Cygwin: fhandler_pipe.cc:nt_select: fix flags again"
This reverts commit c35db324efb5cdc6605eac947e0d4fdeb45e8b43.
2021-09-13 17:45:53 +02:00
Ken Brown 6b52d97900 Cygwin: fhandler_pipe.cc:nt_select: fix flags again 2021-09-13 17:45:53 +02:00
Ken Brown 9d4e58be76 Cygwin: fhandler_pipe.cc:nt_select: fix flags 2021-09-13 17:45:53 +02:00
Ken Brown 24b7a74b94 Revert "Cygwin: pipe: Revert to create() rather than nt_create()."
This reverts commit 5a7a0d34c74a55aa1e76644e61bf4889051cb640.
2021-09-13 17:45:53 +02:00
Takashi Yano cf3a7a9132 Cygwin: pipe: Revert to create() rather than nt_create(). 2021-09-13 17:45:53 +02:00
Takashi Yano b75d855fb0 Cygwin: select: Improve select/poll response. 2021-09-13 17:45:53 +02:00
Ken Brown 8a10f6302c Cygwin: add fhandler_base::npfs_handle
It replaces the three identical functions of the same name in the
classes fhandler_pipe, fhandler_fifo, and fhandler_socket_unix.
2021-09-13 17:45:53 +02:00
Ken Brown f002d02b17 Cygwin: remove the fhandler_base_overlapped class
Also remove the 'was_nonblocking' flag, which was needed only for
fhandler_base_overlapped.
2021-09-13 17:45:53 +02:00
Ken Brown f56206cd86 Cygwin: fhandler_pipe: fix permission problem
The read handles of pipes created by CreateNamedPipe don't have
FILE_WRITE_ATTRIBUTES access unless the pipe is created with
PIPE_ACCESS_DUPLEX.  This causes set_pipe_non_blocking to fail on such
handles.  To fix this, add a helper function nt_create, which uses
NtCreateNamedPipeFile instead of CreateNamedPipe and gives us more
flexibility in setting access rights.

Use this helper function in fhandler_pipe::create (fhandler_pipe *[2],
unsigned, int), which is the version of fhandler_pipe::create used by
the pipe and pipe2 system calls.

For convenience, also add a static member function
fhandler_pipe::npfs_handle similar to those used by fhandler_fifo and
fhandler_socket_unix.
2021-09-13 17:45:53 +02:00
Ken Brown d0ad52aa6e Cygwin: fhandler_pipe: control blocking mode of the Windows pipe
Add methods 'set_pipe_non_blocking' and 'fcntl' to keep the blocking
mode of the Windows pipe in sync with that of the fhandler_pipe
object.  This applies to pipes created with the 'pipe' and 'pipe2'
system calls.
2021-09-13 17:45:53 +02:00
Ken Brown 4b25687ea3 Cygwin: fhandler_pipe: add raw_read and raw_write 2021-09-13 17:45:53 +02:00
Ken Brown 72e083c4a0 Cygwin: fhandler_pipe: derive from fhandler_base
Previously fhandler_pipe was derived from fhandler_base_overlapped,
which we are going to remove in a future commit.  Make minimal changes
so that the build still succeeds.
2021-09-13 17:45:53 +02:00
Corinna Vinschen 8fba45f0cc Cygwin: fix initializing MEM_EXTENDED_PARAMETER, take 2
In https://cygwin.com/pipermail/cygwin/2021-September/249361.html
Brian pointed out that initializing the structure would be more
future proof, should the developers at Microsoft ever decide to
split the Reserved field and use some bits of the struct for
other purposes.

Fixes: 3d322ac930 ("Cygwin: fix initializing MEM_EXTENDED_PARAMETER")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-08 10:07:46 +02:00
Takashi Yano b52f10c4ca Cygwin: pty: Fix error handling of master write().
- Currently, error handling of write() in pty master side is broken.
  This patch fixes that.
2021-09-07 20:21:18 +02:00
Corinna Vinschen 3d322ac930 Cygwin: fix initializing MEM_EXTENDED_PARAMETER
MEM_EXTENDED_PARAMETER consists of a 64 bit bitfield which contains
the Type and the Reserved members.  The former usage of designated
initializer lists initialized Type, but not Reserved.  Since that's
not possible anymore due to a g++ 11.2 bug, Cygwin initializes the
MEM_EXTENDED_PARAMETER structs explicitely.  This results in a
random value in Reserved, which at least VirtualAlloc2 chokes on
(ERROR_INVALID_PARAMETER).

Set Reserved explicitely to 0 for a fix.

Fixes: bdb7991db3 ("Cygwin: workaround a g++ 11.2 initialization bug")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-06 20:28:34 +02:00
Corinna Vinschen eeeb5650cf Cygwin: fix declaration of RtlInitEmptyUnicodeString
This avoids "-Werror=maybe-uninitialized" errors due to
using WCSTR accidentally.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-03 13:16:48 +02:00
Corinna Vinschen d5cc66426b Cygwin: testsuite: avoid "conflicting types" gcc warning
With gcc 11.2:

test.h:50:5: warning: conflicting types for built-in function ‘execve’; expected ‘int(const char *, char * const*)’ [-Wbuiltin-declaration-mismatch]
test.h:51:5: warning: conflicting types for built-in function ‘execv’; expected ‘int(const char *, char * const*)’ [-Wbuiltin-declaration-mismatch]
test.h:52:5: warning: conflicting types for built-in function ‘execvp’; expected ‘int(const char *, char * const*)’ [-Wbuiltin-declaration-mismatch]

Fix prototypes accordingly.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-03 12:15:53 +02:00
Corinna Vinschen 9069cb9171 Cygwin: dup: fix handle inheritence for disk file pread/pwrite handle
The handle is created non-inheritable but gets inheritable when
dup'ing the file descriptor.  Fix that.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-08-30 21:56:33 +02:00
Corinna Vinschen 801120c1f4 Cygwin: loader script: add DWARF 5 sections
Modern gcc's generate additional DWARF 5 debug sections, which were
still missing in our Cygwin loader script.  With ld from binutils 2.37,
this results in diagnostic output when linking the Cygwin DLL...

  ld: cygwin0.dll:/4: section below image base
  ld: cygwin0.dll:/20: section below image base
  ld: cygwin0.dll:/36: section below image base

...and the section addresses given to these sections (.debug_loclists,
.debug_rnglists, debug_line_str) will be wrong.

Fix this by adding the missing DWARF 5 sections to our linker script
template cygwin.sc.in.  Add a comment in terms of the deprecated
DWARF 4 section .debug_types.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2021-08-27 14:27:41 +02:00
Corinna Vinschen 88c0276358 Cygwin: Allow using CFLAGS also for C++ files
This was used before switching to automake to allow easy tweaking
of optimization and debugging settings from the command line during
testing.  Reenable.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-08-26 22:21:53 +02:00
Corinna Vinschen bdb7991db3 Cygwin: workaround a g++ 11.2 initialization bug
trying to use aggregate initialization syntax on a member of a
nameless union member failes in g++ 11.2.

Workaround this by using explicit initialization.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-08-26 22:21:45 +02:00
Corinna Vinschen 3ca80b360c Cygwin: dumper: fix up GCC pragma for g++ 11.2
The GCC diagnostic ignored "-Wstringop-overflow" pragma doesn't work
as expected anymore.  Use the still working expression.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-08-26 22:15:49 +02:00
Corinna Vinschen 8169e39abf Cygwin: C++17: register keyword is deprecated
The register keyword was already deprecated with C++11, but
with C++17 it has been entirely removed.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-08-26 22:14:11 +02:00
Aleksand Malikov 1a821390d1 fix race condition in List_insert
Revert mx parameter and mutex lock while operating the list.
Mutex was removed with 94d24160 informing that:
'Use InterlockedCompareExchangePointer to ensure race safeness
without using a mutex.'

But it does not.

Calling pthread_mutex_init and pthread_mutex_destroy from two or
more threads occasionally leads to hang in pthread_mutex_destroy.

To not change the behaviour of other cases where List_insert was called,
List_insert_nolock is added.
2021-08-23 19:36:10 +02:00
Corinna Vinschen 5036d447c5 Cygwin: fhandler_procsys::readdir: fix NtQueryDirectoryObject usage
As outlined in the previous patch, the non-atomicity of iterating
over a directory in the NT namespace via NtQueryDirectoryObject
one entry each, results in potential duplication of directory entries.

Fix this for fhandler_procsys::readdir as well by fetching the entire
dir inside fhandler_procsys::opendir, storing it in a buffer, and just
return buffer content from fhandler_procsys::readdir.

Fixes: 43f65cdd7d ("fhandler_procsys.cc: New file.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-08-19 21:17:11 +02:00
Corinna Vinschen 2f05de4dbf Cygwin: fix all usages of NtQueryDirectoryObject
Due to reports on the Cygwin mailing list[1][2], it was uncovered
that a NtOpenDirectoryObject/NtQueryDirectoryObject/NtClose sequence
with NtQueryDirectoryObject iterating over the directory entries,
one entry per invocation, is not running atomically.  If new entries
are inserted into the queried directory, other entries may be moved
around and then accidentally show up twice while iterating.

Change (almost) all NtQueryDirectoryObject invocations so that it gets
a really big buffer (64K) and ideally fetches all entries at once.
This appears to work atomically.

"Almost" all, because fhandler_procsys::readdir can't be easily changed.

[1] https://cygwin.com/pipermail/cygwin/2021-July/248998.html
[2] https://cygwin.com/pipermail/cygwin/2021-August/249124.html

Fixes: e9c8cb3193 ("(format_proc_partitions): Revamp loop over existing harddisks by scanning the NT native \Device object directory and looking for Harddisk entries.")
Fixes: a998dd7055 ("Implement advisory file locking.")
Fixes: 3b7cd74bfd ("(winpids::enum_processes): Fetch Cygwin processes from listing of shared cygwin object dir in the native NT namespace.")
Fixes: 0d6f2b0117 ("syscalls.cc (sync_worker): Rewrite using native NT functions.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-08-19 16:42:23 +02:00
Corinna Vinschen ad35bfbb0f Cygwin: return better inode numbers for block device entries in /proc/sys
Commit 3434d35a64 fixed a problem when
accessing block devices via their /proc/sys/Device entries.  This
changed the way stat info is generated for these devices, resulting
in identical inode numbers for all block devices under /proc/sys/Device.

This patch fixes that by faking a device number for these devices, just as
before.

Fixes: 3434d35a64 ("Cygwin: Fix access to block devices below /proc/sys.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-08-19 16:08:34 +02:00
Mark Geisert 94ead7b76d Cygwin: More profiler format + small issue fixes
Make sure to cast to ulong all DWORD values displayed with format "%lu".
More instances are fixed here than in either my earlier unused patch or
Corinna's patch. I decided to use typedef..ulong for more compact code.

Address jturney's reported small issues:
- Remove explicit external ref for cygwin_internal() as it is already
  provided by <sys/cygwin.h>.
- Leave intact ref for cygwin_dll_path[] as it is required by function(s)
  in path.cc that profiler uses. Added comment to that effect.
- Delete existing main() wrapper. Rename main2() to main(). This because
  profiler is now a Cygwin program and doesn't need to dynamically load
  cygwin1.dll.
- Documentation issues will be addressed in a separate xml patch.

(I would have linked message-ids of Corinna's and Jon's messages for
proper theading but I no longer have their original emails and the mail
archives don't show msgids any more.)
2021-08-03 10:05:50 +02:00
Mark Geisert 99a4b087d4 Cygwin: Make gmondump conform to its doc + adjust doc
The doc for gmondump says 1 or more FILENAME are expected, but 0 is
handled. That's an oversight. Make invocation with 0 FILENAMEs print a
one-line help message.

Reword the beginning of profiler's description doc to clarify target's
child processes are run but only optionally profiled.
2021-08-03 10:00:56 +02:00
Corinna Vinschen 5970bbded8 Cygwin: export new sig2str/str2sig
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-08-02 13:57:03 +02:00
Corinna Vinschen cf9a51371c Cygwin: clarify importance of new GNU-specifc API
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-08-02 13:53:38 +02:00
Jon Turney 38965159df
Cygwin: Add winsymlinks:sys
Add winsymlinks:sys, to explicitly select always using plain files with
the system attribute containing a magic cookie to represent a symlink.
2021-07-30 15:48:26 +01:00
Jon Turney 66eefa25f2
Cygwin: Rename WSYM_sysfile to WSYM_default
Rename WSYM_sysfile to WSYM_default, since it selects more than just
sysfile with magic cookie now.
2021-07-30 15:48:21 +01:00
Corinna Vinschen 26d6595f54 Cygwin: add release msg for previous getaddrinfo patch
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-07-30 12:43:26 +02:00
Corinna Vinschen 582c7f9664 Cygwin: getaddrinfo: return valid ai_socktype and ai_protocol values
If a service is supported as TCP and UDP service, GetAddrInfo does not
return two entries, one for TCP, one for UDP, as on Linux.  Rather, it
just returns a single entry with ai_socktype and ai_protocol set to 0.
If the service only exists as TCP or UDP service, then ai->ai_socktype
is set, but ai_protocol isn't.

Fortunately we copy over the result from Windows into local storage
anyway, so this patch adds code to fix up the fields neglected by
Windows.  In case ai_socktype as well as ai_protocol are 0, duplicate
the entry with valid values for ai_socktype and ai_protocol.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-07-30 12:40:35 +02:00
Corinna Vinschen fff00f776b Cygwin: bump API minor and set DLL version to 3.3.0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-07-29 17:44:20 +02:00
Corinna Vinschen c2ad78d672 Cygwin: implement pthread_rwlock_clockrdlock/pthread_rwlock_clockwrlock
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-07-29 17:31:31 +02:00
Corinna Vinschen 520c3a3fa2 Cygwin: pthread.h: clean namespace
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-07-29 17:27:41 +02:00
Corinna Vinschen 5c4eaf45f1 Cygwin: implement pthread_mutex_clocklock
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-07-29 17:22:11 +02:00
Corinna Vinschen 123454f9d0 Cygwin: implement pthread_cond_clockwait
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-07-29 17:21:13 +02:00
Corinna Vinschen edf48054e9 Cygwin: implement sem_clockwait
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-07-29 17:13:47 +02:00
Corinna Vinschen d4e7869ee4 Cygwin: semaphore.h: clean namespace
use underscored identifiers

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-07-29 16:53:15 +02:00
Corinna Vinschen ad8730cc91 Cygwin: utils: refresh tzmap.h
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-07-28 22:19:37 +02:00
Corinna Vinschen 4f999b4eab Cygwin: utils: tzmap-from-unicode.org: enforce sorting order for LANG=C
Generating the tzmap.h file requires to use the default sorting order.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-07-28 22:18:38 +02:00
Jon Turney d930fbb6ae
Cygwin: Convert gmondump and profiler synopses to <cmdsynopsis>
Convert gmondump and profiler synopses to <cmdsynopsis>, since
addition of these crossed with e6b667f1.
2021-07-28 15:20:03 +01:00
Ken Brown f9f1b39180 Cygwin: document getifaddrs fixes 2021-07-28 07:44:25 -04:00
Ken Brown b88d686a68 Cygwin: getifaddrs: don't return a zero IPv4 address
If an interface is disconnected, net.cc:get_ifs tries to fetch IPv4
addresses from the registry.  If it fails, it currently returns
pointers to sockaddr structs with zero address.  Return a NULL pointer
instead, to signal the caller of getifaddrs that we do not have a
valid struct sockaddr.

Partially addresses: https://cygwin.com/pipermail/cygwin/2021-July/248970.html
2021-07-28 07:37:43 -04:00
Ken Brown c08ee10d6b Cygwin: getifaddrs: fix address family for IPv6 netmasks
The code in net.cc:get_ifs that sets the netmask omitted setting the
address family in the IPv6 case.  Fix this by setting it to AF_INET6.

Partially addresses: https://cygwin.com/pipermail/cygwin/2021-July/248970.html
2021-07-28 07:37:43 -04:00
David Allsopp 51a297bcbf Ensure nanosleep(2) never returns negative rem
It appears to be the case that NtQueryTimer can return a negative time
remaining for an unsignalled timer. The value appears to be less than
the timer resolution.

Signed-off-by: David Allsopp <david.allsopp@metastack.com>
2021-07-22 09:57:40 +02:00
Corinna Vinschen bf8f2a95df Cygwin: profiler: Fix formatting warnings
DWORD has different types on 32 and 64 bit.  Use a common cast to
unsigned long to use %lu format for DWORD values throughout.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-07-21 10:07:22 +02:00
Mark Geisert ff9c2b3ab9
Cygwin: updates to wire in profiler, gmondump
These are updates to wire into the build tree the new tools profiler and
gmondump, and to supply documentation for the tools.

The documentation for profiler and ssp now mention each other but do not
discuss their similarities or differences.  That will be handled in a
future update to the "Profiling Cygwin Programs" section of the Cygwin
User's Guide, to be supplied.
2021-07-19 13:29:34 +01:00
Mark Geisert 4ad5b0ca31
Cygwin: New tool: gmondump
This new tool was formerly part of 'profiler' but was spun out thanks to
Jon T's reasonable review comment.  Gmondump is more of a debugging tool
than something users might have need for.  Users would more likely use
gprof to make use of symbolic info like function names and source line
numbers.
2021-07-19 13:29:13 +01:00
Mark Geisert 9bd6c0b2b1
Cygwin: New tool: profiler
The new tool formerly known as cygmon is renamed to 'profiler'.  For the
name I considered 'ipsampler' and could not think of any others.  I'm open
to a different name if any is suggested.

I decided that a discussion of the pros and cons of this profiler vs the
existing ssp should probably be in the "Profiling Cygwin Programs" section
of the Cygwin User's Guide rather than in the help for either.  That
material will be supplied at some point.

CONTEXT buffers are made child-specific and thus thread-specific since
there is one profiler thread for each child program being profiled.

The SetThreadPriority() warning comment has been expanded.

chmod() works on Cygwin so the "//XXX ineffective" comment is gone.

I decided to make the "sample all executable sections" and "sample
dynamically generated code" suggestions simply expanded comments for now.

The profiler program is now a Cygwin exe rather than a native exe.
2021-07-19 13:28:37 +01:00
Ken Brown cee03513d8 Cygwin: cfsetspeed: allow speed to be a numerical baud rate
The Linux man page for cfsetspeed(3) specifies that the speed argument
must be one of the constants Bnnn (e.g., B9600) defined in termios.h.
But Linux in fact allows the speed to be the numerical baud rate
(e.g., 9600).  For consistency with Linux, we now do the same.

Addresses: https://cygwin.com/pipermail/cygwin/2021-July/248887.html
2021-07-12 16:26:13 -04:00
Jon Turney 9a231073a5
Cygwin: Define PSAPI_VERSION as 1 before including psapi.h
The default PSAPI_VERSION is controlled by WIN32_WINNT, which we set to
0x0a00 when building utils since 48a76190 (and is the default in w32api
>= 9.0.0)

In order for the built executables to run on Windows Vista, we must also
define PSAPI_VERSION as 1 (otherwise '#define GetModuleFileNameExA
K32GetModuleFileNameExA' causes a 'The procedure entry point
K32GetModuleFilenameExA could not be located in the dynamic link library
kernel32.dll' error at run time).

Also drop uneeded psapi.h from dlfcn.cc (31ddf45d), resource.cc
(34a6eeab) and ps.cc (1def2148).
2021-07-09 13:24:08 +01:00
Jon Turney e6b667f1a4
Cygwin: Use cmdsynopsis element in utils documentation
Use <cmdsynopsis> element markup in utils docbook documentation, rather
than some preformatted text inside <screen>.

(This didn't happen as part of 646745cb, when we first started using
refentry elements to make it possible to generate manpages)

This helps produce better looking manpages:

* uses bold (for command names) and italic (for replaceable items)
* different output formats inconsistently treat tabs inside <screen>
(so we have to be careful to not use them in that preformatted text)

Also clean up various issues:

* Replace '[OPTIONS]' with a real synopsis of the options
* Consistently use 'ITEM...' rather than 'ITEM1 [ITEM2...]' for an item
which should appear 1 or more times (cygcheck -f, getfacl, kill)
* Consistently document the '-h | -V' invocation form
* Since replaceable items are now marked up so they have some formatting
indicating they are replaceable, we can drop wrapping them in angle
brackets, as is done in some places
* Add missing '-W' and '-p PID' options to ps synopsis
* Adjust cygpath synopsis to show that only one 'System information'
option is allowed, possibly modified by -A

Future work:
* Sync up the actual help emitted by the util, where it's been improved
* Also don't use <screen> for formatting 'OPTIONS' section of manpage
* pldd inconsistently uses '-?' rather than '-h'!
2021-07-09 13:21:18 +01:00
Jon Turney be4a8b91ff
Cygwin: Various minor fixes to utils documentation
* Drop duplicate 'Options:' headers (mkgroup, mkpassword)
* Add missing indication that MACHINE is optional with -L (mkgroup, mkpassword)
* Tweak some <refpurpose> which try to be a synopsis, rather than a decription (passwd, ssp)
* Drop some stray '\n' in setfacl options
* Move 'Original Author' note in ssp to an AUTHORS section
* Use <para> to improve formatting of tzset manpage
2021-07-09 13:21:16 +01:00
Thomas Wolff 1290301b89 tty/pty: support TIOCSWINSZ pixel-size-only change notification
xterm 368 and mintty 3.5.1 implement a new feature to support
notification of terminal scaling via font zooming also if the terminal
text dimensions (rows/columns) stay unchanged, using
ioctl(TIOCSWINSZ), raising SIGWINCH;
this patches cygwin to support that scenario
2021-07-07 13:38:30 +02:00
Jeremy Drake 4fca7b0da6 Cygwin: respect PC_SYM_FOLLOW and PC_SYM_NOFOLLOW_REP with inner links.
The new GetFinalPathNameW handling for native symlinks in inner path
components is disabled if caller doesn't want to follow symlinks, or
doesn't want to follow reparse points.
2021-07-07 10:46:06 +02:00
Jeremy Drake d0e42141b8 Revert "Cygwin: Handle virtual drives as non-symlinks"
This reverts commit c8949d0400.
2021-07-06 16:57:02 +02:00
Brian Inglis 7323efd73c format_proc_cpuinfo: add Linux 5.13 AMD/Hygon rapl
Linux 5.13 Opossums on Parade added features and changes:
add AMD 0x80000007 EDX:14 rapl runtime average power limit
2021-07-06 16:06:29 +02:00
Takashi Yano 98e3aeb1f5 Cygwin: console: Fix garbled input for non-ASCII chars.
- After the commit ff4440fc, non-ASCII input may sometimes be garbled.
  This patch fixes the issue.

  Addresses: https://cygwin.com/pipermail/cygwin/2021-June/248775.html
2021-07-06 16:04:44 +02:00
Corinna Vinschen bc184284cb Revert "Cygwin: console: Fix garbled input for non-ASCII chars."
This reverts commit 1b242c12aa.
2021-07-06 16:04:22 +02:00
Takashi Yano 1b242c12aa Cygwin: console: Fix garbled input for non-ASCII chars.
- After the commit ff4440fc, non-ASCII input may sometimes be garbled.
  This patch fixes the issue.

  Addresses: https://cygwin.com/pipermail/cygwin/2021-June/248775.html
2021-07-06 16:00:20 +02:00
Mark Geisert 5c9c31c52b
Cygwin: Zero out gmon header before use
Tools that process gmon.out files can be confused by gmon header fields
with garbage in them due to lack of initialization.  Repair that.
2021-06-26 15:24:27 +01:00
Mark Geisert ee0986cfe1
Cygwin: Fix a stray tab in strace documentation 2021-06-13 15:51:11 +01:00
Ken Brown dfe5988f96 Cygwin: fhandler_mqueue::mq_open: fix typo 2021-05-26 12:48:58 -04:00
Corinna Vinschen fd84f6cf51 Cygwin: utils: enable -idirafter to fetch Cygwin headers from mingw sources
Get rid of the last dreaded relative paths pointing to the cygwin dir.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-26 11:01:32 +02:00
Corinna Vinschen 48a76190e8 Cygwin: utils: set _WIN32_WINNT and NTDDI_VERSION via Makefile
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-26 11:01:32 +02:00
Corinna Vinschen 88a2f9875a Cygwin: set NTDDI_VERSION to enable more recent windows definitions
Set to WDK_NTDDI_VERSION since that enables all the latest.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-26 11:01:32 +02:00
Corinna Vinschen 1adb3f11b7 Cygwin: fhandler_mqueue: add missing __reg2 for 32 bit build
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-26 11:01:32 +02:00
Corinna Vinschen 59ba43dd9e Cygwin: fhandler_mqueue: disable more methods, add fcntl
Unsupported functionality returns EPERM, fcntl supports
only F_GETFD and F_GETFL.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 23:00:32 +02:00
Corinna Vinschen 2b4c7f90d4 Cygwin: fhandler_mqueue::mq_open: set all required fhandler flags
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 22:43:41 +02:00
Corinna Vinschen fd3fb7a147 Cygwin: disable creating directories below /dev/mqueue
...as on Linux.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 22:05:13 +02:00
Corinna Vinschen 90e5dbfc24 Cygwin: fhandler_mqueue: fix method declarations
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 22:04:43 +02:00
Corinna Vinschen 782b338530 Cygwin: path_conv: fix mqueue path check
The check for a file or dir within /dev/mqueue is accidentally using
the incoming path, which could be a relative path.  Make sure to
restore the absolute POSIX path in path_copy and only then test the
path.

Also, move the actual check for a valid path below /dev/mqueue into
the fhandler_mqueue class.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 22:03:36 +02:00
Corinna Vinschen 4c09dc4f9c Cygwin: cwdstuff: check if /dev exists
/dev has been handled as virtual dir in cwdstuff, thus not allowing
to start native apps from /dev as CWD, even if /dev actually exists
on disk.  Unfortunately this also affects Cygwin executables started
from a debugger.

When chdir'ing to /dev, check if /dev exists on disk.  If so, treat
it as any other existing path.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 21:46:13 +02:00
Corinna Vinschen efef4b8bf1 Cygwin: POSIX msg queues: implement read(2)/lseek(2)
reuse fhandler_virtual implementation to implement read and lseek.
The output from read(2) is modelled after the output when reading
from an mq file on Linux.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 20:19:19 +02:00
Corinna Vinschen 517c7e79da Cygwin: POSIX msg queues: implement ioctl(2)
Call into fhandler_base::ioctl immediately, thus only allowing
FIONBIO to manipulate blocking behaviour.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 20:17:07 +02:00
Corinna Vinschen 46f3b0ce85 Cygwin: POSIX msg queues: move all mq_* functionality into fhandler_mqueue
The POSIX entry points are just wrappers now, calling into
fhandler_mqueue.  While at it, eliminate mqi_flags, replace with
standard fhandler nonblocking flag.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 20:15:16 +02:00
Corinna Vinschen e0cdd462f1 Cygwin: POSIX msg queues: allocate section views top down
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:55:38 +02:00
Corinna Vinschen fbcd61063b Cygwin: POSIX msg queues: Implement dup
Create a private method fhandler_mqueue::_dup and call it from
dup and fixup_after_fork methods.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:50:16 +02:00
Corinna Vinschen b62450cf17 Cygwin: POSIX msg queues: implement open/mq_open entirely in fhandler
The mq_open call is just a framework now.  This patch moves the
entire functionality into fhandler_mqueue.  To support standard
OS calls (as on Linux), make fhandler_mqueue a derived class from
fhandler_disk_file and keep the base handle the handle to the
default stream, to allow implementing O_PATH functionlaity as well
as reading from the file and NOT reading binary message queue data.

Implement a standard fhandler_mqueue::open method, allowing, for
instance, to touch a file under /dev/mqueue and if it doesn't exist,
to create a message queue file.

FIXME: This introduces a BAD HACK into path_conv::check, which needs
reviewing.

Keep the posix path intact in the fhandler, and change get_proc_fd_name
accordingly to return only the basename plus leading slash for
/proc/<PID>/fd.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:49:04 +02:00
Corinna Vinschen a4e074672a Cygwin: POSIX msg queues: slightly rephrase get_mqinfo
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:42:44 +02:00
Corinna Vinschen 2cc914a34e Cygwin: POSIX msg queues: simplify mq_close
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:41:45 +02:00
Corinna Vinschen 15c96f2b26 Cygwin: get_nt_native_path: allow to append suffix
POSIX message queues will be moved into NTFS streams.
Extend get_nt_native_path to provide a filename suffix which is not
subject to special character transposition, to allow specifying
a colon.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:31:26 +02:00
Corinna Vinschen 4ea7c12a20 Cygwin: POSIX msg queues: move definition of struct msg_hdr
...to mqueue_types.h header.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-25 16:17:58 +02:00
Corinna Vinschen 49b84cb264 Cygwin: POSIX msg queues: improve error output in fixup_after_fork
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-22 18:03:01 +02:00
Jon Turney a9c8050c36
Cygwin: Ensure PSAPI_VERSION is 1 when building ldd
The default PSAPI_VERSION is controlled by WIN32_WINNT, which we set to
0x0a00 when building ldd, which gets PSAPI_VERSION=2.

This causes K32GetModuleFileNameEx to be used for GetModuleFileNameEx,
which isn't available on Windows Vista.

Define PSAPI_VERSION as 1 for the built executable to work on Windows
Vista.
2021-05-22 16:06:51 +01:00
Corinna Vinschen bce3563e98 Cygwin: POSIX msg queues: destroy msg queue fhandler in case of error
...and don't leave a descriptor dangling

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 15:26:51 +02:00
Corinna Vinschen 723f38b10a Cygwin: POSIX msg queues: move handling of memory map into fhandler
This encapsulated creation, duplication, and closing of all
Windows objects connected to the message queue in the fhandler.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 15:25:37 +02:00
Corinna Vinschen 5b380b1ca6 Cygwin: POSIX ipc: fix evaluation of naming rules
The function evaluating correctness of ipc object names was a
bit half-hearted.  Fix the tests to follow more closely the
desriptions in the Linux man pages.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 15:21:29 +02:00
Corinna Vinschen 5f621bd38f Cygwin: posix_ipc.cc: fix typo
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 15:18:38 +02:00
Corinna Vinschen 65cb82839a Cygwin: POSIX msg queues: create fhandler with object name
build_fh_dev can take the POSIX object name as parameter anyway,
so use that and drop from mqinfo call.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 13:43:51 +02:00
Corinna Vinschen 3342549fcf Cygwin: POSIX msg queues: move IPC object creation into fhandler
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 13:43:51 +02:00
Corinna Vinschen 438764a9de Cygwin: fix formatting in mqueue_types.h
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 13:43:51 +02:00
Corinna Vinschen 6c901b928f Cygwin: POSIX msg queues: use queue name as key
Drop creating a unique ID, the queue name itself is already
unique.  This allows to move ipc object generation into the
fhandler in the next step.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 13:43:51 +02:00
Corinna Vinschen 4fc922b2c8 Cygwin: POSIX msg queues: Convert mqd_t to a descriptor
So far, the mqd_t type returned a pointer to an allocated
area under the hood.  The mutex and event objects attached
to the message queue were implemented as inheritable types.

As unfortunate side effect the HANDLEs to these objects
were inherited by exec'd child processes, even though all
other message queue properties are not inherted, per POSIX.

Fix this by converting an mqd_t to a descriptor, and create a
matching fhandler_mqueue object to handle various aspects of
the message queues inside the fhandler.  Especially, create the
IPC objects as non-inheritable and duplicate the HANDLEs as
part of the fixup_after_fork mechanism.

Drop using mmap and create the memory map with NT functions.
This allows to control duplication of handle and mapping in the
forked child process, without the requirement to regenerate the
map in the same spot.  It also allows to dup() the descriptor,
as on Linux, albeit this isn't implemented yet.

This patch is the first cut.  There's a bit more to do, like
moving more functionality from the POSIX functions into the
fhandler and making sure the mqd_t type can't be used in other
descriptor-related functions willy-nilly.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-21 13:43:24 +02:00
Christian Franke c0949782b7 Cygwin: utils: chattr: Allow to clear all attributes with '='.
Signed-off-by: Christian Franke <christian.franke@t-online.de>
2021-05-21 12:56:59 +02:00
Corinna Vinschen 6462a0844d Cygwin: utils: ldd: use GetFinalPathNameByHandleW
drop replacement function GetFileNameFromHandle which was
only required pre-Vista.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-20 23:07:05 +02:00
Corinna Vinschen 8c6c9b097d Cygwin: utils: avoid warning when building path_testsuite-path.o
Avoid this warning:

[...]/winsup/utils/mingw/../path.cc:569:1: warning: 'void read_mounts() ' defined but not used [-Wunused-function]
  569 | read_mounts ()
      | ^~~~~~~~~~~

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-20 22:47:44 +02:00
Corinna Vinschen 3053632389 Cygwin: utils: chattr: do not default to CWD
Drop the unexpected behaviour to run chattr in the CWD if no file has
been specified on the command line.  Bail out with usage info instead.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-20 22:39:25 +02:00
Corinna Vinschen f8eecf22db Cygwin: utils: chattr: fix recursive behaviour
chattr [mode] dir

incorrectly recurses one level into the given directory, even if the
--recursive option has not been used.  This patch adds a test to avoid
this bug.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-20 22:32:37 +02:00
Christian Franke cb674a4ad1 Cygwin: utils: chattr: Improve option parsing, fix some messages.
Allow multiple characters also in first '-mode' argument.
Use '-H' instead of '-h' for '--help' to fix ambiguity with
hidden attribute.  Fix help and usage texts and documentation.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
2021-05-20 22:29:58 +02:00
Corinna Vinschen 9b24fc9505 Cygwin: autoload: fix case in DLL name for sanity
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-20 10:04:07 +02:00
Corinna Vinschen 23d071229d Cygwin: Add missing IsWow64Process2 declaration
The previous patch is accidentally missing the declaration of
IsWow64Process2.  Add it belatedly.

Fixes: 1865a41cb383 ("Cygwin: suppress FAST_CWD warnings on ARM64")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-20 10:04:07 +02:00
Jeremy Drake 338548f82f Cygwin: suppress FAST_CWD warnings on ARM64
The old check was insufficient: new insider preview builds of Windows
allow running x86_64 process on ARM64.  The IsWow64Process2 function
seems to be the intended way to figure this situation out.
2021-05-19 14:40:51 +02:00
Jeremy Drake c8949d0400 Cygwin: Handle virtual drives as non-symlinks
This avoids MAX_PATH-related problems in native tools in case the
virtual drive points to a deep directory

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-19 14:40:51 +02:00
Corinna Vinschen 7b8edba625 Cygwin: POSIX message queues: simplify sync object creation
Introduce new inline function mq_ipc_init to create all three
required sync objects.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-12 11:04:44 +02:00
Jon Turney 71e8b45007
Get rid of relative include paths in strace.cc 2021-05-10 14:41:41 +01:00
Jon Turney b8bd9d1b01
Move source files used in utils/mingw/ into that subdirectory
Move all the source files used in utils/mingw/ into that subdirectory,
so the built objects are in the expected place.

(path.cc requires some more unpicking, and even then there is genuinely
some shared code, so use a trivial file which includes the real path.cc
so the object file is generated where expected)
2021-05-10 14:41:40 +01:00
Jon Turney 9ce70bf450
Unpick cygpath TESTSUITE
Rather than having testsuite.h do various things, depending on defines,
just have it do one thing, and then explicitly redirect to test stubs in
path.cc when building test.
2021-05-10 14:41:39 +01:00
Corinna Vinschen 44eb416323 Cygwin: fetch Windows directory on all platforms and use throughout
Rather than fetching the system Windows directory at dll init time
only on 32 bit, fetch it on all platforms.  Store as WCHAR and
UNICODE_STRING.  Use where appropriate to simplify code.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-07 23:05:24 +02:00
Corinna Vinschen 19d59ce75d Cygwin: path_conv: Rework handling native symlinks as inner path components
commit 456c3a4638 was only going half-way.  It handled symlinks and
junction points as inner path components and made realpath return the
correct path, but it ignored drive letter substitution, i. e., virtual
drives created with, e. g.

  subst X: C:\foo\bar

It was also too simple.  Just returning an error code from
symlink_info::check puts an unnecessary onus on the symlink evaluation
loop in path_conv::check.

Rework the code to use GetFinalPathNameByHandle, and only do this after
checking the current file for being a symlink failed.

If the final path returned by GetFinalPathNameByHandle is not the same
as the incoming path, replace the incoming path with the POSIXified
final path.  This also short-circuits path evaluation, because
path_conv::check doesn't have to recurse over the inner path components
multiple times if all symlinks are of a native type, while still getting
the final path as end result.

Virtual drives are now handled like symlinks.  This is a necessary change
from before to make sure virtual drives are handled identically across
different access methods.  An example is realpath(1) from coreutils.  It
doesn't call readlink(2), but iterates over all path components using
lstat/readlink calls.  Both methods should result in the same real path.

Fixes: 456c3a4638 ("path_conv: Try to handle native symlinks more sanely")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-07 22:52:16 +02:00
Corinna Vinschen 9ea0f37667 Cygwin: revert handwritten tags/ctags target, take 2
Fix accidental checkin of the wrong test version

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-06 13:35:26 +02:00
Corinna Vinschen a5b24cb241 Cygwin: revert handwritten tags/ctags target
Converting to automake dropped the former, handwritten tags/ctags
target.  This leads to a couple of problems:

- For no good reason the tags file gets written to the builddir
  instead of to the srcdir where it's needed.

- `make tags' requires etags to exist, rather than checking if it
  exists and skipping it.

- Adding the extra ctags arguments to AM_CTAGSFLAGS still results
  in a shortened tags file.

(Temporary?) solution: Revert the old tags/ctags rules and silence
the automake warnings.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-06 11:12:46 +02:00
Corinna Vinschen 895f6d2b59 Cygwin: autogen.sh: Allow running from any directory
autogen.sh expects to run from within the winsup dir, so
set CWD accordingly before running autotools.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-05-06 10:56:20 +02:00
Jon Turney b05b790689 Cygwin: Ensure toollibdir exists before installing a link there
This helps 'make install -j2' work.
2021-04-30 21:06:33 +02:00
Brian Inglis 6914b40c14 format_proc_swaps: ensure space between fields for clarity
page/swap space name >= 40 or size/used >= 8 leaves no space between fields;
ensure a space after name and add extra tabs after size and used fields;
output appears like Linux 5.8 after changes to mm/swapfile(swap_show);

proc-swaps-space-before.log:
==> /proc/swaps <==
Filename				Type		Size	Used	Priority
/mnt/c/pagefile.sys                     file            11567748292920  0
/mnt/d/pagefile.sys                     file            12582912205960  0

proc-swaps-space-after.log:
==> /proc/swaps <==
Filename				Type		Size		Used		Priority
/mnt/c/pagefile.sys			file		11567748	241024		0
/mnt/d/pagefile.sys			file		12582912	182928		0
2021-04-30 21:05:11 +02:00
Corinna Vinschen 715c4208e4 Cygwin: mq_open: set filesize using ftruncate
ftruncate is leaner than lseek/write.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-04-30 20:32:52 +02:00
Jon Turney 2d34164402
Cygwin: CI configuration update
Install autoconf and automake, and run winsup/autogen.sh, and don't have
it silently ignore failures.

On AppVeyor:
- use latest VM image, to reduce time spent installing updates.
- run the testsuite, but ignore the result, as some tests don't work
correctly.
- hardcode the python-lxml and python-ply packages to install, so we get
ones for the right python.
- install texlive collections now needed to build documentation.

On github:
- Use a copr for cocom, since RPMSphere's package updates don't track
fedora:latest very efficently.
2021-04-30 14:22:07 +01:00
Corinna Vinschen 548a4c3ca4 Cygwin: POSIX mq: avoid double calls to ipc_mutex_unlock
_mq_send as well as _mq_receive call ipc_mutex_unlock twice in case
of success, after having introduced __try/__except blocks.

Fixes: 3f3bd10104 ("* Throughout, use __try/__except/__endtry blocks, rather than myfault handler.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-04-30 10:30:21 +02:00
Corinna Vinschen 4f89f24fbe Cygwin: POSIX mq: only allo priority up to MQ_PRIO_MAX - 1
POSIX requires that message priorities range from 0 (low) to
sysconf(_SC_MQ_PRIO_MAX) - 1 (high).  Cygwin's mq_send erroneously
allowed a message priority of sysconf(_SC_MQ_PRIO_MAX).  Fix it.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-04-29 20:09:10 +02:00