Commit Graph

17591 Commits

Author SHA1 Message Date
asomers 84a6dba57e Fix C++ includability of crypto headers with static array sizes
C99 allows array function parameters to use the static keyword for their
sizes. This tells the compiler that the parameter will have at least the
specified size, and calling code will fail to compile if that guarantee is
not met. However, this syntax is not legal in C++.

This commit reverts r300824, which worked around the problem for
sys/md5.h only, and introduces a new macro: min_size(). min_size(x) can
be used in headers as a static array size, but will still compile in C++
mode.

Reviewed by:	cem, ed
MFC after:	4 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D8277

fix a typo in __STDC_VERSION__ in __min_size requirements

MFC after:	1 week
Sponsored by:	Panzura
2017-04-04 11:44:02 +02:00
dim e0dabc0e8d Stop exposing the C11 _Atomic() macro in <sys/cdefs.h>, when compiling for C++.
It clashes with the one in libc++'s <atomic> header.

(Previously, the _Atomic() macro was defined in <stdatomic.h>, which is
only for use with C11, but for various reasons it was moved to its
current location in r251804.)

Discussed with:	bdrewery, ed
MFC after:	2 weeks
2017-04-04 11:43:49 +02:00
pfg 086730fb14 Rename __sentinel to __null_sentinel
GCC 5 uses a conflicting __sentinel definition in include/c++/bits/stl_algo.h

Reported by:	matteo
2017-04-04 11:41:13 +02:00
Sebastian Huber f70d9ae6ad Use enum __packed in favour of -fshort-enums
Some architectures like ARM encode the short enum option state in the
object file and the linker checks that this option is consistent for all
objects of an executable.  In case applications use -fno-short-enums,
then this leads to linker warnings.  Use the enum __packed attribute for
the relevent enums to avoid the -fshort-enums compiler option.  This
attribute is at least available on GCC, LLVM/clang and the Intel
compiler.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2017-04-03 10:26:33 +02:00
Catherine Moore 571c69656a Use .syntax unified instead of .syntax divided. 2017-03-30 17:18:12 +02:00
Corinna Vinschen 577c9d55da Add latest changes to Cygwin release information
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-28 13:42:11 +02:00
Corinna Vinschen b5b03d2d5f Change CURR_SHARED_MAGIC to account for getloadavg patch
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-28 13:41:31 +02:00
Jon Turney d0a359f6d2 Implement getloadavg()
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>
2017-03-27 22:03:58 +01:00
Jon Turney b568f92c50 declaration of ppoll() by poll.h should be guarded by _GNU_SOURCE
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2017-03-27 22:03:01 +01:00
Corinna Vinschen bbffd7ce7a Recognize Netapp mode supporting reparse points
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-27 20:28:03 +02:00
Corinna Vinschen fa4fcf7373 cygwin: Do not generate surrogate chars on netapp
Just like Samba, Netapp FSes seem to dislike invalid surrogate usage in
filenames.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-24 20:52:25 +01:00
Corinna Vinschen 0accc5332a Document cygserver changes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-24 18:13:08 +01:00
Corinna Vinschen 663b4ab824 cygserver: Speed up non-debug scenario
_log/_vlog were always called so we always had a function call hit even
if we're not debugging.  Expand on the debugging macros so the decision
to call _log/_vlog is done in the caller already.  Also, make a log level
difference between syscall_printf and system_printf.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-24 17:55:36 +01:00
Corinna Vinschen 4dbcfeb7d0 cygserver: Small code cleanup
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-24 17:53:40 +01:00
Corinna Vinschen b80b2c0119 cygserver: Revamp thread sleep handling
The current implementation is a very simple approach to implement
a statically sized sleep queue.  The problem is that this code requires
a certain amount of synchronization because the slots in the queue are
used dynamically.  To top it off, the Event objects used for sync'ing
are created and destroyed on demand.  This is complicated, slow, and
error prone.

There's also a blatant bug here: The number of slots in the queue was
wrongly computed in size.  It was too small if XSI IPC was used a lot.

