Commit Graph

60 Commits

Author SHA1 Message Date
Samuel Thibault
6414eef6e0 htl: Move cleanup handling to non-private libc-lock
This adds sysdeps/htl/libc-lock.h which augments sysdeps/mach/libc-lock.h with
the htl-aware cleanup handling. Otherwise inclusion of libc-lock.h
without libc-lockP.h would keep only the mach-aware handling.

This also fixes cleanup getting called when the binary is
statically-linked without libpthread.

* sysdeps/htl/libc-lockP.h (__libc_cleanup_region_start,
__libc_cleanup_end, __libc_cleanup_region_end,
__pthread_get_cleanup_stack): Move to...
* sysdeps/htl/libc-lock.h: ... new file.
(__libc_cleanup_region_start): Always set handler and arg.
(__libc_cleanup_end): Always call the cleanup handler.
(__libc_cleanup_push, __libc_cleanup_pop): New macros.
2020-06-28 00:13:57 +00:00
Samuel Thibault
cf2c8cc2c6 htl: Fix includes for lockfile
These only need exactly to use __libc_ptf_call.

* sysdeps/htl/flockfile.c: Include <libc-lockP.h> instead of
<libc-lock.h>
* sysdeps/htl/ftrylockfile.c: Include <libc-lockP.h> instead of
<errno.h>, <pthread.h>, <stdio-lock.h>
* sysdeps/htl/funlockfile.c: Include <libc-lockP.h> instead of
<pthread.h> and <stdio-lock.h>
2020-06-28 00:13:57 +00:00
Florian Weimer
1fb7dc751e htl: Add wrapper header for <semaphore.h> with hidden __sem_post
This is required to avoid a check-localplt failure due to a
sem_post call through the PLT.

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
2020-06-24 13:38:08 +02:00
Samuel Thibault
1b90d52df9 htl: Fix case when sem_*wait is canceled while holding a token
* sysdeps/htl/sem-timedwait.c (struct cancel_ctx): Add cancel_wake
field.
(cancel_hook): When unblocking thread, set cancel_wake field to 1.
(__sem_timedwait_internal): Set cancel_wake field to 0 by default.
On cancellation exit, check whether we hold a token, to be put back.
2020-06-24 02:20:42 +02:00
Samuel Thibault
eca16db02d htl: Make sem_*wait cancellations points
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.
2020-06-24 01:19:49 +02:00
Samuel Thibault
3513d5af3d htl: Simplify non-cancel path of __pthread_cond_timedwait_internal
Since __pthread_exit does not return, we do not need to indent the
noncancel path

* sysdeps/htl/pt-cond-timedwait.c (__pthread_cond_timedwait_internal):
Move cancelled path before non-cancelled path, to avoid "else"
indentation.
2020-06-24 01:19:48 +02:00
Samuel Thibault
76fe4ef4be htl: Fix cleanup support for IO locking
* sysdeps/htl/stdio-lock.h: New file, registers locking cleanup to htl.
* sysdeps/htl/libc-lockP.h: Include <libc-lock.h>.
(__libc_cleanup_region_start, __libc_cleanup_end,
__libc_cleanup_region_end): Override macros from <libc-lock.h> with
versions which register cleanup to htl.
(__pthread_get_cleanup_stack): Make reference weak for skipping
registration on in the static non-libpthread case.
2020-06-14 15:53:04 +00:00
Samuel Thibault
ea5cad3e37 htl: Add noreturn attribute on __pthread_exit forward
* sysdeps/htl/pthread-functions.h (__pthread_exit): Add noreturn
attribute.
(struct pthread_functions): Add noreturn attribute on ptr___pthread_exit
field.
2020-06-14 12:53:38 +00:00
Samuel Thibault
15e995a8fb htl: Fix registration of atfork handlers in modules
We really need modules to use their own pthread_atfork so that
__dso_handle properly identifies them.

