Rounddown incoming addr on a page boundary. Without this, we may end
up with a fork error for private, anonymous maps. The reason is, we
use VirtualAlloc in this case which will potentially overcommit if
addr is not on a page boundary. This isn't taken into account in
bookkeeping, but fixup_mmaps_after_fork will eventually stumble over
this when trying to reproduce the copy-on-write pages: VirtualQuery
returns a region reaching beyond the supposedly allocated address
range and from there it goes downhill.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* change memcpy to internal _memcpy not setting the return value in %rax
* implement all memcpy-like functions as caller to _memcpy, setting %rax
to correct return value beforehand. This is possible because _memcpy
does not use %rax at all
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Since commit 8128f5482f, we have all the
non-tracing functions listed in posixoptions(7). The tracing functions
are gated by their own option, and are obsolecent anyway.
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
* Don't use a bool var to store three states (-1, 0, 1).
* Correctly check for NT_SUCCESS of a function returning NTSTATUS.
* Straighten out code for better readability.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Commit 603ef545bd broke this snippet and
commit 5b312b4747 didn't help at all since
FILE_CREATE is exactly *not* the situation the test was originally
supposed to handle.
In fact, none of the open flags used by fhandler_base::open actually
hits this problem anymore, so just drop the code.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Difference to Linux: We can't create files which don't show up
in the filesystem due to OS restrictions. As a kludge, make a
(half-hearted) attempt to hide the file in the filesystem.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* Fix the maximum number of sockets allowed in the session to 2048,
instead of making it relative to sizeof(wsa_event).
The original choice of 2048 was in order to fit the wsa_events array
in the .cygwin_dll_common shared section, but there is still enough
room to grow there to have 2048 sockets on 64-bit as well.
* Return an error and set errno=ENOBUF if a socket can't be created
due to this limit being reached.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Also updates the fhandler_*::ftruncate implementations to adhere to the same
semantics. The error handling semantics of those syscalls that use
fhandler_*::ftruncate are moved to the implementations of those syscalls (
in particular ftruncate() and friends still set errno and return -1 on error
but that logic is handled in the syscall implementation).
Under some not quite clear conditions, NFS fails to use its
unlink workaround to rename a file to ".nfsXYZ". The problem has been
reproduced with the GAWK testext.awk testcase. To workaround this in
Cygwin, we now call try_to_bin on NFS, too. For some reason NFS doesn't
fail to rename the .cygXYZ file to .nfsXYZ after this Cygwin rename.
Fix comment in unlink_nt accordingly.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The "final trick" code in try_to_bin accidentally never worked on
remote drives because it relies on rootdir. Which isn't set for
remote unlinks. The code now creates a full path for remote files.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The try_to_bin function isn't called for netapp FSes anyway, so testing
for this FS type in the function is moot.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The first argument of gethostbyaddr needs to accept a generic pointer
to be compatible with e.g. struct in_addr *. This caused an issue
compiling krb5-1.15.
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
herror etc. are MISC, rcmd etc. are BSD, addrinfo functions are
POSIX.1-2001, except for IDN functionality which is GNU.
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
When fork fails, we can use "%s" now with system_sprintf for the errmsg
rather than a (potentially too small) buffer for the format string.
* fork.cc (fork): Use "%s" with system_printf now.
With "%C" format string, argument may convert in up to MB_LEN_MAX bytes.
Relying on sys_wcstombs to add a trailing zero here requires us to
provide a large enough buffer.
* smallprint.c (__small_vsprintf): Use MB_LEN_MAX+1 bufsize for "%C".
The third argument of RtlLookupFunctionEntry actually is documented as
_Inout_opt_ for both x64 and ARM, although generic doc says _Out_ only.
* exceptions.cc (__unwind_single_frame): Initialize hist variable.
In order to avoid the year 2038 problem, define time_t to a signed
integer with at least 64-bits. The type for time_t can be forced to
long with the --enable-newlib-long-time_t configure option or with the
_USE_LONG_TIME_T system configuration define.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
Always use the __-decorated form of an attribute name in public
headers, as the bareword form is in the user's namespace, and we
don't want compilation to break just because the user defines the
bareword to mean something else.
Signed-off-by: Eric Blake <eblake@redhat.com>
- pthread_mutex::lock now takes a PLARGE_INTEGER timeout pointer
and uses that in the call to cygwait.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
- Introduce inline helper pthread_convert_abstime. It converts
an absolute timespec to a Windows LARGE_INTEGER timestamp,
depending on the used clock.
- Use this function from pthread_cond_timedwait and semaphore::timedwait
- Merge semaphore::_wait and semaphore::_timedwait into single _wait
method, taking a LARGER_INTEGER timestamp.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This is copied from musl (MIT license). This is newer and more thorough
than that of FreeBSD currently shipped only on Cygwin.
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
For historical reasons peek_console was calling the functions
PeekConsoleInputA and ReadConsoleInputA. However, these functions are
not working correctly under at least codepage 65001 (UTF-8) on systems
prior to Windows 10.
Use PeekConsoleInputW and ReadConsoleInputW instead, which work
correctly under all systems and all codepages.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
FillConsoleOutputCharacterA doesn't work correctly in codepage 65001
(UTF-8). Looks like the character conversion function from ascii char
to unicode char works incorrectly then. Use FillConsoleOutputCharacterW
instead.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
So far we had two functions checking the content of a reparse point,
readdir_check_reparse_point in fhandler_disk_file.cc for the sake of
readdir, and symlink_info::check_reparse_point for the sake of
generic path checking.
* Rename check_reparse_point_target helper to check_reparse_point_string
and convert to static function.
* Create new check_reparse_point_target helper containing the core
reparse point checking code
* Just call check_reparse_point_target from readdir_check_reparse_point
and symlink_info::check_reparse_point and only perform the unique
task in those functions.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
struct sigaction is POSIX.1-1990 but siginfo_t, which is used by its
sa_sigaction member, is POSIX.1b-1993. Therefore it needs to be guarded
as well, and as part of a union, the struct size is protected.
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
When SA_RESTART is not set on a socket, a blocking send() that is
interrupted mid-transition by a signal should return success (and
report just how many bytes were actually transmitted).
The err variable used here was not always guaranteed to be set
correctly in the loop, so better to just remove it and call
WSAGetLastError() explicitly.
There are two common sigpause variants, both of which take an int argument.
If you request _XOPEN_SOURCE or _GNU_SOURCE, you get the System V version,
which removes the given signal from the process's signal mask; otherwise
you get the BSD version, which sets the process's signal mask to the given
value.
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
So far Cygwin's readdir returned the inode number of a mount target
in d_ino, rather than the actual inode number of the mount point in
the underlying filesystem. This not only results in a performance
hit if the mount target is a remote FS, it is also not done on other
POSIX systems.
Remove the code evaluating the mount target inode number.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This patch fixes a minor compatibility issue w/ cygwin mount point handling in
readdir(), compared to equivalent behavior of Linux and MacOS. dentry.d_ino
should indicate the INO of the mount point itself, not the target volume root
folder.
Changed return type from readdir_check_reparse_point to uint8_t, to avoid
unnecessarily being implicitly cast to and from a signed int.
Renamed a related local variable "attr" to "oattr" that was eclipsing a member
variable with the same name.
Joe L.
Mingw-w64 (where the code has been taken from) has 4 byte longs
independently of the architecture but x86_64 Cygwin has 64 bit longs.
So use fistpll instead of fistpl on x86_64 Cygwin.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Workaround a bug (or undocumented behaviour) in LCMapStringW:
It's documented(*) that the cchDest parameter is a byte count with
LCMAP_SORTKEY, but a character count otherwise. But the docs don't
state what happens if you combine LCMAP_SORTKEY with LCMAP_BYTEREV.
Tests indicate that LCMAP_SORTKEY treats cchDest as byte count, but
then LCMAP_BYTEREV treats it as char count in the same call. So the
latter swaps twice as much bytes in the destination buffer than the
byte count it returns, which potentially results in writing past the
end of the given output buffer.
Solution: Don't specify LCMAP_BYTEREV in the LCMapStringW(LCMAP_SORTKEY)
call, rather byte swap afterwards.
(*) https://msdn.microsoft.com/en-us/library/windows/desktop/dd318702(v=vs.85).aspx
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This leads to excessive lag when stracing processes if the inferior
process checks the process table. The reason is that ppid isn't set
in the procinfo memory of the dynamically loading strace itself.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Add new SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE flag to
CreateSymbolicLinkW call when running on W10 1703 or later.
Don't do that on older versions to avoid ERROR_INVALID_PARAMETER.
Preliminary, needs testing. There's an off-chance that the
flag results in the same ERROR_INVALID_PARAMETER on 1703 if the
developer settings are not enabled.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
RtlGetNtVersionNumbers returns the build number with some upper bits
set for no apparent reason. The fact that RtlGetNtVersionNumbers is
undocumented doesn't exactly help.
Just filter out the upper WORD for now. If build numbers are in
danger to become 6 digit numbers, re-evaluate.
Always retrieve FileCompressionInformation for non-empty
files if FileStandardInformation returns 0 allocated blocks.
This fixes stat.st_blocks for files compressed with CompactOS method.
Signed-off-by: Christian Franke <franke@computer.org>
previous commit 4c90db7bc8 introduced
a compile time error because libm/common/s_infconst.c used the remove
__fmath, __dmath, and __ldmath union types.
Since this is very old, and unused for a very long time, just drop the
file and thus the __infinity constants entirely.
Exception: Cygwin exports __infinity from the beginning. There's a very,
VERY low probability that any existing executable or lib still uses this
constant, but we just keep it in for backward compat, nevertheless.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Explicitly format the contents of /proc/loadavg to avoid the decimal point
getting localized according to LC_NUMERIC. Using anything other than '.' is
wrong and breaks top.
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
v2:
autoload PerfDataHelper functions
Keep loadavg in shared memory
Guard loadavg access by a mutex
Initialize loadavg to the current load
v3:
Shared memory version bump isn't needed if we are only extending it
Remove unused autoload
Mark inititalized flags as NO_COPY for correct behaviour in fork child
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>