Make the code more robust.  Let the queue have the right size.  Every
slot is now used for a specific IPC object.  All sync objects (switched
to Semaphores) are only created when first required, but never destroyed.
This reduces the usage of a critical section to the creation of a new
sync object.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-24 17:53:34 +01:00
Corinna Vinschen 0b73dba4de cygserver: raise number of worker threads on demand
The number of threads in the worker pool is fixed so far.  This is a
problem in XSI IPC scenarions with an unknown number of consumers.
It doesn't make sense to make the pool very big for a start, but when
the need arises, we need to make sure we can serve the request even if
all other worker threads are in a wait state.

This patch changes threaded_queue to just add another worker thread
if all current workers are busy.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-24 16:18:26 +01:00
Corinna Vinschen 838eaf6674 cygserver: Only print basename of source in debug output to raise readability
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-24 16:12:52 +01:00
Corinna Vinschen 8d6a522877 cygserver: Seralize debug output to stdout to raise readability
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-24 16:12:00 +01:00
Corinna Vinschen 8259db586a dlfcn: Remove stray debug output
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-22 11:10:15 +01:00
Yaakov Selkowitz 90e35b1eb3 Rename <sys/_locale.h> to <xlocale.h>
The locale_t type is provided by <xlocale.h> on Linux, FreeBSD, and Darwin.
While, like on some of those systems, it is automatically included by
<locale.h> with the proper feature test macros, its presence under this
particular name is still presumed in real-world software.

Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
2017-03-22 10:03:45 +01:00
Sebastian Huber ffbfb332d6 ARM: Fix IEEE-754 sqrt implementation
Older GCC (e.g. 4.9.3) seem to define __ARM_FP even in case soft-float
is used.
2017-03-22 10:01:50 +01:00
Sebastian Huber baf32fb85f ARM: Optimize IEEE-754 sqrt implementation
Use the vsqrt.f64 and vsqrt.f32 instructions if available.
2017-03-21 14:42:26 +01:00
Corinna Vinschen 33297d810d Cygwin: dlfcn: Fix reference counting
The original dll_init code was living under the wrong assumption that
dll_dllcrt0_1 and in turn dll_list::alloc will be called for each
LoadLibrary call.  The same wrong assumption was made for
cygwin_detach_dll/dll_list::detach called via FreeLibrary.

In reality, dll_dllcrt0_1 gets only called once at first LoadLibrary
and cygwin_detach_dll once at last FreeLibrary.

In effect, reference counting for DLLs was completely broken after fork:

  parent:
    l1 = dlopen ("lib1");  // LoadLibrary, LoadCount = 1
    l2 = dlopen ("lib1");  // LoadLibrary, LoadCount = 2

    fork ();               // LoadLibrary in the child, LoadCount = 1!
      child:
        dlclose (l1);      // FreeLibrary actually frees the lib
        x = dlsym (l2);    // SEGV

* Move reference counting to dlopen/dlclose since only those functions
  have to keep track of loading/unloading DLLs in the application context.

* Remove broken accounting code from dll_list::alloc and dll_list::detach.

* Fix error handling in dlclose.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-21 14:31:03 +01:00
Joel Sherrill 33c7b2b544 libc/string/strsignal.c: Use of || not && lead to dead code.
Coverity Id: 175333
2017-03-15 12:04:34 -05:00
Joel Sherrill 6e3a2037eb rtems/crt0.c: getentropy() stub did not return a value.
Coverity Scan ID: 175342
2017-03-15 12:04:28 -05:00
Corinna Vinschen 778f4397f3 Add release message for commit 973f766f6
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-14 16:54:57 +01:00
Corinna Vinschen 73d3f9cf20 Revert "Add release message for commit 973f766f6"
This reverts commit 125852d77b.

Accidentally commited too much.
2017-03-14 16:52:20 +01:00
Corinna Vinschen 125852d77b Add release message for commit 973f766f6
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-14 09:24:48 +01:00
Koichi Murase 973f766f6e Fix duplocale (libc/locale/duplocale.c) which fails to properly call __loadlocale
Problem:

  After  passing  locales  created  by  'duplocale'   to   'uselocale',
  referencing   'MB_CUR_MAX',   which   is   actually   expanded    to
  '__locale_mb_cur_max()' by preprocessors, causes segmentation faults.
  Direct use of locales from 'newlocale' does not  cause  the  problem.
  This is the problem of 'duplocale'.

  $ echo $LANG
  ja_JP.UTF-8
  $ cat test.c
  #include <stdlib.h>
  #include <locale.h>

  volatile int var;

  int main(void) {
    locale_t const loc = newlocale(LC_ALL_MASK, "", NULL);
    locale_t const dup = duplocale(loc);
    locale_t const old = uselocale(dup);
    var = MB_CUR_MAX; /* <-- crashes here */
    uselocale(old);
    freelocale(dup);
    freelocale(loc);
    return 0;
  }
  $ gcc test.c
  $ ./a
  Segmentation fault (core dumped)

  # Note: "core dumped" in the above message was  actually written  in
  # Japanese, but I translated the part to post a mail in English.