* sysdeps/htl/pt-atfork.c (__pthread_atfork): Hide function.
(pthread_atfork): Hide alias.
* sysdeps/htl/old_pt-atfork.c (pthread_atfork): Rename macro to
__pthread_atfork to fix building the compatibility alias.
2020-06-07 23:36:42 +00:00
Samuel Thibault
af27fabe40 htl: Fix tls initialization for already-created threads
* sysdeps/htl/pthreadP.h: Include <link.h>
(__pthread_init_static_tls): New prototype.
* htl/pt-alloc.c (__pthread_init_static_tls): New function.
* sysdeps/mach/hurd/htl/pt-sysdep.c (_init_routine): Initialize tcb
field of initial thread. Set GL(dl_init_static_tls) to
&__pthread_init_static_tls.
2020-06-07 23:36:40 +00:00
Samuel Thibault
be22a151f3 htl: Add sem_clockwait support
* sysdeps/htl/sem-timedwait.c (__sem_timedwait_internal): Add clock_id
parameter instead of hardcoding CLOCK_REALTIME.
(__sem_clockwait): New function.
(sem_clockwait): New weak alias.
* sysdeps/htl/sem-wait.c (__sem_timedwait_internal): Update declaration.
(__sem_wait): Update call to __sem_timedwait_internal.
* htl/Versions (GLIBC_2.32): Add sem_clockwait.
* sysdeps/mach/hurd/i386/libpthread.abilist (sem_clockwait): Add symbol.
* nptl/Makefile (tests): Move tst-sem5 to...
* sysdeps/pthread/Makefile (tests): ... here.
2020-06-07 03:14:49 +02:00
Samuel Thibault
8c64cc78bc htl: Fix gsync_wait symbol exposition
* sysdeps/htl/pt-cond-destroy.c (__pthread_cond_destroy): Call
__gsync_wait instead of gsync_wait.
2020-06-01 22:22:03 +02:00
Samuel Thibault
8081702460 htl: Make pthread_cond_destroy wait for threads to be woken
This allows to reuse the storage after calling pthread_cond_destroy.

* sysdeps/htl/bits/types/struct___pthread_cond.h (__pthread_cond):
Replace unused struct __pthread_condimpl *__impl field with unsigned int
__wrefs.
(__PTHREAD_COND_INITIALIZER): Update accordingly.
* sysdeps/htl/pt-cond-timedwait.c (__pthread_cond_timedwait_internal):
Register as waiter in __wrefs field. On unregistering, wake any pending
pthread_cond_destroy.
* sysdeps/htl/pt-cond-destroy.c (__pthread_cond_destroy): Register wake
request in __wrefs.
* nptl/Makefile (tests): Move tst-cond20 tst-cond21 to...
* sysdeps/pthread/Makefile (tests): ... here.
* nptl/tst-cond20.c nptl/tst-cond21.c: Move to...
* sysdeps/pthread/tst-cond20.c sysdeps/pthread/tst-cond21.c: ... here.
2020-06-01 17:38:31 +00:00
Samuel Thibault
28cada0418 htl: Add clock variants
* htl/pt-join.c (__pthread_join): Move implementation to...
(__pthread_join_common): ... new function. Add try, timed and clock support.
(__pthread_join): Reimplement on top of __pthread_join_common.
(__pthread_tryjoin_np, __pthread_timedjoin_np, __pthread_clockjoin_np):
Implement on top of __pthread_join_common.
(pthread_tryjoin_np, pthread_timedjoin_np, pthread_clockjoin_np): New
aliases.

* hurd/hurdlock.c (__lll_abstimed_wait, __lll_abstimed_xwait,
__lll_abstimed_lock): Check for supported clock.

* sysdeps/htl/pt-cond-timedwait.c (__pthread_cond_timedwait_internal):
Add clockid parameter and support it.
(__pthread_cond_timedwait): Pass -1 as clockid.
(__pthread_cond_clockwait): New function.
(pthread_cond_clockwait): New alias.
* sysdeps/htl/pt-cond-wait.c (__pthread_cond_timedwait_internal): Update
prototype.
(__pthread_cond_wait): Pass -1 as clockid.

* sysdeps/htl/pt-rwlock-timedrdlock.c
(__pthread_rwlock_timedrdlock_internal): Add clockid parameter, and
support id.
(__pthread_rwlock_clockrdlock): New function.
(pthread_rwlock_clockrdlock): New alias.
* sysdeps/htl/pt-rwlock-rdlock.c (__pthread_rwlock_timedrdlock_internal): Update
prototype.
(__pthread_rwlock_rdlock): Pass -1 as clockid.

* sysdeps/htl/pt-rwlock-timedwrlock.c
(__pthread_rwlock_timedwrlock_internal): Add clockid parameter, and
support id.
(__pthread_rwlock_clockwrlock): New function.
(pthread_rwlock_clockwrlock): New alias.
* sysdeps/htl/pt-rwlock-wrlock.c (__pthread_rwlock_timedwrlock_internal): Update
prototype.
(__pthread_rwlock_wrlock): Pass -1 as clockid.

* sysdeps/mach/hurd/htl/pt-mutex-timedlock.c (__pthread_mutex_timedlock): Move implementation to
(__pthread_mutex_clocklock): New function with additional clockid
parameter and support it.
(pthread_mutex_clocklock): New alias.
(__pthread_mutex_timedlock): Reimplement on top of __pthread_mutex_clocklock.

