Commit Graph

12090 Commits

Author SHA1 Message Date
Corinna Vinschen 99cd3df6ec Cygwin: timerfd: drop outdated TODO comment
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-04 21:08:03 +01:00
Corinna Vinschen 49ea15ef17 Cygwin: fix typo
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-02 21:15:50 +01:00
Corinna Vinschen d5d9aac759 Cygwin: tweak Cygwin PID change release note
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-02 21:13:37 +01:00
Corinna Vinschen 658f939003 Cygwin: kill(1): introduce a -W option
Allow to kill processes using Windows PIDs on the command line.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-02 21:02:00 +01:00
Corinna Vinschen 3a3934252c Cygwin: spawn: create and maintain winpid symlinks
- If the execve'ed process is a non-Cygwin process, we have to
  create the matching winpid symlink and remove the old one
  ourselves.

- If we spawn a child, the winpid symlink has to be maintained
  by the child process, otherwise it disappears if the parent
  process exits.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-02 20:01:41 +01:00
Corinna Vinschen d6cf2b781f Cygwin: pinfo: simplify create_winpid_symlink
The arguments are not used anyway, so drop them.  When called,
procinfo->dwProcessId is already set right, so we don't have
to access myself_initial.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-02 18:11:42 +01:00
Corinna Vinschen f5c2d4db5b Cygwin: kill(1): revert casts required for 32 bit to avoid spurious warnings
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-02 15:32:28 +01:00
Corinna Vinschen 2cd6829619 Cygwin: Makefile.in: Fix previous version info generation fix
Commit 231ad6941f looks good...
as long as you never build Cygwin from scratch.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-02 15:27:29 +01:00
Corinna Vinschen 8de660271f Cygwin: kill(1): disallow killing process using raw Windows PID
This may end up killing the wrong process.  Only allow Cygwin PID.

Slightly clean up code: Remove outdated W95 considerations.  Fix
a bug in commandline argument processing.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-02 15:00:39 +01:00
Corinna Vinschen 448cf5aa4b Cygwin: processes: fix handling of native Windows processes
Since commit b5e1003722, native
Windows processes not started by Cygwin processes don't have a
Cygwin PID anymore.  This breaks ps -W and kill -f <WINPID>.

Introduce MAX_PID (65536 for now).

Cygwin processes as well as native Windows processes started
from a Cygwin process get a PID < MAX_PID.  All other native
Windows processes get a faked Cygwin PID >= MAX_PID.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-02 12:23:39 +01:00
Corinna Vinschen 231ad6941f Cygwin: Makefile.in: Fix another dependency problem in version info
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-02 11:13:17 +01:00
Corinna Vinschen b5e1003722 Cygwin: processes: use dedicated Cygwin PID rather than Windows PID
Using the Windows PID as Cygwin PID has a few drawbacks:

- the PIDs on Windows get reused quickly.  Some POSIX applications choke
  on that, so we need extra code to avoid too quick PID reuse.

- The code to avoid PID reuse keeps parent process handles and
  (depending on a build option) child processes open unnecessarily.

- After an execve, the process has a split personality:  Its Windows PID
  is a new PID, while its Cygwin PID is the PID of the execve caller
  process.  This requires to keep two procinfo shared sections open, the
  second just to redirect process info requests to the first, correct
  one.

This patch changes the way Cygwin PIDs are generated:

- Cygwin PIDs are generated independently of the Windows PID, in a way
  expected by POSIX processes.  The PIDs are created incrementally in
  the range between 2 and 65535, round-robin.

- On startup of the first Cygwin process, choose a semi-random start PID
  for the first process in the lower PID range to make the PIDs slightly
  unpredictable.  This may not be necessary but it seems kind of inviting
  to know that the first Cygwin process always starts with PID 2.

- Every process not only creates the shared procinfo section, but also a
  symlink in the NT namespace, symlinking the Windows PID to the Cygwin
  PID.  This drops the need for the extra procinfo section after execve.

- Don't keep other process handles around unnecessarily.

- Simplify the code creating/opening the shared procinfo section and
  make a clear distinction between interfaces getting a Cygwin PID and
  interfaces getting a Windows PID.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-01 20:06:47 +01:00
Corinna Vinschen c0b9f600f9 Cygwin: remove outdated vfork doc
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-01 13:37:28 +01:00
Corinna Vinschen 210bd56aa2 Cygwin: /proc: don't exit prematurely from /proc/PID/status
If a process is just exiting, requesting memory info may fail
with STATUS_PROCESS_IS_TERMINATING.  Right now the code just bails
out if fetching mem info fails.  However, the rest of the info is
still valuable for procps, so just carry on.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-01 13:18:15 +01:00
Corinna Vinschen 351b57527d Cygwin: Add pthread exception handling patch to release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-02-01 10:45:27 +01:00
Corinna Vinschen 9a5abcc896 Cygwin: x86_64: pthreads: Install exception handler after switching stack
After creating a pthread, the stack gets moved to the desired memory
location.  While the 32 bit thread wrapper copies the exception handler
information to the new stack (so we have at least *some* exception
handler present), the x86_64 code didn't perform any exception handler
magic.  Fix that.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-30 20:05:39 +01:00
Corinna Vinschen ba3e20894d Cygwin: document W10 1803 per-directory case-sensitivity behaviour
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-30 16:16:25 +01:00
Corinna Vinschen ef8ce3077f Cygwin: fork: fix child process permissions, take 2
VirtualQueryEx, called by fixup_mmaps_after_fork, requires
PROCESS_QUERY_INFORMATION permissions per MSDN.  However, testing
shows that PROCESS_QUERY_LIMITED_INFORMATION is sufficient when
running the same code on Windows 8.1 or Windows 10.  Fix the code
to give the forked child always PROCESS_QUERY_INFORMATION perms
on Windows Vista/7 and respective server releases.

