glibc/sysdeps/nptl
Adhemerval Zanella 290db09546 nptl: Handle spurious EINTR when thread cancellation is disabled (BZ#29029)
Some Linux interfaces never restart after being interrupted by a signal
handler, regardless of the use of SA_RESTART [1].  It means that for
pthread cancellation, if the target thread disables cancellation with
pthread_setcancelstate and calls such interfaces (like poll or select),
it should not see spurious EINTR failures due the internal SIGCANCEL.

However recent changes made pthread_cancel to always sent the internal
signal, regardless of the target thread cancellation status or type.
To fix it, the previous semantic is restored, where the cancel signal
is only sent if the target thread has cancelation enabled in
asynchronous mode.

The cancel state and cancel type is moved back to cancelhandling
and atomic operation are used to synchronize between threads.  The
patch essentially revert the following commits:

  8c1c0aae20 nptl: Move cancel type out of cancelhandling
  2b51742531 nptl: Move cancel state out of cancelhandling
  26cfbb7162 nptl: Remove CANCELING_BITMASK

However I changed the atomic operation to follow the internal C11
semantic and removed the MACRO usage, it simplifies a bit the
resulting code (and removes another usage of the old atomic macros).

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

[1] https://man7.org/linux/man-pages/man7/signal.7.html

Reviewed-by: Florian Weimer <fweimer@redhat.com>
Tested-by: Aurelien Jarno <aurelien@aurel32.net>

(cherry-picked from commit 404656009b)
2022-04-15 09:52:54 -03:00
..
bits Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
sys Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
_Fork.c posix: Consolidate fork implementation 2021-06-24 10:02:06 -03:00
aio_misc.h Linux: Move aio_init from librt into libc 2021-06-25 11:48:25 +02:00
dl-mutex.c elf, nptl: Resolve recursive lock implementation early 2021-05-10 10:31:41 +02:00
dl-thread_gscope_wait.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
dl-tls_init_tp.c nptl: Handle spurious EINTR when thread cancellation is disabled (BZ#29029) 2022-04-15 09:52:54 -03:00
dl-tunables.list nptl: Add glibc.pthread.stack_cache_size tunable 2021-06-28 16:41:58 +02:00
fork.h Linux: Move timer helper routines from librt to libc 2021-06-25 12:21:12 +02:00
futex-internal.h linux: Only use 64-bit syscall if required for internal futex 2021-06-22 12:09:52 -03:00
gai_misc.h resolv: Move libanl into libc (if libpthread is in libc) 2021-07-02 11:45:00 +02:00
Implies Get rid of nptl/sysdeps/pthread/ subdirectory 2014-06-12 13:48:47 -07:00
internaltypes.h Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
jmp-unwind.c nptl: Move pthreadP.h into sysdeps directory 2021-06-22 09:51:10 +02:00
libc_start_call_main.h nptl: Move pthreadP.h into sysdeps directory 2021-06-22 09:51:10 +02:00
libc-lock.h nptl: Move legacy unwinding implementation into libc 2021-04-21 19:49:50 +02:00
libc-lockP.h nptl: Use internal low-level lock type for !IS_IN (libc) 2021-07-07 08:41:14 +02:00
lowlevellock-futex.h nptl: Consolidate async cancel enable/disable implementation in libc 2021-05-05 17:19:32 +02:00
lowlevellock.h nptl: Use out-of-line wake function in __libc_lock_unlock slow path 2021-07-09 10:59:22 +02:00
Makeconfig Linux: Cleanups after librt move 2021-06-28 09:51:01 +02:00
Makefile Linux: Move timer helper routines from librt to libc 2021-06-25 12:21:12 +02:00
malloc-machine.h Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
proc_service.h Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
pthread_atfork_compat.h Consolidate pthread_atfork 2021-06-24 10:04:41 -03:00
pthread_early_init.h nptl: Move pthreadP.h into sysdeps directory 2021-06-22 09:51:10 +02:00
pthread_mutex_conf.h nptl: Move internal symbol __mutex_aconf into libc 2021-04-21 19:49:51 +02:00
pthread-offsets.h nptl: update default pthread-offsets.h 2020-02-10 17:01:21 +01:00
pthread.h nptl: Fix type of pthread_mutexattr_getrobust_np, pthread_mutexattr_setrobust_np (bug 28036) 2021-09-21 07:15:25 +02:00
pthreadP.h nptl: Handle spurious EINTR when thread cancellation is disabled (BZ#29029) 2022-04-15 09:52:54 -03:00
setxid.h nptl: Move pthreadP.h into sysdeps directory 2021-06-22 09:51:10 +02:00
stdio-lock.h libio: Assume _IO_lock_inexpensive 2021-06-04 09:54:52 -03:00
Subdirs Get rid of nptl/sysdeps/pthread/ subdirectory 2014-06-12 13:48:47 -07:00
tcb-offsets.h Get rid of nptl/sysdeps/pthread/ subdirectory 2014-06-12 13:48:47 -07:00
thread_db.h Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
timer_routines.h Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
tst-mqueue8x.c Get rid of nptl/sysdeps/pthread/ subdirectory 2014-06-12 13:48:47 -07:00