* sysdeps/htl/pthread.h (pthread_tryjoin_np, pthread_timedjoin_np,
pthread_clockjoin_np, pthread_mutex_clocklock, pthread_cond_clockwait,
pthread_rwlock_clockrdlock, pthread_rwlock_clockwrlock): New prototypes.
* sysdeps/htl/pthreadP.h (__pthread_cond_clockwait): New prototype.

* htl/Versions (GLIBC_2.32): Add pthread_cond_clockwait,
pthread_mutex_clocklock, pthread_rwlock_clockrdlock, pthread_rwlock_clockwrlock,
pthread_tryjoin_np, pthread_timedjoin_np, pthread_clockjoin_np.
* sysdeps/mach/hurd/i386/libpthread.abilist (pthread_clockjoin_np,
pthread_cond_clockwait, pthread_mutex_clocklock, pthread_rwlock_clockrdlock,
pthread_rwlock_clockwrlock, pthread_timedjoin_np, pthread_tryjoin_np):
New functions.

* nptl/tst-abstime.c, nptl/tst-join10.c, nptl/tst-join11.c, nptl/tst-join12.c,
nptl/tst-join13.c, nptl/tst-join14.c, nptl/tst-join2.c, nptl/tst-join3.c,
nptl/tst-join8.c, nptl/tst-join9.c, nptl/tst-mutex-errorcheck.c,
nptl/tst-pthread-mutexattr.c, nptl/tst-mutex11.c, nptl/tst-mutex5.c,
nptl/tst-mutex7.c, nptl/tst-mutex7robus.c, nptl/tst-mutex9.c,
nptl/tst-rwlock12.c, nptl/tst-rwlock14.c: Move to sysdeps/pthread.
* sysdeps/pthread/tst-mutex8.c: Move back to nptl.
* nptl/Makefile (tests): Move tst-mutex5, tst-mutex7, tst-mutex7robust,
tst-mutex9, tst-mutex11, tst-rwlock12, tst-rwlock14, tst-join2, tst-join3,
tst-join8, tst-join9 tst-join10, tst-join11, tst-join12, tst-join13, tst-join14,
tst-abstime, tst-mutex-errorcheck, tst-pthread-mutexattr to ...
* sysdeps/pthread/Makefile (tests): ... here.
2020-05-26 00:46:07 +00:00
Samuel Thibault
a25077a431 pthread: Move robust mutex tests from nptl to sysdeps/pthread
tst-robust8.c prints some mutex internals for nptl debugging, this
needed to be made conditioned by getting built with nptl.
2020-02-16 14:43:54 +00:00
Samuel Thibault
6c43d94a96 htl: Add missing functions and defines for robust mutexes 2020-02-16 14:08:56 +00: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
f3a7ff069f htl: Fix barrier_wait with one thread 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
1cec114b17 htl: Make sem_open return ENOSYS
instead of EOPNOTSUPP, which is for sockets.
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
59b7fe99f2 htl: Add support for libc cancellation points 2020-02-10 01:03:50 +00:00
Samuel Thibault
f1cd3407e4 htl: clean __pthread_get_cleanup_stack hidden proto 2020-02-10 00:06:59 +00:00
Samuel Thibault
52b6cdb4e3 htl: support cancellation during pthread_once 2020-02-09 19:43:46 +00:00
Samuel Thibault
faae4b2bdd htl: make pthread_cond_destroy return EBUSY on waiters 2020-02-09 19:24:42 +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
e622ce98c5 htl: Avoid check-installed-headers looking at inlines 2020-02-09 16:42:36 +00:00
Samuel Thibault
865bf71109 htl: Do not put spin_lock inlines in public headers
They were not getting used anyway.
Also do not make libsupport use them, it would make tests using it have
to be made to link against libmachuser for gsync_wait.
2020-02-09 16:36:37 +00: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
6cefe985b8 htl: Add C11 threads types definitions 2020-02-09 13:56:48 +01:00
Samuel Thibault
f827f0e473 htl: Make __PTHREAD_ONCE_INIT more flexible
by moving its (struct __pthread_once) cast into PTHREAD_ONCE_INIT.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-02-09 13:56:48 +01:00
Samuel Thibault
0c0361235c htl: Add support for C11 threads behavior
Essentially properly calling the thread function which returns an int
instead of a void*.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2020-02-09 13:56:48 +01:00
Samuel Thibault
95669bbf2c htl: Add missing internal functions declarations 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
a99155555c htl: Remove unused files
These have never been used.
2020-02-09 01:27:38 +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
e404be33fe htl: Add internal versions of functions used by C11 threads
The C11 threads implementation needs to call pthread_join and
pthread_key_delete without exposing them.
2020-01-13 00:48:47 +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
Samuel Thibault
50a78baa8e htl: Move pthread_atfork to libc_nonshared.a
This follows bd60ce8652 ('nptl: Move pthread_atfork to libc_nonshared.a')
with the same rationale: there is no non-libpthread equivalent to be used
for making linking against libpthread optional.

