Commit Graph

18769 Commits

Author SHA1 Message Date
Corinna Vinschen ea99e9fdda Cygwin: timerfd: fix overrun computation
- Drop erroneous initial computation of overrun count in settime
  for absolute non-realtime clocks.  It's repeated in thread_func
  and thus counted twice.

- Fix overrun computation for timestamp offsets being a multiple of
  the timer interval.  The timestamp has to be corrected after the
  first offset, otherwise the correction loop counts the intervals
  again.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-21 11:14:16 +01:00
Corinna Vinschen 6ed50a68a1 Cygwin: timerfd: settime: fix computing DueTime on non-realtime clocks
Non-CLOCK_REALTIME counters always use a relative DueTime in NtSetTimer.
However, relative DueTime has to be negative, but the code

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-21 10:05:16 +01:00
Corinna Vinschen a3268ac392 Cygwin: timerfd: Handle gettime error in settime
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-21 00:14:51 +01:00
Corinna Vinschen 02de9ac61e Cygwin: timerfd: fill out it_interval on timerfd_gettime
Might not be such a bad idea, after all...

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-21 00:14:09 +01:00
Corinna Vinschen 2993057a94 Cygwin: timerfd: implement TFD_TIMER_CANCEL_ON_SET
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-20 22:47:52 +01:00
Corinna Vinschen 95bc4240ed Cygwin: timerfd: convert expiry timestamp to LONG64
Turns out we never need it as LARGE_INTEGER.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-20 22:46:44 +01:00
Corinna Vinschen 693c98c5e2 Cygwin: timerfd: Fix entering critical section
Getting an abandonded mutex is just as well and must be handled.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-20 22:19:27 +01:00
Corinna Vinschen 597285ca58 Cygwin: timerfd: fix read(2) running wild
- On systems with inexact realtime clock, the current timestamp may
  be fractionally smaller than the desired timestamp.  This breaks the
  computation for incrementing overrun_count so overrun_count may end
  up as 0.  Expiring the timer with an overrun_count of 0 is a no-go.
  Make sure we always increment overrun_count by at least one after
  timer expiry.

- Do not expire the timer when another process deletes its timer_tracker.
  This, too, may result in a 0 overrun_count.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-20 22:18:17 +01:00
Corinna Vinschen e32d1510da Cygwin: timerfd: prepare for TFD_TIMER_CANCEL_ON_SET
Also drop debugging sleep and make sure overrun count is positive.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-19 20:53:38 +01:00
Corinna Vinschen 3bfe18c643 Cygwin: fhandler_pipe: fix comment
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-19 20:04:35 +01:00
Corinna Vinschen 40481dbabb Cygwin: timerfd: reimplement from scratch
Using posix timers "timer_tracker" as base class for timerfd was flawed.
Posix timers are not inherited by child processes and don't survive
execve.  The method used by posix timers didn't allow to share timers
between processes. The timers were still per-process timers and worked
entirely separate from each other.  Reading from these timers via
different descriptors was only synchronized within the same process.

This does not reflect the timerfd semantics in Linux: The per-file
timers can be dup'ed and survive fork and execve.  They are still just
descriptors pointing to the same timer object originally created by
timerfd_create.  Synchronization is performed between all descriptor
instances of the same timer, system-wide.

Thus, reimplement timerfd using a timer instance in shared memory,
a kernel timer, and a handful of sync objects.

Every process maintains a per-process timerfd struct on the cygheap
maintaining a per-process thread.  Every process sharing the same
timerfd will run this thread checking the state of the timer, similar
to the posix timer thread, just working on the shared objects and
synchronizing its job with each other thread.

Drop the timerfd implementation in the posix timer code and move the
public API to fhandler_timerfd.c.  Keep the ttstart timer_tracker
anchor out of "NO_COPY" since the fixup_after_fork code should run to
avoid memory leakage.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-19 20:00:06 +01:00
Corinna Vinschen 397526dee8 Cygwin: clock.h: add valid_timespec() to check timespec for validity
Use throughout, drop local timespec_bad() in timer.cc.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-18 14:31:01 +01:00
Corinna Vinschen 7f983079d4 Cygwin: timerfd/signalfd: return EINVAL from write
Linux returns EINVAL, "fd is attached to an object which is unsuitable
for writing".  If we don't handle write locally, write returns EBADF.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-17 11:51:11 +01:00
Corinna Vinschen 173e067a31 Cygwin: timerfd: implement TFD_IOC_SET_TICKS ioctl
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-16 18:40:53 +01:00
Corinna Vinschen 0e8c7b8689 Cygwin: timerfd: implement execve semantics
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-16 18:40:26 +01:00
Corinna Vinschen 4195bae67f Cygwin: timerfd: implement fork semantics
- Puzzeling: Commit ec98d19a08
  changed ttstart to NO_COPY but kept all the code to handle
  fixup after fork.  Revert to not-NO_COPY and make timerfd
  fork work.

