about summary refs log tree commit diff
path: root/nptl
Commit message (Collapse)AuthorAgeFilesLines
* nptl: Fix __futex_clocklock64 return error check [BZ #26964]Lucas A. M. Magalhaes2020-12-012-1/+139
| | | | | | | | | | | | | | | | | The earlier implementation of this, __lll_clocklock, calls lll_clockwait that doesn't return the futex syscall error codes. It always tries again if that fails. However in the current implementation, when the futex returns EAGAIN, __futex_clocklock64 will also return EGAIN, even if the futex is taken. This patch fixes the EAGAIN issue and also adds a check for EINTR. As futex syscall can return EINTR if the thread is interrupted by a signal. In this case I'm assuming the function should continue trying to lock as there is no mention to about it on POSIX. Also add a test for both scenarios. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* y2038: Convert aio_suspend to support 64 bit timeLukasz Majewski2020-11-301-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The aio_suspend function has been converted to support 64 bit time. This change uses (in aio_misc.h): - __futex_abstimed_wait64 (instead of futex_reltimed_wait) - __futex_abstimed_wait_cancellable64 (instead of futex_reltimed_wait_cancellable) from ./sysdeps/nptl/futex-helpers.h The aio_suspend() accepts relative timeout, which then is converted to absolute one. The i686-gnu port (HURD) do not define DONT_NEED_AIO_MISC_COND and as it doesn't (yet) support 64 bit time it uses not converted pthread_cond_timedwait(). The __aio_suspend() is supposed to be run on ports with __TIMESIZE !=64 and __WORDSIZE==32. It internally utilizes __aio_suspend_time64() and hence the conversion from 32 bit struct timespec to 64 bit one is required. For ports supporting 64 bit time the __aio_suspend_time64() will be used either via alias (to __aio_suspend when __TIMESIZE==64) or redirection (when -D_TIME_BITS=64 is passed). 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>
* nptl: Add EOVERFLOW checks for futex callsAdhemerval Zanella2020-11-274-13/+13
| | | | | | | | | | | | | | | | | | | | | Some futex-internal calls require additional check for EOVERFLOW (as indicated by [1] [2] [3]). For both mutex and rwlock code, EOVERFLOW is handle as ETIMEDOUT; since it indicate to the caller that the blocking operation could not be issued. For mutex it avoids a possible issue where PTHREAD_MUTEX_ROBUST_* might assume EOVERFLOW indicate futex has succeed, and for PTHREAD_MUTEX_PP_* it avoid a potential busy infinite loop. For rwlock and semaphores, it also avoids potential busy infinite loops. Checked on x86_64-linux-gnu and i686-linux-gnu, although EOVERFLOW won't be possible with current usage (since all timeouts on 32-bit architectures with 32-bit time_t support will be in the range of 32-bit time_t). [1] https://sourceware.org/pipermail/libc-alpha/2020-November/120079.html [2] https://sourceware.org/pipermail/libc-alpha/2020-November/120080.html [3] https://sourceware.org/pipermail/libc-alpha/2020-November/120127.html
* nptl: Fix PTHREAD_PRIO_PROTECT timed lockAdhemerval Zanella2020-11-274-25/+11
| | | | | | | | | | | | | | | | | The 878fe624d4 changed lll_futex_timed_wait, which expects a relative timeout, with a __futex_abstimed_wait64, which expects an absolute timeout. However the code still passes a relative timeout. Also, the PTHREAD_PRIO_PROTECT support for clocks different than CLOCK_REALTIME was broken since the inclusion of pthread_mutex_clocklock (9d20e22e46) since lll_futex_timed_wait always use CLOCK_REALTIME. This patch fixes by removing the relative time calculation. It also adds some xtests that tests both thread and inter-process usage. Checked on x86_64-linux-gnu.
* nptl: Return EINVAL for invalid clock for pthread_clockjoin_npAdhemerval Zanella2020-11-251-0/+4
| | | | | | | | | The align the GNU extension with the others one that accept specify which clock to wait for (such as pthread_mutex_clocklock). Check on x86_64-linux-gnu. Reviewed-by: Lukasz Majewski <lukma@denx.de>
* nptl: Return EINVAL for pthread_mutex_clocklock/PI with CLOCK_MONOTONIC [BZ ↵Adhemerval Zanella2020-11-253-1/+76
| | | | | | | | | | | | | | | | #26801] Linux futex FUTEX_LOCK_PI operation only supports CLOCK_REALTIME, so pthread_mutex_clocklock operation with priority aware mutexes may fail depending of the input timeout. Also, it is not possible to convert a CLOCK_MONOTONIC to a CLOCK_REALTIME due the possible wall clock time change which might invalid the requested timeout. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski <lukma@denx.de>
* nptl: Replace lll_futex_wake with futex-internal.hAdhemerval Zanella2020-11-253-12/+7
| | | | | | | | | The idea is to make NPTL implementation to use on the functions provided by futex-internal.h. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski <lukma@denx.de>
* nptl: Replace lll_futex_supported_clockid with futex-internal.hAdhemerval Zanella2020-11-251-1/+1
| | | | | | | | | The idea is to make NPTL implementation to use on the functions provided by futex-internal.h. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski <lukma@denx.de>
* nptl: Replace lll_futex_{timed_}wait by futex-internal.hAdhemerval Zanella2020-11-254-12/+14
| | | | | | | | | The idea is to make NPTL implementation to use on the functions provided by futex-internal.h. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski <lukma@denx.de>
* nptl: Replace lll_timedwait with __futex_abstimed_wait64Adhemerval Zanella2020-11-253-65/+2
| | | | | | Checked with x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski <lukma@denx.de>
* nptl: Replace __futex_clocklock_wait64 with __futex_abstimed_wait64Adhemerval Zanella2020-11-251-2/+2
| | | | | | | | | | | | | | | | | For non null timeouts, the __futex_clocklock_wait64 creates an a relative timeout by subtracting the current time from the input argument. The same behavior can be obtained with FUTEX_WAIT_BITSET without the need to calculate the relative timeout. Besides consolidate the code it also avoid the possible relative timeout issues [1]. The __futex_abstimed_wait64 needs also to return EINVAL syscall errors. Checked on x86_64-linux-gnu and i686-linux-gnu. [1] https://sourceware.org/pipermail/libc-alpha/2020-November/119881.html Reviewed-by: Lukasz Majewski <lukma@denx.de>
* nptl: Remove _futex_clock_wait_bitset64Adhemerval Zanella2020-11-251-3/+4
| | | | | | | | It can be replaced with a __futex_abstimed_wait64 call. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski <lukma@denx.de>
* nptl: Remove clockwait_tidAdhemerval Zanella2020-11-251-58/+18
| | | | | | | | | | | It can be replaced with a __futex_abstimed_wait_cancelable64 call, with the advantage that there is no need to further clock adjustments to create a absolute timeout. It allows to remove the now ununsed futex_timed_wait_cancel64 internal function. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski <lukma@denx.de>
* nptl: Remove futex_wait_cancelableAdhemerval Zanella2020-11-251-20/+2
| | | | | | | | | It is used solely on __pthread_cond_wait_common and the call can be replaced by a __futex_abstimed_wait_cancelable64 one. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski <lukma@denx.de>
* nptl: Remove unused internal futex functionsAdhemerval Zanella2020-11-251-2/+1
| | | | | | | | | | The __futex_abstimed_wait usage was remove with 3102e28bd11 and the __futex_abstimed_wait_cancelable by 323592fdc92 and b8d3e8fbaac. The futex_lock_pi can be replaced by a futex_lock_pi64. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski <lukma@denx.de>
* Add {,sysdep-}ld-library-path make variableSamuel Thibault2020-11-161-1/+1
| | | | | | | | On GNU/Hurd we not only need $(common-objpfx) in LD_LIBRARY_PATH when loading dynamic objects, but also $(common-objpfx)/mach and $(common-objpfx)/hurd. This adds an ld-library-path variable to be used as LD_LIBRARY_PATH basis in Makefiles, and a sysdep-ld-library-path variable for sysdeps to add some more paths, here mach/ and hurd/.
* nptl: Move stack list variables into _rtld_globalFlorian Weimer2020-11-165-126/+47
| | | | | | | | | Now __thread_gscope_wait (the function behind THREAD_GSCOPE_WAIT, formerly __wait_lookup_done) can be implemented directly in ld.so, eliminating the unprotected GL (dl_wait_lookup_done) function pointer. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* nptl: Eliminate <smp.h> and __is_smpFlorian Weimer2020-11-136-43/+0
| | | | | | | | | | | Most systems are SMP, so optimizing for the UP case is no longer approriate. A dynamic check based on the kernel identification has been only implemented for i386 anyway. To disable adaptive mutexes on sh, define DEFAULT_ADAPTIVE_COUNT as zero for this architecture. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* tst-setuid1-static-ENV: Add $(common-objpfx)nss [BZ #26820]H.J. Lu2020-11-031-1/+1
| | | | | | | | | | | | | | | | | | commit def674652eeac60c386d04733318b311f8a5b620 Author: Florian Weimer <fweimer@redhat.com> Date: Mon Apr 27 15:00:14 2020 +0200 nptl/tst-setuid1-static: Improve isolation from system objects Static dlopen needs an LD_LIBRARY_PATH setting to avoid loading system libraries. missed $(common-objpfx)nss. Add $(common-objpfx)nss to LD_LIBRARY_PATH for tst-setuid1-static to support struct passwd *pwd = getpwnam ("nobody"); in nptl/tst-setuid1.c.
* Disable spurious -Wstringop-overflow for setjmp/longjmp (bug 26647)Joseph Myers2020-10-302-0/+20
| | | | | | | | | | | | | | | | | Building glibc with GCC 11 fails with (among other warnings) spurious -Wstringop-overflow warnings from calls to setjmp and longjmp with a pointer to a pthread_unwind_buf that is smaller than jmp_buf. As discussed in bug 26647, the warning in libc-start.c is a false positive, because setjmp and longjmp do not access anything (the signal mask) beyond the common prefix of the two structures, so this patch disables the warning for that call to setjmp, as well as for two calls in NPTL code that produce the same warning and look like false positives for the same reason. Tested with build-many-glibcs.py for arm-linux-gnueabi, where this allows the build to get further. Reviewed-by: DJ Delorie <dj@redhat.com>
* y2038: nptl: Provide __futex_clock_wait_bitset64 to support 64 bit bitsetLukasz Majewski2020-10-211-1/+1
| | | | | | | | | | | | | | | The commit: "y2038: nptl: Convert pthread_mutex_{clock|timed}lock to support 64 bit" SHA1: 29e9874a048f47e2d46c40253036c8d2de921548 introduced support for 64 bit timeouts. Unfortunately, it was missing the code for bitset - i.e. lll_futex_clock_wait_bitset C preprocessor macro was used. As a result the 64 bit struct __timespec64 was coerced to 32 bit struct timespec and regression visible as timeout was observed (nptl/tst-robust10 on s390). Reported-by: Stefan Liebler <stli@linux.ibm.com> Tested-by: Stefan Liebler <stli@linux.ibm.com>
* y2038: nptl: Convert pthread_mutex_{clock|timed}lock to support 64 bitLukasz Majewski2020-10-152-20/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The pthread_mutex_clocklock and pthread_mutex_timedlock have been converted to support 64 bit time. This change uses: - New __futex_clocklock_wait64 (instead of lll_timedwait) from ./sysdeps/nptl/futex-helpers.c and - New __futex_clocklock64 function (instead of lll_clocklock) - New futex_lock_pi64 defined in sysdeps/nptl/futex-internal.h The pthread_mutex_{clock|timed}lock only accepts absolute time. Moreover, there is no need to check for NULL passed as *abstime pointer to the syscalls as those calls have exported symbols marked with __nonull attribute for abstime. Some architectures - namely x86, powerpc and s390 - do support lock elision. For those - adjustments have been made in arch specific elision-*.c files to use __futex_clocklock64 instead of lll_clocklock. The __lll_lock_elision (aliased to __lll_clocklock_elision in e.g. sysdeps/unix/sysv/linux/s390/elision-timed.c) just uses, in this patch provided, __futex_clocklock64. For systems with __TIMESIZE != 64 && __WORDSIZE == 32: - Conversions between 64 bit time to 32 bit are necessary - Redirection to pthread_mutex_{clock|timed}lock will provide support for 64 bit time Build tests: ./src/scripts/build-many-glibcs.py glibcs Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* Revert "Fix missing redirects in testsuite targets"Andreas Schwab2020-10-081-1/+1
| | | | | This reverts commit d5afb38503. The log files are actually created by the various shell scripts that drive the tests.
* y2038: nptl: Convert pthread_rwlock_{clock|timed}{rd|wr}lock to support 64 ↵Lukasz Majewski2020-10-048-31/+104
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | bit time The pthread_rwlock_clockrdlock, pthread_rwlock_clockwrlock, pthread_rwlock_timedrdlock and pthread_rwlock_timedwrlock have been converted to support 64 bit time. This change uses new futex_abstimed_wait64 function in ./sysdeps/nptl/futex-helpers.c, which uses futex_time64 where possible. The pthread_rwlock_{clock|timed}{rd|wr}lock only accepts absolute time. Moreover, there is no need to check for NULL passed as *abstime pointer to the syscalls as those calls have exported symbols marked with __nonull attribute for abstime. For systems with __TIMESIZE != 64 && __WORDSIZE == 32: - Conversions between 64 bit time to 32 bit are necessary - Redirection to pthread_rwlock_{clock|timed}{rd|wr}lock will provide support for 64 bit time Build tests: ./src/scripts/build-many-glibcs.py glibcs Run-time tests: - Run specific tests on ARM/x86 32bit systems (qemu): https://github.com/lmajewski/meta-y2038 and run tests: https://github.com/lmajewski/y2038-tests/commits/master Above tests were performed with Y2038 redirection applied as well as without to test the proper usage of both __pthread_rwlock_{clock|timed}{rd|wr}lock64 and __pthread_rwlock_{clock|timed}{rd|wr}lock. Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
* aarch64: enforce >=64K guard size [BZ #26691]Szabolcs Nagy2020-10-021-2/+12
| | | | | | | | | | | | | | | | | | | | | | | There are several compiler implementations that allow large stack allocations to jump over the guard page at the end of the stack and corrupt memory beyond that. See CVE-2017-1000364. Compilers can emit code to probe the stack such that the guard page cannot be skipped, but on aarch64 the probe interval is 64K by default instead of the minimum supported page size (4K). This patch enforces at least 64K guard on aarch64 unless the guard is disabled by setting its size to 0. For backward compatibility reasons the increased guard is not reported, so it is only observable by exhausting the address space or parsing /proc/self/maps on linux. On other targets the patch has no effect. If the stack probe interval is larger than a page size on a target then ARCH_MIN_GUARD_SIZE can be defined to get large enough stack guard on libc allocated stacks. The patch does not affect threads with user allocated stacks. Fixes bug 26691.
* y2038: nptl: Convert sem_{clock|timed}wait to support 64 bit timeLukasz Majewski2020-09-145-14/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The sem_clockwait and sem_timedwait have been converted to support 64 bit time. This change reuses futex_abstimed_wait_cancelable64 function introduced earlier. The sem_{clock|timed}wait only accepts absolute time. Moreover, there is no need to check for NULL passed as *abstime pointer to the syscalls as both calls have exported symbols marked with __nonull attribute for abstime. For systems with __TIMESIZE != 64 && __WORDSIZE == 32: - Conversion from 32 bit time to 64 bit struct __timespec64 was necessary - Redirection to __sem_{clock|timed}wait64 will provide support for 64 bit time Build tests: ./src/scripts/build-many-glibcs.py glibcs Run-time tests: - Run specific tests on ARM/x86 32bit systems (qemu): https://github.com/lmajewski/meta-y2038 and run tests: https://github.com/lmajewski/y2038-tests/commits/master Above tests were performed with Y2038 redirection applied as well as without to test the proper usage of both __sem_{clock|timed}wait64 and __sem_{clock|timed}wait. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* Remove internal usage of extensible stat functionsAdhemerval Zanella2020-09-111-1/+1
| | | | | | | | | | | | It replaces the internal usage of __{f,l}xstat{at}{64} with the __{f,l}stat{at}{64}. It should not change the generate code since sys/stat.h explicit defines redirections to internal calls back to xstat* symbols. Checked with a build for all affected ABIs. I also check on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski <lukma@denx.de>
* y2038: nptl: Convert pthread_cond_{clock|timed}wait to support 64 bit timeLukasz Majewski2020-09-022-8/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The pthread_cond_clockwait and pthread_cond_timedwait have been converted to support 64 bit time. This change introduces new futex_abstimed_wait_cancelable64 function in ./sysdeps/nptl/futex-helpers.c, which uses futex_time64 where possible and tries to replace low-level preprocessor macros from lowlevellock-futex.h The pthread_cond_{clock|timed}wait only accepts absolute time. Moreover, there is no need to check for NULL passed as *abstime pointer as __pthread_cond_wait_common() always passes non-NULL struct __timespec64 pointer to futex_abstimed_wait_cancellable64(). For systems with __TIMESIZE != 64 && __WORDSIZE == 32: - Conversions between 64 bit time to 32 bit are necessary - Redirection to __pthread_cond_{clock|timed}wait64 will provide support for 64 bit time The futex_abstimed_wait_cancelable64 function has been put into a separate file on the purpose - to avoid issues apparent on the m68k architecture related to small number of available registers (there is not enough registers to put all necessary arguments in them if the above function would be added to futex-internal.h with __always_inline attribute). In fact - new function - namely __futex_abstimed_wait_cancellable32 is used to reduce number of needed registers (as some in-register values are stored on the stack when function call is made). Build tests: ./src/scripts/build-many-glibcs.py glibcs Run-time tests: - Run specific tests on ARM/x86 32bit systems (qemu): https://github.com/lmajewski/meta-y2038 and run tests: https://github.com/lmajewski/y2038-tests/commits/master Above tests were performed with Y2038 redirection applied as well as without to test the proper usage of both __pthread_cond_{clock|timed}wait64 and __pthread_cond_{clock|timed}wait. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* nptl: Handle NULL abstime [BZ #26394]H.J. Lu2020-08-172-6/+16
| | | | | Since abstime passed to pthread_{clock|timed}join_np may be NULL, convert to 64 bit abstime only if abstime isn't NULL.
* y2038: nptl: Convert pthread_{clock|timed}join_np to support 64 bit timeLukasz Majewski2020-08-134-14/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The pthread_clockjoin_np and pthread_timedjoin_np have been converted to support 64 bit time. This change introduces new futex_timed_wait_cancel64 function in ./sysdeps/nptl/futex-internal.h, which uses futex_time64 where possible and tries to replace low-level preprocessor macros from lowlevellock-futex.h The pthread_{timed|clock}join_np only accept absolute time. Moreover, there is no need to check for NULL passed as *abstime pointer as clockwait_tid() always passes struct __timespec64. For systems with __TIMESIZE != 64 && __WORDSIZE == 32: - Conversions between 64 bit time to 32 bit are necessary - Redirection to __pthread_{clock|timed}join_np64 will provide support for 64 bit time Build tests: ./src/scripts/build-many-glibcs.py glibcs Run-time tests: - Run specific tests on ARM/x86 32bit systems (qemu): https://github.com/lmajewski/meta-y2038 and run tests: https://github.com/lmajewski/y2038-tests/commits/master Above tests were performed with Y2038 redirection applied as well as without to test the proper usage of both __pthread_{timed|clock}join_np64 and __pthread_{timed|clock}join_np. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
* htl: Enable tst-cancelx?[45]Samuel Thibault2020-08-067-1991/+2
| | | | | | | * nptl/{tst-cancel4-common.c, tst-cancel4-common.h, tst-cancel4.c, tst-cancel5.c, tst-cancelx4.c, tst-cancelx5.c}: Move to sysdeps/pthread/ * nptl/Makefile: Move corresponding rules to... * sysdeps/pthread/Makefile: ... here.
* tst-cancel4: Make blocking on write more portableSamuel Thibault2020-08-071-4/+4
| | | | | * nptl/tst-cancel4.c (tf_send, tf_sendto): Set socket buffer size after connecting.
* nptl: Zero-extend arguments to SETXID syscalls [BZ #26248]H.J. Lu2020-07-273-2/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | nptl has /* Opcodes and data types for communication with the signal handler to change user/group IDs. */ struct xid_command { int syscall_no; long int id[3]; volatile int cntr; volatile int error; }; /* This must be last, otherwise the current thread might not have permissions to send SIGSETXID syscall to the other threads. */ result = INTERNAL_SYSCALL_NCS (cmdp->syscall_no, 3, cmdp->id[0], cmdp->id[1], cmdp->id[2]); But the second argument of setgroups syscal is a pointer: int setgroups (size_t size, const gid_t *list); But on x32, pointers passed to syscall must have pointer type so that they will be zero-extended. The kernel XID arguments are unsigned and do not require sign extension. Change xid_command to struct xid_command { int syscall_no; unsigned long int id[3]; volatile int cntr; volatile int error; }; so that all arguments are zero-extended. A testcase is added for x32 and setgroups returned with EFAULT when running as root without the fix.
* Linux: Remove rseq supportFlorian Weimer2020-07-161-13/+0
| | | | | | | | | | | | | | | | | | The kernel ABI is not finalized, and there are now various proposals to change the size of struct rseq, which would make the glibc ABI dependent on the version of the kernels used for building glibc. This is of course not acceptable. This reverts commit 48699da1c468543ade14777819bd1b4d652709de ("elf: Support at least 32-byte alignment in static dlopen"), commit 8f4632deb3545b2949cec5454afc3cb21a0024ea ("Linux: rseq registration tests"), commit 6e29cb3f61ff5432c78a1c84b0d9b123a350ab36 ("Linux: Use rseq in sched_getcpu if available"), and commit 0c76fc3c2b346dc5401dc055d97d4279632b0fb3 ("Linux: Perform rseq registration at C startup and thread creation"), resolving the conflicts introduced by the ARC port and the TLS static surplus changes. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* string: Remove old TLS usage on strsignalAdhemerval Zanella2020-07-072-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The per-thread state is refactored two use two strategies: 1. The default one uses a TLS structure, which will be placed in the static TLS space (using __thread keyword). 2. Linux allocates via struct pthread and access it through THREAD_* macros. The default strategy has the disadvantage of increasing libc.so static TLS consumption and thus decreasing the possible surplus used in some scenarios (which might be mitigated by BZ#25051 fix). It is used only on Hurd, where accessing the thread storage in the in single thread case is not straightforward (afaiu, Hurd developers could correct me here). The fallback static allocation used for allocation failure is also removed: defining its size is problematic without synchronizing with translated messages (to avoid partial translation) and the resulting usage is not thread-safe. Checked on x86-64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu, and s390x-linux-gnu. Tested-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* linux: Fix __NSIG_WORDS and add __NSIG_BYTESAdhemerval Zanella2020-07-072-2/+2
| | | | | | | | | | | | | | The __NSIG_WORDS value is based on minimum number of words to hold the maximum number of signals supported by the architecture. This patch also adds __NSIG_BYTES, which is the number of bytes required to represent the supported number of signals. It is used in syscalls which takes a sigset_t. Checked on x86_64-linux-gnu and i686-linux-gnu. Tested-by: Carlos O'Donell <carlos@redhat.com> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* Add the __libc_single_threaded variableFlorian Weimer2020-07-061-0/+5
| | | | | | | | | | | | | | The variable is placed in libc.so, and it can be true only in an outer libc, not libcs loaded via dlmopen or static dlopen. Since thread creation from inner namespaces does not work, pthread_create can update __libc_single_threaded directly. Using __libc_early_init and its initial flag, implementation of this variable is very straightforward. A future version may reset the flag during fork (but not in an inner namespace), or after joining all threads except one. Reviewed-by: DJ Delorie <dj@redhat.com>
* Linux: Perform rseq registration at C startup and thread creationMathieu Desnoyers2020-07-061-0/+13
| | | | | | | | | | | | | | | | | | | Register rseq TLS for each thread (including main), and unregister for each thread (excluding main). "rseq" stands for Restartable Sequences. See the rseq(2) man page proposed here: https://lkml.org/lkml/2018/9/19/647 Those are based on glibc master branch commit 3ee1e0ec5c. The rseq system call was merged into Linux 4.18. The TLS_STATIC_SURPLUS define is increased to leave additional room for dlopen'd initial-exec TLS, which keeps elf/tst-auditmany working. The increase (76 bytes) is larger than 32 bytes because it has not been increased in quite a while. The cost in terms of additional TLS storage is quite significant, but it will also obscure some initial-exec-related dlopen failures.
* tst-cancel4: deal with ENOSYS errorsSamuel Thibault2020-07-051-4/+38
| | | | | | | | | | The Hurd port doesn't have support for sigwaitinfo, sigtimedwait, and msgget yet, so let us ignore the test for these when they return ENOSYS. * nptl/tst-cancel4.c (tf_sigwaitinfo): Fallback on sigwait when sigwaitinfo returns ENOSYS. (tf_sigtimedwait): Likewise with sigtimedwait. (tf_msgrcv, tf_msgsnd): Fallback on tf_usleep when msgget returns ENOSYS.
* htl: Enable cancel*16 an cancel*20 testsSamuel Thibault2020-06-295-507/+2
| | | | | | | | | | * nptl/tst-cancel16.c, tst-cancel20.c, tst-cancelx16.c, tst-cancelx20.c: Move to... * sysdeps/pthread: ... here. * nptl/Makefile: Move corresponding references and rules to... * sysdeps/pthread/Makefile: ... here. * sysdeps/mach/hurd/i386/Makefile: Xfail tst-cancel*16 for now: missing barrier pshared support, but test should be working otherwise.
* tst-cancel4-common.c: fix calling socketpairSamuel Thibault2020-06-261-1/+1
| | | | | | | | | | | PF_UNIX was actually never intended to be passed as protocol parameter to socket() calls: it is a protocol family, not a protocol. It happens that Linux introduced accepting it during its 2.0 development, but it shouldn't. OpenBSD kernels accept it as well, but FreeBSD and NetBSD rightfully do not. GNU/Hurd does not either. * nptl/tst-cancel4-common.c (do_test): Pass 0 instead of PF_UNIX as protocol.
* nptl: Don't madvise user provided stackSzabolcs Nagy2020-06-251-2/+3
| | | | | | | | | | | | | | | User provided stack should not be released nor madvised at thread exit because it's owned by the user. If the memory is shared or file based then MADV_DONTNEED can have unwanted effects. With memory tagging on aarch64 linux the tags are dropped and thus it may invalidate pointers. Tested on aarch64-linux-gnu with MTE, it fixes FAIL: nptl/tst-stack3 FAIL: nptl/tst-stack3-mem
* htl: Make sem_*wait cancellations pointsSamuel Thibault2020-06-243-131/+1
| | | | | | | | | | | | | | By aligning its implementation on pthread_cond_wait. * sysdeps/htl/sem-timedwait.c (cancel_ctx): New structure. (cancel_hook): New function. (__sem_timedwait_internal): Check for cancellation and register cancellation hook that wakes the thread up, and check again for cancellation on exit. * nptl/tst-cancel13.c, nptl/tst-cancelx13.c: Move to... * sysdeps/pthread/: ... here. * nptl/Makefile: Move corresponding references and rules to... * sysdeps/pthread/Makefile: ... here.
* htl: Enable tst-cancel25 testSamuel Thibault2020-06-242-172/+1
| | | | | | | | * nptl/tst-cancel25.c: Move to... * sysdeps/pthread/tst-cancel25.c: ... here. (tf2) Do not test for SIGCANCEL when it is not defined. * nptl/Makefile: Move corresponding reference to... * sysdeps/pthread/Makefile: ... here.
* nptl: Remove now-spurious tst-cancelx9 referencesSamuel Thibault2020-06-171-2/+1
| | | | | | | | They were to be moved to sysdeps/pthread/Makefile in 45fce058f ('htl: Enable more cancellation tests') * nptl/Makefile: (tests): Remove tst-cancelx9. (CFLAGS-tst-cancelx9.c): Remove.
* htl: Enable more cancellation testsSamuel Thibault2020-06-145-241/+1
| | | | | | | | * nptl/tst-cancel-self-cancelstate.c, tst-cancel-self.c, tst-cancel9.c, tst-cancelx9.c: Move to... * sysdeps/pthread: ... here. * nptl/Makefile: Move corresponding references and rules to... * sysdeps/pthread/Makefile: ... here.
* htl: Enable more cancel testsSamuel Thibault2020-06-108-512/+7
| | | | | | | * nptl/tst-cancel11.c, tst-cancel21-static.c, tst-cancel21.c, tst-cancel6.c, tst-cancelx11.c, tst-cancelx21.c, tst-cancelx6.c: Move to... * sysdeps/pthread: ... here. * nptl/Makefile: Move corresponding references and rules to... * sysdeps/pthread/Makefile: ... here.
* pthread: Move back linking rules to nptl and htlSamuel Thibault2020-06-081-0/+18
| | | | | | | | | | | | | d6d74ec16 ('htl: Enable more tests') moved the linking rules from nptl/Makefile and htl/Makefile to the shared sysdeps/pthread/Makefile. But e.g. on powerpc some tests are added in sysdeps/powerpc/Makefile, which is included *after* sysdeps/pthread/Makefile, and thus the tests don't get affected by the rules and fail to link. For now let's just copy over the set of rules in both nptl/Makefile and htl/Makefile. * sysdeps/pthread/Makefile: Move libpthread linking rules to... * htl/Makefile: ... here and... * nptl/Makefile: ... there.
* htl: Enable more testsSamuel Thibault2020-06-0711-735/+4
| | | | | | | | | | * nptl/tst-_res1.c, tst-_res1mod1.c, tst-_res1mod2.c, tst-atfork2.c, tst-atfork2mod.c, tst-fini1.c, tst-fini1mod.c, tst-tls4.c, tst-tls4moda.c, tst-tls4modb.c: Move to... * sysdeps/pthread: ... here. Rename tst-tls4.c to tst-pt-tls4.c to avoid conflicting with elf/tst-tls4.c. * nptl/Makefile: Move corresponding references and rules to... * sysdeps/pthread/Makefile: ... here.
* htl: Enable but XFAIL tst-flock2, tst-signal1, tst-signal2Samuel Thibault2020-06-074-646/+1
| | | | | | | | | | | They need setpshared support. * nptl/tst-flock2.c, tst-signal1.c, tst-signal2.c: Move to... * sysdeps/pthread: ... here. * nptl/Makefile: Move corresponding tests references to... * sysdeps/pthread/Makefile: ... here. * sysdeps/mach/hurd/i386/Makefile (test-xfail-tst-flock2, test-xfail-tst-signal1, test-xfail-tst-signal2): Add.