Bug:

  In the beginning of '__loadlocale' (newlib/libc/locale/locale.c:501),
  there is a code which checks if the operations can be skipped:

  > /* Avoid doing everything twice if nothing has changed. */
  > if (!strcmp (new_locale, loc->categories[category]))
  >   return loc->categories[category];

  While,   in   the   function   '_duplocale_r'    (newlib/libc/locale/
  duplocale.c), '__loadlocale'  is  called  as  in  the  quoted  codes:

  > /* If the object is not a "C" locale category, copy it.  Just call
  >    __loadlocale.  It knows what to do to replicate the category. */
  > tmp_locale.lc_cat[i].ptr = NULL;
  > tmp_locale.lc_cat[i].buf = NULL;
  > if (!__loadlocale (&tmp_locale, i, tmp_locale.categories[i]))
  >   goto error;

  This call of '__loadlocale' results in the skip check being

    !strcmp(tmp_locale.categories[i], tmp_locale.categories[i]),

  which is always true. This  means  that  the  actual  operations  of
  '__loadLocale' will never be performed for 'duplocale'.

Fix:

  The call of '__loadlocale' in '_duplocale_r' is modified.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-13 11:12:01 +01:00
Corinna Vinschen 02011278e0 Extend 2.8.0 release text
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-12 12:21:40 +01:00
Corinna Vinschen dd757cc43a Implement fhandler_dev_null::write to workaround a problem with NUL
Windows NUL device returns only the lower 32 bit of the number of
bytes written.  Implement a fake write function to ignore the underlying
NUL device.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-12 12:17:43 +01:00
Corinna Vinschen a3f297d3c2 Return value from write is ssize_t, not int
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-12 12:16:23 +01:00
Yaakov Selkowitz 6c420fa494 getrandom: it's MIN, not MAX
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-11 10:03:29 +01:00
Corinna Vinschen c9e4b69e9f Belatedly bump Cygwin DLL version to 2.8.0
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-10 20:50:35 +01:00
Corinna Vinschen 45d0d75910 Drop now unused child_info_fork::from_main
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-10 20:45:19 +01:00
Corinna Vinschen 48755fb9bc fork: Don't copy _main_tls->local_clib from *_impure_ptr
So far we copy *_impure_ptr into _main_tls->local_clib if the child
process has been forked from a pthread.  But that's not required.
The local_clib area of the new thread is on the stack and the stack
gets copied from the parent anyway (in frok::parent).  So we only
have to make sure _main_tls is pointing to the right address and
do the simple post-fork thread init.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-10 20:44:53 +01:00
Corinna Vinschen 35d344babe _dll_crt0: Drop incorrect check for being started from parent main thread
This test was broken from the start.  It leads to creating a completely
new stack for the main thread of the child process when started from
the main thread of the parent.  However, the main thread of a process
can easily running on a completely different stack, if the parent's main
thread was created by calling fork() from a pthread.  For an example,
see https://cygwin.com/ml/cygwin/2017-03/msg00113.html

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-10 20:28:09 +01:00
Corinna Vinschen 44b1746a41 errno: Stop using _impure_ptr->_errno completely
We use errno AKA _REENT->_errno since the last century and only set
_impure_ptr->_errno for backward compat.  Stop that.  Also, remove
the last check for _impure_ptr->_errno in Cygwin code.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-10 20:21:09 +01:00
Corinna Vinschen f2e6553c25 Drop redundant brackets in call to _reclaim_reent
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-10 20:16:48 +01:00
Jon Turney c8432a01c8 Implement dladdr() (partially)
Note that this always returns with dli_sname and dli_saddr set to NULL,
indicating no symbol matching addr could be found.

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2017-03-08 17:49:08 +00:00
Corinna Vinschen 51a993c266 yield: Don't lower thread priority, it leads to starvation
...and it's not required anymore to have the same effect as the original
code post-XP.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-08 17:44:15 +01:00
Corinna Vinschen 994a4b7dcc Cygwin: Emit correct errno EAGAIN if we can't create another thread
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-08 17:43:23 +01:00
Jon Turney b9498f17f9 Export timingsafe_bcmp and timingsafe_memcmp
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2017-03-07 18:40:35 +00:00
Corinna Vinschen eed33fa2c4 Document pthread_cond_wait change in release notes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-07 15:18:03 +01:00
Corinna Vinschen 49505a907f Cygwin: pthread_cond_wait: Do as Linux and BSD do.
POSIX states as follows about pthread_cond_wait:
If a signal is delivered to a thread waiting for a condition variable,
upon return from the signal handler the thread resumes waiting for the
condition variable as if it was not interrupted, or it returns zero
due to spurious wakeup.

