Commit Graph

1254 Commits

Author SHA1 Message Date
Florian Weimer
6b89c385d8 io: Implement lchmod using fchmodat [BZ #14578] 2020-02-12 08:43:59 +01:00
Samuel Thibault
fba7fc5a21 htl C11 threads: Avoid pthread_ symbols visibility in static library 2020-02-10 23:45:23 +00:00
Samuel Thibault
8ba6ad703c hurd: Add __pthread_spin_wait and use it
900778283a ("htl: make pthread_spin_lock really spin") made
pthread_spin_lock really spin and not block, but the current users of
__pthread_spin_lock were assuming that it blocks, i.e. they use it as a
lightweight mutex fitting in just one int.

__pthread_spin_wait provides that support back.
2020-02-11 00:32:44 +01:00
Samuel Thibault
6acd77229a pthread: Move most barrier tests from nptl to sysdeps/pthread
So they can be checked with htl too.
2020-02-10 01:03:55 +00:00
Samuel Thibault
8a195ec810 pthread: Move most sem tests from nptl to sysdeps/pthread
So they can be checked with htl too.
2020-02-10 01:03:54 +00:00
Samuel Thibault
e9644c20ce htl: Make sem_wait/sem_timedwait interruptible 2020-02-10 01:03:54 +00:00
Samuel Thibault
5e77ec7c6e htl: Add support for semaphore maximum value 2020-02-10 01:03:54 +00:00
Samuel Thibault
7e7182256a hurd: Make nanosleep a cancellation point 2020-02-10 01:03:53 +00:00
Samuel Thibault
59b7fe99f2 htl: Add support for libc cancellation points 2020-02-10 01:03:50 +00:00
Samuel Thibault
782ee4e256 htl: XFAIL rwlock tests which need pshared support 2020-02-09 22:29:28 +00:00
Samuel Thibault
d8f1f2d9ab pthread: Move most cond tests from nptl to sysdeps/pthread
So they can be checked with htl too.
2020-02-09 19:24:44 +00:00
Samuel Thibault
cd94860c56 htl: Report missing mutex lock on pthread_cond_*wait 2020-02-09 18:33:14 +00:00
Samuel Thibault
34f168fb82 htl: Fix default guard size
When it is not hardcoded by the architecture with PAGESIZE, we need to
use the dynamic values from __vm_page_size.
2020-02-09 17:28:33 +00:00
Samuel Thibault
74159dc58a pthread: Move most mutex tests from nptl to sysdeps/pthread
So they can be checked with htl too.

XFAIL tst-mutex4, for which support is still missing in htl.
2020-02-09 17:17:06 +00:00
Samuel Thibault
900778283a htl: make pthread_spin_lock really spin
__spin_lock would actually use gsync_wait to block, which is not what
pthread_spin_lock is about.
2020-02-09 16:54:58 +00:00
Samuel Thibault
19a64d9f6e htl: Fix calling pthread_exit in the child of a fork
We need to reset the threads counter, otherwise pthread_exit() would not
call exit(0).
2020-02-09 17:01:06 +01:00
Samuel Thibault
b05de10400 C11 threads: Move implementation to sysdeps/pthread
so it gets shared by nptl and htl. Also add htl versions of thrd_current and
thrd_yield.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-02-09 13:56:48 +01:00
Samuel Thibault
e775f443bd htl: Rename _pthread_mutex_init/destroy to __pthread_mutex_init/destroy 2020-02-09 13:56:45 +01:00
Samuel Thibault
0093df204a htl: Move internal mutex/rwlock symbols to GLIBC_PRIVATE
Their prototypes have never been made public, and they are not used outside
libc (checked on the whole Debian archive)
2020-02-09 13:06:35 +01:00
Samuel Thibault
cc79354ecc htl: Remove duplicate files
The generic versions have the same content.
2020-02-09 01:27:53 +01:00
Samuel Thibault
a99155555c htl: Remove unused files
These have never been used.
2020-02-09 01:27:38 +01:00
Lukasz Majewski
3fced064f2 y2038: Define __suseconds64_t type to be used with struct __timeval64
The __suseconds64_t type is supposed to be the 64 bit type across all
architectures.

It would be mostly used internally in the glibc - however, when passed to
Linux kernel (very unlikely), if necessary, it shall be converted to 32
bit type (i.e. __suseconds_t)

Build tests:
./src/scripts/build-many-glibcs.py glibcs

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-02-07 17:55:07 +01:00
Samuel Thibault
a8f0fc4e5f htl: Add internal version of __pthread_mutex_timedlock
The C11 threads implementation will need it.
2020-01-13 20:41:07 +01:00
Samuel Thibault
ae793cc20d htl: Avoid exposing unixoid functions
C11 threads should not expose them.
2020-01-13 01:38:33 +01:00
Samuel Thibault
196e62cbe4 htl: Add type sizes in bits/pthreadtypes-arch.h and check them 2020-01-13 01:24:43 +01:00
Samuel Thibault
cbce69e70d hurd: Fix message reception for timer_thread
Without a proper size, we get MACH_RCV_TOO_LARGE instead of MACH_MSG_SUCCESS.

* sysdeps/mach/hurd/setitimer.c (timer_thread): Add return_code_type
field to received message, and set the receive size in __mach_msg call.
2020-01-05 18:09:13 +01:00
Samuel Thibault
25c084e0a7 htl: Add __errno_location and __h_errno_location
As explained on
https://sourceware.org/ml/libc-alpha/2020-01/msg00049.html
the presence of __errno_location in libpthread.so on GNU/Linux makes
libpthread getting linked in for libstdc++. This aligns on that behavior, to
avoid issues that only GNU/Hurd would get.
2020-01-04 19:37:53 +01:00
Joseph Myers
d614a75396 Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
Jeremie Koenig
653d74f12a hurd: Global signal disposition
This adds _hurd_sigstate_set_global_rcv used by libpthread to enable
POSIX-confirming behavior of signals on a per-thread basis.

This also provides a sigstate destructor _hurd_sigstate_delete, and a
global process signal state, which needs to be locked and check when
global disposition is enabled, thus the addition of _hurd_sigstate_lock
_hurd_sigstate_actions _hurd_sigstate_pending _hurd_sigstate_unlock helpers.

This also updates all the glibc code accordingly.

This also drops support for get_int(INIT_SIGMASK), which did not make sense
any more since we do not have a single signal thread any more.

During fork/spawn, this also reinitializes the child global sigstate's
lock. That cures an issue that would very rarely cause a deadlock in the
child in fork, tries to unlock ss' critical section lock at the end of
fork.  This will typically (always?) be observed in /bin/sh, which is not
surprising as that is the foremost caller of fork.

To reproduce an intermediate state, add an endless loop if
_hurd_global_sigstate is locked after __proc_dostop (cast through
volatile); that is, while still being in the fork's parent process.

When that triggers (use the libtool testsuite), the signal thread has
already locked ss (which is _hurd_global_sigstate), and is stuck at
hurdsig.c:685 in post_signal, trying to lock _hurd_siglock (which the
main thread already has locked and keeps locked until after
__task_create).  This is the case that ss->thread == MACH_PORT_NULL, that
is, a global signal.  In the main thread, between __proc_dostop and
__task_create is the __thread_abort call on the signal thread which would
abort any current kernel operation (but leave ss locked).  Later in fork,
in the parent, when _hurd_siglock is unlocked in fork, the parent's
signal thread can proceed and will unlock eventually the global sigstate.
In the client, _hurd_siglock will likewise be unlocked, but the global
sigstate never will be, as the client's signal thread has been configured
to restart execution from _hurd_msgport_receive.  Thus, when the child
tries to unlock ss' critical section lock at the end of fork, it will
first lock the global sigstate, will spin trying to lock it, which can
never be successful, and we get our deadlock.

Options seem to be:

  * Move the locking of _hurd_siglock earlier in post_signal -- but that
    may generally impact performance, if this locking isn't generally
    needed anyway?

    On the other hand, would it actually make sense to wait here until we
    are not any longer in a critical section (which is meant to disable
    signal delivery anyway (but not for preempted signals?))?

  * Clear the global sigstate in the fork's child with the rationale that
    we're anyway restarting the signal thread from a clean state.  This
    has now been implemented.

Why has this problem not been observed before Jérémie's patches?  (Or has
it?  Perhaps even more rarely?)  In _S_msg_sig_post, the signal is now
posted to a *global receiver thread*, whereas previously it was posted to
the *designated signal-receiving thread*.  The latter one was in a
critical section in fork, so didn't try to handle the signal until after
leaving the critical section?  (Not completely analyzed and verified.)

