The check for current timestamp > start timestamp has an unwelcome
side effect: The loop is not left as long as the current timestamp
hasn't been incremented. This leads to busy loops of about one tick
(10 to 16 ms per MSDN).
This fixes https://cygwin.com/ml/cygwin/2016-05/msg00327.html
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
'man termios' says:
"A read(2) returns at most one line of input" in canonical mode.
On cygwin 2.5.1, read(2) returns all data in buffer if the buffer
size specified is large enough. This behaviour is correct in
noncanonical mode, but is not correct in canonical mode.
While checking this problem, I found a bug of tcflush(). tcflush()
flushes only partial data in the buffer. The patch also fixes this bug.
The patch has also been tested against the problem reported in
https://cygwin.com/ml/cygwin/2016-05/msg00318.html.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The rule to make tlsoffset{64}.h has a flaw. If cygtls.h can't be
built for whatever reason, it *still* regenerates tlsoffsets{64}.h,
just with size 0. If the bug is not in cygtls.h itself, this behaviour
breaks further building, because fixing the problem won't result in
regenerating tlsoffset{64}.h. Manual intervention is required.
Fix that by removing tlsoffsets{64}.h if gentls_offsets fails.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Using libattr's <xattr/xattr.h> requires consumers to explicitly include
<sys/types.h> first, but glibc's header in sys/ already contains the include.
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
Temporarily revert to use PROCESS_QUERY_INFORMATION instead of
PROCESS_QUERY_LIMITED_INFORMATION to make sure every aspect of the
next release is still XP/2003 compatible.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
We're appending a dot to the filename before calling LoadLibrary to
override ".dll" automagic. This only worked for paths, not for simple
filenames since it required a slash in the pathname. Fix that.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
So far drive letter paths have been handled special since path_conv
leaves the incoming path untouched except for converting backslashes
to forward slashes. However, if the incoming path starts with a
long path prefix, the same problem occurs. Therefore handle all
paths starting with a backslahs the same way.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
In case the TZ variable is empty, Cygwin fetches timezone info from
Windows. Extracting the timezone short name uses isupper on wide chars.
Replace with explicit check for A <= character <= Z to be independent
of undefined behaviour.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Throughout mmap, size-related variables and parameters are still using
DWORD as type, which disallows mapping ranges > 4Gigs. Fix this by
using SIZE_T throughout for those vars and parameters.
Also, drop unused off parameter from 1st variant of mmap_record::map_pages.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
So far pthread::postcreate() only sets the thread priority at all, only
if the inherit-scheduler attribute is PTHREAD_EXPLICIT_SCHED. This
completely ignores the PTHREAD_INHERIT_SCHED case, since in contrast
to POSIX, a thread does not inherit its priority from the creating
thread, but always starts with THREAD_PRIORITY_NORMAL.
pthread_getschedparam() only returns what's stored in the thread attributes,
not the actual thread priority.
This patch fixes both problems.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
So far the scheduler priority handling is not POSIX compatible.
The priorities use a range of -14 up to +15, which means it's not clear
if the POSIX-required return value of -1 in case of an error is *really*
an error or just the valid priority value -1. Even more confusing, -14
is the *max* value and 15 is the *min* value. Last but not least this
range doesn't match the POSIX requirement of at least 32 priority values.
This patch cleans up scheduler priority handling and moves the valid
priority range to 1 (min) - 32 (max). It also adds a function
sched_get_thread_priority() which will help to make thread priority
more POSIX-like.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* select.h: Eliminate redundant select_stuff::select_loop state.
* select.cc (select): Eliminate redundant
select_stuff::select_loop state. Eliminate redundant code for
zero timeout. Do not return early on early timer return.
(select_stuff::wait): Eliminate redundant
select_stuff::select_loop state.
* select.h: Change prototype for select_stuff::wait() for larger
microsecond timeouts.
* select.cc (pselect): Convert from old cygwin_select().
Implement microsecond timeouts.
(cygwin_select): Rewrite as a wrapper on pselect().
(select): Implement microsecond timeouts.
(select_stuff::wait): Implement microsecond timeouts with a timer
object.
Always provide register_t via <sys/types.h> for glibc and BSD
compatibility. Define __BIT_TYPES_DEFINED__ to 1 like glibc for legacy
header files.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
Resurrect <machine/_user_types.h> for use in <sys/types.h>. Newlib
targets may provide an own version of <machine/types.h> in their machine
directory to add custom user types for <sys/types.h>. Check the
_SYS_TYPES_H header guard to prevent a direct include of
<machine/types.h>, since the <machine/types.h> file is a Newlib
speciality.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
For all pthread init functions, POSIX says
Results are undefined if pthread_FOO_init() is called specifying an
already initialized pthread_FOO object.
So far our pthread init functions tested the incoming object if it's
already an initialized object and, if so, returned EBUSY. That's ok
*iff* the object was already initialized. However, as the example in
https://cygwin.com/ml/cygwin/2016-04/msg00473.html shows, an uninitialized
pthread object could also accidentally look like an initialized object
and then returning EBUSY is not ok.
Consequentially, all those tests are dangerous. Per POSIX, an application
has to know what its doing when calling any of the pthread init functions
anyway, and re-initializing the object is just as well as undefined
behaviour as is returning EBUSY on already initialized objects.
* thread.cc (pthread_attr_init): Drop check for already initialized
object.
(pthread_condattr_init): Ditto.
(pthread_rwlockattr_init): Ditto.
(pthread_mutexattr_init): Ditto.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Introduce <machine/_endian.h> to let target based customization of
<machine/endian.h> via
* _LITTLE_ENDIAN,
* _BIG_ENDIAN,
* _PDP_ENDIAN, and
* _BYTE_ORDER.
defines. Add definitions expected by FreeBSD to
<machine/endian.h> like
* _QUAD_HIGHWORD,
* _QUAD_LOWWORD,
* __bswap16(),
* __bswap32(),
* __bswap64(),
* __htonl(),
* __htons(),
* __ntohl(), and
* __ntohs().
Also, if __BSD_VISIBLE
* LITTLE_ENDIAN,
* BIG_ENDIAN,
* PDP_ENDIAN, and
* BYTE_ORDER.
Targets that define __machine_host_to_from_network_defined in
<machine/_endian.h> must provide their own implementation of
* __htonl(),
* __htons(),
* __ntohl(), and
* __ntohs(),
otherwise a default implementation is provided by <machine/endian.h>.
In case of GCC defines to builtins are used.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
We can't handle the S_ISGID bit if the child didn't inherit a NULL SID
ACE with the S_ISGID bit set. On directories without default ACL
entries we would have to add an inheritable NULL SID ACE and nothing else.
This in turn results in permission problems when calling set_file_sd
from set_created_file_access. That's fixable, but it would only work
for files created from Cygwin while files created from native Windows
tools end up with really ugly permissions.
This patch only makes sure that the S_ISGID bit is reset for a directory
if it has no inheritable ACEs. Still having the 's' bit shown in ls or
getfacl output would be misleading. So, calling `setfacl -k' on a dir
also removes the S_ISGID bit now.
* sec_acl.cc (set_posix_access): Drop S_ISGID bit on directories
without inheritable ACEs. Explain why.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
So far we tweaked ACL_GROUP_OBJ and ACL_MASK values the same way when
creating a file. We now do what POSIX requires, namely just change
ACL_MASK if it's present, otherwise ACL_GROUP_OBJ. Note that we only
do this at creation time. Chmod still tweaks both to create less
surprising results for the unsuspecting user.
Additionally make sure to take umask only into account if no ACL_MASK
value is present. That has been missed so far.
* sec_acl.cc (set_posix_access): Perform check for non-existant
default ACEs earlier. Ignore umask also if ACL_MASK is present.
Only set owner_eq_group if we're actually handling a user entry.
Mention chmod in a comment.
* security.cc (set_created_file_access): Perform group/mask
permission setting as required by POSIX 1003.1e.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Commit e2ea143 forgot to take special POSIX bits into account.
* sec_acl.cc (set_posix_access): Make sure to create NULL SID
ACE if any special POSIX permission bits are set.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Commit f75114fc was supposed to drop NULL SIDs in case the permissions
are simple enough not to require mask values or special POSIX bits
(S_ISVTX, etc). The check was incorrect. This patch is supposed to
fix the problem.
* sec_acl.cc (set_posix_access): Fix condition under which we
write a NULL SID.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Newlib defines defaults for internal types via <sys/_types.h> and uses
<machine/_types.h> to let targets define their own type if necessary.
Previously for example
#ifndef __dev_t_defined
typedef short __dev_t;
#endif
However, the __*_t_defined pattern conflicts with the glibc type guard
pattern for user types, e.g. dev_t in this example. Introduce a
__machine_*_t_defined pattern for internal types (defined by
<machine/_types.h>, used by <sys/_types.h>). For example
#ifndef __machine_dev_t_defined
typedef short __dev_t;
#endif
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
Remove off_t typedef from cygwin/types.h thus relying on sys/types.h.
Introduce winsup/cygwin/machine/_types.h and move some types shared
with newlib into it. Get rid of their definition in cygwin/types.h.
Add same handling for __key_t/key_t as for the other types.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This change solves a glibc/BSD compatibility problem.
glibc and BSD use double underscore types for internal types. The Linux
port of Newlib uses some glibc provided internal type definitions which
are not protected by guard defines, e.g. __off_t. To avoid a conflict
Newlib uses single underscore types for some internal types, e.g.
_off_t. However, for BSD compatibility we have to define the internal
types with double underscore names in <sys/_types.h>.
The header file <machine/types.h> is Newlib-specific. It was used
instead of <sys/_types.h> to provide the internal type definitions
_CLOCK_T, _TIME_T_, _CLOCKID_T_, _TIMER_T_, and __suseconds_t. Move
these definitions to <sys/_types.h> (there exist two instances of this
file, one for Linux and one for all other targets). This makes the
_HAVE_SYSTYPES configuration define obsolete (could possibly break the
__RDOS__ target). Use the standard <sys/_types.h> include throughout.
Move __loff_t defintion to default (non-Linux) <sys/_types.h>. Define
it via _off64_t to avoid a dependency on the compiler.
Provide the __off_t definition via default (non-Linux) <sys/_types.h>
based on _off_t for all systems except Cygwin. For Cygwin use _off64_t.
Define off_t via __off_t.
Provide the __pid_t definition via default (non-Linux) <sys/_types.h>.
This prevents a potential __pid_t and pid_t incompatibility. Add BSD
guard defines for pid_t.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
Cygwin's strxfrm/wcsfrm treated a too short output buffer as an error
condition and always returned the size value provided as third parameter.
This is not as it's documented in POSIX.1-2008. Rather, the only error
condition is an invalid input string(*).
Other than that, the functions are supposed to return the length of the
resulting sort key, even if the output buffer is too small. In the latter
case the content of the output array is unspecified, but it's the job
of the application to check that the return value is greater or equal to
the provided buffer size.
(*) We have to make an exception in Cygwin: strxfrm has to call the
UNICODE function LCMapStringW for reasons outlined in a source comment.
If the incoming multibyte string is so large that we fail to malloc
the space required to convert it to a wchar_t string, we have to
ser errno as well since we have nothing to call LCMapStringW with.
* nlsfuncs.cc (wcsxfrm): Fix expression computing offset of
trailing wchar_t NUL. Compute correct return value even if
output buffer is too small.
(strxfrm): Handle failing malloc. Compute correct return value
even if output buffer is too small.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
In 7346568 (Make requested console reports work, 2016-03-16), code was
introduced to report the current cursor position. It works by using a
pointer that either points to the next byte in the readahead buffer, or
to a NUL byte if the buffer is depleted, or the pointer is NULL.
These conditions are heeded in the fhandler_console::read() method, but
the condition that the pointer can point at the end of the readahead
buffer was not handled properly in the get_cons_readahead_valid()
method.
This poses a problem e.g. in Git for Windows (which uses a slightly
modified MSYS2 runtime which is in turn a slightly modified Cygwin
runtime) when vim queries the cursor position and immediately goes on to
read console input, erroneously thinking that the readahead buffer is
valid when it is already depleted instead. This condition results in an
apparent freeze that can be helped only by pressing keys repeatedly.
The full Git for Windows bug report is here:
https://github.com/git-for-windows/git/issues/711
Let's just teach the get_cons_readahead_valid() method to handle a
depleted readahead buffer correctly.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>