- On fixup_after_fork, keep timerfd timers and restart thread
  if they were armed in the parent.

- Move timerfd timer_trackers to cygheap.  Overload timer_tracker
  new and delete methods to handle timers accordingly.  This is not
  exactly required for fork, but exec will be grateful.

- Give up on TFD_TIMER_CANCEL_ON_SET for now.  There's no easy way
  to recognize a discontinuous change in a clock.

- Be paranoid when cleaning out ttstart.

- Fix some minor issues.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-16 15:33:51 +01:00
Corinna Vinschen f5808867cf Cygwin: fork: move extern declarations to appropriate headers
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-16 12:59:27 +01:00
Corinna Vinschen 89a99d3b58 Cygwin: posix timers: fix overrun computation
- Drop initial overrun computation from timer_tracker::settimer.
  It's performed in timer_tracker::thread_func anyway.

- Fix regression in returning correct overrun count narrowed down to
  int from timer_getoverrun.  This has been introduced by changing
  overrun_count_curr to LONG64.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-16 12:53:56 +01:00
Corinna Vinschen 5b147c76d2 Cygwin: timerfd_create: add missing type
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-16 09:25:12 +01:00
Corinna Vinschen 068182e26c Cygwin: timers: implement timerfd
First cut of a timerfd implementation.

Still TODO:
- fork/exec semantics
- timerfd_settime TFD_TIMER_CANCEL_ON_SET flag
- ioctl(TFD_IOC_SET_TICKS)
- bug fixes

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-15 22:02:33 +01:00
Corinna Vinschen b6f53617a7 Cygwin: signalfd: set st_mode in fhandler_signalfd::fstat
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-15 21:49:52 +01:00
Corinna Vinschen 9b2318c428 Cygwin: signalfd: fix comment
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-15 21:46:23 +01:00
Jeff Johnston 17f8dfd314 Update config.guess, config.sub to gcc master branch versions 2019-01-15 14:13:30 -05:00
Jeff Johnston 1787e9d033 AMD GCN Port contributed by Andrew Stubbs <ams@codesourcery.com>
Add support for the AMD GCN GPU architecture.  This is primarily intended for
use with OpenMP and OpenACC offloading.  It can also be used for stand-alone
programs, but this is intended mostly for testing the compiler and is not
expected to be useful in general.

The GPU architecture is highly parallel, and therefore Newlib must be
configured to use dynamic re-entrancy, and thread-safe malloc.

The only I/O available is a via a shared-memory interface provided by libgomp
and the gcn-run tool included with GCC.  At this time this is limited to
stdout, argc/argv, and the return code.
2019-01-15 10:48:08 -05:00
Corinna Vinschen 4d2d891b99 Cygwin: gentls_offsets: Remove obsolte 'o' regex option
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-15 13:19:41 +01:00
Corinna Vinschen f7566c83c6 Cygwin: tlsoffsets64.h: regenerate
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-15 12:25:12 +01:00
Corinna Vinschen 704068e4f9 Cygwin: signalfd: drop incorrect handling of EINTR in read(2)
In case sigwait_common returns EINTR, read wrongly ignores it,
so read can't be interrupt by a signal.  Fix that.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-15 09:58:30 +01:00
Corinna Vinschen 837eb2af5b Cygwin: document POSIX rename semantics availability with W10 1809 only
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-14 21:57:46 +01:00
Corinna Vinschen 5275b3e3f2 Cygwin: wincap: split has_posix_file_info
While FileRenameInformationEx is defined starting with Windows
10 1709 per MSDN, it only starts working in W10 1809, apparently.
Users of 1803 report "Function not implemented".

Introduce wincap_10_1809 and change the version check in
wincapc::init accordingly.  Split has_posix_file_info into
has_posix_unlink_semantics and has_posix_rename_semantics.
Enable the latter only starting with W10 1809.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-14 20:38:24 +01:00
Corinna Vinschen f42776fa78 Cygwin: signalfd: implement non-polling select
Allow the signal thread to recognize we're called in consequence of
select on a signalfd.  If the signal is part of the wait mask, don't
call any signal handler and don't remove the signal from the queue,
so a subsequent read (or sigwaitinfo/sigtimedwait) still gets the
signal.  Instead, just signal the event object at
_cygtls::signalfd_select_wait for the thread running select.