libpthread_nonshared.a is unused after this, so remove it from the
build.

There is no ABI impact because pthread_atfork was implemented using
__register_atfork in libc even before this change.

pthread_atfork has to be a weak alias because pthread_* names are not
reserved in libc.
2020-01-04 18:55:47 +01:00
Samuel Thibault
af7be496c9 htl: Use dso_handle.h 2020-01-04 17:25:08 +01:00
Joseph Myers
d614a75396 Update copyright dates with scripts/update-copyrights. 2020-01-01 00:14:33 +00:00
Lukasz Majewski
4812365660 time: Introduce function to check correctness of nanoseconds value
The valid_nanoseconds () static inline function has been introduced to
check if nanoseconds value is in the correct range - greater or equal to
zero and less than 1000000000.

The explicit #include <time.h> has been added to files where it was
missing.

The __syscall_slong_t type for ns has been used to avoid issues on x32.

Tested with:
- scripts/build-many-glibcs.py
- make PARALLELMFLAGS="-j12" && make PARALLELMFLAGS="-j12" xcheck on x86_64
2019-10-27 21:49:25 +01:00
Paul Eggert
5a82c74822 Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:

sed -ri '
  s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
  s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
  $(find $(git ls-files) -prune -type f \
      ! -name '*.po' \
      ! -name 'ChangeLog*' \
      ! -path COPYING ! -path COPYING.LIB \
      ! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
      ! -path manual/texinfo.tex ! -path scripts/config.guess \
      ! -path scripts/config.sub ! -path scripts/install-sh \
      ! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
      ! -path INSTALL ! -path  locale/programs/charmap-kw.h \
      ! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
      ! '(' -name configure \
            -execdir test -f configure.ac -o -f configure.in ';' ')' \
      ! '(' -name preconfigure \
            -execdir test -f preconfigure.ac ';' ')' \
      -print)

and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:

  chmod a+x sysdeps/unix/sysv/linux/riscv/configure
  # Omit irrelevant whitespace and comment-only changes,
  # perhaps from a slightly-different Autoconf version.
  git checkout -f \
    sysdeps/csky/configure \
    sysdeps/hppa/configure \
    sysdeps/riscv/configure \
    sysdeps/unix/sysv/linux/csky/configure
  # Omit changes that caused a pre-commit check to fail like this:
  # remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
  git checkout -f \
    sysdeps/powerpc/powerpc64/ppc-mcount.S \
    sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
  # Omit change that caused a pre-commit check to fail like this:
  # remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
  git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 02:43:31 -07:00
Samuel Thibault
55137f7dd9 hurd: advertise *_setpshared as not supported
The functions themselves return 0, but initializing a mutex/etc with       .
pshared set to 1 will fail anyway                                          .

	* sysdeps/htl/pt-barrierattr-setpshared.c
	(pthread_barrierattr_setpshared): Add stub warning.
	* sysdeps/htl/pt-condattr-setpshared.c
	(pthread_condattr_setpshared): Likewise.
	* sysdeps/htl/pt-mutexattr-setpshared.c
	(pthread_mutexattr_setpshared): Likewise.
	* sysdeps/htl/pt-rwlockattr-setpshared.c
	(pthread_rwlockattr_setpshared): Likewise.
	* sysdeps/mach/hurd/htl/pt-mutexattr-setpshared.c
	(pthread_mutexattr_setpshared): Likewise.
2019-01-02 22:21:34 +01:00
Joseph Myers
04277e02d7 Update copyright dates with scripts/update-copyrights.
* All files with FSF copyright notices: Update copyright dates
	using scripts/update-copyrights.
	* locale/programs/charmap-kw.h: Regenerated.
	* locale/programs/locfile-kw.h: Likewise.
2019-01-01 00:11:28 +00:00
Samuel Thibault
fc493bc9e6 htl: Fix comparing attr with default values
Fortunately we were previously only missing an optimization.

Thanks dcb <dcb314@hotmail.com> for the report

	[BZ #23032]
	* sysdeps/htl/pt-barrier-init.c (pthread_barrier_init): Fix comparing
	attr with __pthread_default_barrierattr.
	* sysdeps/htl/pt-cond-init.c (__pthread_cond_init): Fix comparing
	attr with __pthread_default_condattr.
	* sysdeps/htl/pt-mutex-init.c (_pthread_mutex_init): Fix comparing
	attr with __pthread_default_mutexattr.
	* sysdeps/htl/pt-rwlock-init.c (_pthread_rwlock_init): Fix comparing
	attr with __pthread_default_rwlockattr.
2018-12-01 21:42:12 +01:00