Commit Graph

8585 Commits

Author SHA1 Message Date
Corinna Vinschen 5993fdab0b Revert "Cygwin: fix potential SEGV in sigwaitinfo/signalfd scenario"
This reverts commit 92115a83a4.

This was utterly wrong.
2020-10-14 10:53:59 -04:00
Takashi Yano fae6075d2d Cygwin: console: Fix the condition to interrupt select() by SIGWINCH
- Add code so that select() is not interrupted by SIGWINCH if it is
  ignored (SIG_IGN or SIG_DFL).
2020-10-14 10:53:58 -04:00
Takashi Yano e548c131d8 Cygwin: console: Fix workaround for horizontal tab position
- The workaround commit 33a21904a7
  does not work as expected if window size is changed while screen
  is alternated. Fixed.
2020-10-14 10:53:58 -04:00
Corinna Vinschen cb1469277a Cygwin: fix potential SEGV in sigwaitinfo/signalfd scenario
On sigwaitinfo or reading from a signalfd, signal processing sets up
signal handling via sigdelayed even if the handler address is NULL.
This doesn't have any impact on sigwaitinfo scenarios (or at least, I
wasn't able to come up with a reproducer) but it breaks signalfd
scenarios, where eventually a call to call_signal_handler from
sigdelayed will try to call the NULL function.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-10-14 10:53:58 -04:00
Takashi Yano aa058617e4 Cygwin: console: Fix cursor position restore after screen alternation.
- If screen is alternated on console, cursor position is not restored
  correctly in the case of xterm compatible mode is enabled. For example,
  the shell prompt is shown at incorrect position after using vim.
  This patch fixes this problem.
2020-10-14 10:53:58 -04:00
Takashi Yano 4348014d21 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.
2020-10-14 10:53:58 -04:00
Takashi Yano 72a762c36b 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.
2020-10-14 10:53:58 -04:00
Joel Sherrill 0efd05546a 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.
2020-10-14 10:53:58 -04:00
Corinna Vinschen 8f9ccad72c Cygwin: drop preliminary 3.0.8 release file
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-10-14 10:53:58 -04:00
Corinna Vinschen 5b50e403a4 Cygwin: add missing bugfix release messages for 3.1.0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-10-14 10:53:57 -04:00
Corinna Vinschen 13bcb08856 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.
2020-10-14 10:53:57 -04:00
Lavrentiev, Anton 332c11b97a Cygwin: getpriority() and top display for priority is inconsistent
Fix this by aligning /proc/[PID]/stat to the values returned by getpriority().
2020-10-14 10:53:57 -04:00
Michael Haubenwallner f5ffd27dc6 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)
2020-10-14 10:53:57 -04:00
Corinna Vinschen 4fe789e6c5 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>
2020-10-14 10:53:57 -04:00
Mark Geisert bb7eb423b2 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.
2020-10-14 10:53:57 -04:00
Michael Haubenwallner 721ed1f466 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
2020-10-14 10:53:57 -04:00
Michael Haubenwallner 8e4dc79301 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
2020-10-14 10:53:57 -04:00
Corinna Vinschen 4dd0d0b7dc 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>
2020-10-14 10:53:57 -04:00
Corinna Vinschen 86e4739e23 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>
2020-10-14 10:53:57 -04:00
Corinna Vinschen cea4d92780 Cygwin: Export newlib ndbm functions
Signed-off-by: Corinna Vinschen <corinna-cygwin@cygwin.com>
2020-10-14 10:53:57 -04:00
Ken Brown f5b381ff56 Cygwin: document the last bug fix 2020-10-14 10:53:56 -04:00
Ken Brown 53f657e4a6 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.
2020-10-14 10:53:56 -04:00
Ken Brown e3e9002520 Cygwin: fix one more check for positive virtual_ftype_t values
Also drop more comments referring to numerical virtual_ftype_t values.
2020-10-14 10:53:56 -04:00
Corinna Vinschen b2671d9e1c 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>
2020-10-14 10:53:56 -04:00
Corinna Vinschen 30b08fcbdb 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>
2020-10-14 10:53:56 -04:00
Ken Brown aeb38a24af Cygwin: add release notes for 3.0.8 2020-10-14 10:53:56 -04:00
Ken Brown ceca51fdde 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().
2020-10-14 10:53:56 -04:00
Ken Brown 3b23fe5d82 Cygwin: remove path_conv::is_fs_device()
It is used only once.
2020-10-14 10:53:56 -04:00
Ken Brown 0bb03f90e7 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.
2020-10-14 10:53:56 -04:00
Ken Brown eb171bc799 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.
2020-10-14 10:53:56 -04:00
Ken Brown 103f6a72a3 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.
2020-10-14 10:53:56 -04:00
Ken Brown a596f6e389 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.
2020-10-14 10:53:56 -04:00
Ken Brown aa6d3f0250 Cygwin: avoid GCC 8.3 errors with -Werror=stringop-truncation 2020-10-14 10:53:55 -04:00
Ken Brown 603b83eed7 Cygwin: avoid GCC 8.3 errors with -Werror=class-memaccess 2020-10-14 10:53:55 -04:00
Corinna Vinschen 5e3733ac79 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>
2020-10-14 10:53:55 -04:00
Corinna Vinschen 54eb35e966 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>
2020-10-14 10:53:55 -04:00
Mark Geisert 3988834ee1 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).
2020-10-14 10:53:55 -04:00
Corinna Vinschen f132e630c4 sched: Move Cygwin cpuset definitions into Cygwin-specific header
This avoids build breakage on RTEMS.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2020-10-14 10:53:55 -04:00
Ken Brown c2b392c600 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.
2020-10-14 10:53:55 -04:00
Ken Brown a83682e167 Cygwin: FIFO: fix a thinko in raw_write
Remove a line that has no effect.
2020-10-14 10:53:55 -04:00
Ken Brown 7faf75c189 Tweak release message 2020-10-14 10:53:55 -04:00
Ken Brown 73e3ff9328 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.
2020-10-14 10:53:55 -04:00
Mark Geisert 860ed4a2bf 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.
2020-10-14 10:53:55 -04:00
Ken Brown e5a7dc08c1 Cygwin: FIFO: minor cleanup
Don't use a label with the same name as a variable.

Also fix indentation in fhandler.h.
2020-10-14 10:53:54 -04:00
Ken Brown 4763dcc080 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.
2020-10-14 10:53:54 -04:00
Ken Brown 6af347ba41 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.
2020-10-14 10:53:54 -04:00
Ken Brown 85601de166 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.
2020-10-14 10:53:54 -04:00
Ken Brown 229be09b1b 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.
2020-10-14 10:53:54 -04:00
Ken Brown 027adac187 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.
2020-10-14 10:53:54 -04:00
Ken Brown a92e5ecd0d Cygwin: FIFO: clean up locks
Make sure to use the fifo_client lock when (and only when) it is
needed.
2020-10-14 10:53:54 -04:00