From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Cc: Florian Weimer <fweimer@redhat.com>
Subject: [PATCH v9 1/5] nptl: Add __raise_direct
Date: Fri, 29 May 2026 13:26:40 -0300 [thread overview]
Message-ID: <20260529162818.3749464-2-adhemerval.zanella@linaro.org> (raw)
In-Reply-To: <20260529162818.3749464-1-adhemerval.zanella@linaro.org>
The function sends a signal to current thread using raw syscalls.
Reviewed-by: Florian Weimer <fweimer@redhat.com>
---
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
diff --git a/include/signal.h b/include/signal.h
index 73f18dddd7f..099d7215146 100644
--- a/include/signal.h
+++ b/include/signal.h
@@ -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;
diff --git a/nptl/pthread_kill.c b/nptl/pthread_kill.c
index 221689e36a9..bc038e9824c 100644
--- a/nptl/pthread_kill.c
+++ b/nptl/pthread_kill.c
@@ -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;
diff --git a/sysdeps/posix/raise.c b/sysdeps/posix/raise.c
index 8abe8d4cad4..cf0770f1c81 100644
--- a/sysdeps/posix/raise.c
+++ b/sysdeps/posix/raise.c
@@ -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);
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index 63e7046cb3a..17f0c309a62 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -455,6 +455,10 @@ tests += \
endif
ifeq ($(subdir),signal)
+sysdep_routines += \
+ raise_direct \
+ # sysdep_routines
+
tests-special += \
$(objpfx)tst-signal-numbers.out \
# tests-special
diff --git a/sysdeps/unix/sysv/linux/raise_direct.c b/sysdeps/unix/sysv/linux/raise_direct.c
new file mode 100644
index 00000000000..d38bd10817a
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/raise_direct.c
@@ -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;
+}
--
2.43.0
next prev parent reply other threads:[~2026-05-29 16:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-29 16:26 [PATCH v9 0/5] elf: Allow RPATH/RUNPATH for static-pie Adhemerval Zanella
2026-05-29 16:26 ` Adhemerval Zanella [this message]
2026-05-29 16:26 ` [PATCH v9 2/5] Use _dl_writev on __libc_message_impl Adhemerval Zanella
2026-05-29 16:26 ` [PATCH v9 3/5] Fix assert during static startup (BZ 33326) Adhemerval Zanella
2026-06-08 10:46 ` Florian Weimer
2026-06-08 12:14 ` Adhemerval Zanella Netto
2026-06-08 14:26 ` Adhemerval Zanella Netto
2026-06-11 18:39 ` Adhemerval Zanella Netto
2026-06-17 18:10 ` Adhemerval Zanella Netto
2026-05-29 16:26 ` [PATCH v9 4/5] elf: Allow RPATH/RUNPATH for static-pie " Adhemerval Zanella
2026-05-29 16:26 ` [PATCH v9 5/5] elf: Remove __chk_fail from dl-minimal.c Adhemerval Zanella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260529162818.3749464-2-adhemerval.zanella@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).