Commit Graph

12105 Commits

Author SHA1 Message Date
Corinna Vinschen c6171b9fde Cygwin: gethostname: fix fetching hostname from non-winsock function
If gethostname() fails we call GetComputerNameEx with
ComputerNameDnsFullyQualified.  This is wrong, gethostname should return
the hostname only, not the FQDN.  Fix this by calling GetComputerNameEx
with ComputerNameDnsHostname.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-24 14:04:42 +01:00
Corinna Vinschen 04e3dc1128 Cygwin: version: Use UTC timestamp as build time
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-24 11:39:43 +01:00
Corinna Vinschen b79b0c2bae Cygwin: cygthread: set thread name before calling thread func
When reusing a cygthread, the stub method fails to set the thread name
to the new name.  The name is only set when actually creating the
thread.  Fix that by moving the SetThreadName call right in front of the
thread function call.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-23 21:45:59 +01:00
Jozef Lawrynowicz b14a879d85 Remove matherr, and SVID and X/Open math library configurations
Default math library configuration is now IEEE
2019-01-23 10:46:24 +01:00
Corinna Vinschen 1f10a00ba7 Cygwin: posix timers: fix overrun count always being 1 too big
Combine with a bit of cleanup:
- Drop overrun_event_running in favor of overrun_count being -1.
- Fix include guard in posix_timer.h.
- Drop ununsed function timespec_to_us.
- Don't use Interlocked functions without need.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 18:20:18 +01:00
Corinna Vinschen de0ec284a3 Cygwin: posix timers: fix error handling in public API
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 16:38:21 +01:00
Corinna Vinschen 83c51fffe6 Cygwin: posix timers: allocate timer_tracker on system heap.
Allocating on the cygheap would copy information of the tracker into
the child process.  A forked child knows the timer id and could simply
still access the (free'd but still valid) timer_tracker on the heap,
which is dangerous and very certainly doesn't reflect POSIX semantics.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 16:38:14 +01:00
Corinna Vinschen 6c44af8179 Cygwin: timerfd: Add support for CLOCK_REALTIME_ALARM/CLOCK_BOOTTIME_ALARM
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 15:46:17 +01:00
Corinna Vinschen 013e2bd9ec Cygwin: posix timers: Add support for CLOCK_REALTIME_ALARM/CLOCK_BOOTTIME_ALARM
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 15:45:58 +01:00
Corinna Vinschen 1daece5861 Cygwin: clocks: Add CLOCK_REALTIME_ALARM/CLOCK_BOOTTIME_ALARM clocks
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 15:42:07 +01:00
Corinna Vinschen 229ea3f23c Cygwin: posix timers: reimplement using OS timer
- Rename files timer.* to posix_timer.*.
- Reimplement using an OS timer rather than a handcrafted wait loop.
- Use a Slim R/W Lock for synchronization.
- Drop timer chaining.  It doesn't server a purpose since all timers
  are local only.
- Rename ttstart to itimer_tracker to better reflect its purpose.
  It's not the anchor for a timer chain anymore anyway.
- Drop fixup_timers_after_fork.  Everything is process-local, nothing
  gets inherited.
- Rename timer_tracker::disarm_event to disarm_overrun_event for
  better readability.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 15:23:05 +01:00
Corinna Vinschen 4c50dc94c3 Cygwin: timerfd: another overrun computation fix and drop useless variable
- When correcting the next expiration timestamp, the number of
  expirations gets computed correctly, just the expiration timestamp
  itself is then only incremented by a single interval, rather than
  the just computed expired intervals.  Fix that.

- drop the local clock variable in timerfd_tracker::create.  It doesn't
  serve any purpose.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 15:06:51 +01:00
Corinna Vinschen a75bd958b4 Cygwin: timerfd: reset expiry counter in settime
As on Linux, reset the expiry counter when the timer gets rearmed.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-21 22:54:26 +01:00
Corinna Vinschen 5b23a8e831 Cygwin: timerfd: fix gettime
- split into to __try/__except blocks to make sure
  leave_critical_section is always called when required.

- Actually fill time_spec in settime so it_interval is returned
  correctly.

- Return all 0 if timer is disarmed.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-21 22:52:39 +01:00
Corinna Vinschen 289b7c09c8 Cygwin: timerfd: move ioctl error handling into timerfd_tracker
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-21 12:41:00 +01:00
Corinna Vinschen 528f4d4938 Cygwin: timerfd: rename overrun_count to expiration_count
The value returned by reading from a timerfd is not an overrun
count in the same sense as for posix timers, it's an expiry counter.
Reflect that in the name.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-21 12:26:51 +01:00
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
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
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
Corinna Vinschen dee6cb133a Cygwin: try_to_bin: don't reopen the file
So far we reopened the file if it was opened case sensitive to
workaround the problem that the recycler could be named in
camel back or all upper case, depending on who created it.
That's a problem for O_TMPFILE on pre-W10.  As soon as the
original HANDLE gets closed, delete-on-close is converted to full
delete disposition and all useful operations on the file cease to
work (STATUS_ACCESS_DENIED or STATUS_FILE_DELETED).

To avoid that problem drop the reopen code and check for the exact
recycler filename, either $Recycle.Bin or $RECYCLE.BIN, if the file
has been opened case sensitive.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-08 21:47:28 +01:00
Corinna Vinschen ec36c59f1a Cygwin: open: workaround reopen file w/ delete disposition set
On pre-W10 systems there's no way to reopen a file by handle if
the delete disposition is set.  We try to get around with
duplicating the handle.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-08 21:47:28 +01:00
Corinna Vinschen 0c545f3264 Cygwin: open: handle O_CLOEXEC when opening file from handle
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-08 21:47:28 +01:00
Corinna Vinschen 9ba65ab8b5 Cygwin: fhandler_process_fd: Fix spacing
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-08 21:47:28 +01:00
Corinna Vinschen 2d015e0e68 Cygwin: remove unused tmpbuf.h
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-08 18:49:29 +01:00
Corinna Vinschen 9443efe099 Cygwin: linkat: support Linux-specific AT_EMPTY_PATH flag
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-07 19:36:37 +01:00
Corinna Vinschen b93022a82d Cygwin: open: support Linux-specific O_PATH flag
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-07 19:35:00 +01:00
Corinna Vinschen 91ca95ae4a Cygwin: rename pipe.cc to fhandler_pipe.cc
move pipe syscalls to syscalls.cc

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-07 12:31:28 +01:00
Corinna Vinschen 9db7f4d1dd Cygwin: move fhandler_cygdrive methods into own source file
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-07 12:29:07 +01:00
Corinna Vinschen 4c33add5b8 Cygwin: drop redundant includes from fhandler_process_fd.cc
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-06 22:40:17 +01:00
Corinna Vinschen 9dae73edb8 Cygwin: fix regression in O_TMPFILE | O_EXCL case
The new proc fd code accidentally allowed to linkat an O_TMPFILE
even if the file has been opened with O_EXCL.  This patch fixes it.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-06 22:39:45 +01:00
Corinna Vinschen 8a17b1b2bf Cygwin: document proc fd changes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-06 20:30:14 +01:00
Corinna Vinschen 7aca27b4fe Cygwin: introduce fhandler_process_fd and add stat(2) handling
move special fd symlink code into own fhandler_process_fd class
to simplify further additions to /proc/PID/fd/DESCRIPTOR symlink
handling.

Add a method to handle stat(2) on such a proc fd symlink by handle.
This allows correct reply from stat(2) if the target file has been
deleted.  This eventually fixes `awk -f /dev/fd/3 3<<eof'.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-06 20:30:14 +01:00
Corinna Vinschen ba12614f79 Cygwin: path_conv: add PATH_RESOLVE_PROCFD path_types flag
path_conv now sets the PATH_RESOLVE_PROCFD flag in path_flags if
the PC_SYM_NOFOLLOW_PROCFD pathconv_arg flag has been set on input
*and* the file is actually a proc fd symlink.

Add matching path_conv::follow_fd_symlink method for checking and
use it in open(2).

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-06 20:30:14 +01:00
Corinna Vinschen c1023ee353 Cygwin: path_conv: decouple path_types from mount types
- Remove another unfortunate amalgamation: Mount flags (MOUNT_xxx)
  are converted to path_types (PATH_xxx) and mixed with non-mount
  path_types flags in the same storage, leading to a tangled,
  pell-mell usage of mount flags and path flags in path_conv and
  symlink_info.

- There's also the case of PC_NONULLEMPTY.  It's used in exactly
  one place with a path_conv constructor only used in this single
  place, just to override the automatic PC_NULLEMPTY addition
  when calling the other path_conv constructors.  Crazily,
  PC_NONULLEMPTY is a define, no path_types flag, despite its
  name.

- It doesn't help that the binary flag exists as mount and path
  flag, while the text flag only exists as path flag.  This leads
  to mount code using path flags to set text/binary.  Very confusing
  is the fact that a text mount/path flag is not actually required;
  the mount code sets the text flag on non binary mounts anyway, so
  there are only two states.  However, to puzzle people a bit more,
  path_conv::binary wrongly implies there's a third, non-binary/non-text
  state.

Clean up this mess:

- Store path flags separately from mount flags in path_conv and
  symlink_info classes and change all checks and testing inline
  methods accordingly.

- Make PC_NONULLEMPTY a simple path_types flag and drop the
  redundant path_check constructor.

- Clean up the definition of pathconv_arg, path_types, and mount flags.
  Use _BIT expression, newly define in cygwin/bits.h.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-06 20:30:14 +01:00
Corinna Vinschen fde4eaa105 Cygwin: path_conv: decouple pathconv_flags from path_types
There's an unfortunate amalgamation of caller-provided pathconv_arg
flags with path_types flags which in turn are mostly mount flags.

This leads to a confusion of flag values in sylink_info::pflags and,
in turn, in path_conv::path_flags.

This patch decouples pathconv_flags from the other flags by making
sure that a pathconv_flag is never copied into a variable used for
path_types flags.  Also, remove PATH_NO_ACCESS_CHECK since it's
not necessary.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-06 20:30:14 +01:00
Corinna Vinschen c90f4c0e27 Cygwin: Mark all O_TMPFILEs as deleted
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-06 20:30:14 +01:00
Corinna Vinschen 7dbe307e38 Cygwin: Move O_TMPFILE to bin and allow linkat by handle
Along the same lines as the previous patch: By reopening an
O_TMPFILE by handle, we can now move the file to the bin at
open time and thus free'ing up the parent dir and *still*
open the file as /proc/PID/fd/DESCRIPTOR by linkat(2).
2019-01-06 20:30:14 +01:00
Corinna Vinschen a1a750325e Cygwin: try_to_bin: allow to move O_TMPFILE files into bin
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-06 20:30:14 +01:00
Corinna Vinschen 732613f30a Cygwin: implement /proc/PID/fd/DESCRIPTOR reopening by handle
Allows expressions along the lines of `cat /proc/self/fd/0 <<EOF'.
The problem here is that the temporary file used for the here script
has already been deleted by the shell.  Opening by filename, as
implemented so far, doesn't work because the file has been moved
to the bin.

Allow reopening files by handle the same way from another process
as long as we have sufficient permissions on the foreign process.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-06 20:30:14 +01:00
Corinna Vinschen c76468182b Cygwin: pinfo: add method to send a serialized path_conv and HANDLE
To allow reopening a file open in another process by HANDLE, introduce
a matching file_pathconv method, taking a file descriptor as parameter.
The result is a serialized path_conv and a HANDLE value.  The HANDLE is
valid in the foreign process and MUST be duplicated into the target
process before usage.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-06 20:30:14 +01:00
Corinna Vinschen 91b264c76c Cygwin: path_conv: add serialization/deserialization facility
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-06 20:30:14 +01:00
Corinna Vinschen 26d9536893 Cygwin: path_conv: reorder private method declarations
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-06 20:30:14 +01:00
Corinna Vinschen c208ecd540 Cygwin: fhandler_base::open: allow to reopen file from handle
So far io_handle is NULL when calling fhandler_base::open to
open or create a file.  Add a check for io_handle to allow
priming the fhandler with a HANDLE value so we can reopen a
file from a HANDLE on file systems supporting it.  This allows
to open already deleted files for further action.  This will
be used by open("/proc/PID/fd/DESCRIPTOR") scenarios.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-06 20:30:14 +01:00
Corinna Vinschen 97d2fe2694 Cygwin: pipe: use /proc/PID/fd/... or /proc/self/fd/... name
Don't emit /dev/fd/... filename.  This simplifies pipe path handling
and avoids another symlink redirection.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-05 21:42:33 +01:00
Corinna Vinschen a3a5d52b39 Cygwin: introduce virt_fdsymlink to simplify /proc/PID/fd symlink handling
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-05 21:41:01 +01:00
Corinna Vinschen f72191ac01 Cygwin: return correct FH_PROCESSFD for files under /proc/PID/fd subdir
This allows easier handling of fd symlinks.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-05 21:36:34 +01:00
Corinna Vinschen 36ff506ddc Cygwin: try_to_bin: fix typos in comments
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-05 11:32:23 +01:00
Corinna Vinschen 844a1b4fe4 Cygwin: path_conv: nobody cares if a path had symlinks after the fact
remove set_has_symlinks/has_symlinks/PATH_HAS_SYMLINKS.  Nobody's
asking for this information.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-05 11:31:52 +01:00
Corinna Vinschen 34d9bb7093 Cygwin: drop disabled O_TMPFILE POSIX unlink code
The commit message of commit 07e0a9584f
and the expectation set therein, are wrong.

There's no POSIX semantics allowing to link a file with a link
count of 0 and making it available in the file system again.
In fact, the Linux linkat extension AT_EMPTY_PATH explicitely
disallows to link a file descriptor to a file with a link count
of 0, except for O_TMPFILE without O_EXCL.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-04 11:01:47 +01:00
Corinna Vinschen 07e0a9584f Cygwin: open(2): Change comment in disabled O_TMPFILE POSIX unlink code
- Turns out, the definition of POSIX unlink semantics is half-hearted
  so far: It's not possible to link an open file HANDLE if it has
  been deleted with POSIX semantics, nor is it possible to remove
  the delete disposition.  This breaks linkat on an O_TMPFILE.

  Tested with W10 1809.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-12-26 22:16:59 +01:00
Corinna Vinschen 7148fbc496 Cygwin: Change /proc/$PID/fd/<fd> symlink target for deleted files
- As on Linux, print the file name with an attached " (deleted)"

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-12-26 22:16:24 +01:00
Corinna Vinschen 4cd209e921 Cygwin: Add Christmas hacking release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-12-26 11:36:22 +01:00
Corinna Vinschen 66cd1cbaf8 Cygwin: Add documentation for chattr and lsattr
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-12-26 11:22:06 +01:00
Corinna Vinschen 0d4b39d37b Cygwin: Add lsattr and chattr tools
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-12-26 09:24:33 +01:00
Corinna Vinschen af4a65a26d Cygwin: Add FS_IOC_GETFLAGS and FS_IOC_SETFLAGS ioctls
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-12-25 23:38:52 +01:00
Corinna Vinschen 4021509ba2 Cygwin: mkdir: create case-sensitive dirs
On Windows 10 1803 and later, create dirs under the Cygwin
installation dir as case sensitive, if WSL is installed.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-12-25 01:09:12 +01:00
Corinna Vinschen 92edcf929a Cygwin: wincap: add wincap_10_1803, add has_case_sensitive_dirs item
- Allow to disable the flag by calling disable_case_sensitive_dirs.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-12-25 01:07:51 +01:00
Corinna Vinschen 866901441b Cygwin: cygheap: convert installation paths to UNICODE_STRINGS
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-12-25 01:06:34 +01:00
Corinna Vinschen a7f392686b Cygwin: utilize FILE_DISPOSITION_POSIX_SEMANTICS
- short-circuit most code in unlink_nt since it's not necessary
  anymore if FILE_DISPOSITION_POSIX_SEMANTICS is supported.

- Immediately remove O_TMPFILE from filesystem after creation.
  Disable code for now because we have to implement /proc/self/fd
  opening by handle first, lest linkat fails.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-12-23 21:36:42 +01:00
Corinna Vinschen 0c25ca40ce Cygwin: support exFAT and fix remote FAT/FAT32 recognition
Newer FAT32 and exFAT add FILE_SUPPORTS_ENCRYPTION to their
flags which wasn't handled by Cygwin yet.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-12-23 17:53:55 +01:00
Corinna Vinschen 092a768885 Cygwin: wincap: add wincap_10_1709, add has_posix_file_info item
Various new file info class members adding important POSIX semantics
have been added with W10 1709.  We may want to utilize them, so add
a matching wincaps.

Rearrange checking the W10 build number to prefer the latest builds
over the older builds.  Rename wincap_10 to wincap_10_1507 for
enhanced clarity.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-12-23 00:24:05 +01:00
Corinna Vinschen 29cfc892a5 Cygwin: ntdll.h: Update _FILE_INFORMATION_CLASS
- Add missing members added in later OS versions
- Rearrange accompanying FILE_foo_INFORMATION structs
  ordered by info class
- Add promising FILE_foo_INFORMATION structs of later
  Windows 10 releases plus accompanying enums
- Drop "Checked on 64 bit" comments since that's self-evident
  these days

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-12-23 00:24:05 +01:00
Corinna Vinschen a091d5da63 Cygwin: fix heap allocation on WOW64 and /3GB enabled 32 bit machines
The check for the TEB being allocated beyond the first 2GB area is not
valid anymore.  At least on W10 WOW64, the TEB is allocated in the
lower 2GB even in large-address aware executables.  Use VirtualQuery
instead.  It fails for invalid addresses so that's a simple enough test.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-12-19 21:10:37 +01:00
Corinna Vinschen 5b4de1c915 Cygwin: mkvers: fix a bug in sed statement
While reformatting the script, backticks `` were replaced with
brackets $().  This in turn invalidated the \\( ... \\) expressions in the
sed script because backslash resolution in $() works differently from
backslash resolution in ``.  Only a single backslash is valid now.

While at it, fix up the uname(2) date representation when building a
snapshot.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-12-01 17:00:35 +01:00
Corinna Vinschen 2b72887ac8 Cygwin: clocks: fix a hang on pre-Windows 10 machines
when calling clocks too early in DLL init, the vtables are not correctly
set up for some reason.  Calls to init() from now() fail because the init
pointer in the vtable is NULL.

Real life example is mintty which runs into a minor problem at startup,
triggering a system_printf call.  Strace is another problem, it's called
the first time prior to any class initialization.

Workaround is to make sure that no virtual methods are called in an
early stage.  Make init() non-virtual and convert resolution() to a
virtual method instead.  Add a special non-virtual
clk_monotonic_t::strace_usecs.

While at it:

- Inline internal-only methods.

- Drop the `inited' member.  Convert period/ticks_per_sec toa union.
  Initialize period/ticks_per_sec via InterlockeExchange64.

- Fix GetTickCount64 usage.  No, it's not returning ticks but
  milliseconds since boot (unbiased).

- Fix comment indentation.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-12-01 15:11:12 +01:00
Mark Geisert 166914ea8c fix version typo 2018-12-01 12:06:24 +01:00
Corinna Vinschen 43e8fddfa6 Cygwin: clocks: use either tickcount or tick period
Use whatever native unit the system provides for the resolution of
a timer to avoid rounding problems

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-11-29 13:03:54 +01:00
Corinna Vinschen 3cbb70f890 Cygwin: document latest changes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-11-29 11:12:05 +01:00
Corinna Vinschen c05df02725 Cygwin: implement extensible clock interface
- Drop hires_[nm]s clocks, rename hires.h to clock.h.

- Implement clk_t class as an extensible clock class in new file clock.cc.

- Introduce get_clock(clock_id) returning a pointer to the clk_t instance
  for clock_id.  Provide the following methods along the lines of the former
  hires classes:

	void		clk_t::nsecs (struct timespec *);
	ULONGLONG	clk_t::nsecs ();
	LONGLONG	clk_t::usecs ();
	LONGLONG	clk_t::msecs ();
	void 		clk_t::resolution (struct timespec *);

- Add CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC_RAW, CLOCK_MONOTONIC_COARSE
  and CLOCK_BOOTTIME clocks.

- Allow clock_nanosleep, pthread_condattr_setclock and timer_create to use
  all new clocks (both clocks should be usable with a small tweak, though).

- Bump DLL major version to 2.12.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-11-29 11:05:42 +01:00
Corinna Vinschen 6df301076a Cygwin: timers: clock_setres: make no-op
clock_setres is a questionable function only existing on QNX.
Disable the function, just return success for CLOCK_REALTIME
to maintain backward compatibility.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-11-29 10:01:57 +01:00
Corinna Vinschen 0b868df147 Cygwin: pthread_cond_timedwait: make sure to wait until abstime finishes 2018-11-29 10:01:57 +01:00
Corinna Vinschen 5eaa64f9d8 Cygwin: timers: use spinlock to prime hires_ns thread-safe
The current method to make hires_ns priming thread-safe isn't
thread-safe.  Rather than hoping that running the thread in
TIME_CRITICAL priority is doing the right thing, use a spinlock.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-11-26 17:59:11 +01:00
Corinna Vinschen 161d0fd27b Cygwin: timers: drop error handling for Windows perf timer functions
Per MSDN, the perf timer functions always succeed on Windows XP or
later.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-11-26 17:59:11 +01:00
Corinna Vinschen 65091f0f35 Cygwin: timers: Simplify hires_ms and hires_ns
Drop hires_base and move inited into hires_ns.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-11-26 17:59:10 +01:00
Corinna Vinschen a094c5bafa Cygwin: spinlock: remove useless get_ll call
LARGE_INTEGER has QuadPart anyway, no reason to compute the
64 bit value from HighPart and LowPart.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-11-26 17:59:10 +01:00
Corinna Vinschen bba82041b2 Cygwin: Bump DLL version to 2.11.3
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-11-08 15:31:25 +01:00
Corinna Vinschen 535903696c Cygwin: honor SOCK_NONBLOCK/SOCK_CLOEXEC in socket(2)/socketpair(2)
fhandler_socket_wsock::set_socket_handle calls set_flags after
setting the O_NONBLOCK/O_CLOEXEC flags, thus overwriting them.

It also turns out that fhandler_socket_wsock::init_events is called
too late.  The inheritence flags are changed before creating the
socket event handling objects.  Thus, inheritence flags for
those objects are wrong with SOCK_CLOEXEC.

Fix this by reordering the calls and setting the file flags through
fhandler_base::set_flags.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-11-05 21:02:22 +01:00
Corinna Vinschen 2bbe8697d8 Cygwin: fix memory corruption/SEGV if certain socket functions fail
Regression introduced with 2.11.0:

The failure paths in socket, socketpair and accept4 functions and
methods accidentally release *unused* cygheap_fdmanip objects.  The
subsequently called dtable::release method was designed to be called for
*used* cygheap_fdmanip objects only.  Using them on unused objects leads
to NULL pointer member dereferencing.

Worse, the inet/local accept4 methods only release the cygheap_fdmanip
object but neglect to delete the just created fhandler_socket_* object.

Fix this by removing the erroneous release calls in the aforementioned
failure paths and delete the fhandler_socket_* object in accept4 instead.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-10-29 16:32:48 +01:00
David McFarland af85fdd73f Cygwin: Fix cygheap corruption caused by cloned atomic buffer
The fhandler_base_overlapped::copyto clears atomic_write_buf on the
clone, but none of the derived classes were doing this.  This allowed
the destructor to double-free the buffer and corrupt cygheap.
Clear atomic_write_buf in copyto of all derived classes.
2018-10-29 10:08:53 +01:00
Sebastian Huber da418955f5 Move common <sys/dirent.h> content to <dirent.h>
Move common content of the various <sys/dirent.h> and the latest FreeBSD
<dirent.h> to <dirent.h>.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-10-11 08:29:16 +02:00
Corinna Vinschen 682c4a9f1e Implement nanl in newlib only
Drop Cygwin-specific nanl in favor of a generic implementation
in newlib.  Requires GCC 3.3 or later.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-10-10 17:49:53 +02:00
Corinna Vinschen 323b48b975 Cygwin: lseek: return ESPIPE rather than EINVAL when called on a fifo
Thanks to Henri for tracking this down:
https://cygwin.com/ml/cygwin/2018-10/msg00062.html

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-10-10 13:20:45 +02:00
Corinna Vinschen d83404e418 Cygwin: console: make sure EnumFontFamiliesExW loop isn't infinite
The current loop condition is borderline.  Make sure it ends and
choose a replacement char in the unlikely case the current console
font isn't recognized at all.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-09-07 13:49:54 +02:00
Corinna Vinschen 7a720bfe08 Cygwin: console: store replacement char directly
Rather than relying on an index variable, store the current
replacement char and use that directly in WriteConsoleW.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-09-07 13:48:35 +02:00
Corinna Vinschen 60471176fd Cygwin: console: don't hang in check_font with raster fonts
EnumFontFamiliesExW fails if the font is "Terminal" (aka "Raster Fonts")
and lfCharSet requests ANSI_CHARSET.  Using DEFAULT_CHARSET fixes this.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-09-07 13:44:44 +02:00
Corinna Vinschen 85c030a75f Cygwin: console: device context is process private
Make sure device context is not copied to forked process.
It is a process-specific datastructure.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-09-06 13:05:55 +02:00
Corinna Vinschen bf8aabe830 Cygwin: console: improve replacement char algorithm
Try various Unicode characters which may be used as a replacement
character in case an invalid character has to be printed.

Current list is 0xfffd "REPLACEMENT CHARACTER", 0x25a1 "WHITE SQUARE",
and 0x2592 "MEDIUM SHADE" in that order.

Additionally workaround a problem with some fonts (namely DejaVu
Sans Mono) which are returned wit ha broken fontname with trailing
stray characters.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-09-05 23:39:25 +02:00
Corinna Vinschen 213d8cac24 Cygwin: console: use UNICODE API throughout
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-09-05 13:08:33 +02:00
Corinna Vinschen 9bbda85e27 Cygwin: Bump DLL version to 2.11.2
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-09-05 13:02:09 +02:00
Corinna Vinschen d1454de7b0 Cygwin: console: Print Unicode REPLACEMENT CHARACTER for invalid input chars
So far we printed a half filled square (0x2592) if the input char is
invalid, but using REPLACEMENT CHARACTER (0xfffd) is apparently the way
to go.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-09-01 21:34:37 +02:00
Corinna Vinschen 3a880bf5e0 Cygwin: fix Win32 path ".." backtracking
Commit 35998fc2fa fixed the buffer underun
in win32 path normalization, but introduced a new bug: A wrong
assumption led to the inability to backtrack the path outside of the
current working directory in case of relative paths.

This patch fixes this problem, together with a minor problem if the CWD
is on a network share: The result erroneously started with tripple
backslash if the src path starts with a single backslash.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-09-01 21:06:24 +02:00
Corinna Vinschen fc3a8ecca5 Cygwin: Bump DLL version to 2.11.1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-31 13:01:23 +02:00
Corinna Vinschen 03cd2c4efa Cygwin: Accommodate logon sessions on Windows 10
Starting with Windows 10, LookupAccountSid/Name return valid
info for the login session with new SID_NAME_USE value
SidTypeLogonSession.  To return the same info as on pre-Windows 10,
we have to handle this type.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-28 11:28:28 +02:00
Corinna Vinschen 3aba266aa9 Cygwin: drop workaround for missing USER_INFO_24 definition
Recent mingw64 provide USER_INFO_24

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-28 11:24:59 +02:00
Corinna Vinschen fc8aaa40fe Cygwin: add release note for previous ACL changes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-27 18:30:59 +02:00
Corinna Vinschen 33b8c406dc Cygwin: Add name->SID conversion for self-constructed names
...as far as it makes sense.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-27 18:28:33 +02:00
Corinna Vinschen fcfcc288c4 Cygwin: don't return valid acl entry type for unknown SID
cygpsid::get_id neglects to set the type to 0 (ACL_UNDEFINED_TAG
in POSIX speak) if the SID can not be translated into a valid
uid or gid.  This in turn leads to incorrect handling of uid/gid -1
entries.

Fix this by setting type to 0 if the id is unknown.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-27 13:48:07 +02:00
Corinna Vinschen 6706b19a97 Cygwin: Remove union wait
This patch follows glibc.  Original commit message:

Author:	Florian Weimer <fweimer@redhat.com>
Date:   Thu, 14 Apr 2016 06:54:57 +0000

Remove union wait [BZ #19613]

The overloading approach in the W* macros was incompatible with
integer expressions of a type different from int.  Applications
using union wait and these macros will have to migrate to the
POSIX-specified int status type.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-24 20:57:47 +02:00
Sebastian Huber 5d29023c11 Add __nl_item to <sys/_types.h> and use it
Add __nl_item to <sys/_types.h> for FreeBSD compatibility.  Use it in
<langinfo.h> and the Cygwin <nl_types.h>.  Make the enum __nl_item in
<langinfo.h> anonymous.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2018-08-24 15:00:01 +02:00
Corinna Vinschen 36cb95f602 CYgwin: fix typo in comment
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-24 13:36:06 +02:00
Corinna Vinschen 71b4e3b336 Cygwin: get_mem_values: Fix prototype
Incomplete change unsigned long -> size_t was only visible on 32 bit, sigh.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-17 20:40:18 +02:00
Corinna Vinschen 09c114d7e2 Cygwin: document /proc/<PID>/status and /proc/<PID>/statm patches
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-17 20:33:38 +02:00
Corinna Vinschen c2fa05899d Cygwin: get_mem_values: Return number of Cygwin pages in arguments
Simplify callers accordingly.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-17 20:32:42 +02:00
Corinna Vinschen 7b70195f5d Cygwin: get_mem_values: Convert arguments to call-by-reference
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-17 20:32:42 +02:00
Corinna Vinschen 630294d373 Cygwin: get_mem_values: Return allocation as size_t values
Use size_t in callers, too.  Fix __small_sprintf format specifiers.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-17 20:32:42 +02:00
Corinna Vinschen ca2ec0c5cc Revert "Use allocation granularity as the 'page_size' in /proc/<pid>/status as well, for consistency with /proc/<pid>/statm"
This reverts commit 8a32c24a7b.

Replacing page_size() with allocation_granularity() was incorrect.
The values returned by get_mem_values() are # of pages of size
page_size().  Multiplying with allocation_granularity() here
results in values 16 times too big.
2018-08-17 19:16:42 +02:00
Corinna Vinschen 76d17e6860 Cygwin: Add missing items to release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-17 11:49:24 +02:00
Ken Brown ed4d919c24 setfacl: Rename the option --file to --set-file, as on Linux
Retain --file as an undocumented option for backwards compatibility.
2018-08-17 11:35:24 +02:00
Corinna Vinschen ef11dd8b47 Cygwin: Add FE_ALL_EXCEPT change to release notes.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-15 18:02:22 +02:00
J.H. van de Water 4c4c19f548 Keep the denormal-operand exception masked; modify FE_ALL_EXCEPT accordingly.
By excluding the denormal-operand exception from FE_ALL_EXCEPT, it will not
be possible anymore to UNmask this exception by means of the API defined by
/usr/include/fenv.h

Note: terminology has changed since IEEE Std 854-1987; denormalized numbers
are called subnormal numbers nowadays.

This modification has basically been motivated by the fact that it is also
not possible on Linux to manipulate the denormal-operand exception by means
of the interface as defined by /usr/include/fenv.h. This has been the state
of affairs on Linux since 2001 (Andreas Jaeger).

The exceptions required by the standard (IEEE Std 754), in case they can be
supported by the implementation, are:
FE_INEXACT, FE_UNDERFLOW, FE_OVERFLOW, FE_DIVBYZERO and FE_INVALID.

Although it is allowed to define additional exceptions, there is no reason
to support the "denormal-operand exception" in this case (fenv.h), because
the subnormal numbers can be handled almost as fast the normalized numbers
by the hardware of the x86/x86_64 architecture. Said differently, a reason
to trap on the input of subnormal numbers does not exist. At least that is
what William Kahan and others at Intel asserted around 2000.
(that is William Kahan of the K-C-S draft, the precursor to the standard)

This commit modifies winsup/cygwin/include/fenv.h as follows:
 - redefines FE_ALL_EXCEPT from 0x3f to 0x3d
 - removes the definition for FE_DENORMAL
 - introduces __FE_DENORM (0x2) (enum in Linux also uses __FE_DENORM)
 - introduces FE_ALL_EXCEPT_X86 (0x3f), i.e. ALL x86/x86_64 FP exceptions
2018-08-15 18:02:22 +02:00
Corinna Vinschen 9122f82a55 Cygwin: Add J.H. van de Water to CONTRIBUTORS
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-15 18:02:22 +02:00
Corinna Vinschen dbd872f4ad Cygwin: fenv.h: Convert to ASCII-only
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-14 11:48:29 +02:00
Corinna Vinschen 423fc83dfd Cygwin: utils: ps: use fputs to print fixed strings
Avoid gcc warning "format not a string literal and no format arguments"

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-09 08:41:18 +02:00
Corinna Vinschen 8bfb1afd6b Cygwin: utils: strace: fix format string
%ll is long valid for mingw builds.  Use this rather than %I64
to avoid a gcc warning

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-08 10:50:19 +02:00
Corinna Vinschen 37f4fea07c Cygwin: utils: change 3rd readlink param to size_t
Avoid gcc warnings

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-08 10:50:19 +02:00
Corinna Vinschen 13909bc262 Cygwin: utils: cygcheck: fix filesystem output format
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-08 10:50:13 +02:00
Corinna Vinschen 1e0a1f59d9 Cygwin: implement sched_getcpu
* create new function __get_cpus_per_group to evaluate # of CPU groups
* Call from  format_proc_cpuinfo and sched_getcpu
* Bump API minor version

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-07 14:51:10 +02:00
Mark Geisert b1952c03a8 Fix return value on aio_read/write success
Internally track resultant byte counts as ssize_t, but return 0 as int
for success indication, per POSIX.
2018-08-07 09:49:18 +02:00
Corinna Vinschen f16b198c3b Cygwin: Document fegetenv patch
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-03 09:35:31 +02:00
J.H. van de Water d79069d2ff Cygwin: fegetenv() should not disable exceptions
fnstenv MUST be followed by fldenv in fegetenv(), as the former disables all
exceptions in the x87 FPU, which is not appropriate here (fegetenv() ).
fldenv after fnstenv should reload the x87 FPU w/ the configuration that was
saved by fnstenv, i.e. a configuration that might have exceptions enabled.

Note: x86_64 uses SSE for floating-point, not the x87 FPU. However, because
feraiseexcept() attempts to provoke an exception using the x87 FPU, the bug
in fegetenv() will make this attempt futile here (x86_64).

Note: WoW uses the x87 FPU for floating-point, not SSE. Here anything that
would normally result in triggering an exception, not only feraiseexcept(),
will not be able to, as result of the bug in fegetenv().
2018-08-03 09:33:49 +02:00
Yaakov Selkowitz 7e09931ad9 Cygwin: fpathconf: update _PC_ASYNC_IO return value
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-07-25 15:00:43 -05:00
Yaakov Selkowitz f6417be2aa Cygwin: define _POSIX_ASYNCHRONOUS_IO
This feature is now available as of the recent AIO commits.

Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2018-07-25 10:48:55 -05:00
Mark Geisert 7f32efbf73 POSIX Asynchronous I/O support: other files
Updates to misc files to integrate AIO into the Cygwin source tree.
Much of it has to be done when adding any new syscalls.  There are
some updates to limits.h for AIO-specific limits.  And some doc mods.
2018-07-25 09:36:24 +02:00
Mark Geisert 87253cbe38 POSIX Asynchronous I/O support: fhandler files
This code is where the AIO implementation is wired into existing Cygwin
mechanisms for file and device I/O: the fhandler* functions.  It makes
use of an existing internal routine prw_open to supply a "shadow fd"
that permits asynchronous operations on a file the user app accesses
via its own fd.  This allows AIO to read or write at arbitrary locations
within a file without disturbing the app's file pointer.  (This was
already the case with normal pread|pwrite; we're just adding "async"
to the mix.)
2018-07-25 09:36:24 +02:00
Mark Geisert a9ffa71a15 POSIX Asynchronous I/O support: aio files
This is the core of the AIO implementation: aio.cc and aio.h.  The
latter is used within the Cygwin DLL by aio.cc and the fhandler* modules,
as well as by user programs wanting the AIO functionality.
2018-07-25 09:36:22 +02:00
Ken Brown 982dd20ed9 getfacl: Simplify by using acl_to_any_text 2018-07-25 09:32:36 +02:00
Ken Brown b610a9cf29 getfacl and setfacl: Align with Linux
Make getfacl print two colons instead of one after "other" and "mask".
Change the help text for setfacl to indicate that there can be either
one colon or two.
2018-07-23 17:31:09 +02:00
Corinna Vinschen e9f223877f Cygwin: move FP environment exports to common.din
We only have the symbols defined for i686 by accident since 2013...

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-07-20 13:55:26 +02:00
Mark Geisert 3e51cc478d fix duration handling in sigtimedwait 2018-07-19 13:18:49 +02:00
Corinna Vinschen 5ed8f2354f Cygwin: Treat PROCESSOR_ARCHITECTURE_INTEL as running under WOW64 on ARM64
Bug in current ARM64 WOW64: GetNativeSystemInfo returns
PROCESSOR_ARCHITECTURE_INTEL rather than PROCESSOR_ARCHITECTURE_ARM64.
Provide for this.

Make code better readable.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-07-12 15:28:13 +02:00
Corinna Vinschen a4f1f59bc7 Cygwin: Don't print FAST_CWD warning in WOW64 on ARM64 systems
No way to test this, yet.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-07-10 14:45:52 +02:00
Corinna Vinschen 698d93c4b4 Cygwin: fix a race in the FAST_CWD fallback code
Guard the entire operation with the FastPebLock critical section
used by RtlSetCurrentDirectory_U as well, thus eliminating the
race between concurrent chdir/fchdir/SetCurrentDirectory calls.

Streamline comment explaining the fallback method.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-07-10 14:13:15 +02:00
Takashi Yano 8e782bbd94 Fix a problem that connection to syslogd fails.
* fhandler_socket_local.cc (get_inet_addr_local): Change type from
  'static int' to 'int' to be callable from syslog.cc.
* syslog.cc (connect_syslogd): Use get_inet_addr_local() instead of
  getsockname() to retrieve name information of the syslogd socket.
2018-07-06 10:41:21 +02:00
Takashi Yano 0ce27ecd08 Cygwin: Include local ntsecapi.h
Our local ntsecapi.h wrapper corrects a bug in the definition of
SystemFunction036 which otherwise leads to crashes on 32 bit when
using RtlGenRandom.  The fhandler_socket_local.cc file accidentally
included the incorrect w32api version of that file, rather than the
local wrapper.  Fix it.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-07-04 14:17:28 +02:00
Takashi Yano 1c1cec9cdf Fix a bug of psiginfo() that changes the orientation of stderr.
* strsig.cc (psiginfo): Fix the problem that psiginfo() changes
  the orientation of stderr to byte-oriented mode if stderr is
  not oriented yet.
2018-07-03 15:38:47 +02:00
Corinna Vinschen 995d2a824a Cygwin: tape: Handle non-standard "no medium" error code
Certain tape drives (known example: QUANTUM_ULTRIUM-HH6) return
the non-standard ERROR_NOT_READY rather than ERROR_NO_MEDIA_IN_DRIVE
if no media is present.  ERROR_NOT_READY is not documented as valid
return code from GetTapeStatus.  Without handling this error code
Cygwin's tape code can't report an offline state to user space.

Fix this by converting ERROR_NOT_READY to ERROR_NO_MEDIA_IN_DRIVE
where appropriate.

Add a debug_printf to mtinfo_drive::get_status to allow requesting
user info without having to rebuild the DLL.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-06-29 15:31:15 +02:00
Corinna Vinschen 4b97244d12 Cygwin: define pthread_tryjoin_np/pthread_timedjoin_np _GNU_VISIBLE
These functions are GNU extensions.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-06-27 18:20:47 +02:00
Corinna Vinschen c9d6787e76 Cygwin: doc: add pthread_tryjoin_np, pthread_timedjoin_np
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-06-27 18:20:11 +02:00
Corinna Vinschen cb3ddf9e2a Cygwin: pthread_timedjoin_np: return ETIMEDOUT, not EBUSY
pthread_timedjoin_np returns ETIMEDOUT if a thread is still running,
not EBUSY as pthread_tryjoin_np.

Also, clean up initializing timeout in pthread_tryjoin_np.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-06-27 18:19:18 +02:00
Corinna Vinschen 732e0b395d Cygwin: Implement pthread_tryjoin_np and pthread_timedjoin_np
- Move pthread_join to thread.cc to have all `join' calls in
  the same file (pthread_timedjoin_np needs pthread_convert_abstime
  which is static inline in thread.cc)
- Bump API version

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-06-27 17:56:59 +02:00
Corinna Vinschen 6497fdfaf4 Cygwin: fix bumptious GCC 7 warnings
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-06-26 17:20:48 +02:00
Corinna Vinschen 6c55be9dbb Cygwin: Allow to build without experimental AF_UNIX code by default
Introduce __WITH_AF_UNIX preprocessor flag to enable the new code

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-06-26 16:31:17 +02:00
Corinna Vinschen 17918cc6a6 Cygwin: add Unicode patch to release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-06-26 10:21:18 +02:00
Corinna Vinschen dbe905c140 Cygwin: exceptions: fix FPE exception flags
The FPE flags for divisions by zero were not implemented

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-06-26 10:12:19 +02:00
Corinna Vinschen 3dc89bbafe Cygwin: signal.h: improve exception flags definition
- add numbers for readability
- add a preprocessor macro for each flag

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-06-26 10:12:10 +02:00
Takashi Yano 9c84bfd479 Fix the handling of out-of-band (OOB) data in a socket.
* fhandler.h (class fhandler_socket_inet): Add variable bool oobinline.
* fhandler_socket_inet.cc (fhandler_socket_inet::fhandler_socket_inet):
  Initialize variable oobinline.
(fhandler_socket_inet::recv_internal): Make the handling of OOB data
  as consistent with POSIX as possible. Add simulation of inline mode
  for OOB data as a workaround for broken winsock behavior.
(fhandler_socket_inet::setsockopt): Ditto.
(fhandler_socket_inet::getsockopt): Ditto.
(fhandler_socket_wsock::ioctl): Fix return value of SIOCATMARK command.
  The return value of SIOCATMARK of winsock is almost opposite to
  expectation.
* fhandler_socket_local.cc (fhandler_socket_local::recv_internal):
  Remove the handling of OOB data from AF_LOCAL domain socket. Operation
  related to OOB data will result in an error like Linux does.
(fhandler_socket_local::sendto): Ditto.
(fhandler_socket_local::sendmsg): Ditto.

This fixes the issue reported in following post.
https://cygwin.com/ml/cygwin/2018-06/msg00143.html
2018-06-22 10:20:08 +02:00
Ken Brown ebc9171ede Bump Cygwin DLL version to 2.11.0 2018-06-07 09:42:36 +02:00
Ken Brown 2ea436b433 Cygwin: Document clearenv and bump API minor
Also add earlier "What changed" items to new-features.xml.
2018-06-07 09:42:36 +02:00
Ken Brown 3a049236db Cygwin: Remove workaround in environ.cc
Commit ebd645e on 2001-10-03 made environ.cc:_addenv() add unneeded
space at the end of the environment block to "work around problems
with some buggy applications."  This clutters the code and is
presumably no longer needed.
2018-06-07 09:42:36 +02:00
Ken Brown defaa2ca31 Cygwin: Implement the GNU extension clearenv 2018-06-07 09:42:36 +02:00
Ken Brown 9234545e3d Cygwin: Allow the environment pointer to be NULL
Following glibc, interpret this as meaning the environment is empty.
2018-06-07 09:42:36 +02:00
Ken Brown 1ecbb8d7b7 Cygwin: Clarify some code in environ.cc 2018-06-07 09:42:36 +02:00
Ken Brown a7c23d109f Cygwin: Add pthread_rwlock_* fix to release notes 2018-06-01 21:59:42 +02:00
Ken Brown 59847b5d73 Declare the pthread_rwlock_* functions if __cplusplus >= 201402L
Some of these functions are used in the <shared_mutex> C++ header.
2018-06-01 12:09:12 +02:00
Corinna Vinschen 8ac6b15487 Cygwin: Add stack alignment crash after fork fix to release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-05-29 18:43:20 +02:00
Sergejs Lukanihins 06797545b3 Cygwin: Fixing the math behind rounding down ch.stacklimit to page size. 2018-05-29 18:37:33 +02:00
Corinna Vinschen 53960db861 Cygwin: Add Sergejs Lukanihins to contributors
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-05-29 18:34:54 +02:00