[v8,1/6] nptl: Add __raise_direct
Checks
| Context |
Check |
Description |
| redhat-pt-bot/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
| linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_glibc_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_glibc_check--master-arm |
success
|
Test passed
|
Commit Message
The function sends a signal to current thread using raw syscalls.
---
include/signal.h | 3 +++
nptl/pthread_kill.c | 21 +++++++------------
sysdeps/posix/raise.c | 2 +-
sysdeps/unix/sysv/linux/Makefile | 4 ++++
sysdeps/unix/sysv/linux/raise_direct.c | 29 ++++++++++++++++++++++++++
5 files changed, 44 insertions(+), 15 deletions(-)
create mode 100644 sysdeps/unix/sysv/linux/raise_direct.c
Comments
* Adhemerval Zanella:
> The function sends a signal to current thread using raw syscalls.
> ---
> include/signal.h | 3 +++
> nptl/pthread_kill.c | 21 +++++++------------
> sysdeps/posix/raise.c | 2 +-
> sysdeps/unix/sysv/linux/Makefile | 4 ++++
> sysdeps/unix/sysv/linux/raise_direct.c | 29 ++++++++++++++++++++++++++
> 5 files changed, 44 insertions(+), 15 deletions(-)
> create mode 100644 sysdeps/unix/sysv/linux/raise_direct.c
Okay.
Reviewed-by: Florian Weimer <fweimer@redhat.com>
Thanks,
Florian
@@ -65,6 +65,9 @@ extern int __xpg_sigpause (int sig);
/* Allocate real-time signal with highest/lowest available priority. */
extern int __libc_allocate_rtsig (int __high);
+/* Similar to raise, but does not set errno. */
+extern int __raise_direct (int signo) attribute_hidden;
+
# if IS_IN (rtld)
extern __typeof (__sigaction) __sigaction attribute_hidden;
extern __typeof (__libc_sigaction) __libc_sigaction attribute_hidden;
@@ -29,20 +29,13 @@ __pthread_kill_implementation (pthread_t threadid, int signo, int no_tid)
{
struct pthread *pd = (struct pthread *) threadid;
if (pd == THREAD_SELF)
- {
- /* Use the actual TID from the kernel, so that it refers to the
- current thread even if called after vfork. There is no
- signal blocking in this case, so that the signal is delivered
- immediately, before __pthread_kill_internal returns: a signal
- sent to the thread itself needs to be delivered
- synchronously. (It is unclear if Linux guarantees the
- delivery of all pending signals after unblocking in the code
- below. POSIX only guarantees delivery of a single signal,
- which may not be the right one.) */
- pid_t tid = INTERNAL_SYSCALL_CALL (gettid);
- int ret = INTERNAL_SYSCALL_CALL (tgkill, __getpid (), tid, signo);
- return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0;
- }
+ /* There is no signal blocking in this case, so that the signal is
+ delivered immediately, before __pthread_kill_internal returns: a signal
+ sent to the thread itself needs to be delivered synchronously. (It is
+ unclear whether Linux guarantees the delivery of all pending signals
+ after unblocking in the code below. POSIX only guarantees delivery
+ of a single signal, which may not be the right one.) */
+ return __raise_direct (signo);
/* Block all signals, as required by pd->exit_lock. */
internal_sigset_t old_mask;
@@ -23,7 +23,7 @@
int
raise (int sig)
{
- int ret = __pthread_kill (__pthread_self (), sig);
+ int ret = __raise_direct (sig);
if (ret != 0)
{
__set_errno (ret);
@@ -455,6 +455,10 @@ tests += \
endif
ifeq ($(subdir),signal)
+sysdep_routines += \
+ raise_direct \
+ # sysdep_routines
+
tests-special += \
$(objpfx)tst-signal-numbers.out \
# tests-special
new file mode 100644
@@ -0,0 +1,29 @@
+/* Internal function to send a signal to itself. Linux version.
+ Copyright (C) 2026 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+#include <pthread.h>
+#include <unistd.h>
+
+int
+__raise_direct (int signo)
+{
+ pid_t tid = INTERNAL_SYSCALL_CALL (gettid);
+ int ret = INTERNAL_SYSCALL_CALL (tkill, tid, signo);
+ return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0;
+}