The addition of signalfd_select_wait to _cygtls unearthed the alignment
problem of the context member again.  To make sure this doesn't get lost,
improve the related comment in the header file so that this (hopefully)
doesn't get lost (again).

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-14 17:19:37 +01:00
Corinna Vinschen 752151e715 Cygwin: select: always store the running thread's TLS into select_record
This allows select threads to access our current tls if required.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-14 17:03:39 +01:00
Corinna Vinschen 19b7c7ab2e Cygwin: document wctype changes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-13 23:35:28 +01:00
Thomas Wolff 41397e13ce update to Unicode 11.0 2019-01-13 23:33:51 +01:00
Thomas Wolff 30062d409d map WEOF to undefined rather than the control char category
Fixes https://cygwin.com/ml/cygwin/2018-12/msg00173.html
2019-01-13 23:33:51 +01:00
Corinna Vinschen 9d13a2995c Cygwin: signal: implement signalfd
First cut of a signalfd implementation.

Still TODO: Non-polling select.

This should mostly work as on Linux except for missing support
for some members of struct signalfd_siginfo, namely ssi_fd,
ssi_band (both SIGIO/SIGPOLL, not fully implemented) and ssi_trapno
(HW exception, required HW support).

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-13 23:13:33 +01:00
Corinna Vinschen 8ae26f96ae Cygwin: proc fd: return EACCES for HANDLE-less fds
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-13 23:09:48 +01:00
Corinna Vinschen 7f60199032 Cygwin: minor cleanups
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-13 22:48:43 +01:00
Corinna Vinschen b6694df619 Cygwin: select: fix overwriting fd sets if poll returns no fd
There's a long-standing bug in select.  If we have poll-only
descriptors in the fd set, select overwrites the incoming
fd sets with the polling result.  If none of the fds is ready,
select has to loop again.  But now the fd sets are set to all
zero and select hangs.

Fix this by utilizing the local fd sets r, w, e as storage for
the incoming fd sets and use them to initialize select_stuff.

If we have to loop, overwritung the incoming fd sets doesn't matter.

While at it, rename r, w, e to readfds_in, writefds_in, exceptfds_in.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-13 22:43:52 +01:00
Corinna Vinschen d31f9f9c13 Cygwin: fhandler_pipe: unify format directives
The format directives in sscanf/__small_sprintf are not
matching.  Fix that.
2019-01-13 22:30:33 +01:00
Corinna Vinschen 9e295a8d19 Cygwin: posix timers: implement timer_getoverrun
- set DELAYTIMER_MAX to INT_MAX
- make sure to set siginfo_t::si_overrun, as on Linux

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-12 21:26:07 +01:00
Corinna Vinschen 961be8d726 Cygwin: posix timers: some cleanup
- use int64_t instead of long long
- make is_timer_tracker const
- improve copyright header comment

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-12 21:20:37 +01:00
Corinna Vinschen 92cbaa9f23 Cygwin: posix timers: convert timer_tracker::fixup_after_fork to static method
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-12 21:20:31 +01:00
Corinna Vinschen c406bea20b Cygwin: posix timers: move definition of timer_tracker class to new timer.h
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-12 21:20:19 +01:00
Corinna Vinschen 9ef0cd6a6c Cygwin: clock_nanosleep is not supposed to crash, return EFAULT instead
...in case rqtp or rmtp specified invalid addresses.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-11 15:15:32 +01:00
Corinna Vinschen 8d1d8fc914 Cygwin: timer: convert timer_tracker to a real C++ class
...with private members and all the jazz

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-11 15:13:11 +01:00
Ken Brown 367df1d4e0 Cygwin: af_unix_spinlock_t: add initializer
Also fix a typo.
2019-01-10 19:05:58 +01:00
Corinna Vinschen fbd3835384 Cygwin: try_to_bin: don't check recycler filename all the time
So far we check the recycler name all the time, and the last interation
also only managed to handle two ways to write the recycler.  However,
an adventurous user might change the case of the recycler arbitrarily.

Fix this problem by keeping track of the name in a somewhat relaxed
fashion.  Use camel back on drive C by default, all upper case elsewhere.
Only if the rename op fails do we fix the recycler name on the fly
when trying to create it, and it turns out it already existed.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-09 21:48:43 +01:00
Corinna Vinschen b7a6d357ee Cygwin: try_to_bin: fix rootdir handle after reopening
If the first rename fails, we reopen the rootdir for creating a subdir.
The rootdir handle can change its value at this point, but the code
doesn't take this into account.  The subsequent rename then fails with
STATUS_INVALID_HANDLE.  Fix this by copying the new rootdir value to
pfri->RootDirectory.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-09 21:48:43 +01:00
Corinna Vinschen ec457e0351 Cygwin: rename: use FILE_RENAME_POSIX_SEMANTICS if available
starting with W10 1709 on local NTFS drives

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-09 15:47:43 +01:00
Corinna Vinschen 15094d5d01 Cygwin: rename: rename incoming flags argument to at2flags
Avoid name confusion with later used flags variable

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-09 14:45:37 +01:00