Cygwin so far employs the latter behaviour, while Linux and BSD employ
the former one.

Align Cygwin behaviour to Linux and BSD.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-07 15:15:47 +01:00
Corinna Vinschen 88443b0a22 cwdstuff: Don't leave from setting the CWD prematurely on init
There are certain, very obscure scenarios, which render the Windows
CWD handle inaccessible for reopening.  An easy one is, the handle can
be NULL if the permissions of the CWD changed under the parent processes
feet.

Originally we just set errno and returned, but in case of init at
process startup that left the "posix" member NULL and subsequent
calls to getcwd failed with EFAULT.

We now check for a NULL handle and change the reopen approach
accordingly.  If that doesn't work, try to duplicate the handle instead.
If duplicating fails, too, we set the dir handle to NULL and carry on.
This will at least set posix to some valid path and subsequent getcwd
calls won't fail.  A NULL dir handle is ok, because we already do this
for virtual paths.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-03-03 13:55:55 +01:00
David Allsopp 226f69422a Preserve order of dlopen'd modules in dll_list::topsort
This patch alters the behaviour of dll_list::topsort to preserve the
order of dlopen'd units.

The load order of unrelated DLLs is reversed every time fork is called,
since dll_list::topsort finds the tail of the list and then unwinds to
reinsert items. My change takes advantage of what should be undefined
behaviour in dll_list::populate_deps (ndeps non-zero and ndeps and deps
not initialised) to allow the deps field to be initialised prior to the
call and appended to, rather than overwritten.

All DLLs which have been dlopen'd have their deps list initialised with
the list of all previously dlopen'd units. These extra dependencies mean
that the unwind preserves the order of dlopen'd units.

The motivation for this is the FlexDLL linker used in OCaml. The FlexDLL
linker allows a dlopen'd unit to refer to symbols in previously dlopen'd
units and it resolves these symbols in DllMain before anything else has
initialised (including the Cygwin DLL). This means that dependencies may
exist between dlopen'd units (which the OCaml runtime system
understands) but which Windows is unaware of. During fork, the
process-level table which FlexDLL uses to get the symbol table of each
DLL is copied over but because the load order of dlopen'd DLLs is
reversed, it is possible for FlexDLL to attempt to access memory in the
DLL before it has been loaded and hence it fails with an access
violation. Because the list is reversed on each call to fork, it means
that a subsequent call to fork puts the DLLs back into the correct
order, hence "even" invocations of fork work!

An interesting side-effect is that this only occurs if the DLLs load at
their preferred base address - if they have to be rebased, then FlexDLL
works because at the time that the dependent unit is loaded out of
order, there is still in memory the "dummy" DONT_RESOLVE_DLL_REFERENCES
version of the dependency which, as it happens, will contain the correct
symbol table in the data section. For my tests, this initially appeared
to be an x86-only problem, but that was only because the two DLLs on x64
should have been rebased.

Signed-off-by: David Allsopp <david.allsopp@metastack.com>
2017-02-28 16:12:03 +01:00
Corinna Vinschen 45d3296d0d Add 2.7.1 release file
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-02-24 20:57:02 +01:00
Corinna Vinschen f5ecacfc6c Generate output with Unix line endings even from Mingw64 utils
This affects cygcheck and strace.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-02-24 20:55:14 +01:00
Corinna Vinschen fa9d3148bf Bump Cygwin version to 2.7.1
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2017-02-24 20:51:50 +01:00