From patchwork Wed Mar 18 19:34:12 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 131922 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id D40504C3180C for ; Wed, 18 Mar 2026 19:37:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D40504C3180C Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Dw+kskuz X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dy1-x1335.google.com (mail-dy1-x1335.google.com [IPv6:2607:f8b0:4864:20::1335]) by sourceware.org (Postfix) with ESMTPS id F3F724B196D3 for ; Wed, 18 Mar 2026 19:35:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F3F724B196D3 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F3F724B196D3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1335 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773862503; cv=none; b=YtcXV0zUrOnT45yaqvzYnnd0jJFTzxvvdMmbOZnvslHS3vpPsjE+ssq1eJfugmEH7iYV6y9B1YX0yo6sTjGMcR4KiF2c/K5nkdozwOERMWvcFEPgdm1qBySOCBLIO9mz9mcxXXMcjZlr9ONhPDWXmAjC9v+kiAGNIUx27XWp/O8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773862503; c=relaxed/simple; bh=HcFj522Jj4ABEymZbb8lh+hugtOM04RQLDNghvO9GuQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=RYcHivhRcp1YSsVoDO4CEpIy5CcL+JJcV+/wzDAuw7aU8QbpgXx+mHcCGQeFnazutI/BZ9QLCnGh7/FYWFfNNLFkoascL51pkxyvpq2C5VVx6C9oRi+bBhNKAmBIEY4WiVsnSxUsHP4GOTuVAGyZsBRdGMLWFM/CO7RtL0g1ZdQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F3F724B196D3 Received: by mail-dy1-x1335.google.com with SMTP id 5a478bee46e88-2b4520f6b32so509751eec.0 for ; Wed, 18 Mar 2026 12:35:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1773862502; x=1774467302; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YqVtf1Y91sP4bNakMMDwc1QDAm2i4btaq1BCC9NGsP8=; b=Dw+kskuzDVBlKjYN/7sU1hXHGTH4gf7raEZKIkvmSHayAdIJeNr60G1mI/cISrGtMH jmH6lGNnvyT6RlITP/toXpi41UWsdZLVR0mGS7reXKPe9GydGYF+oPcw06N7gh37Tx2I Qd5dHBz/KhyItu4Eoc6J1Bfg5zcS/zKQBfsrv3uCHIKbk1Go+WgwIZ9r3nno5QsTdJcg aUssKmUX6aXAU/8HpQ6qGfBxsZJF3xukBJhOkmnKA98HiRmZiS9qtnHjUxovhQSvdzn6 O7qItHWDvRiF07f7NTCQg4yDjD/Xfl59fnkUxyaLZD2xj+XRFfWGNKpazqAyk/V9qL/a xo7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773862502; x=1774467302; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-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05:7022:225:b0:129:ea6:a3c7 with SMTP id a92af1059eb24-1299b9c25dcmr2187622c88.0.1773862501294; Wed, 18 Mar 2026 12:35:01 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:f5a4:2159:38c8:c951:d029]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-129b4147522sm4238937c88.15.2026.03.18.12.34.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 12:35:00 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer , Samuel Thibault Subject: [PATCH v8 1/6] nptl: Add __raise_direct Date: Wed, 18 Mar 2026 16:34:12 -0300 Message-ID: <20260318193454.2466865-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260318193454.2466865-1-adhemerval.zanella@linaro.org> References: <20260318193454.2466865-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org The function sends a signal to current thread using raw syscalls. Reviewed-by: Florian Weimer --- 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 73f18dddd7..099d721514 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 221689e36a..bc038e9824 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 8abe8d4cad..cf0770f1c8 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 c6bd97abf1..8797c5c9b3 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 0000000000..d38bd10817 --- /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 + . */ + +#include +#include +#include + +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; +}