Another question is what the signal is that is being received
during/around the time __proc_dostop executes.
2019-12-29 18:32:49 +01:00
Samuel Thibault
eb87a46c56 hurd sendmsg: Fix warning on calling CMSG_*HDR 2019-12-29 17:49:41 +01:00
Thomas Schwinge
a678c13b8f hurd: Add getcontext, makecontext, setcontext, swapcontext
Adapted from the Linux x86 functions.

Not thoroughly tested, but manual testing as well as glibc tests look fine, and
manual -lpthread testing also looks fine (within the given bounds for a new
stack to be used with makecontext).

This has also been in use in Debian since 2013.
2019-12-29 16:54:08 +01:00
Emilio Pozuelo Monfort
344e755248 hurd: Support sending file descriptors over Unix sockets 2019-12-29 16:34:20 +01:00
Adhemerval Zanella
848791557b Implement waitpid in terms of wait4
This also consolidate all waitpid implementations.

Checked on x86_64-linux-gnu.
2019-12-19 16:11:09 -03:00
Florian Weimer
3dcad8158f hurd: Do not make sigprocmask available in ld.so
After commit f7649d5780 ("dlopen: Do not
block signals"), the dynamic linker no longer uses sigprocmask, which
means that it does not have to be made available explicitly on hurd.

This reverts commit 892badc9bb
("hurd: Make __sigprocmask GLIBC_PRIVATE") and commit
d5ed9ba29a ("hurd: Fix ld.so link"),
but keeps the comment changes from the second commit.
2019-12-18 10:53:17 +01:00
James Clarke
a45244ce12 hurd: Make getrandom honour GRND_NONBLOCK
* sysdeps/mach/hurd/getrandom.c (__getrandom): Open the random source
with O_NONBLOCK when the GRND_NONBLOCK flag is provided.
Message-Id: <20191217182929.90989-1-jrtc27@jrtc27.com>
2019-12-17 20:38:01 +01:00
Samuel Thibault
8eaf34eda2 hurd: Fix local PLT
* include/sys/random.h (__getrandom): Add hidden prototype.
* stdlib/getrandom.c (getrandom): Rename to hidden definition __getrandom.
Add weak alias.
* sysdeps/mach/hurd/getrandom.c (getrandom): Likewise.
* sysdeps/unix/sysv/linux/getrandom.c (getrandom): Likewise.
* sysdeps/mach/hurd/getentropy.c (getentropy): Use __getrandom instead of
getrandom.
2019-12-13 11:11:54 +01:00
Samuel Thibault
186e119bbd hurd: Fix __close_nocancel_nostatus availability
Not only libc/rtld use __close_nocancel_nostatus.

* sysdeps/mach/hurd/Makefile [$(subdir) == io] (sysdep_routines): Add
close_nocancel_nostatus.
* sysdeps/mach/hurd/Versions (libc): Add __close_nocancel_nostatus to
GLIBC_PRIVATE.
* sysdeps/mach/hurd/not-cancel.h (__close_nocancel_nostatus): Declare
function instead of defining inline.
[IS_IN (libc) || IS_IN (rtld)] (__close_nocancel_nostatus): Make
function hidden.
* sysdeps/mach/hurd/close_nocancel_nostatus.c: New file.
2019-12-13 03:39:28 +01:00
Andrew Eggenberger
fe75ee0ca6 hurd: add getrandom and getentropy implementations
* sysdeps/mach/hurd/getentropy.c: New file.
* sysdeps/mach/hurd/getrandom.c: Likewise.
2019-12-13 03:24:31 +01:00
Samuel Thibault
c1f25758c3 hurd: Implement __close_nocancel_nostatus
* sysdeps/mach/hurd/not-cancel.h: New file.
2019-12-13 03:24:31 +01:00
Samuel Thibault
e46efff895 hurd: Fix using altstack while in an RPC call to be aborted
* sysdeps/mach/hurd/i386/trampoline.c (_hurd_setup_sighandler): Always check
for interrupted code being with esp pointing at mach_msg arguments, even
when using an altstack. If we need to abort the RPC we will need
this.
2019-12-11 00:33:36 +01:00
Samuel Thibault
dd67928700 hurd: Fix ld.so __access override from libc
ld.so symbols to be overriden by libc need to be extern to really get
overriden. __access happens to have never been exposed, putting it to
GLIBC_PRIVATE.
2019-12-01 21:05:56 +00:00
Samuel Thibault
db25266c92 hurd: Fix ld.so __getcwd override from libc
ld.so symbols to be overriden by libc need to be extern to really get
overriden. __getcwd happens to have never been exposed, putting it to
GLIBC_PRIVATE.
2019-12-01 21:05:51 +00:00
Samuel Thibault
892badc9bb hurd: Make __sigprocmask GLIBC_PRIVATE
We do not need to expose it.
2019-12-01 19:20:51 +00:00
Samuel Thibault
d51ca7d6ad hurd: Fix renameat2 error
renameat2 has to exclude RENAME_EXCHANGE | RENAME_NOREPLACE with EINVAL,
as tested by stdio-common/tst-renameat2.
2019-12-01 16:46:59 +00:00
Samuel Thibault
d5ed9ba29a hurd: Fix ld.so link
Since a2e8aa0d9e ("Block signals during the initial part of dlopen") dl_open
uses sigprocmask, so we need a stub implementation.
2019-12-01 16:17:22 +00:00
Florian Weimer
84df7a4637 hurd: Suppress GCC 10 -Warray-bounds warning in init-first.c [BZ #25097]
The trampoline code should really be rewritten in assembler because
this is all very undefined at the C level.

Change-Id: Ided58244ca0ee48892519faac5ac222a4e02dec4
2019-11-16 15:40:59 +01:00
Florian Weimer
50471a8613 hurd: Remove lingering references to the time function
They cause a check-localplt failure after commit f9a7554009.

Fixes: f9a7554009
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Change-Id: I37bc20f3449b9e358f32879ed231720c969965b4
2019-11-07 09:54:33 +01:00
Adhemerval Zanella
3537ecb49c Refactor nanosleep in terms of clock_nanosleep
The generic version is straightforward.  For Hurd, its nanosleep
implementation is moved to clock_nanosleep with adjustments from
generic unix implementation.

The generic clock_nanosleep unix version is also removed since
it calls nanosleep.

Checked on x86_64-linux-gnu and powerpc64le-linux-gnu.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2019-11-06 14:47:02 -03:00
Adhemerval Zanella
5e46749c64 Use clock_gettime to implement gettimeofday.
Consolidate generic gettimeofday implementation to use clock_gettime.
Linux ports that still provide gettimeofday through vDSO are not
changed.

Remove sysdeps/unix/clock_gettime.c, which implemented clock_gettime
using gettimeofday; new OS ports must provide a real implementation of
clock_gettime.

Rename sysdeps/mach/gettimeofday.c to sysdeps/mach/clock_gettime.c and
convert into an implementation of clock_gettime.  It only supports
CLOCK_REALTIME; Mach does not appear to have any support for monotonic
clocks.  It uses __host_get_time, which provides at best microsecond
resolution.  Hurd is currently using sysdeps/posix/clock_getres.c for
clock_getres; its output for CLOCK_REALTIME is based on
sysconf (_SC_CLK_TCK), and I do not know whether that gives the
correct result.

Unlike settimeofday, there are no known uses of gettimeofday's
vestigial "get time zone" feature that are not bugs.  (The per-process
timezone support in localtime and friends is unrelated, and the
programs that set the kernel's offset between the hardware clock and
UTC do not need to read it back.)  Therefore, this feature is dummied
out.  Henceforth, if gettimeofday's "struct timezone" argument is not
NULL, it will write zeroes to both fields.  Any program that is
actually looking at this data will thus think it is running in UTC,
which is probably more correct than whatever it was doing before.

[__]gettimeofday no longer has any internal callers, so we can now
remove its internal prototype and PLT bypass aliases.  The
__gettimeofday@GLIBC_2.0 export remains, in case it is used by any
third-party code.

It also allows to simplify the arch-specific implementation on x86 and
powerpc to remove the hack to disable the internal route to non iFUNC
variant for internal symbol.

This patch also fixes a missing optimization on aarch64, powerpc, and
x86 where the code used on static build do not use the vDSO.

Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
powerpc64-linux-gnu, powerpc-linux-gnu, and aarch64-linux-gnu.

Co-authored-by: Zack Weinberg <zackw@panix.com>
Reviewed-by: Lukasz Majewski <lukma@denx.de>
2019-10-30 17:11:10 -03:00
Zack Weinberg
c3f9aef063 Use clock_settime to implement settimeofday.
Unconditionally, on all ports, use clock_settime to implement
settimeofday.  Remove sysdeps/unix/clock_settime.c, which implemented
clock_settime by calling settimeofday; new OS ports must henceforth
provide a real implementation of clock_settime.

Hurd had a real implementation of settimeofday but not of
clock_settime; this patch converts it into an implementation of
clock_settime.  It only supports CLOCK_REALTIME and microsecond
resolution; Hurd/Mach does not appear to have any support for
finer-resolution clocks.

The vestigial "set time zone" feature of settimeofday complicates the
generic settimeofday implementation a little.  The only remaining uses
of this feature that aren't just bugs, are using it to inform the
Linux kernel of the offset between the hardware clock and UTC, on
systems where the hardware clock doesn't run in UTC (usually because
of dual-booting with Windows).  There currently isn't any other way to
do this.  However, the callers that do this call settimeofday with
_only_ the timezone argument non-NULL.  Therefore, glibc's new
behavior is: callers of settimeofday must supply one and only one of
the two arguments.  If both arguments are non-NULL, or both arguments
are NULL, the call fails and sets errno to EINVAL.

When only the timeval argument is supplied, settimeofday calls
__clock_settime(CLOCK_REALTIME), same as stime.

When only the timezone argument is supplied, settimeofday calls a new
internal function called __settimezone.  On Linux, only, this function
will pass the timezone structure to the settimeofday system call.  On
all other operating systems, and on Linux architectures that don't
define __NR_settimeofday, __settimezone is a stub that always sets
errno to ENOSYS and returns -1.

The settimeoday syscall is enabled on Linux by the flag
COMPAT_32BIT_TIME, which is an option to either 32-bits ABIs or COMPAT
builds (defined usually by 64-bit kernels that want to support 32-bit
 ABIs, such as x86).  The idea to future 64-bit time_t only ABIs
is to not provide settimeofday syscall.

The same semantics are implemented for Linux/Alpha's GLIBC_2.0 compat
symbol for settimeofday.

There are no longer any internal callers of __settimeofday, so the
internal prototype is removed.

Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
powerpc64-linux-gnu, powerpc-linux-gnu, and aarch64-linux-gnu.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Lukasz Majewski <lukma@denx.de>
2019-10-30 17:05:14 -03:00