Revert now unneeded patch to check_token_membership as well.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-30 12:18:03 +01:00
Corinna Vinschen a52396bd07 Cygwin: raise: change to call pthread_kill
POSIX requires that raise(3) is equivalent to

  pthread_kill(pthread_self(), sig);

in multi-threaded applications.  Our raise just called kill(sig).
Fix that.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-30 11:36:45 +01:00
Corinna Vinschen 4d738e0f62 Cygwin: execve: reduce parent handle to non-inheritable SYNCHRONIZE
Keeping an inheritable handle open results in that handle being
spilled over into grandchild processes, which is not desired.
Duplicate original parent handle into a non-inheritable one with
minimal SYNCHRONIZE permissions and close the original handle.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-29 20:37:00 +01:00
Corinna Vinschen 5a0f2c00aa Cygwin: fork/exec: fix child process permissions
- Exec'ed/spawned processes don't need PROCESS_DUP_HANDLE.  Remove that
  permission from the parent handle.

- PROCESS_QUERY_LIMITED_INFORMATION doesn't work for Windows 7 if the
  process is started as a service.  Add PROCESS_QUERY_INFORMATION for
  pre-Windows 8 in that case.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-29 17:59:23 +01:00
Corinna Vinschen c86b2f549b Cygwin: Makefile.in: Improve dependency for version info
The version info only depends on the object files.  This results
in the version info not being rebuild immediately if a source
file is changed.  Rather, the version info is only rebuilt on the
next make run.

Fix that by making the version info build rule dependent on the
source files.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-29 17:55:37 +01:00
Corinna Vinschen e148aa62a7 Cygwin: procfd: improve debug output
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-28 10:24:39 +01:00
Corinna Vinschen 2741dd0550 Cygwin: seteuid: disable unused funcs and lsaauth subdir
If S4U proves to be usable alone, remove this code entirely.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-28 10:24:18 +01:00
Corinna Vinschen 3b21333172 Cygwin: spawn: revert incorrect restriction of permissions
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-27 22:42:41 +01:00
Corinna Vinschen 69cc7a0686 Cygwin: fork: restrict parent handle perms and drop handle after use
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-27 13:15:31 +01:00
Corinna Vinschen 0fb497165f Cygwin: seteuid: use Kerberos/MsV1_0 S4U authentication by default
- This simple and official method replaces cyglsa and "create token"
  methods.  No network share access, same as before.

- lsaauth and create_token are disabled now.  If problems crop up,
  they can be easily reactivated.  If no problems crop up, they
  can be removed in a while, together with the lsaauth subdir.

- Bump Cygwin version to 3.0.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26 19:41:03 +01:00
Corinna Vinschen 84230b71c6 Cygwin: uname: Raise size of utsname fields and revamp uname(2) output
New format:

  sysname:      CYGWIN_NT-${osversion}-${os_build_number}[-WOW64]
  nodename:     `gethostname`
  release:      ${cygwin_version}-${API minor}.${arch}[.snap]
  version:      YYYY-MM-DD HH:MM UTC
  machine:      ${arch}
_GNU_SOURCE:
  domainname:   `getdomainname`
!_GNU_SOURCE:
  __domainname: `getdomainname`

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26 18:37:25 +01:00
Corinna Vinschen 6ffcc50f19 Cygwin: netdb.h: fix __GNU_VISIBLE tests
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26 18:34:03 +01:00
Corinna Vinschen 0e3fd33321 Cygwin: create_token: Return NULL, not INVALID_HANDLE_VALUE
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26 12:42:38 +01:00
Corinna Vinschen 3a1ed0ef70 Cygwin: syscalls.cc: fix formatting
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26 12:42:38 +01:00
Corinna Vinschen c524a915a5 Cygwin: lsaauth: Drop outdated test for loading Secur32.dll
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26 12:42:37 +01:00
Corinna Vinschen 02373d8bec Cygwin: seteuid: work with password-less user switch as well
The previous patch failed with password-less auth because in
that case the return code from get_server_groups wasn't tested.
Fix that.  Also make sure that get_server_groups does not
check if the account is disabled or locked out when just fetching
the group list for initgroups or getgrouplist.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-24 21:20:09 +01:00
Corinna Vinschen 2c12a2c32a Cygwin: seteuid: refuse changing uid to disabled or locked out user
So far seteuid could change uid to any existing account, given
sufficient permissions of the caller.  This is kind of bad since
it disallows admins to refuse login to disabled or locked out
accounts.

Add check for the account's UF_ACCOUNTDISABLE or UF_LOCKOUT flags
and don't let the user in, if one of the flags is set.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-24 16:24:35 +01:00
Corinna Vinschen 2166f7dc0d Cygwin: net: unify gethostname/getdomainname
Use info from same source (GetNetworkParams).
Also move getdomainname near gethostname in source.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-24 14:22:24 +01:00
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